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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 (acceptQuirkyColors) { |
408 if (token.type() == NumberToken && token.numericValueType() == IntegerVa lueType | 408 if (token.type() == NumberToken) { // e.g. 112233 |
409 && token.numericValue() >= 0. && token.numericValue() < 1000000.) { // e.g. 112233 | 409 if (token.numericValueType() != IntegerValueType |
410 || token.numericValue() < 0. || token.numericValue() >= 1000000. ) | |
411 return false; | |
410 color = String::format("%06d", static_cast<int>(token.numericValue() )); | 412 color = String::format("%06d", static_cast<int>(token.numericValue() )); |
411 } else if (token.type() == DimensionToken) { // e.g. 0001FF | 413 } else if (token.type() == DimensionToken) { // e.g. 0001FF |
412 // TODO(timloh): This should check the numericValueType flag | 414 if (token.numericValueType() != IntegerValueType |
415 || token.numericValue() < 0. || token.numericValue() > std::nume ric_limits<int>::max()) | |
Timothy Loh
2016/05/11 02:12:55
Why not compare to 10^6, similar to number types?
rwlbuis
2016/05/11 02:28:47
Ah, I got confused by https://codereview.chromium.
| |
416 return false; | |
413 color = String::number(static_cast<int>(token.numericValue())) + Str ing(token.value()); | 417 color = String::number(static_cast<int>(token.numericValue())) + Str ing(token.value()); |
414 if (color.length() > 6) | |
415 return false; | |
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 color = token.value(); | 421 color = token.value(); |
420 } | 422 } |
421 } | 423 } |
422 if (token.type() == HashToken) | 424 if (token.type() == HashToken) |
423 color = token.value(); | 425 color = token.value(); |
424 if (!Color::parseHexColor(color, result)) | 426 if (!Color::parseHexColor(color, result)) |
425 return false; | 427 return false; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 if (!value2) { | 592 if (!value2) { |
591 positionFromOneValue(value1, resultX, resultY); | 593 positionFromOneValue(value1, resultX, resultY); |
592 return true; | 594 return true; |
593 } | 595 } |
594 return positionFromTwoValues(value1, value2, resultX, resultY); | 596 return positionFromTwoValues(value1, value2, resultX, resultY); |
595 } | 597 } |
596 | 598 |
597 } // namespace CSSPropertyParserHelpers | 599 } // namespace CSSPropertyParserHelpers |
598 | 600 |
599 } // namespace blink | 601 } // namespace blink |
OLD | NEW |