Skip to content

Commit 6b8d8d4

Browse files
frehnerAhmad Saleem
authored andcommitted
Implement name only container queries
https://bugs.webkit.org/show_bug.cgi?id=302433 Reviewed by Antti Koivisto. Allows parsing of Container Queries where the query is empty but there is a name. Then allows the Evaluator to match a container when there aren't conditions and there is a name. * LayoutTests/imported/w3c/web-platform-tests/css/css-conditional/container-queries/at-container-parsing-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-conditional/container-queries/query-container-name-expected.txt: * Source/WebCore/css/query/ContainerQueryParser.cpp: (WebCore::CQ::ContainerQueryParser::consumeContainerQuery): * Source/WebCore/style/ContainerQueryEvaluator.cpp: (WebCore::Style::ContainerQueryEvaluator::evaluate const): Canonical link: https://commits.webkit.org/304388@main
1 parent 0816811 commit 6b8d8d4

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

LayoutTests/imported/w3c/web-platform-tests/css/css-conditional/container-queries/at-container-parsing-expected.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ PASS @container rule should be valid: @container not (width <= 500px) {} {}
8383
FAIL @container rule should be valid: @container (width: 100px), (height: 100px) {} {} assert_equals: expected 1 but got 0
8484
FAIL @container rule should be valid: @container (width),(height) , (inline-size > 20px) {} {} assert_equals: expected 1 but got 0
8585
FAIL @container rule should be valid: @container (width), name (height) {} {} assert_equals: expected 1 but got 0
86-
FAIL @container rule should be valid: @container --foo {} {} assert_equals: expected 1 but got 0
87-
FAIL @container rule should be valid: @container container {} {} assert_equals: expected 1 but got 0
86+
PASS @container rule should be valid: @container --foo {} {}
87+
PASS @container rule should be valid: @container container {} {}
8888
FAIL @container rule should be valid: @container container, container2 {} {} assert_equals: expected 1 but got 0
8989
PASS @container rule should be invalid: @container {} {}
9090
PASS @container rule should be invalid: @container (width), {} {}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
FAIL match closest named container assert_equals: expected "yes" but got "no"
3-
FAIL match ancestor named container assert_equals: expected "yes" but got "no"
2+
PASS match closest named container
3+
PASS match ancestor named container
44
PASS no match for unused container name
55

Source/WebCore/css/query/ContainerQueryParser.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ std::optional<ContainerQuery> ContainerQueryParser::consumeContainerQuery(CSSPar
5252
auto name = consumeName();
5353

5454
auto condition = consumeCondition(range, context);
55-
if (!condition)
56-
return { };
55+
56+
if (!condition) {
57+
if (name.isEmpty())
58+
return { };
59+
// it's valid to have a named container query without a condition, like "@container --name {}"
60+
condition = MQ::Condition { };
61+
}
5762

5863
OptionSet<Axis> requiredAxes;
5964
auto containsUnknownFeature = ContainsUnknownFeature::No;

Source/WebCore/style/ContainerQueryEvaluator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ bool ContainerQueryEvaluator::evaluate(const CQ::ContainerQuery& containerQuery)
5757
if (!context)
5858
return false;
5959

60+
if (containerQuery.condition.queries.isEmpty() && !containerQuery.name.isEmpty())
61+
return true;
62+
6063
return evaluateCondition(containerQuery.condition, *context) == MQ::EvaluationResult::True;
6164
}
6265

0 commit comments

Comments
 (0)