| 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/CSSVariableData.h" |
| 25 #include "core/css/parser/CSSParserToken.h" | 26 #include "core/css/parser/CSSParserToken.h" |
| 26 #include "core/css/parser/CSSParserTokenRange.h" | 27 #include "core/css/parser/CSSParserTokenRange.h" |
| 27 #include "core/css/parser/CSSPropertyParser.h" | 28 #include "core/css/parser/CSSPropertyParser.h" |
| 29 #include "core/css/parser/CSSVariableParser.h" |
| 28 #include "core/html/parser/HTMLParserIdioms.h" | 30 #include "core/html/parser/HTMLParserIdioms.h" |
| 29 | 31 |
| 30 namespace blink { | 32 namespace blink { |
| 31 | 33 |
| 32 using namespace WTF; | 34 using namespace WTF; |
| 33 | 35 |
| 34 CSSParserValueList::CSSParserValueList(CSSParserTokenRange range) | 36 CSSParserValueList::CSSParserValueList(CSSParserTokenRange range) |
| 35 : m_current(0) | 37 : m_current(0) |
| 36 { | 38 { |
| 39 CSSParserTokenRange originalRangeForVariables = range; |
| 40 |
| 37 Vector<CSSParserValueList*> stack; | 41 Vector<CSSParserValueList*> stack; |
| 38 Vector<int> bracketCounts; | 42 Vector<int> bracketCounts; |
| 39 stack.append(this); | 43 stack.append(this); |
| 40 bracketCounts.append(0); | 44 bracketCounts.append(0); |
| 41 while (!range.atEnd()) { | 45 while (!range.atEnd()) { |
| 42 ASSERT(stack.size() == bracketCounts.size()); | 46 ASSERT(stack.size() == bracketCounts.size()); |
| 43 ASSERT(!stack.isEmpty()); | 47 ASSERT(!stack.isEmpty()); |
| 44 const CSSParserToken& token = range.peek(); | 48 const CSSParserToken& token = range.peek(); |
| 45 if (token.type() != FunctionToken) | 49 if (token.type() != FunctionToken) |
| 46 range.consume(); | 50 range.consume(); |
| 47 CSSParserValue value; | 51 CSSParserValue value; |
| 48 switch (token.type()) { | 52 switch (token.type()) { |
| 49 case FunctionToken: { | 53 case FunctionToken: { |
| 50 if (token.valueEqualsIgnoringCase("url")) { | 54 if (token.valueEqualsIgnoringCase("url")) { |
| 51 range.consume(); | 55 range.consume(); |
| 52 const CSSParserToken& next = range.consumeIncludingWhitespace(); | 56 const CSSParserToken& next = range.consumeIncludingWhitespace(); |
| 53 if (next.type() == BadStringToken || range.consume().type() != R
ightParenthesisToken) { | 57 if (next.type() == BadStringToken || range.consume().type() != R
ightParenthesisToken) { |
| 54 destroyAndClear(); | 58 checkForVariableReferencesOrDestroyAndClear(originalRangeFor
Variables); |
| 55 return; | 59 return; |
| 56 } | 60 } |
| 57 ASSERT(next.type() == StringToken); | 61 ASSERT(next.type() == StringToken); |
| 58 value.id = CSSValueInvalid; | 62 value.id = CSSValueInvalid; |
| 59 value.isInt = false; | 63 value.isInt = false; |
| 60 value.setUnit(CSSPrimitiveValue::UnitType::URI); | 64 value.setUnit(CSSPrimitiveValue::UnitType::URI); |
| 61 value.string = next.value(); | 65 value.string = next.value(); |
| 62 break; | 66 break; |
| 67 } else if (token.valueEqualsIgnoringCase("var")) { |
| 68 checkForVariableReferencesOrDestroyAndClear(originalRangeForVari
ables); |
| 69 return; |
| 63 } | 70 } |
| 64 | 71 |
| 65 value.id = CSSValueInvalid; | 72 value.id = CSSValueInvalid; |
| 66 value.isInt = false; | 73 value.isInt = false; |
| 67 | 74 |
| 68 CSSValueID id = token.functionId(); | 75 CSSValueID id = token.functionId(); |
| 69 if (id == CSSValueCalc || id == CSSValueWebkitCalc) { | 76 if (id == CSSValueCalc || id == CSSValueWebkitCalc) { |
| 70 value.m_unit = CSSParserValue::CalcFunction; | 77 value.m_unit = CSSParserValue::CalcFunction; |
| 71 value.calcFunction = new CSSParserCalcFunction(range.consumeBloc
k()); | 78 value.calcFunction = new CSSParserCalcFunction(range.consumeBloc
k()); |
| 72 break; | 79 break; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 91 stack.last()->addValue(value); | 98 stack.last()->addValue(value); |
| 92 stack.append(list); | 99 stack.append(list); |
| 93 bracketCounts.append(0); | 100 bracketCounts.append(0); |
| 94 continue; | 101 continue; |
| 95 } | 102 } |
| 96 case RightParenthesisToken: { | 103 case RightParenthesisToken: { |
| 97 if (bracketCounts.last() == 0) { | 104 if (bracketCounts.last() == 0) { |
| 98 stack.removeLast(); | 105 stack.removeLast(); |
| 99 bracketCounts.removeLast(); | 106 bracketCounts.removeLast(); |
| 100 if (bracketCounts.isEmpty()) { | 107 if (bracketCounts.isEmpty()) { |
| 101 destroyAndClear(); | 108 checkForVariableReferencesOrDestroyAndClear(originalRangeFor
Variables); |
| 102 return; | 109 return; |
| 103 } | 110 } |
| 104 continue; | 111 continue; |
| 105 } | 112 } |
| 106 bracketCounts.last()--; | 113 bracketCounts.last()--; |
| 107 value.setFromOperator(')'); | 114 value.setFromOperator(')'); |
| 108 break; | 115 break; |
| 109 } | 116 } |
| 110 case IdentToken: { | 117 case IdentToken: { |
| 111 value.id = token.id(); | 118 value.id = token.id(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 ASSERT_NOT_REACHED(); | 202 ASSERT_NOT_REACHED(); |
| 196 case CDOToken: | 203 case CDOToken: |
| 197 case CDCToken: | 204 case CDCToken: |
| 198 case AtKeywordToken: | 205 case AtKeywordToken: |
| 199 case IncludeMatchToken: | 206 case IncludeMatchToken: |
| 200 case DashMatchToken: | 207 case DashMatchToken: |
| 201 case PrefixMatchToken: | 208 case PrefixMatchToken: |
| 202 case SuffixMatchToken: | 209 case SuffixMatchToken: |
| 203 case SubstringMatchToken: | 210 case SubstringMatchToken: |
| 204 case ColumnToken: | 211 case ColumnToken: |
| 212 case ColonToken: |
| 213 case SemicolonToken: |
| 214 checkForVariableReferencesOrDestroyAndClear(originalRangeForVariable
s); |
| 215 return; |
| 205 case BadStringToken: | 216 case BadStringToken: |
| 206 case BadUrlToken: | 217 case BadUrlToken: |
| 207 case ColonToken: | |
| 208 case SemicolonToken: | |
| 209 destroyAndClear(); | 218 destroyAndClear(); |
| 210 return; | 219 return; |
| 211 } | 220 } |
| 212 stack.last()->addValue(value); | 221 stack.last()->addValue(value); |
| 213 } | 222 } |
| 214 | 223 |
| 215 CSSParserValue rightParenthesis; | 224 CSSParserValue rightParenthesis; |
| 216 rightParenthesis.setFromOperator(')'); | 225 rightParenthesis.setFromOperator(')'); |
| 217 while (!stack.isEmpty()) { | 226 while (!stack.isEmpty()) { |
| 218 while (bracketCounts.last() > 0) { | 227 while (bracketCounts.last() > 0) { |
| 219 bracketCounts.last()--; | 228 bracketCounts.last()--; |
| 220 stack.last()->addValue(rightParenthesis); | 229 stack.last()->addValue(rightParenthesis); |
| 221 } | 230 } |
| 222 stack.removeLast(); | 231 stack.removeLast(); |
| 223 bracketCounts.removeLast(); | 232 bracketCounts.removeLast(); |
| 224 } | 233 } |
| 225 } | 234 } |
| 226 | 235 |
| 227 static void destroy(Vector<CSSParserValue, 4>& values) | 236 static void destroy(Vector<CSSParserValue, 4>& values) |
| 228 { | 237 { |
| 229 size_t numValues = values.size(); | 238 size_t numValues = values.size(); |
| 230 for (size_t i = 0; i < numValues; i++) { | 239 for (size_t i = 0; i < numValues; i++) { |
| 231 if (values[i].m_unit == CSSParserValue::Function) | 240 if (values[i].m_unit == CSSParserValue::Function) |
| 232 delete values[i].function; | 241 delete values[i].function; |
| 233 else if (values[i].m_unit == CSSParserValue::CalcFunction) | 242 else if (values[i].m_unit == CSSParserValue::CalcFunction) |
| 234 delete values[i].calcFunction; | 243 delete values[i].calcFunction; |
| 235 else if (values[i].m_unit == CSSParserValue::ValueList | 244 else if (values[i].m_unit == CSSParserValue::ValueList |
| 236 || values[i].m_unit == CSSParserValue::DimensionList) | 245 || values[i].m_unit == CSSParserValue::DimensionList) |
| 237 delete values[i].valueList; | 246 delete values[i].valueList; |
| 247 else if (values[i].unit() == CSSPrimitiveValue::UnitType::VariableRefere
nce) |
| 248 values[i].variableData->deref(); |
| 238 } | 249 } |
| 239 } | 250 } |
| 240 | 251 |
| 252 void CSSParserValueList::checkForVariableReferencesOrDestroyAndClear(const CSSPa
rserTokenRange& originalRange) |
| 253 { |
| 254 // We have to clear any state that may have been previously loaded |
| 255 destroyAndClear(); |
| 256 if (RuntimeEnabledFeatures::cssVariablesEnabled() && CSSVariableParser::cont
ainsValidVariableReferences(originalRange)) |
| 257 consumeVariableValue(originalRange); |
| 258 } |
| 259 |
| 260 void CSSParserValueList::consumeVariableValue(const CSSParserTokenRange& origina
lRange) |
| 261 { |
| 262 ASSERT(m_values.isEmpty()); |
| 263 CSSParserValue variableValue; |
| 264 variableValue.id = CSSValueInternalVariableValue; |
| 265 variableValue.isInt = false; |
| 266 variableValue.setUnit(CSSPrimitiveValue::UnitType::VariableReference); |
| 267 variableValue.variableData = CSSVariableData::create(originalRange).leakRef(
); |
| 268 addValue(variableValue); |
| 269 } |
| 270 |
| 271 |
| 241 void CSSParserValueList::destroyAndClear() | 272 void CSSParserValueList::destroyAndClear() |
| 242 { | 273 { |
| 243 destroy(m_values); | 274 destroy(m_values); |
| 244 clearAndLeakValues(); | 275 clearAndLeakValues(); |
| 245 } | 276 } |
| 246 | 277 |
| 247 CSSParserValueList::~CSSParserValueList() | 278 CSSParserValueList::~CSSParserValueList() |
| 248 { | 279 { |
| 249 destroy(m_values); | 280 destroy(m_values); |
| 250 } | 281 } |
| 251 | 282 |
| 252 void CSSParserValueList::addValue(const CSSParserValue& v) | 283 void CSSParserValueList::addValue(const CSSParserValue& v) |
| 253 { | 284 { |
| 254 m_values.append(v); | 285 m_values.append(v); |
| 255 } | 286 } |
| 256 | 287 |
| 257 } // namespace blink | 288 } // namespace blink |
| OLD | NEW |