Title: [191610] trunk
Revision
191610
Author
[email protected]
Date
2015-10-26 16:36:01 -0700 (Mon, 26 Oct 2015)

Log Message

Floating box is misplaced after content change.
https://bugs.webkit.org/show_bug.cgi?id=150271

Reviewed by David Hyatt.

Collapse anonymous block when as the result of a sibling removal only floating siblings are left.

Source/WebCore:

Test: fast/block/collapse-anon-block-with-float-siblings-only.html

* rendering/RenderBlock.cpp:
(WebCore::canCollapseAnonymousBlock):
(WebCore::canMergeContiguousAnonymousBlocks):
(WebCore::RenderBlock::collapseAnonymousBoxChild):
(WebCore::RenderBlock::removeChild):
(WebCore::canMergeAnonymousBlock): Deleted.
* rendering/RenderBlock.h:
* rendering/RenderElement.cpp:
(WebCore::RenderElement::removeAnonymousWrappersForInlinesIfNecessary):

LayoutTests:

* fast/block/collapse-anon-block-with-float-siblings-only-expected.html: Added.
* fast/block/collapse-anon-block-with-float-siblings-only.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (191609 => 191610)


--- trunk/LayoutTests/ChangeLog	2015-10-26 23:08:06 UTC (rev 191609)
+++ trunk/LayoutTests/ChangeLog	2015-10-26 23:36:01 UTC (rev 191610)
@@ -1,3 +1,15 @@
+2015-10-26  Zalan Bujtas  <[email protected]>
+
+        Floating box is misplaced after content change.
+        https://bugs.webkit.org/show_bug.cgi?id=150271
+
+        Reviewed by David Hyatt.
+
+        Collapse anonymous block when as the result of a sibling removal only floating siblings are left.
+
+        * fast/block/collapse-anon-block-with-float-siblings-only-expected.html: Added.
+        * fast/block/collapse-anon-block-with-float-siblings-only.html: Added.
+
 2015-10-26  Jiewen Tan  <[email protected]>
 
         Null dereference loading Blink layout test editing/execCommand/crash-replacing-list-by-list.html

Added: trunk/LayoutTests/fast/block/collapse-anon-block-with-float-siblings-only-expected.html (0 => 191610)


--- trunk/LayoutTests/fast/block/collapse-anon-block-with-float-siblings-only-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/block/collapse-anon-block-with-float-siblings-only-expected.html	2015-10-26 23:36:01 UTC (rev 191610)
@@ -0,0 +1,8 @@
+<!DOCTYPE HTML>
+<head>
+<title>This tests that floating box is properly positioned after removing sibling block content.</title>
+</head>
+<body>
+should not wrap
+</body>
+</html>

Added: trunk/LayoutTests/fast/block/collapse-anon-block-with-float-siblings-only.html (0 => 191610)


--- trunk/LayoutTests/fast/block/collapse-anon-block-with-float-siblings-only.html	                        (rev 0)
+++ trunk/LayoutTests/fast/block/collapse-anon-block-with-float-siblings-only.html	2015-10-26 23:36:01 UTC (rev 191610)
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML>
+<head>
+<title>This tests that floating box is properly positioned after removing sibling block content.</title>
+<style>
+	.floating {
+    	float: left;
+	}
+</style>
+</head>
+<body>
+<span>wrap</span><div id=removeThis></div><div class="floating">should not&nbsp</div>
+<script>
+	if (window.testRunner)
+  		testRunner.waitUntilDone();
+	setTimeout(function() { 
+		var ele = document.getElementById("removeThis"); 
+		ele.parentNode.removeChild(ele);
+		if (window.testRunner)
+			testRunner.notifyDone(); 
+	}, 0);
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (191609 => 191610)


--- trunk/Source/WebCore/ChangeLog	2015-10-26 23:08:06 UTC (rev 191609)
+++ trunk/Source/WebCore/ChangeLog	2015-10-26 23:36:01 UTC (rev 191610)
@@ -1,3 +1,24 @@
+2015-10-26  Zalan Bujtas  <[email protected]>
+
+        Floating box is misplaced after content change.
+        https://bugs.webkit.org/show_bug.cgi?id=150271
+
+        Reviewed by David Hyatt.
+
+        Collapse anonymous block when as the result of a sibling removal only floating siblings are left.
+
+        Test: fast/block/collapse-anon-block-with-float-siblings-only.html
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::canCollapseAnonymousBlock):
+        (WebCore::canMergeContiguousAnonymousBlocks):
+        (WebCore::RenderBlock::collapseAnonymousBoxChild):
+        (WebCore::RenderBlock::removeChild):
+        (WebCore::canMergeAnonymousBlock): Deleted.
+        * rendering/RenderBlock.h:
+        * rendering/RenderElement.cpp:
+        (WebCore::RenderElement::removeAnonymousWrappersForInlinesIfNecessary):
+
 2015-10-26  Jiewen Tan  <[email protected]>
 
         Null dereference loading Blink layout test editing/execCommand/crash-replacing-list-by-list.html

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (191609 => 191610)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2015-10-26 23:08:06 UTC (rev 191609)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2015-10-26 23:36:01 UTC (rev 191610)
@@ -637,7 +637,7 @@
     child->destroy();
 }
 
-static bool canMergeAnonymousBlock(RenderBlock& anonymousBlock)
+static bool canDropAnonymousBlock(const RenderBlock& anonymousBlock)
 {
     if (anonymousBlock.beingDestroyed() || anonymousBlock.continuation())
         return false;
@@ -655,33 +655,32 @@
         if (!previous->isAnonymousBlock())
             return false;
         RenderBlock& previousAnonymousBlock = downcast<RenderBlock>(*previous);
-        if (!canMergeAnonymousBlock(previousAnonymousBlock))
+        if (!canDropAnonymousBlock(previousAnonymousBlock))
             return false;
     }
     if (next) {
         if (!next->isAnonymousBlock())
             return false;
         RenderBlock& nextAnonymousBlock = downcast<RenderBlock>(*next);
-        if (!canMergeAnonymousBlock(nextAnonymousBlock))
+        if (!canDropAnonymousBlock(nextAnonymousBlock))
             return false;
     }
     return true;
 }
 
-void RenderBlock::collapseAnonymousBoxChild(RenderBlock& parent, RenderBlock* child)
+void RenderBlock::dropAnonymousBoxChild(RenderBlock& parent, RenderBlock& child)
 {
     parent.setNeedsLayoutAndPrefWidthsRecalc();
-    parent.setChildrenInline(child->childrenInline());
-    RenderObject* nextSibling = child->nextSibling();
+    parent.setChildrenInline(child.childrenInline());
+    if (auto* childFlowThread = child.flowThreadContainingBlock())
+        childFlowThread->removeFlowChildInfo(&child);
 
-    if (auto* childFlowThread = child->flowThreadContainingBlock())
-        childFlowThread->removeFlowChildInfo(child);
-
-    parent.removeChildInternal(*child, child->hasLayer() ? NotifyChildren : DontNotifyChildren);
-    child->moveAllChildrenTo(&parent, nextSibling, child->hasLayer());
+    RenderObject* nextSibling = child.nextSibling();
+    parent.removeChildInternal(child, child.hasLayer() ? NotifyChildren : DontNotifyChildren);
+    child.moveAllChildrenTo(&parent, nextSibling, child.hasLayer());
     // Delete the now-empty block's lines and nuke it.
-    child->deleteLines();
-    child->destroy();
+    child.deleteLines();
+    child.destroy();
 }
 
 void RenderBlock::removeChild(RenderObject& oldChild)
@@ -746,19 +745,26 @@
     RenderBox::removeChild(oldChild);
 
     RenderObject* child = prev ? prev : next;
-    if (canMergeAnonymousBlocks && child && !child->previousSibling() && !child->nextSibling() && canCollapseAnonymousBlockChild()) {
+    if (canMergeAnonymousBlocks && child && !child->previousSibling() && !child->nextSibling() && canDropAnonymousBlockChild()) {
         // The removal has knocked us down to containing only a single anonymous
         // box. We can pull the content right back up into our box.
-        collapseAnonymousBoxChild(*this, downcast<RenderBlock>(child));
-    } else if (((prev && prev->isAnonymousBlock()) || (next && next->isAnonymousBlock())) && canCollapseAnonymousBlockChild()) {
+        dropAnonymousBoxChild(*this, downcast<RenderBlock>(*child));
+    } else if (((prev && prev->isAnonymousBlock()) || (next && next->isAnonymousBlock())) && canDropAnonymousBlockChild()) {
         // It's possible that the removal has knocked us down to a single anonymous
-        // block with pseudo-style element siblings (e.g. first-letter). If these
-        // are floating, then we need to pull the content up also.
-        RenderBlock* anonBlock = downcast<RenderBlock>((prev && prev->isAnonymousBlock()) ? prev : next);
-        if ((anonBlock->previousSibling() || anonBlock->nextSibling())
-            && (!anonBlock->previousSibling() || (anonBlock->previousSibling()->style().styleType() != NOPSEUDO && anonBlock->previousSibling()->isFloating() && !anonBlock->previousSibling()->previousSibling()))
-            && (!anonBlock->nextSibling() || (anonBlock->nextSibling()->style().styleType() != NOPSEUDO && anonBlock->nextSibling()->isFloating() && !anonBlock->nextSibling()->nextSibling()))) {
-            collapseAnonymousBoxChild(*this, anonBlock);
+        // block with floating siblings.
+        RenderBlock& anonBlock = downcast<RenderBlock>((prev && prev->isAnonymousBlock()) ? *prev : *next);
+        if (canDropAnonymousBlock(anonBlock)) {
+            bool dropAnonymousBlock = true;
+            for (auto& sibling : childrenOfType<RenderObject>(*this)) {
+                if (&sibling == &anonBlock)
+                    continue;
+                if (!sibling.isFloating()) {
+                    dropAnonymousBlock = false;
+                    break;
+                }
+            }
+            if (dropAnonymousBlock)
+                dropAnonymousBoxChild(*this, anonBlock);
         }
     }
 

Modified: trunk/Source/WebCore/rendering/RenderBlock.h (191609 => 191610)


--- trunk/Source/WebCore/rendering/RenderBlock.h	2015-10-26 23:08:06 UTC (rev 191609)
+++ trunk/Source/WebCore/rendering/RenderBlock.h	2015-10-26 23:36:01 UTC (rev 191610)
@@ -195,7 +195,7 @@
 
     static RenderBlock* createAnonymousWithParentRendererAndDisplay(const RenderObject*, EDisplay = BLOCK);
     RenderBlock* createAnonymousBlock(EDisplay display = BLOCK) const { return createAnonymousWithParentRendererAndDisplay(this, display); }
-    static void collapseAnonymousBoxChild(RenderBlock& parent, RenderBlock* child);
+    static void dropAnonymousBoxChild(RenderBlock& parent, RenderBlock& child);
 
     virtual RenderBox* createAnonymousBoxWithSameTypeAs(const RenderObject* parent) const override;
 
@@ -300,7 +300,7 @@
     virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&) override;
 
     virtual bool canHaveChildren() const override { return true; }
-    virtual bool canCollapseAnonymousBlockChild() const { return true; }
+    virtual bool canDropAnonymousBlockChild() const { return true; }
 
     RenderFlowThread* cachedFlowThreadContainingBlock() const;
     void setCachedFlowThreadContainingBlockNeedsUpdate();

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.h (191609 => 191610)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.h	2015-10-26 23:08:06 UTC (rev 191609)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.h	2015-10-26 23:36:01 UTC (rev 191610)
@@ -277,7 +277,7 @@
     }
     void layoutLineGridBox();
 
-    virtual bool canCollapseAnonymousBlockChild() const override { return !renderNamedFlowFragment(); }
+    virtual bool canDropAnonymousBlockChild() const override { return !renderNamedFlowFragment(); }
     RenderNamedFlowFragment* renderNamedFlowFragment() const { return hasRareBlockFlowData() ? rareBlockFlowData()->m_renderNamedFlowFragment : nullptr; }
     void setRenderNamedFlowFragment(RenderNamedFlowFragment*);
 

Modified: trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.h (191609 => 191610)


--- trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.h	2015-10-26 23:08:06 UTC (rev 191609)
+++ trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.h	2015-10-26 23:36:01 UTC (rev 191610)
@@ -47,7 +47,7 @@
     bool isStretchingChildren() const { return m_stretchingChildren; }
 
     virtual bool avoidsFloats() const override { return true; }
-    virtual bool canCollapseAnonymousBlockChild() const override { return false; }
+    virtual bool canDropAnonymousBlockChild() const override { return false; }
 
     void placeChild(RenderBox* child, const LayoutPoint& location, LayoutSize* childLayoutDelta = nullptr);
 

Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (191609 => 191610)


--- trunk/Source/WebCore/rendering/RenderElement.cpp	2015-10-26 23:08:06 UTC (rev 191609)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp	2015-10-26 23:36:01 UTC (rev 191610)
@@ -953,7 +953,7 @@
 void RenderElement::removeAnonymousWrappersForInlinesIfNecessary()
 {
     RenderBlock& parentBlock = downcast<RenderBlock>(*parent());
-    if (!parentBlock.canCollapseAnonymousBlockChild())
+    if (!parentBlock.canDropAnonymousBlockChild())
         return;
 
     // We have changed to floated or out-of-flow positioning so maybe all our parent's
@@ -972,7 +972,7 @@
     for (current = parent()->firstChild(); current; current = next) {
         next = current->nextSibling();
         if (current->isAnonymousBlock())
-            parentBlock.collapseAnonymousBoxChild(parentBlock, downcast<RenderBlock>(current));
+            parentBlock.dropAnonymousBoxChild(parentBlock, downcast<RenderBlock>(*current));
     }
 }
 

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.h (191609 => 191610)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2015-10-26 23:08:06 UTC (rev 191609)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.h	2015-10-26 23:36:01 UTC (rev 191610)
@@ -45,7 +45,7 @@
     virtual const char* renderName() const override;
 
     virtual bool avoidsFloats() const override final { return true; }
-    virtual bool canCollapseAnonymousBlockChild() const override final { return false; }
+    virtual bool canDropAnonymousBlockChild() const override final { return false; }
     virtual void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) override final;
 
     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const override;

Modified: trunk/Source/WebCore/rendering/RenderGrid.h (191609 => 191610)


--- trunk/Source/WebCore/rendering/RenderGrid.h	2015-10-26 23:08:06 UTC (rev 191609)
+++ trunk/Source/WebCore/rendering/RenderGrid.h	2015-10-26 23:36:01 UTC (rev 191610)
@@ -55,7 +55,7 @@
     virtual void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) override;
 
     virtual bool avoidsFloats() const override { return true; }
-    virtual bool canCollapseAnonymousBlockChild() const override { return false; }
+    virtual bool canDropAnonymousBlockChild() const override { return false; }
 
     const Vector<LayoutUnit>& columnPositions() const { return m_columnPositions; }
     const Vector<LayoutUnit>& rowPositions() const { return m_rowPositions; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to