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 "config.h" | 5 #include "config.h" |
| 6 #include "core/css/parser/CSSPropertyParser.h" | 6 #include "core/css/parser/CSSPropertyParser.h" |
| 7 | 7 |
| 8 #include "core/StylePropertyShorthand.h" | 8 #include "core/StylePropertyShorthand.h" |
| 9 #include "core/css/CSSCalculationValue.h" | 9 #include "core/css/CSSCalculationValue.h" |
| 10 #include "core/css/CSSCustomIdentValue.h" | 10 #include "core/css/CSSCustomIdentValue.h" |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 int i = defaultValue; | 656 int i = defaultValue; |
| 657 if (RefPtrWillBeRawPtr<CSSPrimitiveValue> counterValue = consumeInteger( range, cssParserMode)) | 657 if (RefPtrWillBeRawPtr<CSSPrimitiveValue> counterValue = consumeInteger( range, cssParserMode)) |
| 658 i = clampTo<int>(counterValue->getDoubleValue()); | 658 i = clampTo<int>(counterValue->getDoubleValue()); |
| 659 list->append(CSSValuePair::create(counterName.release(), | 659 list->append(CSSValuePair::create(counterName.release(), |
| 660 cssValuePool().createValue(i, CSSPrimitiveValue::UnitType::Number), | 660 cssValuePool().createValue(i, CSSPrimitiveValue::UnitType::Number), |
| 661 CSSValuePair::DropIdenticalValues)); | 661 CSSValuePair::DropIdenticalValues)); |
| 662 } while (!range.atEnd()); | 662 } while (!range.atEnd()); |
| 663 return list.release(); | 663 return list.release(); |
| 664 } | 664 } |
| 665 | 665 |
| 666 static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnWidth(CSSParserTokenRange& range) | |
| 667 { | |
| 668 if (range.peek().id() == CSSValueAuto) | |
| 669 return consumeIdent(range); | |
| 670 // Always parse lengths in strict mode here, since it would be ambiguous oth erwise when used in | |
| 671 // the 'columns' shorthand property. | |
| 672 RefPtrWillBeRawPtr<CSSPrimitiveValue> columnWidth = consumeLength(range, HTM LStandardMode, ValueRangeNonNegative); | |
| 673 if (!columnWidth || (!columnWidth->isCalculated() && columnWidth->getDoubleV alue() == 0)) | |
| 674 return nullptr; | |
| 675 return columnWidth.release(); | |
| 676 } | |
| 677 | |
| 678 static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnCount(CSSParserTokenRange& range, CSSParserMode cssParserMode) | |
| 679 { | |
| 680 if (range.peek().id() == CSSValueAuto) | |
| 681 return consumeIdent(range); | |
| 682 return consumeInteger(range, cssParserMode, 1); | |
| 683 } | |
| 684 | |
| 685 static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnGap(CSSParserTokenRange& ra nge, CSSParserMode cssParserMode) | |
| 686 { | |
| 687 if (range.peek().id() == CSSValueNormal) | |
| 688 return consumeIdent(range); | |
| 689 return consumeLength(range, cssParserMode, ValueRangeNonNegative); | |
| 690 } | |
| 691 | |
| 692 static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnSpan(CSSParserTokenRange& r ange, CSSParserMode cssParserMode) | |
| 693 { | |
| 694 CSSValueID id = range.peek().id(); | |
| 695 if (id == CSSValueAll || id == CSSValueNone) | |
| 696 return consumeIdent(range); | |
| 697 if (range.peek().type() != NumberToken) | |
|
Timothy Loh
2015/10/13 00:30:03
I probably wouldn't bother with this check
rwlbuis
2015/10/13 02:27:02
The check was done to filter out any calc() usage.
| |
| 698 return nullptr; | |
| 699 if (RefPtrWillBeRawPtr<CSSPrimitiveValue> spanValue = consumeInteger(range, cssParserMode)) { | |
| 700 // 1 (will be dropped in the unprefixed property). | |
| 701 if (spanValue->getIntValue() == 1) | |
| 702 return spanValue.release(); | |
| 703 } | |
| 704 return nullptr; | |
| 705 } | |
| 706 | |
| 666 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) | 707 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) |
| 667 { | 708 { |
| 668 m_range.consumeWhitespace(); | 709 m_range.consumeWhitespace(); |
| 669 switch (propId) { | 710 switch (propId) { |
| 670 case CSSPropertyWillChange: | 711 case CSSPropertyWillChange: |
| 671 return consumeWillChange(m_range); | 712 return consumeWillChange(m_range); |
| 672 case CSSPropertyPage: | 713 case CSSPropertyPage: |
| 673 return consumePage(m_range); | 714 return consumePage(m_range); |
| 674 case CSSPropertyQuotes: | 715 case CSSPropertyQuotes: |
| 675 return consumeQuotes(m_range); | 716 return consumeQuotes(m_range); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 695 case CSSPropertyLineHeight: | 736 case CSSPropertyLineHeight: |
| 696 return consumeLineHeight(m_range, m_context.mode()); | 737 return consumeLineHeight(m_range, m_context.mode()); |
| 697 case CSSPropertyRotate: | 738 case CSSPropertyRotate: |
| 698 return consumeRotation(m_range); | 739 return consumeRotation(m_range); |
| 699 case CSSPropertyWebkitBorderHorizontalSpacing: | 740 case CSSPropertyWebkitBorderHorizontalSpacing: |
| 700 case CSSPropertyWebkitBorderVerticalSpacing: | 741 case CSSPropertyWebkitBorderVerticalSpacing: |
| 701 return consumeLength(m_range, m_context.mode(), ValueRangeNonNegative); | 742 return consumeLength(m_range, m_context.mode(), ValueRangeNonNegative); |
| 702 case CSSPropertyCounterIncrement: | 743 case CSSPropertyCounterIncrement: |
| 703 case CSSPropertyCounterReset: | 744 case CSSPropertyCounterReset: |
| 704 return consumeCounter(m_range, m_context.mode(), propId == CSSPropertyCo unterIncrement ? 1 : 0); | 745 return consumeCounter(m_range, m_context.mode(), propId == CSSPropertyCo unterIncrement ? 1 : 0); |
| 746 case CSSPropertyWebkitColumnWidth: | |
| 747 return consumeColumnWidth(m_range); | |
| 748 case CSSPropertyWebkitColumnCount: | |
| 749 return consumeColumnCount(m_range, m_context.mode()); | |
| 750 case CSSPropertyWebkitColumnGap: | |
| 751 return consumeColumnGap(m_range, m_context.mode()); | |
| 752 case CSSPropertyWebkitColumnSpan: | |
| 753 return consumeColumnSpan(m_range, m_context.mode()); | |
| 705 default: | 754 default: |
| 706 return nullptr; | 755 return nullptr; |
| 707 } | 756 } |
| 708 } | 757 } |
| 709 | 758 |
| 710 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) | 759 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) |
| 711 { | 760 { |
| 712 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 761 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
| 713 | 762 |
| 714 do { | 763 do { |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1029 if (!parsedValue || !m_range.atEnd()) | 1078 if (!parsedValue || !m_range.atEnd()) |
| 1030 return false; | 1079 return false; |
| 1031 addProperty(propId, parsedValue.release(), important); | 1080 addProperty(propId, parsedValue.release(), important); |
| 1032 return true; | 1081 return true; |
| 1033 } | 1082 } |
| 1034 default: | 1083 default: |
| 1035 return false; | 1084 return false; |
| 1036 } | 1085 } |
| 1037 } | 1086 } |
| 1038 | 1087 |
| 1088 static void consumeColumnWidthOrCount(CSSParserTokenRange& range, CSSParserMode cssParserMode, RefPtrWillBeRawPtr<CSSValue> &columnWidth, RefPtrWillBeRawPtr<CSS Value> &columnCount) | |
| 1089 { | |
| 1090 if (range.peek().id() == CSSValueAuto) { | |
| 1091 consumeIdent(range); | |
| 1092 return; | |
| 1093 } | |
| 1094 if (!columnWidth) { | |
| 1095 if ((columnWidth = consumeColumnWidth(range))) | |
| 1096 return; | |
| 1097 } | |
| 1098 if (!columnCount) | |
| 1099 columnCount = consumeColumnCount(range, cssParserMode); | |
| 1100 } | |
| 1101 | |
| 1102 bool CSSPropertyParser::consumeColumns(bool important) | |
|
Timothy Loh
2015/10/13 00:30:03
Do we check somewhere that the input isn't blank (
rwlbuis
2015/10/13 02:27:01
Good point, I'll check tomorrow, likely with this
| |
| 1103 { | |
| 1104 RefPtrWillBeRawPtr<CSSValue> columnWidth = nullptr; | |
| 1105 RefPtrWillBeRawPtr<CSSValue> columnCount = nullptr; | |
| 1106 consumeColumnWidthOrCount(m_range, m_context.mode(), columnWidth, columnCoun t); | |
| 1107 consumeColumnWidthOrCount(m_range, m_context.mode(), columnWidth, columnCoun t); | |
| 1108 if (!m_range.atEnd()) | |
| 1109 return false; | |
| 1110 if (!columnWidth) | |
| 1111 columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 1112 if (!columnCount) | |
| 1113 columnCount = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 1114 addProperty(CSSPropertyWebkitColumnWidth, columnWidth.release(), important); | |
| 1115 addProperty(CSSPropertyWebkitColumnCount, columnCount.release(), important); | |
| 1116 return true; | |
| 1117 } | |
| 1118 | |
| 1039 bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) | 1119 bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) |
| 1040 { | 1120 { |
| 1041 m_range.consumeWhitespace(); | 1121 m_range.consumeWhitespace(); |
| 1042 CSSPropertyID oldShorthand = m_currentShorthand; | 1122 CSSPropertyID oldShorthand = m_currentShorthand; |
| 1043 // TODO(rob.buis): Remove this when the legacy property parser is gone | 1123 // TODO(rob.buis): Remove this when the legacy property parser is gone |
| 1044 m_currentShorthand = propId; | 1124 m_currentShorthand = propId; |
| 1045 switch (propId) { | 1125 switch (propId) { |
| 1046 case CSSPropertyWebkitMarginCollapse: { | 1126 case CSSPropertyWebkitMarginCollapse: { |
| 1047 CSSValueID id = m_range.consumeIncludingWhitespace().id(); | 1127 CSSValueID id = m_range.consumeIncludingWhitespace().id(); |
| 1048 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyWebki tMarginBeforeCollapse, id)) | 1128 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyWebki tMarginBeforeCollapse, id)) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1082 return true; | 1162 return true; |
| 1083 } | 1163 } |
| 1084 case CSSPropertyFont: { | 1164 case CSSPropertyFont: { |
| 1085 const CSSParserToken& token = m_range.peek(); | 1165 const CSSParserToken& token = m_range.peek(); |
| 1086 if (token.id() >= CSSValueCaption && token.id() <= CSSValueStatusBar) | 1166 if (token.id() >= CSSValueCaption && token.id() <= CSSValueStatusBar) |
| 1087 return consumeSystemFont(important); | 1167 return consumeSystemFont(important); |
| 1088 return consumeFont(important); | 1168 return consumeFont(important); |
| 1089 } | 1169 } |
| 1090 case CSSPropertyBorderSpacing: | 1170 case CSSPropertyBorderSpacing: |
| 1091 return consumeBorderSpacing(important); | 1171 return consumeBorderSpacing(important); |
| 1172 case CSSPropertyWebkitColumns: { | |
| 1173 m_currentShorthand = oldShorthand; | |
|
Timothy Loh
2015/10/13 00:30:03
?
rwlbuis
2015/10/13 02:27:02
Columns did not use ShorthandScope, causing the ou
| |
| 1174 return consumeColumns(important); | |
| 1175 } | |
| 1092 default: | 1176 default: |
| 1093 m_currentShorthand = oldShorthand; | 1177 m_currentShorthand = oldShorthand; |
| 1094 return false; | 1178 return false; |
| 1095 } | 1179 } |
| 1096 } | 1180 } |
| 1097 | 1181 |
| 1098 } // namespace blink | 1182 } // namespace blink |
| OLD | NEW |