Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1529)

Unified Diff: Source/core/rendering/style/GridResolvedPosition.cpp

Issue 148293008: [CSS Grid Layout] Add support to place items using named grid lines (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Implementation following specs Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/rendering/style/GridResolvedPosition.cpp
diff --git a/Source/core/rendering/style/GridResolvedPosition.cpp b/Source/core/rendering/style/GridResolvedPosition.cpp
index 7249b15e739b0e8d7dac18dabeae7a6dd85219bb..ca9356bfa49e7338a8d5e6f43dc0b085e050646f 100644
--- a/Source/core/rendering/style/GridResolvedPosition.cpp
+++ b/Source/core/rendering/style/GridResolvedPosition.cpp
@@ -80,11 +80,16 @@ size_t GridResolvedPosition::explicitGridSizeForSide(const RenderStyle& gridCont
return (side == ColumnStartSide || side == ColumnEndSide) ? explicitGridColumnCount(gridContainerStyle) : explicitGridRowCount(gridContainerStyle);
}
+static const NamedGridLinesMap& gridLinesForSide(const RenderStyle& style, GridPositionSide side)
+{
+ return (side == ColumnStartSide || side == ColumnEndSide) ? style.namedGridColumnLines() : style.namedGridRowLines();
+}
+
GridResolvedPosition GridResolvedPosition::resolveNamedGridLinePositionFromStyle(const RenderStyle& gridContainerStyle, const GridPosition& position, GridPositionSide side)
{
ASSERT(!position.namedGridLine().isNull());
- const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side == ColumnEndSide) ? gridContainerStyle.namedGridColumnLines() : gridContainerStyle.namedGridRowLines();
+ const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyle, side);
NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGridLine());
if (it == gridLinesNames.end()) {
if (position.isPositive())
@@ -125,21 +130,21 @@ GridResolvedPosition GridResolvedPosition::resolveGridPositionFromStyle(const Re
}
case NamedGridAreaPosition:
{
- NamedGridAreaMap::const_iterator it = gridContainerStyle.namedGridArea().find(position.namedGridLine());
- // Unknown grid area should have been computed to 'auto' by now.
- ASSERT_WITH_SECURITY_IMPLICATION(it != gridContainerStyle.namedGridArea().end());
- const GridCoordinate& gridAreaCoordinate = it->value;
- switch (side) {
- case ColumnStartSide:
- return gridAreaCoordinate.columns.resolvedInitialPosition;
- case ColumnEndSide:
- return gridAreaCoordinate.columns.resolvedFinalPosition;
- case RowStartSide:
- return gridAreaCoordinate.rows.resolvedInitialPosition;
- case RowEndSide:
- return GridResolvedPosition(gridAreaCoordinate.rows.resolvedFinalPosition);
- }
- ASSERT_NOT_REACHED();
+ // Four implicit named grid lines are created for each grid area (areaName-{start|end} for rows and
+ // columns). Authors can either use the area names or the implicit grid line names.
+ String namedGridLine = position.namedGridLine();
+ String implicitNamedGridLine = namedGridLine + ((side == ColumnStartSide || side == RowStartSide) ? "-start" : "-end");
+ const NamedGridLinesMap& gridLineNames = gridLinesForSide(gridContainerStyle, side);
+ NamedGridLinesMap::const_iterator implicitLineIter = gridLineNames.find(implicitNamedGridLine);
+ if (implicitLineIter != gridLineNames.end())
+ return adjustGridPositionForSide(implicitLineIter->value[0], side);
+
+ NamedGridLinesMap::const_iterator explicitLineIter = gridLineNames.find(namedGridLine);
Julien - ping for review 2014/05/12 11:42:12 Nit: I would put the specification's wording with
+ if (explicitLineIter != gridLineNames.end())
+ return adjustGridPositionForSide(explicitLineIter->value[0], side);
+
+ // FIXME: if none of the above works specs mandate us to treat it as auto. We cannot return auto right here
+ // right now because callers expect a resolved position. We need deeper changes to support this use case.
return GridResolvedPosition(0);
}
case AutoPosition:
@@ -175,7 +180,7 @@ PassOwnPtr<GridSpan> GridResolvedPosition::resolveNamedGridLinePositionAgainstOp
// Negative positions are not allowed per the specification and should have been handled during parsing.
ASSERT(position.spanPosition() > 0);
- const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side == ColumnEndSide) ? gridContainerStyle.namedGridColumnLines() : gridContainerStyle.namedGridRowLines();
+ const NamedGridLinesMap& gridLinesNames = gridLinesForSide(gridContainerStyle, side);
NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGridLine());
// If there is no named grid line of that name, we resolve the position to 'auto' (which is equivalent to 'span 1' in this case).

Powered by Google App Engine
This is Rietveld 408576698