| 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 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 bool parseTransformRotateArguments(CharType*& pos, CharType* end, CSSFunc
tionValue* transformValue) |
| 904 { |
| 905 static const int kDegLength = 3; |
| 906 |
| 907 size_t delimiter = WTF::find(pos, end - pos, ')'); |
| 908 if (delimiter == kNotFound) |
| 909 return false; |
| 910 CharType* degreeStart = pos + delimiter - kDegLength; |
| 911 bool isDegree = degreeStart > pos // require at least one digit. |
| 912 && toASCIILower(degreeStart[0]) == 'd' |
| 913 && toASCIILower(degreeStart[1]) == 'e' |
| 914 && toASCIILower(degreeStart[2]) == 'g'; |
| 915 if (!isDegree) |
| 916 return false; |
| 917 unsigned argumentLength = static_cast<unsigned>(delimiter - kDegLength); |
| 918 bool ok; |
| 919 double number = charactersToDouble(pos, argumentLength, &ok); |
| 920 if (!ok) |
| 921 return false; |
| 922 transformValue->append(cssValuePool().createValue(number, CSSPrimitiveValue:
:UnitType::Degrees)); |
| 923 pos += delimiter + 1; |
| 924 return true; |
| 925 } |
| 926 |
| 927 template <typename CharType> |
| 903 static CSSFunctionValue* parseSimpleTransformValue(CharType*& pos, CharType* end
) | 928 static CSSFunctionValue* parseSimpleTransformValue(CharType*& pos, CharType* end
) |
| 904 { | 929 { |
| 905 static const int shortestValidTransformStringLength = 12; | 930 static const int shortestValidTransformStringLength = 12; |
| 906 | 931 |
| 907 if (end - pos < shortestValidTransformStringLength) | 932 if (end - pos < shortestValidTransformStringLength) |
| 908 return nullptr; | 933 return nullptr; |
| 909 | 934 |
| 910 const bool isTranslate = toASCIILower(pos[0]) == 't' | 935 const bool isTranslate = toASCIILower(pos[0]) == 't' |
| 911 && toASCIILower(pos[1]) == 'r' | 936 && toASCIILower(pos[1]) == 'r' |
| 912 && toASCIILower(pos[2]) == 'a' | 937 && toASCIILower(pos[2]) == 'a' |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 && pos[7] == '('; | 999 && pos[7] == '('; |
| 975 | 1000 |
| 976 if (isScale3d) { | 1001 if (isScale3d) { |
| 977 pos += 8; | 1002 pos += 8; |
| 978 CSSFunctionValue* transformValue = CSSFunctionValue::create(CSSValueScal
e3d); | 1003 CSSFunctionValue* transformValue = CSSFunctionValue::create(CSSValueScal
e3d); |
| 979 if (!parseTransformNumberArguments(pos, end, 3, transformValue)) | 1004 if (!parseTransformNumberArguments(pos, end, 3, transformValue)) |
| 980 return nullptr; | 1005 return nullptr; |
| 981 return transformValue; | 1006 return transformValue; |
| 982 } | 1007 } |
| 983 | 1008 |
| 1009 const bool isRotate = toASCIILower(pos[0]) == 'r' |
| 1010 && toASCIILower(pos[1]) == 'o' |
| 1011 && toASCIILower(pos[2]) == 't' |
| 1012 && toASCIILower(pos[3]) == 'a' |
| 1013 && toASCIILower(pos[4]) == 't' |
| 1014 && toASCIILower(pos[5]) == 'e'; |
| 1015 |
| 1016 if (isRotate) { |
| 1017 CSSValueID transformType; |
| 1018 unsigned argumentStart = 8; |
| 1019 CharType c6 = toASCIILower(pos[6]); |
| 1020 if (c6 == 'x' && pos[7] == '(') { |
| 1021 transformType = CSSValueRotateX; |
| 1022 } else if (c6 == 'y' && pos[7] == '(') { |
| 1023 transformType = CSSValueRotateY; |
| 1024 } else if (c6 == 'z' && pos[7] == '(') { |
| 1025 transformType = CSSValueRotateZ; |
| 1026 } else if (c6 == '(') { |
| 1027 transformType = CSSValueRotate; |
| 1028 argumentStart = 7; |
| 1029 } else { |
| 1030 return nullptr; |
| 1031 } |
| 1032 pos += argumentStart; |
| 1033 CSSFunctionValue* transformValue = CSSFunctionValue::create(transformTyp
e); |
| 1034 if (!parseTransformRotateArguments(pos, end, transformValue)) |
| 1035 return nullptr; |
| 1036 return transformValue; |
| 1037 } |
| 1038 |
| 984 return nullptr; | 1039 return nullptr; |
| 985 } | 1040 } |
| 986 | 1041 |
| 987 template <typename CharType> | 1042 template <typename CharType> |
| 988 static CSSValueList* parseSimpleTransformList(CharType*& pos, CharType* end) | 1043 static CSSValueList* parseSimpleTransformList(CharType*& pos, CharType* end) |
| 989 { | 1044 { |
| 990 CSSValueList* transformList = nullptr; | 1045 CSSValueList* transformList = nullptr; |
| 991 while (pos < end) { | 1046 while (pos < end) { |
| 992 while (pos < end && isCSSSpace(*pos)) | 1047 while (pos < end && isCSSSpace(*pos)) |
| 993 ++pos; | 1048 ++pos; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 if (isColorPropertyID(propertyID)) | 1083 if (isColorPropertyID(propertyID)) |
| 1029 return parseColor(string, parserMode); | 1084 return parseColor(string, parserMode); |
| 1030 if (CSSValue* keyword = parseKeywordValue(propertyID, string)) | 1085 if (CSSValue* keyword = parseKeywordValue(propertyID, string)) |
| 1031 return keyword; | 1086 return keyword; |
| 1032 if (CSSValue* transform = parseSimpleTransform(propertyID, string)) | 1087 if (CSSValue* transform = parseSimpleTransform(propertyID, string)) |
| 1033 return transform; | 1088 return transform; |
| 1034 return nullptr; | 1089 return nullptr; |
| 1035 } | 1090 } |
| 1036 | 1091 |
| 1037 } // namespace blink | 1092 } // namespace blink |
| OLD | NEW |