mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
Make replace_rules returning boolean.
We only use whether the return value is IMPORTANT_RULES_CHANGED or not, so we can just return true if an important rules was changed in the function. Also, we can just return false in case of animation rules changes sine for animation we can ensure there is no importan rules. Because of these changes, replace_rule_node does not borrow |result| so that we can drop a scope there.
This commit is contained in:
parent
fce7c2d885
commit
a921d1af22
2 changed files with 55 additions and 59 deletions
|
@ -972,78 +972,74 @@ pub trait MatchMethods : TElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the rule nodes without re-running selector matching, using just
|
/// Updates the rule nodes without re-running selector matching, using just
|
||||||
/// the rule tree. Returns RulesChanged which indicates whether the rule nodes changed
|
/// the rule tree. Returns true if an !important rule was replaced.
|
||||||
/// and whether the important rules changed.
|
|
||||||
fn replace_rules(&self,
|
fn replace_rules(&self,
|
||||||
replacements: RestyleReplacements,
|
replacements: RestyleReplacements,
|
||||||
context: &StyleContext<Self>,
|
context: &StyleContext<Self>,
|
||||||
data: &mut ElementData)
|
data: &mut ElementData)
|
||||||
-> RulesChanged {
|
-> bool {
|
||||||
use properties::PropertyDeclarationBlock;
|
use properties::PropertyDeclarationBlock;
|
||||||
use shared_lock::Locked;
|
use shared_lock::Locked;
|
||||||
|
|
||||||
let element_styles = &mut data.styles_mut();
|
let element_styles = &mut data.styles_mut();
|
||||||
let primary_rules = &mut element_styles.primary.rules;
|
let primary_rules = &mut element_styles.primary.rules;
|
||||||
let mut result = RulesChanged::empty();
|
let mut result = false;
|
||||||
|
|
||||||
{
|
let replace_rule_node = |level: CascadeLevel,
|
||||||
let mut replace_rule_node = |level: CascadeLevel,
|
pdb: Option<&Arc<Locked<PropertyDeclarationBlock>>>,
|
||||||
pdb: Option<&Arc<Locked<PropertyDeclarationBlock>>>,
|
path: &mut StrongRuleNode| -> bool {
|
||||||
path: &mut StrongRuleNode| {
|
let new_node = context.shared.stylist.rule_tree()
|
||||||
let new_node = context.shared.stylist.rule_tree()
|
.update_rule_at_level(level, pdb, path, &context.shared.guards);
|
||||||
.update_rule_at_level(level, pdb, path, &context.shared.guards);
|
match new_node {
|
||||||
if let Some(n) = new_node {
|
Some(n) => {
|
||||||
*path = n;
|
*path = n;
|
||||||
if level.is_important() {
|
level.is_important()
|
||||||
result.insert(IMPORTANT_RULES_CHANGED);
|
},
|
||||||
} else {
|
None => false,
|
||||||
result.insert(NORMAL_RULES_CHANGED);
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Animation restyle hints are processed prior to other restyle
|
// Animation restyle hints are processed prior to other restyle
|
||||||
// hints in the animation-only traversal.
|
// hints in the animation-only traversal.
|
||||||
//
|
//
|
||||||
// Non-animation restyle hints will be processed in a subsequent
|
// Non-animation restyle hints will be processed in a subsequent
|
||||||
// normal traversal.
|
// normal traversal.
|
||||||
if replacements.intersects(RestyleReplacements::for_animations()) {
|
if replacements.intersects(RestyleReplacements::for_animations()) {
|
||||||
debug_assert!(context.shared.traversal_flags.for_animation_only());
|
debug_assert!(context.shared.traversal_flags.for_animation_only());
|
||||||
|
|
||||||
if replacements.contains(RESTYLE_SMIL) {
|
if replacements.contains(RESTYLE_SMIL) {
|
||||||
replace_rule_node(CascadeLevel::SMILOverride,
|
replace_rule_node(CascadeLevel::SMILOverride,
|
||||||
self.get_smil_override(),
|
self.get_smil_override(),
|
||||||
primary_rules);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut replace_rule_node_for_animation = |level: CascadeLevel,
|
|
||||||
primary_rules: &mut StrongRuleNode| {
|
|
||||||
let animation_rule = self.get_animation_rule_by_cascade(level);
|
|
||||||
replace_rule_node(level,
|
|
||||||
animation_rule.as_ref(),
|
|
||||||
primary_rules);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Apply Transition rules and Animation rules if the corresponding restyle hint
|
|
||||||
// is contained.
|
|
||||||
if replacements.contains(RESTYLE_CSS_TRANSITIONS) {
|
|
||||||
replace_rule_node_for_animation(CascadeLevel::Transitions,
|
|
||||||
primary_rules);
|
|
||||||
}
|
|
||||||
|
|
||||||
if replacements.contains(RESTYLE_CSS_ANIMATIONS) {
|
|
||||||
replace_rule_node_for_animation(CascadeLevel::Animations,
|
|
||||||
primary_rules);
|
|
||||||
}
|
|
||||||
} else if replacements.contains(RESTYLE_STYLE_ATTRIBUTE) {
|
|
||||||
let style_attribute = self.style_attribute();
|
|
||||||
replace_rule_node(CascadeLevel::StyleAttributeNormal,
|
|
||||||
style_attribute,
|
|
||||||
primary_rules);
|
|
||||||
replace_rule_node(CascadeLevel::StyleAttributeImportant,
|
|
||||||
style_attribute,
|
|
||||||
primary_rules);
|
primary_rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let replace_rule_node_for_animation = |level: CascadeLevel,
|
||||||
|
primary_rules: &mut StrongRuleNode| {
|
||||||
|
let animation_rule = self.get_animation_rule_by_cascade(level);
|
||||||
|
replace_rule_node(level,
|
||||||
|
animation_rule.as_ref(),
|
||||||
|
primary_rules);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Apply Transition rules and Animation rules if the corresponding restyle hint
|
||||||
|
// is contained.
|
||||||
|
if replacements.contains(RESTYLE_CSS_TRANSITIONS) {
|
||||||
|
replace_rule_node_for_animation(CascadeLevel::Transitions,
|
||||||
|
primary_rules);
|
||||||
|
}
|
||||||
|
|
||||||
|
if replacements.contains(RESTYLE_CSS_ANIMATIONS) {
|
||||||
|
replace_rule_node_for_animation(CascadeLevel::Animations,
|
||||||
|
primary_rules);
|
||||||
|
}
|
||||||
|
} else if replacements.contains(RESTYLE_STYLE_ATTRIBUTE) {
|
||||||
|
let style_attribute = self.style_attribute();
|
||||||
|
result |= replace_rule_node(CascadeLevel::StyleAttributeNormal,
|
||||||
|
style_attribute,
|
||||||
|
primary_rules);
|
||||||
|
result |= replace_rule_node(CascadeLevel::StyleAttributeImportant,
|
||||||
|
style_attribute,
|
||||||
|
primary_rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
|
|
|
@ -770,11 +770,11 @@ fn compute_style<E, D>(_traversal: &D,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
CascadeWithReplacements(flags) => {
|
CascadeWithReplacements(flags) => {
|
||||||
let rules_changed = element.replace_rules(flags, context, data);
|
let important_rules_changed = element.replace_rules(flags, context, data);
|
||||||
element.cascade_primary_and_pseudos(
|
element.cascade_primary_and_pseudos(
|
||||||
context,
|
context,
|
||||||
data,
|
data,
|
||||||
rules_changed.important_rules_changed()
|
important_rules_changed
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
CascadeOnly => {
|
CascadeOnly => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue