Title: [289157] trunk
Revision
289157
Author
[email protected]
Date
2022-02-05 08:37:37 -0800 (Sat, 05 Feb 2022)

Log Message

[RenderTreeBuilder] Clean up column spanners when style change affects containing block
https://bugs.webkit.org/show_bug.cgi?id=236042
<rdar://83975391>

Reviewed by Antti Koivisto.

Source/WebCore:

In addition to removing the leftover spanners after style change, this patch also expands on the type of style changes that may affect
subtree state inside a multicolumn flow.

Tests: fast/multicol/leftover-spanner-on-style-change-crash.html
       fast/multicol/leftover-spanner-on-style-change-crash2.html

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::styleDidChange):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::setStyle):
(WebCore::RenderElement::adjustFragmentedFlowStateOnContainingBlockChangeIfNeeded):
* rendering/RenderElement.h:
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::normalizeTreeAfterStyleChange):

LayoutTests:

* fast/multicol/leftover-spanner-on-style-change-crash-expected.txt: Added.
* fast/multicol/leftover-spanner-on-style-change-crash.html: Added.
* fast/multicol/leftover-spanner-on-style-change-crash2-expected.txt: Added.
* fast/multicol/leftover-spanner-on-style-change-crash2.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (289156 => 289157)


--- trunk/LayoutTests/ChangeLog	2022-02-05 16:35:53 UTC (rev 289156)
+++ trunk/LayoutTests/ChangeLog	2022-02-05 16:37:37 UTC (rev 289157)
@@ -1,3 +1,16 @@
+2022-02-05  Alan Bujtas  <[email protected]>
+
+        [RenderTreeBuilder] Clean up column spanners when style change affects containing block
+        https://bugs.webkit.org/show_bug.cgi?id=236042
+        <rdar://83975391>
+
+        Reviewed by Antti Koivisto.
+
+        * fast/multicol/leftover-spanner-on-style-change-crash-expected.txt: Added.
+        * fast/multicol/leftover-spanner-on-style-change-crash.html: Added.
+        * fast/multicol/leftover-spanner-on-style-change-crash2-expected.txt: Added.
+        * fast/multicol/leftover-spanner-on-style-change-crash2.html: Added.
+
 2022-02-04  Yusuke Suzuki  <[email protected]>
 
         WeakRef deref can return null instead of undefined

Added: trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash-expected.txt (0 => 289157)


--- trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash-expected.txt	2022-02-05 16:37:37 UTC (rev 289157)
@@ -0,0 +1 @@
+

Added: trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash.html (0 => 289157)


--- trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash.html	                        (rev 0)
+++ trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash.html	2022-02-05 16:37:37 UTC (rev 289157)
@@ -0,0 +1,31 @@
+<style>
+  html {
+    columns: 1px;
+  }
+  div::before {
+    content: url();
+  }
+  frame {
+    column-span: all;
+  }
+  :first-child {
+    position: absolute;
+    rotate: 0deg;
+  }
+  :read-only {
+    translate: 0;
+  }
+</style>
+<!-- PASS if no crash or assert. -->
+<script>
+  if (window.testRunner)
+    testRunner.dumpAsText();
+  internals.settings.setTextAutosizingEnabled(true);
+  _onload_ = () => {
+    let div0 = document.createElement('div');
+    document.body.appendChild(div0);
+    div0.appendChild(document.createElement('frame'));
+    document.body.offsetTop;
+    document.designMode = 'on';
+  };
+</script>

Added: trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash2-expected.txt (0 => 289157)


--- trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash2-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash2-expected.txt	2022-02-05 16:37:37 UTC (rev 289157)
@@ -0,0 +1 @@
+

Added: trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash2.html (0 => 289157)


--- trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash2.html	                        (rev 0)
+++ trunk/LayoutTests/fast/multicol/leftover-spanner-on-style-change-crash2.html	2022-02-05 16:37:37 UTC (rev 289157)
@@ -0,0 +1,28 @@
+<style>
+  html {
+    columns: 1px;
+  }
+  div {
+    position: absolute;
+  }
+  table {
+    column-span: all;
+  }
+  :read-only {
+    translate: 0;
+  }
+</style>
+<script>
+<!-- PASS if no crash or assert. -->
+  
+  if (window.testRunner)
+    testRunner.dumpAsText();
+  
+  _onload_ = () => {
+    let div0 = document.createElement('div');
+    document.body.append(div0);
+    div0.append(document.createElement('table'));
+    document.body.offsetTop;
+    document.designMode = 'on';
+  };
+</script>

Modified: trunk/Source/WebCore/ChangeLog (289156 => 289157)


--- trunk/Source/WebCore/ChangeLog	2022-02-05 16:35:53 UTC (rev 289156)
+++ trunk/Source/WebCore/ChangeLog	2022-02-05 16:37:37 UTC (rev 289157)
@@ -1,3 +1,26 @@
+2022-02-05  Alan Bujtas  <[email protected]>
+
+        [RenderTreeBuilder] Clean up column spanners when style change affects containing block
+        https://bugs.webkit.org/show_bug.cgi?id=236042
+        <rdar://83975391>
+
+        Reviewed by Antti Koivisto.
+
+        In addition to removing the leftover spanners after style change, this patch also expands on the type of style changes that may affect
+        subtree state inside a multicolumn flow.
+
+        Tests: fast/multicol/leftover-spanner-on-style-change-crash.html
+               fast/multicol/leftover-spanner-on-style-change-crash2.html
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::styleDidChange):
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::setStyle):
+        (WebCore::RenderElement::adjustFragmentedFlowStateOnContainingBlockChangeIfNeeded):
+        * rendering/RenderElement.h:
+        * rendering/updating/RenderTreeBuilder.cpp:
+        (WebCore::RenderTreeBuilder::normalizeTreeAfterStyleChange):
+
 2022-02-05  Antoine Quint  <[email protected]>
 
         [Web Animations] DocumentTimeline::getAnimatedStyle() should be on Styleable

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (289156 => 289157)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2022-02-05 16:35:53 UTC (rev 289156)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2022-02-05 16:37:37 UTC (rev 289157)
@@ -432,11 +432,10 @@
 
 void RenderBlock::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
 {
-    bool hadTransform = hasTransform();
     RenderBox::styleDidChange(diff, oldStyle);
 
-    if (hadTransform != hasTransform())
-        adjustFragmentedFlowStateOnContainingBlockChangeIfNeeded();
+    if (oldStyle)
+        adjustFragmentedFlowStateOnContainingBlockChangeIfNeeded(*oldStyle, style());
 
     propagateStyleToAnonymousChildren(PropagateToBlockChildrenOnly);
 

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (289156 => 289157)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2022-02-05 16:35:53 UTC (rev 289156)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2022-02-05 16:37:37 UTC (rev 289157)
@@ -533,10 +533,7 @@
     auto oldStyle = m_style.replace(WTFMove(style));
     bool detachedFromParent = !parent();
 
-    // Make sure we invalidate the containing block cache for flows when the contianing block context changes
-    // so that styleDidChange can safely use RenderBlock::locateEnclosingFragmentedFlow()
-    if (oldStyle.position() != m_style.position())
-        adjustFragmentedFlowStateOnContainingBlockChangeIfNeeded();
+    adjustFragmentedFlowStateOnContainingBlockChangeIfNeeded(oldStyle, m_style);
 
     styleDidChange(diff, &oldStyle);
 
@@ -2215,11 +2212,22 @@
     return (imageElement && !imageElement->allowsOrientationOverride()) ? ImageOrientation(ImageOrientation::FromImage) : style().imageOrientation();
 }
 
-void RenderElement::adjustFragmentedFlowStateOnContainingBlockChangeIfNeeded()
+void RenderElement::adjustFragmentedFlowStateOnContainingBlockChangeIfNeeded(const RenderStyle& oldStyle, const RenderStyle& newStyle)
 {
     if (fragmentedFlowState() == NotInsideFragmentedFlow)
         return;
 
+    // Make sure we invalidate the containing block cache for flows when the contianing block context changes
+    // so that styleDidChange can safely use RenderBlock::locateEnclosingFragmentedFlow()
+    // FIXME: Share some code with RenderElement::canContain*.
+    auto mayNotBeContainingBlockForDescendantsAnymore = oldStyle.position() != m_style.position()
+        || oldStyle.hasTransformRelatedProperty() != m_style.hasTransformRelatedProperty()
+        || oldStyle.willChange() != newStyle.willChange()
+        || oldStyle.containsLayout() != newStyle.containsLayout()
+        || oldStyle.containsSize() != newStyle.containsSize();
+    if (!mayNotBeContainingBlockForDescendantsAnymore)
+        return;
+
     // Invalidate the containing block caches.
     if (is<RenderBlock>(*this))
         downcast<RenderBlock>(*this).resetEnclosingFragmentedFlowAndChildInfoIncludingDescendants();

Modified: trunk/Source/WebCore/rendering/RenderElement.h (289156 => 289157)


--- trunk/Source/WebCore/rendering/RenderElement.h	2022-02-05 16:35:53 UTC (rev 289156)
+++ trunk/Source/WebCore/rendering/RenderElement.h	2022-02-05 16:37:37 UTC (rev 289157)
@@ -326,7 +326,7 @@
     void updateOutlineAutoAncestor(bool hasOutlineAuto);
 
     void removeFromRenderFragmentedFlowIncludingDescendants(bool shouldUpdateState);
-    void adjustFragmentedFlowStateOnContainingBlockChangeIfNeeded();
+    void adjustFragmentedFlowStateOnContainingBlockChangeIfNeeded(const RenderStyle& oldStyle, const RenderStyle& newStyle);
 
     bool isVisibleInViewport() const;
 

Modified: trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp (289156 => 289157)


--- trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp	2022-02-05 16:35:53 UTC (rev 289156)
+++ trunk/Source/WebCore/rendering/updating/RenderTreeBuilder.cpp	2022-02-05 16:37:37 UTC (rev 289157)
@@ -671,6 +671,20 @@
             multiColumnBuilder().restoreColumnSpannersForContainer(renderer, downcast<RenderMultiColumnFlow>(*enclosingFragmentedFlow));
             return;
         }
+
+        // Style change may have moved some subtree out of the fragmented flow. Their flow states have already been updated (see adjustFragmentedFlowStateOnContainingBlockChangeIfNeeded)
+        // and here is where we take care of the remaining, spanner tree mutation.
+        WeakHashSet<RenderElement> spannerContainingBlockSet;
+        for (auto& descendant : descendantsOfType<RenderMultiColumnSpannerPlaceholder>(renderer)) {
+            if (auto* containingBlock = descendant.containingBlock(); containingBlock && containingBlock->enclosingFragmentedFlow() != enclosingFragmentedFlow)
+                spannerContainingBlockSet.add(*containingBlock);
+        }
+        auto oldEnclosingFragmentedFlow = WeakPtr { *enclosingFragmentedFlow };
+        for (auto& containingBlock : spannerContainingBlockSet) {
+            if (!oldEnclosingFragmentedFlow)
+                break;
+            multiColumnBuilder().restoreColumnSpannersForContainer(containingBlock, downcast<RenderMultiColumnFlow>(*oldEnclosingFragmentedFlow));
+        }
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to