Title: [291154] trunk
Revision
291154
Author
[email protected]
Date
2022-03-11 03:51:29 -0800 (Fri, 11 Mar 2022)

Log Message

[CSS Container Queries] Only apply inline-size containment when it is allowed
https://bugs.webkit.org/show_bug.cgi?id=237761

Reviewed by Antoine Quint.

LayoutTests/imported/w3c:

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

Source/WebCore:

"Giving an element inline-size containment has no effect if any of the following are true:

if the element does not generate a principal box (as is the case with display: contents or display: none)
if its inner display type is table
if its principal box is an internal table box
if its principal box is an internal ruby box or a non-atomic inline-level box"

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

* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::computeInlinePreferredLogicalWidths const):

Check for valid inline-size containment.

* rendering/RenderObject.cpp:
(WebCore::shouldApplyInlineSizeContainment):
* rendering/RenderObject.h:
* style/ContainerQueryEvaluator.cpp:
(WebCore::Style::ContainerQueryEvaluator::selectContainer const):

Cleanups.

(WebCore::Style::ContainerQueryEvaluator::evaluateSizeFeature const):

Check for valid size containment for the type, evaluate to unknown if it doesn't exist.
Also check layout containment.

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (291153 => 291154)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-11 11:17:29 UTC (rev 291153)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-11 11:51:29 UTC (rev 291154)
@@ -1,3 +1,12 @@
+2022-03-11  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Only apply inline-size containment when it is allowed
+        https://bugs.webkit.org/show_bug.cgi?id=237761
+
+        Reviewed by Antoine Quint.
+
+        * web-platform-tests/css/css-contain/container-queries/ineligible-containment-expected.txt:
+
 2022-03-10  Antoine Quint  <[email protected]>
 
         [web-animations] mask-origin should support discrete animation

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/ineligible-containment-expected.txt (291153 => 291154)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/ineligible-containment-expected.txt	2022-03-11 11:17:29 UTC (rev 291153)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/ineligible-containment-expected.txt	2022-03-11 11:51:29 UTC (rev 291154)
@@ -3,6 +3,6 @@
 Test1
 
 
-FAIL Container ineligible for containment assert_equals: expected "rgb(0, 128, 0)" but got "rgb(255, 0, 0)"
-FAIL Changing containment eligibility invalidates style assert_equals: expected "rgb(0, 128, 0)" but got "rgb(255, 0, 0)"
+PASS Container ineligible for containment
+PASS Changing containment eligibility invalidates style
 

Modified: trunk/Source/WebCore/ChangeLog (291153 => 291154)


--- trunk/Source/WebCore/ChangeLog	2022-03-11 11:17:29 UTC (rev 291153)
+++ trunk/Source/WebCore/ChangeLog	2022-03-11 11:51:29 UTC (rev 291154)
@@ -1,3 +1,37 @@
+2022-03-11  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Only apply inline-size containment when it is allowed
+        https://bugs.webkit.org/show_bug.cgi?id=237761
+
+        Reviewed by Antoine Quint.
+
+        "Giving an element inline-size containment has no effect if any of the following are true:
+
+        if the element does not generate a principal box (as is the case with display: contents or display: none)
+        if its inner display type is table
+        if its principal box is an internal table box
+        if its principal box is an internal ruby box or a non-atomic inline-level box"
+
+        https://drafts.csswg.org/css-contain-3/#containment-inline-size
+
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::computeInlinePreferredLogicalWidths const):
+
+        Check for valid inline-size containment.
+
+        * rendering/RenderObject.cpp:
+        (WebCore::shouldApplyInlineSizeContainment):
+        * rendering/RenderObject.h:
+        * style/ContainerQueryEvaluator.cpp:
+        (WebCore::Style::ContainerQueryEvaluator::selectContainer const):
+
+        Cleanups.
+
+        (WebCore::Style::ContainerQueryEvaluator::evaluateSizeFeature const):
+
+        Check for valid size containment for the type, evaluate to unknown if it doesn't exist.
+        Also check layout containment.
+
 2022-03-11  Zan Dobersek  <[email protected]>
 
         Unreviewed isInGPUProcess() fix after 248209@main

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (291153 => 291154)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2022-03-11 11:17:29 UTC (rev 291153)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2022-03-11 11:51:29 UTC (rev 291154)
@@ -4095,7 +4095,7 @@
 {
     // "The inline-axis intrinsic sizes of the principal box are determined as if the element had no content."
     // https://drafts.csswg.org/css-contain-3/#containment-inline-size
-    if (style().effectiveContainment().contains(Containment::InlineSize))
+    if (shouldApplyInlineSizeContainment(*this))
         return;
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (291153 => 291154)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2022-03-11 11:17:29 UTC (rev 291153)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2022-03-11 11:51:29 UTC (rev 291154)
@@ -2603,6 +2603,11 @@
     return renderer.style().containsSize() && (!renderer.isInline() || renderer.isAtomicInlineLevelBox()) && !renderer.isRubyText() && (!renderer.isTablePart() || renderer.isTableCaption()) && !renderer.isTable();
 }
 
+bool WebCore::shouldApplyInlineSizeContainment(const WebCore::RenderObject& renderer)
+{
+    return renderer.style().effectiveContainment().contains(Containment::InlineSize) && (!renderer.isInline() || renderer.isAtomicInlineLevelBox()) && !renderer.isRubyText() && (!renderer.isTablePart() || renderer.isTableCaption()) && !renderer.isTable();
+}
+
 bool WebCore::shouldApplyStyleContainment(const WebCore::RenderObject& renderer)
 {
     if (!renderer.style().containsStyle())

Modified: trunk/Source/WebCore/rendering/RenderObject.h (291153 => 291154)


--- trunk/Source/WebCore/rendering/RenderObject.h	2022-03-11 11:17:29 UTC (rev 291153)
+++ trunk/Source/WebCore/rendering/RenderObject.h	2022-03-11 11:51:29 UTC (rev 291154)
@@ -1210,6 +1210,7 @@
 
 bool shouldApplyLayoutContainment(const RenderObject&);
 bool shouldApplySizeContainment(const RenderObject&);
+bool shouldApplyInlineSizeContainment(const RenderObject&);
 bool shouldApplyStyleContainment(const RenderObject&);
 bool shouldApplyPaintContainment(const RenderObject&);
 bool shouldApplyAnyContainment(const RenderObject&);

Modified: trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp (291153 => 291154)


--- trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp	2022-03-11 11:17:29 UTC (rev 291153)
+++ trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp	2022-03-11 11:51:29 UTC (rev 291154)
@@ -78,19 +78,19 @@
         };
     };
 
-    auto computeUnsupportedAxes = [&](ContainerType containerType, const RenderElement* principalBox) -> OptionSet<CQ::Axis> {
+    auto isValidContainerForRequiredAxes = [&](ContainerType containerType, const RenderElement* principalBox) {
         switch (containerType) {
         case ContainerType::Size:
-            return { };
+            return true;
         case ContainerType::InlineSize:
             // Without a principal box the container matches but the query against it will evaluate to Unknown.
             if (!principalBox)
-                return { };
-            if (!principalBox->isHorizontalWritingMode())
-                return { CQ::Axis::Width, CQ::Axis::Block };
-            return { CQ::Axis::Height, CQ::Axis::Block };
+                return true;
+            if (filteredContainerQuery.axisFilter.contains(CQ::Axis::Block))
+                return false;
+            return !filteredContainerQuery.axisFilter.contains(principalBox->isHorizontalWritingMode() ? CQ::Axis::Height : CQ::Axis::Width);
         case ContainerType::None:
-            return { CQ::Axis::Width, CQ::Axis::Height, CQ::Axis::Inline, CQ::Axis::Block };
+            return false;
         }
         RELEASE_ASSERT_NOT_REACHED();
     };
@@ -99,12 +99,11 @@
         auto* style = element.existingComputedStyle();
         if (!style)
             return false;
-        auto unsupportedAxes = computeUnsupportedAxes(style->containerType(), element.renderer());
-        if (filteredContainerQuery.axisFilter.containsAny(unsupportedAxes))
+        if (!isValidContainerForRequiredAxes(style->containerType(), element.renderer()))
             return false;
         if (filteredContainerQuery.nameFilter.isEmpty())
             return true;
-        return element.existingComputedStyle()->containerNames().contains(filteredContainerQuery.nameFilter);
+        return style->containerNames().contains(filteredContainerQuery.nameFilter);
     };
 
     if (m_selectorMatchingState) {
@@ -201,7 +200,9 @@
 
 auto ContainerQueryEvaluator::evaluateSizeFeature(const CQ::SizeFeature& sizeFeature, const SelectedContainer& container) const -> EvaluationResult
 {
-    // "If the query container does not have a principal box ... then the result of evaluating the size feature is unknown."
+    // "If the query container does not have a principal box, or the principal box is not a layout containment box,
+    // or the query container does not support container size queries on the relevant axes, 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;
@@ -208,6 +209,22 @@
 
     auto& renderer = *container.renderer;
 
+    auto hasEligibleContainment = [&] {
+        if (!shouldApplyLayoutContainment(renderer))
+            return false;
+        switch (renderer.style().containerType()) {
+        case ContainerType::InlineSize:
+            return shouldApplyInlineSizeContainment(renderer);
+        case ContainerType::Size:
+            return shouldApplySizeContainment(renderer);
+        case ContainerType::None:
+            return true;
+        }
+    };
+
+    if (!hasEligibleContainment())
+        return EvaluationResult::Unknown;
+
     auto compare = [](CQ::ComparisonOperator op, auto left, auto right) {
         switch (op) {
         case CQ::ComparisonOperator::LessThan:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to