| 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 return false; | 421 return false; |
| 422 if (current != end) | 422 if (current != end) |
| 423 return false; | 423 return false; |
| 424 rgb = makeRGB(red, green, blue); | 424 rgb = makeRGB(red, green, blue); |
| 425 return true; | 425 return true; |
| 426 } | 426 } |
| 427 | 427 |
| 428 return false; | 428 return false; |
| 429 } | 429 } |
| 430 | 430 |
| 431 PassRefPtrWillBeRawPtr<CSSValue> CSSParserFastPaths::parseColor(const String& st
ring, bool quirksMode) | 431 NullableCSSValue CSSParserFastPaths::parseColor(const String& string, bool quirk
sMode) |
| 432 { | 432 { |
| 433 ASSERT(!string.isEmpty()); | 433 ASSERT(!string.isEmpty()); |
| 434 CSSParserString cssString; | 434 CSSParserString cssString; |
| 435 cssString.init(string); | 435 cssString.init(string); |
| 436 CSSValueID valueID = cssValueKeywordID(cssString); | 436 CSSValueID valueID = cssValueKeywordID(cssString); |
| 437 if (valueID == CSSValueWebkitText || valueID == CSSValueCurrentcolor | 437 if (valueID == CSSValueWebkitText || valueID == CSSValueCurrentcolor |
| 438 || (valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID
== CSSValueMenu | 438 || (valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID
== CSSValueMenu |
| 439 || (quirksMode && valueID >= CSSValueWebkitFocusRingColor && valueID < C
SSValueWebkitText)) | 439 || (quirksMode && valueID >= CSSValueWebkitFocusRingColor && valueID < C
SSValueWebkitText)) |
| 440 return cssValuePool().createIdentifierValue(valueID); | 440 return cssValuePool().createIdentifierValue(valueID); |
| 441 | 441 |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 case CSSPropertyScrollSnapType: | 742 case CSSPropertyScrollSnapType: |
| 743 return true; | 743 return true; |
| 744 case CSSPropertyAlignItems: | 744 case CSSPropertyAlignItems: |
| 745 case CSSPropertyAlignSelf: | 745 case CSSPropertyAlignSelf: |
| 746 return !RuntimeEnabledFeatures::cssGridLayoutEnabled(); | 746 return !RuntimeEnabledFeatures::cssGridLayoutEnabled(); |
| 747 default: | 747 default: |
| 748 return false; | 748 return false; |
| 749 } | 749 } |
| 750 } | 750 } |
| 751 | 751 |
| 752 static PassRefPtrWillBeRawPtr<CSSValue> parseKeywordValue(CSSPropertyID property
Id, const String& string) | 752 static NullableCSSValue parseKeywordValue(CSSPropertyID propertyId, const String
& string) |
| 753 { | 753 { |
| 754 ASSERT(!string.isEmpty()); | 754 ASSERT(!string.isEmpty()); |
| 755 | 755 |
| 756 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) { | 756 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) { |
| 757 // All properties accept the values of "initial" and "inherit". | 757 // All properties accept the values of "initial" and "inherit". |
| 758 String lowerCaseString = string.lower(); | 758 String lowerCaseString = string.lower(); |
| 759 if (lowerCaseString != "initial" && lowerCaseString != "inherit") | 759 if (lowerCaseString != "initial" && lowerCaseString != "inherit") |
| 760 return nullptr; | 760 return nullptr; |
| 761 | 761 |
| 762 // Parse initial/inherit shorthands using the CSSPropertyParser. | 762 // Parse initial/inherit shorthands using the CSSPropertyParser. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 transformList = CSSValueList::createSpaceSeparated(); | 919 transformList = CSSValueList::createSpaceSeparated(); |
| 920 transformList->append(transformValue.release()); | 920 transformList->append(transformValue.release()); |
| 921 if (pos < end) { | 921 if (pos < end) { |
| 922 if (isCSSSpace(*pos)) | 922 if (isCSSSpace(*pos)) |
| 923 return nullptr; | 923 return nullptr; |
| 924 } | 924 } |
| 925 } | 925 } |
| 926 return transformList.release(); | 926 return transformList.release(); |
| 927 } | 927 } |
| 928 | 928 |
| 929 static PassRefPtrWillBeRawPtr<CSSValue> parseSimpleTransform(CSSPropertyID prope
rtyID, const String& string) | 929 static NullableCSSValue parseSimpleTransform(CSSPropertyID propertyID, const Str
ing& string) |
| 930 { | 930 { |
| 931 ASSERT(!string.isEmpty()); | 931 ASSERT(!string.isEmpty()); |
| 932 | 932 |
| 933 if (propertyID != CSSPropertyTransform) | 933 if (propertyID != CSSPropertyTransform) |
| 934 return nullptr; | 934 return nullptr; |
| 935 if (string.is8Bit()) { | 935 if (string.is8Bit()) { |
| 936 const LChar* pos = string.characters8(); | 936 const LChar* pos = string.characters8(); |
| 937 const LChar* end = pos + string.length(); | 937 const LChar* end = pos + string.length(); |
| 938 return parseSimpleTransformList(pos, end); | 938 return parseSimpleTransformList(pos, end); |
| 939 } | 939 } |
| 940 const UChar* pos = string.characters16(); | 940 const UChar* pos = string.characters16(); |
| 941 const UChar* end = pos + string.length(); | 941 const UChar* end = pos + string.length(); |
| 942 return parseSimpleTransformList(pos, end); | 942 return parseSimpleTransformList(pos, end); |
| 943 } | 943 } |
| 944 | 944 |
| 945 PassRefPtrWillBeRawPtr<CSSValue> CSSParserFastPaths::maybeParseValue(CSSProperty
ID propertyID, const String& string, CSSParserMode parserMode) | 945 NullableCSSValue CSSParserFastPaths::maybeParseValue(CSSPropertyID propertyID, c
onst String& string, CSSParserMode parserMode) |
| 946 { | 946 { |
| 947 if (RefPtrWillBeRawPtr<CSSValue> length = parseSimpleLengthValue(propertyID,
string, parserMode)) | 947 if (NullableCSSValue length = parseSimpleLengthValue(propertyID, string, par
serMode)) |
| 948 return length.release(); | 948 return length; |
| 949 if (isColorPropertyID(propertyID)) | 949 if (isColorPropertyID(propertyID)) |
| 950 return parseColor(string, isQuirksModeBehavior(parserMode)); | 950 return parseColor(string, isQuirksModeBehavior(parserMode)); |
| 951 if (RefPtrWillBeRawPtr<CSSValue> keyword = parseKeywordValue(propertyID, str
ing)) | 951 if (NullableCSSValue keyword = parseKeywordValue(propertyID, string)) |
| 952 return keyword.release(); | 952 return keyword; |
| 953 if (RefPtrWillBeRawPtr<CSSValue> transform = parseSimpleTransform(propertyID
, string)) | 953 if (NullableCSSValue transform = parseSimpleTransform(propertyID, string)) |
| 954 return transform.release(); | 954 return transform; |
| 955 return nullptr; | 955 return nullptr; |
| 956 } | 956 } |
| 957 | 957 |
| 958 } // namespace blink | 958 } // namespace blink |
| OLD | NEW |