Changeset 284642 in webkit


Ignore:
Timestamp:
Oct 21, 2021 1:48:28 PM (9 months ago)
Author:
commit-queue@webkit.org
Message:

[css-contain] Support contain:style for counters
https://bugs.webkit.org/show_bug.cgi?id=226458

Patch by Rob Buis <rbuis@igalia.com> on 2021-10-21
Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

Update improved test results.

  • web-platform-tests/css/css-contain/content-visibility/content-visibility-026-expected.txt:
  • web-platform-tests/css/css-contain/parsing/contain-computed-expected.txt:
  • web-platform-tests/css/css-contain/parsing/contain-valid-expected.txt:

Source/WebCore:

Parse contain: style and use it (if set) to scope
counter-increment to the element's sub-tree [1].

Tests: imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-001.html

imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-002.html
imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-003.html
imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-004.html

[1] https://drafts.csswg.org/css-contain-2/#containment-style

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::ComputedStyleExtractor::valueForPropertyInStyle):

  • css/parser/CSSPropertyParser.cpp:

(WebCore::consumeContain):

  • rendering/RenderCounter.cpp:

(WebCore::ancestorStyleContainmentObject):
(WebCore::previousInPreOrder):
(WebCore::previousSiblingOrParentElement):
(WebCore::makeCounterNode):
(WebCore::RenderCounter::rendererSubtreeAttached):

  • rendering/RenderObject.cpp:

(WebCore::shouldApplyStyleContainment):

  • rendering/RenderObject.h:
  • rendering/style/RenderStyle.h:

(WebCore::RenderStyle::containsStyle const):

  • rendering/style/RenderStyleConstants.h:
  • style/StyleBuilderCustom.h:

(WebCore::Style::BuilderCustom::applyValueContain):

LayoutTests:

Unskip tests that now pass.

Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r284640 r284642  
     12021-10-21  Rob Buis  <rbuis@igalia.com>
     2
     3        [css-contain] Support contain:style for counters
     4        https://bugs.webkit.org/show_bug.cgi?id=226458
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Unskip tests that now pass.
     9
     10        * TestExpectations:
     11
    1122021-10-21  Eric Hutchison  <ehutchison@apple.com>
    213
  • trunk/LayoutTests/TestExpectations

    r284577 r284642  
    48564856imported/w3c/web-platform-tests/css/css-contain/contain-strict-002.html [ ImageOnlyFailure ]
    48574857imported/w3c/web-platform-tests/css/css-contain/contain-strict-011.html [ ImageOnlyFailure ]
    4858 imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-001.html [ ImageOnlyFailure ]
    4859 imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-002.html [ ImageOnlyFailure ]
    4860 imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-003.html [ ImageOnlyFailure ]
    4861 imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-004.html [ ImageOnlyFailure ]
    48624858imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-032.html [ ImageOnlyFailure ]
    48634859imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-033.sub.https.html [ ImageOnlyFailure ]
     
    48824878imported/w3c/web-platform-tests/css/css-contain/counter-scoping-001.html [ ImageOnlyFailure ]
    48834879imported/w3c/web-platform-tests/css/css-contain/counter-scoping-002.html [ ImageOnlyFailure ]
    4884 imported/w3c/web-platform-tests/css/css-contain/counter-scoping-003.html [ ImageOnlyFailure ]
    48854880imported/w3c/web-platform-tests/css/css-contain/quote-scoping-001.html [ ImageOnlyFailure ]
    48864881imported/w3c/web-platform-tests/css/css-contain/quote-scoping-002.html [ ImageOnlyFailure ]
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r284610 r284642  
     12021-10-21  Rob Buis  <rbuis@igalia.com>
     2
     3        [css-contain] Support contain:style for counters
     4        https://bugs.webkit.org/show_bug.cgi?id=226458
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Update improved test results.
     9
     10        * web-platform-tests/css/css-contain/content-visibility/content-visibility-026-expected.txt:
     11        * web-platform-tests/css/css-contain/parsing/contain-computed-expected.txt:
     12        * web-platform-tests/css/css-contain/parsing/contain-valid-expected.txt:
     13
    1142021-10-21  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-026-expected.txt

    r274957 r284642  
    22FAIL content-visibility: hidden adds contain: size layout style; assert_equals: expected "size layout style paint" but got "none"
    33FAIL content-visibility: auto adds contain: size layout style paint; assert_equals: initial onscreen expected "size layout style paint" but got "none"
    4 FAIL content-visibility: auto adds contain: size layout style paint, can't be overridden assert_equals: expected "size layout style paint" but got "none"
     4FAIL content-visibility: auto adds contain: size layout style paint, can't be overridden assert_equals: expected "size layout style paint" but got "style"
    55FAIL content-visibility keeps all containment even when shorthands are specified assert_equals: expected "size layout style paint" but got "paint"
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/parsing/contain-computed-expected.txt

    r274957 r284642  
    55PASS Property contain value 'size'
    66PASS Property contain value 'layout'
    7 FAIL Property contain value 'style' assert_true: 'style' is a supported value for contain. expected true got false
     7PASS Property contain value 'style'
    88PASS Property contain value 'paint'
    99PASS Property contain value 'size layout'
    10 FAIL Property contain value 'style paint' assert_true: 'style paint' is a supported value for contain. expected true got false
    11 FAIL Property contain value 'layout style paint' assert_true: 'layout style paint' is a supported value for contain. expected true got false
    12 FAIL Property contain value 'size layout style paint' assert_true: 'size layout style paint' is a supported value for contain. expected true got false
     10PASS Property contain value 'style paint'
     11PASS Property contain value 'layout style paint'
     12PASS Property contain value 'size layout style paint'
    1313PASS Property contain value 'size layout paint'
    1414PASS Property contain value 'layout paint'
  • trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/parsing/contain-valid-expected.txt

    r274957 r284642  
    55PASS e.style['contain'] = "size" should set the property value
    66PASS e.style['contain'] = "layout" should set the property value
    7 FAIL e.style['contain'] = "style" should set the property value assert_not_equals: property should be set got disallowed value ""
     7PASS e.style['contain'] = "style" should set the property value
    88PASS e.style['contain'] = "paint" should set the property value
    99PASS e.style['contain'] = "layout size" should set the property value
    10 FAIL e.style['contain'] = "paint style" should set the property value assert_not_equals: property should be set got disallowed value ""
    11 FAIL e.style['contain'] = "layout style paint" should set the property value assert_not_equals: property should be set got disallowed value ""
    12 FAIL e.style['contain'] = "layout paint style size" should set the property value assert_not_equals: property should be set got disallowed value ""
     10PASS e.style['contain'] = "paint style" should set the property value
     11PASS e.style['contain'] = "layout style paint" should set the property value
     12PASS e.style['contain'] = "layout paint style size" should set the property value
    1313
  • trunk/Source/WebCore/ChangeLog

    r284630 r284642  
     12021-10-21  Rob Buis  <rbuis@igalia.com>
     2
     3        [css-contain] Support contain:style for counters
     4        https://bugs.webkit.org/show_bug.cgi?id=226458
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Parse contain: style and use it (if set) to scope
     9        counter-increment to the element's sub-tree [1].
     10
     11        Tests: imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-001.html
     12               imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-002.html
     13               imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-003.html
     14               imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-004.html
     15
     16        [1] https://drafts.csswg.org/css-contain-2/#containment-style
     17
     18        * css/CSSComputedStyleDeclaration.cpp:
     19        (WebCore::ComputedStyleExtractor::valueForPropertyInStyle):
     20        * css/parser/CSSPropertyParser.cpp:
     21        (WebCore::consumeContain):
     22        * rendering/RenderCounter.cpp:
     23        (WebCore::ancestorStyleContainmentObject):
     24        (WebCore::previousInPreOrder):
     25        (WebCore::previousSiblingOrParentElement):
     26        (WebCore::makeCounterNode):
     27        (WebCore::RenderCounter::rendererSubtreeAttached):
     28        * rendering/RenderObject.cpp:
     29        (WebCore::shouldApplyStyleContainment):
     30        * rendering/RenderObject.h:
     31        * rendering/style/RenderStyle.h:
     32        (WebCore::RenderStyle::containsStyle const):
     33        * rendering/style/RenderStyleConstants.h:
     34        * style/StyleBuilderCustom.h:
     35        (WebCore::Style::BuilderCustom::applyValueContain):
     36
    1372021-10-19  Darin Adler  <darin@apple.com>
    238
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r284447 r284642  
    35733573            if (containment & Containment::Layout)
    35743574                list->append(cssValuePool.createIdentifierValue(CSSValueLayout));
     3575            if (containment & Containment::Style)
     3576                list->append(cssValuePool.createIdentifierValue(CSSValueStyle));
    35753577            if (containment & Containment::Paint)
    35763578                list->append(cssValuePool.createIdentifierValue(CSSValuePaint));
  • trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp

    r284440 r284642  
    38683868        return singleValue;
    38693869    auto list = CSSValueList::createSpaceSeparated();
    3870     RefPtr<CSSPrimitiveValue> size, layout, paint;
     3870    RefPtr<CSSPrimitiveValue> size, layout, paint, style;
    38713871    while (!range.atEnd()) {
    38723872        switch (range.peek().id()) {
     
    38863886            paint = consumeIdent(range);
    38873887            break;
     3888        case CSSValueStyle:
     3889            if (style)
     3890                return nullptr;
     3891            style = consumeIdent(range);
     3892            break;
    38883893        default:
    38893894            return nullptr;
     
    38943899    if (layout)
    38953900        list->append(layout.releaseNonNull());
     3901    if (style)
     3902        list->append(style.releaseNonNull());
    38963903    if (paint)
    38973904        list->append(paint.releaseNonNull());
  • trunk/Source/WebCore/rendering/RenderCounter.cpp

    r278253 r284642  
    5858}
    5959
     60static Element* ancestorStyleContainmentObject(const Element& element)
     61{
     62    Element* ancestor = is<PseudoElement>(element) ? downcast<PseudoElement>(element).hostElement() : element.parentElement();
     63    while (ancestor) {
     64        if (auto* style = ancestor->existingComputedStyle()) {
     65            if (style->containsStyle())
     66                break;
     67        }
     68        // FIXME: this should use parentInComposedTree but for now matches the rest of RenderCounter.
     69        ancestor = ancestor->parentElement();
     70    }
     71    return ancestor;
     72}
     73
    6074// This function processes the renderer tree in the order of the DOM tree
    6175// including pseudo elements as defined in CSS 2.1.
     
    6478    ASSERT(renderer.element());
    6579    Element* previous = ElementTraversal::previousIncludingPseudo(*renderer.element());
    66     while (previous && !previous->renderer())
    67         previous = ElementTraversal::previousIncludingPseudo(*previous);
    68     return previous ? previous->renderer() : 0;
     80    Element* styleContainAncestor = ancestorStyleContainmentObject(*renderer.element());
     81
     82    while (true) {
     83        while (previous && !previous->renderer())
     84            previous = ElementTraversal::previousIncludingPseudo(*previous, styleContainAncestor);
     85        if (!previous)
     86            return nullptr;
     87        Element* previousStyleContainAncestor = ancestorStyleContainmentObject(*previous);
     88        if (previousStyleContainAncestor == styleContainAncestor)
     89            return previous->renderer();
     90        if (!previousStyleContainAncestor)
     91            return nullptr;
     92        previous = previousStyleContainAncestor;
     93    }
    6994}
    7095
     
    97122    if (parent && !parent->renderer())
    98123        parent = previousSiblingOrParentElement(*parent);
     124    if (parent && parent->renderer() && parent->renderer()->style().containsStyle())
     125        return nullptr;
    99126    return parent;
    100127}
     
    336363    renderer.setHasCounterNodeMap(true);
    337364
    338     if (newNode->parent())
     365    if (newNode->parent() || shouldApplyStyleContainment(renderer))
    339366        return newNode.ptr();
    340367
     
    344371    bool skipDescendants = false;
    345372    while ((currentRenderer = nextInPreOrder(*currentRenderer, stayWithin, skipDescendants))) {
    346         skipDescendants = false;
     373        skipDescendants = shouldApplyStyleContainment(*currentRenderer);
    347374        if (!currentRenderer->hasCounterNodeMap())
    348375            continue;
     
    550577    if (element && !element->renderer())
    551578        return; // No need to update if the parent is not attached yet
     579    bool crossedStyleContainmentBoundary = false;
    552580    for (RenderObject* descendant = &renderer; descendant; descendant = descendant->nextInPreOrder(&renderer)) {
    553         if (is<RenderElement>(*descendant))
     581        crossedStyleContainmentBoundary = crossedStyleContainmentBoundary || shouldApplyStyleContainment(*descendant);
     582        if (crossedStyleContainmentBoundary && is<RenderElement>(*descendant))
    554583            updateCounters(downcast<RenderElement>(*descendant));
    555584    }
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r284366 r284642  
    25402540    return renderer.style().containsSize() && (!renderer.isInline() || renderer.isAtomicInlineLevelBox()) && !renderer.isRubyText() && (!renderer.isTablePart() || renderer.isTableCaption()) && !renderer.isTable();
    25412541}
     2542
     2543bool WebCore::shouldApplyStyleContainment(const WebCore::RenderObject& renderer)
     2544{
     2545    if (!renderer.style().containsStyle())
     2546        return false;
     2547    return (!renderer.isInline() || renderer.isAtomicInlineLevelBox()) && !renderer.isRubyText() && (!renderer.isTablePart() || renderer.isTableCaption()) && !renderer.isTable();
     2548}
  • trunk/Source/WebCore/rendering/RenderObject.h

    r284080 r284642  
    12091209bool shouldApplyLayoutContainment(const RenderObject&);
    12101210bool shouldApplySizeContainment(const RenderObject&);
     1211bool shouldApplyStyleContainment(const RenderObject&);
    12111212
    12121213} // namespace WebCore
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r284366 r284642  
    532532    bool containsLayout() const { return m_rareNonInheritedData->contain.contains(Containment::Layout); }
    533533    bool containsSize() const { return m_rareNonInheritedData->contain.contains(Containment::Size); }
     534    bool containsStyle() const { return m_rareNonInheritedData->contain.contains(Containment::Style); }
    534535    BoxAlignment boxAlign() const { return static_cast<BoxAlignment>(m_rareNonInheritedData->deprecatedFlexibleBox->align); }
    535536    BoxDirection boxDirection() const { return static_cast<BoxDirection>(m_inheritedFlags.boxDirection); }
  • trunk/Source/WebCore/rendering/style/RenderStyleConstants.h

    r282750 r284642  
    12421242    Paint    = 1 << 1,
    12431243    Size     = 1 << 2,
     1244    Style    = 1 << 3,
    12441245};
    12451246
  • trunk/Source/WebCore/style/StyleBuilderCustom.h

    r284437 r284642  
    12771277        case CSSValuePaint:
    12781278            containment.add(Containment::Paint);
     1279            break;
     1280        case CSSValueStyle:
     1281            containment.add(Containment::Style);
    12791282            break;
    12801283        default:
Note: See TracChangeset for help on using the changeset viewer.