Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 2466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2477 case CSSPropertyTextLineThroughWidth: | 2477 case CSSPropertyTextLineThroughWidth: |
| 2478 case CSSPropertyTextOverlineWidth: | 2478 case CSSPropertyTextOverlineWidth: |
| 2479 case CSSPropertyTextUnderlineWidth: | 2479 case CSSPropertyTextUnderlineWidth: |
| 2480 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin || | 2480 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin || |
| 2481 id == CSSValueMedium || id == CSSValueThick) | 2481 id == CSSValueMedium || id == CSSValueThick) |
| 2482 validPrimitive = true; | 2482 validPrimitive = true; |
| 2483 else | 2483 else |
| 2484 validPrimitive = !id && validUnit(value, FNumber | FLength | FPercen t); | 2484 validPrimitive = !id && validUnit(value, FNumber | FLength | FPercen t); |
| 2485 break; | 2485 break; |
| 2486 case CSSPropertyWebkitColumnCount: | 2486 case CSSPropertyWebkitColumnCount: |
| 2487 if (id == CSSValueAuto) | 2487 parsedValue = parseColumnCount(); |
| 2488 validPrimitive = true; | |
| 2489 else | |
| 2490 validPrimitive = !id && validUnit(value, FPositiveInteger, CSSQuirks Mode); | |
| 2491 break; | 2488 break; |
| 2492 case CSSPropertyWebkitColumnGap: // normal | <length> | 2489 case CSSPropertyWebkitColumnGap: // normal | <length> |
| 2493 if (id == CSSValueNormal) | 2490 if (id == CSSValueNormal) |
| 2494 validPrimitive = true; | 2491 validPrimitive = true; |
| 2495 else | 2492 else |
| 2496 validPrimitive = validUnit(value, FLength | FNonNeg); | 2493 validPrimitive = validUnit(value, FLength | FNonNeg); |
| 2497 break; | 2494 break; |
| 2498 case CSSPropertyWebkitColumnAxis: | 2495 case CSSPropertyWebkitColumnAxis: |
| 2499 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValue Auto) | 2496 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValue Auto) |
| 2500 validPrimitive = true; | 2497 validPrimitive = true; |
| 2501 break; | 2498 break; |
| 2502 case CSSPropertyWebkitColumnProgression: | 2499 case CSSPropertyWebkitColumnProgression: |
| 2503 if (id == CSSValueNormal || id == CSSValueReverse) | 2500 if (id == CSSValueNormal || id == CSSValueReverse) |
| 2504 validPrimitive = true; | 2501 validPrimitive = true; |
| 2505 break; | 2502 break; |
| 2506 case CSSPropertyWebkitColumnSpan: // none | all | 1 (will be dropped in the unprefixed property) | 2503 case CSSPropertyWebkitColumnSpan: // none | all | 1 (will be dropped in the unprefixed property) |
| 2507 if (id == CSSValueAll || id == CSSValueNone) | 2504 if (id == CSSValueAll || id == CSSValueNone) |
| 2508 validPrimitive = true; | 2505 validPrimitive = true; |
| 2509 else | 2506 else |
| 2510 validPrimitive = validUnit(value, FNumber | FNonNeg) && value->fValu e == 1; | 2507 validPrimitive = validUnit(value, FNumber | FNonNeg) && value->fValu e == 1; |
| 2511 break; | 2508 break; |
| 2512 case CSSPropertyWebkitColumnWidth: // auto | <length> | 2509 case CSSPropertyWebkitColumnWidth: // auto | <length> |
| 2513 if (id == CSSValueAuto) | 2510 parsedValue = parseColumnWidth(); |
| 2514 validPrimitive = true; | |
| 2515 else // Always parse this property in strict mode, since it would be amb iguous otherwise when used in the 'columns' shorthand property. | |
| 2516 validPrimitive = validUnit(value, FLength | FNonNeg, CSSStrictMode) && value->fValue; | |
| 2517 break; | 2511 break; |
| 2518 // End of CSS3 properties | 2512 // End of CSS3 properties |
| 2519 | 2513 |
| 2520 // Apple specific properties. These will never be standardized and are pure ly to | 2514 // Apple specific properties. These will never be standardized and are pure ly to |
| 2521 // support custom WebKit-based Apple applications. | 2515 // support custom WebKit-based Apple applications. |
| 2522 case CSSPropertyWebkitLineClamp: | 2516 case CSSPropertyWebkitLineClamp: |
| 2523 // When specifying number of lines, don't allow 0 as a valid value | 2517 // When specifying number of lines, don't allow 0 as a valid value |
| 2524 // When specifying either type of unit, require non-negative integers | 2518 // When specifying either type of unit, require non-negative integers |
| 2525 validPrimitive = (!id && (value->unit == CSSPrimitiveValue::CSS_PERCENTA GE || value->fValue) && validUnit(value, FInteger | FPercent | FNonNeg, CSSQuirk sMode)); | 2519 validPrimitive = (!id && (value->unit == CSSPrimitiveValue::CSS_PERCENTA GE || value->fValue) && validUnit(value, FInteger | FPercent | FNonNeg, CSSQuirk sMode)); |
| 2526 break; | 2520 break; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2653 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? | 2647 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? |
| 2654 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit | 2648 // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit |
| 2655 if (id >= CSSValueCaption && id <= CSSValueStatusBar) | 2649 if (id >= CSSValueCaption && id <= CSSValueStatusBar) |
| 2656 validPrimitive = true; | 2650 validPrimitive = true; |
| 2657 else | 2651 else |
| 2658 return parseFont(important); | 2652 return parseFont(important); |
| 2659 break; | 2653 break; |
| 2660 case CSSPropertyListStyle: | 2654 case CSSPropertyListStyle: |
| 2661 return parseShorthand(propId, listStyleShorthand(), important); | 2655 return parseShorthand(propId, listStyleShorthand(), important); |
| 2662 case CSSPropertyWebkitColumns: | 2656 case CSSPropertyWebkitColumns: |
| 2663 return parseShorthand(propId, webkitColumnsShorthand(), important); | 2657 return parseColumnsShorthand(important); |
| 2664 case CSSPropertyWebkitColumnRule: | 2658 case CSSPropertyWebkitColumnRule: |
| 2665 return parseShorthand(propId, webkitColumnRuleShorthand(), important); | 2659 return parseShorthand(propId, webkitColumnRuleShorthand(), important); |
| 2666 case CSSPropertyWebkitTextStroke: | 2660 case CSSPropertyWebkitTextStroke: |
| 2667 return parseShorthand(propId, webkitTextStrokeShorthand(), important); | 2661 return parseShorthand(propId, webkitTextStrokeShorthand(), important); |
| 2668 case CSSPropertyWebkitAnimation: | 2662 case CSSPropertyWebkitAnimation: |
| 2669 return parseAnimationShorthand(important); | 2663 return parseAnimationShorthand(important); |
| 2670 case CSSPropertyTransition: | 2664 case CSSPropertyTransition: |
| 2671 case CSSPropertyWebkitTransition: | 2665 case CSSPropertyWebkitTransition: |
| 2672 return parseTransitionShorthand(propId, important); | 2666 return parseTransitionShorthand(propId, important); |
| 2673 case CSSPropertyInvalid: | 2667 case CSSPropertyInvalid: |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3203 addAnimationValue(values[i], cssValuePool().createImplicitInitialVal ue()); | 3197 addAnimationValue(values[i], cssValuePool().createImplicitInitialVal ue()); |
| 3204 } | 3198 } |
| 3205 | 3199 |
| 3206 // Now add all of the properties we found. | 3200 // Now add all of the properties we found. |
| 3207 for (i = 0; i < numProperties; i++) | 3201 for (i = 0; i < numProperties; i++) |
| 3208 addPropertyWithPrefixingVariant(shorthand.properties()[i], values[i].rel ease(), important); | 3202 addPropertyWithPrefixingVariant(shorthand.properties()[i], values[i].rel ease(), important); |
| 3209 | 3203 |
| 3210 return true; | 3204 return true; |
| 3211 } | 3205 } |
| 3212 | 3206 |
| 3207 PassRefPtr<CSSValue> CSSParser::parseColumnWidth() | |
| 3208 { | |
| 3209 CSSParserValue* value = m_valueList->current(); | |
| 3210 // Always parse lengths in strict mode here, since it would be ambiguous oth erwise when used in | |
| 3211 // the 'columns' shorthand property. | |
| 3212 if (value->id == CSSValueAuto | |
| 3213 || validUnit(value, FLength | FNonNeg, CSSStrictMode) && value->fValue) { | |
| 3214 RefPtr<CSSValue> parsedValue = parseValidPrimitive(value->id, value); | |
| 3215 m_valueList->next(); | |
| 3216 return parsedValue; | |
| 3217 } | |
| 3218 return 0; | |
| 3219 } | |
| 3220 | |
| 3221 PassRefPtr<CSSValue> CSSParser::parseColumnCount() | |
| 3222 { | |
| 3223 CSSParserValue* value = m_valueList->current(); | |
| 3224 if (value->id == CSSValueAuto | |
| 3225 || (!value->id && validUnit(value, FPositiveInteger, CSSQuirksMode))) { | |
| 3226 RefPtr<CSSValue> parsedValue = parseValidPrimitive(value->id, value); | |
| 3227 m_valueList->next(); | |
| 3228 return parsedValue; | |
| 3229 } | |
| 3230 return 0; | |
| 3231 } | |
| 3232 | |
| 3233 bool CSSParser::parseColumnsShorthand(bool important) | |
| 3234 { | |
| 3235 RefPtr <CSSValue> columnWidth; | |
| 3236 RefPtr <CSSValue> columnCount; | |
| 3237 bool hasPendingExplicitAuto = false; | |
| 3238 | |
| 3239 for (unsigned propertiesParsed = 0; CSSParserValue* value = m_valueList->cur rent(); propertiesParsed++) { | |
| 3240 if (propertiesParsed >= 2) | |
| 3241 return false; // Too many values for this shorthand. Invalid declara tion. | |
| 3242 if (!propertiesParsed && value->id == CSSValueAuto) { | |
| 3243 // 'auto' is a valid value for any of the two longhands, and at this point we | |
| 3244 // don't know which one(s) it is meant for. We need to see if there are other | |
| 3245 // values first. | |
| 3246 m_valueList->next(); | |
| 3247 hasPendingExplicitAuto = true; | |
| 3248 } else { | |
| 3249 if (columnWidth || !(columnWidth = parseColumnWidth())) { | |
|
Julien - ping for review
2013/07/26 20:14:39
The second part of the 'if' is unusual in Blink. S
mstensho (USE GERRIT)
2013/07/26 22:20:19
Done.
I omitted the "else"s, though. Otherwise it
| |
| 3250 if (columnCount || !(columnCount = parseColumnCount())) { | |
| 3251 // If we didn't find at least one match, this is an | |
| 3252 // invalid shorthand and we have to ignore it. | |
| 3253 return false; | |
| 3254 } | |
| 3255 } | |
| 3256 } | |
| 3257 } | |
| 3258 if (hasPendingExplicitAuto) { | |
| 3259 // Time to assign the previously skipped 'auto' value to a property. If both properties are | |
| 3260 // unassigned at this point (i.e. 'columns:auto'), it doesn't really mat ter which one we | |
| 3261 // set. The one we don't set will get an implicit 'auto' value further d own. | |
|
Julien - ping for review
2013/07/26 20:14:39
Note that it does make a difference when using the
mstensho (USE GERRIT)
2013/07/26 22:20:19
Right. That's undefined behavior. I guess it's pro
| |
| 3262 if (!columnWidth) { | |
| 3263 columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 3264 } else { | |
| 3265 ASSERT(!columnCount); | |
| 3266 columnCount = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 3267 } | |
| 3268 } | |
| 3269 ASSERT(columnCount || columnWidth); | |
| 3270 | |
| 3271 // Any unassigned property at this point will become implicit 'auto'. | |
| 3272 if (columnWidth) { | |
| 3273 addProperty(CSSPropertyWebkitColumnWidth, columnWidth, important); | |
| 3274 } else { | |
| 3275 ImplicitScope implicitScope(this, PropertyImplicit); | |
|
Julien - ping for review
2013/07/26 20:14:39
Note that you don't necessarily need the ImplicitS
mstensho (USE GERRIT)
2013/07/26 22:20:19
Nice! I failed to notice that. Got totally blinded
| |
| 3276 addProperty(CSSPropertyWebkitColumnWidth, cssValuePool().createIdentifie rValue(CSSValueAuto), important); | |
| 3277 } | |
| 3278 if (columnCount) { | |
| 3279 addProperty(CSSPropertyWebkitColumnCount, columnCount, important); | |
| 3280 } else { | |
| 3281 ImplicitScope implicitScope(this, PropertyImplicit); | |
| 3282 addProperty(CSSPropertyWebkitColumnCount, cssValuePool().createIdentifie rValue(CSSValueAuto), important); | |
| 3283 } | |
| 3284 return true; | |
| 3285 } | |
| 3286 | |
| 3213 bool CSSParser::parseShorthand(CSSPropertyID propId, const StylePropertyShorthan d& shorthand, bool important) | 3287 bool CSSParser::parseShorthand(CSSPropertyID propId, const StylePropertyShorthan d& shorthand, bool important) |
| 3214 { | 3288 { |
| 3215 // We try to match as many properties as possible | 3289 // We try to match as many properties as possible |
| 3216 // We set up an array of booleans to mark which property has been found, | 3290 // We set up an array of booleans to mark which property has been found, |
| 3217 // and we try to search for properties until it makes no longer any sense. | 3291 // and we try to search for properties until it makes no longer any sense. |
| 3218 ShorthandScope scope(this, propId); | 3292 ShorthandScope scope(this, propId); |
| 3219 | 3293 |
| 3220 bool found = false; | 3294 bool found = false; |
| 3221 unsigned propertiesParsed = 0; | 3295 unsigned propertiesParsed = 0; |
| 3222 bool propertyFound[6]= { false, false, false, false, false, false }; // 6 is enough size. | 3296 bool propertyFound[6]= { false, false, false, false, false, false }; // 6 is enough size. |
| (...skipping 8517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11740 { | 11814 { |
| 11741 // The tokenizer checks for the construct of an+b. | 11815 // The tokenizer checks for the construct of an+b. |
| 11742 // However, since the {ident} rule precedes the {nth} rule, some of those | 11816 // However, since the {ident} rule precedes the {nth} rule, some of those |
| 11743 // tokens are identified as string literal. Furthermore we need to accept | 11817 // tokens are identified as string literal. Furthermore we need to accept |
| 11744 // "odd" and "even" which does not match to an+b. | 11818 // "odd" and "even" which does not match to an+b. |
| 11745 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") | 11819 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") |
| 11746 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); | 11820 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); |
| 11747 } | 11821 } |
| 11748 | 11822 |
| 11749 } | 11823 } |
| OLD | NEW |