mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Add support for touch-action:pinch-zoom - Rewrite to_css and parse for touchAction
Differential Revision: https://phabricator.services.mozilla.com/D97650
This commit is contained in:
parent
9f40b9ba38
commit
85b45cd615
1 changed files with 53 additions and 28 deletions
|
@ -1199,43 +1199,68 @@ impl ToCss for TouchAction {
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
match *self {
|
if self.contains(TouchAction::AUTO) {
|
||||||
TouchAction::NONE => dest.write_str("none"),
|
return dest.write_str("auto");
|
||||||
TouchAction::AUTO => dest.write_str("auto"),
|
|
||||||
TouchAction::MANIPULATION => dest.write_str("manipulation"),
|
|
||||||
_ if self.contains(TouchAction::PAN_X | TouchAction::PAN_Y) => {
|
|
||||||
dest.write_str("pan-x pan-y")
|
|
||||||
},
|
|
||||||
_ if self.contains(TouchAction::PAN_X) => dest.write_str("pan-x"),
|
|
||||||
_ if self.contains(TouchAction::PAN_Y) => dest.write_str("pan-y"),
|
|
||||||
_ => panic!("invalid touch-action value"),
|
|
||||||
}
|
}
|
||||||
|
if self.contains(TouchAction::NONE) {
|
||||||
|
return dest.write_str("none");
|
||||||
|
}
|
||||||
|
if self.contains(TouchAction::MANIPULATION) {
|
||||||
|
return dest.write_str("manipulation");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut has_any = false;
|
||||||
|
macro_rules! maybe_write_value {
|
||||||
|
($ident:path => $str:expr) => {
|
||||||
|
if self.contains($ident) {
|
||||||
|
if has_any {
|
||||||
|
dest.write_str(" ")?;
|
||||||
|
}
|
||||||
|
has_any = true;
|
||||||
|
dest.write_str($str)?;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
maybe_write_value!(TouchAction::PAN_X => "pan-x");
|
||||||
|
maybe_write_value!(TouchAction::PAN_Y => "pan-y");
|
||||||
|
|
||||||
|
debug_assert!(has_any);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for TouchAction {
|
impl Parse for TouchAction {
|
||||||
|
/// auto | none | [ pan-x || pan-y ] | manipulation
|
||||||
fn parse<'i, 't>(
|
fn parse<'i, 't>(
|
||||||
_context: &ParserContext,
|
_context: &ParserContext,
|
||||||
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,
|
let mut result = TouchAction::empty();
|
||||||
"auto" => Ok(TouchAction::AUTO),
|
while let Ok(name) = input.try_parse(|i| i.expect_ident_cloned()) {
|
||||||
"none" => Ok(TouchAction::NONE),
|
let flag = match_ignore_ascii_case! { &name,
|
||||||
"manipulation" => Ok(TouchAction::MANIPULATION),
|
"pan-x" => Some(TouchAction::PAN_X),
|
||||||
"pan-x" => {
|
"pan-y" => Some(TouchAction::PAN_Y),
|
||||||
if input.try_parse(|i| i.expect_ident_matching("pan-y")).is_ok() {
|
"none" if result.is_empty() => return Ok(TouchAction::NONE),
|
||||||
Ok(TouchAction::PAN_X | TouchAction::PAN_Y)
|
"manipulation" if result.is_empty() => return Ok(TouchAction::MANIPULATION),
|
||||||
} else {
|
"auto" if result.is_empty() => return Ok(TouchAction::AUTO),
|
||||||
Ok(TouchAction::PAN_X)
|
_ => None
|
||||||
}
|
};
|
||||||
|
|
||||||
|
let flag = match flag {
|
||||||
|
Some(flag) if !result.contains(flag) => flag,
|
||||||
|
_ => {
|
||||||
|
return Err(
|
||||||
|
input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name))
|
||||||
|
);
|
||||||
},
|
},
|
||||||
"pan-y" => {
|
};
|
||||||
if input.try_parse(|i| i.expect_ident_matching("pan-x")).is_ok() {
|
result.insert(flag);
|
||||||
Ok(TouchAction::PAN_X | TouchAction::PAN_Y)
|
|
||||||
} else {
|
|
||||||
Ok(TouchAction::PAN_Y)
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
if !result.is_empty() {
|
||||||
|
Ok(result)
|
||||||
|
} else {
|
||||||
|
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue