Changeset 291154 in webkit


Ignore:
Timestamp:
Mar 11, 2022 3:51:29 AM (4 months ago)
Author:
Antti Koivisto
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.

Location:
trunk
Files:
7 edited

Legend:

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

    r291148 r291154  
     12022-03-11  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS Container Queries] Only apply inline-size containment when it is allowed
     4        https://bugs.webkit.org/show_bug.cgi?id=237761
     5
     6        Reviewed by Antoine Quint.
     7
     8        * web-platform-tests/css/css-contain/container-queries/ineligible-containment-expected.txt:
     9
    1102022-03-10  Antoine Quint  <graouts@webkit.org>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/container-queries/ineligible-containment-expected.txt

    r288786 r291154  
    44
    55
    6 FAIL Container ineligible for containment assert_equals: expected "rgb(0, 128, 0)" but got "rgb(255, 0, 0)"
    7 FAIL Changing containment eligibility invalidates style assert_equals: expected "rgb(0, 128, 0)" but got "rgb(255, 0, 0)"
     6PASS Container ineligible for containment
     7PASS Changing containment eligibility invalidates style
    88
  • trunk/Source/WebCore/ChangeLog

    r291153 r291154  
     12022-03-11  Antti Koivisto  <antti@apple.com>
     2
     3        [CSS Container Queries] Only apply inline-size containment when it is allowed
     4        https://bugs.webkit.org/show_bug.cgi?id=237761
     5
     6        Reviewed by Antoine Quint.
     7
     8        "Giving an element inline-size containment has no effect if any of the following are true:
     9
     10        if the element does not generate a principal box (as is the case with display: contents or display: none)
     11        if its inner display type is table
     12        if its principal box is an internal table box
     13        if its principal box is an internal ruby box or a non-atomic inline-level box"
     14
     15        https://drafts.csswg.org/css-contain-3/#containment-inline-size
     16
     17        * rendering/RenderBlockFlow.cpp:
     18        (WebCore::RenderBlockFlow::computeInlinePreferredLogicalWidths const):
     19
     20        Check for valid inline-size containment.
     21
     22        * rendering/RenderObject.cpp:
     23        (WebCore::shouldApplyInlineSizeContainment):
     24        * rendering/RenderObject.h:
     25        * style/ContainerQueryEvaluator.cpp:
     26        (WebCore::Style::ContainerQueryEvaluator::selectContainer const):
     27
     28        Cleanups.
     29
     30        (WebCore::Style::ContainerQueryEvaluator::evaluateSizeFeature const):
     31
     32        Check for valid size containment for the type, evaluate to unknown if it doesn't exist.
     33        Also check layout containment.
     34
    1352022-03-11  Zan Dobersek  <zdobersek@igalia.com>
    236
  • trunk/Source/WebCore/rendering/RenderBlockFlow.cpp

    r291134 r291154  
    40964096    // "The inline-axis intrinsic sizes of the principal box are determined as if the element had no content."
    40974097    // https://drafts.csswg.org/css-contain-3/#containment-inline-size
    4098     if (style().effectiveContainment().contains(Containment::InlineSize))
     4098    if (shouldApplyInlineSizeContainment(*this))
    40994099        return;
    41004100
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r290867 r291154  
    26042604}
    26052605
     2606bool WebCore::shouldApplyInlineSizeContainment(const WebCore::RenderObject& renderer)
     2607{
     2608    return renderer.style().effectiveContainment().contains(Containment::InlineSize) && (!renderer.isInline() || renderer.isAtomicInlineLevelBox()) && !renderer.isRubyText() && (!renderer.isTablePart() || renderer.isTableCaption()) && !renderer.isTable();
     2609}
     2610
    26062611bool WebCore::shouldApplyStyleContainment(const WebCore::RenderObject& renderer)
    26072612{
  • trunk/Source/WebCore/rendering/RenderObject.h

    r290881 r291154  
    12111211bool shouldApplyLayoutContainment(const RenderObject&);
    12121212bool shouldApplySizeContainment(const RenderObject&);
     1213bool shouldApplyInlineSizeContainment(const RenderObject&);
    12131214bool shouldApplyStyleContainment(const RenderObject&);
    12141215bool shouldApplyPaintContainment(const RenderObject&);
  • trunk/Source/WebCore/style/ContainerQueryEvaluator.cpp

    r291098 r291154  
    7979    };
    8080
    81     auto computeUnsupportedAxes = [&](ContainerType containerType, const RenderElement* principalBox) -> OptionSet<CQ::Axis> {
     81    auto isValidContainerForRequiredAxes = [&](ContainerType containerType, const RenderElement* principalBox) {
    8282        switch (containerType) {
    8383        case ContainerType::Size:
    84             return { };
     84            return true;
    8585        case ContainerType::InlineSize:
    8686            // Without a principal box the container matches but the query against it will evaluate to Unknown.
    8787            if (!principalBox)
    88                 return { };
    89             if (!principalBox->isHorizontalWritingMode())
    90                 return { CQ::Axis::Width, CQ::Axis::Block };
    91             return { CQ::Axis::Height, CQ::Axis::Block };
     88                return true;
     89            if (filteredContainerQuery.axisFilter.contains(CQ::Axis::Block))
     90                return false;
     91            return !filteredContainerQuery.axisFilter.contains(principalBox->isHorizontalWritingMode() ? CQ::Axis::Height : CQ::Axis::Width);
    9292        case ContainerType::None:
    93             return { CQ::Axis::Width, CQ::Axis::Height, CQ::Axis::Inline, CQ::Axis::Block };
     93            return false;
    9494        }
    9595        RELEASE_ASSERT_NOT_REACHED();
     
    100100        if (!style)
    101101            return false;
    102         auto unsupportedAxes = computeUnsupportedAxes(style->containerType(), element.renderer());
    103         if (filteredContainerQuery.axisFilter.containsAny(unsupportedAxes))
     102        if (!isValidContainerForRequiredAxes(style->containerType(), element.renderer()))
    104103            return false;
    105104        if (filteredContainerQuery.nameFilter.isEmpty())
    106105            return true;
    107         return element.existingComputedStyle()->containerNames().contains(filteredContainerQuery.nameFilter);
     106        return style->containerNames().contains(filteredContainerQuery.nameFilter);
    108107    };
    109108
     
    202201auto ContainerQueryEvaluator::evaluateSizeFeature(const CQ::SizeFeature& sizeFeature, const SelectedContainer& container) const -> EvaluationResult
    203202{
    204     // "If the query container does not have a principal box ... then the result of evaluating the size feature is unknown."
     203    // "If the query container does not have a principal box, or the principal box is not a layout containment box,
     204    // or the query container does not support container size queries on the relevant axes, then the result of
     205    // evaluating the size feature is unknown."
    205206    // https://drafts.csswg.org/css-contain-3/#size-container
    206207    if (!container.renderer)
     
    208209
    209210    auto& renderer = *container.renderer;
     211
     212    auto hasEligibleContainment = [&] {
     213        if (!shouldApplyLayoutContainment(renderer))
     214            return false;
     215        switch (renderer.style().containerType()) {
     216        case ContainerType::InlineSize:
     217            return shouldApplyInlineSizeContainment(renderer);
     218        case ContainerType::Size:
     219            return shouldApplySizeContainment(renderer);
     220        case ContainerType::None:
     221            return true;
     222        }
     223    };
     224
     225    if (!hasEligibleContainment())
     226        return EvaluationResult::Unknown;
    210227
    211228    auto compare = [](CQ::ComparisonOperator op, auto left, auto right) {
Note: See TracChangeset for help on using the changeset viewer.