Title: [289466] trunk
Revision
289466
Author
[email protected]
Date
2022-02-09 04:42:22 -0800 (Wed, 09 Feb 2022)

Log Message

[CSS Container Queries] Implement inline-size containment
https://bugs.webkit.org/show_bug.cgi?id=236354

Reviewed by Antoine Quint.

LayoutTests/imported/w3c:

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

Source/WebCore:

"Giving an element inline-size containment applies size containment to the inline-axis sizing
of its principal box. This means 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

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

Compute inline axis preferred width as if the block had no content.

* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::effectiveContainment const):
* rendering/style/RenderStyleConstants.h:

For completeness, add an enum value for inline-size containment. It can only be set by 'container'
property for now.

* style/StyleScope.cpp:
(WebCore::Style::Scope::updateQueryContainerState):

Ignore block axis for inline-size containers.

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (289465 => 289466)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-09 10:37:47 UTC (rev 289465)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-09 12:42:22 UTC (rev 289466)
@@ -1,3 +1,12 @@
+2022-02-09  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Implement inline-size containment
+        https://bugs.webkit.org/show_bug.cgi?id=236354
+
+        Reviewed by Antoine Quint.
+
+        * web-platform-tests/css/css-contain/container-queries/container-type-containment-expected.txt:
+
 2022-02-09  Ziran Sun  <[email protected]>
 
         [Forms] Improving applyStep() to be in line with specs

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-type-containment-expected.txt (289465 => 289466)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-type-containment-expected.txt	2022-02-09 10:37:47 UTC (rev 289465)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-type-containment-expected.txt	2022-02-09 12:42:22 UTC (rev 289466)
@@ -2,7 +2,7 @@
 A
 
 PASS container-type:inline-size turns on layout containment
-FAIL container-type:inline-size turns on inline-size containment assert_equals: expected 0 but got 12
+PASS container-type:inline-size turns on inline-size containment
 PASS container-type:size turns on full size containment
 PASS container-type:inline/size turns on style containment
 

Modified: trunk/Source/WebCore/ChangeLog (289465 => 289466)


--- trunk/Source/WebCore/ChangeLog	2022-02-09 10:37:47 UTC (rev 289465)
+++ trunk/Source/WebCore/ChangeLog	2022-02-09 12:42:22 UTC (rev 289466)
@@ -1,3 +1,33 @@
+2022-02-09  Antti Koivisto  <[email protected]>
+
+        [CSS Container Queries] Implement inline-size containment
+        https://bugs.webkit.org/show_bug.cgi?id=236354
+
+        Reviewed by Antoine Quint.
+
+        "Giving an element inline-size containment applies size containment to the inline-axis sizing
+        of its principal box. This means 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
+
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::computeInlinePreferredLogicalWidths const):
+
+        Compute inline axis preferred width as if the block had no content.
+
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::effectiveContainment const):
+        * rendering/style/RenderStyleConstants.h:
+
+        For completeness, add an enum value for inline-size containment. It can only be set by 'container'
+        property for now.
+
+        * style/StyleScope.cpp:
+        (WebCore::Style::Scope::updateQueryContainerState):
+
+        Ignore block axis for inline-size containers.
+
 2022-02-09  Ziran Sun  <[email protected]>
 
         [Forms] Improving applyStep() to be in line with specs

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (289465 => 289466)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2022-02-09 10:37:47 UTC (rev 289465)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2022-02-09 12:42:22 UTC (rev 289466)
@@ -4081,6 +4081,11 @@
 
 void RenderBlockFlow::computeInlinePreferredLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
 {
+    // "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))
+        return;
+
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
     if (const_cast<RenderBlockFlow&>(*this).tryComputePreferredWidthsUsingModernPath(minLogicalWidth, maxLogicalWidth))
         return;

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (289465 => 289466)


--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2022-02-09 10:37:47 UTC (rev 289465)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2022-02-09 12:42:22 UTC (rev 289466)
@@ -2835,8 +2835,7 @@
         containment.add({ Containment::Layout, Containment::Style, Containment::Size });
         break;
     case ContainerType::InlineSize:
-        // FIXME: Support inline-size containment.
-        containment.add({ Containment::Layout, Containment::Style });
+        containment.add({ Containment::Layout, Containment::Style, Containment::InlineSize });
         break;
     };
 

Modified: trunk/Source/WebCore/rendering/style/RenderStyleConstants.h (289465 => 289466)


--- trunk/Source/WebCore/rendering/style/RenderStyleConstants.h	2022-02-09 10:37:47 UTC (rev 289465)
+++ trunk/Source/WebCore/rendering/style/RenderStyleConstants.h	2022-02-09 12:42:22 UTC (rev 289466)
@@ -1225,10 +1225,11 @@
 };
 
 enum class Containment : uint8_t {
-    Layout   = 1 << 0,
-    Paint    = 1 << 1,
-    Size     = 1 << 2,
-    Style    = 1 << 3,
+    Layout      = 1 << 0,
+    Paint       = 1 << 1,
+    Size        = 1 << 2,
+    InlineSize  = 1 << 3,
+    Style       = 1 << 4,
 };
 
 enum class ContainerType : uint8_t {

Modified: trunk/Source/WebCore/style/StyleScope.cpp (289465 => 289466)


--- trunk/Source/WebCore/style/StyleScope.cpp	2022-02-09 10:37:47 UTC (rev 289465)
+++ trunk/Source/WebCore/style/StyleScope.cpp	2022-02-09 12:42:22 UTC (rev 289466)
@@ -797,9 +797,23 @@
         auto* containerElement = containerRenderer.element();
         if (!containerElement)
             continue;
-        auto size = containerRenderer.size();
+        
+        auto size = containerRenderer.logicalSize();
+
+        auto sizeChanged = [&](LayoutSize oldSize) {
+            switch (containerRenderer.style().containerType()) {
+            case ContainerType::InlineSize:
+                return size.width() != oldSize.width();
+            case ContainerType::Size:
+                return size != oldSize;
+            case ContainerType::None:
+                ASSERT_NOT_REACHED();
+                return false;
+            }
+        };
+
         auto it = previousStates.find(*containerElement);
-        bool changed = it == previousStates.end() || it->value != size;
+        bool changed = it == previousStates.end() || sizeChanged(it->value);
         if (changed)
             changedContainers.append(containerElement);
         m_queryContainerStates.add(*containerElement, size);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to