Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSPropertyParserHelpers.cpp

Issue 2755493004: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in core/css/ (Closed)
Patch Set: All windows error are Resolved now. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/CSSColorValue.h" 8 #include "core/css/CSSColorValue.h"
9 #include "core/css/CSSCrossfadeValue.h" 9 #include "core/css/CSSCrossfadeValue.h"
10 #include "core/css/CSSGradientValue.h" 10 #include "core/css/CSSGradientValue.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 bool consumeSlashIncludingWhitespace(CSSParserTokenRange& range) { 90 bool consumeSlashIncludingWhitespace(CSSParserTokenRange& range) {
91 CSSParserToken value = range.peek(); 91 CSSParserToken value = range.peek();
92 if (value.type() != DelimiterToken || value.delimiter() != '/') 92 if (value.type() != DelimiterToken || value.delimiter() != '/')
93 return false; 93 return false;
94 range.consumeIncludingWhitespace(); 94 range.consumeIncludingWhitespace();
95 return true; 95 return true;
96 } 96 }
97 97
98 CSSParserTokenRange consumeFunction(CSSParserTokenRange& range) { 98 CSSParserTokenRange consumeFunction(CSSParserTokenRange& range) {
99 ASSERT(range.peek().type() == FunctionToken); 99 DCHECK_EQ(range.peek().type(), FunctionToken);
100 CSSParserTokenRange contents = range.consumeBlock(); 100 CSSParserTokenRange contents = range.consumeBlock();
101 range.consumeWhitespace(); 101 range.consumeWhitespace();
102 contents.consumeWhitespace(); 102 contents.consumeWhitespace();
103 return contents; 103 return contents;
104 } 104 }
105 105
106 // TODO(rwlbuis): consider pulling in the parsing logic from 106 // TODO(rwlbuis): consider pulling in the parsing logic from
107 // CSSCalculationValue.cpp. 107 // CSSCalculationValue.cpp.
108 class CalcParser { 108 class CalcParser {
109 STACK_ALLOCATED(); 109 STACK_ALLOCATED();
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 if (token.type() == UrlToken) { 421 if (token.type() == UrlToken) {
422 range.consumeIncludingWhitespace(); 422 range.consumeIncludingWhitespace();
423 return token.value(); 423 return token.value();
424 } 424 }
425 if (token.functionId() == CSSValueUrl) { 425 if (token.functionId() == CSSValueUrl) {
426 CSSParserTokenRange urlRange = range; 426 CSSParserTokenRange urlRange = range;
427 CSSParserTokenRange urlArgs = urlRange.consumeBlock(); 427 CSSParserTokenRange urlArgs = urlRange.consumeBlock();
428 const CSSParserToken& next = urlArgs.consumeIncludingWhitespace(); 428 const CSSParserToken& next = urlArgs.consumeIncludingWhitespace();
429 if (next.type() == BadStringToken || !urlArgs.atEnd()) 429 if (next.type() == BadStringToken || !urlArgs.atEnd())
430 return StringView(); 430 return StringView();
431 ASSERT(next.type() == StringToken); 431 DCHECK_EQ(next.type(), StringToken);
432 range = urlRange; 432 range = urlRange;
433 range.consumeWhitespace(); 433 range.consumeWhitespace();
434 return next.value(); 434 return next.value();
435 } 435 }
436 436
437 return StringView(); 437 return StringView();
438 } 438 }
439 439
440 CSSURIValue* consumeUrl(CSSParserTokenRange& range, 440 CSSURIValue* consumeUrl(CSSParserTokenRange& range,
441 const CSSParserContext* context) { 441 const CSSParserContext* context) {
442 StringView url = consumeUrlAsStringView(range); 442 StringView url = consumeUrlAsStringView(range);
443 if (url.isNull()) 443 if (url.isNull())
444 return nullptr; 444 return nullptr;
445 String urlString = url.toString(); 445 String urlString = url.toString();
446 return CSSURIValue::create(urlString, context->completeURL(urlString)); 446 return CSSURIValue::create(urlString, context->completeURL(urlString));
447 } 447 }
448 448
449 static int clampRGBComponent(const CSSPrimitiveValue& value) { 449 static int clampRGBComponent(const CSSPrimitiveValue& value) {
450 double result = value.getDoubleValue(); 450 double result = value.getDoubleValue();
451 // TODO(timloh): Multiply by 2.55 and round instead of floor. 451 // TODO(timloh): Multiply by 2.55 and round instead of floor.
452 if (value.isPercentage()) 452 if (value.isPercentage())
453 result *= 2.56; 453 result *= 2.56;
454 return clampTo<int>(result, 0, 255); 454 return clampTo<int>(result, 0, 255);
455 } 455 }
456 456
457 static bool parseRGBParameters(CSSParserTokenRange& range, 457 static bool parseRGBParameters(CSSParserTokenRange& range,
458 RGBA32& result, 458 RGBA32& result,
459 bool parseAlpha) { 459 bool parseAlpha) {
460 ASSERT(range.peek().functionId() == CSSValueRgb || 460 DCHECK(range.peek().functionId() == CSSValueRgb ||
461 range.peek().functionId() == CSSValueRgba); 461 range.peek().functionId() == CSSValueRgba);
462 CSSParserTokenRange args = consumeFunction(range); 462 CSSParserTokenRange args = consumeFunction(range);
463 CSSPrimitiveValue* colorParameter = consumeInteger(args); 463 CSSPrimitiveValue* colorParameter = consumeInteger(args);
464 if (!colorParameter) 464 if (!colorParameter)
465 colorParameter = consumePercent(args, ValueRangeAll); 465 colorParameter = consumePercent(args, ValueRangeAll);
466 if (!colorParameter) 466 if (!colorParameter)
467 return false; 467 return false;
468 const bool isPercent = colorParameter->isPercentage(); 468 const bool isPercent = colorParameter->isPercentage();
469 int colorArray[3]; 469 int colorArray[3];
470 colorArray[0] = clampRGBComponent(*colorParameter); 470 colorArray[0] = clampRGBComponent(*colorParameter);
(...skipping 19 matching lines...) Expand all
490 makeRGBA(colorArray[0], colorArray[1], colorArray[2], alphaComponent); 490 makeRGBA(colorArray[0], colorArray[1], colorArray[2], alphaComponent);
491 } else { 491 } else {
492 result = makeRGB(colorArray[0], colorArray[1], colorArray[2]); 492 result = makeRGB(colorArray[0], colorArray[1], colorArray[2]);
493 } 493 }
494 return args.atEnd(); 494 return args.atEnd();
495 } 495 }
496 496
497 static bool parseHSLParameters(CSSParserTokenRange& range, 497 static bool parseHSLParameters(CSSParserTokenRange& range,
498 RGBA32& result, 498 RGBA32& result,
499 bool parseAlpha) { 499 bool parseAlpha) {
500 ASSERT(range.peek().functionId() == CSSValueHsl || 500 DCHECK(range.peek().functionId() == CSSValueHsl ||
501 range.peek().functionId() == CSSValueHsla); 501 range.peek().functionId() == CSSValueHsla);
502 CSSParserTokenRange args = consumeFunction(range); 502 CSSParserTokenRange args = consumeFunction(range);
503 CSSPrimitiveValue* hslValue = consumeNumber(args, ValueRangeAll); 503 CSSPrimitiveValue* hslValue = consumeNumber(args, ValueRangeAll);
504 if (!hslValue) 504 if (!hslValue)
505 return false; 505 return false;
506 double colorArray[3]; 506 double colorArray[3];
507 colorArray[0] = (((hslValue->getIntValue() % 360) + 360) % 360) / 360.0; 507 colorArray[0] = (((hslValue->getIntValue() % 360) + 360) % 360) / 360.0;
508 for (int i = 1; i < 3; i++) { 508 for (int i = 1; i < 3; i++) {
509 if (!consumeCommaIncludingWhitespace(args)) 509 if (!consumeCommaIncludingWhitespace(args))
510 return false; 510 return false;
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 1405
1406 // https://drafts.csswg.org/css-shapes-1/#typedef-shape-box 1406 // https://drafts.csswg.org/css-shapes-1/#typedef-shape-box
1407 CSSIdentifierValue* consumeShapeBox(CSSParserTokenRange& range) { 1407 CSSIdentifierValue* consumeShapeBox(CSSParserTokenRange& range) {
1408 return consumeIdent<CSSValueContentBox, CSSValuePaddingBox, CSSValueBorderBox, 1408 return consumeIdent<CSSValueContentBox, CSSValuePaddingBox, CSSValueBorderBox,
1409 CSSValueMarginBox>(range); 1409 CSSValueMarginBox>(range);
1410 } 1410 }
1411 1411
1412 } // namespace CSSPropertyParserHelpers 1412 } // namespace CSSPropertyParserHelpers
1413 1413
1414 } // namespace blink 1414 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698