Truly independent web browser
LibWeb: Parse Typed OM keywords into the parser's representation
Andreas Kling0a93fa265dac
diff --git a/Libraries/LibWeb/CSS/CSSKeywordValue.cpp b/Libraries/LibWeb/CSS/CSSKeywordValue.cppindex 64fc2ac3c30..2a1cff52678 100644--- a/Libraries/LibWeb/CSS/CSSKeywordValue.cpp+++ b/Libraries/LibWeb/CSS/CSSKeywordValue.cpp@@ -7,10 +7,10 @@#include "CSSKeywordValue.h"#include <LibWeb/Bindings/CSSKeywordValue.h>#include <LibWeb/CSS/Keyword.h>+#include <LibWeb/CSS/Parser/Parser.h>#include <LibWeb/CSS/PropertyNameAndID.h>#include <LibWeb/CSS/Serialize.h>#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>-#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>#include <LibWeb/WebIDL/ExceptionOr.h>@@ -99,10 +99,14 @@ WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> CSSKeywordValue::create_an_// Return the value.if (auto keyword = keyword_from_string(m_value); keyword.has_value()) {- if (!is_css_wide_keyword(*keyword)) {- // NB: Non-css-wide keyword `display` values are represented internally by DisplayStyleValue, not KeywordStyleValue.- if (property.id() == PropertyID::Display)- return DisplayStyleValue::create(Display::from_keyword(keyword.release_value()));+ // NB: Style computation expects the same internal representation that the CSS parser produces for the+ // property. For example, `display` keywords become a DisplayStyleValue, and keyword combinations like+ // `text-decoration-line` or `white-space-trim` become a list even when only one keyword is given. So we+ // parse the keyword as a value of the property to get that representation. List-valued properties are+ // instead wrapped in a list by StylePropertyMap.+ if (!is_css_wide_keyword(*keyword) && !property.is_custom_property() && !property_is_list_valued(property.id())) {+ if (auto parsed_value = parse_css_value(Parser::ParsingParams {}, m_value.view(), property.id()))+ return parsed_value.release_nonnull();}return KeywordStyleValue::create(*keyword);diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/white-space.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/white-space.txtnew file mode 100644index 00000000000..8fb378834d1--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/white-space.txt@@ -0,0 +1,150 @@+Harness status: OK++Found 144 tests++141 Pass+3 Fail+Pass Can set 'white-space-collapse' to CSS-wide keywords: initial+Pass Can set 'white-space-collapse' to CSS-wide keywords: inherit+Pass Can set 'white-space-collapse' to CSS-wide keywords: unset+Pass Can set 'white-space-collapse' to CSS-wide keywords: revert+Pass Can set 'white-space-collapse' to var() references: var(--A)+Pass Can set 'white-space-collapse' to the 'collapse' keyword: collapse+Pass Can set 'white-space-collapse' to the 'discard' keyword: discard+Pass Can set 'white-space-collapse' to the 'preserve' keyword: preserve+Pass Can set 'white-space-collapse' to the 'preserve-breaks' keyword: preserve-breaks+Pass Can set 'white-space-collapse' to the 'preserve-spaces' keyword: preserve-spaces+Pass Can set 'white-space-collapse' to the 'break-spaces' keyword: break-spaces+Pass Setting 'white-space-collapse' to a length: 0px throws TypeError+Pass Setting 'white-space-collapse' to a length: -3.14em throws TypeError+Pass Setting 'white-space-collapse' to a length: 3.14cm throws TypeError+Pass Setting 'white-space-collapse' to a length: calc(0px + 0em) throws TypeError+Pass Setting 'white-space-collapse' to a percent: 0% throws TypeError+Pass Setting 'white-space-collapse' to a percent: -3.14% throws TypeError+Pass Setting 'white-space-collapse' to a percent: 3.14% throws TypeError+Pass Setting 'white-space-collapse' to a percent: calc(0% + 0%) throws TypeError+Pass Setting 'white-space-collapse' to a time: 0s throws TypeError+Pass Setting 'white-space-collapse' to a time: -3.14ms throws TypeError+Pass Setting 'white-space-collapse' to a time: 3.14s throws TypeError+Pass Setting 'white-space-collapse' to a time: calc(0s + 0ms) throws TypeError+Pass Setting 'white-space-collapse' to an angle: 0deg throws TypeError+Pass Setting 'white-space-collapse' to an angle: 3.14rad throws TypeError+Pass Setting 'white-space-collapse' to an angle: -3.14deg throws TypeError+Pass Setting 'white-space-collapse' to an angle: calc(0rad + 0deg) throws TypeError+Pass Setting 'white-space-collapse' to a flexible length: 0fr throws TypeError+Pass Setting 'white-space-collapse' to a flexible length: 1fr throws TypeError+Pass Setting 'white-space-collapse' to a flexible length: -3.14fr throws TypeError+Pass Setting 'white-space-collapse' to a number: 0 throws TypeError+Pass Setting 'white-space-collapse' to a number: -3.14 throws TypeError+Pass Setting 'white-space-collapse' to a number: 3.14 throws TypeError+Pass Setting 'white-space-collapse' to a number: calc(2 + 3) throws TypeError+Pass Setting 'white-space-collapse' to a transform: translate(50%, 50%) throws TypeError+Pass Setting 'white-space-collapse' to a transform: perspective(10em) throws TypeError+Pass Setting 'white-space-collapse' to a transform: translate3d(0px, 1px, 2px) translate(0px, 1px) rotate3d(1, 2, 3, 45deg) rotate(45deg) scale3d(1, 2, 3) scale(1, 2) skew(1deg, 1deg) skewX(1deg) skewY(45deg) perspective(1px) matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) matrix(1, 2, 3, 4, 5, 6) throws TypeError+Pass Can set 'text-wrap-mode' to CSS-wide keywords: initial+Pass Can set 'text-wrap-mode' to CSS-wide keywords: inherit+Pass Can set 'text-wrap-mode' to CSS-wide keywords: unset+Pass Can set 'text-wrap-mode' to CSS-wide keywords: revert+Pass Can set 'text-wrap-mode' to var() references: var(--A)+Pass Can set 'text-wrap-mode' to the 'wrap' keyword: wrap+Pass Can set 'text-wrap-mode' to the 'nowrap' keyword: nowrap+Pass Setting 'text-wrap-mode' to a length: 0px throws TypeError+Pass Setting 'text-wrap-mode' to a length: -3.14em throws TypeError+Pass Setting 'text-wrap-mode' to a length: 3.14cm throws TypeError+Pass Setting 'text-wrap-mode' to a length: calc(0px + 0em) throws TypeError+Pass Setting 'text-wrap-mode' to a percent: 0% throws TypeError+Pass Setting 'text-wrap-mode' to a percent: -3.14% throws TypeError+Pass Setting 'text-wrap-mode' to a percent: 3.14% throws TypeError+Pass Setting 'text-wrap-mode' to a percent: calc(0% + 0%) throws TypeError+Pass Setting 'text-wrap-mode' to a time: 0s throws TypeError+Pass Setting 'text-wrap-mode' to a time: -3.14ms throws TypeError+Pass Setting 'text-wrap-mode' to a time: 3.14s throws TypeError+Pass Setting 'text-wrap-mode' to a time: calc(0s + 0ms) throws TypeError+Pass Setting 'text-wrap-mode' to an angle: 0deg throws TypeError+Pass Setting 'text-wrap-mode' to an angle: 3.14rad throws TypeError+Pass Setting 'text-wrap-mode' to an angle: -3.14deg throws TypeError+Pass Setting 'text-wrap-mode' to an angle: calc(0rad + 0deg) throws TypeError+Pass Setting 'text-wrap-mode' to a flexible length: 0fr throws TypeError+Pass Setting 'text-wrap-mode' to a flexible length: 1fr throws TypeError+Pass Setting 'text-wrap-mode' to a flexible length: -3.14fr throws TypeError+Pass Setting 'text-wrap-mode' to a number: 0 throws TypeError+Pass Setting 'text-wrap-mode' to a number: -3.14 throws TypeError+Pass Setting 'text-wrap-mode' to a number: 3.14 throws TypeError+Pass Setting 'text-wrap-mode' to a number: calc(2 + 3) throws TypeError+Pass Setting 'text-wrap-mode' to a transform: translate(50%, 50%) throws TypeError+Pass Setting 'text-wrap-mode' to a transform: perspective(10em) throws TypeError+Pass Setting 'text-wrap-mode' to a transform: translate3d(0px, 1px, 2px) translate(0px, 1px) rotate3d(1, 2, 3, 45deg) rotate(45deg) scale3d(1, 2, 3) scale(1, 2) skew(1deg, 1deg) skewX(1deg) skewY(45deg) perspective(1px) matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) matrix(1, 2, 3, 4, 5, 6) throws TypeError+Pass Can set 'text-wrap-style' to CSS-wide keywords: initial+Pass Can set 'text-wrap-style' to CSS-wide keywords: inherit+Pass Can set 'text-wrap-style' to CSS-wide keywords: unset+Pass Can set 'text-wrap-style' to CSS-wide keywords: revert+Pass Can set 'text-wrap-style' to var() references: var(--A)+Pass Can set 'text-wrap-style' to the 'auto' keyword: auto+Pass Can set 'text-wrap-style' to the 'balance' keyword: balance+Pass Can set 'text-wrap-style' to the 'stable' keyword: stable+Pass Can set 'text-wrap-style' to the 'pretty' keyword: pretty+Pass Setting 'text-wrap-style' to a length: 0px throws TypeError+Pass Setting 'text-wrap-style' to a length: -3.14em throws TypeError+Pass Setting 'text-wrap-style' to a length: 3.14cm throws TypeError+Pass Setting 'text-wrap-style' to a length: calc(0px + 0em) throws TypeError+Pass Setting 'text-wrap-style' to a percent: 0% throws TypeError+Pass Setting 'text-wrap-style' to a percent: -3.14% throws TypeError+Pass Setting 'text-wrap-style' to a percent: 3.14% throws TypeError+Pass Setting 'text-wrap-style' to a percent: calc(0% + 0%) throws TypeError+Pass Setting 'text-wrap-style' to a time: 0s throws TypeError+Pass Setting 'text-wrap-style' to a time: -3.14ms throws TypeError+Pass Setting 'text-wrap-style' to a time: 3.14s throws TypeError+Pass Setting 'text-wrap-style' to a time: calc(0s + 0ms) throws TypeError+Pass Setting 'text-wrap-style' to an angle: 0deg throws TypeError+Pass Setting 'text-wrap-style' to an angle: 3.14rad throws TypeError+Pass Setting 'text-wrap-style' to an angle: -3.14deg throws TypeError+Pass Setting 'text-wrap-style' to an angle: calc(0rad + 0deg) throws TypeError+Pass Setting 'text-wrap-style' to a flexible length: 0fr throws TypeError+Pass Setting 'text-wrap-style' to a flexible length: 1fr throws TypeError+Pass Setting 'text-wrap-style' to a flexible length: -3.14fr throws TypeError+Pass Setting 'text-wrap-style' to a number: 0 throws TypeError+Pass Setting 'text-wrap-style' to a number: -3.14 throws TypeError+Pass Setting 'text-wrap-style' to a number: 3.14 throws TypeError+Pass Setting 'text-wrap-style' to a number: calc(2 + 3) throws TypeError+Pass Setting 'text-wrap-style' to a transform: translate(50%, 50%) throws TypeError+Pass Setting 'text-wrap-style' to a transform: perspective(10em) throws TypeError+Pass Setting 'text-wrap-style' to a transform: translate3d(0px, 1px, 2px) translate(0px, 1px) rotate3d(1, 2, 3, 45deg) rotate(45deg) scale3d(1, 2, 3) scale(1, 2) skew(1deg, 1deg) skewX(1deg) skewY(45deg) perspective(1px) matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) matrix(1, 2, 3, 4, 5, 6) throws TypeError+Pass Can set 'white-space-trim' to CSS-wide keywords: initial+Pass Can set 'white-space-trim' to CSS-wide keywords: inherit+Pass Can set 'white-space-trim' to CSS-wide keywords: unset+Pass Can set 'white-space-trim' to CSS-wide keywords: revert+Pass Can set 'white-space-trim' to var() references: var(--A)+Pass Can set 'white-space-trim' to the 'none' keyword: none+Fail Can set 'white-space-trim' to the 'discard-before' keyword: discard-before+Fail Can set 'white-space-trim' to the 'discard-after' keyword: discard-after+Fail Can set 'white-space-trim' to the 'discard-inner' keyword: discard-inner+Pass Setting 'white-space-trim' to a length: 0px throws TypeError+Pass Setting 'white-space-trim' to a length: -3.14em throws TypeError+Pass Setting 'white-space-trim' to a length: 3.14cm throws TypeError+Pass Setting 'white-space-trim' to a length: calc(0px + 0em) throws TypeError+Pass Setting 'white-space-trim' to a percent: 0% throws TypeError+Pass Setting 'white-space-trim' to a percent: -3.14% throws TypeError+Pass Setting 'white-space-trim' to a percent: 3.14% throws TypeError+Pass Setting 'white-space-trim' to a percent: calc(0% + 0%) throws TypeError+Pass Setting 'white-space-trim' to a time: 0s throws TypeError+Pass Setting 'white-space-trim' to a time: -3.14ms throws TypeError+Pass Setting 'white-space-trim' to a time: 3.14s throws TypeError+Pass Setting 'white-space-trim' to a time: calc(0s + 0ms) throws TypeError+Pass Setting 'white-space-trim' to an angle: 0deg throws TypeError+Pass Setting 'white-space-trim' to an angle: 3.14rad throws TypeError+Pass Setting 'white-space-trim' to an angle: -3.14deg throws TypeError+Pass Setting 'white-space-trim' to an angle: calc(0rad + 0deg) throws TypeError+Pass Setting 'white-space-trim' to a flexible length: 0fr throws TypeError+Pass Setting 'white-space-trim' to a flexible length: 1fr throws TypeError+Pass Setting 'white-space-trim' to a flexible length: -3.14fr throws TypeError+Pass Setting 'white-space-trim' to a number: 0 throws TypeError+Pass Setting 'white-space-trim' to a number: -3.14 throws TypeError+Pass Setting 'white-space-trim' to a number: 3.14 throws TypeError+Pass Setting 'white-space-trim' to a number: calc(2 + 3) throws TypeError+Pass Setting 'white-space-trim' to a transform: translate(50%, 50%) throws TypeError+Pass Setting 'white-space-trim' to a transform: perspective(10em) throws TypeError+Pass Setting 'white-space-trim' to a transform: translate3d(0px, 1px, 2px) translate(0px, 1px) rotate3d(1, 2, 3, 45deg) rotate(45deg) scale3d(1, 2, 3) scale(1, 2) skew(1deg, 1deg) skewX(1deg) skewY(45deg) perspective(1px) matrix3d(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) matrix(1, 2, 3, 4, 5, 6) throws TypeError+Pass 'white-space-trim' does not support 'discard-before discard-after'+Pass 'white-space-trim' does not support 'discard-before discard-inner'+Pass 'white-space-trim' does not support 'discard-after discard-inner'+Pass 'white-space-trim' does not support 'discard-before discard-after discard-inner'\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-typed-om/the-stylepropertymap/properties/white-space.html b/Tests/LibWeb/Text/input/wpt-import/css/css-typed-om/the-stylepropertymap/properties/white-space.htmlnew file mode 100644index 00000000000..fcf03c2c028--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-typed-om/the-stylepropertymap/properties/white-space.html@@ -0,0 +1,51 @@+<!doctype html>+<meta charset="utf-8">+<title>'white-space' property</title>+<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-get">+<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-set">+<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#property-stle-value-normalization">+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<script src="../../resources/testhelper.js"></script>+<script src="resources/testsuite.js"></script>+<body>+<div id="log"></div>+<script>+'use strict';++runPropertyTests('white-space-collapse', [+ { syntax: 'collapse'},+ { syntax: 'discard' },+ { syntax: 'preserve' },+ { syntax: 'preserve-breaks' },+ { syntax: 'preserve-spaces' },+ { syntax: 'break-spaces' },+]);++runPropertyTests('text-wrap-mode', [+ { syntax: 'wrap'},+ { syntax: 'nowrap' },+]);++runPropertyTests('text-wrap-style', [+ { syntax: 'auto' },+ { syntax: 'balance' },+ { syntax: 'stable' },+ { syntax: 'pretty' },+]);++runPropertyTests('white-space-trim', [+ { syntax: 'none'},+ { syntax: 'discard-before' },+ { syntax: 'discard-after' },+ { syntax: 'discard-inner' },+]);++runUnsupportedPropertyTests('white-space-trim', [+ 'discard-before discard-after',+ 'discard-before discard-inner',+ 'discard-after discard-inner',+ 'discard-before discard-after discard-inner'+]);++</script>