From 21b7b256c2df54a5d357c930174f413e8202a443 Mon Sep 17 00:00:00 2001 From: Daisuke Akatsuka Date: Fri, 9 Jun 2017 18:32:48 +0900 Subject: [PATCH] Implements bitflags properties animatable --- components/style/properties/gecko.mako.rs | 95 ++++--------------- .../style/properties/longhand/box.mako.rs | 5 +- .../properties/longhand/position.mako.rs | 44 +++++++-- .../style/properties/longhand/text.mako.rs | 10 +- .../style/properties/properties.mako.rs | 17 ++++ components/style/values/specified/align.rs | 18 +++- 6 files changed, 97 insertions(+), 92 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 3905400ce8d..d0a22b2b78c 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -680,6 +680,20 @@ impl Debug for ${style_struct.gecko_struct_name} { %endif +<%def name="impl_simple_type_with_conversion(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)) %> + + #[allow(non_snake_case)] + pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { + From::from(self.gecko.m${to_camel_case(ident)}) + } + + <%def name="raw_impl_trait(style_struct, skip_longhands='', skip_additionals='')"> <% longhands = [x for x in style_struct.longhands @@ -1134,53 +1148,11 @@ fn static_assert() { } } - pub fn set_align_content(&mut self, v: longhands::align_content::computed_value::T) { - self.gecko.mAlignContent = v.bits() - } - - ${impl_simple_copy('align_content', 'mAlignContent')} - - pub fn set_justify_content(&mut self, v: longhands::justify_content::computed_value::T) { - self.gecko.mJustifyContent = v.bits() - } - - ${impl_simple_copy('justify_content', 'mJustifyContent')} - - pub fn set_align_self(&mut self, v: longhands::align_self::computed_value::T) { - self.gecko.mAlignSelf = v.0.bits() - } - - ${impl_simple_copy('align_self', 'mAlignSelf')} - - pub fn set_justify_self(&mut self, v: longhands::justify_self::computed_value::T) { - self.gecko.mJustifySelf = v.0.bits() - } - - ${impl_simple_copy('justify_self', 'mJustifySelf')} - - pub fn set_align_items(&mut self, v: longhands::align_items::computed_value::T) { - self.gecko.mAlignItems = v.0.bits() - } - - ${impl_simple_copy('align_items', 'mAlignItems')} - - pub fn clone_align_items(&self) -> longhands::align_items::computed_value::T { - use values::specified::align::{AlignFlags, AlignItems}; - AlignItems(AlignFlags::from_bits(self.gecko.mAlignItems) - .expect("mAlignItems contains valid flags")) - } - - pub fn set_justify_items(&mut self, v: longhands::justify_items::computed_value::T) { - self.gecko.mJustifyItems = v.0.bits() - } - - ${impl_simple_copy('justify_items', 'mJustifyItems')} - - pub fn clone_justify_items(&self) -> longhands::justify_items::computed_value::T { - use values::specified::align::{AlignFlags, JustifyItems}; - JustifyItems(AlignFlags::from_bits(self.gecko.mJustifyItems) - .expect("mJustifyItems contains valid flags")) - } + % for kind in ["align", "justify"]: + ${impl_simple_type_with_conversion(kind + "_content")} + ${impl_simple_type_with_conversion(kind + "_self")} + ${impl_simple_type_with_conversion(kind + "_items")} + % endfor pub fn set_order(&mut self, v: longhands::order::computed_value::T) { self.gecko.mOrder = v; @@ -2855,11 +2827,7 @@ fn static_assert() { ${impl_simple_copy("contain", "mContain")} - pub fn set_touch_action(&mut self, v: longhands::touch_action::computed_value::T) { - self.gecko.mTouchAction = v.bits(); - } - - ${impl_simple_copy("touch_action", "mTouchAction")} + ${impl_simple_type_with_conversion("touch_action")} <%def name="simple_image_array_property(name, shorthand, field_name)"> @@ -3843,28 +3811,7 @@ fn static_assert() { skip_longhands="text-decoration-line text-overflow initial-letter" skip_additionals="*"> - pub fn set_text_decoration_line(&mut self, v: longhands::text_decoration_line::computed_value::T) { - let mut bits: u8 = 0; - if v.contains(longhands::text_decoration_line::UNDERLINE) { - bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE as u8; - } - if v.contains(longhands::text_decoration_line::OVERLINE) { - bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_OVERLINE as u8; - } - if v.contains(longhands::text_decoration_line::LINE_THROUGH) { - bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH as u8; - } - if v.contains(longhands::text_decoration_line::BLINK) { - bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_BLINK as u8; - } - if v.contains(longhands::text_decoration_line::COLOR_OVERRIDE) { - bits |= structs::NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL as u8; - } - self.gecko.mTextDecorationLine = bits; - } - - ${impl_simple_copy('text_decoration_line', 'mTextDecorationLine')} - + ${impl_simple_type_with_conversion("text_decoration_line")} fn clear_overflow_sides_if_string(&mut self) { use gecko_bindings::structs::nsStyleTextOverflowSide; diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 03891fe3b54..a6fc0f66add 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -1925,7 +1925,7 @@ ${helpers.predefined_type("shape-outside", "basic_shape::FloatAreaShape", <%helpers:longhand name="touch-action" products="gecko" - animation_value_type="none" + animation_value_type="discrete" disable_when_testing="True" spec="https://compat.spec.whatwg.org/#touch-action"> use gecko_bindings::structs; @@ -1999,4 +1999,7 @@ ${helpers.predefined_type("shape-outside", "basic_shape::FloatAreaShape", _ => Err(()), } } + + #[cfg(feature = "gecko")] + impl_bitflags_conversions!(SpecifiedValue); diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index ebf4265cd0d..ac220446e64 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -24,6 +24,24 @@ animation_value_type="ComputedValue", logical=True)} % endfor +#[cfg(feature = "gecko")] +macro_rules! impl_align_conversions { + ($name: path) => { + impl From for $name { + fn from(bits: u8) -> $name { + $name(::values::specified::align::AlignFlags::from_bits(bits) + .expect("bits contain valid flag")) + } + } + + impl From<$name> for u8 { + fn from(v: $name) -> u8 { + v.0.bits() + } + } + }; +} + ${helpers.predefined_type("z-index", "IntegerOrAuto", "Either::Second(Auto)", spec="https://www.w3.org/TR/CSS2/visuren.html#z-index", @@ -48,14 +66,14 @@ ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse", ${helpers.single_keyword("justify-content", "flex-start stretch flex-end center space-between space-around", extra_prefixes="webkit", spec="https://drafts.csswg.org/css-align/#propdef-justify-content", - animation_value_type="none")} + animation_value_type="discrete")} % else: ${helpers.predefined_type(name="justify-content", type="AlignJustifyContent", initial_value="specified::AlignJustifyContent::normal()", spec="https://drafts.csswg.org/css-align/#propdef-justify-content", extra_prefixes="webkit", - animation_value_type="none")} + animation_value_type="discrete")} % endif % if product == "servo": @@ -63,7 +81,7 @@ ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse", ${helpers.single_keyword("align-content", "stretch flex-start flex-end center space-between space-around", extra_prefixes="webkit", spec="https://drafts.csswg.org/css-align/#propdef-align-content", - animation_value_type="none")} + animation_value_type="discrete")} ${helpers.single_keyword("align-items", "stretch flex-start flex-end center baseline", @@ -76,7 +94,7 @@ ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse", initial_value="specified::AlignJustifyContent::normal()", spec="https://drafts.csswg.org/css-align/#propdef-align-content", extra_prefixes="webkit", - animation_value_type="none")} + animation_value_type="discrete")} ${helpers.predefined_type(name="align-items", type="AlignItems", @@ -85,11 +103,17 @@ ${helpers.single_keyword("flex-wrap", "nowrap wrap wrap-reverse", extra_prefixes="webkit", animation_value_type="discrete")} + #[cfg(feature = "gecko")] + impl_align_conversions!(::values::specified::align::AlignItems); + ${helpers.predefined_type(name="justify-items", type="JustifyItems", initial_value="specified::JustifyItems::auto()", spec="https://drafts.csswg.org/css-align/#propdef-justify-items", - animation_value_type="none")} + animation_value_type="discrete")} + + #[cfg(feature = "gecko")] + impl_align_conversions!(::values::specified::align::JustifyItems); % endif // Flex item properties @@ -109,23 +133,25 @@ ${helpers.predefined_type("flex-shrink", "Number", % if product == "servo": // FIXME: Update Servo to support the same syntax as Gecko. ${helpers.single_keyword("align-self", "auto stretch flex-start flex-end center baseline", - need_clone=True, extra_prefixes="webkit", spec="https://drafts.csswg.org/css-flexbox/#propdef-align-self", - animation_value_type="none")} + animation_value_type="discrete")} % else: ${helpers.predefined_type(name="align-self", type="AlignJustifySelf", initial_value="specified::AlignJustifySelf::auto()", spec="https://drafts.csswg.org/css-align/#align-self-property", extra_prefixes="webkit", - animation_value_type="none")} + animation_value_type="discrete")} ${helpers.predefined_type(name="justify-self", type="AlignJustifySelf", initial_value="specified::AlignJustifySelf::auto()", spec="https://drafts.csswg.org/css-align/#justify-self-property", - animation_value_type="none")} + animation_value_type="discrete")} + + #[cfg(feature = "gecko")] + impl_align_conversions!(::values::specified::align::AlignJustifySelf); % endif // https://drafts.csswg.org/css-flexbox/#propdef-order diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index 08113b228f2..0e384c8d93a 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -156,10 +156,9 @@ ${helpers.single_keyword("unicode-bidi", animation_value_type="discrete", spec="https://drafts.csswg.org/css-writing-modes/#propdef-unicode-bidi")} -// FIXME: This prop should be animatable. <%helpers:longhand name="text-decoration-line" custom_cascade="${product == 'servo'}" - animation_value_type="none" + animation_value_type="discrete" spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration-line"> use std::fmt; use style_traits::ToCss; @@ -172,8 +171,8 @@ ${helpers.single_keyword("unicode-bidi", #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub flags SpecifiedValue: u8 { const NONE = 0, - const OVERLINE = 0x01, - const UNDERLINE = 0x02, + const UNDERLINE = 0x01, + const OVERLINE = 0x02, const LINE_THROUGH = 0x04, const BLINK = 0x08, % if product == "gecko": @@ -269,6 +268,9 @@ ${helpers.single_keyword("unicode-bidi", longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(context); } % endif + + #[cfg(feature = "gecko")] + impl_bitflags_conversions!(SpecifiedValue); ${helpers.single_keyword("text-decoration-style", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 9e8420fa471..f140e07939b 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -53,6 +53,23 @@ macro_rules! property_name { ($s: tt) => { atom!($s) } } +#[cfg(feature = "gecko")] +macro_rules! impl_bitflags_conversions { + ($name: ident) => { + impl From for $name { + fn from(bits: u8) -> $name { + $name::from_bits(bits).expect("bits contain valid flag") + } + } + + impl From<$name> for u8 { + fn from(v: $name) -> u8 { + v.bits() + } + } + }; +} + <%! from data import Method, Keyword, to_rust_ident, to_camel_case, SYSTEM_FONT_LONGHANDS import os.path diff --git a/components/style/values/specified/align.rs b/components/style/values/specified/align.rs index 6fb637b6942..0d202ea0db5 100644 --- a/components/style/values/specified/align.rs +++ b/components/style/values/specified/align.rs @@ -137,10 +137,6 @@ impl AlignJustifyContent { AlignJustifyContent(flags.bits() as u16 | ((fallback.bits() as u16) << ALIGN_ALL_SHIFT)) } - /// The combined 16-bit flags, for copying into a Gecko style struct. - #[inline] - pub fn bits(self) -> u16 { self.0 } - /// The primary alignment #[inline] pub fn primary(self) -> AlignFlags { @@ -325,6 +321,20 @@ impl Parse for JustifyItems { } } +#[cfg(feature = "gecko")] +impl From for AlignJustifyContent { + fn from(bits: u16) -> AlignJustifyContent { + AlignJustifyContent(bits) + } +} + +#[cfg(feature = "gecko")] +impl From for u16 { + fn from(v: AlignJustifyContent) -> u16 { + v.0 + } +} + // auto | normal | stretch | fn parse_auto_normal_stretch_baseline(input: &mut Parser) -> Result { if let Ok(baseline) = input.try(parse_baseline) {