Bug 1368610 - Part 2: Implements gecko keyword bit type properties animatable. r?hiro
In this patch. implements following properties.
* font_variant_ligatures
* font_variant_east_asian
* font_variant_numeric
Those properties are reprensented by bit in Gecko as keyword.
MozReview-Commit-ID: HcjSkRcGlAs
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -675,27 +675,32 @@ 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_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)
- }
-
- <% impl_simple_copy(ident, "m" + to_camel_case(ident)) %>
+ self.gecko.${gecko_ffi_name} = From::from(v)
+ }
+
+ <% 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})
}
</%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())]
@@ -1845,33 +1850,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_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) {
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,33 @@
<%def name="nongecko_unreachable()">
%if product == "gecko":
${caller.body()}
%else:
unreachable!()
%endif
</%def>
+#[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)">
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(())
@@ -1357,17 +1374,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! {
@@ -1495,19 +1512,22 @@ macro_rules! exclusive_value {
}
if !result.is_empty() {
Ok(SpecifiedValue::Value(result))
} else {
Err(())
}
}
+
+ #[cfg(feature = "gecko")]
+ impl_gecko_keyword_from_trait!(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! {
@@ -1645,19 +1665,22 @@ macro_rules! exclusive_value {
}
if !result.is_empty() {
Ok(SpecifiedValue::Value(result))
} else {
Err(())
}
}
+
+ #[cfg(feature = "gecko")]
+ impl_gecko_keyword_from_trait!(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! {
@@ -1788,16 +1811,19 @@ macro_rules! exclusive_value {
}
if !result.is_empty() {
Ok(SpecifiedValue::Value(result))
} else {
Err(())
}
}
+
+ #[cfg(feature = "gecko")]
+ impl_gecko_keyword_from_trait!(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",