Title: [292045] trunk
Revision
292045
Author
[email protected]
Date
2022-03-29 11:19:56 -0700 (Tue, 29 Mar 2022)

Log Message

[CSS Container Queries] Support CSSOM
https://bugs.webkit.org/show_bug.cgi?id=238500

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

* web-platform-tests/css/css-contain/container-queries/at-container-serialization-expected.txt:
* web-platform-tests/css/css-contain/container-queries/idlharness-expected.txt:

Source/WebCore:

Add CSSContainerRule interface.

https://drafts.csswg.org/css-contain-3/#the-csscontainerrule-interface

* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSCSSRuleCustom.cpp:
(WebCore::toJSNewlyCreated):
* css/CSSContainerRule.cpp: Added.
(WebCore::CSSContainerRule::CSSContainerRule):
(WebCore::CSSContainerRule::create):
(WebCore::CSSContainerRule::styleRuleContainer const):
(WebCore::CSSContainerRule::cssText const):
(WebCore::CSSContainerRule::conditionText const):

Implementation, the only real functionality is serialization.

* css/CSSContainerRule.h: Added.
* css/CSSContainerRule.idl: Added.

Interface.

* css/ContainerQuery.cpp:
(WebCore::CQ::serialize):
(WebCore::serialize):

Query syntax serialization support.

* css/ContainerQuery.h:
* css/ContainerQueryParser.cpp:
(WebCore::ContainerQueryParser::consumeContainerQuery):

Remember the text of unknown queries.

* css/StyleRule.cpp:
(WebCore::StyleRuleBase::createCSSOMWrapper const):

LayoutTests:

* TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (292044 => 292045)


--- trunk/LayoutTests/ChangeLog	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/LayoutTests/ChangeLog	2022-03-29 18:19:56 UTC (rev 292045)
@@ -1,3 +1,12 @@
+2022-03-29  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Support CSSOM
+        https://bugs.webkit.org/show_bug.cgi?id=238500
+
+        Reviewed by Simon Fraser.
+
+        * TestExpectations:
+
 2022-03-29  Sam Sneddon  <[email protected]>
 
         Re-import web-platform-tests/css/css-conditional

Modified: trunk/LayoutTests/TestExpectations (292044 => 292045)


--- trunk/LayoutTests/TestExpectations	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/LayoutTests/TestExpectations	2022-03-29 18:19:56 UTC (rev 292045)
@@ -4706,8 +4706,6 @@
 webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/custom-layout-container-001.https.html [ ImageOnlyFailure ]
 webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/pseudo-elements-002.html [ ImageOnlyFailure ]
 webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/svg-foreignobject-no-size-container.html [ Skip ]
-webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/at-container-serialization.html [ Skip ]
-webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/idlharness.html [ Skip ]
 
 # Flaky css-contain test
 imported/w3c/web-platform-tests/css/css-contain/content-visibility/animation-display-lock.html [ Failure Pass ]

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (292044 => 292045)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-29 18:19:56 UTC (rev 292045)
@@ -1,3 +1,13 @@
+2022-03-29  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Support CSSOM
+        https://bugs.webkit.org/show_bug.cgi?id=238500
+
+        Reviewed by Simon Fraser.
+
+        * web-platform-tests/css/css-contain/container-queries/at-container-serialization-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/idlharness-expected.txt:
+
 2022-03-29  Sam Sneddon  <[email protected]>
 
         Re-import web-platform-tests/css/css-conditional

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/at-container-serialization-expected.txt (292044 => 292045)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/at-container-serialization-expected.txt	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/at-container-serialization-expected.txt	2022-03-29 18:19:56 UTC (rev 292045)
@@ -1,5 +1,5 @@
 
-FAIL Serialization of conditionText null is not an object (evaluating 'rules[0].cssRules')
-FAIL Serialization of inner @container rule null is not an object (evaluating 'rules[0].cssRules')
-FAIL Serialization of nested @container rule null is not an object (evaluating 'rules[0].cssText')
+PASS Serialization of conditionText
+PASS Serialization of inner @container rule
+PASS Serialization of nested @container rule
 

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/idlharness-expected.txt (0 => 292045)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/idlharness-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/idlharness-expected.txt	2022-03-29 18:19:56 UTC (rev 292045)
@@ -0,0 +1,14 @@
+
+PASS idl_test setup
+PASS idl_test validation
+PASS CSSContainerRule interface: existence and properties of interface object
+PASS CSSContainerRule interface object length
+PASS CSSContainerRule interface object name
+PASS CSSContainerRule interface: existence and properties of interface prototype object
+PASS CSSContainerRule interface: existence and properties of interface prototype object's "constructor" property
+PASS CSSContainerRule interface: existence and properties of interface prototype object's @@unscopables property
+PASS CSSContainerRule must be primary interface of sheet.cssRules[0]
+PASS Stringification of sheet.cssRules[0]
+PASS CSSContainerRule must be primary interface of sheet.cssRules[0].cssRules[0]
+PASS Stringification of sheet.cssRules[0].cssRules[0]
+

Modified: trunk/Source/WebCore/CMakeLists.txt (292044 => 292045)


--- trunk/Source/WebCore/CMakeLists.txt	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/CMakeLists.txt	2022-03-29 18:19:56 UTC (rev 292045)
@@ -763,6 +763,7 @@
     crypto/parameters/RsaPssParams.idl
 
     css/CSSConditionRule.idl
+    css/CSSContainerRule.idl
     css/CSSCounterStyleRule.idl
     css/CSSFontFaceRule.idl
     css/CSSFontPaletteValuesRule.idl

Modified: trunk/Source/WebCore/ChangeLog (292044 => 292045)


--- trunk/Source/WebCore/ChangeLog	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/ChangeLog	2022-03-29 18:19:56 UTC (rev 292045)
@@ -1,3 +1,50 @@
+2022-03-29  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Support CSSOM
+        https://bugs.webkit.org/show_bug.cgi?id=238500
+
+        Reviewed by Simon Fraser.
+
+        Add CSSContainerRule interface.
+
+        https://drafts.csswg.org/css-contain-3/#the-csscontainerrule-interface
+
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSCSSRuleCustom.cpp:
+        (WebCore::toJSNewlyCreated):
+        * css/CSSContainerRule.cpp: Added.
+        (WebCore::CSSContainerRule::CSSContainerRule):
+        (WebCore::CSSContainerRule::create):
+        (WebCore::CSSContainerRule::styleRuleContainer const):
+        (WebCore::CSSContainerRule::cssText const):
+        (WebCore::CSSContainerRule::conditionText const):
+
+        Implementation, the only real functionality is serialization.
+
+        * css/CSSContainerRule.h: Added.
+        * css/CSSContainerRule.idl: Added.
+
+        Interface.
+
+        * css/ContainerQuery.cpp:
+        (WebCore::CQ::serialize):
+        (WebCore::serialize):
+
+        Query syntax serialization support.
+
+        * css/ContainerQuery.h:
+        * css/ContainerQueryParser.cpp:
+        (WebCore::ContainerQueryParser::consumeContainerQuery):
+
+        Remember the text of unknown queries.
+
+        * css/StyleRule.cpp:
+        (WebCore::StyleRuleBase::createCSSOMWrapper const):
+
 2022-03-29  Alan Bujtas  <[email protected]>
 
         RenderText::width should call FontCascade directly on single space characters

Modified: trunk/Source/WebCore/DerivedSources-input.xcfilelist (292044 => 292045)


--- trunk/Source/WebCore/DerivedSources-input.xcfilelist	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/DerivedSources-input.xcfilelist	2022-03-29 18:19:56 UTC (rev 292045)
@@ -892,6 +892,7 @@
 $(PROJECT_DIR)/crypto/parameters/RsaOaepParams.idl
 $(PROJECT_DIR)/crypto/parameters/RsaPssParams.idl
 $(PROJECT_DIR)/css/CSSConditionRule.idl
+$(PROJECT_DIR)/css/CSSContainerRule.idl
 $(PROJECT_DIR)/css/CSSCounterStyleRule.idl
 $(PROJECT_DIR)/css/CSSFontFaceRule.idl
 $(PROJECT_DIR)/css/CSSFontPaletteValuesRule.idl

Modified: trunk/Source/WebCore/DerivedSources-output.xcfilelist (292044 => 292045)


--- trunk/Source/WebCore/DerivedSources-output.xcfilelist	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/DerivedSources-output.xcfilelist	2022-03-29 18:19:56 UTC (rev 292045)
@@ -299,6 +299,8 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSColorValue.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSConditionRule.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSConditionRule.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSContainerRule.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSContainerRule.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSCounterStyleRule.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSCounterStyleRule.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCSSFontFaceRule.cpp

Modified: trunk/Source/WebCore/DerivedSources.make (292044 => 292045)


--- trunk/Source/WebCore/DerivedSources.make	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/DerivedSources.make	2022-03-29 18:19:56 UTC (rev 292045)
@@ -771,6 +771,7 @@
     $(WebCore)/crypto/parameters/RsaOaepParams.idl \
     $(WebCore)/crypto/parameters/RsaPssParams.idl \
     $(WebCore)/css/CSSConditionRule.idl \
+    $(WebCore)/css/CSSContainerRule.idl \
     $(WebCore)/css/CSSCounterStyleRule.idl \
     $(WebCore)/css/CSSFontFaceRule.idl \
     $(WebCore)/css/CSSFontPaletteValuesRule.idl \

Modified: trunk/Source/WebCore/Sources.txt (292044 => 292045)


--- trunk/Source/WebCore/Sources.txt	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/Sources.txt	2022-03-29 18:19:56 UTC (rev 292045)
@@ -715,6 +715,7 @@
 css/CSSCanvasValue.cpp
 css/CSSComputedStyleDeclaration.cpp
 css/CSSConditionRule.cpp
+css/CSSContainerRule.cpp
 css/CSSContentDistributionValue.cpp
 css/CSSCounterStyleRule.cpp
 css/CSSCrossfadeValue.cpp
@@ -2947,6 +2948,7 @@
 JSCDATASection.cpp
 JSCSSAnimation.cpp
 JSCSSConditionRule.cpp
+JSCSSContainerRule.cpp
 JSCSSCounterStyleRule.cpp
 JSCSSFontFaceRule.cpp
 JSCSSFontPaletteValuesRule.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (292044 => 292045)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-03-29 18:19:56 UTC (rev 292045)
@@ -5382,6 +5382,7 @@
 		E46B41F91CB24E70008F11DE /* ScriptDisallowedScope.h in Headers */ = {isa = PBXBuildFile; fileRef = E46B41F81CB24E70008F11DE /* ScriptDisallowedScope.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E46C794B1F13E82B00F371E1 /* StyleInvalidationFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = E4A1822F1F13BE5800FEF698 /* StyleInvalidationFunctions.h */; };
 		E47127CB163438AE00ED6F5A /* StyleInvalidator.h in Headers */ = {isa = PBXBuildFile; fileRef = E47A97CF163059FC005DCD99 /* StyleInvalidator.h */; };
+		E476EF4A27E07A410056AC6E /* CSSContainerRule.h in Headers */ = {isa = PBXBuildFile; fileRef = E476EF4827E07A1A0056AC6E /* CSSContainerRule.h */; };
 		E4778B80115A581A00B5D372 /* JSCustomEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = E4778B7E115A581A00B5D372 /* JSCustomEvent.h */; };
 		E47A3AC61C5EAC9D00CCBFA7 /* StyleSharingResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = E47A3AC41C5EAC7900CCBFA7 /* StyleSharingResolver.h */; };
 		E47B4BE80E71241600038854 /* CachedResourceHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = E47B4BE60E71241600038854 /* CachedResourceHandle.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -17537,6 +17538,9 @@
 		E46A2B1B17CA65B9000DBCD8 /* TypedElementDescendantIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypedElementDescendantIterator.h; sourceTree = "<group>"; };
 		E46A2B1D17CA76B1000DBCD8 /* ElementChildIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementChildIterator.h; sourceTree = "<group>"; };
 		E46B41F81CB24E70008F11DE /* ScriptDisallowedScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptDisallowedScope.h; sourceTree = "<group>"; };
+		E476EF4727E07A020056AC6E /* CSSContainerRule.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = CSSContainerRule.idl; sourceTree = "<group>"; };
+		E476EF4827E07A1A0056AC6E /* CSSContainerRule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSSContainerRule.h; sourceTree = "<group>"; };
+		E476EF4927E07A280056AC6E /* CSSContainerRule.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CSSContainerRule.cpp; sourceTree = "<group>"; };
 		E4778B7D115A581A00B5D372 /* JSCustomEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomEvent.cpp; sourceTree = "<group>"; };
 		E4778B7E115A581A00B5D372 /* JSCustomEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCustomEvent.h; sourceTree = "<group>"; };
 		E47A3AC21C5EABBE00CCBFA7 /* StyleSharingResolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleSharingResolver.cpp; sourceTree = "<group>"; };
@@ -31784,6 +31788,9 @@
 				930AAC96250EB8170013DA9F /* CSSConditionRule.cpp */,
 				930AAC98250EB8170013DA9F /* CSSConditionRule.h */,
 				930AAC99250EB8180013DA9F /* CSSConditionRule.idl */,
+				E476EF4927E07A280056AC6E /* CSSContainerRule.cpp */,
+				E476EF4827E07A1A0056AC6E /* CSSContainerRule.h */,
+				E476EF4727E07A020056AC6E /* CSSContainerRule.idl */,
 				9DAC7C521AF2CAA100437C44 /* CSSContentDistributionValue.cpp */,
 				9DAC7C531AF2CAA100437C44 /* CSSContentDistributionValue.h */,
 				98F9D66525FDDFE700BD842D /* CSSCounterStyleRule.cpp */,
@@ -34199,6 +34206,7 @@
 				BC6049CC0DB560C200204739 /* CSSCanvasValue.h in Headers */,
 				BCEA4790097CAAC80094C9E4 /* CSSComputedStyleDeclaration.h in Headers */,
 				930AAC9A250EB8490013DA9F /* CSSConditionRule.h in Headers */,
+				E476EF4A27E07A410056AC6E /* CSSContainerRule.h in Headers */,
 				9DAC7C551AF2CAA200437C44 /* CSSContentDistributionValue.h in Headers */,
 				98F9D66925FDE02200BD842D /* CSSCounterStyleRule.h in Headers */,
 				2D8FEBDD143E3EF70072502B /* CSSCrossfadeValue.h in Headers */,

Modified: trunk/Source/WebCore/bindings/js/JSCSSRuleCustom.cpp (292044 => 292045)


--- trunk/Source/WebCore/bindings/js/JSCSSRuleCustom.cpp	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/bindings/js/JSCSSRuleCustom.cpp	2022-03-29 18:19:56 UTC (rev 292045)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "JSCSSRule.h"
 
+#include "CSSContainerRule.h"
 #include "CSSCounterStyleRule.h"
 #include "CSSFontFaceRule.h"
 #include "CSSFontPaletteValuesRule.h"
@@ -39,6 +40,7 @@
 #include "CSSPageRule.h"
 #include "CSSStyleRule.h"
 #include "CSSSupportsRule.h"
+#include "JSCSSContainerRule.h"
 #include "JSCSSCounterStyleRule.h"
 #include "JSCSSFontFaceRule.h"
 #include "JSCSSFontPaletteValuesRule.h"
@@ -97,6 +99,7 @@
     case StyleRuleType::LayerStatement:
         return createWrapper<CSSLayerStatementRule>(globalObject, WTFMove(rule));
     case StyleRuleType::Container:
+        return createWrapper<CSSContainerRule>(globalObject, WTFMove(rule));
     case StyleRuleType::Unknown:
     case StyleRuleType::Charset:
     case StyleRuleType::Margin:

Added: trunk/Source/WebCore/css/CSSContainerRule.cpp (0 => 292045)


--- trunk/Source/WebCore/css/CSSContainerRule.cpp	                        (rev 0)
+++ trunk/Source/WebCore/css/CSSContainerRule.cpp	2022-03-29 18:19:56 UTC (rev 292045)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CSSContainerRule.h"
+
+#include "CSSMarkup.h"
+#include "CSSStyleSheet.h"
+#include "StyleRule.h"
+#include <wtf/text/StringBuilder.h>
+
+namespace WebCore {
+
+CSSContainerRule::CSSContainerRule(StyleRuleContainer& rule, CSSStyleSheet* parent)
+    : CSSConditionRule(rule, parent)
+{
+}
+
+Ref<CSSContainerRule> CSSContainerRule::create(StyleRuleContainer& rule, CSSStyleSheet* parent)
+{
+    return adoptRef(*new CSSContainerRule(rule, parent));
+}
+
+const StyleRuleContainer& CSSContainerRule::styleRuleContainer() const
+{
+    return downcast<StyleRuleContainer>(groupRule());
+}
+
+String CSSContainerRule::cssText() const
+{
+    StringBuilder builder;
+
+    builder.append("@container ");
+
+    auto name = styleRuleContainer().filteredQuery().nameFilter;
+    if (!name.isEmpty()) {
+        serializeIdentifier(name, builder);
+        builder.append(' ');
+    }
+
+    serialize(builder, styleRuleContainer().filteredQuery().query);
+
+    builder.append(" {\n");
+    appendCSSTextForItems(builder);
+    builder.append('}');
+
+    return builder.toString();
+}
+
+String CSSContainerRule::conditionText() const
+{
+    StringBuilder builder;
+    serialize(builder, styleRuleContainer().filteredQuery().query);
+    return builder.toString();
+}
+
+} // namespace WebCore
+

Added: trunk/Source/WebCore/css/CSSContainerRule.h (0 => 292045)


--- trunk/Source/WebCore/css/CSSContainerRule.h	                        (rev 0)
+++ trunk/Source/WebCore/css/CSSContainerRule.h	2022-03-29 18:19:56 UTC (rev 292045)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "CSSConditionRule.h"
+
+namespace WebCore {
+
+class StyleRuleContainer;
+
+class CSSContainerRule final : public CSSConditionRule {
+public:
+    static Ref<CSSContainerRule> create(StyleRuleContainer&, CSSStyleSheet* parent);
+
+    String cssText() const final;
+    String conditionText() const final;
+
+private:
+    const StyleRuleContainer& styleRuleContainer() const;
+
+    CSSContainerRule(StyleRuleContainer&, CSSStyleSheet*);
+    StyleRuleType styleRuleType() const final { return StyleRuleType::Container; }
+};
+
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_CSS_RULE(CSSContainerRule, StyleRuleType::Container)

Added: trunk/Source/WebCore/css/CSSContainerRule.idl (0 => 292045)


--- trunk/Source/WebCore/css/CSSContainerRule.idl	                        (rev 0)
+++ trunk/Source/WebCore/css/CSSContainerRule.idl	2022-03-29 18:19:56 UTC (rev 292045)
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+    Exposed=Window
+] interface CSSContainerRule : CSSConditionRule {
+};
+

Modified: trunk/Source/WebCore/css/ContainerQuery.cpp (292044 => 292045)


--- trunk/Source/WebCore/css/ContainerQuery.cpp	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/css/ContainerQuery.cpp	2022-03-29 18:19:56 UTC (rev 292045)
@@ -25,10 +25,12 @@
 #include "config.h"
 #include "ContainerQuery.h"
 
+#include "CSSMarkup.h"
 #include <wtf/NeverDestroyed.h>
+#include <wtf/text/StringBuilder.h>
 
-namespace WebCore::CQ {
-
+namespace WebCore {
+namespace CQ {
 namespace FeatureNames {
 
 const AtomString& width()
@@ -84,5 +86,90 @@
     return { };
 }
 
+void serialize(StringBuilder&, const SizeQuery&);
+void serialize(StringBuilder&, const SizeFeature&);
+template<typename ConditionType> void serialize(StringBuilder&, const ConditionType&);
+
+static void serialize(StringBuilder& builder, const ContainerQuery& containerQuery)
+{
+    WTF::switchOn(containerQuery, [&](auto& node) {
+        builder.append('(');
+        serialize(builder, node);
+        builder.append(')');
+    }, [&](const CQ::UnknownQuery& unknownQuery) {
+        builder.append(unknownQuery.name);
+        builder.append('(');
+        builder.append(unknownQuery.text);
+        builder.append(')');
+    });
 }
 
+void serialize(StringBuilder& builder, const SizeQuery& sizeQuery)
+{
+    WTF::switchOn(sizeQuery, [&](auto& node) {
+        serialize(builder, node);
+    });
+}
+
+void serialize(StringBuilder& builder, const SizeFeature& sizeFeature)
+{
+    auto serializeComparisonOperator = [&](ComparisonOperator op) {
+        builder.append(' ');
+        switch (op) {
+        case ComparisonOperator::LessThan:
+            builder.append('<');
+            break;
+        case ComparisonOperator::LessThanOrEqual:
+            builder.append("<=");
+            break;
+        case ComparisonOperator::Equal:
+            builder.append('=');
+            break;
+        case ComparisonOperator::GreaterThan:
+            builder.append('>');
+            break;
+        case ComparisonOperator::GreaterThanOrEqual:
+            builder.append(">=");
+            break;
+        }
+        builder.append(' ');
+    };
+
+    if (sizeFeature.leftComparison) {
+        builder.append(sizeFeature.leftComparison->value->cssText());
+        serializeComparisonOperator(sizeFeature.leftComparison->op);
+    }
+
+    serializeIdentifier(sizeFeature.name, builder);
+
+    if (sizeFeature.rightComparison) {
+        serializeComparisonOperator(sizeFeature.rightComparison->op);
+        builder.append(sizeFeature.rightComparison->value->cssText());
+    }
+}
+
+template<typename ConditionType>
+void serialize(StringBuilder& builder, const ConditionType& condition)
+{
+    if (condition.queries.size() == 1 && condition.logicalOperator == LogicalOperator::Not) {
+        builder.append("not ");
+        serialize(builder, condition.queries.first());
+        return;
+    }
+
+    for (auto& query : condition.queries) {
+        if (&query != &condition.queries.first())
+            builder.append(condition.logicalOperator == LogicalOperator::And ? " and " : " or ");
+        serialize(builder, query);
+    }
+}
+
+}
+
+void serialize(StringBuilder& builder, const ContainerQuery& query)
+{
+    CQ::serialize(builder, query);
+}
+
+}
+

Modified: trunk/Source/WebCore/css/ContainerQuery.h (292044 => 292045)


--- trunk/Source/WebCore/css/ContainerQuery.h	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/css/ContainerQuery.h	2022-03-29 18:19:56 UTC (rev 292045)
@@ -39,7 +39,10 @@
 struct SizeCondition;
 struct SizeFeature;
 
-struct UnknownQuery { };
+struct UnknownQuery {
+    String name;
+    String text;
+};
 
 using SizeQuery = std::variant<SizeCondition, SizeFeature>;
 using ContainerQuery = std::variant<ContainerCondition, SizeQuery, UnknownQuery>;
@@ -97,4 +100,6 @@
 
 using CachedQueryContainers = Vector<Ref<const Element>>;
 
+void serialize(StringBuilder&, const ContainerQuery&);
+
 }

Modified: trunk/Source/WebCore/css/ContainerQueryParser.cpp (292044 => 292045)


--- trunk/Source/WebCore/css/ContainerQueryParser.cpp	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/css/ContainerQueryParser.cpp	2022-03-29 18:19:56 UTC (rev 292045)
@@ -61,9 +61,10 @@
 std::optional<CQ::ContainerQuery> ContainerQueryParser::consumeContainerQuery(CSSParserTokenRange& range)
 {
     if (range.peek().type() == FunctionToken) {
-        range.consumeBlock();
+        auto name = range.peek().value();
+        auto functionRange = range.consumeBlock();
         // This is where we would support style() queries.
-        return CQ::UnknownQuery { };
+        return CQ::UnknownQuery { name.toString(), functionRange.serialize() };
     }
 
     if (range.peek().type() == LeftParenthesisToken) {

Modified: trunk/Source/WebCore/css/StyleRule.cpp (292044 => 292045)


--- trunk/Source/WebCore/css/StyleRule.cpp	2022-03-29 18:15:41 UTC (rev 292044)
+++ trunk/Source/WebCore/css/StyleRule.cpp	2022-03-29 18:19:56 UTC (rev 292045)
@@ -22,6 +22,7 @@
 #include "config.h"
 #include "StyleRule.h"
 
+#include "CSSContainerRule.h"
 #include "CSSCounterStyleRule.h"
 #include "CSSDeferredParser.h"
 #include "CSSFontFaceRule.h"
@@ -194,7 +195,7 @@
         rule = CSSLayerStatementRule::create(downcast<StyleRuleLayer>(self), parentSheet);
         break;
     case StyleRuleType::Container:
-        // FIXME: Implement CSSOM.
+        rule = CSSContainerRule::create(downcast<StyleRuleContainer>(self), parentSheet);
         break;
     case StyleRuleType::Unknown:
     case StyleRuleType::Charset:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to