Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: Source/core/css/parser/CSSParserValues.cpp

Issue 647483009: CSS Parser: Implement parseValue (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase / update Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/parser/CSSParserValues.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
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 + 2 < end && (it + 2)->type() == Ri ghtParenthesisToken) {
49 ++it;
50 if (it->type() == BadStringToken) {
51 destroyAndClear();
52 return;
53 }
54 ASSERT(it->type() == StringToken);
55 CSSParserString string;
56 string.init(it->value());
57 value.id = CSSValueInvalid;
58 value.isInt = false;
59 value.unit = CSSPrimitiveValue::CSS_URI;
60 value.string = string;
61 ++it;
62 }
63
64 CSSParserFunction* function = new CSSParserFunction;
65 CSSParserString name;
66 name.init(token.value());
67 function->id = cssValueKeywordID(name);
68 CSSParserValueList* list = new CSSParserValueList;
69 function->args = adoptPtr(list);
70
71 value.id = CSSValueInvalid;
72 value.isInt = false;
73 value.unit = CSSParserValue::Function;
74 value.function = function;
75
76 stack.last()->addValue(value);
77 stack.append(list);
78 bracketCounts.append(0);
79 calcDepth += (function->id == CSSValueCalc || function->id == CSSVal ueWebkitCalc);
80 continue;
81 }
82 case LeftParenthesisToken: {
83 if (calcDepth == 0) {
84 CSSParserValueList* list = new CSSParserValueList;
85 value.setFromValueList(adoptPtr(list));
86 stack.last()->addValue(value);
87 stack.append(list);
88 bracketCounts.append(0);
89 continue;
90 }
91 bracketCounts.last()++;
92 value.setFromOperator('(');
93 break;
94 }
95 case RightParenthesisToken: {
96 if (bracketCounts.last() == 0) {
97 stack.removeLast();
98 bracketCounts.removeLast();
99 if (bracketCounts.isEmpty()) {
100 destroyAndClear();
101 return;
102 }
103 CSSParserValueList* currentList = stack.last();
104 CSSParserValue* current = currentList->valueAt(currentList->size ()-1);
105 if (current->unit == CSSParserValue::Function) {
106 CSSValueID id = current->function->id;
107 calcDepth -= (id == CSSValueCalc || id == CSSValueWebkitCalc );
108 }
109 continue;
110 }
111 ASSERT(calcDepth > 0);
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
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
OLDNEW
« no previous file with comments | « Source/core/css/parser/CSSParserValues.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698