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

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

Issue 1715513002: Move background related shorthands into CSSPropertyParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase tests 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 4504 matching lines...) Expand 10 before | Expand all | Expand 10 after
4515 ASSERT_NOT_REACHED(); 4515 ASSERT_NOT_REACHED();
4516 } 4516 }
4517 if (value == CSSValueInvalid) 4517 if (value == CSSValueInvalid)
4518 return false; 4518 return false;
4519 4519
4520 CSSPropertyID genericBreakProperty = mapFromLegacyBreakProperty(property); 4520 CSSPropertyID genericBreakProperty = mapFromLegacyBreakProperty(property);
4521 addProperty(genericBreakProperty, cssValuePool().createIdentifierValue(value ), important); 4521 addProperty(genericBreakProperty, cssValuePool().createIdentifierValue(value ), important);
4522 return true; 4522 return true;
4523 } 4523 }
4524 4524
4525 static bool consumeBackgroundPosition(CSSParserTokenRange& range, const CSSParse rContext& context, UnitlessQuirk unitless, RefPtrWillBeRawPtr<CSSValue>& resultX , RefPtrWillBeRawPtr<CSSValue>& resultY)
4526 {
4527 do {
4528 RefPtrWillBeRawPtr<CSSValue> positionX = nullptr;
4529 RefPtrWillBeRawPtr<CSSValue> positionY = nullptr;
4530 if (!consumePosition(range, context.mode(), unitless, positionX, positio nY))
4531 return false;
4532 addBackgroundValue(resultX, positionX);
4533 if (positionY)
Timothy Loh 2016/02/23 05:53:15 I think both always get set if consumePosition ret
rwlbuis 2016/02/23 20:16:42 Done.
4534 addBackgroundValue(resultY, positionY);
4535 } while (consumeCommaIncludingWhitespace(range));
4536 return resultX;
Timothy Loh 2016/02/23 05:53:14 return true?
rwlbuis 2016/02/23 20:16:42 Done, also in consumeRepeatStyle.
4537 }
4538
4539 static bool consumeRepeatStyleComponent(CSSParserTokenRange& range, RefPtrWillBe RawPtr<CSSValue>& value1, RefPtrWillBeRawPtr<CSSValue>& value2, bool& implicit)
4540 {
4541 if (consumeIdent<CSSValueRepeatX>(range)) {
4542 value1 = cssValuePool().createIdentifierValue(CSSValueRepeat);
4543 value2 = cssValuePool().createIdentifierValue(CSSValueNoRepeat);
4544 implicit = true;
4545 return true;
4546 }
4547 if (consumeIdent<CSSValueRepeatY>(range)) {
4548 value1 = cssValuePool().createIdentifierValue(CSSValueNoRepeat);
4549 value2 = cssValuePool().createIdentifierValue(CSSValueRepeat);
4550 implicit = true;
4551 return true;
4552 }
4553 CSSValueID id = range.peek().id();
4554 value1 = consumeIdent<CSSValueRepeat, CSSValueNoRepeat, CSSValueRound, CSSVa lueSpace>(range);
4555 if (!value1)
4556 return false;
4557
4558 value2 = consumeIdent<CSSValueRepeat, CSSValueNoRepeat, CSSValueRound, CSSVa lueSpace>(range);
4559 if (!value2) {
4560 value2 = cssValuePool().createIdentifierValue(id);
Timothy Loh 2016/02/23 05:53:14 isn't this just value1?
rwlbuis 2016/02/23 20:16:41 True, I changed it.
4561 implicit = true;
4562 }
4563 return true;
4564 }
4565
4566 static bool consumeRepeatStyle(CSSParserTokenRange& range, RefPtrWillBeRawPtr<CS SValue>& resultX, RefPtrWillBeRawPtr<CSSValue>& resultY, bool& implicit)
4567 {
4568 do {
4569 RefPtrWillBeRawPtr<CSSValue> repeatX = nullptr;
4570 RefPtrWillBeRawPtr<CSSValue> repeatY = nullptr;
4571 if (!consumeRepeatStyleComponent(range, repeatX, repeatY, implicit))
4572 break;
Timothy Loh 2016/02/23 05:53:15 Any reason for this to be different than consumeBa
rwlbuis 2016/02/23 20:16:42 Maybe at some point, but probably not anymore, fix
4573 addBackgroundValue(resultX, repeatX);
4574 addBackgroundValue(resultY, repeatY);
4575 } while (consumeCommaIncludingWhitespace(range));
4576 return resultX;
4577 }
4578
4525 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) 4579 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant)
4526 { 4580 {
4527 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); 4581 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
4528 4582
4529 CSSPropertyID oldShorthand = m_currentShorthand; 4583 CSSPropertyID oldShorthand = m_currentShorthand;
4530 // TODO(rob.buis): Remove this when the legacy property parser is gone 4584 // TODO(rob.buis): Remove this when the legacy property parser is gone
4531 m_currentShorthand = property; 4585 m_currentShorthand = property;
4532 switch (property) { 4586 switch (property) {
4533 case CSSPropertyWebkitMarginCollapse: { 4587 case CSSPropertyWebkitMarginCollapse: {
4534 CSSValueID id = m_range.consumeIncludingWhitespace().id(); 4588 CSSValueID id = m_range.consumeIncludingWhitespace().id();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
4656 case CSSPropertyBorderImage: 4710 case CSSPropertyBorderImage:
4657 case CSSPropertyWebkitMaskBoxImage: 4711 case CSSPropertyWebkitMaskBoxImage:
4658 return consumeBorderImage(property, important); 4712 return consumeBorderImage(property, important);
4659 case CSSPropertyPageBreakAfter: 4713 case CSSPropertyPageBreakAfter:
4660 case CSSPropertyPageBreakBefore: 4714 case CSSPropertyPageBreakBefore:
4661 case CSSPropertyPageBreakInside: 4715 case CSSPropertyPageBreakInside:
4662 case CSSPropertyWebkitColumnBreakAfter: 4716 case CSSPropertyWebkitColumnBreakAfter:
4663 case CSSPropertyWebkitColumnBreakBefore: 4717 case CSSPropertyWebkitColumnBreakBefore:
4664 case CSSPropertyWebkitColumnBreakInside: 4718 case CSSPropertyWebkitColumnBreakInside:
4665 return consumeLegacyBreakProperty(property, important); 4719 return consumeLegacyBreakProperty(property, important);
4720 case CSSPropertyWebkitMaskPosition:
4721 case CSSPropertyBackgroundPosition: {
4722 RefPtrWillBeRawPtr<CSSValue> resultX = nullptr;
4723 RefPtrWillBeRawPtr<CSSValue> resultY = nullptr;
4724 CSSPropertyID positionX = property == CSSPropertyBackgroundPosition ? CS SPropertyBackgroundPositionX : CSSPropertyWebkitMaskPositionX;
4725 CSSPropertyID positionY = property == CSSPropertyBackgroundPosition ? CS SPropertyBackgroundPositionY : CSSPropertyWebkitMaskPositionY;
4726 if (!consumeBackgroundPosition(m_range, m_context, UnitlessQuirk::Allow, resultX, resultY) || !m_range.atEnd())
4727 return false;
4728 addProperty(positionX, resultX.release(), important);
4729 if (resultY)
Timothy Loh 2016/02/23 05:53:14 There shouldn't be any case where a shorthand only
rwlbuis 2016/02/23 20:16:42 Good point! Fixed.
4730 addProperty(positionY, resultY.release(), important);
4731 return true;
4732 }
4733 case CSSPropertyBackgroundRepeat:
4734 case CSSPropertyWebkitMaskRepeat: {
4735 RefPtrWillBeRawPtr<CSSValue> resultX = nullptr;
4736 RefPtrWillBeRawPtr<CSSValue> resultY = nullptr;
4737 CSSPropertyID repeatX = property == CSSPropertyBackgroundRepeat ? CSSPro pertyBackgroundRepeatX : CSSPropertyWebkitMaskRepeatX;
4738 CSSPropertyID repeatY = property == CSSPropertyBackgroundRepeat ? CSSPro pertyBackgroundRepeatY : CSSPropertyWebkitMaskRepeatY;
4739 bool implicit = false;
4740 if (!consumeRepeatStyle(m_range, resultX, resultY, implicit) || !m_range .atEnd())
4741 return false;
4742 addProperty(repeatX, resultX.release(), important, implicit);
4743 if (resultY)
4744 addProperty(repeatY, resultY.release(), important, implicit);
4745 return true;
4746 }
4666 default: 4747 default:
4667 m_currentShorthand = oldShorthand; 4748 m_currentShorthand = oldShorthand;
4668 CSSParserValueList valueList(m_range); 4749 CSSParserValueList valueList(m_range);
4669 if (!valueList.size()) 4750 if (!valueList.size())
4670 return false; 4751 return false;
4671 m_valueList = &valueList; 4752 m_valueList = &valueList;
4672 return legacyParseShorthand(unresolvedProperty, important); 4753 return legacyParseShorthand(unresolvedProperty, important);
4673 } 4754 }
4674 } 4755 }
4675 4756
4676 } // namespace blink 4757 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698