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 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1476 if (!url.isNull()) { | 1476 if (!url.isNull()) { |
1477 filterValue = CSSFunctionValue::create(CSSValueUrl); | 1477 filterValue = CSSFunctionValue::create(CSSValueUrl); |
1478 filterValue->append(CSSSVGDocumentValue::create(url)); | 1478 filterValue->append(CSSSVGDocumentValue::create(url)); |
1479 } else { | 1479 } else { |
1480 filterValue = consumeFilterFunction(range, context); | 1480 filterValue = consumeFilterFunction(range, context); |
1481 if (!filterValue) | 1481 if (!filterValue) |
1482 return nullptr; | 1482 return nullptr; |
1483 } | 1483 } |
1484 list->append(filterValue.release()); | 1484 list->append(filterValue.release()); |
1485 } while (!range.atEnd()); | 1485 } while (!range.atEnd()); |
1486 | |
1487 return list.release(); | 1486 return list.release(); |
1488 } | 1487 } |
1489 | 1488 |
1489 static bool matchKeywords(CSSValueID target, const HashSet<int>& ids) | |
1490 { | |
1491 for (const auto& id : ids) { | |
1492 if (id == target) | |
1493 return true; | |
1494 } | |
1495 return false; | |
1496 } | |
1497 | |
1498 static PassRefPtrWillBeRawPtr<CSSValue> consumeTextDecorationLine(CSSParserToken Range& range) | |
1499 { | |
1500 CSSValueID id = range.peek().id(); | |
1501 if (id == CSSValueNone) | |
1502 return consumeIdent(range); | |
1503 | |
1504 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated() ; | |
1505 HashSet<int> ids; | |
1506 ids.add(CSSValueUnderline); | |
1507 ids.add(CSSValueOverline); | |
1508 ids.add(CSSValueLineThrough); | |
1509 ids.add(CSSValueBlink); | |
1510 while (matchKeywords(id, ids)) { | |
1511 list->append(consumeIdent(range)); | |
1512 ids.remove(id); | |
1513 id = range.peek().id(); | |
1514 } | |
1515 | |
1516 // Values are either valid or in shorthand scope. | |
1517 if (!list->length()) | |
1518 return nullptr; | |
1519 return list.release(); | |
1520 } | |
1521 | |
1490 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) | 1522 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) |
1491 { | 1523 { |
1492 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 1524 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
1493 m_range.consumeWhitespace(); | 1525 m_range.consumeWhitespace(); |
1494 switch (property) { | 1526 switch (property) { |
1495 case CSSPropertyWillChange: | 1527 case CSSPropertyWillChange: |
1496 return consumeWillChange(m_range); | 1528 return consumeWillChange(m_range); |
1497 case CSSPropertyPage: | 1529 case CSSPropertyPage: |
1498 return consumePage(m_range); | 1530 return consumePage(m_range); |
1499 case CSSPropertyQuotes: | 1531 case CSSPropertyQuotes: |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1579 case CSSPropertyAnimationPlayState: | 1611 case CSSPropertyAnimationPlayState: |
1580 case CSSPropertyTransitionProperty: | 1612 case CSSPropertyTransitionProperty: |
1581 case CSSPropertyAnimationTimingFunction: | 1613 case CSSPropertyAnimationTimingFunction: |
1582 case CSSPropertyTransitionTimingFunction: | 1614 case CSSPropertyTransitionTimingFunction: |
1583 return consumeAnimationPropertyList(property, m_range, m_context, unreso lvedProperty == CSSPropertyAliasWebkitAnimationName); | 1615 return consumeAnimationPropertyList(property, m_range, m_context, unreso lvedProperty == CSSPropertyAliasWebkitAnimationName); |
1584 case CSSPropertyOrphans: | 1616 case CSSPropertyOrphans: |
1585 case CSSPropertyWidows: | 1617 case CSSPropertyWidows: |
1586 return consumeWidowsOrOrphans(m_range); | 1618 return consumeWidowsOrOrphans(m_range); |
1587 case CSSPropertyWebkitTextFillColor: | 1619 case CSSPropertyWebkitTextFillColor: |
1588 case CSSPropertyWebkitTapHighlightColor: | 1620 case CSSPropertyWebkitTapHighlightColor: |
1621 case CSSPropertyTextDecorationColor: | |
1622 ASSERT(property != CSSPropertyTextDecorationColor || RuntimeEnabledFeatu res::css3TextDecorationsEnabled()); | |
1589 return consumeColor(m_range, m_context); | 1623 return consumeColor(m_range, m_context); |
1590 case CSSPropertyColor: | 1624 case CSSPropertyColor: |
1591 return consumeColor(m_range, m_context, inQuirksMode()); | 1625 return consumeColor(m_range, m_context, inQuirksMode()); |
1592 case CSSPropertyZIndex: | 1626 case CSSPropertyZIndex: |
1593 return consumeZIndex(m_range); | 1627 return consumeZIndex(m_range); |
1594 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS 3, so treat as CSS3 | 1628 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS 3, so treat as CSS3 |
1595 case CSSPropertyBoxShadow: | 1629 case CSSPropertyBoxShadow: |
1596 return consumeShadow(m_range, m_context, property == CSSPropertyBoxShado w); | 1630 return consumeShadow(m_range, m_context, property == CSSPropertyBoxShado w); |
1597 case CSSPropertyWebkitFilter: | 1631 case CSSPropertyWebkitFilter: |
1598 case CSSPropertyBackdropFilter: | 1632 case CSSPropertyBackdropFilter: |
1599 return consumeFilter(m_range, m_context); | 1633 return consumeFilter(m_range, m_context); |
1634 case CSSPropertyWebkitTextDecorationsInEffect: | |
1635 case CSSPropertyTextDecorationLine: | |
1636 return consumeTextDecorationLine(m_range); | |
1600 default: | 1637 default: |
1601 return nullptr; | 1638 return nullptr; |
1602 } | 1639 } |
1603 } | 1640 } |
1604 | 1641 |
1605 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) | 1642 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) |
1606 { | 1643 { |
1607 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); | 1644 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); |
1608 | 1645 |
1609 do { | 1646 do { |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1952 return false; | 1989 return false; |
1953 if (!columnWidth) | 1990 if (!columnWidth) |
1954 columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto); | 1991 columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto); |
1955 if (!columnCount) | 1992 if (!columnCount) |
1956 columnCount = cssValuePool().createIdentifierValue(CSSValueAuto); | 1993 columnCount = cssValuePool().createIdentifierValue(CSSValueAuto); |
1957 addProperty(CSSPropertyWebkitColumnWidth, columnWidth.release(), important); | 1994 addProperty(CSSPropertyWebkitColumnWidth, columnWidth.release(), important); |
1958 addProperty(CSSPropertyWebkitColumnCount, columnCount.release(), important); | 1995 addProperty(CSSPropertyWebkitColumnCount, columnCount.release(), important); |
1959 return true; | 1996 return true; |
1960 } | 1997 } |
1961 | 1998 |
1999 bool CSSPropertyParser::consumeShorthandGreedily(const StylePropertyShorthand& s horthand, bool important) | |
2000 { | |
2001 ASSERT(shorthand.length() <= 6); // Existing shorthands have at most 6 longh ands. | |
2002 RefPtrWillBeRawPtr<CSSValue> longhands[6] = { nullptr, nullptr, nullptr, nul lptr, nullptr, nullptr }; | |
2003 do { | |
2004 bool foundLonghand = false; | |
2005 for (unsigned propertyIndex = 0; !foundLonghand && propertyIndex < short hand.length(); ++propertyIndex) { | |
Timothy Loh
2015/11/03 05:50:58
Can we be consistent with the loop below (which us
rwlbuis
2015/11/03 20:51:09
Done.
| |
2006 if (longhands[propertyIndex]) | |
2007 continue; | |
2008 // TODO: parseSingleValue needs to handle fastpath keywords. | |
2009 if (CSSParserFastPaths::isKeywordPropertyID(shorthand.properties()[p ropertyIndex])) { | |
Timothy Loh
2015/11/03 05:50:58
Would be nice to have a variable for shorthand.pro
rwlbuis
2015/11/03 20:51:09
Done.
| |
2010 if (CSSParserFastPaths::isValidKeywordPropertyAndValue(shorthand .properties()[propertyIndex], m_range.peek().id())) | |
2011 longhands[propertyIndex] = consumeIdent(m_range); | |
2012 } else { | |
2013 longhands[propertyIndex] = parseSingleValue(shorthand.properties ()[propertyIndex]); | |
2014 } | |
2015 if (longhands[propertyIndex]) | |
2016 foundLonghand = true; | |
2017 } | |
2018 if (!foundLonghand) | |
2019 return false; | |
2020 } while (!m_range.atEnd()); | |
2021 | |
2022 ImplicitScope implicitScope(this); | |
2023 for (size_t i = 0; i < shorthand.length(); ++i) { | |
2024 if (longhands[i]) | |
2025 addProperty(shorthand.properties()[i], longhands[i].release(), impor tant); | |
2026 else | |
2027 addProperty(shorthand.properties()[i], cssValuePool().createImplicit InitialValue(), important); | |
2028 } | |
2029 return true; | |
2030 } | |
2031 | |
1962 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) | 2032 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im portant) |
1963 { | 2033 { |
1964 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 2034 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
1965 | 2035 |
1966 m_range.consumeWhitespace(); | 2036 m_range.consumeWhitespace(); |
1967 CSSPropertyID oldShorthand = m_currentShorthand; | 2037 CSSPropertyID oldShorthand = m_currentShorthand; |
1968 // TODO(rob.buis): Remove this when the legacy property parser is gone | 2038 // TODO(rob.buis): Remove this when the legacy property parser is gone |
1969 m_currentShorthand = property; | 2039 m_currentShorthand = property; |
1970 switch (property) { | 2040 switch (property) { |
1971 case CSSPropertyWebkitMarginCollapse: { | 2041 case CSSPropertyWebkitMarginCollapse: { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2016 return consumeBorderSpacing(important); | 2086 return consumeBorderSpacing(important); |
2017 case CSSPropertyWebkitColumns: { | 2087 case CSSPropertyWebkitColumns: { |
2018 // TODO(rwlbuis): investigate if this shorthand hack can be removed. | 2088 // TODO(rwlbuis): investigate if this shorthand hack can be removed. |
2019 m_currentShorthand = oldShorthand; | 2089 m_currentShorthand = oldShorthand; |
2020 return consumeColumns(important); | 2090 return consumeColumns(important); |
2021 } | 2091 } |
2022 case CSSPropertyAnimation: | 2092 case CSSPropertyAnimation: |
2023 return consumeAnimationShorthand(animationShorthandForParsing(), unresol vedProperty == CSSPropertyAliasWebkitAnimation, important); | 2093 return consumeAnimationShorthand(animationShorthandForParsing(), unresol vedProperty == CSSPropertyAliasWebkitAnimation, important); |
2024 case CSSPropertyTransition: | 2094 case CSSPropertyTransition: |
2025 return consumeAnimationShorthand(transitionShorthandForParsing(), false, important); | 2095 return consumeAnimationShorthand(transitionShorthandForParsing(), false, important); |
2096 case CSSPropertyTextDecoration: { | |
2097 // Fall through 'text-decoration-line' parsing if CSS 3 Text Decoration | |
2098 // is disabled to match CSS 2.1 rules for parsing 'text-decoration'. | |
2099 if (RuntimeEnabledFeatures::css3TextDecorationsEnabled()) | |
2100 return consumeShorthandGreedily(textDecorationShorthand(), important ); | |
2101 RefPtrWillBeRawPtr<CSSValue> textDecoration = consumeTextDecorationLine( m_range); | |
2102 if (!textDecoration || !m_range.atEnd()) | |
2103 return false; | |
2104 addProperty(CSSPropertyTextDecoration, textDecoration.release(), importa nt); | |
2105 return true; | |
2106 } | |
2026 default: | 2107 default: |
2027 m_currentShorthand = oldShorthand; | 2108 m_currentShorthand = oldShorthand; |
2028 return false; | 2109 return false; |
2029 } | 2110 } |
2030 } | 2111 } |
2031 | 2112 |
2032 } // namespace blink | 2113 } // namespace blink |
OLD | NEW |