// Sets a single property as dirty. void ElementStyle::DirtyProperty(const String& property) { PropertyNameList properties; properties.insert(String(property)); DirtyProperties(properties); }
// Dirties em-relative properties. void ElementStyle::DirtyEmProperties() { PropertyNameList properties; StyleSheetSpecification::GetRegisteredProperties(properties); // Check if any of these are currently em-relative. If so, dirty them. PropertyNameList em_properties; for (PropertyNameList::iterator list_iterator = properties.begin(); list_iterator != properties.end(); ++list_iterator) { // Skip font-size; this is relative to our parent's em, not ours. if (*list_iterator == FONT_SIZE) continue; // Get this element from this element. If this is em-relative, then add it to the list to // dirty. if (element->GetProperty(*list_iterator)->unit == Property::EM) em_properties.insert(*list_iterator); } if (!em_properties.empty()) DirtyProperties(em_properties); // Now dirty all of our descendant's font-size properties that are relative to ems. int num_children = element->GetNumChildren(true); for (int i = 0; i < num_children; ++i) element->GetChild(i)->GetStyle()->DirtyInheritedEmProperties(); }
// Dirties every property. void ElementStyle::DirtyProperties() { PropertyNameList properties; StyleSheetSpecification::GetRegisteredProperties(properties); DirtyProperties(properties); }
void ElementStyle::UpdateDefinition() { if (definition_dirty) { definition_dirty = false; ElementDefinition* new_definition = NULL; const StyleSheet* style_sheet = GetStyleSheet(); if (style_sheet != NULL) { new_definition = style_sheet->GetElementDefinition(element); } // Switch the property definitions if the definition has changed. if (new_definition != definition || new_definition == NULL) { PropertyNameList properties; if (definition != NULL) { definition->GetDefinedProperties(properties, pseudo_classes); definition->RemoveReference(); } definition = new_definition; if (definition != NULL) definition->GetDefinedProperties(properties, pseudo_classes); DirtyProperties(properties); element->GetElementDecoration()->ReloadDecorators(); } else if (new_definition != NULL) { new_definition->RemoveReference(); } } if (child_definition_dirty) { for (int i = 0; i < element->GetNumChildren(true); i++) { element->GetChild(i)->GetStyle()->UpdateDefinition(); } child_definition_dirty = false; } }
// Dirties rem properties. void ElementStyle::DirtyRemProperties() { const PropertyNameList &properties = StyleSheetSpecification::GetRegisteredProperties(); PropertyNameList rem_properties; // Dirty all the properties of this element that use the rem unit. for (PropertyNameList::const_iterator list_iterator = properties.begin(); list_iterator != properties.end(); ++list_iterator) { if (element->GetProperty(*list_iterator)->unit == Property::REM) rem_properties.insert(*list_iterator); } if (!rem_properties.empty()) DirtyProperties(rem_properties, false); // Now dirty all of our descendant's properties that use the rem unit. int num_children = element->GetNumChildren(true); for (int i = 0; i < num_children; ++i) element->GetChild(i)->GetStyle()->DirtyRemProperties(); }
// Sets or removes a pseudo-class on the element. void ElementStyle::SetPseudoClass(const String& pseudo_class, bool activate) { size_t num_pseudo_classes = pseudo_classes.size(); if (activate) pseudo_classes.insert(pseudo_class); else pseudo_classes.erase(pseudo_class); if (pseudo_classes.size() != num_pseudo_classes) { element->GetElementDecoration()->DirtyDecorators(); const ElementDefinition* definition = element->GetDefinition(); if (definition != NULL) { PropertyNameList properties; definition->GetDefinedProperties(properties, pseudo_classes, pseudo_class); DirtyProperties(properties); switch (definition->GetPseudoClassVolatility(pseudo_class)) { case ElementDefinition::FONT_VOLATILE: element->DirtyFont(); break; case ElementDefinition::STRUCTURE_VOLATILE: DirtyChildDefinitions(); break; default: break; } } } }