From 22cf429c35b1aea9096775a34cdb04bfbaf57b41 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Mon, 9 Apr 2018 19:10:44 +1000 Subject: [PATCH] Use Servo code to check whether a property is inherited. --- .../style/properties/properties.mako.rs | 3 ++- ports/geckolib/glue.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 8c2376ecf85..39e9b25fa1f 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -826,7 +826,8 @@ impl LonghandId { } } - fn inherited(&self) -> bool { + /// Returns whether the longhand property is inherited by default. + pub fn inherited(&self) -> bool { ${static_longhand_id_set("INHERITED", lambda p: p.style_struct.inherited)} INHERITED.contains(*self) } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 41905bfe55e..26cf67dc3a8 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -952,6 +952,25 @@ pub unsafe extern "C" fn Servo_Property_IsShorthand( prop_id.is_shorthand() } +#[no_mangle] +pub unsafe extern "C" fn Servo_Property_IsInherited( + prop_name: *const nsACString, +) -> bool { + let prop_name = prop_name.as_ref().unwrap().as_str_unchecked(); + let prop_id = match PropertyId::parse(prop_name) { + Ok(id) => id, + Err(_) => return false, + }; + let longhand_id = match prop_id { + PropertyId::Custom(_) => return true, + PropertyId::Longhand(id) | + PropertyId::LonghandAlias(id, _) => id, + PropertyId::Shorthand(id) | + PropertyId::ShorthandAlias(id, _) => id.longhands().next().unwrap(), + }; + longhand_id.inherited() +} + #[no_mangle] pub extern "C" fn Servo_Property_IsAnimatable(property: nsCSSPropertyID) -> bool { use style::properties::animated_properties;