| 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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 return false; | 421 return false; |
| 422 if (current != end) | 422 if (current != end) |
| 423 return false; | 423 return false; |
| 424 rgb = makeRGB(red, green, blue); | 424 rgb = makeRGB(red, green, blue); |
| 425 return true; | 425 return true; |
| 426 } | 426 } |
| 427 | 427 |
| 428 return false; | 428 return false; |
| 429 } | 429 } |
| 430 | 430 |
| 431 bool CSSParserFastPaths::parseColorAsRGBA32(RGBA32& rgb, const String& name, boo
l quirksMode) | 431 PassRefPtrWillBeRawPtr<CSSValue> CSSParserFastPaths::parseColor(const String& st
ring, bool quirksMode) |
| 432 { | |
| 433 unsigned length = name.length(); | |
| 434 bool parseResult; | |
| 435 | |
| 436 if (!length) | |
| 437 return false; | |
| 438 | |
| 439 if (name.is8Bit()) | |
| 440 parseResult = fastParseColorInternal(rgb, name.characters8(), length, qu
irksMode); | |
| 441 else | |
| 442 parseResult = fastParseColorInternal(rgb, name.characters16(), length, q
uirksMode); | |
| 443 | |
| 444 if (parseResult) | |
| 445 return true; | |
| 446 | |
| 447 // Try named colors. | |
| 448 Color tc; | |
| 449 if (!tc.setNamedColor(name)) | |
| 450 return false; | |
| 451 rgb = tc.rgb(); | |
| 452 return true; | |
| 453 } | |
| 454 | |
| 455 static PassRefPtrWillBeRawPtr<CSSValue> parseColor(const String& string, bool qu
irksMode) | |
| 456 { | 432 { |
| 457 ASSERT(!string.isEmpty()); | 433 ASSERT(!string.isEmpty()); |
| 458 CSSParserString cssString; | 434 CSSParserString cssString; |
| 459 cssString.init(string); | 435 cssString.init(string); |
| 460 CSSValueID valueID = cssValueKeywordID(cssString); | 436 CSSValueID valueID = cssValueKeywordID(cssString); |
| 461 if (valueID == CSSValueWebkitText || valueID == CSSValueCurrentcolor | 437 if (valueID == CSSValueWebkitText || valueID == CSSValueCurrentcolor |
| 462 || (valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID
== CSSValueMenu | 438 || (valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID
== CSSValueMenu |
| 463 || (quirksMode && valueID >= CSSValueWebkitFocusRingColor && valueID < C
SSValueWebkitText)) | 439 || (quirksMode && valueID >= CSSValueWebkitFocusRingColor && valueID < C
SSValueWebkitText)) |
| 464 return cssValuePool().createIdentifierValue(valueID); | 440 return cssValuePool().createIdentifierValue(valueID); |
| 465 | 441 |
| 466 RGBA32 color; | 442 RGBA32 color; |
| 467 if (!CSSParserFastPaths::parseColorAsRGBA32(color, string, quirksMode)) | 443 |
| 444 // Fast path for hex colors and rgb()/rgba() colors |
| 445 bool parseResult; |
| 446 if (string.is8Bit()) |
| 447 parseResult = fastParseColorInternal(color, string.characters8(), string
.length(), quirksMode); |
| 448 else |
| 449 parseResult = fastParseColorInternal(color, string.characters16(), strin
g.length(), quirksMode); |
| 450 if (parseResult) |
| 451 return cssValuePool().createColorValue(color); |
| 452 |
| 453 Color namedColor; |
| 454 if (!namedColor.setNamedColor(string)) |
| 468 return nullptr; | 455 return nullptr; |
| 469 return cssValuePool().createColorValue(color); | 456 return cssValuePool().createColorValue(namedColor.rgb()); |
| 470 } | 457 } |
| 471 | 458 |
| 472 bool CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyID propertyId
, CSSValueID valueID) | 459 bool CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyID propertyId
, CSSValueID valueID) |
| 473 { | 460 { |
| 474 if (valueID == CSSValueInvalid) | 461 if (valueID == CSSValueInvalid) |
| 475 return false; | 462 return false; |
| 476 | 463 |
| 477 switch (propertyId) { | 464 switch (propertyId) { |
| 478 case CSSPropertyAll: | 465 case CSSPropertyAll: |
| 479 return false; // Only accepts css-wide keywords | 466 return false; // Only accepts css-wide keywords |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 if (isColorPropertyID(propertyID)) | 949 if (isColorPropertyID(propertyID)) |
| 963 return parseColor(string, isQuirksModeBehavior(parserMode)); | 950 return parseColor(string, isQuirksModeBehavior(parserMode)); |
| 964 if (RefPtrWillBeRawPtr<CSSValue> keyword = parseKeywordValue(propertyID, str
ing)) | 951 if (RefPtrWillBeRawPtr<CSSValue> keyword = parseKeywordValue(propertyID, str
ing)) |
| 965 return keyword.release(); | 952 return keyword.release(); |
| 966 if (RefPtrWillBeRawPtr<CSSValue> transform = parseSimpleTransform(propertyID
, string)) | 953 if (RefPtrWillBeRawPtr<CSSValue> transform = parseSimpleTransform(propertyID
, string)) |
| 967 return transform.release(); | 954 return transform.release(); |
| 968 return nullptr; | 955 return nullptr; |
| 969 } | 956 } |
| 970 | 957 |
| 971 } // namespace blink | 958 } // namespace blink |
| OLD | NEW |