Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion float-pigment-css/src/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -1729,6 +1730,32 @@ property_value_format! (PropertyValueWithGlobal, {
};
}};

<touch_action_pan_x: u8>:
"pan-x" -> |_| 3;
| "pan-left" -> |_| 1;
| "pan-right" -> |_| 2;
;
<touch_action_pan_y: u8>:
"pan-y" -> |_| 3;
| "pan-up" -> |_| 1;
| "pan-down" -> |_| 2;
;
touch_action: {{ TouchAction
Comment thread
TtTRz marked this conversation as resolved.
= "auto" => TouchActionType::Auto
| "none" => TouchActionType::None
| "manipulation" => TouchActionType::Manipulation
| [<touch_action_pan_x> || <touch_action_pan_y>] -> |(pan_x, pan_y): (Option<u8>, Option<u8>)| {
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<T: Clone>(x: Vec<T>) -> (T, T) {
Expand Down
29 changes: 29 additions & 0 deletions float-pigment-css/src/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1905,3 +1905,32 @@ pub enum GridAutoFlow {
pub enum GridAuto {
List(Array<TrackSize>),
}

#[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
}
}
37 changes: 37 additions & 0 deletions float-pigment-css/src/typing_stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(" "))
}
}
14 changes: 14 additions & 0 deletions float-pigment-css/tests/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading