mirror of
https://github.com/servo/servo.git
synced 2025-06-23 08:34:42 +01:00
style: Allow calling GetBaseComputedStylesForElement for an unstyled element.
Before this refactoring, getComputedStyle could have side effects, and left the style data in the element, so we could never arrive there without data. There are a few crashtests that caught this, but this was already broken if you called animate() on an element deep in a display: none subtree. MozReview-Commit-ID: 1AvOvhAyOP3
This commit is contained in:
parent
c6d5dbbb01
commit
d15acc219e
2 changed files with 33 additions and 39 deletions
|
@ -840,37 +840,6 @@ pub trait MatchMethods : TElement {
|
|||
// StyleChange::Changed conservatively.
|
||||
StyleDifference::new(damage, StyleChange::Changed)
|
||||
}
|
||||
|
||||
/// Returns computed values without animation and transition rules.
|
||||
fn get_base_style(
|
||||
&self,
|
||||
context: &mut StyleContext<Self>,
|
||||
style: &Arc<ComputedValues>,
|
||||
) -> Arc<ComputedValues> {
|
||||
use style_resolver::StyleResolverForElement;
|
||||
|
||||
let rule_node = style.rules.as_ref().unwrap();
|
||||
let without_animation_rules =
|
||||
context.shared.stylist.rule_tree().remove_animation_rules(rule_node);
|
||||
if without_animation_rules == *rule_node {
|
||||
// Note that unwrapping here is fine, because the style is only
|
||||
// incomplete during the styling process.
|
||||
return style.clone();
|
||||
}
|
||||
|
||||
// This currently ignores visited styles, which seems acceptable,
|
||||
// as existing browsers don't appear to animate visited styles.
|
||||
let inputs =
|
||||
CascadeInputs {
|
||||
rules: Some(without_animation_rules),
|
||||
visited_rules: None,
|
||||
};
|
||||
|
||||
let style =
|
||||
StyleResolverForElement::new(*self, context, RuleInclusion::All)
|
||||
.cascade_style_and_visited_with_default_parents(inputs);
|
||||
style
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: TElement> MatchMethods for E {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue