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

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

Issue 1676513003: Move background/webkit-mask shorthands into CSSPropertyParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix review issues Created 4 years, 9 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 4542 matching lines...) Expand 10 before | Expand all | Expand 10 after
4553 RefPtrWillBeRawPtr<CSSValue> repeatX = nullptr; 4553 RefPtrWillBeRawPtr<CSSValue> repeatX = nullptr;
4554 RefPtrWillBeRawPtr<CSSValue> repeatY = nullptr; 4554 RefPtrWillBeRawPtr<CSSValue> repeatY = nullptr;
4555 if (!consumeRepeatStyleComponent(range, repeatX, repeatY, implicit)) 4555 if (!consumeRepeatStyleComponent(range, repeatX, repeatY, implicit))
4556 return false; 4556 return false;
4557 addBackgroundValue(resultX, repeatX); 4557 addBackgroundValue(resultX, repeatX);
4558 addBackgroundValue(resultY, repeatY); 4558 addBackgroundValue(resultY, repeatY);
4559 } while (consumeCommaIncludingWhitespace(range)); 4559 } while (consumeCommaIncludingWhitespace(range));
4560 return true; 4560 return true;
4561 } 4561 }
4562 4562
4563 // Note: consumeBackgroundShorthand assumes y properties (for example background -position-y) follow
4564 // the x properties in the shorthand array.
4565 bool CSSPropertyParser::consumeBackgroundShorthand(const StylePropertyShorthand& shorthand, bool important)
4566 {
4567 const unsigned longhandCount = shorthand.length();
4568 RefPtrWillBeRawPtr<CSSValue> longhands[10];
4569 ASSERT(longhandCount <= 10);
4570 #if ENABLE(OILPAN)
4571 // Zero initialize the array of raw pointers.
4572 memset(&longhands, 0, sizeof(longhands));
4573 #endif
4574 bool implicit = false;
4575 do {
4576 bool parsedLonghand[10] = { false };
4577 RefPtrWillBeRawPtr<CSSValue> originValue = nullptr;
4578 do {
4579 bool foundProperty = false;
4580 for (size_t i = 0; i < longhandCount; ++i) {
4581 if (parsedLonghand[i])
4582 continue;
4583
4584 RefPtrWillBeRawPtr<CSSValue> value = nullptr;
4585 RefPtrWillBeRawPtr<CSSValue> valueY = nullptr;
4586 CSSPropertyID property = shorthand.properties()[i];
4587 if (property == CSSPropertyBackgroundRepeatX || property == CSSP ropertyWebkitMaskRepeatX) {
4588 consumeRepeatStyleComponent(m_range, value, valueY, implicit );
4589 } else if (property == CSSPropertyBackgroundPositionX || propert y == CSSPropertyWebkitMaskPositionX) {
4590 CSSParserTokenRange rangeCopy = m_range;
4591 if (!consumePosition(rangeCopy, m_context.mode(), UnitlessQu irk::Forbid, value, valueY))
4592 continue;
4593 m_range = rangeCopy;
4594 } else if (property == CSSPropertyBackgroundSize || property == CSSPropertyWebkitMaskSize) {
4595 if (!consumeSlashIncludingWhitespace(m_range))
4596 continue;
4597 value = consumeBackgroundSize(property, m_range, m_context.m ode());
4598 if (!value || !parsedLonghand[i - 1]) // Position must have been parsed in the current layer.
4599 return false;
4600 } else if (property == CSSPropertyBackgroundPositionY || propert y == CSSPropertyBackgroundRepeatY
4601 || property == CSSPropertyWebkitMaskPositionY || property == CSSPropertyWebkitMaskRepeatY) {
4602 continue;
4603 } else {
4604 value = consumeBackgroundComponent(property, m_range, m_cont ext);
4605 }
4606 if (value) {
4607 if (property == CSSPropertyBackgroundOrigin || property == C SSPropertyWebkitMaskOrigin)
4608 originValue = value;
4609 parsedLonghand[i] = true;
4610 foundProperty = true;
4611 addBackgroundValue(longhands[i], value.release());
4612 if (valueY) {
4613 parsedLonghand[i + 1] = true;
4614 addBackgroundValue(longhands[i + 1], valueY.release());
4615 }
4616 }
4617 }
4618 if (!foundProperty)
4619 return false;
4620 } while (!m_range.atEnd() && m_range.peek().type() != CommaToken);
4621
4622 // TODO(timloh): This will make invalid longhands, see crbug.com/386459
4623 for (size_t i = 0; i < longhandCount; ++i) {
4624 CSSPropertyID property = shorthand.properties()[i];
4625 if (property == CSSPropertyBackgroundColor && !m_range.atEnd()) {
4626 if (parsedLonghand[i])
4627 return false; // Colors are only allowed in the last layer.
4628 continue;
4629 }
4630 if ((property == CSSPropertyBackgroundClip || property == CSSPropert yWebkitMaskClip) && !parsedLonghand[i] && originValue) {
4631 addBackgroundValue(longhands[i], originValue.release());
4632 continue;
4633 }
4634 if (!parsedLonghand[i])
4635 addBackgroundValue(longhands[i], cssValuePool().createImplicitIn itialValue());
4636 }
4637 } while (consumeCommaIncludingWhitespace(m_range));
4638 if (!m_range.atEnd())
4639 return false;
4640
4641 for (size_t i = 0; i < longhandCount; ++i) {
4642 CSSPropertyID property = shorthand.properties()[i];
4643 if (property == CSSPropertyBackgroundSize && longhands[i] && m_context.u seLegacyBackgroundSizeShorthandBehavior())
4644 continue;
4645 addProperty(property, longhands[i].release(), important, implicit);
4646 }
4647 return true;
4648 }
4649
4563 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) 4650 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant)
4564 { 4651 {
4565 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); 4652 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
4566 4653
4567 CSSPropertyID oldShorthand = m_currentShorthand; 4654 CSSPropertyID oldShorthand = m_currentShorthand;
4568 // TODO(rob.buis): Remove this when the legacy property parser is gone 4655 // TODO(rob.buis): Remove this when the legacy property parser is gone
4569 m_currentShorthand = property; 4656 m_currentShorthand = property;
4570 switch (property) { 4657 switch (property) {
4571 case CSSPropertyWebkitMarginCollapse: { 4658 case CSSPropertyWebkitMarginCollapse: {
4572 CSSValueID id = m_range.consumeIncludingWhitespace().id(); 4659 CSSValueID id = m_range.consumeIncludingWhitespace().id();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
4715 case CSSPropertyWebkitMaskRepeat: { 4802 case CSSPropertyWebkitMaskRepeat: {
4716 RefPtrWillBeRawPtr<CSSValue> resultX = nullptr; 4803 RefPtrWillBeRawPtr<CSSValue> resultX = nullptr;
4717 RefPtrWillBeRawPtr<CSSValue> resultY = nullptr; 4804 RefPtrWillBeRawPtr<CSSValue> resultY = nullptr;
4718 bool implicit = false; 4805 bool implicit = false;
4719 if (!consumeRepeatStyle(m_range, resultX, resultY, implicit) || !m_range .atEnd()) 4806 if (!consumeRepeatStyle(m_range, resultX, resultY, implicit) || !m_range .atEnd())
4720 return false; 4807 return false;
4721 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatX : CSSPropertyWebkitMaskRepeatX, resultX.release(), important, implici t); 4808 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatX : CSSPropertyWebkitMaskRepeatX, resultX.release(), important, implici t);
4722 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatY : CSSPropertyWebkitMaskRepeatY, resultY.release(), important, implici t); 4809 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatY : CSSPropertyWebkitMaskRepeatY, resultY.release(), important, implici t);
4723 return true; 4810 return true;
4724 } 4811 }
4812 case CSSPropertyBackground:
4813 return consumeBackgroundShorthand(backgroundShorthand(), important);
4814 case CSSPropertyWebkitMask:
4815 return consumeBackgroundShorthand(webkitMaskShorthand(), important);
4725 default: 4816 default:
4726 m_currentShorthand = oldShorthand; 4817 m_currentShorthand = oldShorthand;
4727 CSSParserValueList valueList(m_range); 4818 CSSParserValueList valueList(m_range);
4728 if (!valueList.size()) 4819 if (!valueList.size())
4729 return false; 4820 return false;
4730 m_valueList = &valueList; 4821 m_valueList = &valueList;
4731 return legacyParseShorthand(unresolvedProperty, important); 4822 return legacyParseShorthand(unresolvedProperty, important);
4732 } 4823 }
4733 } 4824 }
4734 4825
4735 } // namespace blink 4826 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698