From f358ec069cc0e6641fb3d7dca945c6532d8e9295 Mon Sep 17 00:00:00 2001 From: Daisuke Akatsuka Date: Fri, 9 Jun 2017 18:33:27 +0900 Subject: [PATCH] Implements gecko keyword bit type properties animatable --- components/style/properties/gecko.mako.rs | 33 +++++++------------ .../style/properties/longhand/font.mako.rs | 32 ++++++++++++++++-- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index d0a22b2b78c..5311f79f71f 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -680,17 +680,22 @@ impl Debug for ${style_struct.gecko_struct_name} { %endif -<%def name="impl_simple_type_with_conversion(ident)"> +<%def name="impl_simple_type_with_conversion(ident, gecko_ffi_name=None)"> + <% + if gecko_ffi_name is None: + gecko_ffi_name = "m" + to_camel_case(ident) + %> + #[allow(non_snake_case)] pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { - self.gecko.m${to_camel_case(ident)} = From::from(v) + self.gecko.${gecko_ffi_name} = From::from(v) } - <% impl_simple_copy(ident, "m" + to_camel_case(ident)) %> + <% impl_simple_copy(ident, gecko_ffi_name) %> #[allow(non_snake_case)] pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - From::from(self.gecko.m${to_camel_case(ident)}) + From::from(self.gecko.${gecko_ffi_name}) } @@ -1851,23 +1856,9 @@ fn static_assert() { // 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_simple_type_with_conversion("font_variant_ligatures", "mFont.variantLigatures")} + ${impl_simple_type_with_conversion("font_variant_east_asian", "mFont.variantEastAsian")} + ${impl_simple_type_with_conversion("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) { diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 825577b1e60..3ba7576fe37 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -16,6 +16,23 @@ %endif +#[cfg(feature = "gecko")] +macro_rules! impl_gecko_keyword_from_trait { + ($name: ident, $utype: ty) => { + impl From<$utype> for $name { + fn from(bits: $utype) -> $name { + $name::from_gecko_keyword(bits) + } + } + + impl From<$name> for $utype { + fn from(v: $name) -> $utype { + v.to_gecko_keyword() + } + } + }; +} + // 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)"> @@ -1362,7 +1379,7 @@ macro_rules! exclusive_value { } } -<%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; @@ -1500,9 +1517,12 @@ macro_rules! exclusive_value { Err(()) } } + + #[cfg(feature = "gecko")] + impl_gecko_keyword_from_trait!(VariantEastAsian, u16); -<%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; @@ -1650,9 +1670,12 @@ macro_rules! exclusive_value { Err(()) } } + + #[cfg(feature = "gecko")] + impl_gecko_keyword_from_trait!(VariantLigatures, u16); -<%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; @@ -1793,6 +1816,9 @@ macro_rules! exclusive_value { Err(()) } } + + #[cfg(feature = "gecko")] + impl_gecko_keyword_from_trait!(VariantNumeric, u8); ${helpers.single_keyword_system("font-variant-position",