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

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

Issue 2632083002: Provide a CSSParserContext to CSSSyntaxDescriptor (Closed)
Patch Set: Fix parser context in PropertyRegistration Created 3 years, 11 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "core/css/CSSSyntaxDescriptor.h" 5 #include "core/css/CSSSyntaxDescriptor.h"
6 6
7 #include "core/css/CSSCustomPropertyDeclaration.h" 7 #include "core/css/CSSCustomPropertyDeclaration.h"
8 #include "core/css/CSSURIValue.h" 8 #include "core/css/CSSURIValue.h"
9 #include "core/css/CSSValueList.h" 9 #include "core/css/CSSValueList.h"
10 #include "core/css/CSSVariableReferenceValue.h" 10 #include "core/css/CSSVariableReferenceValue.h"
11 #include "core/css/parser/CSSParserContext.h"
12 #include "core/css/parser/CSSParserIdioms.h" 11 #include "core/css/parser/CSSParserIdioms.h"
13 #include "core/css/parser/CSSPropertyParserHelpers.h" 12 #include "core/css/parser/CSSPropertyParserHelpers.h"
14 #include "core/css/parser/CSSVariableParser.h" 13 #include "core/css/parser/CSSVariableParser.h"
15 #include "core/html/parser/HTMLParserIdioms.h" 14 #include "core/html/parser/HTMLParserIdioms.h"
16 15
17 namespace blink { 16 namespace blink {
18 17
19 void consumeWhitespace(const String& string, size_t& offset) { 18 void consumeWhitespace(const String& string, size_t& offset) {
20 while (isHTMLSpace(string[offset])) 19 while (isHTMLSpace(string[offset]))
21 offset++; 20 offset++;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 consumeWhitespace(input, offset); 122 consumeWhitespace(input, offset);
124 m_syntaxComponents.push_back(CSSSyntaxComponent(type, ident, repeatable)); 123 m_syntaxComponents.push_back(CSSSyntaxComponent(type, ident, repeatable));
125 124
126 } while (consumeCharacterAndWhitespace(input, '|', offset)); 125 } while (consumeCharacterAndWhitespace(input, '|', offset));
127 126
128 if (offset != input.length()) 127 if (offset != input.length())
129 m_syntaxComponents.clear(); 128 m_syntaxComponents.clear();
130 } 129 }
131 130
132 const CSSValue* consumeSingleType(const CSSSyntaxComponent& syntax, 131 const CSSValue* consumeSingleType(const CSSSyntaxComponent& syntax,
133 CSSParserTokenRange& range) { 132 CSSParserTokenRange& range,
133 const CSSParserContext* context) {
134 using namespace CSSPropertyParserHelpers; 134 using namespace CSSPropertyParserHelpers;
135 135
136 switch (syntax.m_type) { 136 switch (syntax.m_type) {
137 case CSSSyntaxType::Ident: 137 case CSSSyntaxType::Ident:
138 if (range.peek().type() == IdentToken && 138 if (range.peek().type() == IdentToken &&
139 range.peek().value() == syntax.m_string) { 139 range.peek().value() == syntax.m_string) {
140 range.consumeIncludingWhitespace(); 140 range.consumeIncludingWhitespace();
141 return CSSCustomIdentValue::create(AtomicString(syntax.m_string)); 141 return CSSCustomIdentValue::create(AtomicString(syntax.m_string));
142 } 142 }
143 return nullptr; 143 return nullptr;
144 case CSSSyntaxType::Length: 144 case CSSSyntaxType::Length:
145 return consumeLength(range, HTMLStandardMode, ValueRange::ValueRangeAll); 145 return consumeLength(range, HTMLStandardMode, ValueRange::ValueRangeAll);
146 case CSSSyntaxType::Number: 146 case CSSSyntaxType::Number:
147 return consumeNumber(range, ValueRange::ValueRangeAll); 147 return consumeNumber(range, ValueRange::ValueRangeAll);
148 case CSSSyntaxType::Percentage: 148 case CSSSyntaxType::Percentage:
149 return consumePercent(range, ValueRange::ValueRangeAll); 149 return consumePercent(range, ValueRange::ValueRangeAll);
150 case CSSSyntaxType::LengthPercentage: 150 case CSSSyntaxType::LengthPercentage:
151 return consumeLengthOrPercent(range, HTMLStandardMode, 151 return consumeLengthOrPercent(range, HTMLStandardMode,
152 ValueRange::ValueRangeAll); 152 ValueRange::ValueRangeAll);
153 case CSSSyntaxType::Color: 153 case CSSSyntaxType::Color:
154 return consumeColor(range, HTMLStandardMode); 154 return consumeColor(range, HTMLStandardMode);
155 case CSSSyntaxType::Image: 155 case CSSSyntaxType::Image:
156 // TODO(timloh): This probably needs a proper parser context for relative 156 return consumeImage(range, context);
157 // URL resolution.
158 return consumeImage(range, strictCSSParserContext());
159 case CSSSyntaxType::Url: 157 case CSSSyntaxType::Url:
160 return consumeUrl(range); 158 return consumeUrl(range);
161 case CSSSyntaxType::Integer: 159 case CSSSyntaxType::Integer:
162 return consumeInteger(range); 160 return consumeInteger(range);
163 case CSSSyntaxType::Angle: 161 case CSSSyntaxType::Angle:
164 return consumeAngle(range); 162 return consumeAngle(range);
165 case CSSSyntaxType::Time: 163 case CSSSyntaxType::Time:
166 return consumeTime(range, ValueRange::ValueRangeAll); 164 return consumeTime(range, ValueRange::ValueRangeAll);
167 case CSSSyntaxType::Resolution: 165 case CSSSyntaxType::Resolution:
168 return consumeResolution(range); 166 return consumeResolution(range);
169 case CSSSyntaxType::TransformFunction: 167 case CSSSyntaxType::TransformFunction:
170 return nullptr; // TODO(timloh): Implement this. 168 return nullptr; // TODO(timloh): Implement this.
171 case CSSSyntaxType::CustomIdent: 169 case CSSSyntaxType::CustomIdent:
172 return consumeCustomIdent(range); 170 return consumeCustomIdent(range);
173 default: 171 default:
174 NOTREACHED(); 172 NOTREACHED();
175 return nullptr; 173 return nullptr;
176 } 174 }
177 } 175 }
178 176
179 const CSSValue* consumeSyntaxComponent(const CSSSyntaxComponent& syntax, 177 const CSSValue* consumeSyntaxComponent(const CSSSyntaxComponent& syntax,
180 CSSParserTokenRange range) { 178 CSSParserTokenRange range,
179 const CSSParserContext* context) {
181 // CSS-wide keywords are already handled by the CSSPropertyParser 180 // CSS-wide keywords are already handled by the CSSPropertyParser
182 if (syntax.m_repeatable) { 181 if (syntax.m_repeatable) {
183 CSSValueList* list = CSSValueList::createSpaceSeparated(); 182 CSSValueList* list = CSSValueList::createSpaceSeparated();
184 while (!range.atEnd()) { 183 while (!range.atEnd()) {
185 const CSSValue* value = consumeSingleType(syntax, range); 184 const CSSValue* value = consumeSingleType(syntax, range, context);
186 if (!value) 185 if (!value)
187 return nullptr; 186 return nullptr;
188 list->append(*value); 187 list->append(*value);
189 } 188 }
190 return list; 189 return list;
191 } 190 }
192 const CSSValue* result = consumeSingleType(syntax, range); 191 const CSSValue* result = consumeSingleType(syntax, range, context);
193 if (!range.atEnd()) 192 if (!range.atEnd())
194 return nullptr; 193 return nullptr;
195 return result; 194 return result;
196 } 195 }
197 196
198 const CSSValue* CSSSyntaxDescriptor::parse(CSSParserTokenRange range, 197 const CSSValue* CSSSyntaxDescriptor::parse(CSSParserTokenRange range,
198 const CSSParserContext* context,
199 bool isAnimationTainted) const { 199 bool isAnimationTainted) const {
200 if (isTokenStream()) { 200 if (isTokenStream()) {
201 return CSSVariableParser::parseRegisteredPropertyValue(range, false, 201 return CSSVariableParser::parseRegisteredPropertyValue(range, false,
202 isAnimationTainted); 202 isAnimationTainted);
203 } 203 }
204 range.consumeWhitespace(); 204 range.consumeWhitespace();
205 for (const CSSSyntaxComponent& component : m_syntaxComponents) { 205 for (const CSSSyntaxComponent& component : m_syntaxComponents) {
206 if (const CSSValue* result = consumeSyntaxComponent(component, range)) 206 if (const CSSValue* result =
207 consumeSyntaxComponent(component, range, context))
207 return result; 208 return result;
208 } 209 }
209 return CSSVariableParser::parseRegisteredPropertyValue(range, true, 210 return CSSVariableParser::parseRegisteredPropertyValue(range, true,
210 isAnimationTainted); 211 isAnimationTainted);
211 } 212 }
212 213
213 } // namespace blink 214 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSSyntaxDescriptor.h ('k') | third_party/WebKit/Source/core/css/CSSVariableData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698