OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #include "config.h" | 21 #include "config.h" |
22 #include "core/css/parser/CSSParserValues.h" | 22 #include "core/css/parser/CSSParserValues.h" |
23 | 23 |
24 #include "core/css/CSSFunctionValue.h" | 24 #include "core/css/CSSFunctionValue.h" |
25 #include "core/css/CSSSelectorList.h" | 25 #include "core/css/CSSSelectorList.h" |
26 #include "core/css/CSSVariableData.h" | |
26 #include "core/css/parser/CSSParserToken.h" | 27 #include "core/css/parser/CSSParserToken.h" |
27 #include "core/css/parser/CSSParserTokenRange.h" | 28 #include "core/css/parser/CSSParserTokenRange.h" |
28 #include "core/css/parser/CSSPropertyParser.h" | 29 #include "core/css/parser/CSSPropertyParser.h" |
30 #include "core/css/parser/CSSTokenizer.h" | |
Timothy Loh
2015/08/25 09:21:10
not used?
| |
31 #include "core/css/parser/CSSVariableParser.h" | |
29 #include "core/html/parser/HTMLParserIdioms.h" | 32 #include "core/html/parser/HTMLParserIdioms.h" |
33 #include "wtf/text/StringBuilder.h" | |
Timothy Loh
2015/08/25 09:21:10
not used?
| |
30 | 34 |
31 namespace blink { | 35 namespace blink { |
32 | 36 |
33 using namespace WTF; | 37 using namespace WTF; |
34 | 38 |
35 CSSParserValueList::CSSParserValueList(CSSParserTokenRange range) | 39 CSSParserValueList::CSSParserValueList(CSSParserTokenRange range) |
36 : m_current(0) | 40 : m_current(0) |
37 { | 41 { |
42 CSSParserTokenRange originalRangeForVariables = range; | |
Timothy Loh
2015/08/25 09:21:10
Maybe better to check for variables in the CSSProp
| |
43 | |
38 Vector<CSSParserValueList*> stack; | 44 Vector<CSSParserValueList*> stack; |
39 Vector<int> bracketCounts; | 45 Vector<int> bracketCounts; |
40 stack.append(this); | 46 stack.append(this); |
41 bracketCounts.append(0); | 47 bracketCounts.append(0); |
42 while (!range.atEnd()) { | 48 while (!range.atEnd()) { |
43 ASSERT(stack.size() == bracketCounts.size()); | 49 ASSERT(stack.size() == bracketCounts.size()); |
44 ASSERT(!stack.isEmpty()); | 50 ASSERT(!stack.isEmpty()); |
45 const CSSParserToken& token = range.peek(); | 51 const CSSParserToken& token = range.peek(); |
46 if (token.type() != FunctionToken) | 52 if (token.type() != FunctionToken) |
47 range.consume(); | 53 range.consume(); |
48 CSSParserValue value; | 54 CSSParserValue value; |
49 switch (token.type()) { | 55 switch (token.type()) { |
50 case FunctionToken: { | 56 case FunctionToken: { |
51 if (token.valueEqualsIgnoringCase("url")) { | 57 if (token.valueEqualsIgnoringCase("url")) { |
52 range.consume(); | 58 range.consume(); |
53 const CSSParserToken& next = range.consumeIncludingWhitespace(); | 59 const CSSParserToken& next = range.consumeIncludingWhitespace(); |
54 if (next.type() == BadStringToken || range.consume().type() != R ightParenthesisToken) { | 60 if (next.type() == BadStringToken || range.consume().type() != R ightParenthesisToken) { |
55 destroyAndClear(); | 61 checkForVariableReferencesOrDestroyAndClear(originalRangeFor Variables); |
56 return; | 62 return; |
57 } | 63 } |
58 ASSERT(next.type() == StringToken); | 64 ASSERT(next.type() == StringToken); |
59 value.id = CSSValueInvalid; | 65 value.id = CSSValueInvalid; |
60 value.isInt = false; | 66 value.isInt = false; |
61 value.setUnit(CSSPrimitiveValue::UnitType::URI); | 67 value.setUnit(CSSPrimitiveValue::UnitType::URI); |
62 value.string = next.value(); | 68 value.string = next.value(); |
63 break; | 69 break; |
70 } else if (token.valueEqualsIgnoringCase("var")) { | |
71 checkForVariableReferencesOrDestroyAndClear(originalRangeForVari ables); | |
72 return; | |
64 } | 73 } |
65 | 74 |
66 value.id = CSSValueInvalid; | 75 value.id = CSSValueInvalid; |
67 value.isInt = false; | 76 value.isInt = false; |
68 | 77 |
69 CSSValueID id = cssValueKeywordID(token.value()); | 78 CSSValueID id = cssValueKeywordID(token.value()); |
70 if (id == CSSValueCalc || id == CSSValueWebkitCalc) { | 79 if (id == CSSValueCalc || id == CSSValueWebkitCalc) { |
71 value.m_unit = CSSParserValue::CalcFunction; | 80 value.m_unit = CSSParserValue::CalcFunction; |
72 value.calcFunction = new CSSParserCalcFunction(range.consumeBloc k()); | 81 value.calcFunction = new CSSParserCalcFunction(range.consumeBloc k()); |
73 break; | 82 break; |
(...skipping 18 matching lines...) Expand all Loading... | |
92 stack.last()->addValue(value); | 101 stack.last()->addValue(value); |
93 stack.append(list); | 102 stack.append(list); |
94 bracketCounts.append(0); | 103 bracketCounts.append(0); |
95 continue; | 104 continue; |
96 } | 105 } |
97 case RightParenthesisToken: { | 106 case RightParenthesisToken: { |
98 if (bracketCounts.last() == 0) { | 107 if (bracketCounts.last() == 0) { |
99 stack.removeLast(); | 108 stack.removeLast(); |
100 bracketCounts.removeLast(); | 109 bracketCounts.removeLast(); |
101 if (bracketCounts.isEmpty()) { | 110 if (bracketCounts.isEmpty()) { |
102 destroyAndClear(); | 111 checkForVariableReferencesOrDestroyAndClear(originalRangeFor Variables); |
103 return; | 112 return; |
104 } | 113 } |
105 continue; | 114 continue; |
106 } | 115 } |
107 bracketCounts.last()--; | 116 bracketCounts.last()--; |
108 value.setFromOperator(')'); | 117 value.setFromOperator(')'); |
109 break; | 118 break; |
110 } | 119 } |
111 case IdentToken: { | 120 case IdentToken: { |
112 value.id = cssValueKeywordID(token.value()); | 121 value.id = cssValueKeywordID(token.value()); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 ASSERT_NOT_REACHED(); | 205 ASSERT_NOT_REACHED(); |
197 case CDOToken: | 206 case CDOToken: |
198 case CDCToken: | 207 case CDCToken: |
199 case AtKeywordToken: | 208 case AtKeywordToken: |
200 case IncludeMatchToken: | 209 case IncludeMatchToken: |
201 case DashMatchToken: | 210 case DashMatchToken: |
202 case PrefixMatchToken: | 211 case PrefixMatchToken: |
203 case SuffixMatchToken: | 212 case SuffixMatchToken: |
204 case SubstringMatchToken: | 213 case SubstringMatchToken: |
205 case ColumnToken: | 214 case ColumnToken: |
215 case ColonToken: | |
216 case SemicolonToken: | |
217 checkForVariableReferencesOrDestroyAndClear(originalRangeForVariable s); | |
218 return; | |
206 case BadStringToken: | 219 case BadStringToken: |
207 case BadUrlToken: | 220 case BadUrlToken: |
208 case ColonToken: | |
209 case SemicolonToken: | |
210 destroyAndClear(); | 221 destroyAndClear(); |
211 return; | 222 return; |
212 } | 223 } |
213 stack.last()->addValue(value); | 224 stack.last()->addValue(value); |
214 } | 225 } |
215 | 226 |
216 CSSParserValue rightParenthesis; | 227 CSSParserValue rightParenthesis; |
217 rightParenthesis.setFromOperator(')'); | 228 rightParenthesis.setFromOperator(')'); |
218 while (!stack.isEmpty()) { | 229 while (!stack.isEmpty()) { |
219 while (bracketCounts.last() > 0) { | 230 while (bracketCounts.last() > 0) { |
220 bracketCounts.last()--; | 231 bracketCounts.last()--; |
221 stack.last()->addValue(rightParenthesis); | 232 stack.last()->addValue(rightParenthesis); |
222 } | 233 } |
223 stack.removeLast(); | 234 stack.removeLast(); |
224 bracketCounts.removeLast(); | 235 bracketCounts.removeLast(); |
225 } | 236 } |
226 } | 237 } |
227 | 238 |
228 static void destroy(Vector<CSSParserValue, 4>& values) | 239 static void destroy(Vector<CSSParserValue, 4>& values) |
229 { | 240 { |
230 size_t numValues = values.size(); | 241 size_t numValues = values.size(); |
231 for (size_t i = 0; i < numValues; i++) { | 242 for (size_t i = 0; i < numValues; i++) { |
232 if (values[i].m_unit == CSSParserValue::Function) | 243 if (values[i].m_unit == CSSParserValue::Function) |
233 delete values[i].function; | 244 delete values[i].function; |
234 else if (values[i].m_unit == CSSParserValue::CalcFunction) | 245 else if (values[i].m_unit == CSSParserValue::CalcFunction) |
235 delete values[i].calcFunction; | 246 delete values[i].calcFunction; |
236 else if (values[i].m_unit == CSSParserValue::ValueList | 247 else if (values[i].m_unit == CSSParserValue::ValueList |
237 || values[i].m_unit == CSSParserValue::DimensionList) | 248 || values[i].m_unit == CSSParserValue::DimensionList) |
238 delete values[i].valueList; | 249 delete values[i].valueList; |
250 else if (values[i].unit() == CSSPrimitiveValue::UnitType::VariableRefere nce) | |
251 values[i].variableData->deref(); | |
239 } | 252 } |
240 } | 253 } |
241 | 254 |
255 void CSSParserValueList::checkForVariableReferencesOrDestroyAndClear(const CSSPa rserTokenRange& originalRange) | |
256 { | |
257 // We have to clear any state that may have been previously loaded | |
258 destroyAndClear(); | |
259 if (RuntimeEnabledFeatures::cssVariablesEnabled() && CSSVariableParser::cont ainsValidVariableReferences(originalRange)) | |
260 consumeVariableValue(originalRange); | |
261 } | |
262 | |
263 void CSSParserValueList::consumeVariableValue(const CSSParserTokenRange& origina lRange) | |
264 { | |
265 ASSERT(m_values.isEmpty()); | |
266 CSSParserValue variableValue; | |
267 variableValue.id = CSSValueInternalVariableValue; | |
268 variableValue.isInt = false; | |
269 variableValue.setUnit(CSSPrimitiveValue::UnitType::VariableReference); | |
270 variableValue.variableData = CSSVariableData::create(originalRange).leakRef( ); | |
271 addValue(variableValue); | |
272 } | |
273 | |
274 | |
242 void CSSParserValueList::destroyAndClear() | 275 void CSSParserValueList::destroyAndClear() |
243 { | 276 { |
244 destroy(m_values); | 277 destroy(m_values); |
245 clearAndLeakValues(); | 278 clearAndLeakValues(); |
246 } | 279 } |
247 | 280 |
248 CSSParserValueList::~CSSParserValueList() | 281 CSSParserValueList::~CSSParserValueList() |
249 { | 282 { |
250 destroy(m_values); | 283 destroy(m_values); |
251 } | 284 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 bool CSSParserSelector::hasHostPseudoSelector() const | 375 bool CSSParserSelector::hasHostPseudoSelector() const |
343 { | 376 { |
344 for (CSSParserSelector* selector = const_cast<CSSParserSelector*>(this); sel ector; selector = selector->tagHistory()) { | 377 for (CSSParserSelector* selector = const_cast<CSSParserSelector*>(this); sel ector; selector = selector->tagHistory()) { |
345 if (selector->pseudoType() == CSSSelector::PseudoHost || selector->pseud oType() == CSSSelector::PseudoHostContext) | 378 if (selector->pseudoType() == CSSSelector::PseudoHost || selector->pseud oType() == CSSSelector::PseudoHostContext) |
346 return true; | 379 return true; |
347 } | 380 } |
348 return false; | 381 return false; |
349 } | 382 } |
350 | 383 |
351 } // namespace blink | 384 } // namespace blink |
OLD | NEW |