Bug 1341372 - Part 4: Let get_after_change_style return Option.

It is possible to call get_after_change_style if there is no transition
rule. In order to avoid cloning the token computed values, we just return None.
The caller can use this Option to know which computed values should be
used.

MozReview-Commit-ID: 7fcgSVEtXWh
This commit is contained in:
Boris Chiou 2017-04-04 18:45:11 +08:00
parent 145e1b6bff
commit c88ca7dcd0

View file

@ -496,32 +496,34 @@ trait PrivateMatchMethods: TElement {
} }
} }
/// get_after_change_style removes the transition rules from the ComputedValues.
/// If there is no transition rule in the ComputedValues, it returns None.
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn get_after_change_style(&self, fn get_after_change_style(&self,
context: &mut StyleContext<Self>, context: &mut StyleContext<Self>,
primary_style: &ComputedStyle, primary_style: &ComputedStyle,
pseudo_style: &Option<(&PseudoElement, &ComputedStyle)>) pseudo_style: &Option<(&PseudoElement, &ComputedStyle)>)
-> Arc<ComputedValues> { -> Option<Arc<ComputedValues>> {
let style = &pseudo_style.as_ref().map_or(primary_style, |p| &*p.1); let style = &pseudo_style.as_ref().map_or(primary_style, |p| &*p.1);
let rule_node = &style.rules; let rule_node = &style.rules;
let without_transition_rules = let without_transition_rules =
context.shared.stylist.rule_tree.remove_transition_rule_if_applicable(rule_node); context.shared.stylist.rule_tree.remove_transition_rule_if_applicable(rule_node);
if without_transition_rules == *rule_node { if without_transition_rules == *rule_node {
// Note that unwrapping here is fine, because the style is // We don't have transition rule in this case, so return None to let the caller
// only incomplete during the styling process. // use the original ComputedValues.
return style.values.as_ref().unwrap().clone(); return None;
} }
let mut cascade_flags = CascadeFlags::empty(); let mut cascade_flags = CascadeFlags::empty();
if self.skip_root_and_item_based_display_fixup() { if self.skip_root_and_item_based_display_fixup() {
cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP) cascade_flags.insert(SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP);
} }
self.cascade_with_rules(context.shared, Some(self.cascade_with_rules(context.shared,
&context.thread_local.font_metrics_provider, &context.thread_local.font_metrics_provider,
&without_transition_rules, &without_transition_rules,
primary_style, primary_style,
cascade_flags, cascade_flags,
pseudo_style.is_some()) pseudo_style.is_some()))
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]