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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSParserFastPaths.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 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/CSSColorValue.h" 8 #include "core/css/CSSColorValue.h"
9 #include "core/css/CSSFunctionValue.h" 9 #include "core/css/CSSFunctionValue.h"
10 #include "core/css/CSSIdentifierValue.h" 10 #include "core/css/CSSIdentifierValue.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (!ok) 98 if (!ok)
99 return false; 99 return false;
100 number = clampTo<double>(number, -std::numeric_limits<float>::max(), 100 number = clampTo<double>(number, -std::numeric_limits<float>::max(),
101 std::numeric_limits<float>::max()); 101 std::numeric_limits<float>::max());
102 return true; 102 return true;
103 } 103 }
104 104
105 static CSSValue* parseSimpleLengthValue(CSSPropertyID propertyId, 105 static CSSValue* parseSimpleLengthValue(CSSPropertyID propertyId,
106 const String& string, 106 const String& string,
107 CSSParserMode cssParserMode) { 107 CSSParserMode cssParserMode) {
108 ASSERT(!string.isEmpty()); 108 DCHECK(!string.isEmpty());
109 bool acceptsNegativeNumbers = false; 109 bool acceptsNegativeNumbers = false;
110 110
111 // In @viewport, width and height are shorthands, not simple length values. 111 // In @viewport, width and height are shorthands, not simple length values.
112 if (isCSSViewportParsingEnabledForMode(cssParserMode) || 112 if (isCSSViewportParsingEnabledForMode(cssParserMode) ||
113 !isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers)) 113 !isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers))
114 return nullptr; 114 return nullptr;
115 115
116 unsigned length = string.length(); 116 unsigned length = string.length();
117 double number; 117 double number;
118 CSSPrimitiveValue::UnitType unit = CSSPrimitiveValue::UnitType::Number; 118 CSSPrimitiveValue::UnitType unit = CSSPrimitiveValue::UnitType::Number;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 return false; 465 return false;
466 rgb = makeRGB(red, green, blue); 466 rgb = makeRGB(red, green, blue);
467 return true; 467 return true;
468 } 468 }
469 469
470 return false; 470 return false;
471 } 471 }
472 472
473 CSSValue* CSSParserFastPaths::parseColor(const String& string, 473 CSSValue* CSSParserFastPaths::parseColor(const String& string,
474 CSSParserMode parserMode) { 474 CSSParserMode parserMode) {
475 ASSERT(!string.isEmpty()); 475 DCHECK(!string.isEmpty());
476 CSSValueID valueID = cssValueKeywordID(string); 476 CSSValueID valueID = cssValueKeywordID(string);
477 if (StyleColor::isColorKeyword(valueID)) { 477 if (StyleColor::isColorKeyword(valueID)) {
478 if (!isValueAllowedInMode(valueID, parserMode)) 478 if (!isValueAllowedInMode(valueID, parserMode))
479 return nullptr; 479 return nullptr;
480 return CSSIdentifierValue::create(valueID); 480 return CSSIdentifierValue::create(valueID);
481 } 481 }
482 482
483 RGBA32 color; 483 RGBA32 color;
484 bool quirksMode = isQuirksModeBehavior(parserMode); 484 bool quirksMode = isQuirksModeBehavior(parserMode);
485 485
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 case CSSPropertyPosition: 626 case CSSPropertyPosition:
627 return valueID == CSSValueStatic || valueID == CSSValueRelative || 627 return valueID == CSSValueStatic || valueID == CSSValueRelative ||
628 valueID == CSSValueAbsolute || valueID == CSSValueFixed || 628 valueID == CSSValueAbsolute || valueID == CSSValueFixed ||
629 (RuntimeEnabledFeatures::cssStickyPositionEnabled() && 629 (RuntimeEnabledFeatures::cssStickyPositionEnabled() &&
630 valueID == CSSValueSticky); 630 valueID == CSSValueSticky);
631 case CSSPropertyResize: 631 case CSSPropertyResize:
632 return valueID == CSSValueNone || valueID == CSSValueBoth || 632 return valueID == CSSValueNone || valueID == CSSValueBoth ||
633 valueID == CSSValueHorizontal || valueID == CSSValueVertical || 633 valueID == CSSValueHorizontal || valueID == CSSValueVertical ||
634 valueID == CSSValueAuto; 634 valueID == CSSValueAuto;
635 case CSSPropertyScrollBehavior: 635 case CSSPropertyScrollBehavior:
636 ASSERT(RuntimeEnabledFeatures::cssomSmoothScrollEnabled()); 636 DCHECK(RuntimeEnabledFeatures::cssomSmoothScrollEnabled());
637 return valueID == CSSValueAuto || valueID == CSSValueSmooth; 637 return valueID == CSSValueAuto || valueID == CSSValueSmooth;
638 case CSSPropertyShapeRendering: 638 case CSSPropertyShapeRendering:
639 return valueID == CSSValueAuto || valueID == CSSValueOptimizeSpeed || 639 return valueID == CSSValueAuto || valueID == CSSValueOptimizeSpeed ||
640 valueID == CSSValueCrispEdges || 640 valueID == CSSValueCrispEdges ||
641 valueID == CSSValueGeometricPrecision; 641 valueID == CSSValueGeometricPrecision;
642 case CSSPropertySpeak: 642 case CSSPropertySpeak:
643 return valueID == CSSValueNone || valueID == CSSValueNormal || 643 return valueID == CSSValueNone || valueID == CSSValueNormal ||
644 valueID == CSSValueSpellOut || valueID == CSSValueDigits || 644 valueID == CSSValueSpellOut || valueID == CSSValueDigits ||
645 valueID == CSSValueLiteralPunctuation || 645 valueID == CSSValueLiteralPunctuation ||
646 valueID == CSSValueNoPunctuation; 646 valueID == CSSValueNoPunctuation;
(...skipping 12 matching lines...) Expand all
659 case CSSPropertyTextAlignLast: 659 case CSSPropertyTextAlignLast:
660 return (valueID >= CSSValueLeft && valueID <= CSSValueJustify) || 660 return (valueID >= CSSValueLeft && valueID <= CSSValueJustify) ||
661 valueID == CSSValueStart || valueID == CSSValueEnd || 661 valueID == CSSValueStart || valueID == CSSValueEnd ||
662 valueID == CSSValueAuto; 662 valueID == CSSValueAuto;
663 case CSSPropertyTextAnchor: 663 case CSSPropertyTextAnchor:
664 return valueID == CSSValueStart || valueID == CSSValueMiddle || 664 return valueID == CSSValueStart || valueID == CSSValueMiddle ||
665 valueID == CSSValueEnd; 665 valueID == CSSValueEnd;
666 case CSSPropertyTextCombineUpright: 666 case CSSPropertyTextCombineUpright:
667 return valueID == CSSValueNone || valueID == CSSValueAll; 667 return valueID == CSSValueNone || valueID == CSSValueAll;
668 case CSSPropertyTextDecorationStyle: 668 case CSSPropertyTextDecorationStyle:
669 ASSERT(RuntimeEnabledFeatures::css3TextDecorationsEnabled()); 669 DCHECK(RuntimeEnabledFeatures::css3TextDecorationsEnabled());
670 return valueID == CSSValueSolid || valueID == CSSValueDouble || 670 return valueID == CSSValueSolid || valueID == CSSValueDouble ||
671 valueID == CSSValueDotted || valueID == CSSValueDashed || 671 valueID == CSSValueDotted || valueID == CSSValueDashed ||
672 valueID == CSSValueWavy; 672 valueID == CSSValueWavy;
673 case CSSPropertyTextJustify: 673 case CSSPropertyTextJustify:
674 ASSERT(RuntimeEnabledFeatures::css3TextEnabled()); 674 DCHECK(RuntimeEnabledFeatures::css3TextEnabled());
675 return valueID == CSSValueInterWord || valueID == CSSValueDistribute || 675 return valueID == CSSValueInterWord || valueID == CSSValueDistribute ||
676 valueID == CSSValueAuto || valueID == CSSValueNone; 676 valueID == CSSValueAuto || valueID == CSSValueNone;
677 case CSSPropertyTextOrientation: 677 case CSSPropertyTextOrientation:
678 return valueID == CSSValueMixed || valueID == CSSValueUpright || 678 return valueID == CSSValueMixed || valueID == CSSValueUpright ||
679 valueID == CSSValueSideways || valueID == CSSValueSidewaysRight; 679 valueID == CSSValueSideways || valueID == CSSValueSidewaysRight;
680 case CSSPropertyWebkitTextOrientation: 680 case CSSPropertyWebkitTextOrientation:
681 return valueID == CSSValueSideways || valueID == CSSValueSidewaysRight || 681 return valueID == CSSValueSideways || valueID == CSSValueSidewaysRight ||
682 valueID == CSSValueVerticalRight || valueID == CSSValueUpright; 682 valueID == CSSValueVerticalRight || valueID == CSSValueUpright;
683 case CSSPropertyTextOverflow: 683 case CSSPropertyTextOverflow:
684 return valueID == CSSValueClip || valueID == CSSValueEllipsis; 684 return valueID == CSSValueClip || valueID == CSSValueEllipsis;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 valueID == CSSValueLr || valueID == CSSValueRl || 824 valueID == CSSValueLr || valueID == CSSValueRl ||
825 valueID == CSSValueTb; 825 valueID == CSSValueTb;
826 case CSSPropertyWhiteSpace: 826 case CSSPropertyWhiteSpace:
827 return valueID == CSSValueNormal || valueID == CSSValuePre || 827 return valueID == CSSValueNormal || valueID == CSSValuePre ||
828 valueID == CSSValuePreWrap || valueID == CSSValuePreLine || 828 valueID == CSSValuePreWrap || valueID == CSSValuePreLine ||
829 valueID == CSSValueNowrap; 829 valueID == CSSValueNowrap;
830 case CSSPropertyWordBreak: 830 case CSSPropertyWordBreak:
831 return valueID == CSSValueNormal || valueID == CSSValueBreakAll || 831 return valueID == CSSValueNormal || valueID == CSSValueBreakAll ||
832 valueID == CSSValueKeepAll || valueID == CSSValueBreakWord; 832 valueID == CSSValueKeepAll || valueID == CSSValueBreakWord;
833 case CSSPropertyScrollSnapType: 833 case CSSPropertyScrollSnapType:
834 ASSERT(RuntimeEnabledFeatures::cssScrollSnapPointsEnabled()); 834 DCHECK(RuntimeEnabledFeatures::cssScrollSnapPointsEnabled());
835 return valueID == CSSValueNone || valueID == CSSValueMandatory || 835 return valueID == CSSValueNone || valueID == CSSValueMandatory ||
836 valueID == CSSValueProximity; 836 valueID == CSSValueProximity;
837 default: 837 default:
838 ASSERT_NOT_REACHED(); 838 NOTREACHED();
839 return false; 839 return false;
840 } 840 }
841 } 841 }
842 842
843 bool CSSParserFastPaths::isKeywordPropertyID(CSSPropertyID propertyId) { 843 bool CSSParserFastPaths::isKeywordPropertyID(CSSPropertyID propertyId) {
844 switch (propertyId) { 844 switch (propertyId) {
845 case CSSPropertyAlignmentBaseline: 845 case CSSPropertyAlignmentBaseline:
846 case CSSPropertyAll: 846 case CSSPropertyAll:
847 case CSSPropertyMixBlendMode: 847 case CSSPropertyMixBlendMode:
848 case CSSPropertyIsolation: 848 case CSSPropertyIsolation:
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 case CSSPropertyAlignSelf: 953 case CSSPropertyAlignSelf:
954 return !RuntimeEnabledFeatures::cssGridLayoutEnabled(); 954 return !RuntimeEnabledFeatures::cssGridLayoutEnabled();
955 default: 955 default:
956 return false; 956 return false;
957 } 957 }
958 } 958 }
959 959
960 static CSSValue* parseKeywordValue(CSSPropertyID propertyId, 960 static CSSValue* parseKeywordValue(CSSPropertyID propertyId,
961 const String& string, 961 const String& string,
962 CSSParserMode parserMode) { 962 CSSParserMode parserMode) {
963 ASSERT(!string.isEmpty()); 963 DCHECK(!string.isEmpty());
964 964
965 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) { 965 if (!CSSParserFastPaths::isKeywordPropertyID(propertyId)) {
966 // All properties accept the values of "initial" and "inherit". 966 // All properties accept the values of "initial" and "inherit".
967 if (!equalIgnoringASCIICase(string, "initial") && 967 if (!equalIgnoringASCIICase(string, "initial") &&
968 !equalIgnoringASCIICase(string, "inherit")) 968 !equalIgnoringASCIICase(string, "inherit"))
969 return nullptr; 969 return nullptr;
970 970
971 // Parse initial/inherit shorthands using the CSSPropertyParser. 971 // Parse initial/inherit shorthands using the CSSPropertyParser.
972 if (shorthandForProperty(propertyId).length()) 972 if (shorthandForProperty(propertyId).length())
973 return nullptr; 973 return nullptr;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 return nullptr; 1184 return nullptr;
1185 if (!transformList) 1185 if (!transformList)
1186 transformList = CSSValueList::createSpaceSeparated(); 1186 transformList = CSSValueList::createSpaceSeparated();
1187 transformList->append(*transformValue); 1187 transformList->append(*transformValue);
1188 } 1188 }
1189 return transformList; 1189 return transformList;
1190 } 1190 }
1191 1191
1192 static CSSValue* parseSimpleTransform(CSSPropertyID propertyID, 1192 static CSSValue* parseSimpleTransform(CSSPropertyID propertyID,
1193 const String& string) { 1193 const String& string) {
1194 ASSERT(!string.isEmpty()); 1194 DCHECK(!string.isEmpty());
1195 1195
1196 if (propertyID != CSSPropertyTransform) 1196 if (propertyID != CSSPropertyTransform)
1197 return nullptr; 1197 return nullptr;
1198 if (string.is8Bit()) 1198 if (string.is8Bit())
1199 return parseSimpleTransformList(string.characters8(), string.length()); 1199 return parseSimpleTransformList(string.characters8(), string.length());
1200 return parseSimpleTransformList(string.characters16(), string.length()); 1200 return parseSimpleTransformList(string.characters16(), string.length());
1201 } 1201 }
1202 1202
1203 CSSValue* CSSParserFastPaths::maybeParseValue(CSSPropertyID propertyID, 1203 CSSValue* CSSParserFastPaths::maybeParseValue(CSSPropertyID propertyID,
1204 const String& string, 1204 const String& string,
1205 CSSParserMode parserMode) { 1205 CSSParserMode parserMode) {
1206 if (CSSValue* length = parseSimpleLengthValue(propertyID, string, parserMode)) 1206 if (CSSValue* length = parseSimpleLengthValue(propertyID, string, parserMode))
1207 return length; 1207 return length;
1208 if (isColorPropertyID(propertyID)) 1208 if (isColorPropertyID(propertyID))
1209 return parseColor(string, parserMode); 1209 return parseColor(string, parserMode);
1210 if (CSSValue* keyword = parseKeywordValue(propertyID, string, parserMode)) 1210 if (CSSValue* keyword = parseKeywordValue(propertyID, string, parserMode))
1211 return keyword; 1211 return keyword;
1212 if (CSSValue* transform = parseSimpleTransform(propertyID, string)) 1212 if (CSSValue* transform = parseSimpleTransform(propertyID, string))
1213 return transform; 1213 return transform;
1214 return nullptr; 1214 return nullptr;
1215 } 1215 }
1216 1216
1217 } // namespace blink 1217 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSAtRuleID.cpp ('k') | third_party/WebKit/Source/core/css/parser/CSSParserImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698