From 7fb470c373161b8f0dd4cd7d27141032e904df63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 2 Feb 2018 15:00:32 +0100 Subject: [PATCH] style: Remove some uses of StyleBuilder::for_derived_style. for_derived_style(default_values) is effectively for_inheritance(default_values). MozReview-Commit-ID: DfTeD49uTlp --- .../style/properties/properties.mako.rs | 12 ++++--- components/style/stylesheets/viewport_rule.rs | 2 +- components/style/values/computed/mod.rs | 2 +- ports/geckolib/glue.rs | 31 ++++++------------- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 73c0cd6498c..825a3c737cc 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2783,8 +2783,12 @@ impl<'a> StyleBuilder<'a> { self.flags.contains(ComputedValueFlags::IS_STYLE_IF_VISITED) } - /// Creates a StyleBuilder holding only references to the structs of `s`, in - /// order to create a derived style. + /// NOTE(emilio): This is done so we can compute relative units with respect + /// to the parent style, but all the early properties / writing-mode / etc + /// are already set to the right ones on the kid. + /// + /// Do _not_ actually call this to construct a style, this should mostly be + /// used for animations. pub fn for_derived_style( device: &'a Device, style_to_derive_from: &'a ComputedValues, @@ -2805,11 +2809,11 @@ impl<'a> StyleBuilder<'a> { reset_style, pseudo, modified_reset: false, - rules: None, // FIXME(emilio): Dubious... + rules: None, custom_properties: style_to_derive_from.custom_properties().cloned(), writing_mode: style_to_derive_from.writing_mode, flags: style_to_derive_from.flags, - visited_style: style_to_derive_from.clone_visited_style(), + visited_style: None, % for style_struct in data.active_style_structs(): ${style_struct.ident}: StyleStructRef::Borrowed( style_to_derive_from.${style_struct.name_lower}_arc() diff --git a/components/style/stylesheets/viewport_rule.rs b/components/style/stylesheets/viewport_rule.rs index e50d9f1720b..f4bb2fb39df 100644 --- a/components/style/stylesheets/viewport_rule.rs +++ b/components/style/stylesheets/viewport_rule.rs @@ -720,7 +720,7 @@ impl MaybeNew for ViewportConstraints { let mut conditions = RuleCacheConditions::default(); let context = Context { is_root_element: false, - builder: StyleBuilder::for_derived_style(device, default_values, None, None), + builder: StyleBuilder::for_inheritance(device, default_values, None), font_metrics_provider: &provider, cached_system_font: None, in_media_query: false, diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index f3f129fe8fa..5e1c519c7c4 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -179,7 +179,7 @@ impl<'a> Context<'a> { let context = Context { is_root_element: false, - builder: StyleBuilder::for_derived_style(device, default_values, None, None), + builder: StyleBuilder::for_inheritance(device, default_values, None), font_metrics_provider: &provider, cached_system_font: None, in_media_query: true, diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 518c5f46964..ba2614f7dcd 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -2318,30 +2318,19 @@ pub extern "C" fn Servo_ComputedValues_Inherit( let atom = Atom::from(pseudo_tag); let pseudo = PseudoElement::from_anon_box_atom(&atom) .expect("Not an anon-box? Gah!"); - let style = if let Some(reference) = parent_style_context { - let mut style = StyleBuilder::for_inheritance( - data.stylist.device(), - reference, - Some(&pseudo) - ); + let device = data.stylist.device(); - if for_text { - StyleAdjuster::new(&mut style) - .adjust_for_text(); - } + let mut style = StyleBuilder::for_inheritance( + data.stylist.device(), + parent_style_context.unwrap_or_else(|| device.default_computed_values()), + Some(&pseudo) + ); - style.build() - } else { - debug_assert!(!for_text); - StyleBuilder::for_derived_style( - data.stylist.device(), - data.default_computed_values(), - /* parent_style = */ None, - Some(&pseudo), - ).build() - }; + if for_text { + StyleAdjuster::new(&mut style).adjust_for_text(); + } - style.into() + style.build().into() } #[no_mangle]