[css-grid] Clamp the number of autorepeat tracks
authorsvillar@igalia.com <svillar@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Mar 2017 14:40:46 +0000 (14:40 +0000)
committersvillar@igalia.com <svillar@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Mar 2017 14:40:46 +0000 (14:40 +0000)
commita3dcd846c0855d9d421142cce7efb445dd695b46
tree350bb3d46d061fb4ef9b32a52e309942c6022c04
parent85a2a272af7f6079d8ec4ed59351381a8b7a1704
[css-grid] Clamp the number of autorepeat tracks
https://bugs.webkit.org/show_bug.cgi?id=170120

Reviewed by Manuel Rego Casasnovas.

Source/WebCore:

As suggested by the specs we do clamp the maximum number of tracks per grid in order to
minimize potential OOM situations. However we were not considering the case of the recently
added auto repeat syntax. Abnormally huge values for the width/height on the grid container
could lead to a number of auto repeat tracks higher than the maximum.

A new API was added to Internals in order to test limits without having to create huge
grids. This new API allows clients to set an arbitrary limit to the number of tracks. The
addition of this new API forced us to add GridPosition.cpp to the project to define the
global variable we use for testing. We took the chance to move part of the implementation
from the header file to the source file.

Last but not least, several new ASSERTs were added to Grid.cpp implementation to ensure that
we do not surpass the grid track limits.

Test: fast/css-grid-layout/grid-auto-repeat-huge-grid.html

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* css/parser/CSSPropertyParser.cpp:
(WebCore::consumeGridTrackRepeatFunction):
* rendering/Grid.cpp:
(WebCore::Grid::ensureGridSize): Added ASSERT.
(WebCore::Grid::setSmallestTracksStart): Ditto.
(WebCore::Grid::setAutoRepeatTracks): Ditto.
(WebCore::Grid::setAutoRepeatEmptyColumns): Ditto.
(WebCore::Grid::setAutoRepeatEmptyRows): Ditto.
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::clampAutoRepeatTracks): New method.
(WebCore::RenderGrid::placeItemsOnGrid): Clamp the number of auto repeat tracks before
passing them to the Grid.
* rendering/RenderGrid.h:
* rendering/style/GridArea.h:
(WebCore::GridSpan::GridSpan):
* rendering/style/GridPosition.cpp: Added.
(WebCore::GridPosition::setExplicitPosition):
(WebCore::GridPosition::setAutoPosition):
(WebCore::GridPosition::setSpanPosition):
(WebCore::GridPosition::setNamedGridArea):
(WebCore::GridPosition::integerPosition):
(WebCore::GridPosition::namedGridLine):
(WebCore::GridPosition::spanPosition):
(WebCore::GridPosition::operator==):
* rendering/style/GridPosition.h:
(WebCore::GridPosition::shouldBeResolvedAgainstOppositePosition):
(WebCore::GridPosition::max):
(WebCore::GridPosition::min):
(WebCore::GridPosition::setMaxPositionForTesting):
(WebCore::GridPosition::setExplicitPosition): Deleted.
(WebCore::GridPosition::setAutoPosition): Deleted.
(WebCore::GridPosition::setSpanPosition): Deleted.
(WebCore::GridPosition::setNamedGridArea): Deleted.
(WebCore::GridPosition::integerPosition): Deleted.
(WebCore::GridPosition::namedGridLine): Deleted.
(WebCore::GridPosition::spanPosition): Deleted.
(WebCore::GridPosition::operator==): Deleted.
* rendering/style/GridPositionsResolver.cpp:
(WebCore::GridPositionsResolver::explicitGridColumnCount):
(WebCore::GridPositionsResolver::explicitGridRowCount):
* testing/Internals.cpp:
(WebCore::Internals::setGridMaxTracksLimit):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

Added a new test to check the clamping of grid tracks. It's mostly all JavaScript in order
to allow us to run several test cases over a small number of grids in a single file quite
fast. The other option was to statically (CSS) create several huge grids, something that
could potentially be very expensive in terms of memory and CPU leading to timeouts.

* fast/css-grid-layout/grid-auto-repeat-huge-grid-expected.txt: Added.
* fast/css-grid-layout/grid-auto-repeat-huge-grid.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@214604 268f45cc-cd09-0410-ab3c-d52691b4dbfc
17 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css-grid-layout/grid-auto-repeat-huge-grid-expected.txt [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-auto-repeat-huge-grid.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/parser/CSSPropertyParser.cpp
Source/WebCore/rendering/Grid.cpp
Source/WebCore/rendering/RenderGrid.cpp
Source/WebCore/rendering/RenderGrid.h
Source/WebCore/rendering/style/GridArea.h
Source/WebCore/rendering/style/GridPosition.cpp [new file with mode: 0644]
Source/WebCore/rendering/style/GridPosition.h
Source/WebCore/rendering/style/GridPositionsResolver.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl