[CSS Container Queries] Parsing support for container shorthand property
https://bugs.webkit.org/show_bug.cgi?id=235582

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/css/css-contain/container-queries/container-computed-expected.txt:

Source/WebCore:

https://drafts.csswg.org/css-contain-3/#container-shorthand

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::valueForPropertyInStyle):
* css/CSSProperties.json:
* css/parser/CSSPropertyParser.cpp:
(WebCore::CSSPropertyParser::consumeContainerShorthand):
(WebCore::CSSPropertyParser::parseShorthand):
* css/parser/CSSPropertyParser.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@288576 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/imported/w3c/ChangeLog b/LayoutTests/imported/w3c/ChangeLog
index eaa6af6..694d051 100644
--- a/LayoutTests/imported/w3c/ChangeLog
+++ b/LayoutTests/imported/w3c/ChangeLog
@@ -1,3 +1,12 @@
+2022-01-25  Antti Koivisto  <antti@apple.com>
+
+        [CSS Container Queries] Parsing support for container shorthand property
+        https://bugs.webkit.org/show_bug.cgi?id=235582
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/css/css-contain/container-queries/container-computed-expected.txt:
+
 2022-01-25  Yusuke Suzuki  <ysuzuki@apple.com>
 
         [JSC] Wasm module import should be done in sync when WebAssembly.instantiate gets module
diff --git a/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-computed-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-computed-expected.txt
index 6ec109f..14f6cb2 100644
--- a/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-computed-expected.txt
+++ b/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-computed-expected.txt
@@ -1,16 +1,16 @@
 
-FAIL Property container value 'initial' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'inherit' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'unset' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'inline-size' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'size' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'inline-size / inline-size' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'size / block-size' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'size style / name' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'inline-size state style/ name' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'inline-size / foo' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'inline-size /foo' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'inline-size/ foo' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'inline-size/foo' assert_true: container doesn't seem to be supported in the computed style expected true got false
-FAIL Property container value 'size / FoO' assert_true: container doesn't seem to be supported in the computed style expected true got false
+PASS Property container value 'initial'
+PASS Property container value 'inherit'
+PASS Property container value 'unset'
+PASS Property container value 'inline-size'
+PASS Property container value 'size'
+PASS Property container value 'inline-size / inline-size'
+PASS Property container value 'size / block-size'
+FAIL Property container value 'size style / name' assert_true: 'size style / name' is a supported value for container. expected true got false
+FAIL Property container value 'inline-size state style/ name' assert_true: 'inline-size state style/ name' is a supported value for container. expected true got false
+PASS Property container value 'inline-size / foo'
+PASS Property container value 'inline-size /foo'
+PASS Property container value 'inline-size/ foo'
+PASS Property container value 'inline-size/foo'
+PASS Property container value 'size / FoO'
 
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 32200b7..6b813cb 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,20 @@
+2022-01-25  Antti Koivisto  <antti@apple.com>
+
+        [CSS Container Queries] Parsing support for container shorthand property
+        https://bugs.webkit.org/show_bug.cgi?id=235582
+
+        Reviewed by Darin Adler.
+
+        https://drafts.csswg.org/css-contain-3/#container-shorthand
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::valueForPropertyInStyle):
+        * css/CSSProperties.json:
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::CSSPropertyParser::consumeContainerShorthand):
+        (WebCore::CSSPropertyParser::parseShorthand):
+        * css/parser/CSSPropertyParser.h:
+
 2022-01-25  Antoine Quint  <graouts@webkit.org>
 
         Deduplication for @keyframes rules should account for animation-composition
diff --git a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
index 15557ab..3354294 100644
--- a/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
+++ b/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
@@ -3625,6 +3625,13 @@
                 list->append(cssValuePool.createIdentifierValue(CSSValuePaint));
             return list;
         }
+        case CSSPropertyContainer: {
+            auto list = CSSValueList::createSlashSeparated();
+            list->append(propertyValue(CSSPropertyContainerType, DoNotUpdateLayout).releaseNonNull());
+            if (!style.containerNames().isEmpty())
+                list->append(propertyValue(CSSPropertyContainerName, DoNotUpdateLayout).releaseNonNull());
+            return list;
+        }
         case CSSPropertyContainerType:
             return CSSPrimitiveValue::create(style.containerType());
         case CSSPropertyContainerName: {
diff --git a/Source/WebCore/css/CSSProperties.json b/Source/WebCore/css/CSSProperties.json
index 1fd441b..8d6e345 100644
--- a/Source/WebCore/css/CSSProperties.json
+++ b/Source/WebCore/css/CSSProperties.json
@@ -5221,6 +5221,21 @@
                 "url": "https://drafts.csswg.org/css-contain-1/"
             }
         },
+        "container": {
+            "codegen-properties": {
+                "longhands": [
+                    "container-type",
+                    "container-name"
+                ]
+            },
+            "status": {
+                "status": "experimental"
+            },
+            "specification": {
+                "category": "css-contain",
+                "url": "https://drafts.csswg.org/css-contain-3/#container-queries"
+            }
+        },
         "container-name": {
             "codegen-properties": {
                 "settings-flag": "cssContainerQueriesEnabled",
diff --git a/Source/WebCore/css/parser/CSSPropertyParser.cpp b/Source/WebCore/css/parser/CSSPropertyParser.cpp
index 28ed1b2..6757abb 100644
--- a/Source/WebCore/css/parser/CSSPropertyParser.cpp
+++ b/Source/WebCore/css/parser/CSSPropertyParser.cpp
@@ -6151,6 +6151,33 @@
     return true;
 }
 
+bool CSSPropertyParser::consumeContainerShorthand(bool important)
+{
+    auto type = parseSingleValue(CSSPropertyContainerType);
+    if (!type)
+        return false;
+
+    bool sawSlash = false;
+
+    auto consumeSlashName = [&]() -> RefPtr<CSSValue> {
+        if (m_range.atEnd())
+            return nullptr;
+        if (!consumeSlashIncludingWhitespace(m_range))
+            return nullptr;
+        sawSlash = true;
+        return parseSingleValue(CSSPropertyContainerName);
+    };
+
+    auto name = consumeSlashName();
+
+    if (!m_range.atEnd() || (sawSlash && !name))
+        return false;
+
+    addProperty(CSSPropertyContainerType, CSSPropertyContainer, type.releaseNonNull(), important);
+    addPropertyWithImplicitDefault(CSSPropertyContainerName, CSSPropertyContainer, WTFMove(name), CSSValuePool::singleton().createImplicitInitialValue(), important);
+    return true;
+}
+
 bool CSSPropertyParser::parseShorthand(CSSPropertyID property, bool important)
 {
     switch (property) {
@@ -6384,6 +6411,8 @@
         return consumePlaceSelfShorthand(important);
     case CSSPropertyTextDecorationSkip:
         return consumeTextDecorationSkip(important);
+    case CSSPropertyContainer:
+        return consumeContainerShorthand(important);
     default:
         return false;
     }
diff --git a/Source/WebCore/css/parser/CSSPropertyParser.h b/Source/WebCore/css/parser/CSSPropertyParser.h
index 60dddfc..15fec23 100644
--- a/Source/WebCore/css/parser/CSSPropertyParser.h
+++ b/Source/WebCore/css/parser/CSSPropertyParser.h
@@ -123,6 +123,8 @@
 
     bool consumeOverscrollBehaviorShorthand(bool important);
 
+    bool consumeContainerShorthand(bool important);
+
 private:
     // Inputs:
     CSSParserTokenRange m_range;