[New Block-Inside-Inline Model] Floats need to be allowed to intrude into anonymous...
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Apr 2015 18:10:32 +0000 (18:10 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Apr 2015 18:10:32 +0000 (18:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143307

Reviewed by Dean Jackson.

Source/WebCore:

Added fast/block/inside-inlines/basic-float-intrusion.html

* rendering/InlineFlowBox.cpp:
(WebCore::InlineFlowBox::placeBoxesInBlockDirection):
Make sure to exclude the margins of an anonymous inline-block when considering the height of the line.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::lineHeight):
(WebCore::RenderBlock::baselinePosition):
Anonymous inline-block lines ignore line-height and just return the height of the block. For baseline position, the baseline
is considered to be at the bottom border edge of the anonymous inline-block.

* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::rebuildFloatingObjectSetFromIntrudingFloats):
(WebCore::RenderBlockFlow::addIntrudingFloats):
* rendering/RenderBlockFlow.h:
Patch float intrusion to handle the case of anonymous inline-blocks. Instead of collecting the floats from our parent(), we
collect them from the containingBlock() in the anonymous inline-block case. Patch addIntrudingFloats to pass in the container
that acts as the "parent", since it is not the parent() in the anonymous inline-block case.

* rendering/RenderBlockLineLayout.cpp:
(WebCore::updateLogicalInlinePositions):
Make sure to use the full available width for content always in the anonymous inline-block case, since we don't avoid the
floats, but instead let them intrude into the inline-block.

(WebCore::RenderBlockFlow::computeInlineDirectionPositionsForLine):
Patch callers of updateLogicalInlinePositions to pass in the root line box that we're checking for.

(WebCore::RenderBlockFlow::layoutLineBoxes):
Defer the layout of anonymous inline-blocks, since they need to only lay out once the vertical position to lay them out
at is known.

* rendering/RenderBox.cpp:
(WebCore::RenderBox::createsNewFormattingContext):
(WebCore::RenderBox::avoidsFloats):
Anonymous inline-blocks do not establish a new block formatting context, nor do they avoid floats.

* rendering/line/BreakingContext.h:
(WebCore::BreakingContext::handleReplaced):
Add code to do a just-in-time layout of the anonymous inline-block at the time it is being examined (after the break before
it was handled).

LayoutTests:

* fast/block/inside-inlines/basic-float-intrusion-expected.html: Added.
* fast/block/inside-inlines/basic-float-intrusion.html: Added.
* fast/block/inside-inlines/new-model/basic-float-intrusion-expected.html: Added.
* fast/block/inside-inlines/new-model/basic-float-intrusion.html: Added.

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/block/inside-inlines/basic-float-intrusion-expected.html [new file with mode: 0644]
LayoutTests/fast/block/inside-inlines/basic-float-intrusion.html [new file with mode: 0644]
LayoutTests/fast/block/inside-inlines/new-model/basic-float-intrusion-expected.html [new file with mode: 0644]
LayoutTests/fast/block/inside-inlines/new-model/basic-float-intrusion.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/InlineFlowBox.cpp
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderBlockFlow.cpp
Source/WebCore/rendering/RenderBlockFlow.h
Source/WebCore/rendering/RenderBlockLineLayout.cpp
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/line/BreakingContext.h

index ccd4280..716b569 100644 (file)
@@ -1,3 +1,15 @@
+2015-04-01  David Hyatt  <hyatt@apple.com>
+
+        [New Block-Inside-Inline Model] Floats need to be allowed to intrude into anonymous inline-blocks.
+        https://bugs.webkit.org/show_bug.cgi?id=143307
+
+        Reviewed by Dean Jackson.
+
+        * fast/block/inside-inlines/basic-float-intrusion-expected.html: Added.
+        * fast/block/inside-inlines/basic-float-intrusion.html: Added.
+        * fast/block/inside-inlines/new-model/basic-float-intrusion-expected.html: Added.
+        * fast/block/inside-inlines/new-model/basic-float-intrusion.html: Added.
+
 2015-04-01  Hunseop Jeong  <hs85.jeong@samsung.com>
 
         Unreviewed EFL gardening. Remove warning message in layoutTest. 
diff --git a/LayoutTests/fast/block/inside-inlines/basic-float-intrusion-expected.html b/LayoutTests/fast/block/inside-inlines/basic-float-intrusion-expected.html
new file mode 100644 (file)
index 0000000..f61465a
--- /dev/null
@@ -0,0 +1,14 @@
+<!doctype html>
+<head>
+<style>
+.box { border:1px solid black; padding:3px; margin:3px }
+.nowrap { white-space: nowrap; }
+.float { float: left; }
+.box div { height:40px;  }
+.float { width:100px; height:100px; background-color:cyan }
+</style>
+<body>
+
+<div class="float"></div>
+
+<div class="box"><div>Avoid the float!</div></div>
diff --git a/LayoutTests/fast/block/inside-inlines/basic-float-intrusion.html b/LayoutTests/fast/block/inside-inlines/basic-float-intrusion.html
new file mode 100644 (file)
index 0000000..b78eace
--- /dev/null
@@ -0,0 +1,14 @@
+<!doctype html>
+<head>
+<style>
+.box { border:1px solid black; padding:3px; margin:3px }
+.nowrap { white-space: nowrap; }
+.float { float: left; }
+.box div { height:40px;  }
+.float { width:100px; height:100px; background-color:cyan }
+</style>
+<body>
+
+<div class="float"></div>
+
+<div class="box"><a><div>Avoid the float!</div></a></div>
diff --git a/LayoutTests/fast/block/inside-inlines/new-model/basic-float-intrusion-expected.html b/LayoutTests/fast/block/inside-inlines/new-model/basic-float-intrusion-expected.html
new file mode 100644 (file)
index 0000000..f61465a
--- /dev/null
@@ -0,0 +1,14 @@
+<!doctype html>
+<head>
+<style>
+.box { border:1px solid black; padding:3px; margin:3px }
+.nowrap { white-space: nowrap; }
+.float { float: left; }
+.box div { height:40px;  }
+.float { width:100px; height:100px; background-color:cyan }
+</style>
+<body>
+
+<div class="float"></div>
+
+<div class="box"><div>Avoid the float!</div></div>
diff --git a/LayoutTests/fast/block/inside-inlines/new-model/basic-float-intrusion.html b/LayoutTests/fast/block/inside-inlines/new-model/basic-float-intrusion.html
new file mode 100644 (file)
index 0000000..3b556d0
--- /dev/null
@@ -0,0 +1,18 @@
+<!doctype html>
+<head>
+<style>
+.box { border:1px solid black; padding:3px; margin:3px }
+.nowrap { white-space: nowrap; }
+.float { float: left; }
+.box div { height:40px;  }
+.float { width:100px; height:100px; background-color:cyan }
+</style>
+<script>
+if (window.internals)
+    window.internals.settings.setNewBlockInsideInlineModelEnabled(true)
+</script>
+<body>
+
+<div class="float"></div>
+
+<div class="box"><a><div>Avoid the float!</div></a></div>
index f518c1d..4aff0d2 100644 (file)
@@ -1,3 +1,52 @@
+2015-04-01  David Hyatt  <hyatt@apple.com>
+
+        [New Block-Inside-Inline Model] Floats need to be allowed to intrude into anonymous inline-blocks.
+        https://bugs.webkit.org/show_bug.cgi?id=143307
+
+        Reviewed by Dean Jackson.
+
+        Added fast/block/inside-inlines/basic-float-intrusion.html
+
+        * rendering/InlineFlowBox.cpp:
+        (WebCore::InlineFlowBox::placeBoxesInBlockDirection):
+        Make sure to exclude the margins of an anonymous inline-block when considering the height of the line.
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::lineHeight):
+        (WebCore::RenderBlock::baselinePosition):
+        Anonymous inline-block lines ignore line-height and just return the height of the block. For baseline position, the baseline
+        is considered to be at the bottom border edge of the anonymous inline-block.
+
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::rebuildFloatingObjectSetFromIntrudingFloats):
+        (WebCore::RenderBlockFlow::addIntrudingFloats):
+        * rendering/RenderBlockFlow.h:
+        Patch float intrusion to handle the case of anonymous inline-blocks. Instead of collecting the floats from our parent(), we
+        collect them from the containingBlock() in the anonymous inline-block case. Patch addIntrudingFloats to pass in the container
+        that acts as the "parent", since it is not the parent() in the anonymous inline-block case.
+
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::updateLogicalInlinePositions):
+        Make sure to use the full available width for content always in the anonymous inline-block case, since we don't avoid the
+        floats, but instead let them intrude into the inline-block.
+
+        (WebCore::RenderBlockFlow::computeInlineDirectionPositionsForLine):
+        Patch callers of updateLogicalInlinePositions to pass in the root line box that we're checking for.
+
+        (WebCore::RenderBlockFlow::layoutLineBoxes):
+        Defer the layout of anonymous inline-blocks, since they need to only lay out once the vertical position to lay them out
+        at is known.
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::createsNewFormattingContext):
+        (WebCore::RenderBox::avoidsFloats):
+        Anonymous inline-blocks do not establish a new block formatting context, nor do they avoid floats.
+
+        * rendering/line/BreakingContext.h:
+        (WebCore::BreakingContext::handleReplaced):
+        Add code to do a just-in-time layout of the anonymous inline-block at the time it is being examined (after the break before
+        it was handled).
+
 2015-04-01  Eric Carlson  <eric.carlson@apple.com>
 
         [Mac] Do not include route button if element does not support target playback
index eaf17d4..2a1d6c8 100644 (file)
@@ -671,7 +671,7 @@ void InlineFlowBox::placeBoxesInBlockDirection(LayoutUnit top, LayoutUnit maxHei
                     : boxObject.borderRight() + boxObject.paddingRight();
             }
             newLogicalTopIncludingMargins = newLogicalTop;
-        } else if (!child->renderer().isBR()) {
+        } else if (!child->renderer().isBR() && !child->renderer().isAnonymousInlineBlock()) {
             const auto& box = downcast<RenderBox>(child->renderer());
             newLogicalTopIncludingMargins = newLogicalTop;
             LayoutUnit overSideMargin = child->isHorizontal() ? box.marginTop() : box.marginRight();
index 4567f92..f5ba9d4 100644 (file)
@@ -2802,6 +2802,10 @@ bool RenderBlock::hasLineIfEmpty() const
 
 LayoutUnit RenderBlock::lineHeight(bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const
 {
+    // Anonymous inline blocks don't include margins or any real line height.
+    if (isAnonymousInlineBlock() && linePositionMode == PositionOnContainingLine)
+        return direction == HorizontalLine ? height() : width();
+    
     // Inline blocks are replaced elements. Otherwise, just pass off to
     // the base class.  If we're being queried as though we're the root line
     // box, then the fact that we're an inline-block is irrelevant, and we behave
@@ -2825,6 +2829,9 @@ int RenderBlock::baselinePosition(FontBaseline baselineType, bool firstLine, Lin
     // box, then the fact that we're an inline-block is irrelevant, and we behave
     // just like a block.
     if (isReplaced() && linePositionMode == PositionOnContainingLine) {
+        if (isAnonymousInlineBlock())
+            return direction == HorizontalLine ? height() : width();
+        
         // For "leaf" theme objects, let the theme decide what the baseline position is.
         // FIXME: Might be better to have a custom CSS property instead, so that if the theme
         // is turned off, checkboxes/radios will still have decent baselines.
index c3035b7..e36e49d 100644 (file)
@@ -232,17 +232,20 @@ void RenderBlockFlow::rebuildFloatingObjectSetFromIntrudingFloats()
     // We should not process floats if the parent node is not a RenderBlock. Otherwise, we will add 
     // floats in an invalid context. This will cause a crash arising from a bad cast on the parent.
     // See <rdar://problem/8049753>, where float property is applied on a text node in a SVG.
-    if (!is<RenderBlockFlow>(parent()))
+    bool isBlockInsideInline = isAnonymousInlineBlock();
+    if (!is<RenderBlockFlow>(parent()) && !isBlockInsideInline)
         return;
 
     // First add in floats from the parent. Self-collapsing blocks let their parent track any floats that intrude into
     // them (as opposed to floats they contain themselves) so check for those here too.
-    RenderBlockFlow& parentBlock = downcast<RenderBlockFlow>(*parent());
-    bool parentHasFloats = false;
-    RenderBlockFlow* previousBlock = previousSiblingWithOverhangingFloats(parentHasFloats);
+    RenderBlockFlow& parentBlock = downcast<RenderBlockFlow>(isBlockInsideInline ? *containingBlock() : *parent());
+    bool parentHasFloats = isBlockInsideInline ? parentBlock.containsFloats() : false;
+    RenderBlockFlow* previousBlock = nullptr;
+    if (!isBlockInsideInline)
+        previousBlock = previousSiblingWithOverhangingFloats(parentHasFloats);
     LayoutUnit logicalTopOffset = logicalTop();
     if (parentHasFloats || (parentBlock.lowestFloatLogicalBottom() > logicalTopOffset && previousBlock && previousBlock->isSelfCollapsingBlock()))
-        addIntrudingFloats(&parentBlock, parentBlock.logicalLeftOffsetForContent(), logicalTopOffset);
+        addIntrudingFloats(&parentBlock, &parentBlock, parentBlock.logicalLeftOffsetForContent(), logicalTopOffset);
     
     LayoutUnit logicalLeftOffset = 0;
     if (previousBlock)
@@ -254,7 +257,7 @@ void RenderBlockFlow::rebuildFloatingObjectSetFromIntrudingFloats()
 
     // Add overhanging floats from the previous RenderBlock, but only if it has a float that intrudes into our space.    
     if (previousBlock->m_floatingObjects && previousBlock->lowestFloatLogicalBottom() > logicalTopOffset)
-        addIntrudingFloats(previousBlock, logicalLeftOffset, logicalTopOffset);
+        addIntrudingFloats(previousBlock, &parentBlock, logicalLeftOffset, logicalTopOffset);
 
     if (childrenInline()) {
         LayoutUnit changeLogicalTop = LayoutUnit::max();
@@ -2681,7 +2684,7 @@ bool RenderBlockFlow::hasOverhangingFloat(RenderBox& renderer)
     return logicalBottomForFloat(it->get()) > logicalHeight();
 }
 
-void RenderBlockFlow::addIntrudingFloats(RenderBlockFlow* prev, LayoutUnit logicalLeftOffset, LayoutUnit logicalTopOffset)
+void RenderBlockFlow::addIntrudingFloats(RenderBlockFlow* prev, RenderBlockFlow* container, LayoutUnit logicalLeftOffset, LayoutUnit logicalTopOffset)
 {
     ASSERT(!avoidsFloats());
 
@@ -2711,8 +2714,8 @@ void RenderBlockFlow::addIntrudingFloats(RenderBlockFlow* prev, LayoutUnit logic
                 // into account. Only apply this code if prev is the parent, since otherwise the left margin
                 // will get applied twice.
                 LayoutSize offset = isHorizontalWritingMode()
-                    ? LayoutSize(logicalLeftOffset - (prev != parent() ? prev->marginLeft() : LayoutUnit()), logicalTopOffset)
-                    : LayoutSize(logicalTopOffset, logicalLeftOffset - (prev != parent() ? prev->marginTop() : LayoutUnit()));
+                    ? LayoutSize(logicalLeftOffset - (prev != container ? prev->marginLeft() : LayoutUnit()), logicalTopOffset)
+                    : LayoutSize(logicalTopOffset, logicalLeftOffset - (prev != container ? prev->marginTop() : LayoutUnit()));
 
                 m_floatingObjects->add(floatingObject->copyToNewContainer(offset));
             }
index 330fd37..79c8c5f 100644 (file)
@@ -508,7 +508,7 @@ private:
     
     LayoutUnit addOverhangingFloats(RenderBlockFlow& child, bool makeChildPaintOtherFloats);
     bool hasOverhangingFloat(RenderBox&);
-    void addIntrudingFloats(RenderBlockFlow* prev, LayoutUnit xoffset, LayoutUnit yoffset);
+    void addIntrudingFloats(RenderBlockFlow* prev, RenderBlockFlow* container, LayoutUnit xoffset, LayoutUnit yoffset);
     bool hasOverhangingFloats() { return parent() && containsFloats() && lowestFloatLogicalBottom() > logicalHeight(); }
     LayoutUnit getClearDelta(RenderBox& child, LayoutUnit yPos);
 
index 63eb326..5e28c37 100644 (file)
@@ -685,11 +685,17 @@ void RenderBlockFlow::updateLogicalWidthForAlignment(const ETextAlign& textAlign
     }
 }
 
-static void updateLogicalInlinePositions(RenderBlockFlow& block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine, IndentTextOrNot shouldIndentText, LayoutUnit boxLogicalHeight)
+static void updateLogicalInlinePositions(RenderBlockFlow& block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine, IndentTextOrNot shouldIndentText, LayoutUnit boxLogicalHeight,
+    RootInlineBox* rootBox)
 {
     LayoutUnit lineLogicalHeight = block.minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight);
-    lineLogicalLeft = block.logicalLeftOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
-    lineLogicalRight = block.logicalRightOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
+    if (rootBox->hasAnonymousInlineBlock()) {
+        lineLogicalLeft = block.logicalLeftOffsetForContent(block.logicalHeight());
+        lineLogicalRight = block.logicalRightOffsetForContent(block.logicalHeight());
+    } else {
+        lineLogicalLeft = block.logicalLeftOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
+        lineLogicalRight = block.logicalRightOffsetForLine(block.logicalHeight(), shouldIndentText == IndentText, lineLogicalHeight);
+    }
     availableLogicalWidth = lineLogicalRight - lineLogicalLeft;
 }
 
@@ -707,12 +713,12 @@ void RenderBlockFlow::computeInlineDirectionPositionsForLine(RootInlineBox* line
     float lineLogicalLeft;
     float lineLogicalRight;
     float availableLogicalWidth;
-    updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0);
+    updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0, lineBox);
     bool needsWordSpacing;
 
     if (firstRun && firstRun->renderer().isReplaced()) {
         RenderBox& renderBox = downcast<RenderBox>(firstRun->renderer());
-        updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight());
+        updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight(), lineBox);
     }
 
     computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
@@ -1567,10 +1573,12 @@ void RenderBlockFlow::layoutLineBoxes(bool relayoutChildren, LayoutUnit& repaint
                 else if (isFullLayout || box.needsLayout()) {
                     // Replaced element.
                     box.dirtyLineBoxes(isFullLayout);
-                    if (isFullLayout)
-                        replacedChildren.append(&box);
-                    else
-                        box.layoutIfNeeded();
+                    if (!o.isAnonymousInlineBlock()) {
+                        if (isFullLayout)
+                            replacedChildren.append(&box);
+                        else
+                            box.layoutIfNeeded();
+                    }
                 }
             } else if (o.isTextOrLineBreak() || (is<RenderInline>(o) && !walker.atEndOfInline())) {
                 if (is<RenderInline>(o))
index d43c804..e52fa75 100644 (file)
@@ -4302,7 +4302,7 @@ bool RenderBox::shrinkToAvoidFloats() const
 
 bool RenderBox::createsNewFormattingContext() const
 {
-    return isInlineBlockOrInlineTable() || isFloatingOrOutOfFlowPositioned() || hasOverflowClip() || isFlexItemIncludingDeprecated()
+    return (isInlineBlockOrInlineTable() && !isAnonymousInlineBlock()) || isFloatingOrOutOfFlowPositioned() || hasOverflowClip() || isFlexItemIncludingDeprecated()
         || isTableCell() || isTableCaption() || isFieldset() || isWritingModeRoot() || isRoot() || isRenderFlowThread() || isRenderRegion()
 #if ENABLE(CSS_GRID_LAYOUT)
         || isGridItem()
@@ -4312,7 +4312,7 @@ bool RenderBox::createsNewFormattingContext() const
 
 bool RenderBox::avoidsFloats() const
 {
-    return isReplaced() || isHR() || isLegend() || createsNewFormattingContext();
+    return (isReplaced() && !isAnonymousInlineBlock()) || isHR() || isLegend() || createsNewFormattingContext();
 }
 
 void RenderBox::addVisualEffectOverflow()
index ff1955e..1eb716a 100644 (file)
@@ -500,6 +500,9 @@ inline void BreakingContext::handleReplaced()
             return;
         }
     }
+    
+    if (replacedBox.isAnonymousInlineBlock())
+        replacedBox.layoutIfNeeded();
 
     if (m_ignoringSpaces)
         m_lineMidpointState.stopIgnoringSpaces(InlineIterator(0, m_current.renderer(), 0));