OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/CSSPropertyParserHelpers.h" | 5 #include "core/css/parser/CSSPropertyParserHelpers.h" |
6 | 6 |
7 #include "core/css/CSSCalculationValue.h" | 7 #include "core/css/CSSCalculationValue.h" |
8 #include "core/css/CSSStringValue.h" | 8 #include "core/css/CSSStringValue.h" |
9 #include "core/css/CSSValuePair.h" | 9 #include "core/css/CSSValuePair.h" |
10 // TODO(timloh): Remove this dependency | 10 // TODO(timloh): Remove this dependency |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 alpha = clampTo<double>(alpha, 0.0, 1.0); | 397 alpha = clampTo<double>(alpha, 0.0, 1.0); |
398 } | 398 } |
399 result = makeRGBAFromHSLA(colorArray[0], colorArray[1], colorArray[2], alpha
); | 399 result = makeRGBAFromHSLA(colorArray[0], colorArray[1], colorArray[2], alpha
); |
400 return args.atEnd(); | 400 return args.atEnd(); |
401 } | 401 } |
402 | 402 |
403 static bool parseHexColor(CSSParserTokenRange& range, RGBA32& result, bool accep
tQuirkyColors) | 403 static bool parseHexColor(CSSParserTokenRange& range, RGBA32& result, bool accep
tQuirkyColors) |
404 { | 404 { |
405 const CSSParserToken& token = range.peek(); | 405 const CSSParserToken& token = range.peek(); |
406 String color; | 406 String color; |
407 if (acceptQuirkyColors) { | 407 if (token.type() == HashToken) { |
| 408 color = token.value(); |
| 409 } else if (acceptQuirkyColors) { |
408 if (token.type() == NumberToken || token.type() == DimensionToken) { | 410 if (token.type() == NumberToken || token.type() == DimensionToken) { |
409 if (token.numericValueType() != IntegerValueType | 411 if (token.numericValueType() != IntegerValueType |
410 || token.numericValue() < 0. || token.numericValue() >= 1000000.
) | 412 || token.numericValue() < 0. || token.numericValue() >= 1000000.
) |
411 return false; | 413 return false; |
412 if (token.type() == NumberToken) // e.g. 112233 | 414 if (token.type() == NumberToken) // e.g. 112233 |
413 color = String::format("%d", static_cast<int>(token.numericValue
())); | 415 color = String::format("%d", static_cast<int>(token.numericValue
())); |
414 else // e.g. 0001FF | 416 else // e.g. 0001FF |
415 color = String::number(static_cast<int>(token.numericValue())) +
String(token.value()); | 417 color = String::number(static_cast<int>(token.numericValue())) +
String(token.value()); |
416 while (color.length() < 6) | 418 while (color.length() < 6) |
417 color = "0" + color; | 419 color = "0" + color; |
418 } else if (token.type() == IdentToken) { // e.g. FF0000 | 420 } else if (token.type() == IdentToken) { // e.g. FF0000 |
419 unsigned length = token.value().length(); | |
420 if (length != 3 && length != 6) | |
421 return false; | |
422 color = token.value(); | 421 color = token.value(); |
423 } | 422 } |
| 423 unsigned length = color.length(); |
| 424 if (length != 3 && length != 6) |
| 425 return false; |
424 } | 426 } |
425 if (token.type() == HashToken) | |
426 color = token.value(); | |
427 if (!Color::parseHexColor(color, result)) | 427 if (!Color::parseHexColor(color, result)) |
428 return false; | 428 return false; |
429 range.consumeIncludingWhitespace(); | 429 range.consumeIncludingWhitespace(); |
430 return true; | 430 return true; |
431 } | 431 } |
432 | 432 |
433 static bool parseColorFunction(CSSParserTokenRange& range, RGBA32& result) | 433 static bool parseColorFunction(CSSParserTokenRange& range, RGBA32& result) |
434 { | 434 { |
435 CSSValueID functionId = range.peek().functionId(); | 435 CSSValueID functionId = range.peek().functionId(); |
436 if (functionId < CSSValueRgb || functionId > CSSValueHsla) | 436 if (functionId < CSSValueRgb || functionId > CSSValueHsla) |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 if (!value2) { | 593 if (!value2) { |
594 positionFromOneValue(value1, resultX, resultY); | 594 positionFromOneValue(value1, resultX, resultY); |
595 return true; | 595 return true; |
596 } | 596 } |
597 return positionFromTwoValues(value1, value2, resultX, resultY); | 597 return positionFromTwoValues(value1, value2, resultX, resultY); |
598 } | 598 } |
599 | 599 |
600 } // namespace CSSPropertyParserHelpers | 600 } // namespace CSSPropertyParserHelpers |
601 | 601 |
602 } // namespace blink | 602 } // namespace blink |
OLD | NEW |