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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 CSSParserValueList valueList(range); | 46 CSSParserValueList valueList(range); |
47 if (!valueList.size()) | 47 if (!valueList.size()) |
48 return false; // Parser error | 48 return false; // Parser error |
49 CSSPropertyParser parser(&valueList, range, context, parsedProperties, ruleT
ype); | 49 CSSPropertyParser parser(&valueList, range, context, parsedProperties, ruleT
ype); |
50 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); | 50 CSSPropertyID resolvedProperty = resolveCSSPropertyID(unresolvedProperty); |
51 bool parseSuccess; | 51 bool parseSuccess; |
52 | 52 |
53 if (ruleType == StyleRule::Viewport) { | 53 if (ruleType == StyleRule::Viewport) { |
54 parseSuccess = (RuntimeEnabledFeatures::cssViewportEnabled() || isUAShee
tBehavior(context.mode())) | 54 parseSuccess = (RuntimeEnabledFeatures::cssViewportEnabled() || isUAShee
tBehavior(context.mode())) |
55 && parser.parseViewportProperty(resolvedProperty, important); | 55 && parser.parseViewportDescriptor(resolvedProperty, important); |
56 } else if (ruleType == StyleRule::FontFace) { | 56 } else if (ruleType == StyleRule::FontFace) { |
57 parseSuccess = parser.parseFontFaceDescriptor(resolvedProperty); | 57 parseSuccess = parser.parseFontFaceDescriptor(resolvedProperty); |
58 } else { | 58 } else { |
59 parseSuccess = parser.parseValue(unresolvedProperty, important); | 59 parseSuccess = parser.parseValue(unresolvedProperty, important); |
60 } | 60 } |
61 | 61 |
62 // This doesn't count UA style sheets | 62 // This doesn't count UA style sheets |
63 if (parseSuccess && context.useCounter()) | 63 if (parseSuccess && context.useCounter()) |
64 context.useCounter()->count(context, unresolvedProperty); | 64 context.useCounter()->count(context, unresolvedProperty); |
65 | 65 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 || (valueRange == ValueRangeNonNegative && token.numericValue() < 0)
) | 251 || (valueRange == ValueRangeNonNegative && token.numericValue() < 0)
) |
252 return nullptr; | 252 return nullptr; |
253 return cssValuePool().createValue(range.consumeIncludingWhitespace().num
ericValue(), CSSPrimitiveValue::UnitType::Pixels); | 253 return cssValuePool().createValue(range.consumeIncludingWhitespace().num
ericValue(), CSSPrimitiveValue::UnitType::Pixels); |
254 } | 254 } |
255 CalcParser calcParser(range, valueRange); | 255 CalcParser calcParser(range, valueRange); |
256 if (calcParser.value() && calcParser.value()->category() == CalcLength) | 256 if (calcParser.value() && calcParser.value()->category() == CalcLength) |
257 return calcParser.consumeValue(); | 257 return calcParser.consumeValue(); |
258 return nullptr; | 258 return nullptr; |
259 } | 259 } |
260 | 260 |
261 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLengthOrPercent(CSSParse
rTokenRange& range, CSSParserMode cssParserMode, ValueRange valueRange, Unitless
Quirk unitless = UnitlessQuirk::Forbid) | 261 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumePercent(CSSParserTokenRa
nge& range, ValueRange valueRange) |
262 { | 262 { |
263 const CSSParserToken& token = range.peek(); | 263 const CSSParserToken& token = range.peek(); |
264 if (token.type() == DimensionToken || token.type() == NumberToken) | |
265 return consumeLength(range, cssParserMode, valueRange, unitless); | |
266 if (token.type() == PercentageToken) { | 264 if (token.type() == PercentageToken) { |
267 if (valueRange == ValueRangeNonNegative && token.numericValue() < 0) | 265 if (valueRange == ValueRangeNonNegative && token.numericValue() < 0) |
268 return nullptr; | 266 return nullptr; |
269 return cssValuePool().createValue(range.consumeIncludingWhitespace().num
ericValue(), CSSPrimitiveValue::UnitType::Percentage); | 267 return cssValuePool().createValue(range.consumeIncludingWhitespace().num
ericValue(), CSSPrimitiveValue::UnitType::Percentage); |
270 } | 268 } |
271 CalcParser calcParser(range, valueRange); | 269 CalcParser calcParser(range, valueRange); |
272 if (const CSSCalcValue* calculation = calcParser.value()) { | 270 if (const CSSCalcValue* calculation = calcParser.value()) { |
| 271 if (calculation->category() == CalcPercent) |
| 272 return calcParser.consumeValue(); |
| 273 } |
| 274 return nullptr; |
| 275 } |
| 276 |
| 277 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeLengthOrPercent(CSSParse
rTokenRange& range, CSSParserMode cssParserMode, ValueRange valueRange, Unitless
Quirk unitless = UnitlessQuirk::Forbid) |
| 278 { |
| 279 const CSSParserToken& token = range.peek(); |
| 280 if (token.type() == DimensionToken || token.type() == NumberToken) |
| 281 return consumeLength(range, cssParserMode, valueRange, unitless); |
| 282 if (token.type() == PercentageToken) |
| 283 return consumePercent(range, valueRange); |
| 284 CalcParser calcParser(range, valueRange); |
| 285 if (const CSSCalcValue* calculation = calcParser.value()) { |
273 if (calculation->category() == CalcLength || calculation->category() ==
CalcPercent || calculation->category() == CalcPercentLength) | 286 if (calculation->category() == CalcLength || calculation->category() ==
CalcPercent || calculation->category() == CalcPercentLength) |
274 return calcParser.consumeValue(); | 287 return calcParser.consumeValue(); |
275 } | 288 } |
276 return nullptr; | 289 return nullptr; |
277 } | 290 } |
278 | 291 |
279 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeAngle(CSSParserTokenRang
e& range) | 292 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeAngle(CSSParserTokenRang
e& range) |
280 { | 293 { |
281 const CSSParserToken& token = range.peek(); | 294 const CSSParserToken& token = range.peek(); |
282 if (token.type() == DimensionToken) { | 295 if (token.type() == DimensionToken) { |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 RefPtrWillBeRawPtr<CSSValue> verticalSpacing = horizontalSpacing; | 914 RefPtrWillBeRawPtr<CSSValue> verticalSpacing = horizontalSpacing; |
902 if (!m_range.atEnd()) | 915 if (!m_range.atEnd()) |
903 verticalSpacing = consumeLength(m_range, m_context.mode(), ValueRangeNon
Negative, UnitlessQuirk::Allow); | 916 verticalSpacing = consumeLength(m_range, m_context.mode(), ValueRangeNon
Negative, UnitlessQuirk::Allow); |
904 if (!verticalSpacing || !m_range.atEnd()) | 917 if (!verticalSpacing || !m_range.atEnd()) |
905 return false; | 918 return false; |
906 addProperty(CSSPropertyWebkitBorderHorizontalSpacing, horizontalSpacing.rele
ase(), important); | 919 addProperty(CSSPropertyWebkitBorderHorizontalSpacing, horizontalSpacing.rele
ase(), important); |
907 addProperty(CSSPropertyWebkitBorderVerticalSpacing, verticalSpacing.release(
), important); | 920 addProperty(CSSPropertyWebkitBorderVerticalSpacing, verticalSpacing.release(
), important); |
908 return true; | 921 return true; |
909 } | 922 } |
910 | 923 |
| 924 static PassRefPtrWillBeRawPtr<CSSValue> consumeSingleViewportDescriptor(CSSParse
rTokenRange& range, CSSPropertyID propId, CSSParserMode cssParserMode) |
| 925 { |
| 926 CSSValueID id = range.peek().id(); |
| 927 switch (propId) { |
| 928 case CSSPropertyMinWidth: |
| 929 case CSSPropertyMaxWidth: |
| 930 case CSSPropertyMinHeight: |
| 931 case CSSPropertyMaxHeight: |
| 932 if (id == CSSValueAuto || id == CSSValueInternalExtendToZoom) |
| 933 return consumeIdent(range); |
| 934 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegativ
e); |
| 935 case CSSPropertyMinZoom: |
| 936 case CSSPropertyMaxZoom: |
| 937 case CSSPropertyZoom: { |
| 938 if (id == CSSValueAuto) |
| 939 return consumeIdent(range); |
| 940 RefPtrWillBeRawPtr<CSSValue> parsedValue = consumeNumber(range, ValueRan
geNonNegative); |
| 941 if (parsedValue) |
| 942 return parsedValue.release(); |
| 943 return consumePercent(range, ValueRangeNonNegative); |
| 944 } |
| 945 case CSSPropertyUserZoom: |
| 946 if (id == CSSValueZoom || id == CSSValueFixed) |
| 947 return consumeIdent(range); |
| 948 break; |
| 949 case CSSPropertyOrientation: |
| 950 if (id == CSSValueAuto || id == CSSValuePortrait || id == CSSValueLandsc
ape) |
| 951 return consumeIdent(range); |
| 952 break; |
| 953 default: |
| 954 ASSERT_NOT_REACHED(); |
| 955 break; |
| 956 } |
| 957 |
| 958 return nullptr; |
| 959 } |
| 960 |
| 961 bool CSSPropertyParser::parseViewportDescriptor(CSSPropertyID propId, bool impor
tant) |
| 962 { |
| 963 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_c
ontext.mode())); |
| 964 |
| 965 m_range.consumeWhitespace(); |
| 966 |
| 967 switch (propId) { |
| 968 case CSSPropertyWidth: { |
| 969 RefPtrWillBeRawPtr<CSSValue> minWidth = consumeSingleViewportDescriptor(
m_range, CSSPropertyMinWidth, m_context.mode()); |
| 970 if (!minWidth) |
| 971 return false; |
| 972 RefPtrWillBeRawPtr<CSSValue> maxWidth = minWidth; |
| 973 if (!m_range.atEnd()) |
| 974 maxWidth = consumeSingleViewportDescriptor(m_range, CSSPropertyMaxWi
dth, m_context.mode()); |
| 975 if (!maxWidth || !m_range.atEnd()) |
| 976 return false; |
| 977 addProperty(CSSPropertyMinWidth, minWidth.release(), important); |
| 978 addProperty(CSSPropertyMaxWidth, maxWidth.release(), important); |
| 979 return true; |
| 980 } |
| 981 case CSSPropertyHeight: { |
| 982 RefPtrWillBeRawPtr<CSSValue> minHeight = consumeSingleViewportDescriptor
(m_range, CSSPropertyMinHeight, m_context.mode()); |
| 983 if (!minHeight) |
| 984 return false; |
| 985 RefPtrWillBeRawPtr<CSSValue> maxHeight = minHeight; |
| 986 if (!m_range.atEnd()) |
| 987 maxHeight = consumeSingleViewportDescriptor(m_range, CSSPropertyMaxH
eight, m_context.mode()); |
| 988 if (!maxHeight || !m_range.atEnd()) |
| 989 return false; |
| 990 addProperty(CSSPropertyMinHeight, minHeight.release(), important); |
| 991 addProperty(CSSPropertyMaxHeight, maxHeight.release(), important); |
| 992 return true; |
| 993 } |
| 994 case CSSPropertyMinWidth: |
| 995 case CSSPropertyMaxWidth: |
| 996 case CSSPropertyMinHeight: |
| 997 case CSSPropertyMaxHeight: |
| 998 case CSSPropertyMinZoom: |
| 999 case CSSPropertyMaxZoom: |
| 1000 case CSSPropertyZoom: |
| 1001 case CSSPropertyUserZoom: |
| 1002 case CSSPropertyOrientation: { |
| 1003 RefPtrWillBeRawPtr<CSSValue> parsedValue = consumeSingleViewportDescript
or(m_range, propId, m_context.mode()); |
| 1004 if (!parsedValue || !m_range.atEnd()) |
| 1005 return false; |
| 1006 addProperty(propId, parsedValue.release(), important); |
| 1007 return true; |
| 1008 } |
| 1009 default: |
| 1010 return false; |
| 1011 } |
| 1012 } |
| 1013 |
911 bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) | 1014 bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important) |
912 { | 1015 { |
913 m_range.consumeWhitespace(); | 1016 m_range.consumeWhitespace(); |
914 CSSPropertyID oldShorthand = m_currentShorthand; | 1017 CSSPropertyID oldShorthand = m_currentShorthand; |
915 // TODO(rob.buis): Remove this when the legacy property parser is gone | 1018 // TODO(rob.buis): Remove this when the legacy property parser is gone |
916 m_currentShorthand = propId; | 1019 m_currentShorthand = propId; |
917 switch (propId) { | 1020 switch (propId) { |
918 case CSSPropertyWebkitMarginCollapse: { | 1021 case CSSPropertyWebkitMarginCollapse: { |
919 CSSValueID id = m_range.consumeIncludingWhitespace().id(); | 1022 CSSValueID id = m_range.consumeIncludingWhitespace().id(); |
920 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyWebki
tMarginBeforeCollapse, id)) | 1023 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyWebki
tMarginBeforeCollapse, id)) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 } | 1064 } |
962 case CSSPropertyBorderSpacing: | 1065 case CSSPropertyBorderSpacing: |
963 return consumeBorderSpacing(important); | 1066 return consumeBorderSpacing(important); |
964 default: | 1067 default: |
965 m_currentShorthand = oldShorthand; | 1068 m_currentShorthand = oldShorthand; |
966 return false; | 1069 return false; |
967 } | 1070 } |
968 } | 1071 } |
969 | 1072 |
970 } // namespace blink | 1073 } // namespace blink |
OLD | NEW |