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 "core/css/parser/CSSParserTokenRange.h" | 5 #include "core/css/parser/CSSParserTokenRange.h" |
6 | 6 |
7 #include "wtf/StaticConstructors.h" | 7 #include "wtf/StaticConstructors.h" |
8 #include "wtf/text/StringBuilder.h" | 8 #include "wtf/text/StringBuilder.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
(...skipping 26 matching lines...) Expand all Loading... |
37 else if (token.getBlockType() == CSSParserToken::BlockEnd) | 37 else if (token.getBlockType() == CSSParserToken::BlockEnd) |
38 nestingLevel--; | 38 nestingLevel--; |
39 } while (nestingLevel && m_first < m_last); | 39 } while (nestingLevel && m_first < m_last); |
40 | 40 |
41 if (nestingLevel) | 41 if (nestingLevel) |
42 return makeSubRange(start, m_first); // Ended at EOF | 42 return makeSubRange(start, m_first); // Ended at EOF |
43 return makeSubRange(start, m_first - 1); | 43 return makeSubRange(start, m_first - 1); |
44 } | 44 } |
45 | 45 |
46 void CSSParserTokenRange::consumeComponentValue() { | 46 void CSSParserTokenRange::consumeComponentValue() { |
47 // FIXME: This is going to do multiple passes over large sections of a stylesh
eet. | 47 // FIXME: This is going to do multiple passes over large sections of a |
48 // We should consider optimising this by precomputing where each block ends. | 48 // stylesheet. We should consider optimising this by precomputing where each |
| 49 // block ends. |
49 unsigned nestingLevel = 0; | 50 unsigned nestingLevel = 0; |
50 do { | 51 do { |
51 const CSSParserToken& token = consume(); | 52 const CSSParserToken& token = consume(); |
52 if (token.getBlockType() == CSSParserToken::BlockStart) | 53 if (token.getBlockType() == CSSParserToken::BlockStart) |
53 nestingLevel++; | 54 nestingLevel++; |
54 else if (token.getBlockType() == CSSParserToken::BlockEnd) | 55 else if (token.getBlockType() == CSSParserToken::BlockEnd) |
55 nestingLevel--; | 56 nestingLevel--; |
56 } while (nestingLevel && m_first < m_last); | 57 } while (nestingLevel && m_first < m_last); |
57 } | 58 } |
58 | 59 |
59 String CSSParserTokenRange::serialize() const { | 60 String CSSParserTokenRange::serialize() const { |
60 // We're supposed to insert comments between certain pairs of token types | 61 // We're supposed to insert comments between certain pairs of token types |
61 // as per spec, but since this is currently only used for @supports CSSOM | 62 // as per spec, but since this is currently only used for @supports CSSOM |
62 // we just get these cases wrong and avoid the additional complexity. | 63 // we just get these cases wrong and avoid the additional complexity. |
63 StringBuilder builder; | 64 StringBuilder builder; |
64 for (const CSSParserToken* it = m_first; it < m_last; ++it) | 65 for (const CSSParserToken* it = m_first; it < m_last; ++it) |
65 it->serialize(builder); | 66 it->serialize(builder); |
66 return builder.toString(); | 67 return builder.toString(); |
67 } | 68 } |
68 | 69 |
69 } // namespace blink | 70 } // namespace blink |
OLD | NEW |