OLD | NEW |
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/CSSParserTokenRange.h" | 6 #include "core/css/parser/CSSParserTokenRange.h" |
7 | 7 |
8 #include "wtf/StaticConstructors.h" | 8 #include "wtf/StaticConstructors.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 DEFINE_GLOBAL(CSSParserToken, staticEOFToken); | 12 DEFINE_GLOBAL(CSSParserToken, staticEOFToken); |
13 | 13 |
14 void CSSParserTokenRange::initStaticEOFToken() | 14 void CSSParserTokenRange::initStaticEOFToken() |
15 { | 15 { |
16 new ((void*)&staticEOFToken) CSSParserToken(EOFToken); | 16 new ((void*)&staticEOFToken) CSSParserToken(EOFToken); |
17 } | 17 } |
18 | 18 |
19 CSSParserTokenRange CSSParserTokenRange::makeSubRange(const CSSParserToken* firs
t, const CSSParserToken* last) | 19 CSSParserTokenRange CSSParserTokenRange::makeSubRange(const CSSParserToken* firs
t, const CSSParserToken* last) |
20 { | 20 { |
21 if (first == &staticEOFToken) | 21 if (first == &staticEOFToken) |
22 first = m_last; | 22 first = m_last; |
23 if (last == &staticEOFToken) | 23 if (last == &staticEOFToken) |
24 last = m_last; | 24 last = m_last; |
25 ASSERT(first <= last); | 25 ASSERT(first <= last); |
26 return CSSParserTokenRange(first, last); | 26 return CSSParserTokenRange(first, last); |
27 } | 27 } |
28 | 28 |
| 29 CSSParserTokenRange CSSParserTokenRange::consumeBlock() |
| 30 { |
| 31 ASSERT(peek().blockType() == CSSParserToken::BlockStart); |
| 32 const CSSParserToken* start = &peek() + 1; |
| 33 unsigned nestingLevel = 0; |
| 34 do { |
| 35 const CSSParserToken& token = consume(); |
| 36 if (token.blockType() == CSSParserToken::BlockStart) |
| 37 nestingLevel++; |
| 38 else if (token.blockType() == CSSParserToken::BlockEnd) |
| 39 nestingLevel--; |
| 40 } while (nestingLevel && m_first < m_last); |
| 41 |
| 42 if (nestingLevel) |
| 43 return makeSubRange(start, m_first); // Ended at EOF |
| 44 return makeSubRange(start, m_first - 1); |
| 45 } |
| 46 |
29 void CSSParserTokenRange::consumeComponentValue() | 47 void CSSParserTokenRange::consumeComponentValue() |
30 { | 48 { |
31 // FIXME: This is going to do multiple passes over large sections of a style
sheet. | 49 // FIXME: This is going to do multiple passes over large sections of a style
sheet. |
32 // We should consider optimising this by precomputing where each block ends. | 50 // We should consider optimising this by precomputing where each block ends. |
33 unsigned nestingLevel = 0; | 51 unsigned nestingLevel = 0; |
34 do { | 52 do { |
35 const CSSParserToken& token = consume(); | 53 const CSSParserToken& token = consume(); |
36 if (token.blockType() == CSSParserToken::BlockStart) | 54 if (token.blockType() == CSSParserToken::BlockStart) |
37 nestingLevel++; | 55 nestingLevel++; |
38 else if (token.blockType() == CSSParserToken::BlockEnd) | 56 else if (token.blockType() == CSSParserToken::BlockEnd) |
39 nestingLevel--; | 57 nestingLevel--; |
40 } while (nestingLevel && m_first < m_last); | 58 } while (nestingLevel && m_first < m_last); |
41 } | 59 } |
42 | 60 |
43 void CSSParserTokenRange::consumeWhitespaceAndComments() | 61 void CSSParserTokenRange::consumeWhitespaceAndComments() |
44 { | 62 { |
45 while (peek().type() == WhitespaceToken || peek().type() == CommentToken) | 63 while (peek().type() == WhitespaceToken || peek().type() == CommentToken) |
46 ++m_first; | 64 ++m_first; |
47 } | 65 } |
48 | 66 |
49 } // namespace blink | 67 } // namespace blink |
OLD | NEW |