From 01c42693d425c2c779438f2a0f3bd419f948e4b7 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Fri, 6 May 2016 16:01:14 +1000 Subject: [PATCH] Add Servo_InheritComputedValues. --- ports/geckolib/bindings.rs | 2 ++ ports/geckolib/glue.rs | 10 ++++++++++ ports/geckolib/properties.mako.rs | 32 ++++++++++++++++++------------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ports/geckolib/bindings.rs b/ports/geckolib/bindings.rs index 618c049bafc..df04e0f0ccc 100644 --- a/ports/geckolib/bindings.rs +++ b/ports/geckolib/bindings.rs @@ -104,6 +104,8 @@ extern "C" { set: *mut RawServoStyleSet, is_probe: bool) -> *mut ServoComputedValues; + pub fn Servo_InheritComputedValues(parent_style: *mut ServoComputedValues) + -> *mut ServoComputedValues; pub fn Servo_AddRefComputedValues(arg1: *mut ServoComputedValues); pub fn Servo_ReleaseComputedValues(arg1: *mut ServoComputedValues); pub fn Gecko_GetAttrAsUTF8(element: *mut RawGeckoElement, ns: *const u8, diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index d0b75941bdd..fb8c99d597e 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -342,6 +342,16 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser } } +#[no_mangle] +pub extern "C" fn Servo_InheritComputedValues(parent_style: *mut ServoComputedValues) + -> *mut ServoComputedValues { + type Helpers = ArcHelpers; + Helpers::with(parent_style, |parent| { + let style = GeckoComputedValues::inherit_from(parent); + Helpers::from(style) + }) +} + #[no_mangle] pub extern "C" fn Servo_AddRefComputedValues(ptr: *mut ServoComputedValues) -> () { type Helpers = ArcHelpers; diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 24c111b114b..6db5fb6ef40 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -44,6 +44,24 @@ pub struct GeckoComputedValues { pub root_font_size: Au, } +impl GeckoComputedValues { + pub fn inherit_from(parent: &Arc) -> Arc { + Arc::new(GeckoComputedValues { + custom_properties: parent.custom_properties.clone(), + shareable: parent.shareable, + writing_mode: parent.writing_mode, + root_font_size: parent.root_font_size, + % for style_struct in data.style_structs: + % if style_struct.inherited: + ${style_struct.ident}: parent.${style_struct.ident}.clone(), + % else: + ${style_struct.ident}: Self::initial_values().${style_struct.ident}.clone(), + % endif + % endfor + }) + } +} + impl ComputedValues for GeckoComputedValues { % for style_struct in data.style_structs: type Concrete${style_struct.trait_name} = ${style_struct.gecko_struct_name}; @@ -76,19 +94,7 @@ impl ComputedValues for GeckoComputedValues { // Gecko expects text nodes to be styled as if they were elements that // matched no rules (that is, inherited style structs are inherited and // non-inherited style structs are set to their initial values). - Arc::new(GeckoComputedValues { - custom_properties: parent.custom_properties.clone(), - shareable: parent.shareable, - writing_mode: parent.writing_mode, - root_font_size: parent.root_font_size, - % for style_struct in data.style_structs: - % if style_struct.inherited: - ${style_struct.ident}: parent.${style_struct.ident}.clone(), - % else: - ${style_struct.ident}: Self::initial_values().${style_struct.ident}.clone(), - % endif - % endfor - }) + GeckoComputedValues::inherit_from(parent) } fn initial_values() -> &'static Self { &*INITIAL_GECKO_VALUES }