Skip to content

Truly independent web browser

LibWeb: Reify single-keyword style values as CSSKeywordValue

Andreas Kling5b4a406ff653
diff --git a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
index aa32cf55426..b5127678031 100644
--- a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
+++ b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
@@ -11,6 +11,7 @@
#include <AK/Utf16StringBuilder.h>
#include <LibGfx/Font/Font.h>
#include <LibGfx/Font/FontStyleMapping.h>
+#include <LibWeb/CSS/CSSKeywordValue.h>
#include <LibWeb/CSS/CSSStyleValue.h>
#include <LibWeb/CSS/ComputedValues.h>
#include <LibWeb/CSS/Parser/Parser.h>
@@ -522,6 +523,16 @@ GC::Ref<CSSStyleValue> StyleValue::reify(Utf16FlyString const& associated_proper
default:
break;
}
+
+ // AD-HOC: Some values that are just a single keyword are represented by a more specific type, for example
+ // `font-style: italic`, `grid-auto-flow: row` or `font-variant-numeric: ordinal`. Reify those as the
+ // keyword. Colors and shorthands are left alone, as they are not keywords on their own.
+ if (type() != Type::Color && type() != Type::Shorthand) {
+ auto serialized_value = to_utf16_string(SerializationMode::Normal);
+ if (keyword_from_string(serialized_value).has_value())
+ return CSSKeywordValue::create(Utf16FlyString { serialized_value });
+ }
+
return default_reify(associated_property);
}
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-style.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-style.txt
index 24822d534a6..00cb24add70 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-style.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-style.txt
@@ -2,16 +2,15 @@ Harness status: OK
Found 34 tests
-31 Pass
-3 Fail
+34 Pass
Pass Can set 'font-style' to CSS-wide keywords: initial
Pass Can set 'font-style' to CSS-wide keywords: inherit
Pass Can set 'font-style' to CSS-wide keywords: unset
Pass Can set 'font-style' to CSS-wide keywords: revert
Pass Can set 'font-style' to var() references: var(--A)
-Fail Can set 'font-style' to the 'normal' keyword: normal
-Fail Can set 'font-style' to the 'italic' keyword: italic
-Fail Can set 'font-style' to the 'oblique' keyword: oblique
+Pass Can set 'font-style' to the 'normal' keyword: normal
+Pass Can set 'font-style' to the 'italic' keyword: italic
+Pass Can set 'font-style' to the 'oblique' keyword: oblique
Pass Setting 'font-style' to a length: 0px throws TypeError
Pass Setting 'font-style' to a length: -3.14em throws TypeError
Pass Setting 'font-style' to a length: 3.14cm throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-east-asian.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-east-asian.txt
index 18daae768eb..9eb74686be3 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-east-asian.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-east-asian.txt
@@ -2,23 +2,22 @@ Harness status: OK
Found 43 tests
-34 Pass
-9 Fail
+43 Pass
Pass Can set 'font-variant-east-asian' to CSS-wide keywords: initial
Pass Can set 'font-variant-east-asian' to CSS-wide keywords: inherit
Pass Can set 'font-variant-east-asian' to CSS-wide keywords: unset
Pass Can set 'font-variant-east-asian' to CSS-wide keywords: revert
Pass Can set 'font-variant-east-asian' to var() references: var(--A)
Pass Can set 'font-variant-east-asian' to the 'normal' keyword: normal
-Fail Can set 'font-variant-east-asian' to the 'jis78' keyword: jis78
-Fail Can set 'font-variant-east-asian' to the 'jis83' keyword: jis83
-Fail Can set 'font-variant-east-asian' to the 'jis90' keyword: jis90
-Fail Can set 'font-variant-east-asian' to the 'jis04' keyword: jis04
-Fail Can set 'font-variant-east-asian' to the 'simplified' keyword: simplified
-Fail Can set 'font-variant-east-asian' to the 'traditional' keyword: traditional
-Fail Can set 'font-variant-east-asian' to the 'full-width' keyword: full-width
-Fail Can set 'font-variant-east-asian' to the 'proportional-width' keyword: proportional-width
-Fail Can set 'font-variant-east-asian' to the 'ruby' keyword: ruby
+Pass Can set 'font-variant-east-asian' to the 'jis78' keyword: jis78
+Pass Can set 'font-variant-east-asian' to the 'jis83' keyword: jis83
+Pass Can set 'font-variant-east-asian' to the 'jis90' keyword: jis90
+Pass Can set 'font-variant-east-asian' to the 'jis04' keyword: jis04
+Pass Can set 'font-variant-east-asian' to the 'simplified' keyword: simplified
+Pass Can set 'font-variant-east-asian' to the 'traditional' keyword: traditional
+Pass Can set 'font-variant-east-asian' to the 'full-width' keyword: full-width
+Pass Can set 'font-variant-east-asian' to the 'proportional-width' keyword: proportional-width
+Pass Can set 'font-variant-east-asian' to the 'ruby' keyword: ruby
Pass Setting 'font-variant-east-asian' to a length: 0px throws TypeError
Pass Setting 'font-variant-east-asian' to a length: -3.14em throws TypeError
Pass Setting 'font-variant-east-asian' to a length: 3.14cm throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-ligatures.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-ligatures.txt
index ed660b39970..6d1489c4e1b 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-ligatures.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-ligatures.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 43 tests
-35 Pass
-8 Fail
+43 Pass
Pass Can set 'font-variant-ligatures' to CSS-wide keywords: initial
Pass Can set 'font-variant-ligatures' to CSS-wide keywords: inherit
Pass Can set 'font-variant-ligatures' to CSS-wide keywords: unset
@@ -11,14 +10,14 @@ Pass Can set 'font-variant-ligatures' to CSS-wide keywords: revert
Pass Can set 'font-variant-ligatures' to var() references: var(--A)
Pass Can set 'font-variant-ligatures' to the 'normal' keyword: normal
Pass Can set 'font-variant-ligatures' to the 'none' keyword: none
-Fail Can set 'font-variant-ligatures' to the 'common-ligatures' keyword: common-ligatures
-Fail Can set 'font-variant-ligatures' to the 'no-common-ligatures' keyword: no-common-ligatures
-Fail Can set 'font-variant-ligatures' to the 'discretionary-ligatures' keyword: discretionary-ligatures
-Fail Can set 'font-variant-ligatures' to the 'no-discretionary-ligatures' keyword: no-discretionary-ligatures
-Fail Can set 'font-variant-ligatures' to the 'historical-ligatures' keyword: historical-ligatures
-Fail Can set 'font-variant-ligatures' to the 'no-historical-ligatures' keyword: no-historical-ligatures
-Fail Can set 'font-variant-ligatures' to the 'contextual' keyword: contextual
-Fail Can set 'font-variant-ligatures' to the 'no-contextual' keyword: no-contextual
+Pass Can set 'font-variant-ligatures' to the 'common-ligatures' keyword: common-ligatures
+Pass Can set 'font-variant-ligatures' to the 'no-common-ligatures' keyword: no-common-ligatures
+Pass Can set 'font-variant-ligatures' to the 'discretionary-ligatures' keyword: discretionary-ligatures
+Pass Can set 'font-variant-ligatures' to the 'no-discretionary-ligatures' keyword: no-discretionary-ligatures
+Pass Can set 'font-variant-ligatures' to the 'historical-ligatures' keyword: historical-ligatures
+Pass Can set 'font-variant-ligatures' to the 'no-historical-ligatures' keyword: no-historical-ligatures
+Pass Can set 'font-variant-ligatures' to the 'contextual' keyword: contextual
+Pass Can set 'font-variant-ligatures' to the 'no-contextual' keyword: no-contextual
Pass Setting 'font-variant-ligatures' to a length: 0px throws TypeError
Pass Setting 'font-variant-ligatures' to a length: -3.14em throws TypeError
Pass Setting 'font-variant-ligatures' to a length: 3.14cm throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-numeric.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-numeric.txt
index 3e4b3f0c89e..deff9216abb 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-numeric.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/font-variant-numeric.txt
@@ -2,22 +2,21 @@ Harness status: OK
Found 42 tests
-34 Pass
-8 Fail
+42 Pass
Pass Can set 'font-variant-numeric' to CSS-wide keywords: initial
Pass Can set 'font-variant-numeric' to CSS-wide keywords: inherit
Pass Can set 'font-variant-numeric' to CSS-wide keywords: unset
Pass Can set 'font-variant-numeric' to CSS-wide keywords: revert
Pass Can set 'font-variant-numeric' to var() references: var(--A)
Pass Can set 'font-variant-numeric' to the 'normal' keyword: normal
-Fail Can set 'font-variant-numeric' to the 'lining-nums' keyword: lining-nums
-Fail Can set 'font-variant-numeric' to the 'oldstyle-nums' keyword: oldstyle-nums
-Fail Can set 'font-variant-numeric' to the 'proportional-nums' keyword: proportional-nums
-Fail Can set 'font-variant-numeric' to the 'tabular-nums' keyword: tabular-nums
-Fail Can set 'font-variant-numeric' to the 'diagonal-fractions' keyword: diagonal-fractions
-Fail Can set 'font-variant-numeric' to the 'stacked-fractions' keyword: stacked-fractions
-Fail Can set 'font-variant-numeric' to the 'ordinal' keyword: ordinal
-Fail Can set 'font-variant-numeric' to the 'slashed-zero' keyword: slashed-zero
+Pass Can set 'font-variant-numeric' to the 'lining-nums' keyword: lining-nums
+Pass Can set 'font-variant-numeric' to the 'oldstyle-nums' keyword: oldstyle-nums
+Pass Can set 'font-variant-numeric' to the 'proportional-nums' keyword: proportional-nums
+Pass Can set 'font-variant-numeric' to the 'tabular-nums' keyword: tabular-nums
+Pass Can set 'font-variant-numeric' to the 'diagonal-fractions' keyword: diagonal-fractions
+Pass Can set 'font-variant-numeric' to the 'stacked-fractions' keyword: stacked-fractions
+Pass Can set 'font-variant-numeric' to the 'ordinal' keyword: ordinal
+Pass Can set 'font-variant-numeric' to the 'slashed-zero' keyword: slashed-zero
Pass Setting 'font-variant-numeric' to a length: 0px throws TypeError
Pass Setting 'font-variant-numeric' to a length: -3.14em throws TypeError
Pass Setting 'font-variant-numeric' to a length: 3.14cm throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/grid-auto-columns-rows.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/grid-auto-columns-rows.txt
index 9c8bb949dcf..c0e9decf6bc 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/grid-auto-columns-rows.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/grid-auto-columns-rows.txt
@@ -2,16 +2,16 @@ Harness status: OK
Found 72 tests
-60 Pass
-12 Fail
+66 Pass
+6 Fail
Pass Can set 'grid-auto-columns' to CSS-wide keywords: initial
Pass Can set 'grid-auto-columns' to CSS-wide keywords: inherit
Pass Can set 'grid-auto-columns' to CSS-wide keywords: unset
Pass Can set 'grid-auto-columns' to CSS-wide keywords: revert
Pass Can set 'grid-auto-columns' to var() references: var(--A)
-Fail Can set 'grid-auto-columns' to the 'min-content' keyword: min-content
-Fail Can set 'grid-auto-columns' to the 'max-content' keyword: max-content
-Fail Can set 'grid-auto-columns' to the 'auto' keyword: auto
+Pass Can set 'grid-auto-columns' to the 'min-content' keyword: min-content
+Pass Can set 'grid-auto-columns' to the 'max-content' keyword: max-content
+Pass Can set 'grid-auto-columns' to the 'auto' keyword: auto
Pass Can set 'grid-auto-columns' to a length: 0px
Pass Can set 'grid-auto-columns' to a length: -3.14em
Pass Can set 'grid-auto-columns' to a length: 3.14cm
@@ -45,9 +45,9 @@ Pass Can set 'grid-auto-rows' to CSS-wide keywords: inherit
Pass Can set 'grid-auto-rows' to CSS-wide keywords: unset
Pass Can set 'grid-auto-rows' to CSS-wide keywords: revert
Pass Can set 'grid-auto-rows' to var() references: var(--A)
-Fail Can set 'grid-auto-rows' to the 'min-content' keyword: min-content
-Fail Can set 'grid-auto-rows' to the 'max-content' keyword: max-content
-Fail Can set 'grid-auto-rows' to the 'auto' keyword: auto
+Pass Can set 'grid-auto-rows' to the 'min-content' keyword: min-content
+Pass Can set 'grid-auto-rows' to the 'max-content' keyword: max-content
+Pass Can set 'grid-auto-rows' to the 'auto' keyword: auto
Pass Can set 'grid-auto-rows' to a length: 0px
Pass Can set 'grid-auto-rows' to a length: -3.14em
Pass Can set 'grid-auto-rows' to a length: 3.14cm
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/grid-auto-flow.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/grid-auto-flow.txt
index 0bbafaf006a..2398344141b 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/grid-auto-flow.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/grid-auto-flow.txt
@@ -2,15 +2,14 @@ Harness status: OK
Found 34 tests
-32 Pass
-2 Fail
+34 Pass
Pass Can set 'grid-auto-flow' to CSS-wide keywords: initial
Pass Can set 'grid-auto-flow' to CSS-wide keywords: inherit
Pass Can set 'grid-auto-flow' to CSS-wide keywords: unset
Pass Can set 'grid-auto-flow' to CSS-wide keywords: revert
Pass Can set 'grid-auto-flow' to var() references: var(--A)
-Fail Can set 'grid-auto-flow' to the 'row' keyword: row
-Fail Can set 'grid-auto-flow' to the 'column' keyword: column
+Pass Can set 'grid-auto-flow' to the 'row' keyword: row
+Pass Can set 'grid-auto-flow' to the 'column' keyword: column
Pass Setting 'grid-auto-flow' to a length: 0px throws TypeError
Pass Setting 'grid-auto-flow' to a length: -3.14em throws TypeError
Pass Setting 'grid-auto-flow' to a length: 3.14cm throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/scrollbar-gutter.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/scrollbar-gutter.txt
index d70c98bf399..49af14c2cd9 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/scrollbar-gutter.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/scrollbar-gutter.txt
@@ -2,15 +2,14 @@ Harness status: OK
Found 34 tests
-32 Pass
-2 Fail
+34 Pass
Pass Can set 'scrollbar-gutter' to CSS-wide keywords: initial
Pass Can set 'scrollbar-gutter' to CSS-wide keywords: inherit
Pass Can set 'scrollbar-gutter' to CSS-wide keywords: unset
Pass Can set 'scrollbar-gutter' to CSS-wide keywords: revert
Pass Can set 'scrollbar-gutter' to var() references: var(--A)
-Fail Can set 'scrollbar-gutter' to the 'auto' keyword: auto
-Fail Can set 'scrollbar-gutter' to the 'stable' keyword: stable
+Pass Can set 'scrollbar-gutter' to the 'auto' keyword: auto
+Pass Can set 'scrollbar-gutter' to the 'stable' keyword: stable
Pass Setting 'scrollbar-gutter' to a length: 0px throws TypeError
Pass Setting 'scrollbar-gutter' to a length: -3.14em throws TypeError
Pass Setting 'scrollbar-gutter' to a length: 3.14cm throws TypeError
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/text-underline-position.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/text-underline-position.txt
index 33818bf96a1..871916e3b9f 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/text-underline-position.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/text-underline-position.txt
@@ -2,17 +2,16 @@ Harness status: OK
Found 37 tests
-33 Pass
-4 Fail
+37 Pass
Pass Can set 'text-underline-position' to CSS-wide keywords: initial
Pass Can set 'text-underline-position' to CSS-wide keywords: inherit
Pass Can set 'text-underline-position' to CSS-wide keywords: unset
Pass Can set 'text-underline-position' to CSS-wide keywords: revert
Pass Can set 'text-underline-position' to var() references: var(--A)
-Fail Can set 'text-underline-position' to the 'auto' keyword: auto
-Fail Can set 'text-underline-position' to the 'under' keyword: under
-Fail Can set 'text-underline-position' to the 'left' keyword: left
-Fail Can set 'text-underline-position' to the 'right' keyword: right
+Pass Can set 'text-underline-position' to the 'auto' keyword: auto
+Pass Can set 'text-underline-position' to the 'under' keyword: under
+Pass Can set 'text-underline-position' to the 'left' keyword: left
+Pass Can set 'text-underline-position' to the 'right' keyword: right
Pass Setting 'text-underline-position' to a length: 0px throws TypeError
Pass Setting 'text-underline-position' to a length: -3.14em throws TypeError
Pass Setting 'text-underline-position' to a length: 3.14cm throws TypeError