Changeset 289466 in webkit


Ignore:
Timestamp:
Feb 9, 2022 4:42:22 AM (5 months ago)
Author:
Antti Koivisto
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.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r289465 r289466  
     12022-02-09  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS Container Queries] Implement inline-size containment
     4        https://bugs.webkit.org/show_bug.cgi?id=236354
     5
     6        Reviewed by Antoine Quint.
     7
     8        * web-platform-tests/css/css-contain/container-queries/container-type-containment-expected.txt:
     9
    1102022-02-09  Ziran Sun  <zsun@igalia.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/container-type-containment-expected.txt

    r288627 r289466  
    33
    44PASS container-type:inline-size turns on layout containment
    5 FAIL container-type:inline-size turns on inline-size containment assert_equals: expected 0 but got 12
     5PASS container-type:inline-size turns on inline-size containment
    66PASS container-type:size turns on full size containment
    77PASS container-type:inline/size turns on style containment
  • trunk/Source/WebCore/ChangeLog

    r289465 r289466  
     12022-02-09  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS Container Queries] Implement inline-size containment
     4        https://bugs.webkit.org/show_bug.cgi?id=236354
     5
     6        Reviewed by Antoine Quint.
     7
     8        "Giving an element inline-size containment applies size containment to the inline-axis sizing
     9        of its principal box. This means the inline-axis intrinsic sizes of the principal box are
     10        determined as if the element had no content."
     11
     12        https://drafts.csswg.org/css-contain-3/#containment-inline-size
     13
     14        * rendering/RenderBlockFlow.cpp:
     15        (WebCore::RenderBlockFlow::computeInlinePreferredLogicalWidths const):
     16
     17        Compute inline axis preferred width as if the block had no content.
     18
     19        * rendering/style/RenderStyle.cpp:
     20        (WebCore::RenderStyle::effectiveContainment const):
     21        * rendering/style/RenderStyleConstants.h:
     22
     23        For completeness, add an enum value for inline-size containment. It can only be set by 'container'
     24        property for now.
     25
     26        * style/StyleScope.cpp:
     27        (WebCore::Style::Scope::updateQueryContainerState):
     28
     29        Ignore block axis for inline-size containers.
     30
    1312022-02-09  Ziran Sun  <zsun@igalia.com>
    232
  • trunk/Source/WebCore/rendering/RenderBlockFlow.cpp

    r288985 r289466  
    40824082void RenderBlockFlow::computeInlinePreferredLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
    40834083{
     4084    // "The inline-axis intrinsic sizes of the principal box are determined as if the element had no content."
     4085    // https://drafts.csswg.org/css-contain-3/#containment-inline-size
     4086    if (style().effectiveContainment().contains(Containment::InlineSize))
     4087        return;
     4088
    40844089#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    40854090    if (const_cast<RenderBlockFlow&>(*this).tryComputePreferredWidthsUsingModernPath(minLogicalWidth, maxLogicalWidth))
  • trunk/Source/WebCore/rendering/style/RenderStyle.cpp

    r289241 r289466  
    28362836        break;
    28372837    case ContainerType::InlineSize:
    2838         // FIXME: Support inline-size containment.
    2839         containment.add({ Containment::Layout, Containment::Style });
     2838        containment.add({ Containment::Layout, Containment::Style, Containment::InlineSize });
    28402839        break;
    28412840    };
  • trunk/Source/WebCore/rendering/style/RenderStyleConstants.h

    r288465 r289466  
    12261226
    12271227enum class Containment : uint8_t {
    1228     Layout   = 1 << 0,
    1229     Paint    = 1 << 1,
    1230     Size     = 1 << 2,
    1231     Style    = 1 << 3,
     1228    Layout      = 1 << 0,
     1229    Paint       = 1 << 1,
     1230    Size        = 1 << 2,
     1231    InlineSize  = 1 << 3,
     1232    Style       = 1 << 4,
    12321233};
    12331234
  • trunk/Source/WebCore/style/StyleScope.cpp

    r289457 r289466  
    798798        if (!containerElement)
    799799            continue;
    800         auto size = containerRenderer.size();
     800       
     801        auto size = containerRenderer.logicalSize();
     802
     803        auto sizeChanged = [&](LayoutSize oldSize) {
     804            switch (containerRenderer.style().containerType()) {
     805            case ContainerType::InlineSize:
     806                return size.width() != oldSize.width();
     807            case ContainerType::Size:
     808                return size != oldSize;
     809            case ContainerType::None:
     810                ASSERT_NOT_REACHED();
     811                return false;
     812            }
     813        };
     814
    801815        auto it = previousStates.find(*containerElement);
    802         bool changed = it == previousStates.end() || it->value != size;
     816        bool changed = it == previousStates.end() || sizeChanged(it->value);
    803817        if (changed)
    804818            changedContainers.append(containerElement);
Note: See TracChangeset for help on using the changeset viewer.