Title: [284642] trunk
Revision
284642
Author
[email protected]
Date
2021-10-21 13:48:28 -0700 (Thu, 21 Oct 2021)

Log Message

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

Patch by Rob Buis <[email protected]> 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.

* TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (284641 => 284642)


--- trunk/LayoutTests/ChangeLog	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/LayoutTests/ChangeLog	2021-10-21 20:48:28 UTC (rev 284642)
@@ -1,3 +1,14 @@
+2021-10-21  Rob Buis  <[email protected]>
+
+        [css-contain] Support contain:style for counters
+        https://bugs.webkit.org/show_bug.cgi?id=226458
+
+        Reviewed by Antti Koivisto.
+
+        Unskip tests that now pass.
+
+        * TestExpectations:
+
 2021-10-21  Eric Hutchison  <[email protected]>
 
         [ iOS15 EWS ] http/tests/privateClickMeasurement/attribution-conversion-through-image-redirect-with-priority.html crashed.

Modified: trunk/LayoutTests/TestExpectations (284641 => 284642)


--- trunk/LayoutTests/TestExpectations	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/LayoutTests/TestExpectations	2021-10-21 20:48:28 UTC (rev 284642)
@@ -4855,10 +4855,6 @@
 imported/w3c/web-platform-tests/css/css-contain/contain-strict-001.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-contain/contain-strict-002.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-contain/contain-strict-011.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-001.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-002.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-003.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-contain/contain-style-counters-004.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-032.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-033.sub.https.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-034.html [ ImageOnlyFailure ]
@@ -4881,7 +4877,6 @@
 imported/w3c/web-platform-tests/css/css-contain/content-visibility/element-reassigned-to-slot-in-skipped-subtree.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-contain/counter-scoping-001.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-contain/counter-scoping-002.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-contain/counter-scoping-003.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-contain/quote-scoping-001.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-contain/quote-scoping-002.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-contain/quote-scoping-003.html [ ImageOnlyFailure ]

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (284641 => 284642)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-21 20:48:28 UTC (rev 284642)
@@ -1,3 +1,16 @@
+2021-10-21  Rob Buis  <[email protected]>
+
+        [css-contain] Support contain:style for counters
+        https://bugs.webkit.org/show_bug.cgi?id=226458
+
+        Reviewed by Antti Koivisto.
+
+        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:
+
 2021-10-21  Chris Dumez  <[email protected]>
 
         WebKit should process-swap for initial navigation of a popup if it has no opener

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-026-expected.txt (284641 => 284642)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-026-expected.txt	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-026-expected.txt	2021-10-21 20:48:28 UTC (rev 284642)
@@ -1,6 +1,6 @@
 
 FAIL content-visibility: hidden adds contain: size layout style; assert_equals: expected "size layout style paint" but got "none"
 FAIL content-visibility: auto adds contain: size layout style paint; assert_equals: initial onscreen expected "size layout style paint" but got "none"
-FAIL content-visibility: auto adds contain: size layout style paint, can't be overridden assert_equals: expected "size layout style paint" but got "none"
+FAIL content-visibility: auto adds contain: size layout style paint, can't be overridden assert_equals: expected "size layout style paint" but got "style"
 FAIL content-visibility keeps all containment even when shorthands are specified assert_equals: expected "size layout style paint" but got "paint"
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/parsing/contain-computed-expected.txt (284641 => 284642)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/parsing/contain-computed-expected.txt	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/parsing/contain-computed-expected.txt	2021-10-21 20:48:28 UTC (rev 284642)
@@ -4,12 +4,12 @@
 PASS Property contain value 'content'
 PASS Property contain value 'size'
 PASS Property contain value 'layout'
-FAIL Property contain value 'style' assert_true: 'style' is a supported value for contain. expected true got false
+PASS Property contain value 'style'
 PASS Property contain value 'paint'
 PASS Property contain value 'size layout'
-FAIL Property contain value 'style paint' assert_true: 'style paint' is a supported value for contain. expected true got false
-FAIL Property contain value 'layout style paint' assert_true: 'layout style paint' is a supported value for contain. expected true got false
-FAIL Property contain value 'size layout style paint' assert_true: 'size layout style paint' is a supported value for contain. expected true got false
+PASS Property contain value 'style paint'
+PASS Property contain value 'layout style paint'
+PASS Property contain value 'size layout style paint'
 PASS Property contain value 'size layout paint'
 PASS Property contain value 'layout paint'
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/parsing/contain-valid-expected.txt (284641 => 284642)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/parsing/contain-valid-expected.txt	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-contain/parsing/contain-valid-expected.txt	2021-10-21 20:48:28 UTC (rev 284642)
@@ -4,10 +4,10 @@
 PASS e.style['contain'] = "content" should set the property value
 PASS e.style['contain'] = "size" should set the property value
 PASS e.style['contain'] = "layout" should set the property value
-FAIL e.style['contain'] = "style" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['contain'] = "style" should set the property value
 PASS e.style['contain'] = "paint" should set the property value
 PASS e.style['contain'] = "layout size" should set the property value
-FAIL e.style['contain'] = "paint style" should set the property value assert_not_equals: property should be set got disallowed value ""
-FAIL e.style['contain'] = "layout style paint" should set the property value assert_not_equals: property should be set got disallowed value ""
-FAIL e.style['contain'] = "layout paint style size" should set the property value assert_not_equals: property should be set got disallowed value ""
+PASS e.style['contain'] = "paint style" should set the property value
+PASS e.style['contain'] = "layout style paint" should set the property value
+PASS e.style['contain'] = "layout paint style size" should set the property value
 

Modified: trunk/Source/WebCore/ChangeLog (284641 => 284642)


--- trunk/Source/WebCore/ChangeLog	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/Source/WebCore/ChangeLog	2021-10-21 20:48:28 UTC (rev 284642)
@@ -1,3 +1,39 @@
+2021-10-21  Rob Buis  <[email protected]>
+
+        [css-contain] Support contain:style for counters
+        https://bugs.webkit.org/show_bug.cgi?id=226458
+
+        Reviewed by Antti Koivisto.
+
+        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):
+
 2021-10-19  Darin Adler  <[email protected]>
 
         [Cocoa] Merge and simplify the nsColor family of functions

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (284641 => 284642)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2021-10-21 20:48:28 UTC (rev 284642)
@@ -3572,6 +3572,8 @@
                 list->append(cssValuePool.createIdentifierValue(CSSValueSize));
             if (containment & Containment::Layout)
                 list->append(cssValuePool.createIdentifierValue(CSSValueLayout));
+            if (containment & Containment::Style)
+                list->append(cssValuePool.createIdentifierValue(CSSValueStyle));
             if (containment & Containment::Paint)
                 list->append(cssValuePool.createIdentifierValue(CSSValuePaint));
             return list;

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp (284641 => 284642)


--- trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp	2021-10-21 20:48:28 UTC (rev 284642)
@@ -3867,7 +3867,7 @@
     if (auto singleValue = consumeIdent<CSSValueNone, CSSValueStrict, CSSValueContent>(range))
         return singleValue;
     auto list = CSSValueList::createSpaceSeparated();
-    RefPtr<CSSPrimitiveValue> size, layout, paint;
+    RefPtr<CSSPrimitiveValue> size, layout, paint, style;
     while (!range.atEnd()) {
         switch (range.peek().id()) {
         case CSSValueSize:
@@ -3885,6 +3885,11 @@
                 return nullptr;
             paint = consumeIdent(range);
             break;
+        case CSSValueStyle:
+            if (style)
+                return nullptr;
+            style = consumeIdent(range);
+            break;
         default:
             return nullptr;
         }
@@ -3893,6 +3898,8 @@
         list->append(size.releaseNonNull());
     if (layout)
         list->append(layout.releaseNonNull());
+    if (style)
+        list->append(style.releaseNonNull());
     if (paint)
         list->append(paint.releaseNonNull());
     if (!list->length())

Modified: trunk/Source/WebCore/rendering/RenderCounter.cpp (284641 => 284642)


--- trunk/Source/WebCore/rendering/RenderCounter.cpp	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/Source/WebCore/rendering/RenderCounter.cpp	2021-10-21 20:48:28 UTC (rev 284642)
@@ -57,6 +57,20 @@
     return staticCounterMaps;
 }
 
+static Element* ancestorStyleContainmentObject(const Element& element)
+{
+    Element* ancestor = is<PseudoElement>(element) ? downcast<PseudoElement>(element).hostElement() : element.parentElement();
+    while (ancestor) {
+        if (auto* style = ancestor->existingComputedStyle()) {
+            if (style->containsStyle())
+                break;
+        }
+        // FIXME: this should use parentInComposedTree but for now matches the rest of RenderCounter.
+        ancestor = ancestor->parentElement();
+    }
+    return ancestor;
+}
+
 // This function processes the renderer tree in the order of the DOM tree
 // including pseudo elements as defined in CSS 2.1.
 static RenderElement* previousInPreOrder(const RenderElement& renderer)
@@ -63,9 +77,20 @@
 {
     ASSERT(renderer.element());
     Element* previous = ElementTraversal::previousIncludingPseudo(*renderer.element());
-    while (previous && !previous->renderer())
-        previous = ElementTraversal::previousIncludingPseudo(*previous);
-    return previous ? previous->renderer() : 0;
+    Element* styleContainAncestor = ancestorStyleContainmentObject(*renderer.element());
+
+    while (true) {
+        while (previous && !previous->renderer())
+            previous = ElementTraversal::previousIncludingPseudo(*previous, styleContainAncestor);
+        if (!previous)
+            return nullptr;
+        Element* previousStyleContainAncestor = ancestorStyleContainmentObject(*previous);
+        if (previousStyleContainAncestor == styleContainAncestor)
+            return previous->renderer();
+        if (!previousStyleContainAncestor)
+            return nullptr;
+        previous = previousStyleContainAncestor;
+    }
 }
 
 static inline Element* parentOrPseudoHostElement(const RenderElement& renderer)
@@ -96,6 +121,8 @@
     auto* parent = element.parentElement();
     if (parent && !parent->renderer())
         parent = previousSiblingOrParentElement(*parent);
+    if (parent && parent->renderer() && parent->renderer()->style().containsStyle())
+        return nullptr;
     return parent;
 }
 
@@ -335,7 +362,7 @@
     maps.add(&renderer, makeUnique<CounterMap>()).iterator->value->add(identifier, newNode.copyRef());
     renderer.setHasCounterNodeMap(true);
 
-    if (newNode->parent())
+    if (newNode->parent() || shouldApplyStyleContainment(renderer))
         return newNode.ptr();
 
     // Check if some nodes that were previously root nodes should become children of this node now.
@@ -343,7 +370,7 @@
     auto* stayWithin = parentOrPseudoHostElement(renderer);
     bool skipDescendants = false;
     while ((currentRenderer = nextInPreOrder(*currentRenderer, stayWithin, skipDescendants))) {
-        skipDescendants = false;
+        skipDescendants = shouldApplyStyleContainment(*currentRenderer);
         if (!currentRenderer->hasCounterNodeMap())
             continue;
         auto* currentCounter = maps.find(currentRenderer)->value->get(identifier);
@@ -549,8 +576,10 @@
         element = renderer.generatingElement();
     if (element && !element->renderer())
         return; // No need to update if the parent is not attached yet
+    bool crossedStyleContainmentBoundary = false;
     for (RenderObject* descendant = &renderer; descendant; descendant = descendant->nextInPreOrder(&renderer)) {
-        if (is<RenderElement>(*descendant))
+        crossedStyleContainmentBoundary = crossedStyleContainmentBoundary || shouldApplyStyleContainment(*descendant);
+        if (crossedStyleContainmentBoundary && is<RenderElement>(*descendant))
             updateCounters(downcast<RenderElement>(*descendant));
     }
 }

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (284641 => 284642)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2021-10-21 20:48:28 UTC (rev 284642)
@@ -2539,3 +2539,10 @@
 {
     return renderer.style().containsSize() && (!renderer.isInline() || renderer.isAtomicInlineLevelBox()) && !renderer.isRubyText() && (!renderer.isTablePart() || renderer.isTableCaption()) && !renderer.isTable();
 }
+
+bool WebCore::shouldApplyStyleContainment(const WebCore::RenderObject& renderer)
+{
+    if (!renderer.style().containsStyle())
+        return false;
+    return (!renderer.isInline() || renderer.isAtomicInlineLevelBox()) && !renderer.isRubyText() && (!renderer.isTablePart() || renderer.isTableCaption()) && !renderer.isTable();
+}

Modified: trunk/Source/WebCore/rendering/RenderObject.h (284641 => 284642)


--- trunk/Source/WebCore/rendering/RenderObject.h	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/Source/WebCore/rendering/RenderObject.h	2021-10-21 20:48:28 UTC (rev 284642)
@@ -1208,6 +1208,7 @@
 
 bool shouldApplyLayoutContainment(const RenderObject&);
 bool shouldApplySizeContainment(const RenderObject&);
+bool shouldApplyStyleContainment(const RenderObject&);
 
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (284641 => 284642)


--- trunk/Source/WebCore/rendering/style/RenderStyle.h	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h	2021-10-21 20:48:28 UTC (rev 284642)
@@ -531,6 +531,7 @@
     OptionSet<Containment> contain() const { return m_rareNonInheritedData->contain; }
     bool containsLayout() const { return m_rareNonInheritedData->contain.contains(Containment::Layout); }
     bool containsSize() const { return m_rareNonInheritedData->contain.contains(Containment::Size); }
+    bool containsStyle() const { return m_rareNonInheritedData->contain.contains(Containment::Style); }
     BoxAlignment boxAlign() const { return static_cast<BoxAlignment>(m_rareNonInheritedData->deprecatedFlexibleBox->align); }
     BoxDirection boxDirection() const { return static_cast<BoxDirection>(m_inheritedFlags.boxDirection); }
     float boxFlex() const { return m_rareNonInheritedData->deprecatedFlexibleBox->flex; }

Modified: trunk/Source/WebCore/rendering/style/RenderStyleConstants.h (284641 => 284642)


--- trunk/Source/WebCore/rendering/style/RenderStyleConstants.h	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/Source/WebCore/rendering/style/RenderStyleConstants.h	2021-10-21 20:48:28 UTC (rev 284642)
@@ -1241,6 +1241,7 @@
     Layout   = 1 << 0,
     Paint    = 1 << 1,
     Size     = 1 << 2,
+    Style    = 1 << 3,
 };
 
 CSSBoxType transformBoxToCSSBoxType(TransformBox);

Modified: trunk/Source/WebCore/style/StyleBuilderCustom.h (284641 => 284642)


--- trunk/Source/WebCore/style/StyleBuilderCustom.h	2021-10-21 20:36:10 UTC (rev 284641)
+++ trunk/Source/WebCore/style/StyleBuilderCustom.h	2021-10-21 20:48:28 UTC (rev 284642)
@@ -1277,6 +1277,9 @@
         case CSSValuePaint:
             containment.add(Containment::Paint);
             break;
+        case CSSValueStyle:
+            containment.add(Containment::Style);
+            break;
         default:
             break;
         };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to