[CSS Grid layout] Initial position in span not correctly computed sometimes
authorsvillar@igalia.com <svillar@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Mar 2014 10:18:24 +0000 (10:18 +0000)
committersvillar@igalia.com <svillar@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Mar 2014 10:18:24 +0000 (10:18 +0000)
commit8f2f52a83c5e875b37d881d9864ae4e055c4d073
treeba4d809ca94f748f3fcdbfd6f902f6d4fac2fe68
parent4aafccc8f1ed8f6434abefba712c65e40f5b917b
[CSS Grid layout] Initial position in span not correctly computed sometimes
https://bugs.webkit.org/show_bug.cgi?id=130124

Reviewed by Darin Adler.

Source/WebCore:

The code uses std::lower_bound() to get the first grid line
position before a given resolved position in a Vector. That
function returns an iterator pointing to the first value not
"strictly less" than the given one. Consequently, the returned
position might be actually located after the resolved final
position. In those cases we need to select the previous position
in the Vector (which is guaranted to be "< resolved position" due
to how std::lower_bound() works).

For example, if we have vector=[2,5,8] as grid positions, and we
need the first position before 7, std::lower_bound(vector, 7) will
point to 8 (first value not < 7). It's obvious that we should
select 5 instead. Should the pointed value be equal, then we
should do nothing, because the indexes mean tracks, so the item
will be placed in just one cell of the grid.

* rendering/RenderGrid.cpp:
(WebCore::firstNamedGridLineBeforePosition):
(WebCore::RenderGrid::resolveRowStartColumnStartNamedGridLinePositionAgainstOppositePosition):

LayoutTests:

Added the grid positioning example mentioned in the specs which
covers this bug and some other cases.

* fast/css-grid-layout/grid-item-named-grid-line-resolution-expected.txt:
* fast/css-grid-layout/grid-item-named-grid-line-resolution.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@165612 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/css-grid-layout/grid-item-named-grid-line-resolution-expected.txt
LayoutTests/fast/css-grid-layout/grid-item-named-grid-line-resolution.html
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderGrid.cpp