diff options
author | Manish Goregaokar <manishearth@gmail.com> | 2017-01-09 16:05:18 -0800 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2017-01-13 14:22:16 -0800 |
commit | 05728839f1bf64c4e5afbea2bba32347abd22c8f (patch) | |
tree | 290b016bed83ac79f3d9a0e1d6081bd36d4299d0 | |
parent | 296b468801195c359b768fb7ed7f903c6cc6409e (diff) | |
download | servo-05728839f1bf64c4e5afbea2bba32347abd22c8f.tar.gz servo-05728839f1bf64c4e5afbea2bba32347abd22c8f.zip |
stylo: Hook property parsing into Gecko prefs
MozReview-Commit-ID: 7evWOUFwa3K
-rw-r--r-- | components/style/gecko_bindings/bindings.rs | 3 | ||||
-rw-r--r-- | components/style/properties/properties.mako.rs | 94 |
2 files changed, 73 insertions, 24 deletions
diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index b5c454db594..2f8a6aa9c34 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -757,6 +757,9 @@ extern "C" { *mut nsCSSValueSharedList); } extern "C" { + pub fn Gecko_PropertyId_IsPrefEnabled(id: nsCSSPropertyID) -> bool; +} +extern "C" { pub fn Gecko_Construct_Default_nsStyleFont(ptr: *mut nsStyleFont, pres_context: RawGeckoPresContextBorrowed); diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 66cd5d3ae56..3661d03a39c 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -24,7 +24,8 @@ use error_reporting::ParseErrorReporter; use euclid::size::Size2D; use computed_values; use font_metrics::FontMetricsProvider; -#[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSPropertyID; +#[cfg(feature = "gecko")] use gecko_bindings::bindings; +#[cfg(feature = "gecko")] use gecko_bindings::structs::{self, nsCSSPropertyID}; #[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide}; use logical_geometry::WritingMode; use parser::{Parse, ParserContext, ParserContextExtraData}; @@ -734,7 +735,16 @@ enum StaticId { Shorthand(ShorthandId), } include!(concat!(env!("OUT_DIR"), "/static_ids.rs")); - +<% + def alias_to_nscsspropertyid(alias): + if alias == "word-wrap": + return "nsCSSPropertyID_eCSSPropertyAlias_WordWrap" + return "nsCSSPropertyID::eCSSPropertyAlias_%s" % to_camel_case(alias) + def to_nscsspropertyid(ident): + if ident == "float": + ident = "float_" + return "nsCSSPropertyID::eCSSProperty_%s" % ident +%> impl PropertyId { /// Returns a given property from the string `s`. /// @@ -757,16 +767,6 @@ impl PropertyId { #[allow(non_upper_case_globals)] pub fn from_nscsspropertyid(id: nsCSSPropertyID) -> Result<Self, ()> { use gecko_bindings::structs::*; - <% - def alias_to_nscsspropertyid(alias): - if alias == "word-wrap": - return "nsCSSPropertyID_eCSSPropertyAlias_WordWrap" - return "nsCSSPropertyID::eCSSPropertyAlias_%s" % to_camel_case(alias) - def to_nscsspropertyid(ident): - if ident == "float": - ident = "float_" - return "nsCSSPropertyID::eCSSProperty_%s" % ident - %> match id { % for property in data.longhands: ${to_nscsspropertyid(property.ident)} => { @@ -792,6 +792,31 @@ impl PropertyId { } } + /// Returns a property id from Gecko's nsCSSPropertyID. + #[cfg(feature = "gecko")] + #[allow(non_upper_case_globals)] + pub fn to_nscsspropertyid(&self) -> Result<nsCSSPropertyID, ()> { + use gecko_bindings::structs::*; + + match *self { + PropertyId::Longhand(id) => match id { + % for property in data.longhands: + LonghandId::${property.camel_case} => { + Ok(${to_nscsspropertyid(property.ident)}) + } + % endfor + }, + PropertyId::Shorthand(id) => match id { + % for property in data.shorthands: + ShorthandId::${property.camel_case} => { + Ok(${to_nscsspropertyid(property.ident)}) + } + % endfor + }, + _ => Err(()) + } + } + /// Given this property id, get it either as a shorthand or as a /// `PropertyDeclarationId`. pub fn as_shorthand(&self) -> Result<ShorthandId, PropertyDeclarationId> { @@ -876,6 +901,33 @@ impl ToCss for PropertyDeclaration { } } +<%def name="property_pref_check(property)"> + % if property.experimental and product == "servo": + if !PREFS.get("${property.experimental}") + .as_boolean().unwrap_or(false) { + return PropertyDeclarationParseResult::ExperimentalProperty + } + % endif + % if product == "gecko": + <% + # gecko can't use the identifier `float` + # and instead uses `float_` + # XXXManishearth make this an attr on the property + # itself? + pref_ident = property.ident + if pref_ident == "float": + pref_ident = "float_" + %> + if structs::root::mozilla::SERVO_PREF_ENABLED_${pref_ident} { + let id = structs::${to_nscsspropertyid(property.ident)}; + let enabled = unsafe { bindings::Gecko_PropertyId_IsPrefEnabled(id) }; + if !enabled { + return PropertyDeclarationParseResult::ExperimentalProperty + } + } + % endif +</%def> + impl PropertyDeclaration { /// Given a property declaration, return the property declaration id. pub fn id(&self) -> PropertyDeclarationId { @@ -978,12 +1030,9 @@ impl PropertyDeclaration { return PropertyDeclarationParseResult::UnknownProperty } % endif - % if property.experimental and product == "servo": - if !PREFS.get("${property.experimental}") - .as_boolean().unwrap_or(false) { - return PropertyDeclarationParseResult::ExperimentalProperty - } - % endif + + ${property_pref_check(property)} + match longhands::${property.ident}::parse_declared(context, input) { Ok(value) => { result_list.push(PropertyDeclaration::${property.camel_case}(value)); @@ -1010,12 +1059,9 @@ impl PropertyDeclaration { return PropertyDeclarationParseResult::UnknownProperty } % endif - % if shorthand.experimental and product == "servo": - if !PREFS.get("${shorthand.experimental}") - .as_boolean().unwrap_or(false) { - return PropertyDeclarationParseResult::ExperimentalProperty - } - % endif + + ${property_pref_check(shorthand)} + match input.try(|i| CSSWideKeyword::parse(context, i)) { Ok(CSSWideKeyword::InheritKeyword) => { % for sub_property in shorthand.sub_properties: |