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

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

Issue 2366243002: Remove all ordering requirements in CSSValueKeywords.in (WIP) (Closed)
Patch Set: Some mor efixes Created 4 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/CSSPropertyParser.h" 5 #include "core/css/parser/CSSPropertyParser.h"
6 6
7 #include "core/StylePropertyShorthand.h" 7 #include "core/StylePropertyShorthand.h"
8 #include "core/css/CSSBasicShapeValues.h" 8 #include "core/css/CSSBasicShapeValues.h"
9 #include "core/css/CSSBorderImage.h" 9 #include "core/css/CSSBorderImage.h"
10 #include "core/css/CSSContentDistributionValue.h" 10 #include "core/css/CSSContentDistributionValue.h"
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 } while (consumeCommaIncludingWhitespace(range)); 609 } while (consumeCommaIncludingWhitespace(range));
610 610
611 if (values->length()) 611 if (values->length())
612 return values; 612 return values;
613 613
614 return nullptr; 614 return nullptr;
615 } 615 }
616 616
617 static CSSIdentifierValue* consumeFontWeight(CSSParserTokenRange& range) { 617 static CSSIdentifierValue* consumeFontWeight(CSSParserTokenRange& range) {
618 const CSSParserToken& token = range.peek(); 618 const CSSParserToken& token = range.peek();
619 if (token.id() >= CSSValueNormal && token.id() <= CSSValueLighter) 619 if (token.id() == CSSValueNormal || token.id() == CSSValueBold ||
620 token.id() == CSSValueBolder || token.id() == CSSValueLighter)
620 return consumeIdent(range); 621 return consumeIdent(range);
621 if (token.type() != NumberToken || 622 if (token.type() != NumberToken ||
622 token.numericValueType() != IntegerValueType) 623 token.numericValueType() != IntegerValueType)
623 return nullptr; 624 return nullptr;
624 int weight = static_cast<int>(token.numericValue()); 625 int weight = static_cast<int>(token.numericValue());
625 if ((weight % 100) || weight < 100 || weight > 900) 626 if ((weight % 100) || weight < 100 || weight > 900)
626 return nullptr; 627 return nullptr;
627 range.consumeIncludingWhitespace(); 628 range.consumeIncludingWhitespace();
628 return CSSIdentifierValue::create( 629 switch (weight) {
629 static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)); 630 case 100:
631 return CSSIdentifierValue::create(CSSValue100);
632 case 200:
633 return CSSIdentifierValue::create(CSSValue200);
634 case 300:
635 return CSSIdentifierValue::create(CSSValue300);
636 case 400:
637 return CSSIdentifierValue::create(CSSValue400);
638 case 500:
639 return CSSIdentifierValue::create(CSSValue500);
640 case 600:
641 return CSSIdentifierValue::create(CSSValue600);
642 case 700:
643 return CSSIdentifierValue::create(CSSValue700);
644 case 800:
645 return CSSIdentifierValue::create(CSSValue800);
646 case 900:
647 return CSSIdentifierValue::create(CSSValue900);
648 default:
649 NOTREACHED();
650 return nullptr;
651 }
630 } 652 }
631 653
632 static String concatenateFamilyName(CSSParserTokenRange& range) { 654 static String concatenateFamilyName(CSSParserTokenRange& range) {
633 StringBuilder builder; 655 StringBuilder builder;
634 bool addedSpace = false; 656 bool addedSpace = false;
635 const CSSParserToken& firstToken = range.peek(); 657 const CSSParserToken& firstToken = range.peek();
636 while (range.peek().type() == IdentToken) { 658 while (range.peek().type() == IdentToken) {
637 if (!builder.isEmpty()) { 659 if (!builder.isEmpty()) {
638 builder.append(' '); 660 builder.append(' ');
639 addedSpace = true; 661 addedSpace = true;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 return consumeIdent(range); 724 return consumeIdent(range);
703 if (range.peek().id() == CSSValueNone) 725 if (range.peek().id() == CSSValueNone)
704 return consumeIdent(range); 726 return consumeIdent(range);
705 return consumePercent(range, ValueRangeNonNegative); 727 return consumePercent(range, ValueRangeNonNegative);
706 } 728 }
707 729
708 static CSSValue* consumeFontSize( 730 static CSSValue* consumeFontSize(
709 CSSParserTokenRange& range, 731 CSSParserTokenRange& range,
710 CSSParserMode cssParserMode, 732 CSSParserMode cssParserMode,
711 UnitlessQuirk unitless = UnitlessQuirk::Forbid) { 733 UnitlessQuirk unitless = UnitlessQuirk::Forbid) {
712 if (range.peek().id() >= CSSValueXxSmall && 734 switch (range.peek().id()) {
713 range.peek().id() <= CSSValueLarger) 735 case CSSValueXxSmall:
714 return consumeIdent(range); 736 case CSSValueXSmall:
715 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative, 737 case CSSValueSmall:
716 unitless); 738 case CSSValueMedium:
739 case CSSValueLarge:
740 case CSSValueXLarge:
741 case CSSValueXxLarge:
742 case CSSValueWebkitXxxLarge:
743 case CSSValueSmaller:
744 case CSSValueLarger:
745 return consumeIdent(range);
746 default:
747 return consumeLengthOrPercent(range, cssParserMode, ValueRangeNonNegative,
748 unitless);
749 }
717 } 750 }
718 751
719 static CSSValue* consumeLineHeight(CSSParserTokenRange& range, 752 static CSSValue* consumeLineHeight(CSSParserTokenRange& range,
720 CSSParserMode cssParserMode) { 753 CSSParserMode cssParserMode) {
721 if (range.peek().id() == CSSValueNormal) 754 if (range.peek().id() == CSSValueNormal)
722 return consumeIdent(range); 755 return consumeIdent(range);
723 756
724 CSSPrimitiveValue* lineHeight = consumeNumber(range, ValueRangeNonNegative); 757 CSSPrimitiveValue* lineHeight = consumeNumber(range, ValueRangeNonNegative);
725 if (lineHeight) 758 if (lineHeight)
726 return lineHeight; 759 return lineHeight;
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 else 1462 else
1430 return nullptr; 1463 return nullptr;
1431 } while (consumeCommaIncludingWhitespace(range)); 1464 } while (consumeCommaIncludingWhitespace(range));
1432 return shadowValueList; 1465 return shadowValueList;
1433 } 1466 }
1434 1467
1435 static CSSFunctionValue* consumeFilterFunction( 1468 static CSSFunctionValue* consumeFilterFunction(
1436 CSSParserTokenRange& range, 1469 CSSParserTokenRange& range,
1437 const CSSParserContext& context) { 1470 const CSSParserContext& context) {
1438 CSSValueID filterType = range.peek().functionId(); 1471 CSSValueID filterType = range.peek().functionId();
1439 if (filterType < CSSValueInvert || filterType > CSSValueDropShadow) 1472 if (filterType != CSSValueInvert && filterType != CSSValueGrayscale &&
1473 filterType != CSSValueSepia && filterType != CSSValueSaturate &&
1474 filterType != CSSValueHueRotate && filterType != CSSValueOpacity &&
1475 filterType != CSSValueBrightness && filterType != CSSValueContrast &&
1476 filterType != CSSValueBlur && filterType != CSSValueDropShadow)
1440 return nullptr; 1477 return nullptr;
1441 CSSParserTokenRange args = consumeFunction(range); 1478 CSSParserTokenRange args = consumeFunction(range);
1442 CSSFunctionValue* filterValue = CSSFunctionValue::create(filterType); 1479 CSSFunctionValue* filterValue = CSSFunctionValue::create(filterType);
1443 CSSValue* parsedValue = nullptr; 1480 CSSValue* parsedValue = nullptr;
1444 1481
1445 if (filterType == CSSValueDropShadow) { 1482 if (filterType == CSSValueDropShadow) {
1446 parsedValue = parseSingleShadow(args, context.mode(), false, false); 1483 parsedValue = parseSingleShadow(args, context.mode(), false, false);
1447 } else { 1484 } else {
1448 if (args.atEnd()) { 1485 if (args.atEnd()) {
1449 if (context.useCounter()) 1486 if (context.useCounter())
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 context.useCounter()->count(UseCounter::PrefixedCursorZoomIn); 2126 context.useCounter()->count(UseCounter::PrefixedCursorZoomIn);
2090 else if (id == CSSValueWebkitZoomOut) 2127 else if (id == CSSValueWebkitZoomOut)
2091 context.useCounter()->count(UseCounter::PrefixedCursorZoomOut); 2128 context.useCounter()->count(UseCounter::PrefixedCursorZoomOut);
2092 } 2129 }
2093 CSSValue* cursorType = nullptr; 2130 CSSValue* cursorType = nullptr;
2094 if (id == CSSValueHand) { 2131 if (id == CSSValueHand) {
2095 if (!inQuirksMode) // Non-standard behavior 2132 if (!inQuirksMode) // Non-standard behavior
2096 return nullptr; 2133 return nullptr;
2097 cursorType = CSSIdentifierValue::create(CSSValuePointer); 2134 cursorType = CSSIdentifierValue::create(CSSValuePointer);
2098 range.consumeIncludingWhitespace(); 2135 range.consumeIncludingWhitespace();
2099 } else if ((id >= CSSValueAuto && id <= CSSValueWebkitZoomOut) || 2136 } else if (
2137 id == CSSValueAuto ||
2138 id == CSSValueCrosshair ||
2139 id == CSSValueDefault ||
2140 id == CSSValuePointer ||
2141 id == CSSValueMove ||
2142 id == CSSValueVerticalText ||
2143 id == CSSValueCell ||
2144 id == CSSValueContextMenu ||
2145 id == CSSValueAlias ||
2146 id == CSSValueProgress ||
2147 id == CSSValueNoDrop ||
2148 id == CSSValueNotAllowed ||
2149 id == CSSValueZoomIn ||
2150 id == CSSValueZoomOut ||
2151 id == CSSValueEResize ||
2152 id == CSSValueNeResize ||
2153 id == CSSValueNwResize ||
2154 id == CSSValueNResize ||
2155 id == CSSValueSeResize ||
2156 id == CSSValueSwResize ||
2157 id == CSSValueSResize ||
2158 id == CSSValueWResize ||
2159 id == CSSValueEwResize ||
2160 id == CSSValueNsResize ||
2161 id == CSSValueNeswResize ||
2162 id == CSSValueNwseResize ||
2163 id == CSSValueColResize ||
2164 id == CSSValueRowResize ||
2165 id == CSSValueText ||
2166 id == CSSValueWait ||
2167 id == CSSValueHelp ||
2168 id == CSSValueAllScroll ||
2169 id == CSSValueWebkitGrab ||
2170 id == CSSValueWebkitGrabbing ||
2171 id == CSSValueWebkitZoomIn ||
2172 id == CSSValueWebkitZoomOut ||
2100 id == CSSValueCopy || id == CSSValueNone) { 2173 id == CSSValueCopy || id == CSSValueNone) {
2101 cursorType = consumeIdent(range); 2174 cursorType = consumeIdent(range);
2102 } else { 2175 } else {
2103 return nullptr; 2176 return nullptr;
2104 } 2177 }
2105 2178
2106 if (!list) 2179 if (!list)
2107 return cursorType; 2180 return cursorType;
2108 list->append(*cursorType); 2181 list->append(*cursorType);
2109 return list; 2182 return list;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 if (!consumeCommaIncludingWhitespace(args) || 2214 if (!consumeCommaIncludingWhitespace(args) ||
2142 args.peek().type() != StringToken) 2215 args.peek().type() != StringToken)
2143 return nullptr; 2216 return nullptr;
2144 separator = CSSStringValue::create( 2217 separator = CSSStringValue::create(
2145 args.consumeIncludingWhitespace().value().toString()); 2218 args.consumeIncludingWhitespace().value().toString());
2146 } 2219 }
2147 2220
2148 CSSIdentifierValue* listStyle = nullptr; 2221 CSSIdentifierValue* listStyle = nullptr;
2149 if (consumeCommaIncludingWhitespace(args)) { 2222 if (consumeCommaIncludingWhitespace(args)) {
2150 CSSValueID id = args.peek().id(); 2223 CSSValueID id = args.peek().id();
2151 if ((id != CSSValueNone && 2224 if (id != CSSValueNone &&
2152 (id < CSSValueDisc || id > CSSValueKatakanaIroha))) 2225 id != CSSValueDisc &&
2153 return nullptr; 2226 id != CSSValueCircle &&
2154 listStyle = consumeIdent(args); 2227 id != CSSValueSquare &&
2228 id != CSSValueDecimal &&
2229 id != CSSValueDecimalLeadingZero &&
2230 id != CSSValueArabicIndic &&
2231 id != CSSValueBengali &&
2232 id != CSSValueCambodian &&
2233 id != CSSValueKhmer &&
2234 id != CSSValueDevanagari &&
2235 id != CSSValueGujarati &&
2236 id != CSSValueGurmukhi &&
2237 id != CSSValueKannada &&
2238 id != CSSValueLao &&
2239 id != CSSValueMalayalam &&
2240 id != CSSValueMongolian &&
2241 id != CSSValueMyanmar &&
2242 id != CSSValueOriya &&
2243 id != CSSValuePersian &&
2244 id != CSSValueUrdu &&
2245 id != CSSValueTelugu &&
2246 id != CSSValueTibetan &&
2247 id != CSSValueThai &&
2248 id != CSSValueLowerRoman &&
2249 id != CSSValueUpperRoman &&
2250 id != CSSValueLowerGreek &&
2251 id != CSSValueLowerAlpha &&
2252 id != CSSValueLowerLatin &&
2253 id != CSSValueUpperAlpha &&
2254 id != CSSValueUpperLatin &&
2255 id != CSSValueCjkEarthlyBranch &&
2256 id != CSSValueCjkHeavenlyStem &&
2257 id != CSSValueEthiopicHalehame &&
2258 id != CSSValueEthiopicHalehameAm &&
2259 id != CSSValueEthiopicHalehameTiEr &&
2260 id != CSSValueEthiopicHalehameTiEt &&
2261 id != CSSValueHangul &&
2262 id != CSSValueHangulConsonant &&
2263 id != CSSValueKoreanHangulFormal &&
2264 id != CSSValueKoreanHanjaFormal &&
2265 id != CSSValueKoreanHanjaInformal &&
2266 id != CSSValueHebrew &&
2267 id != CSSValueArmenian &&
2268 id != CSSValueLowerArmenian &&
2269 id != CSSValueUpperArmenian &&
2270 id != CSSValueGeorgian &&
2271 id != CSSValueCjkIdeographic &&
2272 id != CSSValueSimpChineseFormal &&
2273 id != CSSValueSimpChineseInformal &&
2274 id != CSSValueTradChineseFormal &&
2275 id != CSSValueTradChineseInformal &&
2276 id != CSSValueHiragana &&
2277 id != CSSValueKatakana &&
2278 id != CSSValueHiraganaIroha &&
2279 id != CSSValueKatakanaIroha) {
2280 return nullptr;
2281 }
2282 listStyle = consumeIdent(args);
2155 } else { 2283 } else {
2156 listStyle = CSSIdentifierValue::create(CSSValueDecimal); 2284 listStyle = CSSIdentifierValue::create(CSSValueDecimal);
2157 } 2285 }
2158 2286
2159 if (!args.atEnd()) 2287 if (!args.atEnd())
2160 return nullptr; 2288 return nullptr;
2161 return CSSCounterValue::create(identifier, listStyle, separator); 2289 return CSSCounterValue::create(identifier, listStyle, separator);
2162 } 2290 }
2163 2291
2164 static CSSValue* consumeContent(CSSParserTokenRange& range, 2292 static CSSValue* consumeContent(CSSParserTokenRange& range,
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
2748 CSSPrimitiveValue* angle = consumeAngle(range); 2876 CSSPrimitiveValue* angle = consumeAngle(range);
2749 if (angle && angle->getDoubleValue() == 0) 2877 if (angle && angle->getDoubleValue() == 0)
2750 return angle; 2878 return angle;
2751 } 2879 }
2752 return nullptr; 2880 return nullptr;
2753 } 2881 }
2754 2882
2755 static CSSValue* consumeBackgroundBlendMode(CSSParserTokenRange& range) { 2883 static CSSValue* consumeBackgroundBlendMode(CSSParserTokenRange& range) {
2756 CSSValueID id = range.peek().id(); 2884 CSSValueID id = range.peek().id();
2757 if (id == CSSValueNormal || id == CSSValueOverlay || 2885 if (id == CSSValueNormal || id == CSSValueOverlay ||
2758 (id >= CSSValueMultiply && id <= CSSValueLuminosity)) 2886 id == CSSValueMultiply ||
2887 id == CSSValueScreen ||
2888 id == CSSValueDarken ||
2889 id == CSSValueLighten ||
2890 id == CSSValueColorDodge ||
2891 id == CSSValueColorBurn ||
2892 id == CSSValueHardLight ||
2893 id == CSSValueSoftLight ||
2894 id == CSSValueDifference ||
2895 id == CSSValueExclusion ||
2896 id == CSSValueHue ||
2897 id == CSSValueSaturation ||
2898 id == CSSValueColor ||
2899 id == CSSValueLuminosity)
2759 return consumeIdent(range); 2900 return consumeIdent(range);
2760 return nullptr; 2901 return nullptr;
2761 } 2902 }
2762 2903
2763 static CSSValue* consumeBackgroundAttachment(CSSParserTokenRange& range) { 2904 static CSSValue* consumeBackgroundAttachment(CSSParserTokenRange& range) {
2764 return consumeIdent<CSSValueScroll, CSSValueFixed, CSSValueLocal>(range); 2905 return consumeIdent<CSSValueScroll, CSSValueFixed, CSSValueLocal>(range);
2765 } 2906 }
2766 2907
2767 static CSSValue* consumeBackgroundBox(CSSParserTokenRange& range) { 2908 static CSSValue* consumeBackgroundBox(CSSParserTokenRange& range) {
2768 return consumeIdent<CSSValueBorderBox, CSSValuePaddingBox, 2909 return consumeIdent<CSSValueBorderBox, CSSValuePaddingBox,
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3969 break; 4110 break;
3970 } 4111 }
3971 4112
3972 if (!parsedValue || !m_range.atEnd()) 4113 if (!parsedValue || !m_range.atEnd())
3973 return false; 4114 return false;
3974 4115
3975 addProperty(propId, CSSPropertyInvalid, *parsedValue, false); 4116 addProperty(propId, CSSPropertyInvalid, *parsedValue, false);
3976 return true; 4117 return true;
3977 } 4118 }
3978 4119
4120 static bool isValidSystemFontValue(CSSValueID systemFontID) {
4121 return systemFontID == CSSValueCaption ||
4122 systemFontID == CSSValueIcon ||
4123 systemFontID == CSSValueMenu ||
4124 systemFontID == CSSValueMessageBox ||
4125 systemFontID == CSSValueSmallCaption ||
4126 systemFontID == CSSValueWebkitMiniControl ||
4127 systemFontID == CSSValueWebkitSmallControl ||
4128 systemFontID == CSSValueWebkitControl ||
4129 systemFontID == CSSValueStatusBar;
4130 }
4131
3979 bool CSSPropertyParser::consumeSystemFont(bool important) { 4132 bool CSSPropertyParser::consumeSystemFont(bool important) {
3980 CSSValueID systemFontID = m_range.consumeIncludingWhitespace().id(); 4133 CSSValueID systemFontID = m_range.consumeIncludingWhitespace().id();
3981 ASSERT(systemFontID >= CSSValueCaption && systemFontID <= CSSValueStatusBar); 4134 ASSERT(isValidSystemFontValue(systemFontID));
3982 if (!m_range.atEnd()) 4135 if (!m_range.atEnd())
3983 return false; 4136 return false;
3984 4137
3985 FontStyle fontStyle = FontStyleNormal; 4138 FontStyle fontStyle = FontStyleNormal;
3986 FontWeight fontWeight = FontWeightNormal; 4139 FontWeight fontWeight = FontWeightNormal;
3987 float fontSize = 0; 4140 float fontSize = 0;
3988 AtomicString fontFamily; 4141 AtomicString fontFamily;
3989 LayoutTheme::theme().systemFont(systemFontID, fontStyle, fontWeight, fontSize, 4142 LayoutTheme::theme().systemFont(systemFontID, fontStyle, fontWeight, fontSize,
3990 fontFamily); 4143 fontFamily);
3991 4144
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after
5141 else 5294 else
5142 overflowXValue = overflowYValue; 5295 overflowXValue = overflowYValue;
5143 addProperty(CSSPropertyOverflowX, CSSPropertyOverflow, *overflowXValue, 5296 addProperty(CSSPropertyOverflowX, CSSPropertyOverflow, *overflowXValue,
5144 important); 5297 important);
5145 addProperty(CSSPropertyOverflowY, CSSPropertyOverflow, *overflowYValue, 5298 addProperty(CSSPropertyOverflowY, CSSPropertyOverflow, *overflowYValue,
5146 important); 5299 important);
5147 return true; 5300 return true;
5148 } 5301 }
5149 case CSSPropertyFont: { 5302 case CSSPropertyFont: {
5150 const CSSParserToken& token = m_range.peek(); 5303 const CSSParserToken& token = m_range.peek();
5151 if (token.id() >= CSSValueCaption && token.id() <= CSSValueStatusBar) 5304 if (isValidSystemFontValue(token.id()))
5152 return consumeSystemFont(important); 5305 return consumeSystemFont(important);
5153 return consumeFont(important); 5306 return consumeFont(important);
5154 } 5307 }
5155 case CSSPropertyFontVariant: 5308 case CSSPropertyFontVariant:
5156 return consumeFontVariantShorthand(important); 5309 return consumeFontVariantShorthand(important);
5157 case CSSPropertyBorderSpacing: 5310 case CSSPropertyBorderSpacing:
5158 return consumeBorderSpacing(important); 5311 return consumeBorderSpacing(important);
5159 case CSSPropertyColumns: 5312 case CSSPropertyColumns:
5160 return consumeColumns(important); 5313 return consumeColumns(important);
5161 case CSSPropertyAnimation: 5314 case CSSPropertyAnimation:
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
5324 case CSSPropertyGridTemplate: 5477 case CSSPropertyGridTemplate:
5325 return consumeGridTemplateShorthand(CSSPropertyGridTemplate, important); 5478 return consumeGridTemplateShorthand(CSSPropertyGridTemplate, important);
5326 case CSSPropertyGrid: 5479 case CSSPropertyGrid:
5327 return consumeGridShorthand(important); 5480 return consumeGridShorthand(important);
5328 default: 5481 default:
5329 return false; 5482 return false;
5330 } 5483 }
5331 } 5484 }
5332 5485
5333 } // namespace blink 5486 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698