| 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 "core/css/parser/CSSParserFastPaths.h" | 5 #include "core/css/parser/CSSParserFastPaths.h" |
| 6 | 6 |
| 7 #include "core/StylePropertyShorthand.h" | 7 #include "core/StylePropertyShorthand.h" |
| 8 #include "core/css/CSSFunctionValue.h" | 8 #include "core/css/CSSFunctionValue.h" |
| 9 #include "core/css/CSSValuePool.h" | 9 #include "core/css/CSSValuePool.h" |
| 10 #include "core/css/parser/CSSParserIdioms.h" | 10 #include "core/css/parser/CSSParserIdioms.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 | 80 |
| 81 // We rely on charactersToDouble for validation as well. The function | 81 // We rely on charactersToDouble for validation as well. The function |
| 82 // will set "ok" to "false" if the entire passed-in character range does | 82 // will set "ok" to "false" if the entire passed-in character range does |
| 83 // not represent a double. | 83 // not represent a double. |
| 84 bool ok; | 84 bool ok; |
| 85 number = charactersToDouble(characters, length, &ok); | 85 number = charactersToDouble(characters, length, &ok); |
| 86 return ok && CSSPropertyParser::isValidNumericValue(number); | 86 return ok && CSSPropertyParser::isValidNumericValue(number); |
| 87 } | 87 } |
| 88 | 88 |
| 89 static PassRefPtrWillBeRawPtr<CSSValue> parseSimpleLengthValue(CSSPropertyID pro
pertyId, const String& string, CSSParserMode cssParserMode) | 89 static RawPtr<CSSValue> parseSimpleLengthValue(CSSPropertyID propertyId, const S
tring& string, CSSParserMode cssParserMode) |
| 90 { | 90 { |
| 91 ASSERT(!string.isEmpty()); | 91 ASSERT(!string.isEmpty()); |
| 92 bool acceptsNegativeNumbers = false; | 92 bool acceptsNegativeNumbers = false; |
| 93 | 93 |
| 94 // In @viewport, width and height are shorthands, not simple length values. | 94 // In @viewport, width and height are shorthands, not simple length values. |
| 95 if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthProp
ertyID(propertyId, acceptsNegativeNumbers)) | 95 if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthProp
ertyID(propertyId, acceptsNegativeNumbers)) |
| 96 return nullptr; | 96 return nullptr; |
| 97 | 97 |
| 98 unsigned length = string.length(); | 98 unsigned length = string.length(); |
| 99 double number; | 99 double number; |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 return false; | 430 return false; |
| 431 if (current != end) | 431 if (current != end) |
| 432 return false; | 432 return false; |
| 433 rgb = makeRGB(red, green, blue); | 433 rgb = makeRGB(red, green, blue); |
| 434 return true; | 434 return true; |
| 435 } | 435 } |
| 436 | 436 |
| 437 return false; | 437 return false; |
| 438 } | 438 } |
| 439 | 439 |
| 440 PassRefPtrWillBeRawPtr<CSSValue> CSSParserFastPaths::parseColor(const String& st
ring, CSSParserMode parserMode) | 440 RawPtr<CSSValue> CSSParserFastPaths::parseColor(const String& string, CSSParserM
ode parserMode) |
| 441 { | 441 { |
| 442 ASSERT(!string.isEmpty()); | 442 ASSERT(!string.isEmpty()); |
| 443 CSSParserString cssString; | 443 CSSParserString cssString; |
| 444 cssString.init(string); | 444 cssString.init(string); |
| 445 CSSValueID valueID = cssValueKeywordID(cssString); | 445 CSSValueID valueID = cssValueKeywordID(cssString); |
| 446 if (CSSPropertyParser::isColorKeyword(valueID)) { | 446 if (CSSPropertyParser::isColorKeyword(valueID)) { |
| 447 if (!isValueAllowedInMode(valueID, parserMode)) | 447 if (!isValueAllowedInMode(valueID, parserMode)) |
| 448 return nullptr; | 448 return nullptr; |
| 449 return cssValuePool().createIdentifierValue(valueID); | 449 return cssValuePool().createIdentifierValue(valueID); |
| 450 } | 450 } |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 case CSSPropertyJustifyContent: | 829 case CSSPropertyJustifyContent: |
| 830 case CSSPropertyAlignContent: | 830 case CSSPropertyAlignContent: |
| 831 case CSSPropertyAlignItems: | 831 case CSSPropertyAlignItems: |
| 832 case CSSPropertyAlignSelf: | 832 case CSSPropertyAlignSelf: |
| 833 return !RuntimeEnabledFeatures::cssGridLayoutEnabled(); | 833 return !RuntimeEnabledFeatures::cssGridLayoutEnabled(); |
| 834 default: | 834 default: |
| 835 return false; | 835 return false; |
| 836 } | 836 } |
| 837 } | 837 } |
| 838 | 838 |
| 839 static PassRefPtrWillBeRawPtr<CSSValue> parseKeywordValue(CSSPropertyID property
Id, const String& string) | 839 static RawPtr<CSSValue> parseKeywordValue(CSSPropertyID propertyId, const String
& string) |
| 840 { | 840 { |
| 841 ASSERT(!string.isEmpty()); | 841 ASSERT(!string.isEmpty()); |
| 842 | 842 |
| 843 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) { | 843 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) { |
| 844 // All properties accept the values of "initial" and "inherit". | 844 // All properties accept the values of "initial" and "inherit". |
| 845 String lowerCaseString = string.lower(); | 845 String lowerCaseString = string.lower(); |
| 846 if (lowerCaseString != "initial" && lowerCaseString != "inherit") | 846 if (lowerCaseString != "initial" && lowerCaseString != "inherit") |
| 847 return nullptr; | 847 return nullptr; |
| 848 | 848 |
| 849 // Parse initial/inherit shorthands using the CSSPropertyParser. | 849 // Parse initial/inherit shorthands using the CSSPropertyParser. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 if (!ok) | 901 if (!ok) |
| 902 return false; | 902 return false; |
| 903 transformValue->append(cssValuePool().createValue(number, CSSPrimitiveVa
lue::UnitType::Number)); | 903 transformValue->append(cssValuePool().createValue(number, CSSPrimitiveVa
lue::UnitType::Number)); |
| 904 pos += argumentLength + 1; | 904 pos += argumentLength + 1; |
| 905 --expectedCount; | 905 --expectedCount; |
| 906 } | 906 } |
| 907 return true; | 907 return true; |
| 908 } | 908 } |
| 909 | 909 |
| 910 template <typename CharType> | 910 template <typename CharType> |
| 911 static PassRefPtrWillBeRawPtr<CSSFunctionValue> parseSimpleTransformValue(CharTy
pe*& pos, CharType* end) | 911 static RawPtr<CSSFunctionValue> parseSimpleTransformValue(CharType*& pos, CharTy
pe* end) |
| 912 { | 912 { |
| 913 static const int shortestValidTransformStringLength = 12; | 913 static const int shortestValidTransformStringLength = 12; |
| 914 | 914 |
| 915 if (end - pos < shortestValidTransformStringLength) | 915 if (end - pos < shortestValidTransformStringLength) |
| 916 return nullptr; | 916 return nullptr; |
| 917 | 917 |
| 918 const bool isTranslate = toASCIILower(pos[0]) == 't' | 918 const bool isTranslate = toASCIILower(pos[0]) == 't' |
| 919 && toASCIILower(pos[1]) == 'r' | 919 && toASCIILower(pos[1]) == 'r' |
| 920 && toASCIILower(pos[2]) == 'a' | 920 && toASCIILower(pos[2]) == 'a' |
| 921 && toASCIILower(pos[3]) == 'n' | 921 && toASCIILower(pos[3]) == 'n' |
| (...skipping 19 matching lines...) Expand all Loading... |
| 941 expectedArgumentCount = 2; | 941 expectedArgumentCount = 2; |
| 942 argumentStart = 10; | 942 argumentStart = 10; |
| 943 } else if (c9 == '3' && toASCIILower(pos[10]) == 'd' && pos[11] == '(')
{ | 943 } else if (c9 == '3' && toASCIILower(pos[10]) == 'd' && pos[11] == '(')
{ |
| 944 transformType = CSSValueTranslate3d; | 944 transformType = CSSValueTranslate3d; |
| 945 expectedArgumentCount = 3; | 945 expectedArgumentCount = 3; |
| 946 argumentStart = 12; | 946 argumentStart = 12; |
| 947 } else { | 947 } else { |
| 948 return nullptr; | 948 return nullptr; |
| 949 } | 949 } |
| 950 pos += argumentStart; | 950 pos += argumentStart; |
| 951 RefPtrWillBeRawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::
create(transformType); | 951 RawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::create(trans
formType); |
| 952 if (!parseTransformTranslateArguments(pos, end, expectedArgumentCount, t
ransformValue.get())) | 952 if (!parseTransformTranslateArguments(pos, end, expectedArgumentCount, t
ransformValue.get())) |
| 953 return nullptr; | 953 return nullptr; |
| 954 return transformValue.release(); | 954 return transformValue.release(); |
| 955 } | 955 } |
| 956 | 956 |
| 957 const bool isMatrix3d = toASCIILower(pos[0]) == 'm' | 957 const bool isMatrix3d = toASCIILower(pos[0]) == 'm' |
| 958 && toASCIILower(pos[1]) == 'a' | 958 && toASCIILower(pos[1]) == 'a' |
| 959 && toASCIILower(pos[2]) == 't' | 959 && toASCIILower(pos[2]) == 't' |
| 960 && toASCIILower(pos[3]) == 'r' | 960 && toASCIILower(pos[3]) == 'r' |
| 961 && toASCIILower(pos[4]) == 'i' | 961 && toASCIILower(pos[4]) == 'i' |
| 962 && toASCIILower(pos[5]) == 'x' | 962 && toASCIILower(pos[5]) == 'x' |
| 963 && pos[6] == '3' | 963 && pos[6] == '3' |
| 964 && toASCIILower(pos[7]) == 'd' | 964 && toASCIILower(pos[7]) == 'd' |
| 965 && pos[8] == '('; | 965 && pos[8] == '('; |
| 966 | 966 |
| 967 if (isMatrix3d) { | 967 if (isMatrix3d) { |
| 968 pos += 9; | 968 pos += 9; |
| 969 RefPtrWillBeRawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::
create(CSSValueMatrix3d); | 969 RawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::create(CSSVa
lueMatrix3d); |
| 970 if (!parseTransformNumberArguments(pos, end, 16, transformValue.get())) | 970 if (!parseTransformNumberArguments(pos, end, 16, transformValue.get())) |
| 971 return nullptr; | 971 return nullptr; |
| 972 return transformValue.release(); | 972 return transformValue.release(); |
| 973 } | 973 } |
| 974 | 974 |
| 975 const bool isScale3d = toASCIILower(pos[0]) == 's' | 975 const bool isScale3d = toASCIILower(pos[0]) == 's' |
| 976 && toASCIILower(pos[1]) == 'c' | 976 && toASCIILower(pos[1]) == 'c' |
| 977 && toASCIILower(pos[2]) == 'a' | 977 && toASCIILower(pos[2]) == 'a' |
| 978 && toASCIILower(pos[3]) == 'l' | 978 && toASCIILower(pos[3]) == 'l' |
| 979 && toASCIILower(pos[4]) == 'e' | 979 && toASCIILower(pos[4]) == 'e' |
| 980 && pos[5] == '3' | 980 && pos[5] == '3' |
| 981 && toASCIILower(pos[6]) == 'd' | 981 && toASCIILower(pos[6]) == 'd' |
| 982 && pos[7] == '('; | 982 && pos[7] == '('; |
| 983 | 983 |
| 984 if (isScale3d) { | 984 if (isScale3d) { |
| 985 pos += 8; | 985 pos += 8; |
| 986 RefPtrWillBeRawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::
create(CSSValueScale3d); | 986 RawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::create(CSSVa
lueScale3d); |
| 987 if (!parseTransformNumberArguments(pos, end, 3, transformValue.get())) | 987 if (!parseTransformNumberArguments(pos, end, 3, transformValue.get())) |
| 988 return nullptr; | 988 return nullptr; |
| 989 return transformValue.release(); | 989 return transformValue.release(); |
| 990 } | 990 } |
| 991 | 991 |
| 992 return nullptr; | 992 return nullptr; |
| 993 } | 993 } |
| 994 | 994 |
| 995 template <typename CharType> | 995 template <typename CharType> |
| 996 static PassRefPtrWillBeRawPtr<CSSValueList> parseSimpleTransformList(CharType*&
pos, CharType* end) | 996 static RawPtr<CSSValueList> parseSimpleTransformList(CharType*& pos, CharType* e
nd) |
| 997 { | 997 { |
| 998 RefPtrWillBeRawPtr<CSSValueList> transformList = nullptr; | 998 RawPtr<CSSValueList> transformList = nullptr; |
| 999 while (pos < end) { | 999 while (pos < end) { |
| 1000 while (pos < end && isCSSSpace(*pos)) | 1000 while (pos < end && isCSSSpace(*pos)) |
| 1001 ++pos; | 1001 ++pos; |
| 1002 RefPtrWillBeRawPtr<CSSFunctionValue> transformValue = parseSimpleTransfo
rmValue(pos, end); | 1002 RawPtr<CSSFunctionValue> transformValue = parseSimpleTransformValue(pos,
end); |
| 1003 if (!transformValue) | 1003 if (!transformValue) |
| 1004 return nullptr; | 1004 return nullptr; |
| 1005 if (!transformList) | 1005 if (!transformList) |
| 1006 transformList = CSSValueList::createSpaceSeparated(); | 1006 transformList = CSSValueList::createSpaceSeparated(); |
| 1007 transformList->append(transformValue.release()); | 1007 transformList->append(transformValue.release()); |
| 1008 if (pos < end) { | 1008 if (pos < end) { |
| 1009 if (isCSSSpace(*pos)) | 1009 if (isCSSSpace(*pos)) |
| 1010 return nullptr; | 1010 return nullptr; |
| 1011 } | 1011 } |
| 1012 } | 1012 } |
| 1013 return transformList.release(); | 1013 return transformList.release(); |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 static PassRefPtrWillBeRawPtr<CSSValue> parseSimpleTransform(CSSPropertyID prope
rtyID, const String& string) | 1016 static RawPtr<CSSValue> parseSimpleTransform(CSSPropertyID propertyID, const Str
ing& string) |
| 1017 { | 1017 { |
| 1018 ASSERT(!string.isEmpty()); | 1018 ASSERT(!string.isEmpty()); |
| 1019 | 1019 |
| 1020 if (propertyID != CSSPropertyTransform) | 1020 if (propertyID != CSSPropertyTransform) |
| 1021 return nullptr; | 1021 return nullptr; |
| 1022 if (string.is8Bit()) { | 1022 if (string.is8Bit()) { |
| 1023 const LChar* pos = string.characters8(); | 1023 const LChar* pos = string.characters8(); |
| 1024 const LChar* end = pos + string.length(); | 1024 const LChar* end = pos + string.length(); |
| 1025 return parseSimpleTransformList(pos, end); | 1025 return parseSimpleTransformList(pos, end); |
| 1026 } | 1026 } |
| 1027 const UChar* pos = string.characters16(); | 1027 const UChar* pos = string.characters16(); |
| 1028 const UChar* end = pos + string.length(); | 1028 const UChar* end = pos + string.length(); |
| 1029 return parseSimpleTransformList(pos, end); | 1029 return parseSimpleTransformList(pos, end); |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 PassRefPtrWillBeRawPtr<CSSValue> CSSParserFastPaths::maybeParseValue(CSSProperty
ID propertyID, const String& string, CSSParserMode parserMode) | 1032 RawPtr<CSSValue> CSSParserFastPaths::maybeParseValue(CSSPropertyID propertyID, c
onst String& string, CSSParserMode parserMode) |
| 1033 { | 1033 { |
| 1034 if (RefPtrWillBeRawPtr<CSSValue> length = parseSimpleLengthValue(propertyID,
string, parserMode)) | 1034 if (RawPtr<CSSValue> length = parseSimpleLengthValue(propertyID, string, par
serMode)) |
| 1035 return length.release(); | 1035 return length.release(); |
| 1036 if (isColorPropertyID(propertyID)) | 1036 if (isColorPropertyID(propertyID)) |
| 1037 return parseColor(string, parserMode); | 1037 return parseColor(string, parserMode); |
| 1038 if (RefPtrWillBeRawPtr<CSSValue> keyword = parseKeywordValue(propertyID, str
ing)) | 1038 if (RawPtr<CSSValue> keyword = parseKeywordValue(propertyID, string)) |
| 1039 return keyword.release(); | 1039 return keyword.release(); |
| 1040 if (RefPtrWillBeRawPtr<CSSValue> transform = parseSimpleTransform(propertyID
, string)) | 1040 if (RawPtr<CSSValue> transform = parseSimpleTransform(propertyID, string)) |
| 1041 return transform.release(); | 1041 return transform.release(); |
| 1042 return nullptr; | 1042 return nullptr; |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 } // namespace blink | 1045 } // namespace blink |
| OLD | NEW |