Bug 1368610 - Part 2: Implements bit as gecko keyword properties. r?hiro draft
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Tue, 06 Jun 2017 16:54:05 +0900
changeset 589458 58c17cfe7265c21a63508359689e2d4946b35bc0
parent 589457 174ea52569d7b5ad0ef2ddbfcb92ad4858865005
child 589459 128ad73101633be7595410a08a32f05a11265ab5
push id62388
push userbmo:dakatsuka@mozilla.com
push dateTue, 06 Jun 2017 08:14:04 +0000
reviewershiro
bugs1368610
milestone55.0a1
Bug 1368610 - Part 2: Implements bit as gecko keyword properties. r?hiro In this patch. implements following properties. * font_variant_ligatures * font_variant_east_asian * font_variant_numeric Those properties are reprensented by bits in Gecko as keyword. MozReview-Commit-ID: HcjSkRcGlAs
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/longhand/font.mako.rs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -652,26 +652,31 @@ impl Debug for ${style_struct.gecko_stru
 %else:
 impl Debug for ${style_struct.gecko_struct_name} {
     // FIXME(bholley): Generate this.
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.gecko.fmt(f) }
 }
 %endif
 </%def>
 
-<%def name="impl_bitsflags(ident)">
+<%def name="impl_bitsflags(ident, gecko_ffi_name=None)">
+    <%
+    if gecko_ffi_name is None:
+        gecko_ffi_name = "m" + to_camel_case(ident)
+    %>
+
     pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
-        self.gecko.m${to_camel_case(ident)} = v.bits()
-    }
-
-    <% impl_simple_copy(ident, "m" + to_camel_case(ident)) %>
+        self.gecko.${gecko_ffi_name} = v.bits()
+    }
+
+    <% impl_simple_copy(ident, gecko_ffi_name) %>
 
     pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T {
-        longhands::${ident}::computed_value::T::from_bits(self.gecko.m${to_camel_case(ident)})
-                                                          .expect("m${to_camel_case(ident)} contains valid flags")
+        longhands::${ident}::computed_value::T::from_bits(self.gecko.${gecko_ffi_name})
+                                                          .expect("${gecko_ffi_name} contains valid flags")
     }
 </%def>
 
 <%def name="raw_impl_trait(style_struct, skip_longhands='', skip_additionals='')">
 <%
     longhands = [x for x in style_struct.longhands
                 if not (skip_longhands == "*" or x.name in skip_longhands.split())]
 
@@ -1844,33 +1849,19 @@ fn static_assert() {
 
     #[allow(non_snake_case)]
     pub fn copy_font_variant_alternates_from(&mut self, other: &Self) {
         self.gecko.mFont.variantAlternates = other.gecko.mFont.variantAlternates;
         // FIXME: Copy alternateValues as well.
         // self.gecko.mFont.alternateValues = other.gecko.mFont.alternateValues;
     }
 
-    pub fn set_font_variant_ligatures(&mut self, v: longhands::font_variant_ligatures::computed_value::T) {
-        self.gecko.mFont.variantLigatures = v.to_gecko_keyword()
-    }
-
-    ${impl_simple_copy('font_variant_ligatures', 'mFont.variantLigatures')}
-
-    pub fn set_font_variant_east_asian(&mut self, v: longhands::font_variant_east_asian::computed_value::T) {
-        self.gecko.mFont.variantEastAsian = v.to_gecko_keyword()
-    }
-
-    ${impl_simple_copy('font_variant_east_asian', 'mFont.variantEastAsian')}
-
-    pub fn set_font_variant_numeric(&mut self, v: longhands::font_variant_numeric::computed_value::T) {
-        self.gecko.mFont.variantNumeric = v.to_gecko_keyword()
-    }
-
-    ${impl_simple_copy('font_variant_numeric', 'mFont.variantNumeric')}
+    ${impl_bitsflags('font_variant_ligatures', 'mFont.variantLigatures')}
+    ${impl_bitsflags('font_variant_east_asian', 'mFont.variantEastAsian')}
+    ${impl_bitsflags('font_variant_numeric', 'mFont.variantNumeric')}
 
     #[allow(non_snake_case)]
     pub fn set__moz_min_font_size_ratio(&mut self, v: longhands::_moz_min_font_size_ratio::computed_value::T) {
         let percentage = if v.0 > 255. {
             255.
         } else if v.0 < 0. {
             0.
         } else {
--- a/servo/components/style/properties/longhand/font.mako.rs
+++ b/servo/components/style/properties/longhand/font.mako.rs
@@ -11,16 +11,31 @@
 <%def name="nongecko_unreachable()">
     %if product == "gecko":
         ${caller.body()}
     %else:
         unreachable!()
     %endif
 </%def>
 
+#[cfg(feature = "gecko")]
+macro_rules! impl_gecko_keyword_bitsflags {
+    ($name: ident, $type: ty) => {
+        impl ::style_traits::GeckoBitsFlags<$name, $type> for $name {
+            fn bits(&self) -> $type {
+                self.to_gecko_keyword()
+            }
+
+            fn from_bits(bits: $type) -> Option<$name> {
+                Some($name::from_gecko_keyword(bits))
+            }
+        }
+    };
+}
+
 // Define ToComputedValue, ToCss, and other boilerplate for a specified value
 // which is of the form `enum SpecifiedValue {Value(..), System(SystemFont)}`
 <%def name="simple_system_boilerplate(name)">
     impl ToCss for SpecifiedValue {
         fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
             match *self {
                 SpecifiedValue::Value(ref v) => v.to_css(dest),
                 SpecifiedValue::System(_) => Ok(())
@@ -1328,17 +1343,17 @@ macro_rules! exclusive_value {
         if $value.intersects($set) {
             return Err(())
         } else {
             $ident
         }
     }
 }
 
-<%helpers:longhand name="font-variant-east-asian" products="gecko" animation_value_type="none"
+<%helpers:longhand name="font-variant-east-asian" products="gecko" animation_value_type="discrete"
                    spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-east-asian">
     use properties::longhands::system_font::SystemFont;
     use std::fmt;
     use style_traits::ToCss;
 
     no_viewport_percentage!(SpecifiedValue);
 
     bitflags! {
@@ -1466,19 +1481,22 @@ macro_rules! exclusive_value {
         }
 
         if !result.is_empty() {
             Ok(SpecifiedValue::Value(result))
         } else {
             Err(())
         }
     }
+
+    #[cfg(feature = "gecko")]
+    impl_gecko_keyword_bitsflags!(VariantEastAsian, u16);
 </%helpers:longhand>
 
-<%helpers:longhand name="font-variant-ligatures" products="gecko" animation_value_type="none"
+<%helpers:longhand name="font-variant-ligatures" products="gecko" animation_value_type="discrete"
                    spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-ligatures">
     use properties::longhands::system_font::SystemFont;
     use std::fmt;
     use style_traits::ToCss;
 
     no_viewport_percentage!(SpecifiedValue);
 
     bitflags! {
@@ -1616,19 +1634,22 @@ macro_rules! exclusive_value {
         }
 
         if !result.is_empty() {
             Ok(SpecifiedValue::Value(result))
         } else {
             Err(())
         }
     }
+
+    #[cfg(feature = "gecko")]
+    impl_gecko_keyword_bitsflags!(VariantLigatures, u16);
 </%helpers:longhand>
 
-<%helpers:longhand name="font-variant-numeric" products="gecko" animation_value_type="none"
+<%helpers:longhand name="font-variant-numeric" products="gecko" animation_value_type="discrete"
                    spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-numeric">
     use properties::longhands::system_font::SystemFont;
     use std::fmt;
     use style_traits::ToCss;
 
     no_viewport_percentage!(SpecifiedValue);
 
     bitflags! {
@@ -1759,16 +1780,19 @@ macro_rules! exclusive_value {
         }
 
         if !result.is_empty() {
             Ok(SpecifiedValue::Value(result))
         } else {
             Err(())
         }
     }
+
+    #[cfg(feature = "gecko")]
+    impl_gecko_keyword_bitsflags!(VariantNumeric, u8);
 </%helpers:longhand>
 
 ${helpers.single_keyword_system("font-variant-position",
                                 "normal sub super",
                                 products="gecko",
                                 gecko_ffi_name="mFont.variantPosition",
                                 gecko_constant_prefix="NS_FONT_VARIANT_POSITION",
                                 spec="https://drafts.csswg.org/css-fonts/#propdef-font-variant-position",