mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-16 05:51:55 +00:00
LibWeb: Parse and propagate touch-action CSS property
Co-authored-by: Sam Atkins <sam@ladybird.org>
This commit is contained in:
parent
b3713db4ab
commit
6cbb5d2785
Notes:
github-actions[bot]
2025-05-06 11:23:01 +00:00
Author: https://github.com/stravant 🔰
Commit: 6cbb5d2785
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3837
Reviewed-by: https://github.com/AtkinsSJ ✅
21 changed files with 364 additions and 19 deletions
|
@ -664,6 +664,10 @@ Parser::ParseErrorOr<NonnullRefPtr<CSSStyleValue const>> Parser::parse_css_value
|
|||
if (auto parsed_value = parse_shadow_value(tokens, AllowInsetKeyword::No); parsed_value && !tokens.has_next_token())
|
||||
return parsed_value.release_nonnull();
|
||||
return ParseError::SyntaxError;
|
||||
case PropertyID::TouchAction:
|
||||
if (auto parsed_value = parse_touch_action_value(tokens); parsed_value && !tokens.has_next_token())
|
||||
return parsed_value.release_nonnull();
|
||||
return ParseError::SyntaxError;
|
||||
case PropertyID::Transform:
|
||||
if (auto parsed_value = parse_transform_value(tokens); parsed_value && !tokens.has_next_token())
|
||||
return parsed_value.release_nonnull();
|
||||
|
@ -3528,6 +3532,67 @@ RefPtr<CSSStyleValue const> Parser::parse_text_decoration_line_value(TokenStream
|
|||
return StyleValueList::create(move(style_values), StyleValueList::Separator::Space);
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/pointerevents/#the-touch-action-css-property
|
||||
RefPtr<CSSStyleValue const> Parser::parse_touch_action_value(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
// auto | none | [ [ pan-x | pan-left | pan-right ] || [ pan-y | pan-up | pan-down ] ] | manipulation
|
||||
|
||||
if (auto value = parse_all_as_single_keyword_value(tokens, Keyword::Auto))
|
||||
return value;
|
||||
if (auto value = parse_all_as_single_keyword_value(tokens, Keyword::None))
|
||||
return value;
|
||||
if (auto value = parse_all_as_single_keyword_value(tokens, Keyword::Manipulation))
|
||||
return value;
|
||||
|
||||
StyleValueVector parsed_values;
|
||||
auto transaction = tokens.begin_transaction();
|
||||
|
||||
// We will verify that we have up to one vertical and one horizontal value
|
||||
bool has_horizontal = false;
|
||||
bool has_vertical = false;
|
||||
|
||||
// Were the values specified in y/x order? (we need to store them in canonical x/y order)
|
||||
bool swap_order = false;
|
||||
|
||||
while (auto parsed_value = parse_css_value_for_property(PropertyID::TouchAction, tokens)) {
|
||||
switch (parsed_value->as_keyword().keyword()) {
|
||||
case Keyword::PanX:
|
||||
case Keyword::PanLeft:
|
||||
case Keyword::PanRight:
|
||||
if (has_horizontal)
|
||||
return {};
|
||||
if (has_vertical)
|
||||
swap_order = true;
|
||||
has_horizontal = true;
|
||||
break;
|
||||
case Keyword::PanY:
|
||||
case Keyword::PanUp:
|
||||
case Keyword::PanDown:
|
||||
if (has_vertical)
|
||||
return {};
|
||||
has_vertical = true;
|
||||
break;
|
||||
case Keyword::Auto:
|
||||
case Keyword::None:
|
||||
case Keyword::Manipulation:
|
||||
// Not valid as part of a list
|
||||
return {};
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
parsed_values.append(parsed_value.release_nonnull());
|
||||
if (!tokens.has_next_token())
|
||||
break;
|
||||
}
|
||||
|
||||
if (swap_order)
|
||||
swap(parsed_values[0], parsed_values[1]);
|
||||
|
||||
transaction.commit();
|
||||
return StyleValueList::create(move(parsed_values), StyleValueList::Separator::Space);
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/css-transforms-1/#transform-property
|
||||
RefPtr<CSSStyleValue const> Parser::parse_transform_value(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue