Chromium Code Reviews| Index: Source/core/css/CSSParser-in.cpp |
| diff --git a/Source/core/css/CSSParser-in.cpp b/Source/core/css/CSSParser-in.cpp |
| index 16298cbeb552b60120b812dc4e07a0f0e0731a7c..4d217c343557007533da9711e0a4f407c47735da 100644 |
| --- a/Source/core/css/CSSParser-in.cpp |
| +++ b/Source/core/css/CSSParser-in.cpp |
| @@ -38,6 +38,7 @@ |
| #include "core/css/CSSCursorImageValue.h" |
| #include "core/css/CSSFontFaceSrcValue.h" |
| #include "core/css/CSSGradientValue.h" |
| +#include "core/css/CSSGridTemplateValue.h" |
| #include "core/css/CSSImageSetValue.h" |
| #include "core/css/CSSImageValue.h" |
| #include "core/css/CSSInheritedValue.h" |
| @@ -2457,6 +2458,12 @@ bool CSSParser::parseValue(CSSPropertyID propId, bool important) |
| return false; |
| return parseGridItemPositionShorthand(propId, important); |
| + case CSSPropertyGridTemplate: |
| + if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) |
| + return false; |
| + parsedValue = parseGridTemplate(); |
| + break; |
| + |
| case CSSPropertyWebkitMarginCollapse: { |
| if (num == 1) { |
| ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse); |
| @@ -4727,6 +4734,80 @@ PassRefPtr<CSSPrimitiveValue> CSSParser::parseGridBreadth(CSSParserValue* curren |
| return createPrimitiveNumericValue(currentValue); |
| } |
| +PassRefPtr<CSSValue> CSSParser::parseGridTemplate() |
| +{ |
| + NamedGridAreaMap gridAreaMap; |
| + size_t rowCount = 0; |
| + size_t columnCount = 0; |
| + |
| + while (CSSParserValue* currentValue = m_valueList->current()) { |
| + if (currentValue->unit != CSSPrimitiveValue::CSS_STRING) |
| + return 0; |
| + |
| + String gridRowNames = currentValue->string; |
| + if (!gridRowNames.length()) |
| + return 0; |
| + |
| + Vector<String> columnNames; |
| + gridRowNames.split(' ', columnNames); |
|
ojan
2013/07/29 23:03:28
Does the spec say what to do if there are multiple
Julien - ping for review
2013/07/30 18:43:33
Not explicitly (the grammar is <string>+). It woul
ojan
2013/07/30 18:53:48
Makes sense to me. We should make the spec explici
|
| + |
| + if (!columnCount) { |
| + columnCount = columnNames.size(); |
| + ASSERT(columnCount); |
| + } else if (columnCount != columnNames.size()) { |
| + // The declaration is invalid is all the rows don't have the number of columns. |
| + return 0; |
| + } |
| + |
| + for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) { |
| + const String& gridAreaName = columnNames[currentCol]; |
| + |
| + // Unamed areas are always valid (we consider them to be 1x1). |
| + DEFINE_STATIC_LOCAL(String, unamedAreaPlaceholder, (ASCIILiteral("."))); |
| + if (gridAreaName == unamedAreaPlaceholder) |
|
esprehn
2013/07/29 23:27:36
This is overly complex, just check if gridAreaName
Julien - ping for review
2013/07/30 18:43:33
I thought it would be more readable but apparently
|
| + continue; |
| + |
| + // We handle several grid areas with the same name at once to simplify the validation code. |
| + size_t lookAheadCol; |
| + for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++lookAheadCol) { |
| + if (columnNames[lookAheadCol + 1] != gridAreaName) |
| + break; |
| + } |
| + |
| + NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName); |
| + if (gridAreaIt == gridAreaMap.end()) { |
| + gridAreaMap.add(gridAreaName, GridCoordinate(GridSpan(rowCount, rowCount), GridSpan(currentCol, lookAheadCol))); |
| + } else { |
| + GridCoordinate& gridCoordinate = gridAreaIt->value; |
| + |
| + // The following checks test that the grid area is a single filled-in rectangle. |
| + // 1. The new row is adjacent to the previously parsed row. |
| + if (rowCount != gridCoordinate.rows.initialPositionIndex + 1) |
| + return 0; |
| + |
| + // 2. The new area starts at the same position as the previously parsed area. |
| + if (currentCol != gridCoordinate.columns.initialPositionIndex) |
| + return 0; |
| + |
| + // 3. The new area ends at the same position as the previously parsed area. |
| + if (lookAheadCol != gridCoordinate.columns.finalPositionIndex) |
| + return 0; |
| + |
| + ++gridCoordinate.rows.finalPositionIndex; |
| + } |
| + currentCol = lookAheadCol; |
| + } |
| + |
| + ++rowCount; |
| + m_valueList->next(); |
| + } |
| + |
| + if (!rowCount || !columnCount) |
| + return 0; |
| + |
| + return CSSGridTemplateValue::create(gridAreaMap, rowCount, columnCount); |
| +} |
| + |
| PassRefPtr<CSSValue> CSSParser::parseCounterContent(CSSParserValueList* args, bool counters) |
| { |
| unsigned numArgs = args->size(); |