示例#1
0
// Iterates over the properties in the definition.
bool ElementDefinition::IterateProperties(int& index, const PseudoClassList& pseudo_classes, PseudoClassList& property_pseudo_classes, String& property_name, const Property*& property) const
{
	if (index < properties.GetNumProperties())
	{
		PropertyMap::const_iterator i = properties.GetProperties().begin();
		for (int count = 0; count < index; ++count)
			++i;

		property_pseudo_classes.clear();
		property_name = (*i).first;
		property = &((*i).second);
		++index;

		return true;
	}

	// Not in the base properties; check for pseudo-class overrides.
	int property_count = properties.GetNumProperties();
	for (PseudoClassPropertyDictionary::const_iterator i = pseudo_class_properties.begin(); i != pseudo_class_properties.end(); ++i)
	{
		// Iterate over each pseudo-class set that has a definition for this property; if we find one that matches our
		// pseudo-class, increment our index counter and either return that property (if we hit the requested index) or
		// continue looking if we're still below it.
		for (size_t j = 0; j < (*i).second.size(); ++j)
		{
			if (IsPseudoClassRuleApplicable((*i).second[j].first, pseudo_classes))
			{
				property_count++;
				if (property_count > index)
				{
					// Copy the list of pseudo-classes.
					property_pseudo_classes.clear();
					for (size_t k = 0; k < (*i).second[j].first.size(); ++k)
						property_pseudo_classes.insert((*i).second[j].first[k]);

					property_name = (*i).first;
					property = &((*i).second[j].second);
					++index;

					return true;
				}
				else
				{
					break;
				}
			}
		}
	}

	return false;
}
// Iterates over the properties defined on the element.
bool ElementStyle::IterateProperties(int& index, PseudoClassList& property_pseudo_classes, String& name, const Property*& property)
{
	// First check for locally defined properties.
	if (local_properties != NULL)
	{
		if (index < local_properties->GetNumProperties())
		{
			PropertyMap::const_iterator i = local_properties->GetProperties().begin();
			for (int count = 0; count < index; ++count)
				++i;

			name = (*i).first;
			property = &((*i).second);
			property_pseudo_classes.clear();
			++index;

			return true;
		}
	}

	const ElementDefinition* definition = GetDefinition();
	if (definition != NULL)
	{
		int index_offset = 0;
		if (local_properties != NULL)
			index_offset = local_properties->GetNumProperties();

		// Offset the index to be relative to the definition before we start indexing. When we do get a property back,
		// check that it hasn't been overridden by the element's local properties; if so, continue on to the next one.
		index -= index_offset;
		while (definition->IterateProperties(index, pseudo_classes, property_pseudo_classes, name, property))
		{
			if (local_properties == NULL ||
				local_properties->GetProperty(name) == NULL)
			{
				index += index_offset;
				return true;
			}
		}

		return false;
	}

	return false;
}