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 "config.h" | 5 #include "config.h" |
| 6 #include "core/css/parser/CSSPropertyParser.h" | 6 #include "core/css/parser/CSSPropertyParser.h" |
| 7 | 7 |
| 8 #include "core/StylePropertyShorthand.h" | 8 #include "core/StylePropertyShorthand.h" |
| 9 #include "core/css/CSSCalculationValue.h" | 9 #include "core/css/CSSCalculationValue.h" |
| 10 #include "core/css/CSSCustomIdentValue.h" | 10 #include "core/css/CSSCustomIdentValue.h" |
| (...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1599 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeBorderWidth(CSSParserTok enRange& range, CSSParserMode cssParserMode) | 1599 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeBorderWidth(CSSParserTok enRange& range, CSSParserMode cssParserMode) |
| 1600 { | 1600 { |
| 1601 return consumeLineWidth(range, cssParserMode); | 1601 return consumeLineWidth(range, cssParserMode); |
| 1602 } | 1602 } |
| 1603 | 1603 |
| 1604 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeTextStrokeWidth(CSSParse rTokenRange& range, CSSParserMode cssParserMode) | 1604 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeTextStrokeWidth(CSSParse rTokenRange& range, CSSParserMode cssParserMode) |
| 1605 { | 1605 { |
| 1606 return consumeLineWidth(range, cssParserMode); | 1606 return consumeLineWidth(range, cssParserMode); |
| 1607 } | 1607 } |
| 1608 | 1608 |
| 1609 static bool consumeTranslate3d(CSSParserTokenRange& args, CSSParserMode cssParse rMode, RefPtrWillBeRawPtr<CSSFunctionValue>& transformValue) | |
| 1610 { | |
| 1611 unsigned numberOfArguments = 2; | |
| 1612 RefPtrWillBeRawPtr<CSSValue> parsedValue; | |
| 1613 do { | |
| 1614 parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeAll) ; | |
| 1615 if (!parsedValue) | |
| 1616 return false; | |
| 1617 transformValue->append(parsedValue); | |
| 1618 if (!consumeCommaIncludingWhitespace(args)) | |
| 1619 return false; | |
| 1620 } while (--numberOfArguments); | |
| 1621 parsedValue = consumeLength(args, cssParserMode, ValueRangeAll); | |
| 1622 if (!parsedValue) | |
| 1623 return false; | |
| 1624 transformValue->append(parsedValue); | |
| 1625 return true; | |
| 1626 } | |
| 1627 | |
| 1628 static bool consumeNumbers(CSSParserTokenRange& args, RefPtrWillBeRawPtr<CSSFunc tionValue>& transformValue, unsigned numberOfArguments) | |
| 1629 { | |
| 1630 do { | |
| 1631 RefPtrWillBeRawPtr<CSSValue> parsedValue = consumeNumber(args, ValueRang eAll); | |
| 1632 if (!parsedValue) | |
| 1633 return false; | |
| 1634 transformValue->append(parsedValue); | |
| 1635 if (--numberOfArguments && !consumeCommaIncludingWhitespace(args)) | |
| 1636 return false; | |
| 1637 } while (numberOfArguments); | |
| 1638 return true; | |
| 1639 } | |
| 1640 | |
| 1641 static bool consumePerspective(CSSParserTokenRange& args, CSSParserMode cssParse rMode, RefPtrWillBeRawPtr<CSSFunctionValue>& transformValue, bool useLegacyParsi ng) | |
| 1642 { | |
| 1643 RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue = consumeLength(args, cssP arserMode, ValueRangeNonNegative); | |
|
Timothy Loh
2015/11/13 18:11:44
I guess this could return a CSSPrimitiveValue inst
| |
| 1644 if (!parsedValue && useLegacyParsing) { | |
| 1645 double perspective; | |
| 1646 if (!consumeNumberRaw(args, perspective) || perspective < 0) | |
| 1647 return false; | |
| 1648 parsedValue = cssValuePool().createValue(perspective, CSSPrimitiveValue: :UnitType::Pixels); | |
| 1649 } | |
| 1650 if (!parsedValue) | |
| 1651 return false; | |
| 1652 transformValue->append(parsedValue); | |
| 1653 return true; | |
| 1654 } | |
| 1655 | |
| 1656 static PassRefPtrWillBeRawPtr<CSSValue> consumeTransformValue(CSSParserTokenRang e& range, CSSParserMode cssParserMode, bool useLegacyParsing) | |
| 1657 { | |
| 1658 CSSValueID functionId = range.peek().functionId(); | |
| 1659 if (functionId == CSSValueInvalid) | |
| 1660 return nullptr; | |
| 1661 CSSParserTokenRange args = consumeFunction(range); | |
| 1662 if (args.atEnd()) | |
| 1663 return nullptr; | |
| 1664 RefPtrWillBeRawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::crea te(functionId); | |
| 1665 RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr; | |
| 1666 switch (functionId) { | |
| 1667 case CSSValueRotate: | |
| 1668 case CSSValueRotateX: | |
| 1669 case CSSValueRotateY: | |
| 1670 case CSSValueRotateZ: | |
| 1671 case CSSValueSkewX: | |
| 1672 case CSSValueSkewY: | |
| 1673 case CSSValueSkew: | |
| 1674 parsedValue = consumeAngle(args, cssParserMode); | |
| 1675 if (!parsedValue) | |
| 1676 return nullptr; | |
| 1677 if (functionId == CSSValueSkew && consumeCommaIncludingWhitespace(args)) { | |
| 1678 transformValue->append(parsedValue); | |
| 1679 parsedValue = consumeAngle(args, cssParserMode); | |
| 1680 } | |
| 1681 break; | |
| 1682 case CSSValueScaleX: | |
| 1683 case CSSValueScaleY: | |
| 1684 case CSSValueScaleZ: | |
| 1685 case CSSValueScale: | |
| 1686 parsedValue = consumeNumber(args, ValueRangeAll); | |
| 1687 if (!parsedValue) | |
| 1688 return nullptr; | |
| 1689 if (functionId == CSSValueScale && consumeCommaIncludingWhitespace(args) ) { | |
| 1690 transformValue->append(parsedValue); | |
| 1691 parsedValue = consumeNumber(args, ValueRangeAll); | |
| 1692 } | |
| 1693 break; | |
| 1694 case CSSValuePerspective: | |
| 1695 if (!consumePerspective(args, cssParserMode, transformValue, useLegacyPa rsing)) | |
| 1696 return nullptr; | |
| 1697 break; | |
| 1698 case CSSValueTranslateX: | |
| 1699 case CSSValueTranslateY: | |
| 1700 case CSSValueTranslate: | |
| 1701 parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRangeAll) ; | |
| 1702 if (!parsedValue) | |
| 1703 return nullptr; | |
| 1704 if (functionId == CSSValueTranslate && consumeCommaIncludingWhitespace(a rgs)) { | |
| 1705 transformValue->append(parsedValue); | |
| 1706 parsedValue = consumeLengthOrPercent(args, cssParserMode, ValueRange All); | |
| 1707 } | |
| 1708 break; | |
| 1709 case CSSValueTranslateZ: | |
| 1710 parsedValue = consumeLength(args, cssParserMode, ValueRangeAll); | |
| 1711 break; | |
| 1712 case CSSValueMatrix: | |
| 1713 case CSSValueMatrix3d: | |
| 1714 if (!consumeNumbers(args, transformValue, (functionId == CSSValueMatrix3 d) ? 16 : 6)) | |
| 1715 return nullptr; | |
| 1716 break; | |
| 1717 case CSSValueScale3d: | |
| 1718 if (!consumeNumbers(args, transformValue, 3)) | |
| 1719 return nullptr; | |
| 1720 break; | |
| 1721 case CSSValueRotate3d: | |
| 1722 if (!consumeNumbers(args, transformValue, 3) || !consumeCommaIncludingWh itespace(args)) | |
| 1723 return nullptr; | |
| 1724 parsedValue = consumeAngle(args, cssParserMode); | |
| 1725 break; | |
| 1726 case CSSValueTranslate3d: | |
| 1727 if (!consumeTranslate3d(args, cssParserMode, transformValue)) | |
| 1728 return nullptr; | |
| 1729 break; | |
| 1730 default: | |
| 1731 return nullptr; | |
| 1732 } | |
| 1733 if (parsedValue) | |
| 1734 transformValue->append(parsedValue); | |
| 1735 if (!args.atEnd()) | |
| 1736 return nullptr; | |
| 1737 return transformValue.release(); | |
| 1738 } | |
| 1739 | |
| 1740 static PassRefPtrWillBeRawPtr<CSSValue> consumeTransform(CSSParserTokenRange& ra nge, CSSParserMode cssParserMode, bool useLegacyParsing) | |
| 1741 { | |
| 1742 if (range.peek().id() == CSSValueNone) | |
| 1743 return consumeIdent(range); | |
| 1744 | |
| 1745 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated() ; | |
| 1746 do { | |
| 1747 RefPtrWillBeRawPtr<CSSValue> parsedTransformValue = consumeTransformValu e(range, cssParserMode, useLegacyParsing); | |
| 1748 if (!parsedTransformValue) | |
| 1749 return nullptr; | |
| 1750 list->append(parsedTransformValue.release()); | |
| 1751 } while (!range.atEnd()); | |
| 1752 | |
| 1753 return list.release(); | |
| 1754 } | |
| 1755 | |
| 1609 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) | 1756 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) |
| 1610 { | 1757 { |
| 1611 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 1758 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
| 1612 m_range.consumeWhitespace(); | 1759 m_range.consumeWhitespace(); |
| 1613 switch (property) { | 1760 switch (property) { |
| 1614 case CSSPropertyWillChange: | 1761 case CSSPropertyWillChange: |
| 1615 return consumeWillChange(m_range); | 1762 return consumeWillChange(m_range); |
| 1616 case CSSPropertyPage: | 1763 case CSSPropertyPage: |
| 1617 return consumePage(m_range); | 1764 return consumePage(m_range); |
| 1618 case CSSPropertyQuotes: | 1765 case CSSPropertyQuotes: |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1745 ASSERT(RuntimeEnabledFeatures::cssMotionPathEnabled()); | 1892 ASSERT(RuntimeEnabledFeatures::cssMotionPathEnabled()); |
| 1746 return consumeMotionRotation(m_range, m_context.mode()); | 1893 return consumeMotionRotation(m_range, m_context.mode()); |
| 1747 case CSSPropertyWebkitTextEmphasisStyle: | 1894 case CSSPropertyWebkitTextEmphasisStyle: |
| 1748 return consumeTextEmphasisStyle(m_range); | 1895 return consumeTextEmphasisStyle(m_range); |
| 1749 case CSSPropertyOutlineColor: | 1896 case CSSPropertyOutlineColor: |
| 1750 return consumeOutlineColor(m_range, m_context); | 1897 return consumeOutlineColor(m_range, m_context); |
| 1751 case CSSPropertyOutlineOffset: | 1898 case CSSPropertyOutlineOffset: |
| 1752 return consumeLength(m_range, m_context.mode(), ValueRangeAll); | 1899 return consumeLength(m_range, m_context.mode(), ValueRangeAll); |
| 1753 case CSSPropertyOutlineWidth: | 1900 case CSSPropertyOutlineWidth: |
| 1754 return consumeLineWidth(m_range, m_context.mode()); | 1901 return consumeLineWidth(m_range, m_context.mode()); |
| 1902 case CSSPropertyTransform: | |
| 1903 return consumeTransform(m_range, m_context.mode(), unresolvedProperty == CSSPropertyAliasWebkitTransform); | |
| 1755 default: | 1904 default: |
| 1756 return nullptr; | 1905 return nullptr; |
| 1757 } | 1906 } |
| 1758 } | 1907 } |
| 1759 | 1908 |
| 1760 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) | 1909 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) |
| 1761 { | 1910 { |
| 1762 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 1911 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
| 1763 | 1912 |
| 1764 do { | 1913 do { |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2242 return consumeShorthandGreedily(webkitBorderAfterShorthand(), important) ; | 2391 return consumeShorthandGreedily(webkitBorderAfterShorthand(), important) ; |
| 2243 case CSSPropertyWebkitTextStroke: | 2392 case CSSPropertyWebkitTextStroke: |
| 2244 return consumeShorthandGreedily(webkitTextStrokeShorthand(), important); | 2393 return consumeShorthandGreedily(webkitTextStrokeShorthand(), important); |
| 2245 default: | 2394 default: |
| 2246 m_currentShorthand = oldShorthand; | 2395 m_currentShorthand = oldShorthand; |
| 2247 return false; | 2396 return false; |
| 2248 } | 2397 } |
| 2249 } | 2398 } |
| 2250 | 2399 |
| 2251 } // namespace blink | 2400 } // namespace blink |
| OLD | NEW |