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

Side by Side Diff: Source/core/css/CSSParser-in.cpp

Issue 14334014: Parse "-webkit-columns: auto <length>" properly. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Compile fix Created 7 years, 5 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
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 2470 matching lines...) Expand 10 before | Expand all | Expand 10 after
2481 case CSSPropertyTextLineThroughWidth: 2481 case CSSPropertyTextLineThroughWidth:
2482 case CSSPropertyTextOverlineWidth: 2482 case CSSPropertyTextOverlineWidth:
2483 case CSSPropertyTextUnderlineWidth: 2483 case CSSPropertyTextUnderlineWidth:
2484 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin || 2484 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin ||
2485 id == CSSValueMedium || id == CSSValueThick) 2485 id == CSSValueMedium || id == CSSValueThick)
2486 validPrimitive = true; 2486 validPrimitive = true;
2487 else 2487 else
2488 validPrimitive = !id && validUnit(value, FNumber | FLength | FPercen t); 2488 validPrimitive = !id && validUnit(value, FNumber | FLength | FPercen t);
2489 break; 2489 break;
2490 case CSSPropertyWebkitColumnCount: 2490 case CSSPropertyWebkitColumnCount:
2491 if (id == CSSValueAuto) 2491 parsedValue = parseColumnCount();
2492 validPrimitive = true;
2493 else
2494 validPrimitive = !id && validUnit(value, FPositiveInteger, CSSQuirks Mode);
2495 break; 2492 break;
2496 case CSSPropertyWebkitColumnGap: // normal | <length> 2493 case CSSPropertyWebkitColumnGap: // normal | <length>
2497 if (id == CSSValueNormal) 2494 if (id == CSSValueNormal)
2498 validPrimitive = true; 2495 validPrimitive = true;
2499 else 2496 else
2500 validPrimitive = validUnit(value, FLength | FNonNeg); 2497 validPrimitive = validUnit(value, FLength | FNonNeg);
2501 break; 2498 break;
2502 case CSSPropertyWebkitColumnAxis: 2499 case CSSPropertyWebkitColumnAxis:
2503 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValue Auto) 2500 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValue Auto)
2504 validPrimitive = true; 2501 validPrimitive = true;
2505 break; 2502 break;
2506 case CSSPropertyWebkitColumnProgression: 2503 case CSSPropertyWebkitColumnProgression:
2507 if (id == CSSValueNormal || id == CSSValueReverse) 2504 if (id == CSSValueNormal || id == CSSValueReverse)
2508 validPrimitive = true; 2505 validPrimitive = true;
2509 break; 2506 break;
2510 case CSSPropertyWebkitColumnSpan: // none | all | 1 (will be dropped in the unprefixed property) 2507 case CSSPropertyWebkitColumnSpan: // none | all | 1 (will be dropped in the unprefixed property)
2511 if (id == CSSValueAll || id == CSSValueNone) 2508 if (id == CSSValueAll || id == CSSValueNone)
2512 validPrimitive = true; 2509 validPrimitive = true;
2513 else 2510 else
2514 validPrimitive = validUnit(value, FNumber | FNonNeg) && value->fValu e == 1; 2511 validPrimitive = validUnit(value, FNumber | FNonNeg) && value->fValu e == 1;
2515 break; 2512 break;
2516 case CSSPropertyWebkitColumnWidth: // auto | <length> 2513 case CSSPropertyWebkitColumnWidth: // auto | <length>
2517 if (id == CSSValueAuto) 2514 parsedValue = parseColumnWidth();
2518 validPrimitive = true;
2519 else // Always parse this property in strict mode, since it would be amb iguous otherwise when used in the 'columns' shorthand property.
2520 validPrimitive = validUnit(value, FLength | FNonNeg, CSSStrictMode) && value->fValue;
2521 break; 2515 break;
2522 // End of CSS3 properties 2516 // End of CSS3 properties
2523 2517
2524 // Apple specific properties. These will never be standardized and are pure ly to 2518 // Apple specific properties. These will never be standardized and are pure ly to
2525 // support custom WebKit-based Apple applications. 2519 // support custom WebKit-based Apple applications.
2526 case CSSPropertyWebkitLineClamp: 2520 case CSSPropertyWebkitLineClamp:
2527 // When specifying number of lines, don't allow 0 as a valid value 2521 // When specifying number of lines, don't allow 0 as a valid value
2528 // When specifying either type of unit, require non-negative integers 2522 // When specifying either type of unit, require non-negative integers
2529 validPrimitive = (!id && (value->unit == CSSPrimitiveValue::CSS_PERCENTA GE || value->fValue) && validUnit(value, FInteger | FPercent | FNonNeg, CSSQuirk sMode)); 2523 validPrimitive = (!id && (value->unit == CSSPrimitiveValue::CSS_PERCENTA GE || value->fValue) && validUnit(value, FInteger | FPercent | FNonNeg, CSSQuirk sMode));
2530 break; 2524 break;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2657 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? 2651 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
2658 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit 2652 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
2659 if (id >= CSSValueCaption && id <= CSSValueStatusBar) 2653 if (id >= CSSValueCaption && id <= CSSValueStatusBar)
2660 validPrimitive = true; 2654 validPrimitive = true;
2661 else 2655 else
2662 return parseFont(important); 2656 return parseFont(important);
2663 break; 2657 break;
2664 case CSSPropertyListStyle: 2658 case CSSPropertyListStyle:
2665 return parseShorthand(propId, listStyleShorthand(), important); 2659 return parseShorthand(propId, listStyleShorthand(), important);
2666 case CSSPropertyWebkitColumns: 2660 case CSSPropertyWebkitColumns:
2667 return parseShorthand(propId, webkitColumnsShorthand(), important); 2661 return parseColumnsShorthand(important);
2668 case CSSPropertyWebkitColumnRule: 2662 case CSSPropertyWebkitColumnRule:
2669 return parseShorthand(propId, webkitColumnRuleShorthand(), important); 2663 return parseShorthand(propId, webkitColumnRuleShorthand(), important);
2670 case CSSPropertyWebkitTextStroke: 2664 case CSSPropertyWebkitTextStroke:
2671 return parseShorthand(propId, webkitTextStrokeShorthand(), important); 2665 return parseShorthand(propId, webkitTextStrokeShorthand(), important);
2672 case CSSPropertyWebkitAnimation: 2666 case CSSPropertyWebkitAnimation:
2673 return parseAnimationShorthand(important); 2667 return parseAnimationShorthand(important);
2674 case CSSPropertyTransition: 2668 case CSSPropertyTransition:
2675 case CSSPropertyWebkitTransition: 2669 case CSSPropertyWebkitTransition:
2676 return parseTransitionShorthand(propId, important); 2670 return parseTransitionShorthand(propId, important);
2677 case CSSPropertyInvalid: 2671 case CSSPropertyInvalid:
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
3207 addAnimationValue(values[i], cssValuePool().createImplicitInitialVal ue()); 3201 addAnimationValue(values[i], cssValuePool().createImplicitInitialVal ue());
3208 } 3202 }
3209 3203
3210 // Now add all of the properties we found. 3204 // Now add all of the properties we found.
3211 for (i = 0; i < numProperties; i++) 3205 for (i = 0; i < numProperties; i++)
3212 addPropertyWithPrefixingVariant(shorthand.properties()[i], values[i].rel ease(), important); 3206 addPropertyWithPrefixingVariant(shorthand.properties()[i], values[i].rel ease(), important);
3213 3207
3214 return true; 3208 return true;
3215 } 3209 }
3216 3210
3211 PassRefPtr<CSSValue> CSSParser::parseColumnWidth()
3212 {
3213 CSSParserValue* value = m_valueList->current();
3214 // Always parse lengths in strict mode here, since it would be ambiguous oth erwise when used in
3215 // the 'columns' shorthand property.
3216 if (value->id == CSSValueAuto
3217 || (validUnit(value, FLength | FNonNeg, CSSStrictMode) && value->fValue) ) {
3218 RefPtr<CSSValue> parsedValue = parseValidPrimitive(value->id, value);
3219 m_valueList->next();
3220 return parsedValue;
3221 }
3222 return 0;
3223 }
3224
3225 PassRefPtr<CSSValue> CSSParser::parseColumnCount()
3226 {
3227 CSSParserValue* value = m_valueList->current();
3228 if (value->id == CSSValueAuto
3229 || (!value->id && validUnit(value, FPositiveInteger, CSSQuirksMode))) {
3230 RefPtr<CSSValue> parsedValue = parseValidPrimitive(value->id, value);
3231 m_valueList->next();
3232 return parsedValue;
3233 }
3234 return 0;
3235 }
3236
3237 bool CSSParser::parseColumnsShorthand(bool important)
3238 {
3239 RefPtr <CSSValue> columnWidth;
3240 RefPtr <CSSValue> columnCount;
3241 bool hasPendingExplicitAuto = false;
3242
3243 for (unsigned propertiesParsed = 0; CSSParserValue* value = m_valueList->cur rent(); propertiesParsed++) {
3244 if (propertiesParsed >= 2)
3245 return false; // Too many values for this shorthand. Invalid declara tion.
3246 if (!propertiesParsed && value->id == CSSValueAuto) {
3247 // 'auto' is a valid value for any of the two longhands, and at this point we
3248 // don't know which one(s) it is meant for. We need to see if there are other
3249 // values first.
3250 m_valueList->next();
3251 hasPendingExplicitAuto = true;
3252 } else {
3253 if (!columnWidth) {
3254 if ((columnWidth = parseColumnWidth()))
3255 continue;
3256 }
3257 if (!columnCount) {
3258 if ((columnCount = parseColumnCount()))
3259 continue;
3260 }
3261 // If we didn't find at least one match, this is an
3262 // invalid shorthand and we have to ignore it.
3263 return false;
3264 }
3265 }
3266 if (hasPendingExplicitAuto) {
3267 // Time to assign the previously skipped 'auto' value to a property. If both properties are
3268 // unassigned at this point (i.e. 'columns:auto'), it doesn't matter tha t much which one we
3269 // set (although it does make a slight difference to web-inspector). The one we don't set
3270 // here will get an implicit 'auto' value further down.
3271 if (!columnWidth) {
3272 columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto);
3273 } else {
3274 ASSERT(!columnCount);
3275 columnCount = cssValuePool().createIdentifierValue(CSSValueAuto);
3276 }
3277 }
3278 ASSERT(columnCount || columnWidth);
3279
3280 // Any unassigned property at this point will become implicit 'auto'.
3281 if (columnWidth)
3282 addProperty(CSSPropertyWebkitColumnWidth, columnWidth, important);
3283 else
3284 addProperty(CSSPropertyWebkitColumnWidth, cssValuePool().createIdentifie rValue(CSSValueAuto), important, true /* implicit */);
3285 if (columnCount)
3286 addProperty(CSSPropertyWebkitColumnCount, columnCount, important);
3287 else
3288 addProperty(CSSPropertyWebkitColumnCount, cssValuePool().createIdentifie rValue(CSSValueAuto), important, true /* implicit */);
3289 return true;
3290 }
3291
3217 bool CSSParser::parseShorthand(CSSPropertyID propId, const StylePropertyShorthan d& shorthand, bool important) 3292 bool CSSParser::parseShorthand(CSSPropertyID propId, const StylePropertyShorthan d& shorthand, bool important)
3218 { 3293 {
3219 // We try to match as many properties as possible 3294 // We try to match as many properties as possible
3220 // We set up an array of booleans to mark which property has been found, 3295 // We set up an array of booleans to mark which property has been found,
3221 // and we try to search for properties until it makes no longer any sense. 3296 // and we try to search for properties until it makes no longer any sense.
3222 ShorthandScope scope(this, propId); 3297 ShorthandScope scope(this, propId);
3223 3298
3224 bool found = false; 3299 bool found = false;
3225 unsigned propertiesParsed = 0; 3300 unsigned propertiesParsed = 0;
3226 bool propertyFound[6]= { false, false, false, false, false, false }; // 6 is enough size. 3301 bool propertyFound[6]= { false, false, false, false, false, false }; // 6 is enough size.
(...skipping 8446 matching lines...) Expand 10 before | Expand all | Expand 10 after
11673 { 11748 {
11674 // The tokenizer checks for the construct of an+b. 11749 // The tokenizer checks for the construct of an+b.
11675 // However, since the {ident} rule precedes the {nth} rule, some of those 11750 // However, since the {ident} rule precedes the {nth} rule, some of those
11676 // tokens are identified as string literal. Furthermore we need to accept 11751 // tokens are identified as string literal. Furthermore we need to accept
11677 // "odd" and "even" which does not match to an+b. 11752 // "odd" and "even" which does not match to an+b.
11678 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") 11753 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even")
11679 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); 11754 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
11680 } 11755 }
11681 11756
11682 } 11757 }
OLDNEW
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698