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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 CSSPrimitiveValue::UnitType unitType = m_calcValue->isInt() ? CSSPrimiti veValue::UnitType::Integer : CSSPrimitiveValue::UnitType::Number; | 162 CSSPrimitiveValue::UnitType unitType = m_calcValue->isInt() ? CSSPrimiti veValue::UnitType::Integer : CSSPrimitiveValue::UnitType::Number; |
| 163 return cssValuePool().createValue(m_calcValue->doubleValue(), unitType); | 163 return cssValuePool().createValue(m_calcValue->doubleValue(), unitType); |
| 164 } | 164 } |
| 165 | 165 |
| 166 private: | 166 private: |
| 167 CSSParserTokenRange& m_sourceRange; | 167 CSSParserTokenRange& m_sourceRange; |
| 168 CSSParserTokenRange m_range; | 168 CSSParserTokenRange m_range; |
| 169 RefPtrWillBeMember<CSSCalcValue> m_calcValue; | 169 RefPtrWillBeMember<CSSCalcValue> m_calcValue; |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeInteger(CSSParserTokenRa nge& range, CSSParserMode cssParserMode, double minimumValue = -std::numeric_lim its<double>::max()) | 172 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeInteger(CSSParserTokenRa nge& range, CSSParserMode cssParserMode, double minimumValue = -std::numeric_lim its<double>::max()) |
|
Timothy Loh
2015/10/15 06:59:38
Unrelated, but I just noticed this doesn't need a
rwlbuis
2015/10/15 22:53:13
Well spotted, I removed it and adjusted the callsi
| |
| 173 { | 173 { |
| 174 const CSSParserToken& token = range.peek(); | 174 const CSSParserToken& token = range.peek(); |
| 175 if (token.type() == NumberToken) { | 175 if (token.type() == NumberToken) { |
| 176 if (token.numericValueType() == NumberValueType || token.numericValue() < minimumValue) | 176 if (token.numericValueType() == NumberValueType || token.numericValue() < minimumValue) |
| 177 return nullptr; | 177 return nullptr; |
| 178 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), token.unitType()); | 178 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), token.unitType()); |
| 179 } | 179 } |
| 180 CalcParser calcParser(range); | 180 CalcParser calcParser(range); |
| 181 if (const CSSCalcValue* calculation = calcParser.value()) { | 181 if (const CSSCalcValue* calculation = calcParser.value()) { |
| 182 if (calculation->category() != CalcNumber || !calculation->isInt()) | 182 if (calculation->category() != CalcNumber || !calculation->isInt()) |
| 183 return nullptr; | 183 return nullptr; |
| 184 double value = calculation->doubleValue(); | 184 double value = calculation->doubleValue(); |
| 185 if (value < minimumValue) | 185 if (value < minimumValue) |
| 186 return nullptr; | 186 return nullptr; |
| 187 return calcParser.consumeNumber(); | 187 return calcParser.consumeNumber(); |
| 188 } | 188 } |
| 189 return nullptr; | 189 return nullptr; |
| 190 } | 190 } |
| 191 | 191 |
| 192 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumePositiveInteger(CSSParse rTokenRange& range, CSSParserMode cssParserMode) | |
| 193 { | |
| 194 return consumeInteger(range, cssParserMode, 1); | |
| 195 } | |
| 196 | |
| 192 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeNumber(CSSParserTokenRan ge& range, ValueRange valueRange) | 197 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeNumber(CSSParserTokenRan ge& range, ValueRange valueRange) |
| 193 { | 198 { |
| 194 const CSSParserToken& token = range.peek(); | 199 const CSSParserToken& token = range.peek(); |
| 195 if (token.type() == NumberToken) { | 200 if (token.type() == NumberToken) { |
| 196 if (valueRange == ValueRangeNonNegative && token.numericValue() < 0) | 201 if (valueRange == ValueRangeNonNegative && token.numericValue() < 0) |
| 197 return nullptr; | 202 return nullptr; |
| 198 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), token.unitType()); | 203 return cssValuePool().createValue(range.consumeIncludingWhitespace().num ericValue(), token.unitType()); |
| 199 } | 204 } |
| 200 CalcParser calcParser(range, ValueRangeAll); | 205 CalcParser calcParser(range, ValueRangeAll); |
| 201 if (const CSSCalcValue* calculation = calcParser.value()) { | 206 if (const CSSCalcValue* calculation = calcParser.value()) { |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 } | 752 } |
| 748 return nullptr; | 753 return nullptr; |
| 749 } while (!range.atEnd()); | 754 } while (!range.atEnd()); |
| 750 | 755 |
| 751 if (!hasLengthOrPercentage) | 756 if (!hasLengthOrPercentage) |
| 752 return nullptr; | 757 return nullptr; |
| 753 | 758 |
| 754 return list.release(); | 759 return list.release(); |
| 755 } | 760 } |
| 756 | 761 |
| 762 static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnWidth(CSSParserTokenRange& range) | |
| 763 { | |
| 764 if (range.peek().id() == CSSValueAuto) | |
| 765 return consumeIdent(range); | |
| 766 // Always parse lengths in strict mode here, since it would be ambiguous oth erwise when used in | |
| 767 // the 'columns' shorthand property. | |
| 768 RefPtrWillBeRawPtr<CSSPrimitiveValue> columnWidth = consumeLength(range, HTM LStandardMode, ValueRangeNonNegative); | |
| 769 if (!columnWidth || (!columnWidth->isCalculated() && columnWidth->getDoubleV alue() == 0)) | |
| 770 return nullptr; | |
| 771 return columnWidth.release(); | |
| 772 } | |
| 773 | |
| 774 static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnCount(CSSParserTokenRange& range, CSSParserMode cssParserMode) | |
| 775 { | |
| 776 if (range.peek().id() == CSSValueAuto) | |
| 777 return consumeIdent(range); | |
| 778 return consumePositiveInteger(range, cssParserMode); | |
| 779 } | |
| 780 | |
| 781 static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnGap(CSSParserTokenRange& ra nge, CSSParserMode cssParserMode) | |
| 782 { | |
| 783 if (range.peek().id() == CSSValueNormal) | |
| 784 return consumeIdent(range); | |
| 785 return consumeLength(range, cssParserMode, ValueRangeNonNegative); | |
| 786 } | |
| 787 | |
| 788 static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnSpan(CSSParserTokenRange& r ange, CSSParserMode cssParserMode) | |
| 789 { | |
| 790 CSSValueID id = range.peek().id(); | |
| 791 if (id == CSSValueAll || id == CSSValueNone) | |
| 792 return consumeIdent(range); | |
| 793 if (range.peek().type() != NumberToken) | |
| 794 return nullptr; | |
| 795 if (RefPtrWillBeRawPtr<CSSPrimitiveValue> spanValue = consumeInteger(range, cssParserMode)) { | |
| 796 // 1 (will be dropped in the unprefixed property). | |
| 797 if (spanValue->getIntValue() == 1) | |
| 798 return spanValue.release(); | |
| 799 } | |
| 800 return nullptr; | |
| 801 } | |
| 802 | |
| 757 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) | 803 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) |
| 758 { | 804 { |
| 759 m_range.consumeWhitespace(); | 805 m_range.consumeWhitespace(); |
| 760 switch (propId) { | 806 switch (propId) { |
| 761 case CSSPropertyWillChange: | 807 case CSSPropertyWillChange: |
| 762 return consumeWillChange(m_range); | 808 return consumeWillChange(m_range); |
| 763 case CSSPropertyPage: | 809 case CSSPropertyPage: |
| 764 return consumePage(m_range); | 810 return consumePage(m_range); |
| 765 case CSSPropertyQuotes: | 811 case CSSPropertyQuotes: |
| 766 return consumeQuotes(m_range); | 812 return consumeQuotes(m_range); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 790 case CSSPropertyWebkitBorderHorizontalSpacing: | 836 case CSSPropertyWebkitBorderHorizontalSpacing: |
| 791 case CSSPropertyWebkitBorderVerticalSpacing: | 837 case CSSPropertyWebkitBorderVerticalSpacing: |
| 792 return consumeLength(m_range, m_context.mode(), ValueRangeNonNegative); | 838 return consumeLength(m_range, m_context.mode(), ValueRangeNonNegative); |
| 793 case CSSPropertyCounterIncrement: | 839 case CSSPropertyCounterIncrement: |
| 794 case CSSPropertyCounterReset: | 840 case CSSPropertyCounterReset: |
| 795 return consumeCounter(m_range, m_context.mode(), propId == CSSPropertyCo unterIncrement ? 1 : 0); | 841 return consumeCounter(m_range, m_context.mode(), propId == CSSPropertyCo unterIncrement ? 1 : 0); |
| 796 case CSSPropertySize: | 842 case CSSPropertySize: |
| 797 return consumeSize(m_range, m_context.mode()); | 843 return consumeSize(m_range, m_context.mode()); |
| 798 case CSSPropertyTextIndent: | 844 case CSSPropertyTextIndent: |
| 799 return consumeTextIndent(m_range, m_context.mode()); | 845 return consumeTextIndent(m_range, m_context.mode()); |
| 846 case CSSPropertyWebkitColumnWidth: | |
| 847 return consumeColumnWidth(m_range); | |
| 848 case CSSPropertyWebkitColumnCount: | |
| 849 return consumeColumnCount(m_range, m_context.mode()); | |
| 850 case CSSPropertyWebkitColumnGap: | |
| 851 return consumeColumnGap(m_range, m_context.mode()); | |
| 852 case CSSPropertyWebkitColumnSpan: | |
| 853 return consumeColumnSpan(m_range, m_context.mode()); | |
| 800 default: | 854 default: |
| 801 return nullptr; | 855 return nullptr; |
| 802 } | 856 } |
| 803 } | 857 } |
| 804 | 858 |
| 805 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) | 859 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) |
| 806 { | 860 { |
| 807 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 861 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
| 808 | 862 |
| 809 do { | 863 do { |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1124 if (!parsedValue || !m_range.atEnd()) | 1178 if (!parsedValue || !m_range.atEnd()) |
| 1125 return false; | 1179 return false; |
| 1126 addProperty(propId, parsedValue.release(), important); | 1180 addProperty(propId, parsedValue.release(), important); |
| 1127 return true; | 1181 return true; |
| 1128 } | 1182 } |
| 1129 default: | 1183 default: |
| 1130 return false; | 1184 return false; |
| 1131 } | 1185 } |
| 1132 } | 1186 } |
| 1133 | 1187 |
| 1188 static void consumeColumnWidthOrCount(CSSParserTokenRange& range, CSSParserMode cssParserMode, RefPtrWillBeRawPtr<CSSValue> &columnWidth, RefPtrWillBeRawPtr<CSS Value> &columnCount) | |
| 1189 { | |
| 1190 if (range.peek().id() == CSSValueAuto) { | |
| 1191 consumeIdent(range); | |
| 1192 return; | |
| 1193 } | |
| 1194 if (!columnWidth) { | |
| 1195 if ((columnWidth = consumeColumnWidth(range))) | |
| 1196 return; | |
| 1197 } | |
| 1198 if (!columnCount) | |
| 1199 columnCount = consumeColumnCount(range, cssParserMode); | |
| 1200 } | |
| 1201 | |
| 1202 bool CSSPropertyParser::consumeColumns(bool important) | |
| 1203 { | |
| 1204 RefPtrWillBeRawPtr<CSSValue> columnWidth = nullptr; | |
| 1205 RefPtrWillBeRawPtr<CSSValue> columnCount = nullptr; | |
| 1206 consumeColumnWidthOrCount(m_range, m_context.mode(), columnWidth, columnCoun t); | |
| 1207 consumeColumnWidthOrCount(m_range, m_context.mode(), columnWidth, columnCoun t); | |
| 1208 if (!m_range.atEnd()) | |
| 1209 return false; | |
| 1210 if (!columnWidth) | |
| 1211 columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 1212 if (!columnCount) | |
| 1213 columnCount = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 1214 addProperty(CSSPropertyWebkitColumnWidth, columnWidth.release(), important); | |
| 1215 addProperty(CSSPropertyWebkitColumnCount, columnCount.release(), important); | |
| 1216 return true; | |
| 1217 } | |
| 1218 | |
| 1134 bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) | 1219 bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) |
| 1135 { | 1220 { |
| 1136 m_range.consumeWhitespace(); | 1221 m_range.consumeWhitespace(); |
| 1137 CSSPropertyID oldShorthand = m_currentShorthand; | 1222 CSSPropertyID oldShorthand = m_currentShorthand; |
| 1138 // TODO(rob.buis): Remove this when the legacy property parser is gone | 1223 // TODO(rob.buis): Remove this when the legacy property parser is gone |
| 1139 m_currentShorthand = propId; | 1224 m_currentShorthand = propId; |
| 1140 switch (propId) { | 1225 switch (propId) { |
| 1141 case CSSPropertyWebkitMarginCollapse: { | 1226 case CSSPropertyWebkitMarginCollapse: { |
| 1142 CSSValueID id = m_range.consumeIncludingWhitespace().id(); | 1227 CSSValueID id = m_range.consumeIncludingWhitespace().id(); |
| 1143 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyWebki tMarginBeforeCollapse, id)) | 1228 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyWebki tMarginBeforeCollapse, id)) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1177 return true; | 1262 return true; |
| 1178 } | 1263 } |
| 1179 case CSSPropertyFont: { | 1264 case CSSPropertyFont: { |
| 1180 const CSSParserToken& token = m_range.peek(); | 1265 const CSSParserToken& token = m_range.peek(); |
| 1181 if (token.id() >= CSSValueCaption && token.id() <= CSSValueStatusBar) | 1266 if (token.id() >= CSSValueCaption && token.id() <= CSSValueStatusBar) |
| 1182 return consumeSystemFont(important); | 1267 return consumeSystemFont(important); |
| 1183 return consumeFont(important); | 1268 return consumeFont(important); |
| 1184 } | 1269 } |
| 1185 case CSSPropertyBorderSpacing: | 1270 case CSSPropertyBorderSpacing: |
| 1186 return consumeBorderSpacing(important); | 1271 return consumeBorderSpacing(important); |
| 1272 case CSSPropertyWebkitColumns: { | |
| 1273 m_currentShorthand = oldShorthand; | |
| 1274 return consumeColumns(important); | |
| 1275 } | |
| 1187 default: | 1276 default: |
| 1188 m_currentShorthand = oldShorthand; | 1277 m_currentShorthand = oldShorthand; |
| 1189 return false; | 1278 return false; |
| 1190 } | 1279 } |
| 1191 } | 1280 } |
| 1192 | 1281 |
| 1193 } // namespace blink | 1282 } // namespace blink |
| OLD | NEW |