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

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: Take into account https://codereview.chromium.org/1708173002/ 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> consumeBackgroundClip(CSSParserTokenRang e& range)
3396 {
3397 return consumeIdent<CSSValueBorderBox, CSSValuePaddingBox, CSSValueContentBo x>(range);
3398 }
3399
3400 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundBlendMode(CSSParserToke nRange& range)
3401 {
3402 if (identMatches<CSSValueNormal, CSSValueOverlay>(range.peek().id()))
Timothy Loh 2016/02/19 04:11:13 I think it'd be clearer to not use these helpers h
rwlbuis 2016/02/21 18:22:08 Done.
3403 return consumeIdent(range);
3404 return consumeIdentRange(range, CSSValueMultiply, CSSValueLuminosity);
3405 }
3406
3407 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundAttachment(CSSParserTok enRange& range)
3408 {
3409 return consumeIdent<CSSValueScroll, CSSValueFixed, CSSValueLocal>(range);
3410 }
3411
3412 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundOrigin(CSSParserTokenRa nge& range)
Timothy Loh 2016/02/19 04:11:13 Can we merge this and consumeBackgroundClip and na
rwlbuis 2016/02/21 18:22:08 Done.
3413 {
3414 return consumeIdent<CSSValueBorderBox, CSSValuePaddingBox, CSSValueContentBo x>(range);
3415 }
3416
3417 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundComposite(CSSParserToke nRange& range)
3418 {
3419 return consumeIdentRange(range, CSSValueClear, CSSValuePlusLighter);
3420 }
3421
3422 static PassRefPtrWillBeRawPtr<CSSValue> consumeMaskSourceType(CSSParserTokenRang e& range)
3423 {
3424 ASSERT(RuntimeEnabledFeatures::cssMaskSourceTypeEnabled());
3425 return consumeIdent<CSSValueAuto, CSSValueAlpha, CSSValueLuminance>(range);
3426 }
3427
3428 static PassRefPtrWillBeRawPtr<CSSValue> consumeClipOrOrigin(CSSPropertyID proper ty, CSSParserTokenRange& range, const CSSParserContext& context)
Timothy Loh 2016/02/19 04:11:13 consumePrefixedBackgroundBox?
rwlbuis 2016/02/21 18:22:08 Done.
3429 {
3430 // CSSValueBorder, CSSValuePadding and CSSValueContent are deprecated and do not apply to the version of the property that has the -webkit- prefix removed.
Timothy Loh 2016/02/19 04:11:13 Maybe better to talk about the actual values and n
rwlbuis 2016/02/21 18:22:08 Done.
3431 if (RefPtrWillBeRawPtr<CSSValue> value = consumeIdentRange(range, CSSValueBo rder, CSSValuePaddingBox))
3432 return value.release();
3433 if ((property == CSSPropertyWebkitBackgroundClip || property == CSSPropertyW ebkitMaskClip) && range.peek().id() == CSSValueText)
3434 return consumeIdent(range);
3435 return nullptr;
3436 }
3437
3438 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundSize(CSSPropertyID unre solvedProperty, CSSParserTokenRange& range, CSSParserMode mode)
3439 {
3440 if (identMatches<CSSValueContain, CSSValueCover>(range.peek().id()))
3441 return consumeIdent(range);
3442
3443 RefPtrWillBeRawPtr<CSSPrimitiveValue> horizontal = consumeIdent<CSSValueAuto >(range);
3444 if (!horizontal)
3445 horizontal = consumeLengthOrPercent(range, mode, ValueRangeAll, Unitless Quirk::Forbid);
3446
3447 RefPtrWillBeRawPtr<CSSPrimitiveValue> vertical = nullptr;
3448 if (!range.atEnd()) {
3449 if (identMatches<CSSValueAuto>(range.peek().id())) // `auto' is the defa ult
Timothy Loh 2016/02/19 04:11:13 Why not just range.peek().id() == CSSValueAuto?
rwlbuis 2016/02/21 18:22:08 Done.
3450 range.consumeIncludingWhitespace();
3451 else
3452 vertical = consumeLengthOrPercent(range, mode, ValueRangeAll, Unitle ssQuirk::Forbid);
3453 } else if (unresolvedProperty == CSSPropertyAliasWebkitBackgroundSize) {
3454 // For backwards compatibility we set the second value to the first if i t is omitted.
Timothy Loh 2016/02/19 04:11:13 I don't think this needs to talk about masks here.
rwlbuis 2016/02/21 18:22:08 Done.
3455 // We only need to do this for -webkit-background-size. It should be saf e to let masks match
3456 // the real property.
3457 vertical = horizontal;
3458 }
3459 if (!vertical)
3460 return horizontal;
3461 return CSSValuePair::create(horizontal.release(), vertical.release(), CSSVal uePair::KeepIdenticalValues);
3462 }
3463
3464 static PassRefPtrWillBeRawPtr<CSSValue> consumeBackgroundComponent(CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& context)
Timothy Loh 2016/02/19 04:11:13 property -> unresolvedProperty
rwlbuis 2016/02/21 18:22:08 Done.
3465 {
3466 switch (property) {
3467 case CSSPropertyBackgroundClip:
3468 return consumeBackgroundClip(range);
3469 case CSSPropertyBackgroundBlendMode:
3470 return consumeBackgroundBlendMode(range);
3471 case CSSPropertyBackgroundAttachment:
3472 return consumeBackgroundAttachment(range);
3473 case CSSPropertyBackgroundOrigin:
3474 return consumeBackgroundOrigin(range);
3475 case CSSPropertyWebkitBackgroundComposite:
3476 case CSSPropertyWebkitMaskComposite:
3477 return consumeBackgroundComposite(range);
3478 case CSSPropertyMaskSourceType:
3479 return consumeMaskSourceType(range);
3480 case CSSPropertyWebkitBackgroundClip:
3481 case CSSPropertyWebkitBackgroundOrigin:
3482 case CSSPropertyWebkitMaskClip:
3483 case CSSPropertyWebkitMaskOrigin:
3484 return consumeClipOrOrigin(property, range, context);
3485 case CSSPropertyBackgroundImage:
3486 case CSSPropertyWebkitMaskImage:
3487 return consumeImage(range, context);
3488 case CSSPropertyBackgroundPositionX:
3489 case CSSPropertyWebkitMaskPositionX:
3490 return consumePositionX(range, context.mode());
3491 case CSSPropertyBackgroundPositionY:
3492 case CSSPropertyWebkitMaskPositionY:
3493 return consumePositionY(range, context.mode());
3494 case CSSPropertyBackgroundSize:
3495 case CSSPropertyAliasWebkitBackgroundSize:
3496 case CSSPropertyWebkitMaskSize:
3497 return consumeBackgroundSize(property, range, context.mode());
3498 case CSSPropertyBackgroundColor:
3499 return consumeColor(range, context.mode());
3500 default:
3501 break;
3502 };
3503 return nullptr;
3504 }
3505
3506 static void addBackgroundValue(RefPtrWillBeRawPtr<CSSValue>& lvalue, PassRefPtrW illBeRawPtr<CSSValue> rvalue)
Timothy Loh 2016/02/19 04:11:13 I think it'd help to write a comment like // To co
rwlbuis 2016/02/21 18:22:07 Done.
3507 {
3508 if (lvalue) {
3509 if (lvalue->isBaseValueList()) {
Timothy Loh 2016/02/19 04:11:13 How about if (!list->isBaseValueList()) { Ref
rwlbuis 2016/02/21 18:22:07 Done, except that I have to cast to CSSValueList :
3510 toCSSValueList(lvalue.get())->append(rvalue);
3511 } else {
3512 PassRefPtrWillBeRawPtr<CSSValue> oldlValue(lvalue.release());
3513 PassRefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createComm aSeparated();
3514 list->append(oldlValue);
3515 list->append(rvalue);
3516 lvalue = list;
3517 }
3518 } else {
3519 lvalue = rvalue;
3520 }
3521 }
3522
3523 static PassRefPtrWillBeRawPtr<CSSValue> consumeCommaSeparatedBackgroundComponent (CSSPropertyID property, CSSParserTokenRange& range, const CSSParserContext& con text)
3524 {
3525 RefPtrWillBeRawPtr<CSSValue> ret = nullptr;
Timothy Loh 2016/02/19 04:11:13 ret -> result
rwlbuis 2016/02/21 18:22:07 Done.
3526 do {
3527 RefPtrWillBeRawPtr<CSSValue> value = consumeBackgroundComponent(property , range, context);
3528 if (!value)
3529 return nullptr;
3530 addBackgroundValue(ret, value);
3531 } while (consumeCommaIncludingWhitespace(range));
3532 return ret.release();
3533 }
3534
3395 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) 3535 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty)
3396 { 3536 {
3397 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); 3537 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
3398 if (CSSParserFastPaths::isKeywordPropertyID(property)) { 3538 if (CSSParserFastPaths::isKeywordPropertyID(property)) {
3399 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_rang e.peek().id())) 3539 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(property, m_rang e.peek().id()))
3400 return nullptr; 3540 return nullptr;
3401 return consumeIdent(m_range); 3541 return consumeIdent(m_range);
3402 } 3542 }
3403 switch (property) { 3543 switch (property) {
3404 case CSSPropertyWillChange: 3544 case CSSPropertyWillChange:
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
3548 case CSSPropertyWebkitBorderEndColor: 3688 case CSSPropertyWebkitBorderEndColor:
3549 case CSSPropertyWebkitBorderBeforeColor: 3689 case CSSPropertyWebkitBorderBeforeColor:
3550 case CSSPropertyWebkitBorderAfterColor: 3690 case CSSPropertyWebkitBorderAfterColor:
3551 case CSSPropertyWebkitTextStrokeColor: 3691 case CSSPropertyWebkitTextStrokeColor:
3552 case CSSPropertyStopColor: 3692 case CSSPropertyStopColor:
3553 case CSSPropertyFloodColor: 3693 case CSSPropertyFloodColor:
3554 case CSSPropertyLightingColor: 3694 case CSSPropertyLightingColor:
3555 case CSSPropertyWebkitColumnRuleColor: 3695 case CSSPropertyWebkitColumnRuleColor:
3556 return consumeColor(m_range, m_context.mode()); 3696 return consumeColor(m_range, m_context.mode());
3557 case CSSPropertyColor: 3697 case CSSPropertyColor:
3698 case CSSPropertyBackgroundColor:
3558 return consumeColor(m_range, m_context.mode(), inQuirksMode()); 3699 return consumeColor(m_range, m_context.mode(), inQuirksMode());
3559 case CSSPropertyWebkitBorderStartWidth: 3700 case CSSPropertyWebkitBorderStartWidth:
3560 case CSSPropertyWebkitBorderEndWidth: 3701 case CSSPropertyWebkitBorderEndWidth:
3561 case CSSPropertyWebkitBorderBeforeWidth: 3702 case CSSPropertyWebkitBorderBeforeWidth:
3562 case CSSPropertyWebkitBorderAfterWidth: 3703 case CSSPropertyWebkitBorderAfterWidth:
3563 return consumeBorderWidth(m_range, m_context.mode(), UnitlessQuirk::Forb id); 3704 return consumeBorderWidth(m_range, m_context.mode(), UnitlessQuirk::Forb id);
3564 case CSSPropertyBorderBottomColor: 3705 case CSSPropertyBorderBottomColor:
3565 case CSSPropertyBorderLeftColor: 3706 case CSSPropertyBorderLeftColor:
3566 case CSSPropertyBorderRightColor: 3707 case CSSPropertyBorderRightColor:
3567 case CSSPropertyBorderTopColor: { 3708 case CSSPropertyBorderTopColor: {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
3717 case CSSPropertyWebkitBorderImage: 3858 case CSSPropertyWebkitBorderImage:
3718 return consumeWebkitBorderImage(property, m_range, m_context); 3859 return consumeWebkitBorderImage(property, m_range, m_context);
3719 case CSSPropertyWebkitBoxReflect: 3860 case CSSPropertyWebkitBoxReflect:
3720 return consumeReflect(m_range, m_context); 3861 return consumeReflect(m_range, m_context);
3721 case CSSPropertyFontSizeAdjust: 3862 case CSSPropertyFontSizeAdjust:
3722 ASSERT(RuntimeEnabledFeatures::cssFontSizeAdjustEnabled()); 3863 ASSERT(RuntimeEnabledFeatures::cssFontSizeAdjustEnabled());
3723 return consumeFontSizeAdjust(m_range); 3864 return consumeFontSizeAdjust(m_range);
3724 case CSSPropertyImageOrientation: 3865 case CSSPropertyImageOrientation:
3725 ASSERT(RuntimeEnabledFeatures::imageOrientationEnabled()); 3866 ASSERT(RuntimeEnabledFeatures::imageOrientationEnabled());
3726 return consumeImageOrientation(m_range, m_context.mode()); 3867 return consumeImageOrientation(m_range, m_context.mode());
3868 case CSSPropertyBackgroundClip:
Timothy Loh 2016/02/19 04:11:13 Probably looks better sorted ;)
rwlbuis 2016/02/21 18:22:08 Done.
3869 case CSSPropertyBackgroundBlendMode:
3870 case CSSPropertyBackgroundAttachment:
3871 case CSSPropertyBackgroundOrigin:
3872 case CSSPropertyWebkitBackgroundComposite:
3873 case CSSPropertyWebkitMaskComposite:
3874 case CSSPropertyMaskSourceType:
3875 case CSSPropertyWebkitBackgroundClip:
3876 case CSSPropertyWebkitBackgroundOrigin:
3877 case CSSPropertyWebkitMaskClip:
3878 case CSSPropertyWebkitMaskOrigin:
3879 case CSSPropertyBackgroundImage:
3880 case CSSPropertyWebkitMaskImage:
3881 case CSSPropertyBackgroundPositionX:
3882 case CSSPropertyWebkitMaskPositionX:
3883 case CSSPropertyBackgroundPositionY:
3884 case CSSPropertyWebkitMaskPositionY:
3885 case CSSPropertyBackgroundSize:
3886 case CSSPropertyWebkitMaskSize:
3887 return consumeCommaSeparatedBackgroundComponent(unresolvedProperty, m_ra nge, m_context);
3888 case CSSPropertyWebkitMaskRepeatX:
3889 case CSSPropertyWebkitMaskRepeatY:
3890 return nullptr;
3727 default: 3891 default:
3728 CSSParserValueList valueList(m_range); 3892 CSSParserValueList valueList(m_range);
3729 if (valueList.size()) { 3893 if (valueList.size()) {
3730 m_valueList = &valueList; 3894 m_valueList = &valueList;
3731 if (RefPtrWillBeRawPtr<CSSValue> result = legacyParseValue(unresolve dProperty)) { 3895 if (RefPtrWillBeRawPtr<CSSValue> result = legacyParseValue(unresolve dProperty)) {
3732 while (!m_range.atEnd()) 3896 while (!m_range.atEnd())
3733 m_range.consume(); 3897 m_range.consume();
3734 return result.release(); 3898 return result.release();
3735 } 3899 }
3736 } 3900 }
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
4511 m_currentShorthand = oldShorthand; 4675 m_currentShorthand = oldShorthand;
4512 CSSParserValueList valueList(m_range); 4676 CSSParserValueList valueList(m_range);
4513 if (!valueList.size()) 4677 if (!valueList.size())
4514 return false; 4678 return false;
4515 m_valueList = &valueList; 4679 m_valueList = &valueList;
4516 return legacyParseShorthand(unresolvedProperty, important); 4680 return legacyParseShorthand(unresolvedProperty, important);
4517 } 4681 }
4518 } 4682 }
4519 4683
4520 } // namespace blink 4684 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698