Skip to content

Truly independent web browser

LibWeb: Add the view-transition-class property

Andreas Kling42f121a869b5
diff --git a/Libraries/LibWeb/CSS/Properties.json b/Libraries/LibWeb/CSS/Properties.json
index 5e708f8ce54..5f9f790364d 100644
--- a/Libraries/LibWeb/CSS/Properties.json
+++ b/Libraries/LibWeb/CSS/Properties.json
@@ -5591,6 +5591,21 @@
],
"multiplicity": "coordinating-list"
},
+ "view-transition-class": {
+ "style-group": "MiscResetValues",
+ "affects-layout": false,
+ "animation-type": "discrete",
+ "inherited": false,
+ "initial": "none",
+ "multiplicity": "list",
+ "requires-computation": "never",
+ "valid-types": [
+ "custom-ident ![none]"
+ ],
+ "valid-identifiers": [
+ "none"
+ ]
+ },
"view-transition-name": {
"style-group": "MiscResetValues",
"affects-layout": false,
diff --git a/Libraries/LibWeb/Rust/src/css/computed_values.rs b/Libraries/LibWeb/Rust/src/css/computed_values.rs
index 81d17f41460..95f64f7534d 100644
--- a/Libraries/LibWeb/Rust/src/css/computed_values.rs
+++ b/Libraries/LibWeb/Rust/src/css/computed_values.rs
@@ -2124,6 +2124,7 @@ pub(crate) fn group_field_descriptors(group: usize) -> &'static [GroupFieldDescr
COLUMN_RULE_WIDTH @ column_rule_width => CssPixelsNonNegative,
USER_SELECT @ user_select => EnumKeyword(enums::keyword_to_user_select),
OBJECT_POSITION => RequireInitialValue,
+ VIEW_TRANSITION_CLASS => RequireKeyword(k::NONE),
VIEW_TRANSITION_NAME => RequireKeyword(k::NONE),
TOUCH_ACTION => RequireInitialValue,
SCROLL_BEHAVIOR @ scroll_behavior => EnumKeyword(enums::keyword_to_scroll_behavior),
diff --git a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
index 280459b1f7e..69f073e7e24 100644
--- a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
+++ b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs
@@ -281,6 +281,7 @@ fn property_uses_special_keyword_parser(property: u16) -> bool {
| property_id::TRANSFORM_ORIGIN
| property_id::TRANSITION_PROPERTY
| property_id::TRANSLATE
+ | property_id::VIEW_TRANSITION_CLASS
| property_id::WHITE_SPACE
| property_id::WHITE_SPACE_TRIM
| property_id::WILL_CHANGE
@@ -2766,6 +2767,23 @@ fn parse_comma_separated_dashed_ident_list(
Some(value_list(values, 1, true))
}
+fn parse_custom_ident_list(
+ context: &ParseContext,
+ values: &[ComponentValue],
+ blacklist: &[&str],
+) -> Option<StyleValueData> {
+ let names = values
+ .iter()
+ .filter(|value| !value.is_whitespace())
+ .map(|value| parse_custom_ident_value(context, value, blacklist))
+ .collect::<Option<Vec<_>>>()?;
+ match names.as_slice() {
+ [] => None,
+ [_] => names.into_iter().next(),
+ _ => Some(value_list(names, 0, false)),
+ }
+}
+
fn parse_special_text_property(context: &ParseContext, property: u16, values: &[ComponentValue]) -> ParseOutcome {
if !matches!(
property,
@@ -2776,6 +2794,7 @@ fn parse_special_text_property(context: &ParseContext, property: u16, values: &[
| property_id::POSITION_ANCHOR
| property_id::TIMELINE_SCOPE
| property_id::TRANSITION_PROPERTY
+ | property_id::VIEW_TRANSITION_CLASS
| property_id::WILL_CHANGE
) {
return ParseOutcome::NotHandled;
@@ -2798,18 +2817,13 @@ fn parse_special_text_property(context: &ParseContext, property: u16, values: &[
}),
property_id::CONTAINER_NAME => single_value
.and_then(|value| parse_specific_keyword(value, &[keyword::NONE]))
- .or_else(|| {
- let names = values
- .iter()
- .filter(|value| !value.is_whitespace())
- .map(|value| parse_custom_ident_value(context, value, &["none", "and", "not", "or"]))
- .collect::<Option<Vec<_>>>()?;
- match names.as_slice() {
- [] => None,
- [_] => names.into_iter().next(),
- _ => Some(value_list(names, 0, false)),
- }
- }),
+ .or_else(|| parse_custom_ident_list(context, values, &["none", "and", "not", "or"])),
+ // https://drafts.csswg.org/css-view-transitions-2/#view-transition-class-prop
+ // none | <custom-ident>+
+ // none is an invalid <custom-ident> for view-transition-class, even when combined with another <custom-ident>.
+ property_id::VIEW_TRANSITION_CLASS => single_value
+ .and_then(|value| parse_specific_keyword(value, &[keyword::NONE]))
+ .or_else(|| parse_custom_ident_list(context, values, &["none"])),
property_id::FONT_LANGUAGE_OVERRIDE => single_value.and_then(|value| {
if let Some(normal) = parse_specific_keyword(value, &[keyword::NORMAL]) {
return Some(normal);
diff --git a/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-has-indexed-property-getter.txt b/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-has-indexed-property-getter.txt
index 98e8e788404..5a3834a31e3 100644
--- a/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-has-indexed-property-getter.txt
+++ b/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-has-indexed-property-getter.txt
@@ -364,6 +364,7 @@ All properties associated with getComputedStyle(document.body):
"view-timeline-axis",
"view-timeline-inset",
"view-timeline-name",
+ "view-transition-class",
"view-transition-name",
"white-space-trim",
"width",
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 cf91c1b63c9..1b52307bbbb 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
@@ -1019,6 +1019,8 @@ All supported properties and their default values exposed from CSSStylePropertie
'view-timeline-inset': 'auto'
'viewTimelineName': 'none'
'view-timeline-name': 'none'
+'viewTransitionClass': 'none'
+'view-transition-class': 'none'
'viewTransitionName': 'none'
'view-transition-name': 'none'
'visibility': 'visible'
diff --git a/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt b/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt
index af0171148be..a0bd1104c89 100644
--- a/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt
+++ b/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt
@@ -362,6 +362,7 @@ vertical-align: baseline
view-timeline-axis: block
view-timeline-inset: auto
view-timeline-name: none
+view-transition-class: none
view-transition-name: none
white-space-trim: none
width: 600px
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-view-transitions/parsing/view-transition-class-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-view-transitions/parsing/view-transition-class-computed.txt
index 105c8f1666b..44af84d87fe 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-view-transitions/parsing/view-transition-class-computed.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-view-transitions/parsing/view-transition-class-computed.txt
@@ -2,15 +2,15 @@ Harness status: OK
Found 11 tests
-11 Fail
-Fail Property view-transition-class value 'none'
-Fail Property view-transition-class value 'foo'
-Fail Property view-transition-class value 'bar'
-Fail Property view-transition-class value 'baz'
-Fail Property view-transition-class value 'foo bar'
-Fail Property view-transition-class value 'foo bar baz'
-Fail Property view-transition-class value 'unset'
-Fail Property view-transition-class value 'initial'
-Fail Property view-transition-class value 'inherit'
-Fail Property view-transition-class value 'revert'
-Fail Property view-transition-class value 'revert-layer'
\ No newline at end of file
+11 Pass
+Pass Property view-transition-class value 'none'
+Pass Property view-transition-class value 'foo'
+Pass Property view-transition-class value 'bar'
+Pass Property view-transition-class value 'baz'
+Pass Property view-transition-class value 'foo bar'
+Pass Property view-transition-class value 'foo bar baz'
+Pass Property view-transition-class value 'unset'
+Pass Property view-transition-class value 'initial'
+Pass Property view-transition-class value 'inherit'
+Pass Property view-transition-class value 'revert'
+Pass Property view-transition-class value 'revert-layer'
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-view-transitions/parsing/view-transition-class-valid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-view-transitions/parsing/view-transition-class-valid.txt
index a1b752a16ce..76ec67bf695 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-view-transitions/parsing/view-transition-class-valid.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-view-transitions/parsing/view-transition-class-valid.txt
@@ -2,10 +2,10 @@ Harness status: OK
Found 6 tests
-6 Fail
-Fail e.style['view-transition-class'] = "none" should set the property value
-Fail e.style['view-transition-class'] = "foo" should set the property value
-Fail e.style['view-transition-class'] = "bar" should set the property value
-Fail e.style['view-transition-class'] = "baz" should set the property value
-Fail e.style['view-transition-class'] = "foo bar" should set the property value
-Fail e.style['view-transition-class'] = "foo bar baz" should set the property value
\ No newline at end of file
+6 Pass
+Pass e.style['view-transition-class'] = "none" should set the property value
+Pass e.style['view-transition-class'] = "foo" should set the property value
+Pass e.style['view-transition-class'] = "bar" should set the property value
+Pass e.style['view-transition-class'] = "baz" should set the property value
+Pass e.style['view-transition-class'] = "foo bar" should set the property value
+Pass e.style['view-transition-class'] = "foo bar baz" should set the property value
\ No newline at end of file