diff options
-rw-r--r-- | ports/geckolib/bindings.rs | 2 | ||||
-rw-r--r-- | ports/geckolib/glue.rs | 10 | ||||
-rw-r--r-- | 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 bbf332a3415..846944920e8 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, nslen: u32, 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 @@ -343,6 +343,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<ServoComputedValues, GeckoComputedValues>; + 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<ServoComputedValues, GeckoComputedValues>; unsafe { Helpers::addref(ptr) }; 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<Self>) -> Arc<Self> { + 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 } |