Chromium Code Reviews| 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, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "core/css/CSSSelectorList.h" | 25 #include "core/css/CSSSelectorList.h" |
| 26 #include "core/css/parser/CSSParserToken.h" | 26 #include "core/css/parser/CSSParserToken.h" |
| 27 #include "core/css/parser/CSSParserTokenRange.h" | 27 #include "core/css/parser/CSSParserTokenRange.h" |
| 28 #include "core/css/parser/CSSPropertyParser.h" | 28 #include "core/css/parser/CSSPropertyParser.h" |
| 29 #include "core/html/parser/HTMLParserIdioms.h" | 29 #include "core/html/parser/HTMLParserIdioms.h" |
| 30 | 30 |
| 31 namespace blink { | 31 namespace blink { |
| 32 | 32 |
| 33 using namespace WTF; | 33 using namespace WTF; |
| 34 | 34 |
| 35 void consumeUntilBlockEnd(CSSParserTokenRange& range, Vector<CSSParserToken> &ar gs, bool& usesRemUnits) | |
| 36 { | |
| 37 unsigned nestingLevel = 1; | |
| 38 do { | |
| 39 const CSSParserToken& token = range.consume(); | |
| 40 if (token.blockType() == CSSParserToken::BlockStart) | |
| 41 nestingLevel++; | |
| 42 else if (token.blockType() == CSSParserToken::BlockEnd) | |
| 43 nestingLevel--; | |
| 44 if (nestingLevel) { | |
| 45 args.append(token); | |
| 46 if (token.unitType() == CSSPrimitiveValue::CSS_REMS) | |
| 47 usesRemUnits = true; | |
| 48 } | |
| 49 } while (nestingLevel && !range.atEnd()); | |
| 50 | |
| 51 while (nestingLevel-- > 1) { | |
| 52 static CSSParserToken rightBracket(DelimiterToken, ')'); | |
| 53 args.append(rightBracket); | |
| 54 } | |
| 55 } | |
| 56 | |
| 35 CSSParserValueList::CSSParserValueList(CSSParserTokenRange range, bool& usesRemU nits) | 57 CSSParserValueList::CSSParserValueList(CSSParserTokenRange range, bool& usesRemU nits) |
| 36 : m_current(0) | 58 : m_current(0) |
| 37 { | 59 { |
| 38 usesRemUnits = false; | 60 usesRemUnits = false; |
| 39 Vector<CSSParserValueList*> stack; | 61 Vector<CSSParserValueList*> stack; |
| 40 Vector<int> bracketCounts; | 62 Vector<int> bracketCounts; |
| 41 stack.append(this); | 63 stack.append(this); |
| 42 bracketCounts.append(0); | 64 bracketCounts.append(0); |
| 43 unsigned calcDepth = 0; | 65 unsigned calcDepth = 0; |
|
Timothy Loh
2015/07/21 07:33:17
don't need this anymore
rwlbuis
2015/07/22 02:19:06
Done.
| |
| 44 while (!range.atEnd()) { | 66 while (!range.atEnd()) { |
| 45 ASSERT(stack.size() == bracketCounts.size()); | 67 ASSERT(stack.size() == bracketCounts.size()); |
| 46 ASSERT(!stack.isEmpty()); | 68 ASSERT(!stack.isEmpty()); |
| 47 const CSSParserToken& token = range.consume(); | 69 const CSSParserToken& token = range.consume(); |
| 48 CSSParserValue value; | 70 CSSParserValue value; |
| 49 switch (token.type()) { | 71 switch (token.type()) { |
| 50 case FunctionToken: { | 72 case FunctionToken: { |
| 51 if (token.valueEqualsIgnoringCase("url")) { | 73 if (token.valueEqualsIgnoringCase("url")) { |
| 52 const CSSParserToken& next = range.consumeIncludingWhitespace(); | 74 const CSSParserToken& next = range.consumeIncludingWhitespace(); |
| 53 if (next.type() == BadStringToken || range.consume().type() != R ightParenthesisToken) { | 75 if (next.type() == BadStringToken || range.consume().type() != R ightParenthesisToken) { |
| 54 destroyAndClear(); | 76 destroyAndClear(); |
| 55 return; | 77 return; |
| 56 } | 78 } |
| 57 ASSERT(next.type() == StringToken); | 79 ASSERT(next.type() == StringToken); |
| 58 value.id = CSSValueInvalid; | 80 value.id = CSSValueInvalid; |
| 59 value.isInt = false; | 81 value.isInt = false; |
| 60 value.unit = CSSPrimitiveValue::CSS_URI; | 82 value.unit = CSSPrimitiveValue::CSS_URI; |
| 61 value.string = next.value(); | 83 value.string = next.value(); |
| 62 break; | 84 break; |
| 63 } | 85 } |
| 64 | 86 |
| 87 value.id = CSSValueInvalid; | |
| 88 value.isInt = false; | |
| 89 | |
| 90 CSSValueID id = cssValueKeywordID(token.value()); | |
| 91 if (id == CSSValueCalc || id == CSSValueWebkitCalc) { | |
| 92 value.unit = CSSParserValue::CalcFunction; | |
| 93 value.calcFunction = new CSSParserCalcFunction; | |
| 94 consumeUntilBlockEnd(range, value.calcFunction->args, usesRemUni ts); | |
| 95 | |
| 96 calcDepth++; | |
| 97 break; | |
| 98 } | |
| 99 value.unit = CSSParserValue::Function; | |
| 65 CSSParserFunction* function = new CSSParserFunction; | 100 CSSParserFunction* function = new CSSParserFunction; |
| 66 function->id = cssValueKeywordID(token.value()); | 101 function->id = id; |
| 67 CSSParserValueList* list = new CSSParserValueList; | 102 CSSParserValueList* list = new CSSParserValueList; |
| 68 function->args = adoptPtr(list); | 103 function->args = adoptPtr(list); |
| 69 | 104 |
| 70 value.id = CSSValueInvalid; | |
| 71 value.isInt = false; | |
| 72 value.unit = CSSParserValue::Function; | |
| 73 value.function = function; | 105 value.function = function; |
| 74 | 106 |
| 75 stack.last()->addValue(value); | 107 stack.last()->addValue(value); |
| 76 stack.append(list); | 108 stack.append(list); |
| 77 bracketCounts.append(0); | 109 bracketCounts.append(0); |
| 78 calcDepth += (function->id == CSSValueCalc || function->id == CSSVal ueWebkitCalc); | |
| 79 continue; | 110 continue; |
| 80 } | 111 } |
| 81 case LeftParenthesisToken: { | 112 case LeftParenthesisToken: { |
| 82 if (calcDepth == 0) { | 113 if (calcDepth == 0) { |
| 83 CSSParserValueList* list = new CSSParserValueList; | 114 CSSParserValueList* list = new CSSParserValueList; |
| 84 value.setFromValueList(adoptPtr(list)); | 115 value.setFromValueList(adoptPtr(list)); |
| 85 stack.last()->addValue(value); | 116 stack.last()->addValue(value); |
| 86 stack.append(list); | 117 stack.append(list); |
| 87 bracketCounts.append(0); | 118 bracketCounts.append(0); |
| 88 continue; | 119 continue; |
| 89 } | 120 } |
| 90 bracketCounts.last()++; | 121 bracketCounts.last()++; |
| 91 value.setFromOperator('('); | 122 value.setFromOperator('('); |
| 92 break; | 123 break; |
| 93 } | 124 } |
| 94 case RightParenthesisToken: { | 125 case RightParenthesisToken: { |
| 95 if (bracketCounts.last() == 0) { | 126 if (bracketCounts.last() == 0) { |
| 96 stack.removeLast(); | 127 stack.removeLast(); |
| 97 bracketCounts.removeLast(); | 128 bracketCounts.removeLast(); |
| 98 if (bracketCounts.isEmpty()) { | 129 if (bracketCounts.isEmpty()) { |
| 99 destroyAndClear(); | 130 destroyAndClear(); |
| 100 return; | 131 return; |
| 101 } | 132 } |
| 102 CSSParserValueList* currentList = stack.last(); | 133 CSSParserValueList* currentList = stack.last(); |
| 103 CSSParserValue* current = currentList->valueAt(currentList->size ()-1); | 134 CSSParserValue* current = currentList->valueAt(currentList->size ()-1); |
| 104 if (current->unit == CSSParserValue::Function) { | 135 if (current->unit == CSSParserValue::CalcFunction) { |
| 105 CSSValueID id = current->function->id; | 136 CSSValueID id = current->function->id; |
| 106 calcDepth -= (id == CSSValueCalc || id == CSSValueWebkitCalc ); | 137 calcDepth -= (id == CSSValueCalc || id == CSSValueWebkitCalc ); |
| 107 } | 138 } |
| 108 continue; | 139 continue; |
| 109 } | 140 } |
| 110 ASSERT(calcDepth > 0); | 141 ASSERT(calcDepth > 0); |
| 111 bracketCounts.last()--; | 142 bracketCounts.last()--; |
| 112 value.setFromOperator(')'); | 143 value.setFromOperator(')'); |
| 113 break; | 144 break; |
| 114 } | 145 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 value.unit = CSSParserValue::HexColor; | 203 value.unit = CSSParserValue::HexColor; |
| 173 else if (token.type() == StringToken) | 204 else if (token.type() == StringToken) |
| 174 value.unit = CSSPrimitiveValue::CSS_STRING; | 205 value.unit = CSSPrimitiveValue::CSS_STRING; |
| 175 else | 206 else |
| 176 value.unit = CSSPrimitiveValue::CSS_URI; | 207 value.unit = CSSPrimitiveValue::CSS_URI; |
| 177 value.string = token.value(); | 208 value.string = token.value(); |
| 178 break; | 209 break; |
| 179 } | 210 } |
| 180 case DelimiterToken: | 211 case DelimiterToken: |
| 181 value.setFromOperator(token.delimiter()); | 212 value.setFromOperator(token.delimiter()); |
| 182 if (calcDepth && token.delimiter() == '+' && (&token - 1)->type() != WhitespaceToken) { | |
| 183 // calc(1px+ 2px) is invalid | |
| 184 destroyAndClear(); | |
| 185 return; | |
| 186 } | |
| 187 break; | 213 break; |
| 188 case CommaToken: | 214 case CommaToken: |
| 189 value.setFromOperator(','); | 215 value.setFromOperator(','); |
| 190 break; | 216 break; |
| 191 case LeftBracketToken: | 217 case LeftBracketToken: |
| 192 value.setFromOperator('['); | 218 value.setFromOperator('['); |
| 193 break; | 219 break; |
| 194 case RightBracketToken: | 220 case RightBracketToken: |
| 195 value.setFromOperator(']'); | 221 value.setFromOperator(']'); |
| 196 break; | 222 break; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 while (!stack.isEmpty()) { | 255 while (!stack.isEmpty()) { |
| 230 while (bracketCounts.last() > 0) { | 256 while (bracketCounts.last() > 0) { |
| 231 bracketCounts.last()--; | 257 bracketCounts.last()--; |
| 232 stack.last()->addValue(rightParenthesis); | 258 stack.last()->addValue(rightParenthesis); |
| 233 } | 259 } |
| 234 stack.removeLast(); | 260 stack.removeLast(); |
| 235 bracketCounts.removeLast(); | 261 bracketCounts.removeLast(); |
| 236 } | 262 } |
| 237 } | 263 } |
| 238 | 264 |
| 239 static void destroy(Vector<CSSParserValue, 4>& values) | 265 static void destroy(Vector<CSSParserValue, 4>& values) |
|
Timothy Loh
2015/07/21 07:33:17
need to update this
rwlbuis
2015/07/22 02:19:06
Ouch I thought it was not needed after I introduce
rwlbuis
2015/07/22 20:53:02
Ok, fixed now :)
PTAL.
| |
| 240 { | 266 { |
| 241 size_t numValues = values.size(); | 267 size_t numValues = values.size(); |
| 242 for (size_t i = 0; i < numValues; i++) { | 268 for (size_t i = 0; i < numValues; i++) { |
| 243 if (values[i].unit == CSSParserValue::Function) | 269 if (values[i].unit == CSSParserValue::Function) |
| 244 delete values[i].function; | 270 delete values[i].function; |
| 245 else if (values[i].unit == CSSParserValue::ValueList | 271 else if (values[i].unit == CSSParserValue::ValueList |
| 246 || values[i].unit == CSSParserValue::DimensionList) | 272 || values[i].unit == CSSParserValue::DimensionList) |
| 247 delete values[i].valueList; | 273 delete values[i].valueList; |
| 248 } | 274 } |
| 249 } | 275 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 bool CSSParserSelector::hasHostPseudoSelector() const | 377 bool CSSParserSelector::hasHostPseudoSelector() const |
| 352 { | 378 { |
| 353 for (CSSParserSelector* selector = const_cast<CSSParserSelector*>(this); sel ector; selector = selector->tagHistory()) { | 379 for (CSSParserSelector* selector = const_cast<CSSParserSelector*>(this); sel ector; selector = selector->tagHistory()) { |
| 354 if (selector->pseudoType() == CSSSelector::PseudoHost || selector->pseud oType() == CSSSelector::PseudoHostContext) | 380 if (selector->pseudoType() == CSSSelector::PseudoHost || selector->pseud oType() == CSSSelector::PseudoHostContext) |
| 355 return true; | 381 return true; |
| 356 } | 382 } |
| 357 return false; | 383 return false; |
| 358 } | 384 } |
| 359 | 385 |
| 360 } // namespace blink | 386 } // namespace blink |
| OLD | NEW |