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

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

Issue 1706573002: Move background related longhands into CSSPropertyParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix logic error Created 4 years, 10 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 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/CSSCalculationValue.h" 10 #include "core/css/CSSCalculationValue.h"
(...skipping 3374 matching lines...) Expand 10 before | Expand all | Expand 10 after
3385 if (range.peek().id() == CSSValueFromImage) 3385 if (range.peek().id() == CSSValueFromImage)
3386 return consumeIdent(range); 3386 return consumeIdent(range);
3387 if (range.peek().type() != NumberToken) { 3387 if (range.peek().type() != NumberToken) {
3388 RefPtrWillBeRawPtr<CSSPrimitiveValue> angle = consumeAngle(range, cssPar serMode); 3388 RefPtrWillBeRawPtr<CSSPrimitiveValue> angle = consumeAngle(range, cssPar serMode);
3389 if (angle && angle->getDoubleValue() == 0) 3389 if (angle && angle->getDoubleValue() == 0)
3390 return angle; 3390 return angle;
3391 } 3391 }
3392 return nullptr; 3392 return nullptr;
3393 } 3393 }
3394 3394
3395 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundBlendMode(CSSParserToke nRange& range)
3396 {
3397 CSSValueID id = range.peek().id();
3398 if (id == CSSValueNormal || id == CSSValueOverlay || (id >= CSSValueMultiply && id <= CSSValueLuminosity))
3399 return consumeIdent(range);
3400 return nullptr;
3401 }
3402
3403 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundAttachment(CSSParserTok enRange& range)
3404 {
3405 return consumeIdent<CSSValueScroll, CSSValueFixed, CSSValueLocal>(range);
3406 }
3407
3408 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundBox(CSSParserTokenRange & range)
3409 {
3410 return consumeIdent<CSSValueBorderBox, CSSValuePaddingBox, CSSValueContentBo x>(range);
3411 }
3412
3413 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundComposite(CSSParserToke nRange& range)
3414 {
3415 return consumeIdentRange(range, CSSValueClear, CSSValuePlusLighter);
3416 }
3417
3418 static PassRefPtrWillBeRawPtr<CSSValue> consumeMaskSourceType(CSSParserTokenRang e& range)
3419 {
3420 ASSERT(RuntimeEnabledFeatures::cssMaskSourceTypeEnabled());
3421 return consumeIdent<CSSValueAuto, CSSValueAlpha, CSSValueLuminance>(range);
3422 }
3423
3424 static PassRefPtrWillBeRawPtr<CSSValue> consumePrefixedBackgroundBox(CSSProperty ID property, CSSParserTokenRange& range, const CSSParserContext& context)
3425 {
3426 // The values 'border', 'padding' and 'content' are deprecated and do not ap ply to the version of the property that has the -webkit- prefix removed.
3427 if (RefPtrWillBeRawPtr<CSSValue> value = consumeIdentRange(range, CSSValueBo rder, CSSValuePaddingBox))
3428 return value.release();
3429 if ((property == CSSPropertyWebkitBackgroundClip || property == CSSPropertyW ebkitMaskClip) && range.peek().id() == CSSValueText)
3430 return consumeIdent(range);
3431 return nullptr;
3432 }
3433
3434 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundSize(CSSPropertyID unre solvedProperty, CSSParserTokenRange& range, CSSParserMode mode)
3435 {
3436 if (identMatches<CSSValueContain, CSSValueCover>(range.peek().id()))
3437 return consumeIdent(range);
3438
3439 RefPtrWillBeRawPtr<CSSPrimitiveValue> horizontal = consumeIdent<CSSValueAuto >(range);
3440 if (!horizontal)
3441 horizontal = consumeLengthOrPercent(range, mode, ValueRangeAll, Unitless Quirk::Forbid);
3442
3443 RefPtrWillBeRawPtr<CSSPrimitiveValue> vertical = nullptr;
3444 if (!range.atEnd()) {
3445 if (range.peek().id() == CSSValueAuto) // `auto' is the default
3446 range.consumeIncludingWhitespace();
3447 else
3448 vertical = consumeLengthOrPercent(range, mode, ValueRangeAll, Unitle ssQuirk::Forbid);
3449 } else if (unresolvedProperty == CSSPropertyAliasWebkitBackgroundSize) {
3450 // Legacy syntax: "-webkit-background-size: 10px" is equivalent to "back ground-size: 10px 10px".
3451 vertical = horizontal;
3452 }
3453 if (!vertical)
3454 return horizontal;
3455 return CSSValuePair::create(horizontal.release(), vertical.release(), CSSVal uePair::KeepIdenticalValues);
3456 }
3457
3458 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundComponent(CSSPropertyID unresolvedProperty, CSSParserTokenRange& range, const CSSParserContext& context )
3459 {
3460 switch (unresolvedProperty) {
3461 case CSSPropertyBackgroundClip:
3462 return consumeBackgroundBox(range);
3463 case CSSPropertyBackgroundBlendMode:
3464 return consumeBackgroundBlendMode(range);
3465 case CSSPropertyBackgroundAttachment:
3466 return consumeBackgroundAttachment(range);
3467 case CSSPropertyBackgroundOrigin:
3468 return consumeBackgroundBox(range);
3469 case CSSPropertyWebkitBackgroundComposite:
3470 case CSSPropertyWebkitMaskComposite:
3471 return consumeBackgroundComposite(range);
3472 case CSSPropertyMaskSourceType:
3473 return consumeMaskSourceType(range);
3474 case CSSPropertyWebkitBackgroundClip:
3475 case CSSPropertyWebkitBackgroundOrigin:
3476 case CSSPropertyWebkitMaskClip:
3477 case CSSPropertyWebkitMaskOrigin:
3478 return consumePrefixedBackgroundBox(unresolvedProperty, range, context);
3479 case CSSPropertyBackgroundImage:
3480 case CSSPropertyWebkitMaskImage:
3481 return consumeImage(range, context);
3482 case CSSPropertyBackgroundPositionX:
3483 case CSSPropertyWebkitMaskPositionX:
3484 return consumePositionX(range, context.mode());
3485 case CSSPropertyBackgroundPositionY:
3486 case CSSPropertyWebkitMaskPositionY:
3487 return consumePositionY(range, context.mode());
3488 case CSSPropertyBackgroundSize:
3489 case CSSPropertyAliasWebkitBackgroundSize:
3490 case CSSPropertyWebkitMaskSize:
3491 return consumeBackgroundSize(unresolvedProperty, range, context.mode());
3492 case CSSPropertyBackgroundColor:
3493 return consumeColor(range, context.mode());
3494 default:
3495 break;
3496 };
3497 return nullptr;
3498 }
3499
3500 static void addBackgroundValue(RefPtrWillBeRawPtr<CSSValue>& list, PassRefPtrWil lBeRawPtr<CSSValue> value)
3501 {
3502 if (list) {
3503 if (!list->isBaseValueList()) {
3504 RefPtrWillBeRawPtr<CSSValue> firstValue = list.release();
3505 list = CSSValueList::createCommaSeparated();
3506 toCSSValueList(list.get())->append(firstValue.release());
3507 }
3508 toCSSValueList(list.get())->append(value);
3509 } else {
3510 // To conserve memory we don't actually wrap a single value in a list.
3511 list = value;
3512 }
3513 }
3514
3515 static PassRefPtrWillBeRawPtr<CSSValue> consumeCommaSeparatedBackgroundComponent (CSSPropertyID unresolvedProperty, CSSParserTokenRange& range, const CSSParserCo ntext& context)
3516 {
3517 RefPtrWillBeRawPtr<CSSValue> result = nullptr;
3518 do {
3519 RefPtrWillBeRawPtr<CSSValue> value = consumeBackgroundComponent(unresolv edProperty, range, context);
3520 if (!value)
3521 return nullptr;
3522 addBackgroundValue(result, value);
3523 } while (consumeCommaIncludingWhitespace(range));
3524 return result.release();
3525 }
3526
3395 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) 3527 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty)
3396 { 3528 {
3397 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); 3529 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
3398 if (CSSParserFastPaths::isKeywordPropertyID(property)) { 3530 if (CSSParserFastPaths::isKeywordPropertyID(property)) {
3399 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_rang e.peek().id())) 3531 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_rang e.peek().id()))
3400 return nullptr; 3532 return nullptr;
3401 return consumeIdent(m_range); 3533 return consumeIdent(m_range);
3402 } 3534 }
3403 switch (property) { 3535 switch (property) {
3404 case CSSPropertyWillChange: 3536 case CSSPropertyWillChange:
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
3548 case CSSPropertyWebkitBorderEndColor: 3680 case CSSPropertyWebkitBorderEndColor:
3549 case CSSPropertyWebkitBorderBeforeColor: 3681 case CSSPropertyWebkitBorderBeforeColor:
3550 case CSSPropertyWebkitBorderAfterColor: 3682 case CSSPropertyWebkitBorderAfterColor:
3551 case CSSPropertyWebkitTextStrokeColor: 3683 case CSSPropertyWebkitTextStrokeColor:
3552 case CSSPropertyStopColor: 3684 case CSSPropertyStopColor:
3553 case CSSPropertyFloodColor: 3685 case CSSPropertyFloodColor:
3554 case CSSPropertyLightingColor: 3686 case CSSPropertyLightingColor:
3555 case CSSPropertyColumnRuleColor: 3687 case CSSPropertyColumnRuleColor:
3556 return consumeColor(m_range, m_context.mode()); 3688 return consumeColor(m_range, m_context.mode());
3557 case CSSPropertyColor: 3689 case CSSPropertyColor:
3690 case CSSPropertyBackgroundColor:
3558 return consumeColor(m_range, m_context.mode(), inQuirksMode()); 3691 return consumeColor(m_range, m_context.mode(), inQuirksMode());
3559 case CSSPropertyWebkitBorderStartWidth: 3692 case CSSPropertyWebkitBorderStartWidth:
3560 case CSSPropertyWebkitBorderEndWidth: 3693 case CSSPropertyWebkitBorderEndWidth:
3561 case CSSPropertyWebkitBorderBeforeWidth: 3694 case CSSPropertyWebkitBorderBeforeWidth:
3562 case CSSPropertyWebkitBorderAfterWidth: 3695 case CSSPropertyWebkitBorderAfterWidth:
3563 return consumeBorderWidth(m_range, m_context.mode(), UnitlessQuirk::Forb id); 3696 return consumeBorderWidth(m_range, m_context.mode(), UnitlessQuirk::Forb id);
3564 case CSSPropertyBorderBottomColor: 3697 case CSSPropertyBorderBottomColor:
3565 case CSSPropertyBorderLeftColor: 3698 case CSSPropertyBorderLeftColor:
3566 case CSSPropertyBorderRightColor: 3699 case CSSPropertyBorderRightColor:
3567 case CSSPropertyBorderTopColor: { 3700 case CSSPropertyBorderTopColor: {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
3717 case CSSPropertyWebkitBorderImage: 3850 case CSSPropertyWebkitBorderImage:
3718 return consumeWebkitBorderImage(property, m_range, m_context); 3851 return consumeWebkitBorderImage(property, m_range, m_context);
3719 case CSSPropertyWebkitBoxReflect: 3852 case CSSPropertyWebkitBoxReflect:
3720 return consumeReflect(m_range, m_context); 3853 return consumeReflect(m_range, m_context);
3721 case CSSPropertyFontSizeAdjust: 3854 case CSSPropertyFontSizeAdjust:
3722 ASSERT(RuntimeEnabledFeatures::cssFontSizeAdjustEnabled()); 3855 ASSERT(RuntimeEnabledFeatures::cssFontSizeAdjustEnabled());
3723 return consumeFontSizeAdjust(m_range); 3856 return consumeFontSizeAdjust(m_range);
3724 case CSSPropertyImageOrientation: 3857 case CSSPropertyImageOrientation:
3725 ASSERT(RuntimeEnabledFeatures::imageOrientationEnabled()); 3858 ASSERT(RuntimeEnabledFeatures::imageOrientationEnabled());
3726 return consumeImageOrientation(m_range, m_context.mode()); 3859 return consumeImageOrientation(m_range, m_context.mode());
3860 case CSSPropertyBackgroundAttachment:
3861 case CSSPropertyBackgroundBlendMode:
3862 case CSSPropertyBackgroundClip:
3863 case CSSPropertyBackgroundImage:
3864 case CSSPropertyBackgroundOrigin:
3865 case CSSPropertyBackgroundPositionX:
3866 case CSSPropertyBackgroundPositionY:
3867 case CSSPropertyBackgroundSize:
3868 case CSSPropertyMaskSourceType:
3869 case CSSPropertyWebkitBackgroundComposite:
3870 case CSSPropertyWebkitBackgroundClip:
3871 case CSSPropertyWebkitBackgroundOrigin:
3872 case CSSPropertyWebkitMaskClip:
3873 case CSSPropertyWebkitMaskComposite:
3874 case CSSPropertyWebkitMaskImage:
3875 case CSSPropertyWebkitMaskOrigin:
3876 case CSSPropertyWebkitMaskPositionX:
3877 case CSSPropertyWebkitMaskPositionY:
3878 case CSSPropertyWebkitMaskSize:
3879 return consumeCommaSeparatedBackgroundComponent(unresolvedProperty, m_ra nge, m_context);
3880 case CSSPropertyWebkitMaskRepeatX:
3881 case CSSPropertyWebkitMaskRepeatY:
3882 return nullptr;
3727 default: 3883 default:
3728 CSSParserValueList valueList(m_range); 3884 CSSParserValueList valueList(m_range);
3729 if (valueList.size()) { 3885 if (valueList.size()) {
3730 m_valueList = &valueList; 3886 m_valueList = &valueList;
3731 if (RefPtrWillBeRawPtr<CSSValue> result = legacyParseValue(unresolve dProperty)) { 3887 if (RefPtrWillBeRawPtr<CSSValue> result = legacyParseValue(unresolve dProperty)) {
3732 while (!m_range.atEnd()) 3888 while (!m_range.atEnd())
3733 m_range.consume(); 3889 m_range.consume();
3734 return result.release(); 3890 return result.release();
3735 } 3891 }
3736 } 3892 }
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
4511 m_currentShorthand = oldShorthand; 4667 m_currentShorthand = oldShorthand;
4512 CSSParserValueList valueList(m_range); 4668 CSSParserValueList valueList(m_range);
4513 if (!valueList.size()) 4669 if (!valueList.size())
4514 return false; 4670 return false;
4515 m_valueList = &valueList; 4671 m_valueList = &valueList;
4516 return legacyParseShorthand(unresolvedProperty, important); 4672 return legacyParseShorthand(unresolvedProperty, important);
4517 } 4673 }
4518 } 4674 }
4519 4675
4520 } // namespace blink 4676 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698