diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 4e3a79f5e77f..17c10809afc2 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -605,8 +605,8 @@ impl AnimationValue { CSSWideKeyword::Unset | % endif CSSWideKeyword::Inherit => { - let inherit_struct = context.inherited_style() - .get_${prop.style_struct.name_lower}(); + let inherit_struct = context.builder + .get_parent_${prop.style_struct.name_lower}(); inherit_struct.clone_${prop.ident}() }, }; diff --git a/components/style/properties/longhand/color.mako.rs b/components/style/properties/longhand/color.mako.rs index d1fb54292619..9ac3bbfcfbc6 100644 --- a/components/style/properties/longhand/color.mako.rs +++ b/components/style/properties/longhand/color.mako.rs @@ -22,7 +22,7 @@ #[inline] fn to_computed_value(&self, context: &Context) -> computed_value::T { self.0.to_computed_value(context) - .to_rgba(context.inherited_style().get_color().clone_color()) + .to_rgba(context.builder.get_parent_color().clone_color()) } #[inline] diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index ca8d227537c3..f6b78a917498 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -548,9 +548,9 @@ ${helpers.single_keyword_system("font-variant-caps", SpecifiedValue::Normal => computed_value::T::normal(), SpecifiedValue::Bold => computed_value::T::bold(), SpecifiedValue::Bolder => - context.inherited_style().get_font().clone_font_weight().bolder(), + context.builder.get_parent_font().clone_font_weight().bolder(), SpecifiedValue::Lighter => - context.inherited_style().get_font().clone_font_weight().lighter(), + context.builder.get_parent_font().clone_font_weight().lighter(), SpecifiedValue::System(_) => { <%self:nongecko_unreachable> context.cached_system_font.as_ref().unwrap().font_weight.clone() @@ -940,7 +940,7 @@ ${helpers.single_keyword_system("font-variant-caps", // recomputed from the base size for the keyword and the relative size. // // See bug 1355707 - if let Some((kw, fraction)) = context.builder.inherited_style().font_computation_data.font_size_keyword { + if let Some((kw, fraction)) = context.builder.inherited_font_computation_data().font_size_keyword { context.builder.font_size_keyword = Some((kw, fraction * ratio)); } else { context.builder.font_size_keyword = None; @@ -956,9 +956,9 @@ ${helpers.single_keyword_system("font-variant-caps", // if the language or generic changed, we need to recalculate // the font size from the stored font-size origin information. if context.builder.get_font().gecko().mLanguage.raw::() != - context.builder.inherited_style().get_font().gecko().mLanguage.raw::() || + context.builder.get_parent_font().gecko().mLanguage.raw::() || context.builder.get_font().gecko().mGenericID != - context.builder.inherited_style().get_font().gecko().mGenericID { + context.builder.get_parent_font().gecko().mGenericID { if let Some((kw, ratio)) = context.builder.font_size_keyword { computed = kw.to_computed_value(context).scale_by(ratio); } @@ -968,8 +968,7 @@ ${helpers.single_keyword_system("font-variant-caps", let device = context.builder.device; let mut font = context.builder.take_font(); let parent_unconstrained = { - let parent_style = context.builder.inherited_style(); - let parent_font = parent_style.get_font(); + let parent_font = context.builder.get_parent_font(); font.apply_font_size(computed, parent_font, device) }; context.builder.put_font(font); @@ -997,9 +996,8 @@ ${helpers.single_keyword_system("font-variant-caps", let device = context.builder.device; let mut font = context.builder.take_font(); let used_kw = { - let parent_style = context.builder.inherited_style(); - let parent_font = parent_style.get_font(); - parent_kw = parent_style.font_computation_data.font_size_keyword; + let parent_font = context.builder.get_parent_font(); + parent_kw = context.builder.inherited_font_computation_data().font_size_keyword; font.inherit_font_size_from(parent_font, kw_inherited_size, device) }; @@ -2279,8 +2277,8 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control- let int = match *self { SpecifiedValue::Auto => { - let parent = cx.inherited_style().get_font().clone__moz_script_level() as i32; - let display = cx.inherited_style().get_font().clone__moz_math_display(); + let parent = cx.builder.get_parent_font().clone__moz_script_level() as i32; + let display = cx.builder.get_parent_font().clone__moz_math_display(); if display == DisplayValue::inline { parent + 1 } else { @@ -2288,7 +2286,7 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control- } } SpecifiedValue::Relative(rel) => { - let parent = cx.inherited_style().get_font().clone__moz_script_level(); + let parent = cx.builder.get_parent_font().clone__moz_script_level(); parent as i32 + rel } SpecifiedValue::Absolute(abs) => abs, diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 80f0624d55fd..50df62db72a2 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -230,8 +230,8 @@ ${helpers.single_keyword("text-align-last", if context.is_root_element { return get_initial_value(); } - let parent = context.inherited_style().get_inheritedtext().clone_text_align(); - let ltr = context.inherited_style().writing_mode.is_bidi_ltr(); + let parent = context.builder.get_parent_inheritedtext().clone_text_align(); + let ltr = context.builder.inherited_writing_mode().is_bidi_ltr(); match (parent, ltr) { (computed_value::T::start, true) => computed_value::T::left, (computed_value::T::start, false) => computed_value::T::right, @@ -241,7 +241,7 @@ ${helpers.single_keyword("text-align-last", } } SpecifiedValue::MozCenterOrInherit => { - let parent = context.inherited_style().get_inheritedtext().clone_text_align(); + let parent = context.builder.get_parent_inheritedtext().clone_text_align(); if parent == computed_value::T::start { computed_value::T::center } else { @@ -340,7 +340,7 @@ ${helpers.predefined_type("word-spacing", overline: None, line_through: None, }, - _ => context.inherited_style().get_inheritedtext().clone__servo_text_decorations_in_effect() + _ => context.builder.get_parent_inheritedtext().clone__servo_text_decorations_in_effect() }; result.underline = maybe(context.style().get_text().has_underline() diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 712b2c644ac9..4a3508848bf8 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2655,11 +2655,6 @@ impl<'a> StyleBuilder<'a> { self.visited_style.is_some() } - /// Returns the style we're inheriting from. - pub fn inherited_style(&self) -> &'a ComputedValues { - self.inherited_style - } - /// Returns the style we're getting reset properties from. pub fn default_style(&self) -> &'a ComputedValues { self.reset_style @@ -2752,6 +2747,38 @@ impl<'a> StyleBuilder<'a> { fn custom_properties(&self) -> Option> { self.custom_properties.clone() } + + /// Access to various information about our inherited styles. We don't + /// expose an inherited ComputedValues directly, because in the + /// ::first-line case some of the inherited information needs to come from + /// one ComputedValues instance and some from a different one. + + /// Inherited font bits. + pub fn inherited_font_computation_data(&self) -> &FontComputationData { + &self.inherited_style.font_computation_data + } + + /// Inherited writing-mode. + pub fn inherited_writing_mode(&self) -> &WritingMode { + &self.inherited_style.writing_mode + } + + /// Inherited style flags. + pub fn inherited_flags(&self) -> &ComputedValueFlags { + &self.inherited_style.flags + } + + /// And access to inherited style structs. + % for style_struct in data.active_style_structs(): + /// Gets our inherited `${style_struct.name}`. We don't name these + /// accessors `inherited_${style_struct.name_lower}` because we already + /// have things like "box" vs "inherited_box" as struct names. Do the + /// next-best thing and call them `parent_${style_struct.name_lower}` + /// instead. + pub fn get_parent_${style_struct.name_lower}(&self) -> &style_structs::${style_struct.name} { + self.inherited_style.get_${style_struct.name_lower}() + } + % endfor } #[cfg(feature = "servo")] diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 8222634317e3..022e5e542641 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -446,7 +446,7 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { let relevant_link_visited = if flags.contains(IS_LINK) { flags.contains(IS_VISITED_LINK) } else { - self.style.inherited_style().flags.contains(IS_RELEVANT_LINK_VISITED) + self.style.inherited_flags().contains(IS_RELEVANT_LINK_VISITED) }; if relevant_link_visited { diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 6a82b8cf8bbf..8e01eda014c6 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -119,11 +119,6 @@ impl<'a> Context<'a> { self.builder.device.au_viewport_size() } - /// The style we're inheriting from. - pub fn inherited_style(&self) -> &ComputedValues { - self.builder.inherited_style() - } - /// The default computed style we're getting our reset style from. pub fn default_style(&self) -> &ComputedValues { self.builder.default_style() @@ -411,7 +406,7 @@ impl ToComputedValue for specified::JustifyItems { // If the inherited value of `justify-items` includes the `legacy` keyword, `auto` computes // to the inherited value. if self.0 == align::ALIGN_AUTO { - let inherited = context.inherited_style().get_position().clone_justify_items(); + let inherited = context.builder.get_parent_position().clone_justify_items(); if inherited.0.contains(align::ALIGN_LEGACY) { return inherited } diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index c3591bdf484a..bf4b83b52932 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -93,7 +93,7 @@ impl FontBaseSize { match *self { FontBaseSize::Custom(size) => size, FontBaseSize::CurrentStyle => context.style().get_font().clone_font_size(), - FontBaseSize::InheritedStyle => context.inherited_style().get_font().clone_font_size(), + FontBaseSize::InheritedStyle => context.style().get_parent_font().clone_font_size(), } } }