[New Block-Inside-Inline Model] Self-collapsing block check needs to account for...
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Sep 2015 22:15:46 +0000 (22:15 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Sep 2015 22:15:46 +0000 (22:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=149042

Reviewed by Dean Jackson.

Source/WebCore:

Added new tests in fast/block/inside-inlines/

* rendering/InlineFlowBox.cpp:
* rendering/InlineFlowBox.h:
(WebCore::InlineFlowBox::anonymousInlineBlock):
Add a new accessor to get the anonymousInlineBlock() for lines that wrap them.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::childrenPreventSelfCollapsing):
(WebCore::RenderBlock::isSelfCollapsingBlock):
isSelfCollapsingBlock() now calls a virtual method that checks lines/children called childrenPreventSelfCollapsing.
This lets us farm out the lines check to the derived RenderBlockFlow class.

* rendering/RenderBlock.h:
(WebCore::RenderBlock::childrenPreventSelfCollapsing):
Added new virtual method for checking children.

* rendering/RenderBlockFlow.cpp:
* rendering/RenderBlockFlow.h:
(WebCore::RenderBlockFlow::childrenPreventSelfCollapsing):
Overridden to ensure that blocks can still be self-collapsing if they only contain anonymous inline-block lines that
are also self-collapsing.

LayoutTests:

* fast/block/inside-inlines/new-model/self-collapsing-test-expected.html: Added.
* fast/block/inside-inlines/new-model/self-collapsing-test.html: Added.
* fast/block/inside-inlines/self-collapsing-test-expected.html: Added.
* fast/block/inside-inlines/self-collapsing-test.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189594 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/block/inside-inlines/new-model/self-collapsing-test-expected.html [new file with mode: 0644]
LayoutTests/fast/block/inside-inlines/new-model/self-collapsing-test.html [new file with mode: 0644]
LayoutTests/fast/block/inside-inlines/self-collapsing-test-expected.html [new file with mode: 0644]
LayoutTests/fast/block/inside-inlines/self-collapsing-test.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/InlineFlowBox.cpp
Source/WebCore/rendering/InlineFlowBox.h
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderBlock.h
Source/WebCore/rendering/RenderBlockFlow.cpp
Source/WebCore/rendering/RenderBlockFlow.h

index 35a5d52..9696fdb 100644 (file)
@@ -1,3 +1,15 @@
+2015-09-10  David Hyatt  <hyatt@apple.com>
+
+        [New Block-Inside-Inline Model] Self-collapsing block check needs to account for anonymous inline blocks
+        https://bugs.webkit.org/show_bug.cgi?id=149042
+
+        Reviewed by Dean Jackson.
+
+        * fast/block/inside-inlines/new-model/self-collapsing-test-expected.html: Added.
+        * fast/block/inside-inlines/new-model/self-collapsing-test.html: Added.
+        * fast/block/inside-inlines/self-collapsing-test-expected.html: Added.
+        * fast/block/inside-inlines/self-collapsing-test.html: Added.
+
 2015-09-10  Dewei Zhu  <dewei_zhu@apple.com>
 
         Update windows platform expected results for bug 148810.
diff --git a/LayoutTests/fast/block/inside-inlines/new-model/self-collapsing-test-expected.html b/LayoutTests/fast/block/inside-inlines/new-model/self-collapsing-test-expected.html
new file mode 100644 (file)
index 0000000..66339e3
--- /dev/null
@@ -0,0 +1,13 @@
+<!doctype html>
+<head>
+<style>
+.margin { margin:20px 0 }
+p { margin:0 }
+span { clear:left; float:left; width:20px; height:20px; background-color:green }
+</style>
+<body>
+The two green floats should be stacked right on top of one another.
+<div>
+<span></span>
+<span></span>
+</div>
\ No newline at end of file
diff --git a/LayoutTests/fast/block/inside-inlines/new-model/self-collapsing-test.html b/LayoutTests/fast/block/inside-inlines/new-model/self-collapsing-test.html
new file mode 100644 (file)
index 0000000..36541ea
--- /dev/null
@@ -0,0 +1,20 @@
+<!doctype html>
+<head>
+<style>
+.margin { margin:20px 0 }
+p { margin:0 }
+span { float:left; width:20px; height:20px; background-color:green }
+</style>
+<script>
+if (window.internals)
+    window.internals.settings.setNewBlockInsideInlineModelEnabled(true)
+</script>
+<body>
+The two green floats should be stacked right on top of one another.
+<p><span></span></p>
+<div class="margin">
+<i>
+<div></div>
+</i>
+</div>
+<p><span></span></p>
\ No newline at end of file
diff --git a/LayoutTests/fast/block/inside-inlines/self-collapsing-test-expected.html b/LayoutTests/fast/block/inside-inlines/self-collapsing-test-expected.html
new file mode 100644 (file)
index 0000000..66339e3
--- /dev/null
@@ -0,0 +1,13 @@
+<!doctype html>
+<head>
+<style>
+.margin { margin:20px 0 }
+p { margin:0 }
+span { clear:left; float:left; width:20px; height:20px; background-color:green }
+</style>
+<body>
+The two green floats should be stacked right on top of one another.
+<div>
+<span></span>
+<span></span>
+</div>
\ No newline at end of file
diff --git a/LayoutTests/fast/block/inside-inlines/self-collapsing-test.html b/LayoutTests/fast/block/inside-inlines/self-collapsing-test.html
new file mode 100644 (file)
index 0000000..c098a69
--- /dev/null
@@ -0,0 +1,16 @@
+<!doctype html>
+<head>
+<style>
+.margin { margin:20px 0 }
+p { margin:0 }
+span { float:left; width:20px; height:20px; background-color:green }
+</style>
+<body>
+The two green floats should be stacked right on top of one another.
+<p><span></span></p>
+<div class="margin">
+<i>
+<div></div>
+</i>
+</div>
+<p><span></span></p>
\ No newline at end of file
index a4e4766..5348f97 100644 (file)
@@ -1,3 +1,33 @@
+2015-09-10  David Hyatt  <hyatt@apple.com>
+
+        [New Block-Inside-Inline Model] Self-collapsing block check needs to account for anonymous inline blocks
+        https://bugs.webkit.org/show_bug.cgi?id=149042
+
+        Reviewed by Dean Jackson.
+
+        Added new tests in fast/block/inside-inlines/
+
+        * rendering/InlineFlowBox.cpp:
+        * rendering/InlineFlowBox.h:
+        (WebCore::InlineFlowBox::anonymousInlineBlock):
+        Add a new accessor to get the anonymousInlineBlock() for lines that wrap them.
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::childrenPreventSelfCollapsing):
+        (WebCore::RenderBlock::isSelfCollapsingBlock):
+        isSelfCollapsingBlock() now calls a virtual method that checks lines/children called childrenPreventSelfCollapsing.
+        This lets us farm out the lines check to the derived RenderBlockFlow class.
+
+        * rendering/RenderBlock.h:
+        (WebCore::RenderBlock::childrenPreventSelfCollapsing):
+        Added new virtual method for checking children.
+
+        * rendering/RenderBlockFlow.cpp:
+        * rendering/RenderBlockFlow.h:
+        (WebCore::RenderBlockFlow::childrenPreventSelfCollapsing):
+        Overridden to ensure that blocks can still be self-collapsing if they only contain anonymous inline-block lines that
+        are also self-collapsing.
+
 2015-09-10  Jinyoung Hur  <hur.ims@navercorp.com>
 
         [WebGL][GLES] bad shaders should not be linked not only for GL but also for GL ES
index a874cdc..3ea07c7 100644 (file)
@@ -69,6 +69,11 @@ void InlineFlowBox::setHasBadChildList()
 
 #endif
 
+RenderBlockFlow* InlineFlowBox::anonymousInlineBlock() const
+{
+    return m_hasAnonymousInlineBlock ? &downcast<RenderBlockFlow>(firstChild()->renderer()) : nullptr;
+}
+
 LayoutUnit InlineFlowBox::getFlowSpacingLogicalWidth()
 {
     LayoutUnit totalWidth = marginBorderPaddingLogicalLeft() + marginBorderPaddingLogicalRight();
index af78474..1533f6e 100644 (file)
@@ -214,7 +214,8 @@ public:
     
     bool hasAnonymousInlineBlock() const { return m_hasAnonymousInlineBlock; }
     void setHasAnonymousInlineBlock(bool b) { m_hasAnonymousInlineBlock = b; }
-
+    RenderBlockFlow* anonymousInlineBlock() const;
+    
     void checkConsistency() const;
     void setHasBadChildList();
 
index 86496df..5b4a5a1 100644 (file)
@@ -795,6 +795,19 @@ void RenderBlock::removeChild(RenderObject& oldChild)
     }
 }
 
+bool RenderBlock::childrenPreventSelfCollapsing() const
+{
+    // Whether or not we collapse is dependent on whether all our normal flow children
+    // are also self-collapsing.
+    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
+        if (child->isFloatingOrOutOfFlowPositioned())
+            continue;
+        if (!child->isSelfCollapsingBlock())
+            return true;
+    }
+    return false;
+}
+
 bool RenderBlock::isSelfCollapsingBlock() const
 {
     // We are not self-collapsing if we
@@ -821,22 +834,9 @@ bool RenderBlock::isSelfCollapsingBlock() const
 
     // If the height is 0 or auto, then whether or not we are a self-collapsing block depends
     // on whether we have content that is all self-collapsing or not.
-    if (hasAutoHeight || ((logicalHeightLength.isFixed() || logicalHeightLength.isPercentOrCalculated()) && logicalHeightLength.isZero())) {
-        // If the block has inline children, see if we generated any line boxes.  If we have any
-        // line boxes, then we can't be self-collapsing, since we have content.
-        if (childrenInline())
-            return !hasLines();
-        
-        // Whether or not we collapse is dependent on whether all our normal flow children
-        // are also self-collapsing.
-        for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
-            if (child->isFloatingOrOutOfFlowPositioned())
-                continue;
-            if (!child->isSelfCollapsingBlock())
-                return false;
-        }
-        return true;
-    }
+    if (hasAutoHeight || ((logicalHeightLength.isFixed() || logicalHeightLength.isPercentOrCalculated()) && logicalHeightLength.isZero()))
+        return !childrenPreventSelfCollapsing();
+
     return false;
 }
 
index 907fe49..f3d5a10 100644 (file)
@@ -413,7 +413,9 @@ private:
     void addChildToContinuation(RenderObject* newChild, RenderObject* beforeChild);
     virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild) override;
 
-    virtual bool isSelfCollapsingBlock() const override final;
+    virtual bool isSelfCollapsingBlock() const override;
+    virtual bool childrenPreventSelfCollapsing() const;
+    
     // FIXME-BLOCKFLOW: Remove virtualizaion when all callers have moved to RenderBlockFlow
     virtual bool hasLines() const { return false; }
 
index e1f3f17..97426b0 100644 (file)
@@ -944,6 +944,27 @@ RenderBlockFlow::MarginValues RenderBlockFlow::marginValuesForChild(RenderBox& c
     return MarginValues(childBeforePositive, childBeforeNegative, childAfterPositive, childAfterNegative);
 }
 
+bool RenderBlockFlow::childrenPreventSelfCollapsing() const
+{
+    if (!childrenInline())
+        return RenderBlock::childrenPreventSelfCollapsing();
+
+    // If the block has inline children, see if we generated any line boxes. If we have any
+    // line boxes, then we can only be self-collapsing if we have nothing but anonymous inline blocks
+    // that are also self-collapsing inside us.
+    if (!hasLines())
+        return false;
+    
+    if (simpleLineLayout())
+        return true; // We have simple line layout lines, so we can't be self-collapsing.
+    
+    for (auto* child = firstRootBox(); child; child = child->nextRootBox()) {
+        if (!child->hasAnonymousInlineBlock() || !child->anonymousInlineBlock()->isSelfCollapsingBlock())
+            return true;
+    }
+    return false; // We have no line boxes, so we must be self-collapsing.
+}
+
 LayoutUnit RenderBlockFlow::collapseMargins(RenderBox& child, MarginInfo& marginInfo)
 {
     bool childDiscardMarginBefore = mustDiscardMarginBeforeForChild(child);
index 9edcf72..a6794f0 100644 (file)
@@ -255,6 +255,8 @@ public:
     void handleAfterSideOfBlock(LayoutUnit top, LayoutUnit bottom, MarginInfo&);
     void setCollapsedBottomMargin(const MarginInfo&);
 
+    virtual bool childrenPreventSelfCollapsing() const override final;
+
     bool shouldBreakAtLineToAvoidWidow() const { return hasRareBlockFlowData() && rareBlockFlowData()->m_lineBreakToAvoidWidow >= 0; }
     void clearShouldBreakAtLineToAvoidWidow() const;
     int lineBreakToAvoidWidow() const { return hasRareBlockFlowData() ? rareBlockFlowData()->m_lineBreakToAvoidWidow : -1; }