[New Block-Inside-Inline Model] Implement margin collapsing across contiguous anonymous inline blocks.
https://bugs.webkit.org/show_bug.cgi?id=149132

Reviewed by Zalan Bujtas.

Source/WebCore:

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

* rendering/InlineFlowBox.cpp:
(WebCore::InlineFlowBox::anonymousInlineBlock):
Change this accessor to be more robust and be willing to both recur (in case we ever do decide intermediate line boxes should exist)
and to type check. This is not currently needed, but I'm just being paranoid and future proof.

(WebCore::InlineFlowBox::addToLine):
Again, for thoroughness, I am making sure to propagate the hasAnonymousInlineBlock() bit through to parents. This is only needed
if we build intermediate line boxes for lines with anonymous inline blocks.

(WebCore::InlineFlowBox::placeBoxesInBlockDirection):
Anonymous inline blocks receive a layout via layoutBlockChild, in order to make sure that margin collapsing runs. This means
that unlike other line objects, the position of the child has been determined already. Therefore we simply set the position
of the line box that wraps the anonymous inline block to the already-computed position for that block.

Also patch the code that sets lineTop and lineBottom using the root box's dimensions. We don't really care about the root line
box on anonymous inline block lines and just want to set lineTop and lineBottom to fit the anonymous inline block.

* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::collapseMargins):
(WebCore::RenderBlockFlow::collapseMarginsWithChildInfo):
Refactor collapseMargins to call a helper function that can pass in a previous "sibling", and that can handle the child
being null. We do this to perform a margin collapse when anonymous inline blocks run up against regular lines (which is like
collapsing with a sibling block "child").

* rendering/RenderBlockFlow.h:
Tweak the MarginInfo constructor to take a const RenderBlockFlow. Tweak some line layout methods to pass in the LineLayoutState
so that MarginInfo is available during line layout.

* rendering/RenderBlockLineLayout.cpp:
(WebCore::RenderBlockFlow::createLineBoxes):
When we create a new line box, if it is not an anonymous inline block line and our previous line was, simulate a margin
collapse in order to possibly push the line box down or up. Re-use the pagination adjustment code to rewind line layout
and perform it again if pushed below a float.

(WebCore::constructBidiRunsForSegment):
(WebCore::RenderBlockFlow::layoutRunsAndFloats):
(WebCore::RenderBlockFlow::layoutRunsAndFloatsInRange):
(WebCore::RenderBlockFlow::layoutLineBoxes):
(WebCore::RenderBlockFlow::determineStartPosition):
(WebCore::RenderBlockFlow::matchedEndLine):
(WebCore::RenderBlockFlow::updateRegionForLine):
(WebCore::RenderBlockFlow::marginCollapseLinesFromStart):
Patch line layout to run margin collapsing when anonymous inline blocks are encountered. This involves making sure
margin info and float bottom positions are passed through so that layoutBlockChild can be properly called on
anonymous inline blocks that we encounter.

In addition line layout when it syncs dirty lines has to run margin collapsing on earlier lines in order to make
sure margin info is properly set up at the first dirty line position.

Note that there will be more improvements/changes in this area (dirty line syncing), as the current model is inefficient
when many anonymous inline blocks are scattered throughout a large-scale line box tree.

* rendering/RootInlineBox.cpp:
(WebCore::RootInlineBox::alignBoxesInBlockDirection):
(WebCore::RootInlineBox::ascentAndDescentForBox):
Make sure to rely on the block layout code for the placement of the boxes themselves. Set up the line box code to not have
an effect on ascent/descent.

* rendering/line/BreakingContext.h:
(WebCore::BreakingContext::BreakingContext):
(WebCore::BreakingContext::handleReplaced):
When we encounter an anonymous inline block, lay it out when it is seen. We have to delay the layout, since we have
to be able to perform it mid-line-layout when the containing block's logical height is at the correct value and all previous
lines are placed. Margin info also has to be current.

* rendering/line/LineBreaker.cpp:
* rendering/line/LineBreaker.h:
Patched to pass LineLayoutState through so that the stuff we need to perform block layout is available (margin info and float vars).

* rendering/line/LineLayoutState.h:
Add the block layout margin and float bottom information to the line layout state so that we have it available when performing
layouts and margin collapses on anonymous inline block children.

LayoutTests:

* fast/block/inside-inlines/new-model/margin-collapse: Added.
* fast/block/inside-inlines/new-model/margin-collapse/001-expected.html: Added.
* fast/block/inside-inlines/new-model/margin-collapse/001.html: Added.
* fast/block/inside-inlines/new-model/margin-collapse/002-expected.html: Added.
* fast/block/inside-inlines/new-model/margin-collapse/002.html: Added.
* fast/block/inside-inlines/new-model/margin-collapse/003-expected.html: Added.
* fast/block/inside-inlines/new-model/margin-collapse/003.html: Added.
* fast/block/inside-inlines/new-model/margin-collapse/004-expected.html: Added.
* fast/block/inside-inlines/new-model/margin-collapse/004.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@189817 268f45cc-cd09-0410-ab3c-d52691b4dbfc
23 files changed