Title: [289838] trunk
Revision
289838
Author
[email protected]
Date
2022-02-15 11:14:03 -0800 (Tue, 15 Feb 2022)

Log Message

[CSS Container Queries] Support all size features
https://bugs.webkit.org/show_bug.cgi?id=236640

Reviewed by Tim Nguyen and Sam Weinig.

LayoutTests/imported/w3c:

* web-platform-tests/css/css-contain/container-queries/at-container-parsing-expected.txt:
* web-platform-tests/css/css-contain/container-queries/query-content-box-expected.txt:
* web-platform-tests/css/css-contain/container-queries/size-feature-evaluation-expected.txt:
* web-platform-tests/css/css-contain/container-queries/unsupported-axis-expected.txt:

Source/WebCore:

Support inline-size, block-size, aspect-ratio and orientation in addition to the currently
supported width and height.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* css/ContainerQuery.cpp: Copied from Source/WebCore/css/ContainerQuery.h.
(WebCore::CQ::FeatureNames::width):
(WebCore::CQ::FeatureNames::height):
(WebCore::CQ::FeatureNames::inlineSize):
(WebCore::CQ::FeatureNames::blockSize):
(WebCore::CQ::FeatureNames::aspectRatio):
(WebCore::CQ::FeatureNames::orientation):
* css/ContainerQuery.h:
* css/ContainerQueryParser.cpp:
(WebCore::ContainerQueryParser::consumeSizeFeature):

Parse the new features.

* css/parser/CSSPropertyParser.cpp:
(WebCore::consumeAspectRatio):

Use the new consumeAspectRatioValue helper.

* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeAspectRatioValue):
* css/parser/CSSPropertyParserHelpers.h:
* style/ContainerQueryEvaluator.cpp:
(WebCore::Style::computeSize):
(WebCore::Style::ContainerQueryEvaluator::evaluateSizeFeature const):

LayoutTests:

* TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (289837 => 289838)


--- trunk/LayoutTests/ChangeLog	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/LayoutTests/ChangeLog	2022-02-15 19:14:03 UTC (rev 289838)
@@ -1,3 +1,12 @@
+2022-02-15  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Support all size features
+        https://bugs.webkit.org/show_bug.cgi?id=236640
+
+        Reviewed by Tim Nguyen and Sam Weinig.
+
+        * TestExpectations:
+
 2022-02-15  Matteo Flores  <[email protected]>
 
         Rebaslining fonts/monospace.html for Monterey.

Modified: trunk/LayoutTests/TestExpectations (289837 => 289838)


--- trunk/LayoutTests/TestExpectations	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/LayoutTests/TestExpectations	2022-02-15 19:14:03 UTC (rev 289838)
@@ -4752,7 +4752,6 @@
 imported/w3c/web-platform-tests/css/css-contain/contain-html-overflow-004.html [ ImageOnlyFailure ]
 
 # Container queries
-webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/display-in-container.html [ ImageOnlyFailure ]
 webkit.org/b/229659 imported/w3c/web-platform-tests/css/css-contain/container-queries/pseudo-elements-002.tentative.html [ ImageOnlyFailure ]
 
 # Flaky css-contain test

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (289837 => 289838)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-15 19:14:03 UTC (rev 289838)
@@ -1,3 +1,15 @@
+2022-02-15  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Support all size features
+        https://bugs.webkit.org/show_bug.cgi?id=236640
+
+        Reviewed by Tim Nguyen and Sam Weinig.
+
+        * web-platform-tests/css/css-contain/container-queries/at-container-parsing-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/query-content-box-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/size-feature-evaluation-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/unsupported-axis-expected.txt:
+
 2022-02-15  Ziran Sun  <[email protected]>
 
         [Forms] the select() method returns should be in line with specs

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/aspect-ratio-feature-evaluation-expected.txt (289837 => 289838)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/aspect-ratio-feature-evaluation-expected.txt	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/aspect-ratio-feature-evaluation-expected.txt	2022-02-15 19:14:03 UTC (rev 289838)
@@ -1,4 +1,4 @@
 
-FAIL @container queries with aspect-ratio and size containment assert_equals: Should match for block-size containment expected "rgb(0, 128, 0)" but got "rgb(255, 0, 0)"
+FAIL @container queries with aspect-ratio and size containment assert_equals: Should not match for inline-size containment expected "rgb(255, 0, 0)" but got "rgb(0, 128, 0)"
 FAIL @container query with aspect-ratio change after resize assert_equals: Should match 2/1 min-ratio expected "rgb(0, 255, 0)" but got "rgba(0, 0, 0, 0)"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/at-container-parsing-expected.txt (289837 => 289838)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/at-container-parsing-expected.txt	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/at-container-parsing-expected.txt	2022-02-15 19:14:03 UTC (rev 289838)
@@ -5,16 +5,16 @@
 PASS size(height)
 PASS size(min-height: 0px)
 PASS size(max-height: 0px)
-FAIL size(aspect-ratio) assert_equals: expected "true" but got ""
-FAIL size(min-aspect-ratio: 1/2) assert_equals: expected 2 but got 0
-FAIL size(max-aspect-ratio: 1/2) assert_equals: expected 2 but got 0
-FAIL size(orientation: portrait) assert_equals: expected 2 but got 0
-FAIL size(inline-size) assert_equals: expected "true" but got ""
-FAIL size(min-inline-size: 0px) assert_equals: expected "true" but got ""
-FAIL size(max-inline-size: 0px) assert_equals: expected "true" but got ""
-FAIL size(block-size) assert_equals: expected "true" but got ""
-FAIL size(min-block-size: 0px) assert_equals: expected "true" but got ""
-FAIL size(max-block-size: 0px) assert_equals: expected "true" but got ""
+PASS size(aspect-ratio)
+PASS size(min-aspect-ratio: 1/2)
+PASS size(max-aspect-ratio: 1/2)
+PASS size(orientation: portrait)
+PASS size(inline-size)
+PASS size(min-inline-size: 0px)
+PASS size(max-inline-size: 0px)
+PASS size(block-size)
+PASS size(min-block-size: 0px)
+PASS size(max-block-size: 0px)
 PASS size(width: 100px)
 PASS size((width: 100px))
 PASS size(not (width: 100px))

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/query-content-box-expected.txt (289837 => 289838)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/query-content-box-expected.txt	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/query-content-box-expected.txt	2022-02-15 19:14:03 UTC (rev 289838)
@@ -1,6 +1,6 @@
 
-FAIL Size queries with content-box sizing assert_equals: expected "rgb(0, 128, 0)" but got "rgba(0, 0, 0, 0)"
-FAIL Size queries with border-box sizing assert_equals: expected "rgb(0, 128, 0)" but got "rgba(0, 0, 0, 0)"
+PASS Size queries with content-box sizing
+PASS Size queries with border-box sizing
 FAIL Size queries with content-box sizing and overflow:scroll assert_equals: expected "rgb(0, 128, 0)" but got "rgba(0, 0, 0, 0)"
 FAIL Size queries with border-box sizing and overflow:scroll assert_equals: expected "rgb(0, 128, 0)" but got "rgba(0, 0, 0, 0)"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/size-feature-evaluation-expected.txt (289837 => 289838)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/size-feature-evaluation-expected.txt	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/size-feature-evaluation-expected.txt	2022-02-15 19:14:03 UTC (rev 289838)
@@ -13,20 +13,20 @@
 PASS size(max-height: 200px) (.horizontal)
 PASS size(max-height: 199px) (.horizontal)
 PASS size(inline-size < 100px) (.horizontal)
-FAIL size(inline-size >= 100px) (.horizontal) assert_equals: expected "true" but got ""
-FAIL size(min-inline-size: 100px) (.horizontal) assert_equals: expected "true" but got ""
+PASS size(inline-size >= 100px) (.horizontal)
+PASS size(min-inline-size: 100px) (.horizontal)
 PASS size(min-inline-size: 101px) (.horizontal)
-FAIL size(max-inline-size: 100px) (.horizontal) assert_equals: expected "true" but got ""
+PASS size(max-inline-size: 100px) (.horizontal)
 PASS size(max-inline-size: 99px) (.horizontal)
 PASS size(block-size < 200px) (.horizontal)
-FAIL size(block-size >= 200px) (.horizontal) assert_equals: expected "true" but got ""
-FAIL size(min-block-size: 200px) (.horizontal) assert_equals: expected "true" but got ""
+PASS size(block-size >= 200px) (.horizontal)
+PASS size(min-block-size: 200px) (.horizontal)
 PASS size(min-block-size: 201px) (.horizontal)
-FAIL size(max-block-size: 200px) (.horizontal) assert_equals: expected "true" but got ""
+PASS size(max-block-size: 200px) (.horizontal)
 PASS size(max-block-size: 199px) (.horizontal)
 PASS size(orientation: landscape) (.horizontal)
-FAIL size(orientation: portrait) (.horizontal) assert_equals: expected "true" but got ""
-FAIL size(aspect-ratio: 1/2) (.horizontal) assert_equals: expected "true" but got ""
+PASS size(orientation: portrait) (.horizontal)
+PASS size(aspect-ratio: 1/2) (.horizontal)
 PASS size(aspect-ratio: 2/1) (.horizontal)
 PASS size(width < 100px) (.vertical)
 PASS size(width >= 100px) (.vertical)
@@ -41,19 +41,19 @@
 PASS size(max-height: 200px) (.vertical)
 PASS size(max-height: 199px) (.vertical)
 PASS size(block-size < 100px) (.vertical)
-FAIL size(block-size >= 100px) (.vertical) assert_equals: expected "true" but got ""
-FAIL size(min-block-size: 100px) (.vertical) assert_equals: expected "true" but got ""
+PASS size(block-size >= 100px) (.vertical)
+PASS size(min-block-size: 100px) (.vertical)
 PASS size(min-block-size: 101px) (.vertical)
-FAIL size(max-block-size: 100px) (.vertical) assert_equals: expected "true" but got ""
+PASS size(max-block-size: 100px) (.vertical)
 PASS size(max-block-size: 99px) (.vertical)
 PASS size(inline-size < 200px) (.vertical)
-FAIL size(inline-size >= 200px) (.vertical) assert_equals: expected "true" but got ""
-FAIL size(min-inline-size: 200px) (.vertical) assert_equals: expected "true" but got ""
+PASS size(inline-size >= 200px) (.vertical)
+PASS size(min-inline-size: 200px) (.vertical)
 PASS size(min-inline-size: 201px) (.vertical)
-FAIL size(max-inline-size: 200px) (.vertical) assert_equals: expected "true" but got ""
+PASS size(max-inline-size: 200px) (.vertical)
 PASS size(max-inline-size: 199px) (.vertical)
 PASS size(orientation: landscape) (.vertical)
-FAIL size(orientation: portrait) (.vertical) assert_equals: expected "true" but got ""
-FAIL size(aspect-ratio: 1/2) (.vertical) assert_equals: expected "true" but got ""
+PASS size(orientation: portrait) (.vertical)
+PASS size(aspect-ratio: 1/2) (.vertical)
 PASS size(aspect-ratio: 2/1) (.vertical)
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/unsupported-axis-expected.txt (289837 => 289838)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/unsupported-axis-expected.txt	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/unsupported-axis-expected.txt	2022-02-15 19:14:03 UTC (rev 289838)
@@ -4,11 +4,11 @@
 FAIL size(height > 0px) assert_equals: expected "" but got "true"
 PASS size((height > 0px) or (width > 0px))
 PASS size((width > 0px) or (height > 0px))
-FAIL size((orientation: landscape) or (width > 0px)) assert_equals: expected "true" but got ""
-FAIL size((width > 0px) or (orientation: landscape)) assert_equals: expected "true" but got ""
-PASS size((height > 0px) or (orientation: landscape))
-PASS size((height > 0px) or (orientation: landscape)), with contain:size
-FAIL size(inline-size > 0px) assert_equals: expected "true" but got ""
-PASS size(block-size > 0px)
-PASS size(block-size > 0px), with writing-mode:vertical-rl
+PASS size((orientation: landscape) or (width > 0px))
+PASS size((width > 0px) or (orientation: landscape))
+FAIL size((height > 0px) or (orientation: landscape)) assert_equals: expected "" but got "true"
+FAIL size((height > 0px) or (orientation: landscape)), with contain:size assert_equals: expected "" but got "true"
+PASS size(inline-size > 0px)
+FAIL size(block-size > 0px) assert_equals: expected "" but got "true"
+FAIL size(block-size > 0px), with writing-mode:vertical-rl assert_equals: expected "" but got "true"
 

Modified: trunk/Source/WebCore/ChangeLog (289837 => 289838)


--- trunk/Source/WebCore/ChangeLog	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/Source/WebCore/ChangeLog	2022-02-15 19:14:03 UTC (rev 289838)
@@ -1,3 +1,40 @@
+2022-02-15  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Support all size features
+        https://bugs.webkit.org/show_bug.cgi?id=236640
+
+        Reviewed by Tim Nguyen and Sam Weinig.
+
+        Support inline-size, block-size, aspect-ratio and orientation in addition to the currently
+        supported width and height.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/ContainerQuery.cpp: Copied from Source/WebCore/css/ContainerQuery.h.
+        (WebCore::CQ::FeatureNames::width):
+        (WebCore::CQ::FeatureNames::height):
+        (WebCore::CQ::FeatureNames::inlineSize):
+        (WebCore::CQ::FeatureNames::blockSize):
+        (WebCore::CQ::FeatureNames::aspectRatio):
+        (WebCore::CQ::FeatureNames::orientation):
+        * css/ContainerQuery.h:
+        * css/ContainerQueryParser.cpp:
+        (WebCore::ContainerQueryParser::consumeSizeFeature):
+
+        Parse the new features.
+
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::consumeAspectRatio):
+
+        Use the new consumeAspectRatioValue helper.
+
+        * css/parser/CSSPropertyParserHelpers.cpp:
+        (WebCore::CSSPropertyParserHelpers::consumeAspectRatioValue):
+        * css/parser/CSSPropertyParserHelpers.h:
+        * style/ContainerQueryEvaluator.cpp:
+        (WebCore::Style::computeSize):
+        (WebCore::Style::ContainerQueryEvaluator::evaluateSizeFeature const):
+
 2022-02-15  Megan Gardner  <[email protected]>
 
         Implement additional Reveal methods.

Modified: trunk/Source/WebCore/Sources.txt (289837 => 289838)


--- trunk/Source/WebCore/Sources.txt	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/Source/WebCore/Sources.txt	2022-02-15 19:14:03 UTC (rev 289838)
@@ -704,6 +704,7 @@
 crypto/keys/CryptoKeyRSAComponents.cpp
 crypto/keys/CryptoKeyRaw.cpp
 css/BasicShapeFunctions.cpp
+css/ContainerQuery.cpp
 css/ContainerQueryParser.cpp
 css/CSSAspectRatioValue.cpp
 css/CSSBasicShapes.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (289837 => 289838)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-02-15 19:14:03 UTC (rev 289838)
@@ -17612,6 +17612,7 @@
 		E4F1573227B6991F00B330D8 /* ContainerQuery.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContainerQuery.h; sourceTree = "<group>"; };
 		E4F1573D27B93B4C00B330D8 /* ContainerQueryParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContainerQueryParser.h; sourceTree = "<group>"; };
 		E4F1573F27B93B5800B330D8 /* ContainerQueryParser.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ContainerQueryParser.cpp; sourceTree = "<group>"; };
+		E4F1574927BB93BE00B330D8 /* ContainerQuery.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ContainerQuery.cpp; sourceTree = "<group>"; };
 		E4F38D192626F13B007B1064 /* DefaultResourceLoadPriority.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DefaultResourceLoadPriority.h; sourceTree = "<group>"; };
 		E4F38D1C2626F144007B1064 /* DefaultResourceLoadPriority.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DefaultResourceLoadPriority.cpp; sourceTree = "<group>"; };
 		E4F819C226FB4EAF0094E162 /* InlineBoxPainter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InlineBoxPainter.cpp; sourceTree = "<group>"; };
@@ -31596,6 +31597,7 @@
 				4BAFD0DA21921EAD00C0AB64 /* typedom */,
 				FBD6AF8415EF21D4008B7110 /* BasicShapeFunctions.cpp */,
 				FBD6AF8515EF21D4008B7110 /* BasicShapeFunctions.h */,
+				E4F1574927BB93BE00B330D8 /* ContainerQuery.cpp */,
 				E4F1573227B6991F00B330D8 /* ContainerQuery.h */,
 				E4F1573F27B93B5800B330D8 /* ContainerQueryParser.cpp */,
 				E4F1573D27B93B4C00B330D8 /* ContainerQueryParser.h */,

Copied: trunk/Source/WebCore/css/ContainerQuery.cpp (from rev 289837, trunk/Source/WebCore/css/ContainerQuery.h) (0 => 289838)


--- trunk/Source/WebCore/css/ContainerQuery.cpp	                        (rev 0)
+++ trunk/Source/WebCore/css/ContainerQuery.cpp	2022-02-15 19:14:03 UTC (rev 289838)
@@ -0,0 +1,69 @@
+/*
+ * 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. ``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
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * 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 "ContainerQuery.h"
+
+#include <wtf/NeverDestroyed.h>
+
+namespace WebCore::CQ::FeatureNames {
+
+const AtomString& width()
+{
+    static MainThreadNeverDestroyed<AtomString> name { "width"_s };
+    return name;
+}
+
+const AtomString& height()
+{
+    static MainThreadNeverDestroyed<AtomString> name { "height"_s };
+    return name;
+}
+
+const AtomString& inlineSize()
+{
+    static MainThreadNeverDestroyed<AtomString> name { "inline-size"_s };
+    return name;
+}
+
+const AtomString& blockSize()
+{
+    static MainThreadNeverDestroyed<AtomString> name { "block-size"_s };
+    return name;
+}
+
+const AtomString& aspectRatio()
+{
+    static MainThreadNeverDestroyed<AtomString> name { "aspect-ratio"_s };
+    return name;
+}
+
+const AtomString& orientation()
+{
+    static MainThreadNeverDestroyed<AtomString> name { "orientation"_s };
+    return name;
+}
+
+}
+

Modified: trunk/Source/WebCore/css/ContainerQuery.h (289837 => 289838)


--- trunk/Source/WebCore/css/ContainerQuery.h	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/Source/WebCore/css/ContainerQuery.h	2022-02-15 19:14:03 UTC (rev 289838)
@@ -28,7 +28,7 @@
 
 namespace WebCore {
 
-class CSSPrimitiveValue;
+class CSSValue;
 
 namespace CQ {
 
@@ -57,9 +57,18 @@
 struct SizeFeature {
     ComparisonOperator comparisonOperator { ComparisonOperator::Equal };
     AtomString name;
-    RefPtr<CSSPrimitiveValue> value;
+    RefPtr<CSSValue> value;
 };
 
+namespace FeatureNames {
+const AtomString& width();
+const AtomString& height();
+const AtomString& inlineSize();
+const AtomString& blockSize();
+const AtomString& aspectRatio();
+const AtomString& orientation();
+};
+
 }
 
 using ContainerQuery = CQ::ContainerQuery;

Modified: trunk/Source/WebCore/css/ContainerQueryParser.cpp (289837 => 289838)


--- trunk/Source/WebCore/css/ContainerQueryParser.cpp	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/Source/WebCore/css/ContainerQueryParser.cpp	2022-02-15 19:14:03 UTC (rev 289838)
@@ -210,11 +210,19 @@
 
     range.consumeWhitespace();
 
-    auto length = CSSPropertyParserHelpers::consumeLength(range, m_context.mode, ValueRange::All);
-    if (!length)
-        return { };
+    auto featureName = name.toAtomString();
 
-    return CQ::SizeFeature { *op, name.toAtomString(), length };
+    auto consumeValue = [&]() -> RefPtr<CSSValue> {
+        if (featureName == CQ::FeatureNames::orientation())
+            return CSSPropertyParserHelpers::consumeIdent(range);
+        if (featureName == CQ::FeatureNames::aspectRatio())
+            return CSSPropertyParserHelpers::consumeAspectRatioValue(range);
+        return CSSPropertyParserHelpers::consumeLength(range, m_context.mode, ValueRange::All);
+    };
+
+    auto value = consumeValue();
+
+    return CQ::SizeFeature { *op, WTFMove(featureName), WTFMove(value) };
 }
 
 }

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp (289837 => 289838)


--- trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2022-02-15 19:14:03 UTC (rev 289838)
@@ -4008,32 +4008,23 @@
         autoValue = consumeIdent<CSSValueAuto>(range);
 
     if (range.atEnd())
-        return RefPtr<CSSValue>(WTFMove(autoValue));
+        return autoValue;
 
-    auto leftValue = consumeNumber(range, ValueRange::NonNegative);
-    if (!leftValue)
+    auto ratioList = consumeAspectRatioValue(range);
+    if (!ratioList)
         return nullptr;
 
-    bool slashSeen = consumeSlashIncludingWhitespace(range);
-
-    auto rightValue = consumeNumber(range, ValueRange::NonNegative);
-    if ((rightValue && !slashSeen) || (!rightValue && slashSeen))
-        return nullptr;
-    if (!slashSeen && !rightValue) // A missing right-hand is treated as 1.
-        rightValue = CSSValuePool::singleton().createValue(1, CSSUnitType::CSS_NUMBER);
     if (!autoValue)
         autoValue = consumeIdent<CSSValueAuto>(range);
 
-    auto ratioList = CSSValueList::createSlashSeparated();
-    ratioList->append(leftValue.releaseNonNull());
-    if (rightValue)
-        ratioList->append(rightValue.releaseNonNull());
     if (!autoValue)
-        return RefPtr<CSSValue>(WTFMove(ratioList));
+        return ratioList;
+
     auto list = CSSValueList::createSpaceSeparated();
     list->append(CSSValuePool::singleton().createIdentifierValue(CSSValueAuto));
-    list->append(ratioList);
-    return RefPtr<CSSValue>(WTFMove(list));
+    list->append(ratioList.releaseNonNull());
+
+    return list;
 }
 
 static RefPtr<CSSValue> consumeContain(CSSParserTokenRange& range)

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (289837 => 289838)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp	2022-02-15 19:14:03 UTC (rev 289838)
@@ -4531,6 +4531,27 @@
     }
 }
 
+RefPtr<CSSValueList> consumeAspectRatioValue(CSSParserTokenRange& range)
+{
+    auto leftValue = consumeNumber(range, ValueRange::NonNegative);
+    if (!leftValue)
+        return nullptr;
+
+    bool slashSeen = consumeSlashIncludingWhitespace(range);
+    auto rightValue = slashSeen
+        ? consumeNumber(range, ValueRange::NonNegative)
+        : CSSValuePool::singleton().createValue(1, CSSUnitType::CSS_NUMBER);
+
+    if (!rightValue)
+        return nullptr;
+
+    auto ratioList = CSSValueList::createSlashSeparated();
+    ratioList->append(leftValue.releaseNonNull());
+    ratioList->append(rightValue.releaseNonNull());
+
+    return ratioList;
+}
+
 } // namespace CSSPropertyParserHelpers
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h (289837 => 289838)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h	2022-02-15 19:14:03 UTC (rev 289838)
@@ -213,6 +213,8 @@
 
 bool isFontStyleAngleInRange(double angleInDegrees);
 
+RefPtr<CSSValueList> consumeAspectRatioValue(CSSParserTokenRange&);
+
 // Template and inline implementations are at the bottom of the file for readability.
 
 template<typename... emptyBaseCase> inline bool identMatches(CSSValueID) { return false; }
@@ -245,6 +247,7 @@
     return angleInDegrees > -90 && angleInDegrees < 90;
 }
 
+
 } // namespace CSSPropertyParserHelpers
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp (289837 => 289838)


--- trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp	2022-02-15 19:04:17 UTC (rev 289837)
+++ trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp	2022-02-15 19:14:03 UTC (rev 289838)
@@ -25,7 +25,9 @@
 #include "config.h"
 #include "ContainerQueryEvaluator.h"
 
+#include "CSSPrimitiveValue.h"
 #include "CSSToLengthConversionData.h"
+#include "CSSValueList.h"
 #include "Document.h"
 #include "MediaFeatureNames.h"
 #include "MediaList.h"
@@ -45,19 +47,6 @@
 {
 }
 
-static std::optional<LayoutUnit> computeSize(const CSSPrimitiveValue& value, const CSSToLengthConversionData& conversionData)
-{
-    if (value.isNumberOrInteger()) {
-        if (value.doubleValue())
-            return { };
-        return 0_lu;
-    }
-
-    if (!value.isLength())
-        return { };
-    return value.computeLength<LayoutUnit>(conversionData);
-}
-
 bool ContainerQueryEvaluator::evaluate(const FilteredContainerQuery& filteredContainerQuery) const
 {
     if (m_containers.isEmpty())
@@ -154,41 +143,108 @@
     }
 }
 
+static std::optional<LayoutUnit> computeSize(const CSSValue* value, const CSSToLengthConversionData& conversionData)
+{
+    if (!is<CSSPrimitiveValue>(value))
+        return { };
+    auto& primitiveValue = downcast<CSSPrimitiveValue>(*value);
+
+    if (primitiveValue.isNumberOrInteger()) {
+        if (primitiveValue.doubleValue())
+            return { };
+        return 0_lu;
+    }
+
+    if (!primitiveValue.isLength())
+        return { };
+    return primitiveValue.computeLength<LayoutUnit>(conversionData);
+}
+
 auto ContainerQueryEvaluator::evaluateSizeFeature(const CQ::SizeFeature& sizeFeature, const EvaluationContext& context) const -> EvaluationResult
 {
-    auto evaluateSize = [&](LayoutUnit size) {
-        std::optional<LayoutUnit> expressionSize;
+    auto toEvaluationResult = [](bool boolean) {
+        return boolean ? EvaluationResult::True : EvaluationResult::False;
+    };
 
-        if (sizeFeature.comparisonOperator != CQ::ComparisonOperator::True) {
-            if (!sizeFeature.value)
-                return false;
-            expressionSize = computeSize(*sizeFeature.value, context.conversionData);
-            if (!expressionSize)
-                return false;
-        }
-
+    auto compare = [&](auto left, auto right) {
         switch (sizeFeature.comparisonOperator) {
         case CQ::ComparisonOperator::LessThan:
-            return size < *expressionSize;
+            return left < right;
         case CQ::ComparisonOperator::GreaterThan:
-            return size > *expressionSize;
+            return left > right;
         case CQ::ComparisonOperator::LessThanOrEqual:
-            return size <= *expressionSize;
+            return left <= right;
         case CQ::ComparisonOperator::GreaterThanOrEqual:
-            return size >= *expressionSize;
+            return left >= right;
         case CQ::ComparisonOperator::Equal:
-            return size == *expressionSize;
+            return left == right;
         case CQ::ComparisonOperator::True:
-            return !!size;
+            ASSERT_NOT_REACHED();
+            return false;
         }
     };
 
-    // FIXME: Support all features.
-    if (sizeFeature.name == MediaFeatureNames::width)
-        return evaluateSize(context.renderer.width()) ? EvaluationResult::True : EvaluationResult::False;
-    if (sizeFeature.name == MediaFeatureNames::height)
-        return evaluateSize(context.renderer.height()) ? EvaluationResult::True : EvaluationResult::False;
+    auto evaluateSize = [&](LayoutUnit size) {
+        if (sizeFeature.comparisonOperator == CQ::ComparisonOperator::True)
+            return toEvaluationResult(!!size);
 
+        auto expressionSize = computeSize(sizeFeature.value.get(), context.conversionData);
+        if (!expressionSize)
+            return EvaluationResult::Unknown;
+
+        return toEvaluationResult(compare(size, *expressionSize));
+    };
+
+    if (sizeFeature.name == CQ::FeatureNames::width())
+        return evaluateSize(context.renderer.contentWidth());
+
+    if (sizeFeature.name == CQ::FeatureNames::height())
+        return evaluateSize(context.renderer.contentHeight());
+
+    if (sizeFeature.name == CQ::FeatureNames::inlineSize())
+        return evaluateSize(context.renderer.contentLogicalWidth());
+
+    if (sizeFeature.name == CQ::FeatureNames::blockSize())
+        return evaluateSize(context.renderer.contentLogicalHeight());
+
+    if (sizeFeature.name == CQ::FeatureNames::aspectRatio()) {
+        auto boxRatio = context.renderer.contentWidth().toDouble() / context.renderer.contentHeight().toDouble();
+        if (sizeFeature.comparisonOperator == CQ::ComparisonOperator::True)
+            return toEvaluationResult(!!boxRatio);
+
+        if (!is<CSSValueList>(sizeFeature.value))
+            return EvaluationResult::Unknown;
+
+        auto& ratioList = downcast<CSSValueList>(*sizeFeature.value);
+        if (ratioList.length() != 2)
+            return EvaluationResult::Unknown;
+
+        auto first = dynamicDowncast<CSSPrimitiveValue>(ratioList.item(0));
+        auto second = dynamicDowncast<CSSPrimitiveValue>(ratioList.item(1));
+
+        if (!first || !second || !first->isNumberOrInteger() || !second->isNumberOrInteger())
+            return EvaluationResult::Unknown;
+
+        auto expressionRatio = first->doubleValue() / second->doubleValue();
+
+        return toEvaluationResult(compare(boxRatio, expressionRatio));
+    }
+
+    if (sizeFeature.name == CQ::FeatureNames::orientation()) {
+        if (!is<CSSPrimitiveValue>(sizeFeature.value) || sizeFeature.comparisonOperator != CQ::ComparisonOperator::Equal)
+            return EvaluationResult::Unknown;
+
+        auto& value = downcast<CSSPrimitiveValue>(*sizeFeature.value);
+
+        bool isPortrait = context.renderer.contentHeight() >= context.renderer.contentWidth();
+        if (value.valueID() == CSSValuePortrait)
+            return toEvaluationResult(isPortrait);
+        if (value.valueID() == CSSValueLandscape)
+            return toEvaluationResult(!isPortrait);
+
+        return EvaluationResult::Unknown;
+    }
+
     return EvaluationResult::Unknown;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to