Auto merge of #16693 - nox:touch-action, r=emilio

Implement touch-action in stylo (fixes #16372)

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16693)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-05-02 09:46:59 -05:00 committed by GitHub
commit 5e2d383274
2 changed files with 86 additions and 1 deletions

View file

@ -1771,7 +1771,7 @@ fn static_assert() {
scroll-snap-points-x scroll-snap-points-y transform
scroll-snap-type-y scroll-snap-coordinate
perspective-origin transform-origin -moz-binding will-change
shape-outside contain""" %>
shape-outside contain touch-action""" %>
<%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}">
// We manually-implement the |display| property until we get general
@ -2488,6 +2488,12 @@ 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")}
</%self:impl_trait>
<%def name="simple_image_array_property(name, shorthand, field_name)">

View file

@ -2514,3 +2514,82 @@ ${helpers.predefined_type("shape-outside", "basic_shape::ShapeWithShapeBox",
products="gecko", boxed="True",
animation_value_type="none",
spec="https://drafts.csswg.org/css-shapes/#shape-outside-property")}
<%helpers:longhand name="touch-action"
products="gecko"
animation_value_type="none"
disable_when_testing="True"
spec="https://compat.spec.whatwg.org/#touch-action">
use gecko_bindings::structs;
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
use values::computed::ComputedValueAsSpecified;
impl ComputedValueAsSpecified for SpecifiedValue {}
no_viewport_percentage!(SpecifiedValue);
pub mod computed_value {
pub use super::SpecifiedValue as T;
}
bitflags! {
/// These constants match Gecko's `NS_STYLE_TOUCH_ACTION_*` constants.
pub flags 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<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
TOUCH_ACTION_NONE => dest.write_str("none"),
TOUCH_ACTION_AUTO => dest.write_str("auto"),
TOUCH_ACTION_MANIPULATION => dest.write_str("manipulation"),
_ if self.contains(TOUCH_ACTION_PAN_X | TOUCH_ACTION_PAN_Y) => {
dest.write_str("pan-x pan-y")
},
_ if self.contains(TOUCH_ACTION_PAN_X) => {
dest.write_str("pan-x")
},
_ if self.contains(TOUCH_ACTION_PAN_Y) => {
dest.write_str("pan-y")
},
_ => panic!("invalid touch-action value"),
}
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
TOUCH_ACTION_AUTO
}
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
let ident = input.expect_ident()?;
match_ignore_ascii_case! { &ident,
"auto" => Ok(TOUCH_ACTION_AUTO),
"none" => Ok(TOUCH_ACTION_NONE),
"manipulation" => Ok(TOUCH_ACTION_MANIPULATION),
"pan-x" => {
if input.try(|i| i.expect_ident_matching("pan-y")).is_ok() {
Ok(TOUCH_ACTION_PAN_X | TOUCH_ACTION_PAN_Y)
} else {
Ok(TOUCH_ACTION_PAN_X)
}
},
"pan-y" => {
if input.try(|i| i.expect_ident_matching("pan-x")).is_ok() {
Ok(TOUCH_ACTION_PAN_X | TOUCH_ACTION_PAN_Y)
} else {
Ok(TOUCH_ACTION_PAN_Y)
}
},
_ => Err(()),
}
}
</%helpers:longhand>