Chromium Code Reviews| 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 seenClip = false; | |
|
Timothy Loh
2016/03/02 04:50:27
Doesn't seem right, this should be per-layer.
bac
rwlbuis
2016/03/07 02:50:04
Done.
| |
| 4575 bool implicit = false; | |
| 4576 do { | |
| 4577 bool parsedLonghand[10] = { false }; | |
| 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) && !consumeSlashIncludingWhitespace(m_range)) | |
|
Timothy Loh
2016/03/02 04:50:27
Slash handling looks wrong here, since we could co
rwlbuis
2016/03/07 02:50:04
Not sure if you meant it the way I implemented it
Timothy Loh
2016/03/07 03:55:07
Wasn't really what I meant, but it works.
| |
| 4595 || property == CSSPropertyBackgroundPositionY || property == CSSPropertyBackgroundRepeatY | |
| 4596 || property == CSSPropertyWebkitMaskPositionY || property == CSSPropertyWebkitMaskRepeatY) { | |
| 4597 continue; | |
| 4598 } | |
| 4599 if (!value) | |
|
Timothy Loh
2016/03/02 04:50:27
can this be an else?
rwlbuis
2016/03/07 02:50:04
Done.
| |
| 4600 value = consumeBackgroundComponent(property, m_range, m_cont ext); | |
| 4601 if (value) { | |
| 4602 if (property == CSSPropertyBackgroundClip || property == CSS PropertyWebkitMaskClip) | |
| 4603 seenClip = true; | |
| 4604 parsedLonghand[i] = true; | |
| 4605 foundProperty = true; | |
| 4606 addBackgroundValue(longhands[i], value.release()); | |
| 4607 if (valueY) { | |
| 4608 parsedLonghand[i + 1] = true; | |
| 4609 addBackgroundValue(longhands[i + 1], valueY.release()); | |
| 4610 } | |
| 4611 } | |
| 4612 } | |
| 4613 if (!foundProperty) | |
| 4614 return false; | |
| 4615 } while (!m_range.atEnd() && m_range.peek().type() != CommaToken); | |
| 4616 | |
| 4617 // TODO(timloh): This will make invalid longhands, see crbug.com/386459 | |
| 4618 bool seenPosition = false; | |
| 4619 for (size_t i = 0; i < longhandCount; ++i) { | |
| 4620 CSSPropertyID property = shorthand.properties()[i]; | |
| 4621 if (property == CSSPropertyBackgroundColor && m_range.peek().type() == CommaToken) { | |
|
Timothy Loh
2016/03/02 04:50:27
maybe clearer to write !m_range.atEnd() instead of
rwlbuis
2016/03/07 02:50:04
Done.
| |
| 4622 if (parsedLonghand[i]) | |
| 4623 return false; // Color is not allowed except as the last ite m in a list for backgrounds. | |
|
Timothy Loh
2016/03/02 04:50:27
Sounds like it has to be the very last thing. Mayb
rwlbuis
2016/03/07 02:50:04
Done.
| |
| 4624 continue; | |
| 4625 } | |
| 4626 if ((property == CSSPropertyBackgroundPositionX || property == CSSPr opertyWebkitMaskPositionX) && parsedLonghand[i]) | |
| 4627 seenPosition = true; | |
| 4628 if ((property == CSSPropertyBackgroundSize || property == CSSPropert yWebkitMaskSize) && parsedLonghand[i] && !seenPosition) | |
| 4629 return false; | |
| 4630 if (!parsedLonghand[i]) | |
| 4631 addBackgroundValue(longhands[i], cssValuePool().createImplicitIn itialValue()); | |
| 4632 parsedLonghand[i] = false; | |
| 4633 } | |
| 4634 } while (consumeCommaIncludingWhitespace(m_range)); | |
| 4635 if (!m_range.atEnd()) | |
| 4636 return false; | |
| 4637 | |
| 4638 RefPtrWillBeRawPtr<CSSValue> originValue = nullptr; | |
| 4639 for (size_t i = 0; i < longhandCount; ++i) { | |
| 4640 CSSPropertyID property = shorthand.properties()[i]; | |
| 4641 if (property == CSSPropertyBackgroundOrigin || property == CSSPropertyWe bkitMaskOrigin) | |
| 4642 originValue = longhands[i]; | |
| 4643 if ((property == CSSPropertyBackgroundClip || property == CSSPropertyWeb kitMaskClip) && !seenClip) | |
| 4644 addProperty(property, originValue.release(), important, implicit); | |
| 4645 else if (property == CSSPropertyBackgroundSize && longhands[i] && m_cont ext.useLegacyBackgroundSizeShorthandBehavior()) | |
| 4646 continue; | |
| 4647 else | |
| 4648 addProperty(property, longhands[i].release(), important, implicit); | |
| 4649 } | |
| 4650 return true; | |
| 4651 } | |
| 4652 | |
| 4563 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) | 4653 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) |
| 4564 { | 4654 { |
| 4565 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 4655 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
| 4566 | 4656 |
| 4567 CSSPropertyID oldShorthand = m_currentShorthand; | 4657 CSSPropertyID oldShorthand = m_currentShorthand; |
| 4568 // TODO(rob.buis): Remove this when the legacy property parser is gone | 4658 // TODO(rob.buis): Remove this when the legacy property parser is gone |
| 4569 m_currentShorthand = property; | 4659 m_currentShorthand = property; |
| 4570 switch (property) { | 4660 switch (property) { |
| 4571 case CSSPropertyWebkitMarginCollapse: { | 4661 case CSSPropertyWebkitMarginCollapse: { |
| 4572 CSSValueID id = m_range.consumeIncludingWhitespace().id(); | 4662 CSSValueID id = m_range.consumeIncludingWhitespace().id(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4715 case CSSPropertyWebkitMaskRepeat: { | 4805 case CSSPropertyWebkitMaskRepeat: { |
| 4716 RefPtrWillBeRawPtr<CSSValue> resultX = nullptr; | 4806 RefPtrWillBeRawPtr<CSSValue> resultX = nullptr; |
| 4717 RefPtrWillBeRawPtr<CSSValue> resultY = nullptr; | 4807 RefPtrWillBeRawPtr<CSSValue> resultY = nullptr; |
| 4718 bool implicit = false; | 4808 bool implicit = false; |
| 4719 if (!consumeRepeatStyle(m_range, resultX, resultY, implicit) || !m_range .atEnd()) | 4809 if (!consumeRepeatStyle(m_range, resultX, resultY, implicit) || !m_range .atEnd()) |
| 4720 return false; | 4810 return false; |
| 4721 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatX : CSSPropertyWebkitMaskRepeatX, resultX.release(), important, implici t); | 4811 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatX : CSSPropertyWebkitMaskRepeatX, resultX.release(), important, implici t); |
| 4722 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatY : CSSPropertyWebkitMaskRepeatY, resultY.release(), important, implici t); | 4812 addProperty(property == CSSPropertyBackgroundRepeat ? CSSPropertyBackgro undRepeatY : CSSPropertyWebkitMaskRepeatY, resultY.release(), important, implici t); |
| 4723 return true; | 4813 return true; |
| 4724 } | 4814 } |
| 4815 case CSSPropertyBackground: | |
| 4816 return consumeBackgroundShorthand(backgroundShorthand(), important); | |
| 4817 case CSSPropertyWebkitMask: | |
| 4818 return consumeBackgroundShorthand(webkitMaskShorthand(), important); | |
| 4725 default: | 4819 default: |
| 4726 m_currentShorthand = oldShorthand; | 4820 m_currentShorthand = oldShorthand; |
| 4727 CSSParserValueList valueList(m_range); | 4821 CSSParserValueList valueList(m_range); |
| 4728 if (!valueList.size()) | 4822 if (!valueList.size()) |
| 4729 return false; | 4823 return false; |
| 4730 m_valueList = &valueList; | 4824 m_valueList = &valueList; |
| 4731 return legacyParseShorthand(unresolvedProperty, important); | 4825 return legacyParseShorthand(unresolvedProperty, important); |
| 4732 } | 4826 } |
| 4733 } | 4827 } |
| 4734 | 4828 |
| 4735 } // namespace blink | 4829 } // namespace blink |
| OLD | NEW |