diff --git a/components/style/matching.rs b/components/style/matching.rs index cb9295c47af..c3c5e37c165 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -394,51 +394,55 @@ trait PrivateMatchMethods: TElement { match difference.change { StyleChange::Unchanged => ChildCascadeRequirement::CanSkipCascade, StyleChange::Changed { reset_only } => { - if reset_only { - let old_display = old_values.get_box().clone_display(); - let new_display = new_values.get_box().clone_display(); - - if old_display.is_item_container() != new_display.is_item_container() { - // Blockification of children may depend on our display - // value, so we need to actually do the recascade. - return ChildCascadeRequirement::MustCascadeChildren - } - - #[cfg(feature = "gecko")] - { - use values::specified::align; - - // Children with justify-items: legacy may depend on our - // property value. - // - // TODO(emilio): We could special-case this even more - // creating a new `ChildCascadeRequirement` variant, but - // it's unclear it matters. - let old_justify_items = - old_values.get_position().clone_justify_items(); - let new_justify_items = - new_values.get_position().clone_justify_items(); - - let was_legacy_justify_items = - old_justify_items.computed.0.contains(align::ALIGN_LEGACY); - - let is_legacy_justify_items = - new_justify_items.computed.0.contains(align::ALIGN_LEGACY); - - if is_legacy_justify_items != was_legacy_justify_items { - return ChildCascadeRequirement::MustCascadeChildren; - } - - if was_legacy_justify_items && - old_justify_items.computed != new_justify_items.computed { - return ChildCascadeRequirement::MustCascadeChildren; - } - } - - ChildCascadeRequirement::MustCascadeChildrenIfInheritResetStyle - } else { - ChildCascadeRequirement::MustCascadeChildren + // If inherited properties changed, the best we can do is + // cascade the children. + if !reset_only { + return ChildCascadeRequirement::MustCascadeChildren } + + let old_display = old_values.get_box().clone_display(); + let new_display = new_values.get_box().clone_display(); + + // Blockification of children may depend on our display value, + // so we need to actually do the recascade. We could potentially + // do better, but it doesn't seem worth it. + if old_display.is_item_container() != new_display.is_item_container() { + return ChildCascadeRequirement::MustCascadeChildren + } + + // Children with justify-items: auto may depend on our + // justify-items property value. + // + // Similarly, we could potentially do better, but this really + // seems not common enough to care about. + #[cfg(feature = "gecko")] + { + use values::specified::align; + + let old_justify_items = + old_values.get_position().clone_justify_items(); + let new_justify_items = + new_values.get_position().clone_justify_items(); + + let was_legacy_justify_items = + old_justify_items.computed.0.contains(align::ALIGN_LEGACY); + + let is_legacy_justify_items = + new_justify_items.computed.0.contains(align::ALIGN_LEGACY); + + if is_legacy_justify_items != was_legacy_justify_items { + return ChildCascadeRequirement::MustCascadeChildren; + } + + if was_legacy_justify_items && + old_justify_items.computed != new_justify_items.computed { + return ChildCascadeRequirement::MustCascadeChildren; + } + } + + // We could prove that, if our children don't inherit reset + // properties, we can stop the cascade. + ChildCascadeRequirement::MustCascadeChildrenIfInheritResetStyle } } } diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 9e0a0e9b409..c2044c143b5 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -50,9 +50,11 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// Apply the blockification rules based on the table in CSS 2.2 section 9.7. /// https://drafts.csswg.org/css2/visuren.html#dis-pos-flo - fn blockify_if_necessary(&mut self, - layout_parent_style: &ComputedValues, - flags: CascadeFlags) { + fn blockify_if_necessary( + &mut self, + layout_parent_style: &ComputedValues, + flags: CascadeFlags, + ) { let mut blockify = false; macro_rules! blockify_if { ($if_what:expr) => { @@ -80,8 +82,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { let blockified_display = display.equivalent_block_display(flags.contains(IS_ROOT_ELEMENT)); if display != blockified_display { - self.style.mutate_box().set_adjusted_display(blockified_display, - is_item_or_root); + self.style.mutate_box().set_adjusted_display( + blockified_display, + is_item_or_root, + ); } } @@ -165,10 +169,14 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// /// https://lists.w3.org/Archives/Public/www-style/2017Mar/0045.html /// https://github.com/servo/servo/issues/15754 - fn adjust_for_writing_mode(&mut self, - layout_parent_style: &ComputedValues) { - let our_writing_mode = self.style.get_inheritedbox().clone_writing_mode(); - let parent_writing_mode = layout_parent_style.get_inheritedbox().clone_writing_mode(); + fn adjust_for_writing_mode( + &mut self, + layout_parent_style: &ComputedValues, + ) { + let our_writing_mode = + self.style.get_inheritedbox().clone_writing_mode(); + let parent_writing_mode = + layout_parent_style.get_inheritedbox().clone_writing_mode(); if our_writing_mode != parent_writing_mode && self.style.get_box().clone_display() == display::inline { @@ -324,9 +332,11 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// If a