Index: third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp |
diff --git a/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp b/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp |
index e077752172eaa48f21ab9809f3cee220c8e90e5b..85b3efa535cc2189c6c05c543b1f31e7b00bc85e 100644 |
--- a/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp |
+++ b/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp |
@@ -206,12 +206,6 @@ RawPtr<CSSPrimitiveValue> CSSPropertyParser::createPrimitiveNumericValue(CSSPars |
return cssValuePool().createValue(value->fValue, value->unit()); |
} |
-inline RawPtr<CSSCustomIdentValue> CSSPropertyParser::createPrimitiveCustomIdentValue(CSSParserValue* value) |
-{ |
- ASSERT(value->m_unit == CSSParserValue::String || value->m_unit == CSSParserValue::Identifier); |
- return CSSCustomIdentValue::create(value->string); |
-} |
- |
static inline bool isComma(CSSParserValue* value) |
{ |
ASSERT(value); |
@@ -281,10 +275,6 @@ RawPtr<CSSValue> CSSPropertyParser::legacyParseValue(CSSPropertyID unresolvedPro |
bool CSSPropertyParser::legacyParseShorthand(CSSPropertyID propertyID, bool important) |
{ |
switch (propertyID) { |
- case CSSPropertyGridTemplate: |
- ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
- return parseGridTemplateShorthand(important); |
- |
case CSSPropertyGrid: |
ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
return parseGridShorthand(important); |
@@ -295,146 +285,13 @@ bool CSSPropertyParser::legacyParseShorthand(CSSPropertyID propertyID, bool impo |
} |
} |
-static inline bool isCSSWideKeyword(const CSSParserValue& value) |
-{ |
- return value.id == CSSValueInitial || value.id == CSSValueInherit || value.id == CSSValueUnset || value.id == CSSValueDefault; |
-} |
- |
-static inline bool isValidCustomIdentForGridPositions(const CSSParserValue& value) |
-{ |
- // FIXME: we need a more general solution for <custom-ident> in all properties. |
- return value.m_unit == CSSParserValue::Identifier && value.id != CSSValueSpan && value.id != CSSValueAuto && !isCSSWideKeyword(value); |
-} |
- |
-RawPtr<CSSValue> CSSPropertyParser::parseGridTemplateColumns(bool important) |
-{ |
- if (!(m_valueList->current() && isForwardSlashOperator(m_valueList->current()) && m_valueList->next())) |
- return nullptr; |
- if (RawPtr<CSSValue> columnsValue = parseGridTrackList()) { |
- if (m_valueList->current()) |
- return nullptr; |
- return columnsValue; |
- } |
- |
- return nullptr; |
-} |
- |
-bool CSSPropertyParser::parseGridTemplateRowsAndAreasAndColumns(bool important) |
-{ |
- NamedGridAreaMap gridAreaMap; |
- size_t rowCount = 0; |
- size_t columnCount = 0; |
- bool trailingIdentWasAdded = false; |
- RawPtr<CSSValueList> templateRows = CSSValueList::createSpaceSeparated(); |
- |
- // At least template-areas strings must be defined. |
- if (!m_valueList->current() || isForwardSlashOperator(m_valueList->current())) |
- return false; |
- |
- while (m_valueList->current() && !isForwardSlashOperator(m_valueList->current())) { |
- // Handle leading <custom-ident>*. |
- if (!parseGridLineNames(*m_valueList, *templateRows, trailingIdentWasAdded ? toCSSGridLineNamesValue(templateRows->item(templateRows->length() - 1)) : nullptr)) |
- return false; |
- |
- // Handle a template-area's row. |
- CSSParserValue* currentValue = m_valueList->current(); |
- if (!currentValue || currentValue->m_unit != CSSParserValue::String) |
- return false; |
- if (!parseGridTemplateAreasRow(currentValue->string, gridAreaMap, rowCount, columnCount)) |
- return false; |
- m_valueList->next(); |
- ++rowCount; |
- |
- // Handle template-rows's track-size. |
- if (m_valueList->current() && m_valueList->current()->m_unit != CSSParserValue::Operator && m_valueList->current()->m_unit != CSSParserValue::String) { |
- RawPtr<CSSValue> value = parseGridTrackSize(*m_valueList); |
- if (!value) |
- return false; |
- templateRows->append(value); |
- } else { |
- templateRows->append(cssValuePool().createIdentifierValue(CSSValueAuto)); |
- } |
- |
- // This will handle the trailing/leading <custom-ident>* in the grammar. |
- if (!parseGridLineNames(*m_valueList, *templateRows)) |
- return false; |
- trailingIdentWasAdded = templateRows->item(templateRows->length() - 1)->isGridLineNamesValue(); |
- } |
- |
- RawPtr<CSSValue> columnsValue = nullptr; |
- if (m_valueList->current()) { |
- ASSERT(isForwardSlashOperator(m_valueList->current())); |
- columnsValue = parseGridTemplateColumns(important); |
- if (!columnsValue) |
- return false; |
- // The template-columns <track-list> can't be 'none'. |
- if (columnsValue->isPrimitiveValue() && toCSSPrimitiveValue(*columnsValue).getValueID() == CSSValueNone) |
- return false; |
- } |
- |
- addProperty(CSSPropertyGridTemplateRows, templateRows.release(), important); |
- addProperty(CSSPropertyGridTemplateColumns, columnsValue ? columnsValue.release() : cssValuePool().createIdentifierValue(CSSValueNone), important); |
- |
- RawPtr<CSSValue> templateAreas = CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount); |
- addProperty(CSSPropertyGridTemplateAreas, templateAreas.release(), important); |
- |
- return true; |
-} |
- |
- |
-bool CSSPropertyParser::parseGridTemplateShorthand(bool important) |
-{ |
- ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
- |
- ShorthandScope scope(this, CSSPropertyGridTemplate); |
- ASSERT(gridTemplateShorthand().length() == 3); |
- |
- // At least "none" must be defined. |
- if (!m_valueList->current()) |
- return false; |
- |
- bool firstValueIsNone = m_valueList->current()->id == CSSValueNone; |
- |
- // 1- 'none' case. |
- if (firstValueIsNone && !m_valueList->next()) { |
- addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdentifierValue(CSSValueNone), important); |
- addProperty(CSSPropertyGridTemplateRows, cssValuePool().createIdentifierValue(CSSValueNone), important); |
- addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdentifierValue(CSSValueNone), important); |
- return true; |
- } |
- |
- // 2- <grid-template-rows> / <grid-template-columns> |
- RawPtr<CSSValue> rowsValue = nullptr; |
- if (firstValueIsNone) { |
- rowsValue = cssValuePool().createIdentifierValue(CSSValueNone); |
- } else { |
- rowsValue = parseGridTrackList(); |
- } |
- |
- if (rowsValue) { |
- RawPtr<CSSValue> columnsValue = parseGridTemplateColumns(important); |
- if (!columnsValue) |
- return false; |
- |
- addProperty(CSSPropertyGridTemplateRows, rowsValue.release(), important); |
- addProperty(CSSPropertyGridTemplateColumns, columnsValue.release(), important); |
- addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdentifierValue(CSSValueNone), important); |
- return true; |
- } |
- |
- // 3- [<line-names>? <string> <track-size>? <line-names>? ]+ syntax. |
- // It requires to rewind parsing due to previous syntax failures. |
- m_valueList->setCurrentIndex(0); |
- return parseGridTemplateRowsAndAreasAndColumns(important); |
-} |
- |
bool CSSPropertyParser::parseGridShorthand(bool important) |
{ |
ShorthandScope scope(this, CSSPropertyGrid); |
ASSERT(shorthandForProperty(CSSPropertyGrid).length() == 8); |
// 1- <grid-template> |
- if (parseGridTemplateShorthand(important)) { |
+ if (consumeGridTemplateShorthand(important)) { |
// It can only be specified the explicit or the implicit grid properties in a single grid declaration. |
// The sub-properties not specified are set to their initial value, as normal for shorthands. |
addProperty(CSSPropertyGridAutoFlow, cssValuePool().createImplicitInitialValue(), important); |
@@ -445,9 +302,6 @@ bool CSSPropertyParser::parseGridShorthand(bool important) |
return true; |
} |
- // Need to rewind parsing to explore the alternative syntax of this shorthand. |
- m_valueList->setCurrentIndex(0); |
- |
// 2- <grid-auto-flow> [ <grid-auto-rows> [ / <grid-auto-columns> ]? ] |
if (!legacyParseAndApplyValue(CSSPropertyGridAutoFlow, important)) |
return false; |
@@ -492,184 +346,6 @@ bool CSSPropertyParser::parseGridShorthand(bool important) |
return true; |
} |
-static inline bool isClosingBracket(const CSSParserValue& value) |
-{ |
- return value.m_unit == CSSParserValue::Operator && value.iValue == ']'; |
-} |
- |
-bool CSSPropertyParser::parseGridLineNames(CSSParserValueList& inputList, CSSValueList& valueList, CSSGridLineNamesValue* previousNamedAreaTrailingLineNames) |
-{ |
- if (!inputList.current() || inputList.current()->m_unit != CSSParserValue::Operator || inputList.current()->iValue != '[') |
- return true; |
- |
- // Skip '[' |
- inputList.next(); |
- |
- RawPtr<CSSGridLineNamesValue> lineNames = previousNamedAreaTrailingLineNames; |
- if (!lineNames) |
- lineNames = CSSGridLineNamesValue::create(); |
- |
- while (CSSParserValue* identValue = inputList.current()) { |
- if (isClosingBracket(*identValue)) |
- break; |
- |
- if (!isValidCustomIdentForGridPositions(*identValue)) |
- return false; |
- |
- RawPtr<CSSCustomIdentValue> lineName = createPrimitiveCustomIdentValue(identValue); |
- lineNames->append(lineName.release()); |
- inputList.next(); |
- } |
- |
- if (!inputList.current() || !isClosingBracket(*inputList.current())) |
- return false; |
- |
- if (!previousNamedAreaTrailingLineNames) |
- valueList.append(lineNames.release()); |
- |
- // Consume ']' |
- inputList.next(); |
- return true; |
-} |
- |
-bool allTracksAreFixedSized(CSSValueList& valueList) |
-{ |
- for (auto value : valueList) { |
- if (value->isGridLineNamesValue()) |
- continue; |
- // The auto-repeat value holds a <fixed-size> = <fixed-breadth> | minmax( <fixed-breadth>, <track-breadth> ) |
- if (value->isGridAutoRepeatValue()) { |
- if (!allTracksAreFixedSized(toCSSValueList(*value))) |
- return false; |
- continue; |
- } |
- ASSERT(value->isPrimitiveValue() || (value->isFunctionValue() && toCSSFunctionValue(*value).item(0))); |
- const CSSPrimitiveValue& primitiveValue = value->isPrimitiveValue() |
- ? toCSSPrimitiveValue(*value) |
- : toCSSPrimitiveValue(*toCSSFunctionValue(*value).item(0)); |
- CSSValueID valueID = primitiveValue.getValueID(); |
- if (valueID == CSSValueMinContent || valueID == CSSValueMaxContent || valueID == CSSValueAuto || primitiveValue.isFlex()) |
- return false; |
- } |
- return true; |
-} |
- |
-RawPtr<CSSValue> CSSPropertyParser::parseGridTrackList() |
-{ |
- ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
- |
- CSSParserValue* value = m_valueList->current(); |
- if (value->id == CSSValueNone) { |
- m_valueList->next(); |
- return cssValuePool().createIdentifierValue(CSSValueNone); |
- } |
- |
- RawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated(); |
- // Handle leading <custom-ident>*. |
- if (!parseGridLineNames(*m_valueList, *values)) |
- return nullptr; |
- |
- bool seenTrackSizeOrRepeatFunction = false; |
- bool seenAutoRepeat = false; |
- while (CSSParserValue* currentValue = m_valueList->current()) { |
- if (isForwardSlashOperator(currentValue)) |
- break; |
- if (currentValue->m_unit == CSSParserValue::Function && currentValue->function->id == CSSValueRepeat) { |
- bool isAutoRepeat; |
- if (!parseGridTrackRepeatFunction(*values, isAutoRepeat)) |
- return nullptr; |
- if (isAutoRepeat && seenAutoRepeat) |
- return nullptr; |
- seenTrackSizeOrRepeatFunction = true; |
- seenAutoRepeat = seenAutoRepeat || isAutoRepeat; |
- } else { |
- RawPtr<CSSValue> value = parseGridTrackSize(*m_valueList, seenAutoRepeat ? FixedSizeOnly : AllowAll); |
- if (!value) |
- return nullptr; |
- values->append(value); |
- seenTrackSizeOrRepeatFunction = true; |
- } |
- // This will handle the trailing <custom-ident>* in the grammar. |
- if (!parseGridLineNames(*m_valueList, *values)) |
- return nullptr; |
- } |
- |
- // We should have found a <track-size> or else it is not a valid <track-list> |
- if (!seenTrackSizeOrRepeatFunction) |
- return nullptr; |
- |
- // <auto-repeat> requires definite minimum track sizes in order to compute the number of repetitions. |
- // The above while loop detects those appearances after the <auto-repeat> but not the ones before. |
- if (seenAutoRepeat && !allTracksAreFixedSized(*values)) |
- return nullptr; |
- |
- return values; |
-} |
- |
-bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list, bool& isAutoRepeat) |
-{ |
- CSSParserValueList* arguments = m_valueList->current()->function->args.get(); |
- if (!arguments || arguments->size() < 3 || !isComma(arguments->valueAt(1))) |
- return false; |
- |
- CSSParserValue* currentValue = arguments->valueAt(0); |
- isAutoRepeat = currentValue->id == CSSValueAutoFill || currentValue->id == CSSValueAutoFit; |
- if (!isAutoRepeat && !validUnit(currentValue, FPositiveInteger)) |
- return false; |
- |
- // The number of repetitions for <auto-repeat> is not important at parsing level |
- // because it will be computed later, let's set it to 1. |
- size_t repetitions = isAutoRepeat ? 1 : clampTo<size_t>(currentValue->fValue, 0, kGridMaxTracks); |
- |
- RawPtr<CSSValueList> repeatedValues = isAutoRepeat ? CSSGridAutoRepeatValue::create(currentValue->id) : CSSValueList::createSpaceSeparated(); |
- arguments->next(); // Skip the repetition count. |
- arguments->next(); // Skip the comma. |
- |
- // Handle leading <custom-ident>*. |
- if (!parseGridLineNames(*arguments, *repeatedValues)) |
- return false; |
- |
- size_t numberOfTracks = 0; |
- TrackSizeRestriction restriction = isAutoRepeat ? FixedSizeOnly : AllowAll; |
- while (arguments->current()) { |
- if (isAutoRepeat && numberOfTracks) |
- return false; |
- |
- RawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments, restriction); |
- if (!trackSize) |
- return false; |
- |
- repeatedValues->append(trackSize); |
- ++numberOfTracks; |
- |
- // This takes care of any trailing <custom-ident>* in the grammar. |
- if (!parseGridLineNames(*arguments, *repeatedValues)) |
- return false; |
- } |
- |
- // We should have found at least one <track-size> or else it is not a valid <track-list>. |
- if (!numberOfTracks) |
- return false; |
- |
- if (isAutoRepeat) { |
- list.append(repeatedValues.release()); |
- } else { |
- // We clamp the number of repetitions to a multiple of the repeat() track list's size, while staying below the max |
- // grid size. |
- repetitions = std::min(repetitions, kGridMaxTracks / numberOfTracks); |
- |
- for (size_t i = 0; i < repetitions; ++i) { |
- for (size_t j = 0; j < repeatedValues->length(); ++j) |
- list.append(repeatedValues->item(j)); |
- } |
- } |
- |
- // parseGridTrackSize iterated over the repeat arguments, move to the next value. |
- m_valueList->next(); |
- return true; |
-} |
- |
- |
RawPtr<CSSValue> CSSPropertyParser::parseGridTrackSize(CSSParserValueList& inputList, TrackSizeRestriction restriction) |
{ |
ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); |
@@ -727,100 +403,6 @@ RawPtr<CSSPrimitiveValue> CSSPropertyParser::parseGridBreadth(CSSParserValue* cu |
return createPrimitiveNumericValue(currentValue); |
} |
-static Vector<String> parseGridTemplateAreasColumnNames(const String& gridRowNames) |
-{ |
- ASSERT(!gridRowNames.isEmpty()); |
- Vector<String> columnNames; |
- // Using StringImpl to avoid checks and indirection in every call to String::operator[]. |
- StringImpl& text = *gridRowNames.impl(); |
- |
- StringBuilder areaName; |
- for (unsigned i = 0; i < text.length(); ++i) { |
- if (text[i] == ' ') { |
- if (!areaName.isEmpty()) { |
- columnNames.append(areaName.toString()); |
- areaName.clear(); |
- } |
- continue; |
- } |
- if (text[i] == '.') { |
- if (areaName == ".") |
- continue; |
- if (!areaName.isEmpty()) { |
- columnNames.append(areaName.toString()); |
- areaName.clear(); |
- } |
- } else { |
- if (areaName == ".") { |
- columnNames.append(areaName.toString()); |
- areaName.clear(); |
- } |
- } |
- |
- areaName.append(text[i]); |
- } |
- |
- if (!areaName.isEmpty()) |
- columnNames.append(areaName.toString()); |
- |
- return columnNames; |
-} |
- |
-bool parseGridTemplateAreasRow(const String& gridRowNames, NamedGridAreaMap& gridAreaMap, const size_t rowCount, size_t& columnCount) |
-{ |
- if (gridRowNames.isEmpty() || gridRowNames.containsOnlyWhitespace()) |
- return false; |
- |
- Vector<String> columnNames = parseGridTemplateAreasColumnNames(gridRowNames); |
- 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 false; |
- } |
- |
- for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) { |
- const String& gridAreaName = columnNames[currentCol]; |
- |
- // Unamed areas are always valid (we consider them to be 1x1). |
- if (gridAreaName == ".") |
- continue; |
- |
- // We handle several grid areas with the same name at once to simplify the validation code. |
- size_t lookAheadCol; |
- for (lookAheadCol = currentCol + 1; lookAheadCol < columnCount; ++lookAheadCol) { |
- if (columnNames[lookAheadCol] != gridAreaName) |
- break; |
- } |
- |
- NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName); |
- if (gridAreaIt == gridAreaMap.end()) { |
- gridAreaMap.add(gridAreaName, GridArea(GridSpan::translatedDefiniteGridSpan(rowCount, rowCount + 1), GridSpan::translatedDefiniteGridSpan(currentCol, lookAheadCol))); |
- } else { |
- GridArea& gridArea = 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 != gridArea.rows.endLine()) |
- return false; |
- |
- // 2. The new area starts at the same position as the previously parsed area. |
- if (currentCol != gridArea.columns.startLine()) |
- return false; |
- |
- // 3. The new area ends at the same position as the previously parsed area. |
- if (lookAheadCol != gridArea.columns.endLine()) |
- return false; |
- |
- gridArea.rows = GridSpan::translatedDefiniteGridSpan(gridArea.rows.startLine(), gridArea.rows.endLine() + 1); |
- } |
- currentCol = lookAheadCol - 1; |
- } |
- |
- return true; |
-} |
- |
RawPtr<CSSValue> CSSPropertyParser::parseGridAutoFlow(CSSParserValueList& list) |
{ |
// [ row | column ] || dense |