Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp

Issue 1412803007: Parse text-decoration shorthand in CSSPropertyParser with CSSParserTokens (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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)) {
Timothy Loh 2015/11/04 00:03:02 just use ids.contains(id)
1511 list->append(consumeIdent(range));
1512 ids.remove(id);
1513 id = range.peek().id();
1514 }
1515
1516 if (!list->length())
1517 return nullptr;
1518 return list.release();
1519 }
1520
1490 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty) 1521 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID unresolvedProperty)
1491 { 1522 {
1492 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); 1523 CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
1493 m_range.consumeWhitespace(); 1524 m_range.consumeWhitespace();
1494 switch (property) { 1525 switch (property) {
1495 case CSSPropertyWillChange: 1526 case CSSPropertyWillChange:
1496 return consumeWillChange(m_range); 1527 return consumeWillChange(m_range);
1497 case CSSPropertyPage: 1528 case CSSPropertyPage:
1498 return consumePage(m_range); 1529 return consumePage(m_range);
1499 case CSSPropertyQuotes: 1530 case CSSPropertyQuotes:
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 case CSSPropertyAnimationIterationCount: 1608 case CSSPropertyAnimationIterationCount:
1578 case CSSPropertyAnimationName: 1609 case CSSPropertyAnimationName:
1579 case CSSPropertyAnimationPlayState: 1610 case CSSPropertyAnimationPlayState:
1580 case CSSPropertyTransitionProperty: 1611 case CSSPropertyTransitionProperty:
1581 case CSSPropertyAnimationTimingFunction: 1612 case CSSPropertyAnimationTimingFunction:
1582 case CSSPropertyTransitionTimingFunction: 1613 case CSSPropertyTransitionTimingFunction:
1583 return consumeAnimationPropertyList(property, m_range, m_context, unreso lvedProperty == CSSPropertyAliasWebkitAnimationName); 1614 return consumeAnimationPropertyList(property, m_range, m_context, unreso lvedProperty == CSSPropertyAliasWebkitAnimationName);
1584 case CSSPropertyOrphans: 1615 case CSSPropertyOrphans:
1585 case CSSPropertyWidows: 1616 case CSSPropertyWidows:
1586 return consumeWidowsOrOrphans(m_range); 1617 return consumeWidowsOrOrphans(m_range);
1618 case CSSPropertyTextDecorationColor:
1619 ASSERT(RuntimeEnabledFeatures::css3TextDecorationsEnabled());
Timothy Loh 2015/11/04 00:03:02 I'd prefer if it didn't fall-through (it's a singl
1587 case CSSPropertyWebkitTextFillColor: 1620 case CSSPropertyWebkitTextFillColor:
1588 case CSSPropertyWebkitTapHighlightColor: 1621 case CSSPropertyWebkitTapHighlightColor:
1589 return consumeColor(m_range, m_context); 1622 return consumeColor(m_range, m_context);
1590 case CSSPropertyColor: 1623 case CSSPropertyColor:
1591 return consumeColor(m_range, m_context, inQuirksMode()); 1624 return consumeColor(m_range, m_context, inQuirksMode());
1592 case CSSPropertyZIndex: 1625 case CSSPropertyZIndex:
1593 return consumeZIndex(m_range); 1626 return consumeZIndex(m_range);
1594 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS 3, so treat as CSS3 1627 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS 3, so treat as CSS3
1595 case CSSPropertyBoxShadow: 1628 case CSSPropertyBoxShadow:
1596 return consumeShadow(m_range, m_context, property == CSSPropertyBoxShado w); 1629 return consumeShadow(m_range, m_context, property == CSSPropertyBoxShado w);
1597 case CSSPropertyWebkitFilter: 1630 case CSSPropertyWebkitFilter:
1598 case CSSPropertyBackdropFilter: 1631 case CSSPropertyBackdropFilter:
1599 return consumeFilter(m_range, m_context); 1632 return consumeFilter(m_range, m_context);
1633 case CSSPropertyWebkitTextDecorationsInEffect:
1634 case CSSPropertyTextDecorationLine:
1635 return consumeTextDecorationLine(m_range);
1600 default: 1636 default:
1601 return nullptr; 1637 return nullptr;
1602 } 1638 }
1603 } 1639 }
1604 1640
1605 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) 1641 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range)
1606 { 1642 {
1607 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); 1643 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated ();
1608 1644
1609 do { 1645 do {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 return false; 1988 return false;
1953 if (!columnWidth) 1989 if (!columnWidth)
1954 columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto); 1990 columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto);
1955 if (!columnCount) 1991 if (!columnCount)
1956 columnCount = cssValuePool().createIdentifierValue(CSSValueAuto); 1992 columnCount = cssValuePool().createIdentifierValue(CSSValueAuto);
1957 addProperty(CSSPropertyWebkitColumnWidth, columnWidth.release(), important); 1993 addProperty(CSSPropertyWebkitColumnWidth, columnWidth.release(), important);
1958 addProperty(CSSPropertyWebkitColumnCount, columnCount.release(), important); 1994 addProperty(CSSPropertyWebkitColumnCount, columnCount.release(), important);
1959 return true; 1995 return true;
1960 } 1996 }
1961 1997
1998 bool CSSPropertyParser::consumeShorthandGreedily(const StylePropertyShorthand& s horthand, bool important)
1999 {
2000 ASSERT(shorthand.length() <= 6); // Existing shorthands have at most 6 longh ands.
2001 RefPtrWillBeRawPtr<CSSValue> longhands[6] = { nullptr, nullptr, nullptr, nul lptr, nullptr, nullptr };
2002 const CSSPropertyID* shorthandProperties = shorthand.properties();
2003 do {
2004 bool foundLonghand = false;
2005 for (size_t i = 0; !foundLonghand && i < shorthand.length(); ++i) {
2006 if (longhands[i])
2007 continue;
2008 // TODO: parseSingleValue needs to handle fastpath keywords.
2009 if (CSSParserFastPaths::isKeywordPropertyID(shorthandProperties[i])) {
2010 if (CSSParserFastPaths::isValidKeywordPropertyAndValue(shorthand Properties[i], m_range.peek().id()))
2011 longhands[i] = consumeIdent(m_range);
2012 } else {
2013 longhands[i] = parseSingleValue(shorthandProperties[i]);
2014 }
2015 if (longhands[i])
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(shorthandProperties[i], longhands[i].release(), importan t);
2026 else
2027 addProperty(shorthandProperties[i], cssValuePool().createImplicitIni tialValue(), 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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698