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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 // We rely on charactersToDouble for validation as well. The function | 79 // We rely on charactersToDouble for validation as well. The function |
80 // will set "ok" to "false" if the entire passed-in character range does | 80 // will set "ok" to "false" if the entire passed-in character range does |
81 // not represent a double. | 81 // not represent a double. |
82 bool ok; | 82 bool ok; |
83 number = charactersToDouble(characters, length, &ok); | 83 number = charactersToDouble(characters, length, &ok); |
84 return ok; | 84 return ok; |
85 } | 85 } |
86 | 86 |
87 static PassRefPtrWillBeRawPtr<CSSValue> parseSimpleLengthValue(CSSPropertyID pro
pertyId, const String& string, CSSParserMode cssParserMode) | 87 static NullableCSSValue parseSimpleLengthValue(CSSPropertyID propertyId, const S
tring& string, CSSParserMode cssParserMode) |
88 { | 88 { |
89 ASSERT(!string.isEmpty()); | 89 ASSERT(!string.isEmpty()); |
90 bool acceptsNegativeNumbers = false; | 90 bool acceptsNegativeNumbers = false; |
91 | 91 |
92 // In @viewport, width and height are shorthands, not simple length values. | 92 // In @viewport, width and height are shorthands, not simple length values. |
93 if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthProp
ertyID(propertyId, acceptsNegativeNumbers)) | 93 if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthProp
ertyID(propertyId, acceptsNegativeNumbers)) |
94 return nullptr; | 94 return nullptr; |
95 | 95 |
96 unsigned length = string.length(); | 96 unsigned length = string.length(); |
97 double number; | 97 double number; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 case CSSPropertyWebkitTextEmphasisColor: | 135 case CSSPropertyWebkitTextEmphasisColor: |
136 case CSSPropertyWebkitTextFillColor: | 136 case CSSPropertyWebkitTextFillColor: |
137 case CSSPropertyWebkitTextStrokeColor: | 137 case CSSPropertyWebkitTextStrokeColor: |
138 case CSSPropertyTextDecorationColor: | 138 case CSSPropertyTextDecorationColor: |
139 return true; | 139 return true; |
140 default: | 140 default: |
141 return false; | 141 return false; |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 static PassRefPtrWillBeRawPtr<CSSValue> parseColorValue(CSSPropertyID propertyId
, const String& string, CSSParserMode cssParserMode) | 145 static NullableCSSValue parseColorValue(CSSPropertyID propertyId, const String&
string, CSSParserMode cssParserMode) |
146 { | 146 { |
147 ASSERT(!string.isEmpty()); | 147 ASSERT(!string.isEmpty()); |
148 bool quirksMode = isQuirksModeBehavior(cssParserMode); | 148 bool quirksMode = isQuirksModeBehavior(cssParserMode); |
149 if (!isColorPropertyID(propertyId)) | 149 if (!isColorPropertyID(propertyId)) |
150 return nullptr; | 150 return nullptr; |
151 CSSParserString cssString; | 151 CSSParserString cssString; |
152 cssString.init(string); | 152 cssString.init(string); |
153 CSSValueID valueID = cssValueKeywordID(cssString); | 153 CSSValueID valueID = cssValueKeywordID(cssString); |
154 bool validPrimitive = false; | 154 bool validPrimitive = false; |
155 if (valueID == CSSValueWebkitText) { | 155 if (valueID == CSSValueWebkitText) { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 case CSSPropertyWordWrap: | 452 case CSSPropertyWordWrap: |
453 return true; | 453 return true; |
454 case CSSPropertyAlignItems: | 454 case CSSPropertyAlignItems: |
455 case CSSPropertyAlignSelf: | 455 case CSSPropertyAlignSelf: |
456 return !RuntimeEnabledFeatures::cssGridLayoutEnabled(); | 456 return !RuntimeEnabledFeatures::cssGridLayoutEnabled(); |
457 default: | 457 default: |
458 return false; | 458 return false; |
459 } | 459 } |
460 } | 460 } |
461 | 461 |
462 static PassRefPtrWillBeRawPtr<CSSValue> parseKeywordValue(CSSPropertyID property
Id, const String& string) | 462 static NullableCSSValue parseKeywordValue(CSSPropertyID propertyId, const String
& string) |
463 { | 463 { |
464 ASSERT(!string.isEmpty()); | 464 ASSERT(!string.isEmpty()); |
465 | 465 |
466 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) { | 466 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) { |
467 // All properties accept the values of "initial" and "inherit". | 467 // All properties accept the values of "initial" and "inherit". |
468 String lowerCaseString = string.lower(); | 468 String lowerCaseString = string.lower(); |
469 if (lowerCaseString != "initial" && lowerCaseString != "inherit") | 469 if (lowerCaseString != "initial" && lowerCaseString != "inherit") |
470 return nullptr; | 470 return nullptr; |
471 | 471 |
472 // Parse initial/inherit shorthands using the CSSPropertyParser. | 472 // Parse initial/inherit shorthands using the CSSPropertyParser. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 transformList = CSSValueList::createSpaceSeparated(); | 629 transformList = CSSValueList::createSpaceSeparated(); |
630 transformList->append(transformValue.release()); | 630 transformList->append(transformValue.release()); |
631 if (pos < end) { | 631 if (pos < end) { |
632 if (isCSSSpace(*pos)) | 632 if (isCSSSpace(*pos)) |
633 return nullptr; | 633 return nullptr; |
634 } | 634 } |
635 } | 635 } |
636 return transformList.release(); | 636 return transformList.release(); |
637 } | 637 } |
638 | 638 |
639 static PassRefPtrWillBeRawPtr<CSSValue> parseSimpleTransform(CSSPropertyID prope
rtyID, const String& string) | 639 static NullableCSSValue parseSimpleTransform(CSSPropertyID propertyID, const Str
ing& string) |
640 { | 640 { |
641 ASSERT(!string.isEmpty()); | 641 ASSERT(!string.isEmpty()); |
642 | 642 |
643 if (propertyID != CSSPropertyTransform) | 643 if (propertyID != CSSPropertyTransform) |
644 return nullptr; | 644 return nullptr; |
645 if (string.is8Bit()) { | 645 if (string.is8Bit()) { |
646 const LChar* pos = string.characters8(); | 646 const LChar* pos = string.characters8(); |
647 const LChar* end = pos + string.length(); | 647 const LChar* end = pos + string.length(); |
648 return parseSimpleTransformList(pos, end); | 648 return parseSimpleTransformList(pos, end); |
649 } | 649 } |
650 const UChar* pos = string.characters16(); | 650 const UChar* pos = string.characters16(); |
651 const UChar* end = pos + string.length(); | 651 const UChar* end = pos + string.length(); |
652 return parseSimpleTransformList(pos, end); | 652 return parseSimpleTransformList(pos, end); |
653 } | 653 } |
654 | 654 |
655 PassRefPtrWillBeRawPtr<CSSValue> CSSParserFastPaths::maybeParseValue(CSSProperty
ID propertyID, const String& string, CSSParserMode parserMode) | 655 NullableCSSValue CSSParserFastPaths::maybeParseValue(CSSPropertyID propertyID, c
onst String& string, CSSParserMode parserMode) |
656 { | 656 { |
657 if (RefPtrWillBeRawPtr<CSSValue> length = parseSimpleLengthValue(propertyID,
string, parserMode)) | 657 if (NullableCSSValue length = parseSimpleLengthValue(propertyID, string, par
serMode)) |
658 return length.release(); | 658 return *length; |
659 if (RefPtrWillBeRawPtr<CSSValue> color = parseColorValue(propertyID, string,
parserMode)) | 659 if (NullableCSSValue color = parseColorValue(propertyID, string, parserMode)
) |
660 return color.release(); | 660 return *color; |
661 if (RefPtrWillBeRawPtr<CSSValue> keyword = parseKeywordValue(propertyID, str
ing)) | 661 if (NullableCSSValue keyword = parseKeywordValue(propertyID, string)) |
662 return keyword.release(); | 662 return *keyword; |
663 if (RefPtrWillBeRawPtr<CSSValue> transform = parseSimpleTransform(propertyID
, string)) | 663 if (NullableCSSValue transform = parseSimpleTransform(propertyID, string)) |
664 return transform.release(); | 664 return *transform; |
665 return nullptr; | 665 return nullptr; |
666 } | 666 } |
667 | 667 |
668 } // namespace blink | 668 } // namespace blink |
OLD | NEW |