style: Use cbindgen for touch-action.

And rename the constants to not be prefixed by TOUCH_ACTION_, since that's part
of the type name anyway.

Differential Revision: https://phabricator.services.mozilla.com/D23413
This commit is contained in:
Emilio Cobos Álvarez 2019-03-18 18:01:55 +00:00
parent b0af565656
commit 6e2643c636
3 changed files with 23 additions and 51 deletions

View file

@ -105,6 +105,7 @@ include = [
"WordBreak", "WordBreak",
"Contain", "Contain",
"RestyleHint", "RestyleHint",
"TouchAction",
"TextDecorationLine", "TextDecorationLine",
] ]
item_types = ["enums", "structs", "typedefs"] item_types = ["enums", "structs", "typedefs"]

View file

@ -2582,7 +2582,7 @@ fn static_assert() {
transform-style transform-style
rotate scroll-snap-points-x scroll-snap-points-y rotate scroll-snap-points-x scroll-snap-points-y
scroll-snap-coordinate -moz-binding will-change scroll-snap-coordinate -moz-binding will-change
offset-path shape-outside touch-action offset-path shape-outside
translate scale""" %> translate scale""" %>
<%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}"> <%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
#[inline] #[inline]
@ -3002,8 +3002,6 @@ fn static_assert() {
<% impl_shape_source("shape_outside", "mShapeOutside") %> <% impl_shape_source("shape_outside", "mShapeOutside") %>
${impl_simple_type_with_conversion("touch_action")}
pub fn set_offset_path(&mut self, v: longhands::offset_path::computed_value::T) { pub fn set_offset_path(&mut self, v: longhands::offset_path::computed_value::T) {
use crate::gecko_bindings::bindings::{Gecko_NewStyleMotion, Gecko_SetStyleMotion}; use crate::gecko_bindings::bindings::{Gecko_NewStyleMotion, Gecko_SetStyleMotion};
use crate::gecko_bindings::structs::StyleShapeSourceType; use crate::gecko_bindings::structs::StyleShapeSourceType;

View file

@ -650,21 +650,22 @@ impl Parse for WillChange {
} }
bitflags! { bitflags! {
/// Values for the `touch-action` property.
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(SpecifiedValueInfo, ToComputedValue)] #[derive(SpecifiedValueInfo, ToComputedValue)]
/// These constants match Gecko's `NS_STYLE_TOUCH_ACTION_*` constants.
#[value_info(other_values = "auto,none,manipulation,pan-x,pan-y")] #[value_info(other_values = "auto,none,manipulation,pan-x,pan-y")]
#[repr(C)]
pub struct TouchAction: u8 { pub struct TouchAction: u8 {
/// `none` variant /// `none` variant
const TOUCH_ACTION_NONE = 1 << 0; const NONE = 1 << 0;
/// `auto` variant /// `auto` variant
const TOUCH_ACTION_AUTO = 1 << 1; const AUTO = 1 << 1;
/// `pan-x` variant /// `pan-x` variant
const TOUCH_ACTION_PAN_X = 1 << 2; const PAN_X = 1 << 2;
/// `pan-y` variant /// `pan-y` variant
const TOUCH_ACTION_PAN_Y = 1 << 3; const PAN_Y = 1 << 3;
/// `manipulation` variant /// `manipulation` variant
const TOUCH_ACTION_MANIPULATION = 1 << 4; const MANIPULATION = 1 << 4;
} }
} }
@ -672,7 +673,7 @@ impl TouchAction {
#[inline] #[inline]
/// Get default `touch-action` as `auto` /// Get default `touch-action` as `auto`
pub fn auto() -> TouchAction { pub fn auto() -> TouchAction {
TouchAction::TOUCH_ACTION_AUTO TouchAction::AUTO
} }
} }
@ -682,16 +683,14 @@ impl ToCss for TouchAction {
W: Write, W: Write,
{ {
match *self { match *self {
TouchAction::TOUCH_ACTION_NONE => dest.write_str("none"), TouchAction::NONE => dest.write_str("none"),
TouchAction::TOUCH_ACTION_AUTO => dest.write_str("auto"), TouchAction::AUTO => dest.write_str("auto"),
TouchAction::TOUCH_ACTION_MANIPULATION => dest.write_str("manipulation"), TouchAction::MANIPULATION => dest.write_str("manipulation"),
_ if self _ if self.contains(TouchAction::PAN_X | TouchAction::PAN_Y) => {
.contains(TouchAction::TOUCH_ACTION_PAN_X | TouchAction::TOUCH_ACTION_PAN_Y) =>
{
dest.write_str("pan-x 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::PAN_X) => dest.write_str("pan-x"),
_ if self.contains(TouchAction::TOUCH_ACTION_PAN_Y) => dest.write_str("pan-y"), _ if self.contains(TouchAction::PAN_Y) => dest.write_str("pan-y"),
_ => panic!("invalid touch-action value"), _ => panic!("invalid touch-action value"),
} }
} }
@ -703,53 +702,27 @@ impl Parse for TouchAction {
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<TouchAction, ParseError<'i>> { ) -> Result<TouchAction, ParseError<'i>> {
try_match_ident_ignore_ascii_case! { input, try_match_ident_ignore_ascii_case! { input,
"auto" => Ok(TouchAction::TOUCH_ACTION_AUTO), "auto" => Ok(TouchAction::AUTO),
"none" => Ok(TouchAction::TOUCH_ACTION_NONE), "none" => Ok(TouchAction::NONE),
"manipulation" => Ok(TouchAction::TOUCH_ACTION_MANIPULATION), "manipulation" => Ok(TouchAction::MANIPULATION),
"pan-x" => { "pan-x" => {
if input.try(|i| i.expect_ident_matching("pan-y")).is_ok() { if input.try(|i| i.expect_ident_matching("pan-y")).is_ok() {
Ok(TouchAction::TOUCH_ACTION_PAN_X | TouchAction::TOUCH_ACTION_PAN_Y) Ok(TouchAction::PAN_X | TouchAction::PAN_Y)
} else { } else {
Ok(TouchAction::TOUCH_ACTION_PAN_X) Ok(TouchAction::PAN_X)
} }
}, },
"pan-y" => { "pan-y" => {
if input.try(|i| i.expect_ident_matching("pan-x")).is_ok() { if input.try(|i| i.expect_ident_matching("pan-x")).is_ok() {
Ok(TouchAction::TOUCH_ACTION_PAN_X | TouchAction::TOUCH_ACTION_PAN_Y) Ok(TouchAction::PAN_X | TouchAction::PAN_Y)
} else { } else {
Ok(TouchAction::TOUCH_ACTION_PAN_Y) Ok(TouchAction::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 crate::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,
}
}
bitflags! { bitflags! {
#[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue)] #[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue)]
#[value_info(other_values = "none,strict,content,size,layout,paint")] #[value_info(other_values = "none,strict,content,size,layout,paint")]