Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSParserFastPaths.cpp

Issue 1858753003: Remove RawPtr from core/css (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 RawPtr<CSSValue> parseSimpleLengthValue(CSSPropertyID propertyId, const S tring& string, CSSParserMode cssParserMode) 89 static CSSValue* parseSimpleLengthValue(CSSPropertyID propertyId, const String& 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
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 RawPtr<CSSValue> CSSParserFastPaths::parseColor(const String& string, CSSParserM ode parserMode) 440 CSSValue* CSSParserFastPaths::parseColor(const String& string, CSSParserMode par serMode)
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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 case CSSPropertyJustifyContent: 821 case CSSPropertyJustifyContent:
822 case CSSPropertyAlignContent: 822 case CSSPropertyAlignContent:
823 case CSSPropertyAlignItems: 823 case CSSPropertyAlignItems:
824 case CSSPropertyAlignSelf: 824 case CSSPropertyAlignSelf:
825 return !RuntimeEnabledFeatures::cssGridLayoutEnabled(); 825 return !RuntimeEnabledFeatures::cssGridLayoutEnabled();
826 default: 826 default:
827 return false; 827 return false;
828 } 828 }
829 } 829 }
830 830
831 static RawPtr<CSSValue> parseKeywordValue(CSSPropertyID propertyId, const String & string) 831 static CSSValue* parseKeywordValue(CSSPropertyID propertyId, const String& strin g)
832 { 832 {
833 ASSERT(!string.isEmpty()); 833 ASSERT(!string.isEmpty());
834 834
835 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) { 835 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) {
836 // All properties accept the values of "initial" and "inherit". 836 // All properties accept the values of "initial" and "inherit".
837 String lowerCaseString = string.lower(); 837 String lowerCaseString = string.lower();
838 if (lowerCaseString != "initial" && lowerCaseString != "inherit") 838 if (lowerCaseString != "initial" && lowerCaseString != "inherit")
839 return nullptr; 839 return nullptr;
840 840
841 // Parse initial/inherit shorthands using the CSSPropertyParser. 841 // Parse initial/inherit shorthands using the CSSPropertyParser.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 if (!ok) 893 if (!ok)
894 return false; 894 return false;
895 transformValue->append(cssValuePool().createValue(number, CSSPrimitiveVa lue::UnitType::Number)); 895 transformValue->append(cssValuePool().createValue(number, CSSPrimitiveVa lue::UnitType::Number));
896 pos += argumentLength + 1; 896 pos += argumentLength + 1;
897 --expectedCount; 897 --expectedCount;
898 } 898 }
899 return true; 899 return true;
900 } 900 }
901 901
902 template <typename CharType> 902 template <typename CharType>
903 static RawPtr<CSSFunctionValue> parseSimpleTransformValue(CharType*& pos, CharTy pe* end) 903 static CSSFunctionValue* parseSimpleTransformValue(CharType*& pos, CharType* end )
904 { 904 {
905 static const int shortestValidTransformStringLength = 12; 905 static const int shortestValidTransformStringLength = 12;
906 906
907 if (end - pos < shortestValidTransformStringLength) 907 if (end - pos < shortestValidTransformStringLength)
908 return nullptr; 908 return nullptr;
909 909
910 const bool isTranslate = toASCIILower(pos[0]) == 't' 910 const bool isTranslate = toASCIILower(pos[0]) == 't'
911 && toASCIILower(pos[1]) == 'r' 911 && toASCIILower(pos[1]) == 'r'
912 && toASCIILower(pos[2]) == 'a' 912 && toASCIILower(pos[2]) == 'a'
913 && toASCIILower(pos[3]) == 'n' 913 && toASCIILower(pos[3]) == 'n'
(...skipping 19 matching lines...) Expand all
933 expectedArgumentCount = 2; 933 expectedArgumentCount = 2;
934 argumentStart = 10; 934 argumentStart = 10;
935 } else if (c9 == '3' && toASCIILower(pos[10]) == 'd' && pos[11] == '(') { 935 } else if (c9 == '3' && toASCIILower(pos[10]) == 'd' && pos[11] == '(') {
936 transformType = CSSValueTranslate3d; 936 transformType = CSSValueTranslate3d;
937 expectedArgumentCount = 3; 937 expectedArgumentCount = 3;
938 argumentStart = 12; 938 argumentStart = 12;
939 } else { 939 } else {
940 return nullptr; 940 return nullptr;
941 } 941 }
942 pos += argumentStart; 942 pos += argumentStart;
943 RawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::create(trans formType); 943 CSSFunctionValue* transformValue = CSSFunctionValue::create(transformTyp e);
944 if (!parseTransformTranslateArguments(pos, end, expectedArgumentCount, t ransformValue.get())) 944 if (!parseTransformTranslateArguments(pos, end, expectedArgumentCount, t ransformValue))
945 return nullptr; 945 return nullptr;
946 return transformValue.release(); 946 return transformValue;
947 } 947 }
948 948
949 const bool isMatrix3d = toASCIILower(pos[0]) == 'm' 949 const bool isMatrix3d = toASCIILower(pos[0]) == 'm'
950 && toASCIILower(pos[1]) == 'a' 950 && toASCIILower(pos[1]) == 'a'
951 && toASCIILower(pos[2]) == 't' 951 && toASCIILower(pos[2]) == 't'
952 && toASCIILower(pos[3]) == 'r' 952 && toASCIILower(pos[3]) == 'r'
953 && toASCIILower(pos[4]) == 'i' 953 && toASCIILower(pos[4]) == 'i'
954 && toASCIILower(pos[5]) == 'x' 954 && toASCIILower(pos[5]) == 'x'
955 && pos[6] == '3' 955 && pos[6] == '3'
956 && toASCIILower(pos[7]) == 'd' 956 && toASCIILower(pos[7]) == 'd'
957 && pos[8] == '('; 957 && pos[8] == '(';
958 958
959 if (isMatrix3d) { 959 if (isMatrix3d) {
960 pos += 9; 960 pos += 9;
961 RawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::create(CSSVa lueMatrix3d); 961 CSSFunctionValue* transformValue = CSSFunctionValue::create(CSSValueMatr ix3d);
962 if (!parseTransformNumberArguments(pos, end, 16, transformValue.get())) 962 if (!parseTransformNumberArguments(pos, end, 16, transformValue))
963 return nullptr; 963 return nullptr;
964 return transformValue.release(); 964 return transformValue;
965 } 965 }
966 966
967 const bool isScale3d = toASCIILower(pos[0]) == 's' 967 const bool isScale3d = toASCIILower(pos[0]) == 's'
968 && toASCIILower(pos[1]) == 'c' 968 && toASCIILower(pos[1]) == 'c'
969 && toASCIILower(pos[2]) == 'a' 969 && toASCIILower(pos[2]) == 'a'
970 && toASCIILower(pos[3]) == 'l' 970 && toASCIILower(pos[3]) == 'l'
971 && toASCIILower(pos[4]) == 'e' 971 && toASCIILower(pos[4]) == 'e'
972 && pos[5] == '3' 972 && pos[5] == '3'
973 && toASCIILower(pos[6]) == 'd' 973 && toASCIILower(pos[6]) == 'd'
974 && pos[7] == '('; 974 && pos[7] == '(';
975 975
976 if (isScale3d) { 976 if (isScale3d) {
977 pos += 8; 977 pos += 8;
978 RawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::create(CSSVa lueScale3d); 978 CSSFunctionValue* transformValue = CSSFunctionValue::create(CSSValueScal e3d);
979 if (!parseTransformNumberArguments(pos, end, 3, transformValue.get())) 979 if (!parseTransformNumberArguments(pos, end, 3, transformValue))
980 return nullptr; 980 return nullptr;
981 return transformValue.release(); 981 return transformValue;
982 } 982 }
983 983
984 return nullptr; 984 return nullptr;
985 } 985 }
986 986
987 template <typename CharType> 987 template <typename CharType>
988 static RawPtr<CSSValueList> parseSimpleTransformList(CharType*& pos, CharType* e nd) 988 static CSSValueList* parseSimpleTransformList(CharType*& pos, CharType* end)
989 { 989 {
990 RawPtr<CSSValueList> transformList = nullptr; 990 CSSValueList* transformList = nullptr;
991 while (pos < end) { 991 while (pos < end) {
992 while (pos < end && isCSSSpace(*pos)) 992 while (pos < end && isCSSSpace(*pos))
993 ++pos; 993 ++pos;
994 RawPtr<CSSFunctionValue> transformValue = parseSimpleTransformValue(pos, end); 994 CSSFunctionValue* transformValue = parseSimpleTransformValue(pos, end);
995 if (!transformValue) 995 if (!transformValue)
996 return nullptr; 996 return nullptr;
997 if (!transformList) 997 if (!transformList)
998 transformList = CSSValueList::createSpaceSeparated(); 998 transformList = CSSValueList::createSpaceSeparated();
999 transformList->append(transformValue.release()); 999 transformList->append(transformValue);
1000 if (pos < end) { 1000 if (pos < end) {
1001 if (isCSSSpace(*pos)) 1001 if (isCSSSpace(*pos))
1002 return nullptr; 1002 return nullptr;
1003 } 1003 }
1004 } 1004 }
1005 return transformList.release(); 1005 return transformList;
1006 } 1006 }
1007 1007
1008 static RawPtr<CSSValue> parseSimpleTransform(CSSPropertyID propertyID, const Str ing& string) 1008 static CSSValue* parseSimpleTransform(CSSPropertyID propertyID, const String& st ring)
1009 { 1009 {
1010 ASSERT(!string.isEmpty()); 1010 ASSERT(!string.isEmpty());
1011 1011
1012 if (propertyID != CSSPropertyTransform) 1012 if (propertyID != CSSPropertyTransform)
1013 return nullptr; 1013 return nullptr;
1014 if (string.is8Bit()) { 1014 if (string.is8Bit()) {
1015 const LChar* pos = string.characters8(); 1015 const LChar* pos = string.characters8();
1016 const LChar* end = pos + string.length(); 1016 const LChar* end = pos + string.length();
1017 return parseSimpleTransformList(pos, end); 1017 return parseSimpleTransformList(pos, end);
1018 } 1018 }
1019 const UChar* pos = string.characters16(); 1019 const UChar* pos = string.characters16();
1020 const UChar* end = pos + string.length(); 1020 const UChar* end = pos + string.length();
1021 return parseSimpleTransformList(pos, end); 1021 return parseSimpleTransformList(pos, end);
1022 } 1022 }
1023 1023
1024 RawPtr<CSSValue> CSSParserFastPaths::maybeParseValue(CSSPropertyID propertyID, c onst String& string, CSSParserMode parserMode) 1024 CSSValue* CSSParserFastPaths::maybeParseValue(CSSPropertyID propertyID, const St ring& string, CSSParserMode parserMode)
1025 { 1025 {
1026 if (RawPtr<CSSValue> length = parseSimpleLengthValue(propertyID, string, par serMode)) 1026 if (CSSValue* length = parseSimpleLengthValue(propertyID, string, parserMode ))
1027 return length.release(); 1027 return length;
1028 if (isColorPropertyID(propertyID)) 1028 if (isColorPropertyID(propertyID))
1029 return parseColor(string, parserMode); 1029 return parseColor(string, parserMode);
1030 if (RawPtr<CSSValue> keyword = parseKeywordValue(propertyID, string)) 1030 if (CSSValue* keyword = parseKeywordValue(propertyID, string))
1031 return keyword.release(); 1031 return keyword;
1032 if (RawPtr<CSSValue> transform = parseSimpleTransform(propertyID, string)) 1032 if (CSSValue* transform = parseSimpleTransform(propertyID, string))
1033 return transform.release(); 1033 return transform;
1034 return nullptr; 1034 return nullptr;
1035 } 1035 }
1036 1036
1037 } // namespace blink 1037 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698