diff --git a/float-pigment-css/src/property.rs b/float-pigment-css/src/property.rs index b725a82..999cf85 100644 --- a/float-pigment-css/src/property.rs +++ b/float-pigment-css/src/property.rs @@ -174,7 +174,7 @@ property_list! (PropertyValueWithGlobal, { 0xa9 GridAutoRows: GridAutoType as Initial default GridAuto::List(vec![TrackSize::Length(Length::Auto)].into()); 0xaa GridAutoColumns: GridAutoType as Initial default GridAuto::List(vec![TrackSize::Length(Length::Auto)].into()); - + // misc 0xd0 ListStyleType: ListStyleTypeType as Inherit default ListStyleType::Disc; 0xd1 ListStyleImage: ListStyleImageType as Inherit default ListStyleImage::None; 0xd2 ListStylePosition: ListStylePositionType as Inherit default ListStylePosition::Outside; @@ -185,6 +185,7 @@ property_list! (PropertyValueWithGlobal, { 0xd7 AspectRatio: AspectRatioType as Initial default AspectRatio::Auto; 0xd8 Contain: ContainType as Initial default Contain::None; 0xd9 Content: ContentType as Initial default Content::None; + 0xda TouchAction: TouchActionType as Initial default TouchAction::Auto; // wx-spec special properties 0xe0 WxScrollbarX: ScrollbarType as Initial default Scrollbar::Auto; @@ -1729,6 +1730,32 @@ property_value_format! (PropertyValueWithGlobal, { }; }}; + : + "pan-x" -> |_| 3; + | "pan-left" -> |_| 1; + | "pan-right" -> |_| 2; + ; + : + "pan-y" -> |_| 3; + | "pan-up" -> |_| 1; + | "pan-down" -> |_| 2; + ; + touch_action: {{ TouchAction + = "auto" => TouchActionType::Auto + | "none" => TouchActionType::None + | "manipulation" => TouchActionType::Manipulation + | [ || ] -> |(pan_x, pan_y): (Option, Option)| { + let pan_x = pan_x.unwrap_or(0); + let pan_y = pan_y.unwrap_or(0); + let ges = TouchActionGestures { + pan_left: (pan_x & 1) > 0, + pan_right: (pan_x & 2) > 0, + pan_up: (pan_y & 1) > 0, + pan_down: (pan_y & 2) > 0, + }; + TouchActionType::Gestures(ges) + }; + }} }); pub(crate) fn split_hv(x: Vec) -> (T, T) { diff --git a/float-pigment-css/src/typing.rs b/float-pigment-css/src/typing.rs index 07cc126..b3d234a 100644 --- a/float-pigment-css/src/typing.rs +++ b/float-pigment-css/src/typing.rs @@ -1905,3 +1905,32 @@ pub enum GridAutoFlow { pub enum GridAuto { List(Array), } + +#[allow(missing_docs)] +#[repr(C)] +#[property_value_type(PropertyValueWithGlobal for TouchActionType)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ResolveFontSize)] +#[cfg_attr(debug_assertions, derive(CompatibilityEnumCheck))] +pub enum TouchAction { + Auto, + None, + Manipulation, + Gestures(TouchActionGestures), +} + +#[allow(missing_docs)] +#[repr(C)] +#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] +#[cfg_attr(debug_assertions, derive(CompatibilityStructCheck))] +pub struct TouchActionGestures { + pub pan_left: bool, + pub pan_right: bool, + pub pan_up: bool, + pub pan_down: bool, +} + +impl ResolveFontSize for TouchActionGestures { + fn resolve_font_size(&mut self, _: f32) { + // empty + } +} diff --git a/float-pigment-css/src/typing_stringify.rs b/float-pigment-css/src/typing_stringify.rs index 1a17262..610788f 100644 --- a/float-pigment-css/src/typing_stringify.rs +++ b/float-pigment-css/src/typing_stringify.rs @@ -2434,3 +2434,40 @@ impl fmt::Display for GridAuto { } } } + +impl fmt::Display for TouchAction { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + TouchAction::Auto => write!(f, "auto"), + TouchAction::None => write!(f, "none"), + TouchAction::Manipulation => write!(f, "manipulation"), + TouchAction::Gestures(ges) => write!(f, "{}", ges), + } + } +} + +impl fmt::Display for TouchActionGestures { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let Self { pan_left, pan_right, pan_up, pan_down } = self; + let pan_x = if *pan_left && *pan_right { + "pan-x" + } else if *pan_left { + "pan-left" + } else if *pan_right { + "pan-right" + } else { + "" + }; + let pan_y = if *pan_up && *pan_down { + "pan-y" + } else if *pan_up { + "pan-up" + } else if *pan_down { + "pan-down" + } else { + "" + }; + let s: Vec<_> = [pan_x, pan_y].into_iter().filter(|x| !x.is_empty()).collect(); + write!(f, "{}", s.join(" ")) + } +} diff --git a/float-pigment-css/tests/property.rs b/float-pigment-css/tests/property.rs index 494214f..5248186 100644 --- a/float-pigment-css/tests/property.rs +++ b/float-pigment-css/tests/property.rs @@ -7289,6 +7289,20 @@ mod other { ) ); } + + // 0xda + #[test] + fn touch_action() { + test_parse_property!(touch_action, "touch-action", "auto", TouchAction::Auto); + test_parse_property!(touch_action, "touch-action", "none", TouchAction::None); + test_parse_property!(touch_action, "touch-action", "manipulation", TouchAction::Manipulation); + test_parse_property!(touch_action, "touch-action", "pan-x", TouchAction::Gestures(TouchActionGestures { pan_left: true, pan_right: true, pan_up: false, pan_down: false })); + test_parse_property!(touch_action, "touch-action", "pan-y", TouchAction::Gestures(TouchActionGestures { pan_left: false, pan_right: false, pan_up: true, pan_down: true })); + test_parse_property!(touch_action, "touch-action", "pan-left", TouchAction::Gestures(TouchActionGestures { pan_left: true, pan_right: false, pan_up: false, pan_down: false })); + test_parse_property!(touch_action, "touch-action", "pan-right", TouchAction::Gestures(TouchActionGestures { pan_left: false, pan_right: true, pan_up: false, pan_down: false })); + test_parse_property!(touch_action, "touch-action", "pan-up", TouchAction::Gestures(TouchActionGestures { pan_left: false, pan_right: false, pan_up: true, pan_down: false })); + test_parse_property!(touch_action, "touch-action", "pan-down", TouchAction::Gestures(TouchActionGestures { pan_left: false, pan_right: false, pan_up: false, pan_down: true })); + } } mod wx_special {