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" |
11 #include "core/css/parser/CSSParserString.h" | |
12 #include "core/css/parser/CSSPropertyParser.h" | 11 #include "core/css/parser/CSSPropertyParser.h" |
13 #include "core/html/parser/HTMLParserIdioms.h" | 12 #include "core/html/parser/HTMLParserIdioms.h" |
14 #include "platform/RuntimeEnabledFeatures.h" | 13 #include "platform/RuntimeEnabledFeatures.h" |
15 | 14 |
16 namespace blink { | 15 namespace blink { |
17 | 16 |
18 static inline bool isSimpleLengthPropertyID(CSSPropertyID propertyId, bool& acce
ptsNegativeNumbers) | 17 static inline bool isSimpleLengthPropertyID(CSSPropertyID propertyId, bool& acce
ptsNegativeNumbers) |
19 { | 18 { |
20 switch (propertyId) { | 19 switch (propertyId) { |
21 case CSSPropertyFontSize: | 20 case CSSPropertyFontSize: |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 rgb = makeRGB(red, green, blue); | 432 rgb = makeRGB(red, green, blue); |
434 return true; | 433 return true; |
435 } | 434 } |
436 | 435 |
437 return false; | 436 return false; |
438 } | 437 } |
439 | 438 |
440 CSSValue* CSSParserFastPaths::parseColor(const String& string, CSSParserMode par
serMode) | 439 CSSValue* CSSParserFastPaths::parseColor(const String& string, CSSParserMode par
serMode) |
441 { | 440 { |
442 ASSERT(!string.isEmpty()); | 441 ASSERT(!string.isEmpty()); |
443 CSSParserString cssString; | 442 CSSValueID valueID = cssValueKeywordID(string); |
444 cssString.init(string); | |
445 CSSValueID valueID = cssValueKeywordID(cssString); | |
446 if (CSSPropertyParser::isColorKeyword(valueID)) { | 443 if (CSSPropertyParser::isColorKeyword(valueID)) { |
447 if (!isValueAllowedInMode(valueID, parserMode)) | 444 if (!isValueAllowedInMode(valueID, parserMode)) |
448 return nullptr; | 445 return nullptr; |
449 return cssValuePool().createIdentifierValue(valueID); | 446 return cssValuePool().createIdentifierValue(valueID); |
450 } | 447 } |
451 | 448 |
452 RGBA32 color; | 449 RGBA32 color; |
453 bool quirksMode = isQuirksModeBehavior(parserMode); | 450 bool quirksMode = isQuirksModeBehavior(parserMode); |
454 | 451 |
455 // Fast path for hex colors and rgb()/rgba() colors | 452 // Fast path for hex colors and rgb()/rgba() colors |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 | 836 |
840 // Parse initial/inherit shorthands using the CSSPropertyParser. | 837 // Parse initial/inherit shorthands using the CSSPropertyParser. |
841 if (shorthandForProperty(propertyId).length()) | 838 if (shorthandForProperty(propertyId).length()) |
842 return nullptr; | 839 return nullptr; |
843 | 840 |
844 // Descriptors do not support css wide keywords. | 841 // Descriptors do not support css wide keywords. |
845 if (CSSPropertyMetadata::isDescriptorOnly(propertyId)) | 842 if (CSSPropertyMetadata::isDescriptorOnly(propertyId)) |
846 return nullptr; | 843 return nullptr; |
847 } | 844 } |
848 | 845 |
849 CSSParserString cssString; | 846 CSSValueID valueID = cssValueKeywordID(string); |
850 cssString.init(string); | |
851 CSSValueID valueID = cssValueKeywordID(cssString); | |
852 | 847 |
853 if (!valueID) | 848 if (!valueID) |
854 return nullptr; | 849 return nullptr; |
855 | 850 |
856 if (valueID == CSSValueInherit) | 851 if (valueID == CSSValueInherit) |
857 return cssValuePool().createInheritedValue(); | 852 return cssValuePool().createInheritedValue(); |
858 if (valueID == CSSValueInitial) | 853 if (valueID == CSSValueInitial) |
859 return cssValuePool().createExplicitInitialValue(); | 854 return cssValuePool().createExplicitInitialValue(); |
860 if (CSSParserFastPaths::isValidKeywordPropertyAndValue(propertyId, valueID,
parserMode)) | 855 if (CSSParserFastPaths::isValidKeywordPropertyAndValue(propertyId, valueID,
parserMode)) |
861 return cssValuePool().createIdentifierValue(valueID); | 856 return cssValuePool().createIdentifierValue(valueID); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 if (isColorPropertyID(propertyID)) | 1070 if (isColorPropertyID(propertyID)) |
1076 return parseColor(string, parserMode); | 1071 return parseColor(string, parserMode); |
1077 if (CSSValue* keyword = parseKeywordValue(propertyID, string, parserMode)) | 1072 if (CSSValue* keyword = parseKeywordValue(propertyID, string, parserMode)) |
1078 return keyword; | 1073 return keyword; |
1079 if (CSSValue* transform = parseSimpleTransform(propertyID, string)) | 1074 if (CSSValue* transform = parseSimpleTransform(propertyID, string)) |
1080 return transform; | 1075 return transform; |
1081 return nullptr; | 1076 return nullptr; |
1082 } | 1077 } |
1083 | 1078 |
1084 } // namespace blink | 1079 } // namespace blink |
OLD | NEW |