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

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

Issue 225293006: Moved MQ parsing block tracking to tokenizer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed unused member var Created 6 years, 8 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 2014 The Chromium Authors. All rights reserved. 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 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/MediaQueryTokenizer.h" 6 #include "core/css/parser/MediaQueryTokenizer.h"
7 7
8 namespace WebCore { 8 namespace WebCore {
9 #include "MediaQueryTokenizerCodepoints.cpp" 9 #include "MediaQueryTokenizerCodepoints.cpp"
10 } 10 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 MediaQueryToken MediaQueryTokenizer::whiteSpace(UChar cc) 62 MediaQueryToken MediaQueryTokenizer::whiteSpace(UChar cc)
63 { 63 {
64 // CSS Tokenization is currently lossy, but we could record 64 // CSS Tokenization is currently lossy, but we could record
65 // the exact whitespace instead of discarding it here. 65 // the exact whitespace instead of discarding it here.
66 consumeUntilNonWhitespace(); 66 consumeUntilNonWhitespace();
67 return MediaQueryToken(WhitespaceToken); 67 return MediaQueryToken(WhitespaceToken);
68 } 68 }
69 69
70 static bool popIfBlockMatches(Vector<MediaQueryTokenType>& blockStack, MediaQuer yTokenType type)
71 {
72 if (!blockStack.isEmpty() && blockStack.last() == type) {
73 blockStack.removeLast();
74 return true;
75 }
76 return false;
77 }
78
79 MediaQueryToken MediaQueryTokenizer::blockStart(MediaQueryTokenType type)
80 {
81 m_blockStack.append(type);
82 return MediaQueryToken(type, MediaQueryToken::BlockStart);
83 }
84
85 MediaQueryToken MediaQueryTokenizer::blockStart(MediaQueryTokenType blockType, M ediaQueryTokenType type, String name)
86 {
87 m_blockStack.append(blockType);
88 return MediaQueryToken(type, name, MediaQueryToken::BlockStart);
89 }
90
91 MediaQueryToken MediaQueryTokenizer::blockEnd(MediaQueryTokenType type, MediaQue ryTokenType startType)
92 {
93 if (popIfBlockMatches(m_blockStack, startType))
94 return MediaQueryToken(type, MediaQueryToken::BlockEnd);
95 return MediaQueryToken(type);
96 }
97
70 MediaQueryToken MediaQueryTokenizer::leftParenthesis(UChar cc) 98 MediaQueryToken MediaQueryTokenizer::leftParenthesis(UChar cc)
71 { 99 {
72 return MediaQueryToken(LeftParenthesisToken); 100 return blockStart(LeftParenthesisToken);
73 } 101 }
74 102
75 MediaQueryToken MediaQueryTokenizer::rightParenthesis(UChar cc) 103 MediaQueryToken MediaQueryTokenizer::rightParenthesis(UChar cc)
76 { 104 {
77 return MediaQueryToken(RightParenthesisToken); 105 return blockEnd(RightParenthesisToken, LeftParenthesisToken);
78 } 106 }
79 107
80 MediaQueryToken MediaQueryTokenizer::leftBracket(UChar cc) 108 MediaQueryToken MediaQueryTokenizer::leftBracket(UChar cc)
81 { 109 {
82 return MediaQueryToken(LeftBracketToken); 110 return blockStart(LeftBracketToken);
83 } 111 }
84 112
85 MediaQueryToken MediaQueryTokenizer::rightBracket(UChar cc) 113 MediaQueryToken MediaQueryTokenizer::rightBracket(UChar cc)
86 { 114 {
87 return MediaQueryToken(RightBracketToken); 115 return blockEnd(RightBracketToken, LeftBracketToken);
88 } 116 }
89 117
90 MediaQueryToken MediaQueryTokenizer::leftBrace(UChar cc) 118 MediaQueryToken MediaQueryTokenizer::leftBrace(UChar cc)
91 { 119 {
92 return MediaQueryToken(LeftBraceToken); 120 return blockStart(LeftBraceToken);
93 } 121 }
94 122
95 MediaQueryToken MediaQueryTokenizer::rightBrace(UChar cc) 123 MediaQueryToken MediaQueryTokenizer::rightBrace(UChar cc)
96 { 124 {
97 return MediaQueryToken(RightBraceToken); 125 return blockEnd(RightBraceToken, LeftBraceToken);
98 } 126 }
99 127
100 MediaQueryToken MediaQueryTokenizer::plusOrFullStop(UChar cc) 128 MediaQueryToken MediaQueryTokenizer::plusOrFullStop(UChar cc)
101 { 129 {
102 if (nextCharsAreNumber()) { 130 if (nextCharsAreNumber()) {
103 reconsume(cc); 131 reconsume(cc);
104 return consumeNumericToken(); 132 return consumeNumericToken();
105 } 133 }
106 return MediaQueryToken(DelimiterToken, cc); 134 return MediaQueryToken(DelimiterToken, cc);
107 } 135 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 237
210 if (isASCII(cc)) { 238 if (isASCII(cc)) {
211 ASSERT_WITH_SECURITY_IMPLICATION(cc < codePointsNumber); 239 ASSERT_WITH_SECURITY_IMPLICATION(cc < codePointsNumber);
212 codePointFunc = codePoints[cc]; 240 codePointFunc = codePoints[cc];
213 } else { 241 } else {
214 codePointFunc = &MediaQueryTokenizer::nameStart; 242 codePointFunc = &MediaQueryTokenizer::nameStart;
215 } 243 }
216 244
217 if (codePointFunc) 245 if (codePointFunc)
218 return ((this)->*(codePointFunc))(cc); 246 return ((this)->*(codePointFunc))(cc);
219
220 return MediaQueryToken(DelimiterToken, cc); 247 return MediaQueryToken(DelimiterToken, cc);
221 } 248 }
222 249
223 static int getSign(MediaQueryInputStream& input, unsigned& offset) 250 static int getSign(MediaQueryInputStream& input, unsigned& offset)
224 { 251 {
225 int sign = 1; 252 int sign = 1;
226 if (input.currentInputChar() == '+') { 253 if (input.currentInputChar() == '+') {
227 ++offset; 254 ++offset;
228 } else if (input.peek(offset) == '-') { 255 } else if (input.peek(offset) == '-') {
229 sign = -1; 256 sign = -1;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 token.convertToDimensionWithUnit(consumeName()); 335 token.convertToDimensionWithUnit(consumeName());
309 else if (consumeIfNext('%')) 336 else if (consumeIfNext('%'))
310 token.convertToPercentage(); 337 token.convertToPercentage();
311 return token; 338 return token;
312 } 339 }
313 340
314 // http://www.w3.org/TR/css3-syntax/#consume-an-ident-like-token 341 // http://www.w3.org/TR/css3-syntax/#consume-an-ident-like-token
315 MediaQueryToken MediaQueryTokenizer::consumeIdentLikeToken() 342 MediaQueryToken MediaQueryTokenizer::consumeIdentLikeToken()
316 { 343 {
317 String name = consumeName(); 344 String name = consumeName();
318 if (consumeIfNext('(')) 345 if (consumeIfNext('(')) {
319 return MediaQueryToken(FunctionToken, name); 346 return blockStart(LeftParenthesisToken, FunctionToken, name);
347 }
320 return MediaQueryToken(IdentToken, name); 348 return MediaQueryToken(IdentToken, name);
321 } 349 }
322 350
323 static bool isNewLine(UChar cc) 351 static bool isNewLine(UChar cc)
324 { 352 {
325 // We check \r and \f here, since we have no preprocessing stage 353 // We check \r and \f here, since we have no preprocessing stage
326 return (cc == '\r' || cc == '\n' || cc == '\f'); 354 return (cc == '\r' || cc == '\n' || cc == '\f');
327 } 355 }
328 356
329 // http://dev.w3.org/csswg/css-syntax/#consume-a-string-token 357 // http://dev.w3.org/csswg/css-syntax/#consume-a-string-token
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 if (firstChar == '-') { 495 if (firstChar == '-') {
468 if (isNameStart(m_input.peek(1))) 496 if (isNameStart(m_input.peek(1)))
469 return true; 497 return true;
470 return nextTwoCharsAreValidEscape(1); 498 return nextTwoCharsAreValidEscape(1);
471 } 499 }
472 500
473 return false; 501 return false;
474 } 502 }
475 503
476 } // namespace WebCore 504 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/parser/MediaQueryTokenizer.h ('k') | Source/core/css/parser/MediaQueryTokenizerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698