| 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 419 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 RawPtr<CSSValue> CSSParserFastPaths::parseColor(const String& string, CSSParserM
ode parserMode) | 440 RawPtr<CSSValue> CSSParserFastPaths::parseColor(const String& string, CSSParserM
ode parserMode, CSSValuePool* cssValuePool) |
| 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 } |
| 451 | 451 |
| 452 RGBA32 color; | 452 RGBA32 color; |
| 453 bool quirksMode = isQuirksModeBehavior(parserMode); | 453 bool quirksMode = isQuirksModeBehavior(parserMode); |
| 454 | 454 |
| 455 // Fast path for hex colors and rgb()/rgba() colors | 455 // Fast path for hex colors and rgb()/rgba() colors |
| 456 bool parseResult; | 456 bool parseResult; |
| 457 if (string.is8Bit()) | 457 if (string.is8Bit()) |
| 458 parseResult = fastParseColorInternal(color, string.characters8(), string
.length(), quirksMode); | 458 parseResult = fastParseColorInternal(color, string.characters8(), string
.length(), quirksMode); |
| 459 else | 459 else |
| 460 parseResult = fastParseColorInternal(color, string.characters16(), strin
g.length(), quirksMode); | 460 parseResult = fastParseColorInternal(color, string.characters16(), strin
g.length(), quirksMode); |
| 461 if (!parseResult) | 461 if (!parseResult) |
| 462 return nullptr; | 462 return nullptr; |
| 463 return cssValuePool().createColorValue(color); | 463 return cssValuePool->createColorValue(color); |
| 464 } | 464 } |
| 465 | 465 |
| 466 bool CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyID propertyId
, CSSValueID valueID) | 466 bool CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyID propertyId
, CSSValueID valueID) |
| 467 { | 467 { |
| 468 if (valueID == CSSValueInvalid) | 468 if (valueID == CSSValueInvalid) |
| 469 return false; | 469 return false; |
| 470 | 470 |
| 471 switch (propertyId) { | 471 switch (propertyId) { |
| 472 case CSSPropertyAlignmentBaseline: | 472 case CSSPropertyAlignmentBaseline: |
| 473 // auto | baseline | before-edge | text-before-edge | middle | | 473 // auto | baseline | before-edge | text-before-edge | middle | |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 RawPtr<CSSValue> CSSParserFastPaths::maybeParseValue(CSSPropertyID propertyID, c
onst String& string, CSSParserMode parserMode, CSSValuePool* localCSSValuePool) |
| 1025 { | 1025 { |
| 1026 if (RawPtr<CSSValue> length = parseSimpleLengthValue(propertyID, string, par
serMode)) | 1026 if (RawPtr<CSSValue> length = parseSimpleLengthValue(propertyID, string, par
serMode)) |
| 1027 return length.release(); | 1027 return length.release(); |
| 1028 if (isColorPropertyID(propertyID)) | 1028 if (isColorPropertyID(propertyID)) |
| 1029 return parseColor(string, parserMode); | 1029 return parseColor(string, parserMode, localCSSValuePool); |
| 1030 if (RawPtr<CSSValue> keyword = parseKeywordValue(propertyID, string)) | 1030 if (RawPtr<CSSValue> keyword = parseKeywordValue(propertyID, string)) |
| 1031 return keyword.release(); | 1031 return keyword.release(); |
| 1032 if (RawPtr<CSSValue> transform = parseSimpleTransform(propertyID, string)) | 1032 if (RawPtr<CSSValue> transform = parseSimpleTransform(propertyID, string)) |
| 1033 return transform.release(); | 1033 return transform.release(); |
| 1034 return nullptr; | 1034 return nullptr; |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 } // namespace blink | 1037 } // namespace blink |
| OLD | NEW |