| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/CSSParserFastPaths.h" | 6 #include "core/css/parser/CSSParserFastPaths.h" |
| 7 | 7 |
| 8 #include "core/StylePropertyShorthand.h" | 8 #include "core/StylePropertyShorthand.h" |
| 9 #include "core/css/CSSFunctionValue.h" | 9 #include "core/css/CSSFunctionValue.h" |
| 10 #include "core/css/CSSValuePool.h" | 10 #include "core/css/CSSValuePool.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 // We rely on charactersToDouble for validation as well. The function | 80 // We rely on charactersToDouble for validation as well. The function |
| 81 // will set "ok" to "false" if the entire passed-in character range does | 81 // will set "ok" to "false" if the entire passed-in character range does |
| 82 // not represent a double. | 82 // not represent a double. |
| 83 bool ok; | 83 bool ok; |
| 84 number = charactersToDouble(characters, length, &ok); | 84 number = charactersToDouble(characters, length, &ok); |
| 85 return ok; | 85 return ok; |
| 86 } | 86 } |
| 87 | 87 |
| 88 static PassRefPtrWillBeRawPtr<CSSValue> parseSimpleLengthValue(CSSPropertyID pro
pertyId, const String& string, CSSParserMode cssParserMode) | 88 static NullableCSSValue parseSimpleLengthValue(CSSPropertyID propertyId, const S
tring& string, CSSParserMode cssParserMode) |
| 89 { | 89 { |
| 90 ASSERT(!string.isEmpty()); | 90 ASSERT(!string.isEmpty()); |
| 91 bool acceptsNegativeNumbers = false; | 91 bool acceptsNegativeNumbers = false; |
| 92 | 92 |
| 93 // In @viewport, width and height are shorthands, not simple length values. | 93 // In @viewport, width and height are shorthands, not simple length values. |
| 94 if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthProp
ertyID(propertyId, acceptsNegativeNumbers)) | 94 if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthProp
ertyID(propertyId, acceptsNegativeNumbers)) |
| 95 return nullptr; | 95 return nullptr; |
| 96 | 96 |
| 97 unsigned length = string.length(); | 97 unsigned length = string.length(); |
| 98 double number; | 98 double number; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 return true; | 445 return true; |
| 446 | 446 |
| 447 // Try named colors. | 447 // Try named colors. |
| 448 Color tc; | 448 Color tc; |
| 449 if (!tc.setNamedColor(name)) | 449 if (!tc.setNamedColor(name)) |
| 450 return false; | 450 return false; |
| 451 rgb = tc.rgb(); | 451 rgb = tc.rgb(); |
| 452 return true; | 452 return true; |
| 453 } | 453 } |
| 454 | 454 |
| 455 static PassRefPtrWillBeRawPtr<CSSValue> parseColor(const String& string, bool qu
irksMode) | 455 static NullableCSSValue parseColor(const String& string, bool quirksMode) |
| 456 { | 456 { |
| 457 ASSERT(!string.isEmpty()); | 457 ASSERT(!string.isEmpty()); |
| 458 CSSParserString cssString; | 458 CSSParserString cssString; |
| 459 cssString.init(string); | 459 cssString.init(string); |
| 460 CSSValueID valueID = cssValueKeywordID(cssString); | 460 CSSValueID valueID = cssValueKeywordID(cssString); |
| 461 if (valueID == CSSValueWebkitText || valueID == CSSValueCurrentcolor | 461 if (valueID == CSSValueWebkitText || valueID == CSSValueCurrentcolor |
| 462 || (valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID
== CSSValueMenu | 462 || (valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID
== CSSValueMenu |
| 463 || (quirksMode && valueID >= CSSValueWebkitFocusRingColor && valueID < C
SSValueWebkitText)) | 463 || (quirksMode && valueID >= CSSValueWebkitFocusRingColor && valueID < C
SSValueWebkitText)) |
| 464 return cssValuePool().createIdentifierValue(valueID); | 464 return cssValuePool().createIdentifierValue(valueID); |
| 465 | 465 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 case CSSPropertyScrollSnapType: | 755 case CSSPropertyScrollSnapType: |
| 756 return true; | 756 return true; |
| 757 case CSSPropertyAlignItems: | 757 case CSSPropertyAlignItems: |
| 758 case CSSPropertyAlignSelf: | 758 case CSSPropertyAlignSelf: |
| 759 return !RuntimeEnabledFeatures::cssGridLayoutEnabled(); | 759 return !RuntimeEnabledFeatures::cssGridLayoutEnabled(); |
| 760 default: | 760 default: |
| 761 return false; | 761 return false; |
| 762 } | 762 } |
| 763 } | 763 } |
| 764 | 764 |
| 765 static PassRefPtrWillBeRawPtr<CSSValue> parseKeywordValue(CSSPropertyID property
Id, const String& string) | 765 static NullableCSSValue parseKeywordValue(CSSPropertyID propertyId, const String
& string) |
| 766 { | 766 { |
| 767 ASSERT(!string.isEmpty()); | 767 ASSERT(!string.isEmpty()); |
| 768 | 768 |
| 769 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) { | 769 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) { |
| 770 // All properties accept the values of "initial" and "inherit". | 770 // All properties accept the values of "initial" and "inherit". |
| 771 String lowerCaseString = string.lower(); | 771 String lowerCaseString = string.lower(); |
| 772 if (lowerCaseString != "initial" && lowerCaseString != "inherit") | 772 if (lowerCaseString != "initial" && lowerCaseString != "inherit") |
| 773 return nullptr; | 773 return nullptr; |
| 774 | 774 |
| 775 // Parse initial/inherit shorthands using the CSSPropertyParser. | 775 // Parse initial/inherit shorthands using the CSSPropertyParser. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 transformList = CSSValueList::createSpaceSeparated(); | 932 transformList = CSSValueList::createSpaceSeparated(); |
| 933 transformList->append(transformValue.release()); | 933 transformList->append(transformValue.release()); |
| 934 if (pos < end) { | 934 if (pos < end) { |
| 935 if (isCSSSpace(*pos)) | 935 if (isCSSSpace(*pos)) |
| 936 return nullptr; | 936 return nullptr; |
| 937 } | 937 } |
| 938 } | 938 } |
| 939 return transformList.release(); | 939 return transformList.release(); |
| 940 } | 940 } |
| 941 | 941 |
| 942 static PassRefPtrWillBeRawPtr<CSSValue> parseSimpleTransform(CSSPropertyID prope
rtyID, const String& string) | 942 static NullableCSSValue parseSimpleTransform(CSSPropertyID propertyID, const Str
ing& string) |
| 943 { | 943 { |
| 944 ASSERT(!string.isEmpty()); | 944 ASSERT(!string.isEmpty()); |
| 945 | 945 |
| 946 if (propertyID != CSSPropertyTransform) | 946 if (propertyID != CSSPropertyTransform) |
| 947 return nullptr; | 947 return nullptr; |
| 948 if (string.is8Bit()) { | 948 if (string.is8Bit()) { |
| 949 const LChar* pos = string.characters8(); | 949 const LChar* pos = string.characters8(); |
| 950 const LChar* end = pos + string.length(); | 950 const LChar* end = pos + string.length(); |
| 951 return parseSimpleTransformList(pos, end); | 951 return parseSimpleTransformList(pos, end); |
| 952 } | 952 } |
| 953 const UChar* pos = string.characters16(); | 953 const UChar* pos = string.characters16(); |
| 954 const UChar* end = pos + string.length(); | 954 const UChar* end = pos + string.length(); |
| 955 return parseSimpleTransformList(pos, end); | 955 return parseSimpleTransformList(pos, end); |
| 956 } | 956 } |
| 957 | 957 |
| 958 PassRefPtrWillBeRawPtr<CSSValue> CSSParserFastPaths::maybeParseValue(CSSProperty
ID propertyID, const String& string, CSSParserMode parserMode) | 958 NullableCSSValue CSSParserFastPaths::maybeParseValue(CSSPropertyID propertyID, c
onst String& string, CSSParserMode parserMode) |
| 959 { | 959 { |
| 960 if (RefPtrWillBeRawPtr<CSSValue> length = parseSimpleLengthValue(propertyID,
string, parserMode)) | 960 if (NullableCSSValue length = parseSimpleLengthValue(propertyID, string, par
serMode)) |
| 961 return length.release(); | 961 return length; |
| 962 if (isColorPropertyID(propertyID)) | 962 if (isColorPropertyID(propertyID)) |
| 963 return parseColor(string, isQuirksModeBehavior(parserMode)); | 963 return parseColor(string, isQuirksModeBehavior(parserMode)); |
| 964 if (RefPtrWillBeRawPtr<CSSValue> keyword = parseKeywordValue(propertyID, str
ing)) | 964 if (NullableCSSValue keyword = parseKeywordValue(propertyID, string)) |
| 965 return keyword.release(); | 965 return keyword; |
| 966 if (RefPtrWillBeRawPtr<CSSValue> transform = parseSimpleTransform(propertyID
, string)) | 966 if (NullableCSSValue transform = parseSimpleTransform(propertyID, string)) |
| 967 return transform.release(); | 967 return transform; |
| 968 return nullptr; | 968 return nullptr; |
| 969 } | 969 } |
| 970 | 970 |
| 971 } // namespace blink | 971 } // namespace blink |
| OLD | NEW |