Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/css/parser/CSSPropertyParser.h" | 5 #include "core/css/parser/CSSPropertyParser.h" |
| 6 | 6 |
| 7 #include "core/StylePropertyShorthand.h" | 7 #include "core/StylePropertyShorthand.h" |
| 8 #include "core/css/CSSBasicShapeValues.h" | 8 #include "core/css/CSSBasicShapeValues.h" |
| 9 #include "core/css/CSSBorderImage.h" | 9 #include "core/css/CSSBorderImage.h" |
| 10 #include "core/css/CSSContentDistributionValue.h" | 10 #include "core/css/CSSContentDistributionValue.h" |
| (...skipping 3097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3108 return consumeIdent(range); | 3108 return consumeIdent(range); |
| 3109 if (token.type() == DimensionToken && token.unitType() == CSSPrimitiveVa lue::UnitType::Fraction) { | 3109 if (token.type() == DimensionToken && token.unitType() == CSSPrimitiveVa lue::UnitType::Fraction) { |
| 3110 if (range.peek().numericValue() < 0) | 3110 if (range.peek().numericValue() < 0) |
| 3111 return nullptr; | 3111 return nullptr; |
| 3112 return cssValuePool().createValue(range.consumeIncludingWhitespace() .numericValue(), CSSPrimitiveValue::UnitType::Fraction); | 3112 return cssValuePool().createValue(range.consumeIncludingWhitespace() .numericValue(), CSSPrimitiveValue::UnitType::Fraction); |
| 3113 } | 3113 } |
| 3114 } | 3114 } |
| 3115 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, U nitlessQuirk::Allow); | 3115 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, U nitlessQuirk::Allow); |
| 3116 } | 3116 } |
| 3117 | 3117 |
| 3118 // TODO(rob.buis): consider adding boolean parameter to disallow <auto-track-lis t> if we keep supporing grid-template. | |
|
Timothy Loh
2016/04/11 03:27:32
In any case, this is going to be used by the grid
| |
| 3118 static CSSValue* consumeGridTrackSize(CSSParserTokenRange& range, CSSParserMode cssParserMode, TrackSizeRestriction restriction = AllowAll) | 3119 static CSSValue* consumeGridTrackSize(CSSParserTokenRange& range, CSSParserMode cssParserMode, TrackSizeRestriction restriction = AllowAll) |
| 3119 { | 3120 { |
| 3120 const CSSParserToken& token = range.peek(); | 3121 const CSSParserToken& token = range.peek(); |
| 3121 if (restriction == AllowAll && identMatches<CSSValueAuto>(token.id())) | 3122 if (restriction == AllowAll && identMatches<CSSValueAuto>(token.id())) |
| 3122 return consumeIdent(range); | 3123 return consumeIdent(range); |
| 3123 | 3124 |
| 3124 if (token.functionId() == CSSValueMinmax) { | 3125 if (token.functionId() == CSSValueMinmax) { |
| 3125 CSSParserTokenRange rangeCopy = range; | 3126 CSSParserTokenRange rangeCopy = range; |
| 3126 CSSParserTokenRange args = consumeFunction(rangeCopy); | 3127 CSSParserTokenRange args = consumeFunction(rangeCopy); |
| 3127 CSSPrimitiveValue* minTrackBreadth = consumeGridBreadth(args, cssParserM ode, restriction); | 3128 CSSPrimitiveValue* minTrackBreadth = consumeGridBreadth(args, cssParserM ode, restriction); |
| 3128 if (!minTrackBreadth || !consumeCommaIncludingWhitespace(args)) | 3129 if (!minTrackBreadth || !consumeCommaIncludingWhitespace(args)) |
| 3129 return nullptr; | 3130 return nullptr; |
| 3130 CSSPrimitiveValue* maxTrackBreadth = consumeGridBreadth(args, cssParserM ode); | 3131 CSSPrimitiveValue* maxTrackBreadth = consumeGridBreadth(args, cssParserM ode); |
| 3131 if (!maxTrackBreadth || !args.atEnd()) | 3132 if (!maxTrackBreadth || !args.atEnd()) |
| 3132 return nullptr; | 3133 return nullptr; |
| 3133 range = rangeCopy; | 3134 range = rangeCopy; |
| 3134 CSSFunctionValue* result = CSSFunctionValue::create(CSSValueMinmax); | 3135 CSSFunctionValue* result = CSSFunctionValue::create(CSSValueMinmax); |
| 3135 result->append(minTrackBreadth); | 3136 result->append(minTrackBreadth); |
| 3136 result->append(maxTrackBreadth); | 3137 result->append(maxTrackBreadth); |
| 3137 return result; | 3138 return result; |
| 3138 } | 3139 } |
| 3139 return consumeGridBreadth(range, cssParserMode, restriction); | 3140 return consumeGridBreadth(range, cssParserMode, restriction); |
| 3140 } | 3141 } |
| 3141 | 3142 |
| 3142 static CSSGridLineNamesValue* consumeGridLineNames(CSSParserTokenRange& range) | 3143 // Appends to the passed in CSSGridLineNamesValue if any, otherwise creates a ne w one. |
| 3144 static CSSGridLineNamesValue* consumeGridLineNames(CSSParserTokenRange& range, C SSGridLineNamesValue* lineNames = nullptr) | |
| 3143 { | 3145 { |
| 3144 CSSParserTokenRange rangeCopy = range; | 3146 CSSParserTokenRange rangeCopy = range; |
| 3145 if (rangeCopy.consumeIncludingWhitespace().type() != LeftBracketToken) | 3147 if (rangeCopy.consumeIncludingWhitespace().type() != LeftBracketToken) |
| 3146 return nullptr; | 3148 return nullptr; |
| 3147 CSSGridLineNamesValue* lineNames = CSSGridLineNamesValue::create(); | 3149 if (!lineNames) |
| 3150 lineNames = CSSGridLineNamesValue::create(); | |
| 3148 while (CSSCustomIdentValue* lineName = consumeCustomIdentForGridLine(rangeCo py)) | 3151 while (CSSCustomIdentValue* lineName = consumeCustomIdentForGridLine(rangeCo py)) |
| 3149 lineNames->append(lineName); | 3152 lineNames->append(lineName); |
| 3150 if (rangeCopy.consumeIncludingWhitespace().type() != RightBracketToken) | 3153 if (rangeCopy.consumeIncludingWhitespace().type() != RightBracketToken) |
| 3151 return nullptr; | 3154 return nullptr; |
| 3152 range = rangeCopy; | 3155 range = rangeCopy; |
| 3153 return lineNames; | 3156 return lineNames; |
| 3154 } | 3157 } |
| 3155 | 3158 |
| 3156 static bool consumeGridTrackRepeatFunction(CSSParserTokenRange& range, CSSParser Mode cssParserMode, CSSValueList& list, bool& isAutoRepeat) | 3159 static bool consumeGridTrackRepeatFunction(CSSParserTokenRange& range, CSSParser Mode cssParserMode, CSSValueList& list, bool& isAutoRepeat) |
| 3157 { | 3160 { |
| (...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4472 if (!columnEndValue) | 4475 if (!columnEndValue) |
| 4473 columnEndValue = columnStartValue->isCustomIdentValue() ? columnStartVal ue : cssValuePool().createIdentifierValue(CSSValueAuto); | 4476 columnEndValue = columnStartValue->isCustomIdentValue() ? columnStartVal ue : cssValuePool().createIdentifierValue(CSSValueAuto); |
| 4474 | 4477 |
| 4475 addProperty(CSSPropertyGridRowStart, rowStartValue, important); | 4478 addProperty(CSSPropertyGridRowStart, rowStartValue, important); |
| 4476 addProperty(CSSPropertyGridColumnStart, columnStartValue, important); | 4479 addProperty(CSSPropertyGridColumnStart, columnStartValue, important); |
| 4477 addProperty(CSSPropertyGridRowEnd, rowEndValue, important); | 4480 addProperty(CSSPropertyGridRowEnd, rowEndValue, important); |
| 4478 addProperty(CSSPropertyGridColumnEnd, columnEndValue, important); | 4481 addProperty(CSSPropertyGridColumnEnd, columnEndValue, important); |
| 4479 return true; | 4482 return true; |
| 4480 } | 4483 } |
| 4481 | 4484 |
| 4485 bool CSSPropertyParser::consumeGridTemplateRowsAndAreasAndColumns(bool important ) | |
| 4486 { | |
| 4487 NamedGridAreaMap gridAreaMap; | |
| 4488 size_t rowCount = 0; | |
| 4489 size_t columnCount = 0; | |
| 4490 RawPtr<CSSValueList> templateRows = CSSValueList::createSpaceSeparated(); | |
| 4491 | |
| 4492 // Persists between loop iterations so we can use the same value for | |
| 4493 // consecutive <line-names> values | |
| 4494 CSSGridLineNamesValue* lineNames = nullptr; | |
| 4495 | |
| 4496 do { | |
| 4497 // Handle leading <custom-ident>*. | |
| 4498 bool hasPreviousLineNames = lineNames; | |
| 4499 lineNames = consumeGridLineNames(m_range, lineNames); | |
| 4500 if (lineNames && !hasPreviousLineNames) | |
| 4501 templateRows->append(lineNames); | |
| 4502 | |
| 4503 // Handle a template-area's row. | |
| 4504 if (m_range.peek().type() != StringToken || !parseGridTemplateAreasRow(m _range.consumeIncludingWhitespace().value(), gridAreaMap, rowCount, columnCount) ) | |
| 4505 return false; | |
| 4506 ++rowCount; | |
| 4507 | |
| 4508 // Handle template-rows's track-size. | |
| 4509 RawPtr<CSSValue> value = consumeGridTrackSize(m_range, m_context.mode()) ; | |
| 4510 if (!value) | |
| 4511 value = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 4512 templateRows->append(value.release()); | |
| 4513 | |
| 4514 // This will handle the trailing/leading <custom-ident>* in the grammar. | |
| 4515 lineNames = consumeGridLineNames(m_range); | |
| 4516 if (lineNames) | |
| 4517 templateRows->append(lineNames); | |
| 4518 } while (!m_range.atEnd() && !(m_range.peek().type() == DelimiterToken && m_ range.peek().delimiter() == '/')); | |
| 4519 | |
| 4520 RawPtr<CSSValue> columnsValue = nullptr; | |
| 4521 if (!m_range.atEnd()) { | |
| 4522 if (!consumeSlashIncludingWhitespace(m_range)) | |
| 4523 return false; | |
| 4524 columnsValue = consumeGridTrackList(m_range, m_context.mode()); | |
| 4525 if (!columnsValue || !m_range.atEnd()) | |
| 4526 return false; | |
| 4527 } else { | |
| 4528 columnsValue = cssValuePool().createIdentifierValue(CSSValueNone); | |
| 4529 } | |
| 4530 addProperty(CSSPropertyGridTemplateRows, templateRows.release(), important); | |
| 4531 addProperty(CSSPropertyGridTemplateColumns, columnsValue.release(), importan t); | |
| 4532 addProperty(CSSPropertyGridTemplateAreas, CSSGridTemplateAreasValue::create( gridAreaMap, rowCount, columnCount), important); | |
| 4533 return true; | |
| 4534 } | |
| 4535 | |
| 4536 bool CSSPropertyParser::consumeGridTemplateShorthand(bool important) | |
| 4537 { | |
| 4538 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | |
| 4539 ASSERT(gridTemplateShorthand().length() == 3); | |
| 4540 | |
| 4541 CSSParserTokenRange rangeCopy = m_range; | |
| 4542 RawPtr<CSSValue> rowsValue = consumeIdent<CSSValueNone>(m_range); | |
| 4543 | |
| 4544 // 1- 'none' case. | |
| 4545 if (rowsValue && m_range.atEnd()) { | |
| 4546 addProperty(CSSPropertyGridTemplateRows, cssValuePool().createIdentifier Value(CSSValueNone), important); | |
| 4547 addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdentif ierValue(CSSValueNone), important); | |
| 4548 addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdentifie rValue(CSSValueNone), important); | |
| 4549 return true; | |
| 4550 } | |
| 4551 | |
| 4552 // 2- <grid-template-rows> / <grid-template-columns> | |
| 4553 if (!rowsValue) | |
| 4554 rowsValue = consumeGridTrackList(m_range, m_context.mode()); | |
| 4555 | |
| 4556 if (rowsValue) { | |
| 4557 if (!consumeSlashIncludingWhitespace(m_range)) | |
| 4558 return false; | |
| 4559 RawPtr<CSSValue> columnsValue = consumeGridTemplatesRowsOrColumns(m_rang e, m_context.mode()); | |
| 4560 if (!columnsValue || !m_range.atEnd()) | |
| 4561 return false; | |
| 4562 | |
| 4563 addProperty(CSSPropertyGridTemplateRows, rowsValue.release(), important) ; | |
| 4564 addProperty(CSSPropertyGridTemplateColumns, columnsValue.release(), impo rtant); | |
| 4565 addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdentifie rValue(CSSValueNone), important); | |
| 4566 return true; | |
| 4567 } | |
| 4568 | |
| 4569 // 3- [ <line-names>? <string> <track-size>? <line-names>? ]+ [ / <track-lis t> ]? | |
| 4570 m_range = rangeCopy; | |
| 4571 return consumeGridTemplateRowsAndAreasAndColumns(important); | |
| 4572 } | |
| 4573 | |
| 4482 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) | 4574 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) |
| 4483 { | 4575 { |
| 4484 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 4576 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
| 4485 | 4577 |
| 4486 CSSPropertyID oldShorthand = m_currentShorthand; | 4578 CSSPropertyID oldShorthand = m_currentShorthand; |
| 4487 // TODO(rob.buis): Remove this when the legacy property parser is gone | 4579 // TODO(rob.buis): Remove this when the legacy property parser is gone |
| 4488 m_currentShorthand = property; | 4580 m_currentShorthand = property; |
| 4489 switch (property) { | 4581 switch (property) { |
| 4490 case CSSPropertyWebkitMarginCollapse: { | 4582 case CSSPropertyWebkitMarginCollapse: { |
| 4491 CSSValueID id = m_range.consumeIncludingWhitespace().id(); | 4583 CSSValueID id = m_range.consumeIncludingWhitespace().id(); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4654 columnGap = rowGap; | 4746 columnGap = rowGap; |
| 4655 addProperty(CSSPropertyGridRowGap, rowGap, important); | 4747 addProperty(CSSPropertyGridRowGap, rowGap, important); |
| 4656 addProperty(CSSPropertyGridColumnGap, columnGap, important); | 4748 addProperty(CSSPropertyGridColumnGap, columnGap, important); |
| 4657 return true; | 4749 return true; |
| 4658 } | 4750 } |
| 4659 case CSSPropertyGridColumn: | 4751 case CSSPropertyGridColumn: |
| 4660 case CSSPropertyGridRow: | 4752 case CSSPropertyGridRow: |
| 4661 return consumeGridItemPositionShorthand(property, important); | 4753 return consumeGridItemPositionShorthand(property, important); |
| 4662 case CSSPropertyGridArea: | 4754 case CSSPropertyGridArea: |
| 4663 return consumeGridAreaShorthand(important); | 4755 return consumeGridAreaShorthand(important); |
| 4756 case CSSPropertyGridTemplate: | |
| 4757 return consumeGridTemplateShorthand(important); | |
| 4664 default: | 4758 default: |
| 4665 m_currentShorthand = oldShorthand; | 4759 m_currentShorthand = oldShorthand; |
| 4666 CSSParserValueList valueList(m_range); | 4760 CSSParserValueList valueList(m_range); |
| 4667 if (!valueList.size()) | 4761 if (!valueList.size()) |
| 4668 return false; | 4762 return false; |
| 4669 m_valueList = &valueList; | 4763 m_valueList = &valueList; |
| 4670 return legacyParseShorthand(unresolvedProperty, important); | 4764 return legacyParseShorthand(unresolvedProperty, important); |
| 4671 } | 4765 } |
| 4672 } | 4766 } |
| 4673 | 4767 |
| 4674 } // namespace blink | 4768 } // namespace blink |
| OLD | NEW |