[css-grid] Support positioned grid children
authorrego@igalia.com <rego@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Nov 2015 09:30:30 +0000 (09:30 +0000)
committerrego@igalia.com <rego@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Nov 2015 09:30:30 +0000 (09:30 +0000)
commit6f5869f0a83080720f5fa576f5240b0f93175497
tree8f3ec89235d7c1bdad090eb13414e3885ea79273
parent452ce9ba29f9bd15cc8e7e43be93ab91b93b65b1
[css-grid] Support positioned grid children
https://bugs.webkit.org/show_bug.cgi?id=150837

Reviewed by Darin Adler.

Source/WebCore:

According to the spec positioned grid children have
a special behavior described at:
https://drafts.csswg.org/css-grid/#abspos

The idea is that for positioned children the containing block will
correspond to the padding edges of the grid container, unless the
grid placement properties are defined.
This not only affects to positioned grid items (direct children) but
also to any descendant where the containing block is the grid container.

In order to manage this special behavior, the patch is overriding
RenderBlock::layoutPositionedObject() to calculate the position and size
depending on the grid-placement properties.

RenderBox class has some changes to calculate the containing block width
and height for positioned objects (using the override value). And also
to compute their static position.

Finally, the positioned items are not taken into account in all the
different grid methods, in order that they do not interfere the layout
of the grid as stated in the spec.

Tests: fast/css-grid-layout/absolute-positioning-grid-container-containing-block.html
       fast/css-grid-layout/absolute-positioning-grid-container-parent.html
       fast/css-grid-layout/grid-positioned-items-background.html
       fast/css-grid-layout/grid-positioned-items-implicit-grid-line.html
       fast/css-grid-layout/grid-positioned-items-implicit-grid.html
       fast/css-grid-layout/grid-positioned-items-unknown-named-grid-line.html
       fast/css-grid-layout/grid-sizing-positioned-items.html
       fast/css-grid-layout/positioned-grid-items-should-not-create-implicit-tracks.html
       fast/css-grid-layout/positioned-grid-items-should-not-take-up-space.html

* rendering/OrderIterator.cpp:
(WebCore::OrderIterator::next): Fix method to avoid issues if no items
are added to the iterator.
* rendering/RenderBlock.h: Mark layoutPositionedObject() as virtual.
* rendering/RenderBox.cpp: Add new maps for inline/block extra offsets.
(WebCore::RenderBox::~RenderBox): Clear the new maps.
(WebCore::RenderBox::extraInlineOffset): Extra offset that we need to
apply to positioned grid children due to the grid placement properties.
(WebCore::RenderBox::extraBlockOffset): Ditto.
(WebCore::RenderBox::setExtraInlineOffset):
(WebCore::RenderBox::setExtraBlockOffset):
(WebCore::RenderBox::clearExtraInlineAndBlockOffests):
(WebCore::RenderBox::containingBlockLogicalWidthForPositioned): Use the
override containing block if any.
(WebCore::RenderBox::containingBlockLogicalHeightForPositioned): Ditto.
(WebCore::RenderBox::computePositionedLogicalWidth): Add the extra
offset if it's a positioned element.
(WebCore::RenderBox::computePositionedLogicalHeight): Ditto.
* rendering/RenderBox.h:
(WebCore::RenderBox::scrollbarLogicalWidth): Add utility method.
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::layoutBlock): Clear grid after layout positioned
objects instead of at the end of layoutGridItems().
(WebCore::RenderGrid::placeItemsOnGrid): Ignore positioned items.
(WebCore::RenderGrid::populateExplicitGridAndOrderIterator): Ditto.
(WebCore::RenderGrid::layoutGridItems): Ditto.
(WebCore::RenderGrid::prepareChildForPositionedLayout): Set static
position for positioned items.
(WebCore::RenderGrid::layoutPositionedObject): Calculate position and
size for positioned children.
(WebCore::RenderGrid::offsetAndBreadthForPositionedChild): Calculate
extra offset and breadth for positioned children.
* rendering/RenderGrid.h:
* rendering/style/GridResolvedPosition.cpp:
(WebCore::GridResolvedPosition::isNonExistentNamedLineOrArea): Make it a
public static method.
(WebCore::GridUnresolvedSpan::adjustGridPositionsFromStyle): Fix calls
to isNonExistentNamedLineOrArea().
(WebCore::resolveGridPositionFromStyle): Ditto.
* rendering/style/GridResolvedPosition.h: Make
isNonExistentNamedLineOrArea() public.

LayoutTests:

* fast/css-grid-layout/absolute-positioning-grid-container-containing-block-expected.txt: Added.
* fast/css-grid-layout/absolute-positioning-grid-container-containing-block.html: Added.
* fast/css-grid-layout/absolute-positioning-grid-container-parent-expected.txt: Added.
* fast/css-grid-layout/absolute-positioning-grid-container-parent.html: Added.
* fast/css-grid-layout/grid-positioned-items-background-expected.html: Added.
* fast/css-grid-layout/grid-positioned-items-background.html: Added.
* fast/css-grid-layout/grid-positioned-items-implicit-grid-expected.txt: Added.
* fast/css-grid-layout/grid-positioned-items-implicit-grid-line-expected.txt: Added.
* fast/css-grid-layout/grid-positioned-items-implicit-grid-line.html: Added.
* fast/css-grid-layout/grid-positioned-items-implicit-grid.html: Added.
* fast/css-grid-layout/grid-positioned-items-unknown-named-grid-line-expected.txt: Added.
* fast/css-grid-layout/grid-positioned-items-unknown-named-grid-line.html: Added.
* fast/css-grid-layout/grid-sizing-positioned-items-expected.txt: Added.
* fast/css-grid-layout/grid-sizing-positioned-items.html: Added.
* fast/css-grid-layout/positioned-grid-items-should-not-create-implicit-tracks-expected.txt: Added.
* fast/css-grid-layout/positioned-grid-items-should-not-create-implicit-tracks.html: Added.
* fast/css-grid-layout/positioned-grid-items-should-not-take-up-space-expected.txt: Added.
* fast/css-grid-layout/positioned-grid-items-should-not-take-up-space.html: Added.
* fast/css-grid-layout/resources/grid.css: Added some common CSS classes.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192054 268f45cc-cd09-0410-ab3c-d52691b4dbfc
29 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css-grid-layout/absolute-positioning-grid-container-containing-block-expected.txt [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/absolute-positioning-grid-container-containing-block.html [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/absolute-positioning-grid-container-parent-expected.txt [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/absolute-positioning-grid-container-parent.html [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-positioned-items-background-expected.html [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-positioned-items-background.html [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-positioned-items-implicit-grid-expected.txt [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-positioned-items-implicit-grid-line-expected.txt [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-positioned-items-implicit-grid-line.html [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-positioned-items-implicit-grid.html [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-positioned-items-unknown-named-grid-line-expected.txt [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-positioned-items-unknown-named-grid-line.html [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-sizing-positioned-items-expected.txt [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-sizing-positioned-items.html [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/positioned-grid-items-should-not-create-implicit-tracks-expected.txt [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/positioned-grid-items-should-not-create-implicit-tracks.html [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/positioned-grid-items-should-not-take-up-space-expected.txt [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/positioned-grid-items-should-not-take-up-space.html [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/resources/grid.css
Source/WebCore/ChangeLog
Source/WebCore/rendering/OrderIterator.cpp
Source/WebCore/rendering/RenderBlock.h
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/RenderBox.h
Source/WebCore/rendering/RenderGrid.cpp
Source/WebCore/rendering/RenderGrid.h
Source/WebCore/rendering/style/GridResolvedPosition.cpp
Source/WebCore/rendering/style/GridResolvedPosition.h