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

Side by Side Diff: Source/core/css/parser/CSSPropertyParserNew.cpp

Issue 1319343004: Add property parser code path based on CSSParserTokenRange (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add handling of overflow shorthand Created 5 years, 3 months 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 namespace blink {
6
7 static bool consumeCommaIncludingWhitespace(CSSParserTokenRange& valueList)
8 {
9 CSSParserToken value = valueList.peek();
10 if (value.type() != CommaToken)
11 return false;
12 valueList.consumeIncludingWhitespace();
13 return true;
14 }
15
16 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeIdent(CSSParserTokenRang e& range)
17 {
18 ASSERT(range.peek().type() == IdentToken);
19 return cssValuePool().createIdentifierValue(range.consumeIncludingWhitespace ().id());
20 }
21
22 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumePrimitiveCustomIdentValu e(CSSParserTokenRange& range)
23 {
24 ASSERT(range.peek().unitType() == CSSPrimitiveValue::UnitType::String || ran ge.peek().type() == IdentToken);
25 return cssValuePool().createValue(range.consumeIncludingWhitespace().value() , CSSPrimitiveValue::UnitType::CustomIdentifier);
26 }
27
28 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId)
29 {
30 m_range.consumeWhitespace();
31 switch (propId) {
32 case CSSPropertyWillChange:
33 return parseWillChange();
34 case CSSPropertyPage:
35 return parsePage();
36 default:
37 return nullptr;
38 }
39 }
40
41 bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important)
42 {
43 m_range.consumeWhitespace();
44 switch (propId) {
45 case CSSPropertyWebkitMarginCollapse: {
46 CSSValueID id = m_range.consumeIncludingWhitespace().id();
47 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(webkitMarginColl apseShorthand().properties()[0], id))
48 return false;
49 addProperty(webkitMarginCollapseShorthand().properties()[0], cssValuePoo l().createIdentifierValue(id), important);
50 if (m_range.atEnd()) {
51 CSSValue* value = m_parsedProperties.last().value();
52 addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
53 return true;
54 }
55 id = m_range.consumeIncludingWhitespace().id();
56 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(webkitMarginColl apseShorthand().properties()[1], id))
57 return false;
58 addProperty(webkitMarginCollapseShorthand().properties()[1], cssValuePoo l().createIdentifierValue(id), important);
59 return true;
60 }
61 case CSSPropertyOverflow: {
62 CSSValueID id = m_range.consumeIncludingWhitespace().id();
63 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyOverf lowY, id))
64 return false;
65 if (!m_range.atEnd())
66 return false;
67 addProperty(CSSPropertyOverflowY, cssValuePool().createIdentifierValue(i d), important);
68
69 RefPtrWillBeRawPtr<CSSValue> overflowXValue = nullptr;
70
71 // FIXME: -webkit-paged-x or -webkit-paged-y only apply to overflow-y. I f this value has been
72 // set using the shorthand, then for now overflow-x will default to auto , but once we implement
73 // pagination controls, it should default to hidden. If the overflow-y v alue is anything but
74 // paged-x or paged-y, then overflow-x and overflow-y should have the sa me value.
75 if (id == CSSValueWebkitPagedX || id == CSSValueWebkitPagedY)
76 overflowXValue = cssValuePool().createIdentifierValue(CSSValueAuto);
77 else
78 overflowXValue = m_parsedProperties.last().value();
79 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important);
80 return true;
81 }
82 default:
83 return false;
84 }
85 }
86
87 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseWillChange()
88 {
89 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated ();
90 if (m_range.peek().id() == CSSValueAuto) {
91 values->append(consumeIdent(m_range));
92 return values.release();
93 }
94
95 // Every comma-separated list of identifiers is a valid will-change value,
96 // unless the list includes an explicitly disallowed identifier.
97 while (true) {
98 if (m_range.peek().type() != IdentToken)
99 return nullptr;
100 CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(m_range.peek( ).value());
101 if (unresolvedProperty) {
102 ASSERT(CSSPropertyMetadata::isEnabledProperty(unresolvedProperty));
103 // Now "all" is used by both CSSValue and CSSPropertyValue.
104 // Need to return nullptr when currentValue is CSSPropertyAll.
105 if (unresolvedProperty == CSSPropertyWillChange || unresolvedPropert y == CSSPropertyAll)
106 return nullptr;
107 values->append(cssValuePool().createIdentifierValue(unresolvedProper ty));
108 m_range.consumeIncludingWhitespace();
109 } else {
110 switch (m_range.peek().id()) {
111 case CSSValueNone:
112 case CSSValueAll:
113 case CSSValueAuto:
114 case CSSValueDefault:
115 case CSSValueInitial:
116 case CSSValueInherit:
117 return nullptr;
118 case CSSValueContents:
119 case CSSValueScrollPosition:
120 values->append(consumeIdent(m_range));
121 break;
122 default:
123 m_range.consumeIncludingWhitespace();
124 break;
125 }
126 }
127
128 if (m_range.atEnd())
129 break;
130 if (!consumeCommaIncludingWhitespace(m_range))
131 return nullptr;
132 }
133
134 return values.release();
135 }
136
137 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parsePage()
138 {
139 CSSParserToken token = m_range.peek();
140 if (token.id() == CSSValueAuto)
141 return consumeIdent(m_range);
142 if (token.type() == IdentToken)
143 return consumePrimitiveCustomIdentValue(m_range);
144 return nullptr;
145 }
146
147 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698