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/parser/CSSPropertyParser.h" | |
26 #include "core/html/parser/HTMLParserIdioms.h" | 27 #include "core/html/parser/HTMLParserIdioms.h" |
27 | 28 |
28 namespace blink { | 29 namespace blink { |
29 | 30 |
30 using namespace WTF; | 31 using namespace WTF; |
31 | 32 |
33 CSSParserValueList::CSSParserValueList(CSSParserTokenIterator start, CSSParserTo kenIterator end) | |
34 : m_current(0) | |
35 { | |
alancutter (OOO until 2018)
2014/11/07 19:36:12
ASSERT(end.type() == EOFToken) ?
Timothy Loh
2014/11/08 00:42:49
It basically never makes sense to deference an end
| |
36 Vector<CSSParserValueList*> stack; | |
37 Vector<int> bracketCounts; | |
38 stack.append(this); | |
39 bracketCounts.append(0); | |
40 unsigned calcDepth = 0; | |
41 for (CSSParserTokenIterator it = start; it != end; ++it) { | |
42 ASSERT(stack.size() == bracketCounts.size()); | |
43 ASSERT(!stack.isEmpty()); | |
44 const CSSParserToken& token = *it; | |
45 CSSParserValue value; | |
46 switch (token.type()) { | |
47 case FunctionToken: { | |
48 if (token.value() == "url" && (it + 1)->type() == StringToken) { | |
49 if ((it + 2)->type() == RightParenthesisToken | |
50 || ((it + 3)->type() == RightParenthesisToken && (it + 2)->t ype() == WhitespaceToken)) { | |
alancutter (OOO until 2018)
2014/11/07 19:36:11
These iterator accesses need to be swapped around
Timothy Loh
2014/11/08 00:42:49
I tweaked the logic a bit here, ptal.
alancutter (OOO until 2018)
2014/11/08 00:59:08
This is better.
| |
51 CSSParserString string; | |
52 ++it; | |
53 string.init(it->value()); | |
54 value.id = CSSValueInvalid; | |
55 value.isInt = false; | |
56 value.unit = CSSPrimitiveValue::CSS_URI; | |
57 value.string = string; | |
58 ++it; | |
59 if (it->type() == WhitespaceToken) | |
60 ++it; | |
61 break; | |
62 } | |
63 } | |
64 | |
65 CSSParserFunction* function = new CSSParserFunction; | |
66 CSSParserString name; | |
67 name.init(token.value()); | |
68 function->id = cssValueKeywordID(name); | |
69 CSSParserValueList* list = new CSSParserValueList; | |
70 function->args = adoptPtr(list); | |
71 | |
72 value.id = CSSValueInvalid; | |
73 value.isInt = false; | |
74 value.unit = CSSParserValue::Function; | |
75 value.function = function; | |
76 | |
77 stack.last()->addValue(value); | |
78 stack.append(list); | |
79 bracketCounts.append(0); | |
80 calcDepth += (function->id == CSSValueCalc || function->id == CSSVal ueWebkitCalc); | |
81 continue; | |
82 } | |
83 case LeftParenthesisToken: { | |
84 if (!calcDepth) { | |
alancutter (OOO until 2018)
2014/11/07 19:36:12
calcDepth == 0
Timothy Loh
2014/11/08 00:42:49
Done.
| |
85 CSSParserValueList* list = new CSSParserValueList; | |
86 value.setFromValueList(adoptPtr(list)); | |
87 stack.last()->addValue(value); | |
88 stack.append(list); | |
89 bracketCounts.append(0); | |
90 continue; | |
91 } | |
92 bracketCounts.last()++; | |
93 value.setFromOperator('('); | |
94 break; | |
95 } | |
96 case RightParenthesisToken: { | |
97 if (!bracketCounts.last()) { | |
alancutter (OOO until 2018)
2014/11/07 19:36:12
backetCounts.last() == 0
Timothy Loh
2014/11/08 00:42:49
Done.
| |
98 stack.removeLast(); | |
99 bracketCounts.removeLast(); | |
100 if (bracketCounts.isEmpty()) { | |
101 destroyAndClear(); | |
102 return; | |
103 } | |
104 CSSParserValueList* currentList = stack.last(); | |
105 CSSParserValue* current = currentList->valueAt(currentList->size ()-1); | |
106 if (current->unit == CSSParserValue::Function) { | |
107 CSSValueID id = current->function->id; | |
108 calcDepth -= (id == CSSValueCalc || id == CSSValueWebkitCalc ); | |
109 } | |
110 continue; | |
111 } | |
alancutter (OOO until 2018)
2014/11/07 19:36:12
ASSERT(calcDepth > 0) for readability.
Timothy Loh
2014/11/08 00:42:49
Done.
| |
112 bracketCounts.last()--; | |
113 value.setFromOperator(')'); | |
114 break; | |
115 } | |
116 case IdentToken: { | |
117 CSSParserString string; | |
118 string.init(token.value()); | |
119 value.id = cssValueKeywordID(string); | |
120 value.isInt = false; | |
121 value.unit = CSSPrimitiveValue::CSS_IDENT; | |
122 value.string = string; | |
123 break; | |
124 } | |
125 case DimensionToken: | |
126 case NumberToken: | |
127 case PercentageToken: | |
128 value.setFromNumber(token.numericValue(), token.unitType()); | |
129 value.isInt = (token.numericValueType() == IntegerValueType); | |
130 break; | |
131 case HashToken: | |
132 case StringToken: | |
133 case UnicodeRangeToken: | |
134 case UrlToken: { | |
135 CSSParserString string; | |
136 string.init(token.value()); | |
137 value.id = CSSValueInvalid; | |
138 value.isInt = false; | |
139 if (token.type() == HashToken) | |
140 value.unit = CSSPrimitiveValue::CSS_PARSER_HEXCOLOR; | |
141 else if (token.type() == StringToken) | |
142 value.unit = CSSPrimitiveValue::CSS_STRING; | |
143 else if (token.type() == UnicodeRangeToken) | |
144 value.unit = CSSPrimitiveValue::CSS_UNICODE_RANGE; | |
145 else | |
146 value.unit = CSSPrimitiveValue::CSS_URI; | |
147 value.string = string; | |
148 break; | |
149 } | |
150 case DelimiterToken: | |
151 value.setFromOperator(token.delimiter()); | |
152 if (calcDepth && token.delimiter() == '+' && (it - 1)->type() != Whi tespaceToken) { | |
153 // calc(1px+ 2px) is invalid | |
154 destroyAndClear(); | |
155 return; | |
156 } | |
157 break; | |
158 case CommaToken: | |
159 value.setFromOperator(','); | |
160 break; | |
161 case LeftBracketToken: | |
162 value.setFromOperator('['); | |
163 break; | |
164 case RightBracketToken: | |
165 value.setFromOperator(']'); | |
166 break; | |
167 case LeftBraceToken: | |
168 value.setFromOperator('{'); | |
169 break; | |
170 case RightBraceToken: | |
171 value.setFromOperator('}'); | |
172 break; | |
173 case WhitespaceToken: | |
174 case CommentToken: | |
175 continue; | |
176 case BadStringToken: | |
177 case BadUrlToken: | |
178 case ColonToken: | |
179 case EOFToken: | |
180 case SemicolonToken: | |
181 destroyAndClear(); | |
182 return; | |
183 } | |
184 stack.last()->addValue(value); | |
185 } | |
186 | |
187 CSSParserValue rightParenthesis; | |
188 rightParenthesis.setFromOperator(')'); | |
189 while (!stack.isEmpty()) { | |
190 while (bracketCounts.last() > 0) { | |
191 bracketCounts.last()--; | |
192 stack.last()->addValue(rightParenthesis); | |
193 } | |
194 stack.removeLast(); | |
195 bracketCounts.removeLast(); | |
196 } | |
197 } | |
198 | |
32 static void destroy(Vector<CSSParserValue, 4>& values) | 199 static void destroy(Vector<CSSParserValue, 4>& values) |
33 { | 200 { |
34 size_t numValues = values.size(); | 201 size_t numValues = values.size(); |
35 for (size_t i = 0; i < numValues; i++) { | 202 for (size_t i = 0; i < numValues; i++) { |
36 if (values[i].unit == CSSParserValue::Function) | 203 if (values[i].unit == CSSParserValue::Function) |
37 delete values[i].function; | 204 delete values[i].function; |
38 else if (values[i].unit == CSSParserValue::ValueList) | 205 else if (values[i].unit == CSSParserValue::ValueList) |
39 delete values[i].valueList; | 206 delete values[i].valueList; |
40 } | 207 } |
41 } | 208 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 bool CSSParserSelector::hasHostPseudoSelector() const | 319 bool CSSParserSelector::hasHostPseudoSelector() const |
153 { | 320 { |
154 for (CSSParserSelector* selector = const_cast<CSSParserSelector*>(this); sel ector; selector = selector->tagHistory()) { | 321 for (CSSParserSelector* selector = const_cast<CSSParserSelector*>(this); sel ector; selector = selector->tagHistory()) { |
155 if (selector->pseudoType() == CSSSelector::PseudoHost || selector->pseud oType() == CSSSelector::PseudoHostContext) | 322 if (selector->pseudoType() == CSSSelector::PseudoHost || selector->pseud oType() == CSSSelector::PseudoHostContext) |
156 return true; | 323 return true; |
157 } | 324 } |
158 return false; | 325 return false; |
159 } | 326 } |
160 | 327 |
161 } // namespace blink | 328 } // namespace blink |
OLD | NEW |