OLD | NEW |
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 #ifndef CSSPropertyParserHelpers_h | 5 #ifndef CSSPropertyParserHelpers_h |
6 #define CSSPropertyParserHelpers_h | 6 #define CSSPropertyParserHelpers_h |
7 | 7 |
8 #include "core/css/CSSCustomIdentValue.h" | 8 #include "core/css/CSSCustomIdentValue.h" |
9 #include "core/css/CSSIdentifierValue.h" | 9 #include "core/css/CSSIdentifierValue.h" |
10 #include "core/css/CSSPrimitiveValue.h" | 10 #include "core/css/CSSPrimitiveValue.h" |
| 11 #include "core/css/CSSValueList.h" |
11 #include "core/css/parser/CSSParserMode.h" | 12 #include "core/css/parser/CSSParserMode.h" |
12 #include "core/css/parser/CSSParserTokenRange.h" | 13 #include "core/css/parser/CSSParserTokenRange.h" |
13 #include "platform/Length.h" // For ValueRange | 14 #include "platform/Length.h" // For ValueRange |
14 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
18 class CSSParserContext; | 19 class CSSParserContext; |
19 class CSSStringValue; | 20 class CSSStringValue; |
20 class CSSURIValue; | 21 class CSSURIValue; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 115 } |
115 | 116 |
116 template <CSSValueID... names> | 117 template <CSSValueID... names> |
117 CSSIdentifierValue* ConsumeIdent(CSSParserTokenRange& range) { | 118 CSSIdentifierValue* ConsumeIdent(CSSParserTokenRange& range) { |
118 if (range.Peek().GetType() != kIdentToken || | 119 if (range.Peek().GetType() != kIdentToken || |
119 !IdentMatches<names...>(range.Peek().Id())) | 120 !IdentMatches<names...>(range.Peek().Id())) |
120 return nullptr; | 121 return nullptr; |
121 return CSSIdentifierValue::Create(range.ConsumeIncludingWhitespace().Id()); | 122 return CSSIdentifierValue::Create(range.ConsumeIncludingWhitespace().Id()); |
122 } | 123 } |
123 | 124 |
| 125 // TODO(bugsnash): add comment about callback requirements |
| 126 template <typename callback, typename... Args> |
| 127 CSSValueList* ConsumeCommaSeparatedList(CSSParserTokenRange& range, |
| 128 callback f, |
| 129 Args... args) { |
| 130 CSSValueList* list = CSSValueList::CreateCommaSeparated(); |
| 131 do { |
| 132 CSSValue* value = f(range, args...); |
| 133 if (!value) |
| 134 return nullptr; |
| 135 list->Append(*value); |
| 136 } while (ConsumeCommaIncludingWhitespace(range)); |
| 137 DCHECK(list->length()); |
| 138 return list; |
| 139 } |
| 140 |
124 } // namespace CSSPropertyParserHelpers | 141 } // namespace CSSPropertyParserHelpers |
125 | 142 |
126 } // namespace blink | 143 } // namespace blink |
127 | 144 |
128 #endif // CSSPropertyParserHelpers_h | 145 #endif // CSSPropertyParserHelpers_h |
OLD | NEW |