From 048044f98b42a84cbd8fec5be7df8517b2a7e895 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 26 Jul 2017 13:41:48 -0400 Subject: [PATCH] Make it possible to construct StyleBuilder with two different inherited styles. Part 3 of Gecko bug 1382806. r=emilio --- components/style/animation.rs | 1 + .../style/properties/properties.mako.rs | 36 ++++++++++++++++++- components/style/style_resolver.rs | 1 + components/style/stylist.rs | 4 +++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/components/style/animation.rs b/components/style/animation.rs index d90467c7eea..69b94edb580 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -499,6 +499,7 @@ fn compute_style_for_animation_step(context: &SharedStyleContext, iter, Some(previous_style), Some(previous_style), + Some(previous_style), /* cascade_info = */ None, /* visited_style = */ None, font_metrics_provider, diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 8b60ee246d1..41e9b3e00ac 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -14,6 +14,7 @@ use servo_arc::{Arc, UniqueArc}; use std::borrow::Cow; use std::collections::HashSet; use std::{fmt, mem, ops}; +#[cfg(feature = "gecko")] use std::ptr; use app_units::Au; #[cfg(feature = "servo")] use cssparser::RGBA; @@ -2512,6 +2513,7 @@ impl<'a> StyleBuilder<'a> { fn new( device: &'a Device, parent_style: Option<<&'a ComputedValues>, + parent_style_ignoring_first_line: Option<<&'a ComputedValues>, pseudo: Option<<&'a PseudoElement>, cascade_flags: CascadeFlags, rules: Option, @@ -2521,8 +2523,19 @@ impl<'a> StyleBuilder<'a> { flags: ComputedValueFlags, visited_style: Option>, ) -> Self { + debug_assert_eq!(parent_style.is_some(), parent_style_ignoring_first_line.is_some()); + #[cfg(feature = "gecko")] + debug_assert!(parent_style.is_none() || + ptr::eq(parent_style.unwrap(), + parent_style_ignoring_first_line.unwrap()) || + parent_style.unwrap().pseudo() == Some(PseudoElement::FirstLine)); let reset_style = device.default_computed_values(); let inherited_style = parent_style.unwrap_or(reset_style); + let inherited_style_ignoring_first_line = parent_style_ignoring_first_line.unwrap_or(reset_style); + // FIXME(bz): INHERIT_ALL seems like a fundamentally broken idea. I'm + // 99% sure it should give incorrect behavior for table anonymous box + // backgrounds, for example. This code doesn't attempt to make it play + // nice with inherited_style_ignoring_first_line. let reset_style = if cascade_flags.contains(INHERIT_ALL) { inherited_style } else { @@ -2533,7 +2546,7 @@ impl<'a> StyleBuilder<'a> { device, parent_style, inherited_style, - inherited_style_ignoring_first_line: inherited_style, + inherited_style_ignoring_first_line, reset_style, pseudo, rules, @@ -2562,10 +2575,14 @@ impl<'a> StyleBuilder<'a> { ) -> Self { let reset_style = device.default_computed_values(); let inherited_style = parent_style.unwrap_or(reset_style); + #[cfg(feature = "gecko")] + debug_assert!(parent_style.is_none() || + parent_style.unwrap().pseudo() != Some(PseudoElement::FirstLine)); StyleBuilder { device, parent_style, inherited_style, + // None of our callers pass in ::first-line parent styles. inherited_style_ignoring_first_line: inherited_style, reset_style, pseudo, @@ -2651,6 +2668,7 @@ impl<'a> StyleBuilder<'a> { Self::new( device, Some(parent), + Some(parent), pseudo, CascadeFlags::empty(), /* rules = */ None, @@ -2910,6 +2928,7 @@ pub fn cascade( rule_node: &StrongRuleNode, guards: &StylesheetGuards, parent_style: Option<<&ComputedValues>, + parent_style_ignoring_first_line: Option<<&ComputedValues>, layout_parent_style: Option<<&ComputedValues>, visited_style: Option>, cascade_info: Option<<&mut CascadeInfo>, @@ -2917,6 +2936,12 @@ pub fn cascade( flags: CascadeFlags, quirks_mode: QuirksMode ) -> Arc { + debug_assert_eq!(parent_style.is_some(), parent_style_ignoring_first_line.is_some()); + #[cfg(feature = "gecko")] + debug_assert!(parent_style.is_none() || + ptr::eq(parent_style.unwrap(), + parent_style_ignoring_first_line.unwrap()) || + parent_style.unwrap().pseudo() == Some(PseudoElement::FirstLine)); let iter_declarations = || { rule_node.self_and_ancestors().flat_map(|node| { let cascade_level = node.cascade_level(); @@ -2962,6 +2987,7 @@ pub fn cascade( rule_node, iter_declarations, parent_style, + parent_style_ignoring_first_line, layout_parent_style, visited_style, cascade_info, @@ -2980,6 +3006,7 @@ pub fn apply_declarations<'a, F, I>( rules: &StrongRuleNode, iter_declarations: F, parent_style: Option<<&ComputedValues>, + parent_style_ignoring_first_line: Option<<&ComputedValues>, layout_parent_style: Option<<&ComputedValues>, visited_style: Option>, mut cascade_info: Option<<&mut CascadeInfo>, @@ -2992,6 +3019,12 @@ where I: Iterator, { debug_assert!(layout_parent_style.is_none() || parent_style.is_some()); + debug_assert_eq!(parent_style.is_some(), parent_style_ignoring_first_line.is_some()); + #[cfg(feature = "gecko")] + debug_assert!(parent_style.is_none() || + ptr::eq(parent_style.unwrap(), + parent_style_ignoring_first_line.unwrap()) || + parent_style.unwrap().pseudo() == Some(PseudoElement::FirstLine)); let (inherited_style, layout_parent_style) = match parent_style { Some(parent_style) => { (parent_style, @@ -3026,6 +3059,7 @@ where builder: StyleBuilder::new( device, parent_style, + parent_style_ignoring_first_line, pseudo, flags, Some(rules.clone()), diff --git a/components/style/style_resolver.rs b/components/style/style_resolver.rs index 71be0609a6e..cf512c4fbdd 100644 --- a/components/style/style_resolver.rs +++ b/components/style/style_resolver.rs @@ -479,6 +479,7 @@ where rules.unwrap_or(self.context.shared.stylist.rule_tree().root()), &self.context.shared.guards, parent_style, + parent_style, layout_parent_style, style_if_visited, Some(&mut cascade_info), diff --git a/components/style/stylist.rs b/components/style/stylist.rs index e5e61752be4..29633ae8509 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -637,6 +637,7 @@ impl Stylist { guards, parent, parent, + parent, None, None, font_metrics, @@ -753,6 +754,7 @@ impl Stylist { guards, Some(inherited_style), Some(inherited_style), + Some(inherited_style), None, None, font_metrics, @@ -778,6 +780,7 @@ impl Stylist { guards, Some(parent_style), Some(parent_style), + Some(parent_style), visited_values, None, font_metrics, @@ -1342,6 +1345,7 @@ impl Stylist { guards, Some(parent_style), Some(parent_style), + Some(parent_style), None, None, &metrics,