Title: [290205] trunk
Revision
290205
Author
[email protected]
Date
2022-02-19 06:05:53 -0800 (Sat, 19 Feb 2022)

Log Message

[CSS Container Queries] Match container queries correctly in non-rendered subtrees
https://bugs.webkit.org/show_bug.cgi?id=236840

Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

* web-platform-tests/css/css-contain/container-queries/backdrop-invalidation-expected.txt:
* web-platform-tests/css/css-contain/container-queries/display-contents-expected.txt:
* web-platform-tests/css/css-contain/container-queries/display-none-expected.txt:
* web-platform-tests/css/css-contain/container-queries/pseudo-elements-001-expected.txt:
* web-platform-tests/css/css-contain/container-queries/pseudo-elements-003.tentative-expected.txt:
* web-platform-tests/css/css-contain/container-queries/size-container-no-principal-box-expected.txt:
* web-platform-tests/css/css-contain/container-queries/top-layer-dialog-container-expected.txt:
* web-platform-tests/css/css-contain/container-queries/top-layer-dialog-expected.txt:
* web-platform-tests/css/css-contain/container-queries/top-layer-nested-dialog-expected.txt:

Source/WebCore:

"If the query container does not have a principal box ... then the result of evaluating the size feature is unknown."

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

* rendering/updating/RenderTreeBuilderFirstLetter.cpp:
(WebCore::styleForFirstLetter):

Remove the assert, this issue is tested by marked-as-failure
imported/w3c/web-platform-tests/css/css-contain/container-queries/pseudo-elements-002.tentative.html

* style/ContainerQueryEvaluator.cpp:
(WebCore::Style::ContainerQueryEvaluator::ContainerQueryEvaluator):
(WebCore::Style::ContainerQueryEvaluator::evaluate const):
(WebCore::Style::ContainerQueryEvaluator::resolveContainer const):

Factor into a function.
If we don't have selector matching state (like we do during style resolution) then look up containers from DOM.
An element without a renderer may still be a valid container (size queries againt it evaluate to unknown).

(WebCore::Style::ContainerQueryEvaluator::evaluateSizeFeature const):
* style/ContainerQueryEvaluator.h:
* style/ElementRuleCollector.cpp:
(WebCore::Style::ElementRuleCollector::containerQueryMatches):

Evaluate to unknown if we don't have a principal box.

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (290204 => 290205)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-19 14:05:53 UTC (rev 290205)
@@ -1,3 +1,20 @@
+2022-02-19  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Match container queries correctly in non-rendered subtrees
+        https://bugs.webkit.org/show_bug.cgi?id=236840
+
+        Reviewed by Dean Jackson.
+
+        * web-platform-tests/css/css-contain/container-queries/backdrop-invalidation-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/display-contents-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/display-none-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/pseudo-elements-001-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/pseudo-elements-003.tentative-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/size-container-no-principal-box-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/top-layer-dialog-container-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/top-layer-dialog-expected.txt:
+        * web-platform-tests/css/css-contain/container-queries/top-layer-nested-dialog-expected.txt:
+
 2022-02-19  Antoine Quint  <[email protected]>
 
         REGRESSION (r287524): hihello.me does not show sliding sheet at the bottom of the page

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/backdrop-invalidation-expected.txt (290204 => 290205)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/backdrop-invalidation-expected.txt	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/backdrop-invalidation-expected.txt	2022-02-19 14:05:53 UTC (rev 290205)
@@ -1,3 +1,3 @@
 
-FAIL Pseudo-element ::backdrop responds to container size changes assert_equals: expected "rgb(0, 0, 0)" but got "rgb(0, 128, 0)"
+FAIL Pseudo-element ::backdrop responds to container size changes assert_equals: expected "rgb(0, 128, 0)" but got "rgb(0, 0, 0)"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/display-contents-expected.txt (290204 => 290205)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/display-contents-expected.txt	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/display-contents-expected.txt	2022-02-19 14:05:53 UTC (rev 290205)
@@ -1,5 +1,5 @@
 
-FAIL getComputedStyle when container is display:contents assert_equals: expected "" but got "50"
-FAIL getComputedStyle when container becomes display:contents assert_equals: expected "" but got "50"
-FAIL getComputedStyle when intermediate container becomes display:contents assert_equals: expected "" but got "50"
+PASS getComputedStyle when container is display:contents
+PASS getComputedStyle when container becomes display:contents
+PASS getComputedStyle when intermediate container becomes display:contents
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/display-none-expected.txt (290204 => 290205)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/display-none-expected.txt	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/display-none-expected.txt	2022-02-19 14:05:53 UTC (rev 290205)
@@ -1,19 +1,19 @@
 
-FAIL getComputedStyle when element is display:none assert_equals: expected "30" but got "50"
-FAIL getComputedStyle when parent is display:none assert_equals: expected "30" but got "50"
-FAIL getComputedStyle when ancestor is display:none assert_equals: expected "30" but got "50"
-FAIL getComputedStyle when container is display:none assert_equals: expected "" but got "50"
-FAIL getComputedStyle when element in nested container is display:none assert_equals: expected "30" but got "50"
-FAIL getComputedStyle when inner container is display:none assert_equals: expected "" but got "50"
-FAIL getComputedStyle when intermediate ancestor is display:none assert_equals: expected "" but got "50"
-FAIL getComputedStyle when outer container is display:none assert_equals: expected "" but got "50"
-FAIL getComputedStyle when element becomes display:none assert_equals: expected "30" but got "50"
-FAIL getComputedStyle when parent becomes display:none assert_equals: expected "30" but got "50"
-FAIL getComputedStyle when ancestor becomes display:none assert_equals: expected "30" but got "50"
-FAIL getComputedStyle when container becomes display:none assert_equals: expected "" but got "50"
-FAIL getComputedStyle when intermediate container becomes display:none assert_equals: expected "" but got "50"
+PASS getComputedStyle when element is display:none
+PASS getComputedStyle when parent is display:none
+PASS getComputedStyle when ancestor is display:none
+PASS getComputedStyle when container is display:none
+PASS getComputedStyle when element in nested container is display:none
+PASS getComputedStyle when inner container is display:none
+PASS getComputedStyle when intermediate ancestor is display:none
+PASS getComputedStyle when outer container is display:none
+PASS getComputedStyle when element becomes display:none
+PASS getComputedStyle when parent becomes display:none
+PASS getComputedStyle when ancestor becomes display:none
+PASS getComputedStyle when container becomes display:none
+PASS getComputedStyle when intermediate container becomes display:none
 PASS getComputedStyle when ::before is display:none
-FAIL getComputedStyle when originating element is display:none assert_equals: expected "30" but got "50"
-FAIL getComputedStyle on ::before when ancestor element is display:none assert_equals: expected "30" but got "50"
-FAIL getComputedStyle on ::before when container is display:none assert_equals: expected "" but got "50"
+PASS getComputedStyle when originating element is display:none
+PASS getComputedStyle on ::before when ancestor element is display:none
+PASS getComputedStyle on ::before when container is display:none
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/pseudo-elements-001-expected.txt (290204 => 290205)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/pseudo-elements-001-expected.txt	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/pseudo-elements-001-expected.txt	2022-02-19 14:05:53 UTC (rev 290205)
@@ -1,6 +1,6 @@
 test
 One
 
-FAIL Pseudo-elements ::before and ::after respond to container size changes assert_equals: expected "none" but got "\"before\""
-FAIL Pseudo-element ::marker responds to container size changes assert_equals: expected "rgb(0, 0, 0)" but got "rgb(0, 128, 0)"
+FAIL Pseudo-elements ::before and ::after respond to container size changes assert_equals: expected "\"before\"" but got "none"
+PASS Pseudo-element ::marker responds to container size changes
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/pseudo-elements-003.tentative-expected.txt (290204 => 290205)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/pseudo-elements-003.tentative-expected.txt	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/pseudo-elements-003.tentative-expected.txt	2022-02-19 14:05:53 UTC (rev 290205)
@@ -8,5 +8,5 @@
 PASS Originating element container for ::first-letter
 PASS Originating element container for outer ::first-line
 PASS Originating element container for outer ::first-letter
-FAIL Originating element container for ::backdrop assert_equals: ::backdrop not rendered expected "rgb(0, 255, 0)" but got "rgb(0, 128, 0)"
+PASS Originating element container for ::backdrop
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/size-container-no-principal-box-expected.txt (290204 => 290205)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/size-container-no-principal-box-expected.txt	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/size-container-no-principal-box-expected.txt	2022-02-19 14:05:53 UTC (rev 290205)
@@ -1,5 +1,5 @@
 
 PASS Check that container queries is supported
-FAIL (min-width: 0) does not match a container without a principal box (display:none) assert_equals: expected "rgb(0, 0, 0)" but got "rgb(255, 0, 0)"
+PASS (min-width: 0) does not match a container without a principal box (display:none)
 PASS (min-width: 0) does not match a container without a principal box (display:contents)
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/top-layer-dialog-container-expected.txt (290204 => 290205)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/top-layer-dialog-container-expected.txt	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/top-layer-dialog-container-expected.txt	2022-02-19 14:05:53 UTC (rev 290205)
@@ -1,4 +1,4 @@
 
-FAIL #dialog initially sized by #containing-block assert_equals: expected "rgb(255, 0, 0)" but got "rgb(0, 128, 0)"
+PASS #dialog initially sized by #containing-block
 PASS #dialog sized by viewport
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/top-layer-dialog-expected.txt (290204 => 290205)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/top-layer-dialog-expected.txt	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/top-layer-dialog-expected.txt	2022-02-19 14:05:53 UTC (rev 290205)
@@ -1,6 +1,6 @@
 
-FAIL #container initially wider than 200px assert_equals: expected "rgb(255, 0, 0)" but got "rgb(0, 255, 0)"
-FAIL #container changed to 200px assert_equals: expected "rgb(0, 128, 0)" but got "rgb(0, 255, 0)"
+PASS #container initially wider than 200px
+PASS #container changed to 200px
 PASS Modal dialog still has parent as query container while in top layer
 PASS Container changes width while dialog is in top layer
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/top-layer-nested-dialog-expected.txt (290204 => 290205)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/top-layer-nested-dialog-expected.txt	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/top-layer-nested-dialog-expected.txt	2022-02-19 14:05:53 UTC (rev 290205)
@@ -1,5 +1,5 @@
 
-FAIL Dialogs initially not matching for container queries assert_equals: expected "rgb(255, 0, 0)" but got "rgb(0, 255, 0)"
+PASS Dialogs initially not matching for container queries
 PASS Dialogs still not matching after showModal
 PASS @container queries start matching
 

Modified: trunk/Source/WebCore/ChangeLog (290204 => 290205)


--- trunk/Source/WebCore/ChangeLog	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/Source/WebCore/ChangeLog	2022-02-19 14:05:53 UTC (rev 290205)
@@ -1,3 +1,36 @@
+2022-02-19  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Match container queries correctly in non-rendered subtrees
+        https://bugs.webkit.org/show_bug.cgi?id=236840
+
+        Reviewed by Dean Jackson.
+
+        "If the query container does not have a principal box ... then the result of evaluating the size feature is unknown."
+
+        https://drafts.csswg.org/css-contain-3/#size-container
+
+        * rendering/updating/RenderTreeBuilderFirstLetter.cpp:
+        (WebCore::styleForFirstLetter):
+
+        Remove the assert, this issue is tested by marked-as-failure
+        imported/w3c/web-platform-tests/css/css-contain/container-queries/pseudo-elements-002.tentative.html
+
+        * style/ContainerQueryEvaluator.cpp:
+        (WebCore::Style::ContainerQueryEvaluator::ContainerQueryEvaluator):
+        (WebCore::Style::ContainerQueryEvaluator::evaluate const):
+        (WebCore::Style::ContainerQueryEvaluator::resolveContainer const):
+
+        Factor into a function.
+        If we don't have selector matching state (like we do during style resolution) then look up containers from DOM.
+        An element without a renderer may still be a valid container (size queries againt it evaluate to unknown).
+
+        (WebCore::Style::ContainerQueryEvaluator::evaluateSizeFeature const):
+        * style/ContainerQueryEvaluator.h:
+        * style/ElementRuleCollector.cpp:
+        (WebCore::Style::ElementRuleCollector::containerQueryMatches):
+
+        Evaluate to unknown if we don't have a principal box.
+
 2022-02-19  Alan Bujtas  <[email protected]>
 
         [LFC][IFC] Introduce LineBoxBuilder::collectFallbackFonts

Modified: trunk/Source/WebCore/rendering/updating/RenderTreeBuilderFirstLetter.cpp (290204 => 290205)


--- trunk/Source/WebCore/rendering/updating/RenderTreeBuilderFirstLetter.cpp	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/Source/WebCore/rendering/updating/RenderTreeBuilderFirstLetter.cpp	2022-02-19 14:05:53 UTC (rev 290205)
@@ -41,8 +41,7 @@
 static RenderStyle styleForFirstLetter(const RenderBlock& firstLetterBlock, const RenderObject& firstLetterContainer)
 {
     auto* containerFirstLetterStyle = firstLetterBlock.getCachedPseudoStyle(PseudoId::FirstLetter, &firstLetterContainer.firstLineStyle());
-    // FIXME: There appears to be some path where we have a first letter renderer without first letter style.
-    ASSERT(containerFirstLetterStyle);
+    // FIXME: first-letter style needs to be computed eagerly.
     auto firstLetterStyle = RenderStyle::clone(containerFirstLetterStyle ? *containerFirstLetterStyle : firstLetterContainer.firstLineStyle());
 
     // If we have an initial letter drop that is >= 1, then we need to force floating to be on.

Modified: trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp (290204 => 290205)


--- trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp	2022-02-19 14:05:53 UTC (rev 290205)
@@ -28,6 +28,7 @@
 #include "CSSPrimitiveValue.h"
 #include "CSSToLengthConversionData.h"
 #include "CSSValueList.h"
+#include "ComposedTreeAncestorIterator.h"
 #include "Document.h"
 #include "MediaFeatureNames.h"
 #include "MediaList.h"
@@ -38,49 +39,71 @@
 namespace WebCore::Style {
 
 struct ContainerQueryEvaluator::ResolvedContainer {
-    const RenderBox& renderer;
+    const RenderBox* renderer { nullptr };
     CSSToLengthConversionData conversionData;
 };
 
-ContainerQueryEvaluator::ContainerQueryEvaluator(const Vector<Ref<const Element>>& containers)
-    : m_containers(containers)
+ContainerQueryEvaluator::ContainerQueryEvaluator(const Element& element, PseudoId pseudoId, SelectorMatchingState* selectorMatchingState)
+    : m_element(element)
+    , m_pseudoId(pseudoId)
+    , m_selectorMatchingState(selectorMatchingState)
 {
 }
 
 bool ContainerQueryEvaluator::evaluate(const FilteredContainerQuery& filteredContainerQuery) const
 {
-    if (m_containers.isEmpty())
+    auto container = resolveContainer(filteredContainerQuery);
+    if (!container)
         return false;
 
-    auto makeResolvedContainer = [&](const RenderBox& renderer) -> ResolvedContainer {
-        auto& view = renderer.view();
-        return {
+    return evaluateQuery(filteredContainerQuery.query, *container) == EvaluationResult::True;
+}
+
+auto ContainerQueryEvaluator::resolveContainer(const FilteredContainerQuery& filteredContainerQuery) const -> std::optional<ResolvedContainer>
+{
+    auto makeResolvedContainer = [](const Element& element) -> ResolvedContainer {
+        auto* renderer = dynamicDowncast<RenderBox>(element.renderer());
+        if (!renderer)
+            return { };
+        auto& view = renderer->view();
+        return ResolvedContainer {
             renderer,
-            CSSToLengthConversionData { &renderer.style(), &view.style(), nullptr, &view, 1 }
+            CSSToLengthConversionData { &renderer->style(), &view.style(), nullptr, &view, 1 }
         };
     };
 
-    auto resolveContainer = [&]() -> std::optional<ResolvedContainer> {
-        for (auto& container : makeReversedRange(m_containers)) {
-            auto* renderer = dynamicDowncast<RenderBox>(container->renderer());
-            if (!renderer)
-                return { };
-            if (filteredContainerQuery.nameFilter.isEmpty())
-                return makeResolvedContainer(*renderer);
-            // FIXME: Support type filter.
-            if (renderer->style().containerNames().contains(filteredContainerQuery.nameFilter))
-                return makeResolvedContainer(*renderer);
+    auto isContainerForQuery = [&](const Element& element) {
+        auto* style = element.existingComputedStyle();
+        if (!style)
+            return false;
+        if (style->containerType() == ContainerType::None)
+            return false;
+        if (filteredContainerQuery.nameFilter.isEmpty())
+            return true;
+        return style->containerNames().contains(filteredContainerQuery.nameFilter);
+    };
+
+    if (m_selectorMatchingState) {
+        for (auto& container : makeReversedRange(m_selectorMatchingState->queryContainers)) {
+            if (isContainerForQuery(container))
+                return makeResolvedContainer(container);
         }
         return { };
-    };
+    }
 
-    auto container = resolveContainer();
-    if (!container)
-        return false;
+    if (m_pseudoId != PseudoId::None) {
+        if (isContainerForQuery(m_element))
+            return makeResolvedContainer(m_element);
+    }
 
-    return evaluateQuery(filteredContainerQuery.query, *container) == EvaluationResult::True;
+    for (auto& ancestor : composedTreeAncestors(const_cast<Element&>(m_element.get()))) {
+        if (isContainerForQuery(ancestor))
+            return makeResolvedContainer(ancestor);
+    }
+    return { };
 }
 
+
 auto ContainerQueryEvaluator::evaluateQuery(const CQ::ContainerQuery& containerQuery, const ResolvedContainer& container) const -> EvaluationResult
 {
     return WTF::switchOn(containerQuery, [&](const CQ::ContainerCondition& containerCondition) {
@@ -154,6 +177,13 @@
 
 auto ContainerQueryEvaluator::evaluateSizeFeature(const CQ::SizeFeature& sizeFeature, const ResolvedContainer& container) const -> EvaluationResult
 {
+    // "If the query container does not have a principal box ... then the result of evaluating the size feature is unknown."
+    // https://drafts.csswg.org/css-contain-3/#size-container
+    if (!container.renderer)
+        return EvaluationResult::Unknown;
+
+    auto& renderer = *container.renderer;
+
     auto compare = [](CQ::ComparisonOperator op, auto left, auto right) {
         switch (op) {
         case CQ::ComparisonOperator::LessThan:
@@ -219,14 +249,14 @@
 
     enum class Axis : uint8_t { Both, Block, Inline, Width, Height };
     auto containerSupportsRequiredAxis = [&](Axis axis) {
-        switch (container.renderer.style().containerType()) {
+        switch (renderer.style().containerType()) {
         case ContainerType::Size:
             return true;
         case ContainerType::InlineSize:
             if (axis == Axis::Width)
-                return container.renderer.isHorizontalWritingMode();
+                return renderer.isHorizontalWritingMode();
             if (axis == Axis::Height)
-                return !container.renderer.isHorizontalWritingMode();
+                return !renderer.isHorizontalWritingMode();
             return axis == Axis::Inline;
         case ContainerType::None:
             ASSERT_NOT_REACHED();
@@ -238,7 +268,7 @@
         if (!containerSupportsRequiredAxis(Axis::Width))
             return EvaluationResult::Unknown;
 
-        return evaluateSize(container.renderer.contentWidth());
+        return evaluateSize(renderer.contentWidth());
     }
 
     if (sizeFeature.name == CQ::FeatureNames::height()) {
@@ -245,7 +275,7 @@
         if (!containerSupportsRequiredAxis(Axis::Height))
             return EvaluationResult::Unknown;
 
-        return evaluateSize(container.renderer.contentHeight());
+        return evaluateSize(renderer.contentHeight());
     }
 
     if (sizeFeature.name == CQ::FeatureNames::inlineSize()) {
@@ -252,7 +282,7 @@
         if (!containerSupportsRequiredAxis(Axis::Inline))
             return EvaluationResult::Unknown;
 
-        return evaluateSize(container.renderer.contentLogicalWidth());
+        return evaluateSize(renderer.contentLogicalWidth());
     }
 
     if (sizeFeature.name == CQ::FeatureNames::blockSize()) {
@@ -259,7 +289,7 @@
         if (!containerSupportsRequiredAxis(Axis::Block))
             return EvaluationResult::Unknown;
 
-        return evaluateSize(container.renderer.contentLogicalHeight());
+        return evaluateSize(renderer.contentLogicalHeight());
     }
 
     if (sizeFeature.name == CQ::FeatureNames::aspectRatio()) {
@@ -266,7 +296,7 @@
         if (!containerSupportsRequiredAxis(Axis::Both))
             return EvaluationResult::Unknown;
 
-        auto boxRatio = container.renderer.contentWidth().toDouble() / container.renderer.contentHeight().toDouble();
+        auto boxRatio = renderer.contentWidth().toDouble() / renderer.contentHeight().toDouble();
         
         if (!sizeFeature.leftComparison && !sizeFeature.rightComparison)
             return toEvaluationResult(!!boxRatio);
@@ -291,7 +321,7 @@
 
         auto& value = downcast<CSSPrimitiveValue>(*sizeFeature.rightComparison->value);
 
-        bool isPortrait = container.renderer.contentHeight() >= container.renderer.contentWidth();
+        bool isPortrait = renderer.contentHeight() >= renderer.contentWidth();
         if (value.valueID() == CSSValuePortrait)
             return toEvaluationResult(isPortrait);
         if (value.valueID() == CSSValueLandscape)

Modified: trunk/Source/WebCore/style/ContainerQueryEvaluator.h (290204 => 290205)


--- trunk/Source/WebCore/style/ContainerQueryEvaluator.h	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/Source/WebCore/style/ContainerQueryEvaluator.h	2022-02-19 14:05:53 UTC (rev 290205)
@@ -25,6 +25,7 @@
 #pragma once
 
 #include "ContainerQuery.h"
+#include "SelectorMatchingState.h"
 #include <wtf/Ref.h>
 
 namespace WebCore {
@@ -37,12 +38,13 @@
 
 class ContainerQueryEvaluator {
 public:
-    ContainerQueryEvaluator(const Vector<Ref<const Element>>& containers);
+    ContainerQueryEvaluator(const Element&, PseudoId, SelectorMatchingState*);
 
     bool evaluate(const FilteredContainerQuery&) const;
 
 private:
     struct ResolvedContainer;
+    std::optional<ResolvedContainer> resolveContainer(const FilteredContainerQuery&) const;
 
     EvaluationResult evaluateQuery(const CQ::ContainerQuery&, const ResolvedContainer&) const;
     EvaluationResult evaluateQuery(const CQ::SizeQuery&, const ResolvedContainer&) const;
@@ -49,7 +51,9 @@
     template<typename ConditionType> EvaluationResult evaluateCondition(const ConditionType&, const ResolvedContainer&) const;
     EvaluationResult evaluateSizeFeature(const CQ::SizeFeature&, const ResolvedContainer&) const;
 
-    const Vector<Ref<const Element>>& m_containers;
+    const Ref<const Element> m_element;
+    const PseudoId m_pseudoId;
+    SelectorMatchingState* m_selectorMatchingState;
 };
 
 inline EvaluationResult toEvaluationResult(bool boolean)

Modified: trunk/Source/WebCore/style/ElementRuleCollector.cpp (290204 => 290205)


--- trunk/Source/WebCore/style/ElementRuleCollector.cpp	2022-02-19 13:30:26 UTC (rev 290204)
+++ trunk/Source/WebCore/style/ElementRuleCollector.cpp	2022-02-19 14:05:53 UTC (rev 290205)
@@ -507,10 +507,7 @@
 
 bool ElementRuleCollector::containerQueryMatches(const FilteredContainerQuery& query)
 {
-    if (!m_selectorMatchingState)
-        return true;
-
-    ContainerQueryEvaluator evaluator(m_selectorMatchingState->queryContainers);
+    ContainerQueryEvaluator evaluator(element(), m_pseudoElementRequest.pseudoId , m_selectorMatchingState);
     return evaluator.evaluate(query);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to