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 PassRefPtrWillBeRawPtr<CSSValue> consumeTextDecorationLine(CSSParserToken
Range& range) |
| 1490 { |
| 1491 CSSValueID id = range.peek().id(); |
| 1492 if (id == CSSValueNone) |
| 1493 return consumeIdent(range); |
| 1494 |
| 1495 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated()
; |
| 1496 RefPtrWillBeRawPtr<CSSPrimitiveValue> ident; |
| 1497 while ((ident = consumeIdent<CSSValueBlink, CSSValueUnderline, CSSValueOverl
ine, CSSValueLineThrough>(range))) { |
| 1498 if (list->hasValue(ident.get())) |
| 1499 return nullptr; |
| 1500 list->append(ident.release()); |
| 1501 } |
| 1502 |
| 1503 if (!list->length()) |
| 1504 return nullptr; |
| 1505 return list.release(); |
| 1506 } |
| 1507 |
1490 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
ID unresolvedProperty) | 1508 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
ID unresolvedProperty) |
1491 { | 1509 { |
1492 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 1510 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
1493 m_range.consumeWhitespace(); | 1511 m_range.consumeWhitespace(); |
1494 switch (property) { | 1512 switch (property) { |
1495 case CSSPropertyWillChange: | 1513 case CSSPropertyWillChange: |
1496 return consumeWillChange(m_range); | 1514 return consumeWillChange(m_range); |
1497 case CSSPropertyPage: | 1515 case CSSPropertyPage: |
1498 return consumePage(m_range); | 1516 return consumePage(m_range); |
1499 case CSSPropertyQuotes: | 1517 case CSSPropertyQuotes: |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 case CSSPropertyAnimationIterationCount: | 1595 case CSSPropertyAnimationIterationCount: |
1578 case CSSPropertyAnimationName: | 1596 case CSSPropertyAnimationName: |
1579 case CSSPropertyAnimationPlayState: | 1597 case CSSPropertyAnimationPlayState: |
1580 case CSSPropertyTransitionProperty: | 1598 case CSSPropertyTransitionProperty: |
1581 case CSSPropertyAnimationTimingFunction: | 1599 case CSSPropertyAnimationTimingFunction: |
1582 case CSSPropertyTransitionTimingFunction: | 1600 case CSSPropertyTransitionTimingFunction: |
1583 return consumeAnimationPropertyList(property, m_range, m_context, unreso
lvedProperty == CSSPropertyAliasWebkitAnimationName); | 1601 return consumeAnimationPropertyList(property, m_range, m_context, unreso
lvedProperty == CSSPropertyAliasWebkitAnimationName); |
1584 case CSSPropertyOrphans: | 1602 case CSSPropertyOrphans: |
1585 case CSSPropertyWidows: | 1603 case CSSPropertyWidows: |
1586 return consumeWidowsOrOrphans(m_range); | 1604 return consumeWidowsOrOrphans(m_range); |
| 1605 case CSSPropertyTextDecorationColor: |
| 1606 ASSERT(RuntimeEnabledFeatures::css3TextDecorationsEnabled()); |
| 1607 return consumeColor(m_range, m_context); |
1587 case CSSPropertyWebkitTextFillColor: | 1608 case CSSPropertyWebkitTextFillColor: |
1588 case CSSPropertyWebkitTapHighlightColor: | 1609 case CSSPropertyWebkitTapHighlightColor: |
1589 return consumeColor(m_range, m_context); | 1610 return consumeColor(m_range, m_context); |
1590 case CSSPropertyColor: | 1611 case CSSPropertyColor: |
1591 return consumeColor(m_range, m_context, inQuirksMode()); | 1612 return consumeColor(m_range, m_context, inQuirksMode()); |
1592 case CSSPropertyZIndex: | 1613 case CSSPropertyZIndex: |
1593 return consumeZIndex(m_range); | 1614 return consumeZIndex(m_range); |
1594 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS
3, so treat as CSS3 | 1615 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS
3, so treat as CSS3 |
1595 case CSSPropertyBoxShadow: | 1616 case CSSPropertyBoxShadow: |
1596 return consumeShadow(m_range, m_context, property == CSSPropertyBoxShado
w); | 1617 return consumeShadow(m_range, m_context, property == CSSPropertyBoxShado
w); |
1597 case CSSPropertyWebkitFilter: | 1618 case CSSPropertyWebkitFilter: |
1598 case CSSPropertyBackdropFilter: | 1619 case CSSPropertyBackdropFilter: |
1599 return consumeFilter(m_range, m_context); | 1620 return consumeFilter(m_range, m_context); |
| 1621 case CSSPropertyWebkitTextDecorationsInEffect: |
| 1622 case CSSPropertyTextDecorationLine: |
| 1623 return consumeTextDecorationLine(m_range); |
1600 default: | 1624 default: |
1601 return nullptr; | 1625 return nullptr; |
1602 } | 1626 } |
1603 } | 1627 } |
1604 | 1628 |
1605 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse
rTokenRange& range) | 1629 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse
rTokenRange& range) |
1606 { | 1630 { |
1607 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated
(); | 1631 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated
(); |
1608 | 1632 |
1609 do { | 1633 do { |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 return false; | 1976 return false; |
1953 if (!columnWidth) | 1977 if (!columnWidth) |
1954 columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto); | 1978 columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto); |
1955 if (!columnCount) | 1979 if (!columnCount) |
1956 columnCount = cssValuePool().createIdentifierValue(CSSValueAuto); | 1980 columnCount = cssValuePool().createIdentifierValue(CSSValueAuto); |
1957 addProperty(CSSPropertyWebkitColumnWidth, columnWidth.release(), important); | 1981 addProperty(CSSPropertyWebkitColumnWidth, columnWidth.release(), important); |
1958 addProperty(CSSPropertyWebkitColumnCount, columnCount.release(), important); | 1982 addProperty(CSSPropertyWebkitColumnCount, columnCount.release(), important); |
1959 return true; | 1983 return true; |
1960 } | 1984 } |
1961 | 1985 |
| 1986 bool CSSPropertyParser::consumeShorthandGreedily(const StylePropertyShorthand& s
horthand, bool important) |
| 1987 { |
| 1988 ASSERT(shorthand.length() <= 6); // Existing shorthands have at most 6 longh
ands. |
| 1989 RefPtrWillBeRawPtr<CSSValue> longhands[6] = { nullptr, nullptr, nullptr, nul
lptr, nullptr, nullptr }; |
| 1990 const CSSPropertyID* shorthandProperties = shorthand.properties(); |
| 1991 do { |
| 1992 bool foundLonghand = false; |
| 1993 for (size_t i = 0; !foundLonghand && i < shorthand.length(); ++i) { |
| 1994 if (longhands[i]) |
| 1995 continue; |
| 1996 // TODO: parseSingleValue needs to handle fastpath keywords. |
| 1997 if (CSSParserFastPaths::isKeywordPropertyID(shorthandProperties[i]))
{ |
| 1998 if (CSSParserFastPaths::isValidKeywordPropertyAndValue(shorthand
Properties[i], m_range.peek().id())) |
| 1999 longhands[i] = consumeIdent(m_range); |
| 2000 } else { |
| 2001 longhands[i] = parseSingleValue(shorthandProperties[i]); |
| 2002 } |
| 2003 if (longhands[i]) |
| 2004 foundLonghand = true; |
| 2005 } |
| 2006 if (!foundLonghand) |
| 2007 return false; |
| 2008 } while (!m_range.atEnd()); |
| 2009 |
| 2010 ImplicitScope implicitScope(this); |
| 2011 for (size_t i = 0; i < shorthand.length(); ++i) { |
| 2012 if (longhands[i]) |
| 2013 addProperty(shorthandProperties[i], longhands[i].release(), importan
t); |
| 2014 else |
| 2015 addProperty(shorthandProperties[i], cssValuePool().createImplicitIni
tialValue(), important); |
| 2016 } |
| 2017 return true; |
| 2018 } |
| 2019 |
1962 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im
portant) | 2020 bool CSSPropertyParser::parseShorthand(CSSPropertyID unresolvedProperty, bool im
portant) |
1963 { | 2021 { |
1964 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); | 2022 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); |
1965 | 2023 |
1966 m_range.consumeWhitespace(); | 2024 m_range.consumeWhitespace(); |
1967 CSSPropertyID oldShorthand = m_currentShorthand; | 2025 CSSPropertyID oldShorthand = m_currentShorthand; |
1968 // TODO(rob.buis): Remove this when the legacy property parser is gone | 2026 // TODO(rob.buis): Remove this when the legacy property parser is gone |
1969 m_currentShorthand = property; | 2027 m_currentShorthand = property; |
1970 switch (property) { | 2028 switch (property) { |
1971 case CSSPropertyWebkitMarginCollapse: { | 2029 case CSSPropertyWebkitMarginCollapse: { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2016 return consumeBorderSpacing(important); | 2074 return consumeBorderSpacing(important); |
2017 case CSSPropertyWebkitColumns: { | 2075 case CSSPropertyWebkitColumns: { |
2018 // TODO(rwlbuis): investigate if this shorthand hack can be removed. | 2076 // TODO(rwlbuis): investigate if this shorthand hack can be removed. |
2019 m_currentShorthand = oldShorthand; | 2077 m_currentShorthand = oldShorthand; |
2020 return consumeColumns(important); | 2078 return consumeColumns(important); |
2021 } | 2079 } |
2022 case CSSPropertyAnimation: | 2080 case CSSPropertyAnimation: |
2023 return consumeAnimationShorthand(animationShorthandForParsing(), unresol
vedProperty == CSSPropertyAliasWebkitAnimation, important); | 2081 return consumeAnimationShorthand(animationShorthandForParsing(), unresol
vedProperty == CSSPropertyAliasWebkitAnimation, important); |
2024 case CSSPropertyTransition: | 2082 case CSSPropertyTransition: |
2025 return consumeAnimationShorthand(transitionShorthandForParsing(), false,
important); | 2083 return consumeAnimationShorthand(transitionShorthandForParsing(), false,
important); |
| 2084 case CSSPropertyTextDecoration: { |
| 2085 // Fall through 'text-decoration-line' parsing if CSS 3 Text Decoration |
| 2086 // is disabled to match CSS 2.1 rules for parsing 'text-decoration'. |
| 2087 if (RuntimeEnabledFeatures::css3TextDecorationsEnabled()) |
| 2088 return consumeShorthandGreedily(textDecorationShorthand(), important
); |
| 2089 RefPtrWillBeRawPtr<CSSValue> textDecoration = consumeTextDecorationLine(
m_range); |
| 2090 if (!textDecoration || !m_range.atEnd()) |
| 2091 return false; |
| 2092 addProperty(CSSPropertyTextDecoration, textDecoration.release(), importa
nt); |
| 2093 return true; |
| 2094 } |
2026 default: | 2095 default: |
2027 m_currentShorthand = oldShorthand; | 2096 m_currentShorthand = oldShorthand; |
2028 return false; | 2097 return false; |
2029 } | 2098 } |
2030 } | 2099 } |
2031 | 2100 |
2032 } // namespace blink | 2101 } // namespace blink |
OLD | NEW |