Skip to content

Truly independent web browser

LibWeb: Add the position-try shorthand

Andreas Kling1d9e90b847b8
diff --git a/Libraries/LibWeb/CSS/Properties.json b/Libraries/LibWeb/CSS/Properties.json
index e45bb2747f4..3adbd8d1d50 100644
--- a/Libraries/LibWeb/CSS/Properties.json
+++ b/Libraries/LibWeb/CSS/Properties.json
@@ -4236,6 +4236,13 @@
"none"
]
},
+ "position-try": {
+ "initial": "normal none",
+ "longhands": [
+ "position-try-order",
+ "position-try-fallbacks"
+ ]
+ },
"position-try-fallbacks": {
"style-group": "AnchorValues",
"animation-type": "discrete",
diff --git a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
index 6f31ff9d73b..47a3921458b 100644
--- a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
+++ b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
@@ -4521,6 +4521,38 @@ fn parse_container_shorthand(context: &ParseContext, values: &[ComponentValue])
)))
}
+// https://drafts.csswg.org/css-anchor-position-1/#position-try-prop
+// <'position-try-order'>? <'position-try-fallbacks'>
+fn parse_position_try_shorthand(context: &ParseContext, values: &[ComponentValue]) -> ParseOutcome {
+ let first = values.iter().position(|value| !value.is_whitespace());
+ let order_and_fallbacks = first.and_then(|first| {
+ let ParseOutcome::Parsed(order) =
+ parse_css_value(context, property_id::POSITION_TRY_ORDER, &values[first..=first])
+ else {
+ return None;
+ };
+ Some(((*order).clone(), &values[first + 1..]))
+ });
+ // If <'position-try-order'> is omitted, it's set to the property's initial value.
+ let (order, fallback_values) = match order_and_fallbacks {
+ Some(parsed) => parsed,
+ None => match parse_initial_longhand(context, property_id::POSITION_TRY_ORDER) {
+ Some(order) => (order, values),
+ None => return ParseOutcome::Invalid,
+ },
+ };
+ let ParseOutcome::Parsed(fallbacks) =
+ parse_css_value(context, property_id::POSITION_TRY_FALLBACKS, fallback_values)
+ else {
+ return ParseOutcome::Invalid;
+ };
+ ParseOutcome::Parsed(shared_style_value(shorthand_value(
+ property_id::POSITION_TRY,
+ longhands_for_shorthand(property_id::POSITION_TRY).to_vec(),
+ vec![order, (*fallbacks).clone()],
+ )))
+}
+
fn parse_place_shorthand(context: &ParseContext, property: u16, values: &[ComponentValue]) -> ParseOutcome {
let (align, justify) = match property {
property_id::PLACE_CONTENT => (property_id::ALIGN_CONTENT, property_id::JUSTIFY_CONTENT),
@@ -5931,6 +5963,9 @@ fn parse_css_value_after_substitution_scan(
if property_id == property_id::CONTAINER {
return parse_container_shorthand(context, values);
}
+ if property_id == property_id::POSITION_TRY {
+ return parse_position_try_shorthand(context, values);
+ }
let outcome = parse_place_shorthand(context, property_id, values);
if !matches!(outcome, ParseOutcome::NotHandled) {
return outcome;
diff --git a/Libraries/LibWeb/Rust/src/css/serialize.rs b/Libraries/LibWeb/Rust/src/css/serialize.rs
index b2d9a8977f5..5afdb7a3621 100644
--- a/Libraries/LibWeb/Rust/src/css/serialize.rs
+++ b/Libraries/LibWeb/Rust/src/css/serialize.rs
@@ -3129,6 +3129,19 @@ fn serialize_shorthand(
}
return;
}
+ if shorthand_property == property_id::POSITION_TRY {
+ let (Some(order), Some(fallbacks)) = (
+ longhand(property_id::POSITION_TRY_ORDER),
+ longhand(property_id::POSITION_TRY_FALLBACKS),
+ ) else {
+ unreachable!("Shorthand style values must have valid value graphs");
+ };
+ if !matches!(order, StyleValueData::Keyword { keyword: code } if *code == keyword::NORMAL) {
+ serialize_style_value(sink, order, mode);
+ sink.push_ascii(" ");
+ }
+ return serialize_style_value(sink, fallbacks, mode);
+ }
if shorthand_property == property_id::GRID_COLUMN || shorthand_property == property_id::GRID_ROW {
let (start_id, end_id) = if shorthand_property == property_id::GRID_COLUMN {
(property_id::GRID_COLUMN_START, property_id::GRID_COLUMN_END)
diff --git a/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt b/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt
index 4e64b081b38..2432a631b27 100644
--- a/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt
+++ b/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt
@@ -811,6 +811,8 @@ All supported properties and their default values exposed from CSSStylePropertie
'position-anchor': 'normal'
'positionArea': 'none'
'position-area': 'none'
+'positionTry': 'none'
+'position-try': 'none'
'positionTryFallbacks': 'none'
'position-try-fallbacks': 'none'
'positionTryOrder': 'normal'
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/parsing/position-try-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/parsing/position-try-computed.txt
index d8ca4cea834..b56b3f0e180 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/parsing/position-try-computed.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/parsing/position-try-computed.txt
@@ -2,13 +2,13 @@ Harness status: OK
Found 9 tests
-9 Fail
-Fail Property position-try value 'none'
-Fail Property position-try value 'normal none'
-Fail Property position-try value 'flip-block'
-Fail Property position-try value 'flip-y'
-Fail Property position-try value 'most-width none'
-Fail Property position-try value 'most-height flip-block, flip-inline'
-Fail Property position-try value 'most-height flip-y, flip-x'
-Fail Property position-try value 'most-width --foo, --bar'
-Fail Property position-try value 'normal --foo'
\ No newline at end of file
+9 Pass
+Pass Property position-try value 'none'
+Pass Property position-try value 'normal none'
+Pass Property position-try value 'flip-block'
+Pass Property position-try value 'flip-y'
+Pass Property position-try value 'most-width none'
+Pass Property position-try value 'most-height flip-block, flip-inline'
+Pass Property position-try value 'most-height flip-y, flip-x'
+Pass Property position-try value 'most-width --foo, --bar'
+Pass Property position-try value 'normal --foo'
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/parsing/position-try-parsing.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/parsing/position-try-parsing.txt
index 6c12542c85b..a7d475a0e2b 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/parsing/position-try-parsing.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/parsing/position-try-parsing.txt
@@ -2,40 +2,39 @@ Harness status: OK
Found 35 tests
-4 Pass
-31 Fail
-Fail e.style['position-try'] = "flip-inline" should set the property value
-Fail e.style['position-try'] = "flip-y" should set the property value
-Fail e.style['position-try'] = "most-height none" should set the property value
-Fail e.style['position-try'] = "--bar, --baz" should set the property value
-Fail e.style['position-try'] = "most-inline-size --baz, flip-inline" should set the property value
-Fail e.style['position-try'] = "most-block-size flip-inline flip-block, --bar, --baz" should set the property value
-Fail e.style['position-try'] = "most-width flip-y flip-x, --foo, --bar" should set the property value
-Fail e.style['position-try'] = "normal none" should set the property value
-Fail e.style['position-try'] = "most-width none" should set the property value
-Fail e.style['position-try'] = "normal --foo" should set the property value
+35 Pass
+Pass e.style['position-try'] = "flip-inline" should set the property value
+Pass e.style['position-try'] = "flip-y" should set the property value
+Pass e.style['position-try'] = "most-height none" should set the property value
+Pass e.style['position-try'] = "--bar, --baz" should set the property value
+Pass e.style['position-try'] = "most-inline-size --baz, flip-inline" should set the property value
+Pass e.style['position-try'] = "most-block-size flip-inline flip-block, --bar, --baz" should set the property value
+Pass e.style['position-try'] = "most-width flip-y flip-x, --foo, --bar" should set the property value
+Pass e.style['position-try'] = "normal none" should set the property value
+Pass e.style['position-try'] = "most-width none" should set the property value
+Pass e.style['position-try'] = "normal --foo" should set the property value
Pass e.style['position-try'] = "normal --foo, most-width --bar" should not set the property value
Pass e.style['position-try'] = "none normal" should not set the property value
Pass e.style['position-try'] = "flip-block most-height" should not set the property value
Pass e.style['position-try'] = "most-height, flip-start" should not set the property value
-Fail e.style['position-try'] = "flip-inline" should set position-try-fallbacks
-Fail e.style['position-try'] = "flip-inline" should set position-try-order
-Fail e.style['position-try'] = "flip-inline" should not set unrelated longhands
-Fail e.style['position-try'] = "flip-y" should set position-try-fallbacks
-Fail e.style['position-try'] = "flip-y" should set position-try-order
-Fail e.style['position-try'] = "flip-y" should not set unrelated longhands
-Fail e.style['position-try'] = "most-width none" should set position-try-fallbacks
-Fail e.style['position-try'] = "most-width none" should set position-try-order
-Fail e.style['position-try'] = "most-width none" should not set unrelated longhands
-Fail e.style['position-try'] = "--foo, --bar" should set position-try-fallbacks
-Fail e.style['position-try'] = "--foo, --bar" should set position-try-order
-Fail e.style['position-try'] = "--foo, --bar" should not set unrelated longhands
-Fail e.style['position-try'] = "most-inline-size --foo, flip-inline" should set position-try-fallbacks
-Fail e.style['position-try'] = "most-inline-size --foo, flip-inline" should set position-try-order
-Fail e.style['position-try'] = "most-inline-size --foo, flip-inline" should not set unrelated longhands
-Fail e.style['position-try'] = "most-inline-size flip-inline flip-block, --foo, --bar" should set position-try-fallbacks
-Fail e.style['position-try'] = "most-inline-size flip-inline flip-block, --foo, --bar" should set position-try-order
-Fail e.style['position-try'] = "most-inline-size flip-inline flip-block, --foo, --bar" should not set unrelated longhands
-Fail e.style['position-try'] = "most-width flip-y flip-x, --foo, --bar" should set position-try-fallbacks
-Fail e.style['position-try'] = "most-width flip-y flip-x, --foo, --bar" should set position-try-order
-Fail e.style['position-try'] = "most-width flip-y flip-x, --foo, --bar" should not set unrelated longhands
\ No newline at end of file
+Pass e.style['position-try'] = "flip-inline" should set position-try-fallbacks
+Pass e.style['position-try'] = "flip-inline" should set position-try-order
+Pass e.style['position-try'] = "flip-inline" should not set unrelated longhands
+Pass e.style['position-try'] = "flip-y" should set position-try-fallbacks
+Pass e.style['position-try'] = "flip-y" should set position-try-order
+Pass e.style['position-try'] = "flip-y" should not set unrelated longhands
+Pass e.style['position-try'] = "most-width none" should set position-try-fallbacks
+Pass e.style['position-try'] = "most-width none" should set position-try-order
+Pass e.style['position-try'] = "most-width none" should not set unrelated longhands
+Pass e.style['position-try'] = "--foo, --bar" should set position-try-fallbacks
+Pass e.style['position-try'] = "--foo, --bar" should set position-try-order
+Pass e.style['position-try'] = "--foo, --bar" should not set unrelated longhands
+Pass e.style['position-try'] = "most-inline-size --foo, flip-inline" should set position-try-fallbacks
+Pass e.style['position-try'] = "most-inline-size --foo, flip-inline" should set position-try-order
+Pass e.style['position-try'] = "most-inline-size --foo, flip-inline" should not set unrelated longhands
+Pass e.style['position-try'] = "most-inline-size flip-inline flip-block, --foo, --bar" should set position-try-fallbacks
+Pass e.style['position-try'] = "most-inline-size flip-inline flip-block, --foo, --bar" should set position-try-order
+Pass e.style['position-try'] = "most-inline-size flip-inline flip-block, --foo, --bar" should not set unrelated longhands
+Pass e.style['position-try'] = "most-width flip-y flip-x, --foo, --bar" should set position-try-fallbacks
+Pass e.style['position-try'] = "most-width flip-y flip-x, --foo, --bar" should set position-try-order
+Pass e.style['position-try'] = "most-width flip-y flip-x, --foo, --bar" should not set unrelated longhands
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/position-try-order-basic.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/position-try-order-basic.txt
index 43bb6cb45c5..bcf01ce1832 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/position-try-order-basic.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/position-try-order-basic.txt
@@ -2,38 +2,38 @@ Harness status: OK
Found 27 tests
-27 Fail
-Fail --right | --right
-Fail --left | --left
-Fail --top | --top
-Fail --bottom | --bottom
-Fail --right, --left, --bottom, --top | --right
-Fail normal --right, --left, --bottom, --top | --right
-Fail normal --top, --left, --bottom, --right | --top
-Fail most-block-size --right, --left | --right
-Fail most-height --right, --left | --right
-Fail most-inline-size --right, --left | --left
-Fail most-width --right, --left | --left
-Fail most-inline-size --bottom, --top | --bottom
-Fail most-width --bottom, --top | --bottom
-Fail most-block-size --bottom, --top | --top
-Fail most-height --bottom, --top | --top
-Fail most-inline-size --right, --left, --bottom, --top | --bottom
-Fail most-inline-size --right, --left, --top, --bottom | --top
-Fail most-block-size --bottom, --top, --right, --left | --right
-Fail most-block-size --bottom, --top, --left, --right | --left
-Fail most-inline-size --left-sweep, --bottom-sweep | --left-sweep
-Fail most-inline-size --bottom-sweep, --left-sweep | --bottom-sweep
-Fail most-block-size --left-sweep, --bottom-sweep | --left-sweep
-Fail most-block-size --bottom-sweep, --left-sweep | --left-sweep
-Fail most-inline-size --right-sweep, --left-sweep, --bottom-sweep, --top-sweep | --left-sweep
-Fail most-block-size --right-sweep, --left-sweep, --bottom-sweep, --top-sweep | --top-sweep
-Fail most-inline-size
+27 Pass
+Pass --right | --right
+Pass --left | --left
+Pass --top | --top
+Pass --bottom | --bottom
+Pass --right, --left, --bottom, --top | --right
+Pass normal --right, --left, --bottom, --top | --right
+Pass normal --top, --left, --bottom, --right | --top
+Pass most-block-size --right, --left | --right
+Pass most-height --right, --left | --right
+Pass most-inline-size --right, --left | --left
+Pass most-width --right, --left | --left
+Pass most-inline-size --bottom, --top | --bottom
+Pass most-width --bottom, --top | --bottom
+Pass most-block-size --bottom, --top | --top
+Pass most-height --bottom, --top | --top
+Pass most-inline-size --right, --left, --bottom, --top | --bottom
+Pass most-inline-size --right, --left, --top, --bottom | --top
+Pass most-block-size --bottom, --top, --right, --left | --right
+Pass most-block-size --bottom, --top, --left, --right | --left
+Pass most-inline-size --left-sweep, --bottom-sweep | --left-sweep
+Pass most-inline-size --bottom-sweep, --left-sweep | --bottom-sweep
+Pass most-block-size --left-sweep, --bottom-sweep | --left-sweep
+Pass most-block-size --bottom-sweep, --left-sweep | --left-sweep
+Pass most-inline-size --right-sweep, --left-sweep, --bottom-sweep, --top-sweep | --left-sweep
+Pass most-block-size --right-sweep, --left-sweep, --bottom-sweep, --top-sweep | --top-sweep
+Pass most-inline-size
--right-sweep, --left-sweep, --bottom-sweep, --top-sweep,
/* --right, --left, --bottom, --top */
--bottom
| --bottom
-Fail most-block-size
+Pass most-block-size
--right-sweep, --left-sweep, --bottom-sweep, --top-sweep,
/* --right, --left, --bottom, --top */
--right
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/position-try-order-position-area.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/position-try-order-position-area.txt
index dfb5eb60fd6..c2caa68b813 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/position-try-order-position-area.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/position-try-order-position-area.txt
@@ -2,38 +2,38 @@ Harness status: OK
Found 27 tests
-27 Fail
-Fail --right | --right
-Fail --left | --left
-Fail --top | --top
-Fail --bottom | --bottom
-Fail --right, --left, --bottom, --top | --right
-Fail normal --right, --left, --bottom, --top | --right
-Fail normal --top, --left, --bottom, --right | --top
-Fail most-block-size --right, --left | --right
-Fail most-height --right, --left | --right
-Fail most-inline-size --right, --left | --left
-Fail most-width --right, --left | --left
-Fail most-inline-size --bottom, --top | --bottom
-Fail most-width --bottom, --top | --bottom
-Fail most-block-size --bottom, --top | --top
-Fail most-height --bottom, --top | --top
-Fail most-inline-size --right, --left, --bottom, --top | --bottom
-Fail most-inline-size --right, --left, --top, --bottom | --top
-Fail most-block-size --bottom, --top, --right, --left | --right
-Fail most-block-size --bottom, --top, --left, --right | --left
-Fail most-inline-size --left-sweep, --bottom-sweep | --left-sweep
-Fail most-inline-size --bottom-sweep, --left-sweep | --bottom-sweep
-Fail most-block-size --left-sweep, --bottom-sweep | --left-sweep
-Fail most-block-size --bottom-sweep, --left-sweep | --left-sweep
-Fail most-inline-size --right-sweep, --left-sweep, --bottom-sweep, --top-sweep | --left-sweep
-Fail most-block-size --right-sweep, --left-sweep, --bottom-sweep, --top-sweep | --top-sweep
-Fail most-inline-size
+27 Pass
+Pass --right | --right
+Pass --left | --left
+Pass --top | --top
+Pass --bottom | --bottom
+Pass --right, --left, --bottom, --top | --right
+Pass normal --right, --left, --bottom, --top | --right
+Pass normal --top, --left, --bottom, --right | --top
+Pass most-block-size --right, --left | --right
+Pass most-height --right, --left | --right
+Pass most-inline-size --right, --left | --left
+Pass most-width --right, --left | --left
+Pass most-inline-size --bottom, --top | --bottom
+Pass most-width --bottom, --top | --bottom
+Pass most-block-size --bottom, --top | --top
+Pass most-height --bottom, --top | --top
+Pass most-inline-size --right, --left, --bottom, --top | --bottom
+Pass most-inline-size --right, --left, --top, --bottom | --top
+Pass most-block-size --bottom, --top, --right, --left | --right
+Pass most-block-size --bottom, --top, --left, --right | --left
+Pass most-inline-size --left-sweep, --bottom-sweep | --left-sweep
+Pass most-inline-size --bottom-sweep, --left-sweep | --bottom-sweep
+Pass most-block-size --left-sweep, --bottom-sweep | --left-sweep
+Pass most-block-size --bottom-sweep, --left-sweep | --left-sweep
+Pass most-inline-size --right-sweep, --left-sweep, --bottom-sweep, --top-sweep | --left-sweep
+Pass most-block-size --right-sweep, --left-sweep, --bottom-sweep, --top-sweep | --top-sweep
+Pass most-inline-size
--right-sweep, --left-sweep, --bottom-sweep, --top-sweep,
/* --right, --left, --bottom, --top */
--bottom
| --bottom
-Fail most-block-size
+Pass most-block-size
--right-sweep, --left-sweep, --bottom-sweep, --top-sweep,
/* --right, --left, --bottom, --top */
--right