From bfd346cb0b78fa56c7378f8f16cd3251f5339db7 Mon Sep 17 00:00:00 2001 From: CYBAI Date: Fri, 29 Dec 2017 06:08:33 -0600 Subject: [PATCH] servo: Merge #19646 - style: Move touch-action outside of mako (from CYBAI:move-touch-action-out-of-mako); r=emilio This is a sub-PR of #19015 r? emilio --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #19645 - [x] These changes do not require tests Source-Repo: https://github.com/servo/servo Source-Revision: 446536b9c34b331f5466bfb212be8cb1faa2dee8 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 95d2c35265415ad7c93319d1364efa59f49cdaad --- .../style/properties/longhand/box.mako.rs | 87 ++-------------- servo/components/style/values/computed/box.rs | 2 +- servo/components/style/values/computed/mod.rs | 2 +- .../components/style/values/specified/box.rs | 99 +++++++++++++++++++ .../components/style/values/specified/mod.rs | 2 +- servo/ports/geckolib/glue.rs | 1 + 6 files changed, 112 insertions(+), 81 deletions(-) diff --git a/servo/components/style/properties/longhand/box.mako.rs b/servo/components/style/properties/longhand/box.mako.rs index 694566ec62f1..58520d3cd903 100644 --- a/servo/components/style/properties/longhand/box.mako.rs +++ b/servo/components/style/properties/longhand/box.mako.rs @@ -910,81 +910,12 @@ ${helpers.predefined_type( spec="https://drafts.csswg.org/css-shapes/#shape-outside-property", )} -<%helpers:longhand name="touch-action" - products="gecko" - animation_value_type="discrete" - gecko_pref="layout.css.touch_action.enabled" - spec="https://compat.spec.whatwg.org/#touch-action"> - use gecko_bindings::structs; - use std::fmt; - use style_traits::ToCss; - - pub mod computed_value { - pub use super::SpecifiedValue as T; - } - - bitflags! { - /// These constants match Gecko's `NS_STYLE_TOUCH_ACTION_*` constants. - #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] - #[derive(ToComputedValue)] - pub struct SpecifiedValue: u8 { - const TOUCH_ACTION_NONE = structs::NS_STYLE_TOUCH_ACTION_NONE as u8; - const TOUCH_ACTION_AUTO = structs::NS_STYLE_TOUCH_ACTION_AUTO as u8; - const TOUCH_ACTION_PAN_X = structs::NS_STYLE_TOUCH_ACTION_PAN_X as u8; - const TOUCH_ACTION_PAN_Y = structs::NS_STYLE_TOUCH_ACTION_PAN_Y as u8; - const TOUCH_ACTION_MANIPULATION = structs::NS_STYLE_TOUCH_ACTION_MANIPULATION as u8; - } - } - - impl ToCss for SpecifiedValue { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - SpecifiedValue::TOUCH_ACTION_NONE => dest.write_str("none"), - SpecifiedValue::TOUCH_ACTION_AUTO => dest.write_str("auto"), - SpecifiedValue::TOUCH_ACTION_MANIPULATION => dest.write_str("manipulation"), - _ if self.contains(SpecifiedValue::TOUCH_ACTION_PAN_X | SpecifiedValue::TOUCH_ACTION_PAN_Y) => { - dest.write_str("pan-x pan-y") - }, - _ if self.contains(SpecifiedValue::TOUCH_ACTION_PAN_X) => { - dest.write_str("pan-x") - }, - _ if self.contains(SpecifiedValue::TOUCH_ACTION_PAN_Y) => { - dest.write_str("pan-y") - }, - _ => panic!("invalid touch-action value"), - } - } - } - - #[inline] - pub fn get_initial_value() -> computed_value::T { - SpecifiedValue::TOUCH_ACTION_AUTO - } - - pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) - -> Result> { - // FIXME: remove clone() when lifetimes are non-lexical - try_match_ident_ignore_ascii_case! { input, - "auto" => Ok(SpecifiedValue::TOUCH_ACTION_AUTO), - "none" => Ok(SpecifiedValue::TOUCH_ACTION_NONE), - "manipulation" => Ok(SpecifiedValue::TOUCH_ACTION_MANIPULATION), - "pan-x" => { - if input.try(|i| i.expect_ident_matching("pan-y")).is_ok() { - Ok(SpecifiedValue::TOUCH_ACTION_PAN_X | SpecifiedValue::TOUCH_ACTION_PAN_Y) - } else { - Ok(SpecifiedValue::TOUCH_ACTION_PAN_X) - } - }, - "pan-y" => { - if input.try(|i| i.expect_ident_matching("pan-x")).is_ok() { - Ok(SpecifiedValue::TOUCH_ACTION_PAN_X | SpecifiedValue::TOUCH_ACTION_PAN_Y) - } else { - Ok(SpecifiedValue::TOUCH_ACTION_PAN_Y) - } - }, - } - } - - #[cfg(feature = "gecko")] - impl_bitflags_conversions!(SpecifiedValue); - +${helpers.predefined_type( + "touch-action", + "TouchAction", + "computed::TouchAction::auto()", + products="gecko", + gecko_pref="layout.css.touch_action.enabled", + animation_value_type="discrete", + spec="https://compat.spec.whatwg.org/#touch-action", +)} diff --git a/servo/components/style/values/computed/box.rs b/servo/components/style/values/computed/box.rs index 989c96174f00..5d606f9fe6ff 100644 --- a/servo/components/style/values/computed/box.rs +++ b/servo/components/style/values/computed/box.rs @@ -10,7 +10,7 @@ use values::generics::box_::AnimationIterationCount as GenericAnimationIteration use values::generics::box_::VerticalAlign as GenericVerticalAlign; pub use values::specified::box_::{AnimationName, OverflowClipBox, OverscrollBehavior}; -pub use values::specified::box_::{ScrollSnapType, WillChange}; +pub use values::specified::box_::{ScrollSnapType, TouchAction, WillChange}; /// A computed value for the `vertical-align` property. pub type VerticalAlign = GenericVerticalAlign; diff --git a/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index 4ad0992d698b..e81dcfc735f1 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/components/style/values/computed/mod.rs @@ -41,7 +41,7 @@ pub use self::font::{FontFamily, FontLanguageOverride, FontVariantSettings, Font pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings}; pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang}; pub use self::box_::{AnimationIterationCount, AnimationName, OverscrollBehavior}; -pub use self::box_::{OverflowClipBox, ScrollSnapType, VerticalAlign, WillChange}; +pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange}; pub use self::color::{Color, ColorPropertyValue, RGBAColor}; pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::flex::FlexBasis; diff --git a/servo/components/style/values/specified/box.rs b/servo/components/style/values/specified/box.rs index 29f699d2c606..b43ae4886214 100644 --- a/servo/components/style/values/specified/box.rs +++ b/servo/components/style/values/specified/box.rs @@ -177,3 +177,102 @@ impl Parse for WillChange { Ok(WillChange::AnimateableFeatures(custom_idents.into_boxed_slice())) } } + +bitflags! { + #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] + #[derive(ToComputedValue)] + /// These constants match Gecko's `NS_STYLE_TOUCH_ACTION_*` constants. + pub struct TouchAction: u8 { + /// `none` variant + const TOUCH_ACTION_NONE = 1 << 0; + /// `auto` variant + const TOUCH_ACTION_AUTO = 1 << 1; + /// `pan-x` variant + const TOUCH_ACTION_PAN_X = 1 << 2; + /// `pan-y` variant + const TOUCH_ACTION_PAN_Y = 1 << 3; + /// `manipulation` variant + const TOUCH_ACTION_MANIPULATION = 1 << 4; + } +} + +impl TouchAction { + #[inline] + /// Get default `touch-action` as `auto` + pub fn auto() -> TouchAction { + TouchAction::TOUCH_ACTION_AUTO + } +} + +impl ToCss for TouchAction { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + match *self { + TouchAction::TOUCH_ACTION_NONE => dest.write_str("none"), + TouchAction::TOUCH_ACTION_AUTO => dest.write_str("auto"), + TouchAction::TOUCH_ACTION_MANIPULATION => dest.write_str("manipulation"), + _ if self.contains(TouchAction::TOUCH_ACTION_PAN_X | TouchAction::TOUCH_ACTION_PAN_Y) => { + dest.write_str("pan-x pan-y") + }, + _ if self.contains(TouchAction::TOUCH_ACTION_PAN_X) => { + dest.write_str("pan-x") + }, + _ if self.contains(TouchAction::TOUCH_ACTION_PAN_Y) => { + dest.write_str("pan-y") + }, + _ => panic!("invalid touch-action value"), + } + } +} + +impl Parse for TouchAction { + fn parse<'i, 't>( + _context: &ParserContext, + input: &mut Parser<'i, 't> + ) -> Result> { + try_match_ident_ignore_ascii_case! { input, + "auto" => Ok(TouchAction::TOUCH_ACTION_AUTO), + "none" => Ok(TouchAction::TOUCH_ACTION_NONE), + "manipulation" => Ok(TouchAction::TOUCH_ACTION_MANIPULATION), + "pan-x" => { + if input.try(|i| i.expect_ident_matching("pan-y")).is_ok() { + Ok(TouchAction::TOUCH_ACTION_PAN_X | TouchAction::TOUCH_ACTION_PAN_Y) + } else { + Ok(TouchAction::TOUCH_ACTION_PAN_X) + } + }, + "pan-y" => { + if input.try(|i| i.expect_ident_matching("pan-x")).is_ok() { + Ok(TouchAction::TOUCH_ACTION_PAN_X | TouchAction::TOUCH_ACTION_PAN_Y) + } else { + Ok(TouchAction::TOUCH_ACTION_PAN_Y) + } + }, + } + } +} + +#[cfg(feature = "gecko")] +impl_bitflags_conversions!(TouchAction); + +/// Asserts that all touch-action matches its NS_STYLE_TOUCH_ACTION_* value. +#[cfg(feature = "gecko")] +#[inline] +pub fn assert_touch_action_matches() { + use gecko_bindings::structs; + + macro_rules! check_touch_action { + ( $( $a:ident => $b:path),*, ) => { + $( + debug_assert_eq!(structs::$a as u8, $b.bits()); + )* + } + } + + check_touch_action! { + NS_STYLE_TOUCH_ACTION_NONE => TouchAction::TOUCH_ACTION_NONE, + NS_STYLE_TOUCH_ACTION_AUTO => TouchAction::TOUCH_ACTION_AUTO, + NS_STYLE_TOUCH_ACTION_PAN_X => TouchAction::TOUCH_ACTION_PAN_X, + NS_STYLE_TOUCH_ACTION_PAN_Y => TouchAction::TOUCH_ACTION_PAN_Y, + NS_STYLE_TOUCH_ACTION_MANIPULATION => TouchAction::TOUCH_ACTION_MANIPULATION, + } +} diff --git a/servo/components/style/values/specified/mod.rs b/servo/components/style/values/specified/mod.rs index 7be271fdd343..b19301166b5b 100644 --- a/servo/components/style/values/specified/mod.rs +++ b/servo/components/style/values/specified/mod.rs @@ -35,7 +35,7 @@ pub use self::font::{FontFamily, FontLanguageOverride, FontVariantSettings, Font pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings}; pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang}; pub use self::box_::{AnimationIterationCount, AnimationName, OverscrollBehavior}; -pub use self::box_::{OverflowClipBox, ScrollSnapType, VerticalAlign, WillChange}; +pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange}; pub use self::color::{Color, ColorPropertyValue, RGBAColor}; pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::flex::FlexBasis; diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 4f871202c9e2..0f0de25da531 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -192,6 +192,7 @@ pub extern "C" fn Servo_Initialize(dummy_url_data: *mut URLExtraData) { traversal_flags::assert_traversal_flags_match(); specified::font::assert_variant_east_asian_matches(); specified::font::assert_variant_ligatures_matches(); + specified::box_::assert_touch_action_matches(); // Initialize the dummy url data unsafe { DUMMY_URL_DATA = dummy_url_data; }