OLD | NEW |
---|---|
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 Loading... | |
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 if (!value) { | |
Timothy Loh
2016/03/07 03:55:07
else
rwlbuis
2016/03/08 02:51:49
Done.
| |
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]; | |
Timothy Loh
2016/03/07 03:55:07
Can we just start with
if (!parsedLonghand[i])
Timothy Loh
2016/03/07 06:25:36
Err.. wait I misread the code. Nevermind.
| |
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 parsedLonghand[i] = false; | |
Timothy Loh
2016/03/07 03:55:07
don't need this, the array will get re-initialized
rwlbuis
2016/03/08 02:51:49
Done.
| |
4637 } | |
4638 } while (consumeCommaIncludingWhitespace(m_range)); | |
4639 if (!m_range.atEnd()) | |
4640 return false; | |
4641 | |
4642 for (size_t i = 0; i < longhandCount; ++i) { | |
4643 CSSPropertyID property = shorthand.properties()[i]; | |
4644 if (property == CSSPropertyBackgroundSize && longhands[i] && m_context.u seLegacyBackgroundSizeShorthandBehavior()) | |
4645 continue; | |
4646 addProperty(property, longhands[i].release(), important, implicit); | |
4647 } | |
4648 return true; | |
4649 } | |
4650 | |
4563 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) | 4651 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) |
4564 { | 4652 { |
4565 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 4653 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
4566 | 4654 |
4567 CSSPropertyID oldShorthand = m_currentShorthand; | 4655 CSSPropertyID oldShorthand = m_currentShorthand; |
4568 // TODO(rob.buis): Remove this when the legacy property parser is gone | 4656 // TODO(rob.buis): Remove this when the legacy property parser is gone |
4569 m_currentShorthand = property; | 4657 m_currentShorthand = property; |
4570 switch (property) { | 4658 switch (property) { |
4571 case CSSPropertyWebkitMarginCollapse: { | 4659 case CSSPropertyWebkitMarginCollapse: { |
4572 CSSValueID id = m_range.consumeIncludingWhitespace().id(); | 4660 CSSValueID id = m_range.consumeIncludingWhitespace().id(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4715 case CSSPropertyWebkitMaskRepeat: { | 4803 case CSSPropertyWebkitMaskRepeat: { |
4716 RefPtrWillBeRawPtr<CSSValue> resultX = nullptr; | 4804 RefPtrWillBeRawPtr<CSSValue> resultX = nullptr; |
4717 RefPtrWillBeRawPtr<CSSValue> resultY = nullptr; | 4805 RefPtrWillBeRawPtr<CSSValue> resultY = nullptr; |
4718 bool implicit = false; | 4806 bool implicit = false; |
4719 if (!consumeRepeatStyle(m_range, resultX, resultY, implicit) || !m_range .atEnd()) | 4807 if (!consumeRepeatStyle(m_range, resultX, resultY, implicit) || !m_range .atEnd()) |
4720 return false; | 4808 return false; |
4721 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatX : CSSPropertyWebkitMaskRepeatX, resultX.release(), important, implici t); | 4809 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatX : CSSPropertyWebkitMaskRepeatX, resultX.release(), important, implici t); |
4722 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatY : CSSPropertyWebkitMaskRepeatY, resultY.release(), important, implici t); | 4810 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatY : CSSPropertyWebkitMaskRepeatY, resultY.release(), important, implici t); |
4723 return true; | 4811 return true; |
4724 } | 4812 } |
4813 case CSSPropertyBackground: | |
4814 return consumeBackgroundShorthand(backgroundShorthand(), important); | |
4815 case CSSPropertyWebkitMask: | |
4816 return consumeBackgroundShorthand(webkitMaskShorthand(), important); | |
4725 default: | 4817 default: |
4726 m_currentShorthand = oldShorthand; | 4818 m_currentShorthand = oldShorthand; |
4727 CSSParserValueList valueList(m_range); | 4819 CSSParserValueList valueList(m_range); |
4728 if (!valueList.size()) | 4820 if (!valueList.size()) |
4729 return false; | 4821 return false; |
4730 m_valueList = &valueList; | 4822 m_valueList = &valueList; |
4731 return legacyParseShorthand(unresolvedProperty, important); | 4823 return legacyParseShorthand(unresolvedProperty, important); |
4732 } | 4824 } |
4733 } | 4825 } |
4734 | 4826 |
4735 } // namespace blink | 4827 } // namespace blink |
OLD | NEW |