author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 3 | 41300fa6a67c |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 2003 Lars Knoll (knoll@kde.org) |
|
3 |
* Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) |
|
4 |
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
|
5 |
* Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> |
|
6 |
* Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
|
7 |
* Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
|
8 |
* |
|
9 |
* This library is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU Library General Public |
|
11 |
* License as published by the Free Software Foundation; either |
|
12 |
* version 2 of the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This library is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 |
* Library General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU Library General Public License |
|
20 |
* along with this library; see the file COPYING.LIB. If not, write to |
|
21 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
22 |
* Boston, MA 02110-1301, USA. |
|
23 |
*/ |
|
24 |
||
25 |
#include "config.h" |
|
26 |
#include "CSSParser.h" |
|
27 |
||
28 |
#include "CString.h" |
|
29 |
#include "CSSTimingFunctionValue.h" |
|
30 |
#include "CSSBorderImageValue.h" |
|
31 |
#include "CSSCanvasValue.h" |
|
32 |
#include "CSSCharsetRule.h" |
|
33 |
#include "CSSCursorImageValue.h" |
|
34 |
#include "CSSHelper.h" |
|
35 |
#include "CSSImageValue.h" |
|
36 |
#include "CSSFontFaceRule.h" |
|
37 |
#include "CSSFontFaceSrcValue.h" |
|
38 |
#include "CSSGradientValue.h" |
|
39 |
#include "CSSImportRule.h" |
|
40 |
#include "CSSInheritedValue.h" |
|
41 |
#include "CSSInitialValue.h" |
|
42 |
#include "CSSMediaRule.h" |
|
43 |
#include "CSSMutableStyleDeclaration.h" |
|
44 |
#include "CSSPrimitiveValue.h" |
|
45 |
#include "CSSProperty.h" |
|
46 |
#include "CSSPropertyNames.h" |
|
47 |
#include "CSSQuirkPrimitiveValue.h" |
|
48 |
#include "CSSReflectValue.h" |
|
49 |
#include "CSSRuleList.h" |
|
50 |
#include "CSSSelector.h" |
|
51 |
#include "CSSStyleRule.h" |
|
52 |
#include "CSSStyleSheet.h" |
|
53 |
#include "CSSUnicodeRangeValue.h" |
|
54 |
#include "CSSValueKeywords.h" |
|
55 |
#include "CSSValueList.h" |
|
56 |
#include "CSSVariableDependentValue.h" |
|
57 |
#include "CSSVariablesDeclaration.h" |
|
58 |
#include "CSSVariablesRule.h" |
|
59 |
#include "Counter.h" |
|
60 |
#include "Document.h" |
|
61 |
#include "FloatConversion.h" |
|
62 |
#include "FontFamilyValue.h" |
|
63 |
#include "FontValue.h" |
|
64 |
#include "MediaList.h" |
|
65 |
#include "MediaQueryExp.h" |
|
66 |
#include "Pair.h" |
|
67 |
#include "Rect.h" |
|
68 |
#include "ShadowValue.h" |
|
69 |
#include "WebKitCSSKeyframeRule.h" |
|
70 |
#include "WebKitCSSKeyframesRule.h" |
|
71 |
#include "WebKitCSSTransformValue.h" |
|
72 |
#include <wtf/dtoa.h> |
|
73 |
||
74 |
#if ENABLE(DASHBOARD_SUPPORT) |
|
75 |
#include "DashboardRegion.h" |
|
76 |
#endif |
|
77 |
||
78 |
#define YYDEBUG 0 |
|
79 |
||
80 |
#if YYDEBUG > 0 |
|
81 |
extern int cssyydebug; |
|
82 |
#endif |
|
83 |
||
84 |
extern int cssyyparse(void* parser); |
|
85 |
||
86 |
using namespace std; |
|
87 |
using namespace WTF; |
|
88 |
||
89 |
#include "CSSPropertyNames.cpp" |
|
90 |
#include "CSSValueKeywords.c" |
|
91 |
||
92 |
namespace WebCore { |
|
93 |
||
94 |
static bool equal(const CSSParserString& a, const char* b) |
|
95 |
{ |
|
96 |
for (int i = 0; i < a.length; ++i) { |
|
97 |
if (!b[i]) |
|
98 |
return false; |
|
99 |
if (a.characters[i] != b[i]) |
|
100 |
return false; |
|
101 |
} |
|
102 |
return !b[a.length]; |
|
103 |
} |
|
104 |
||
105 |
static bool equalIgnoringCase(const CSSParserString& a, const char* b) |
|
106 |
{ |
|
107 |
for (int i = 0; i < a.length; ++i) { |
|
108 |
if (!b[i]) |
|
109 |
return false; |
|
110 |
ASSERT(!isASCIIUpper(b[i])); |
|
111 |
if (toASCIILower(a.characters[i]) != b[i]) |
|
112 |
return false; |
|
113 |
} |
|
114 |
return !b[a.length]; |
|
115 |
} |
|
116 |
||
117 |
static bool hasPrefix(const char* string, unsigned length, const char* prefix) |
|
118 |
{ |
|
119 |
for (unsigned i = 0; i < length; ++i) { |
|
120 |
if (!prefix[i]) |
|
121 |
return true; |
|
122 |
if (string[i] != prefix[i]) |
|
123 |
return false; |
|
124 |
} |
|
125 |
return false; |
|
126 |
} |
|
127 |
||
128 |
CSSParser::CSSParser(bool strictParsing) |
|
129 |
: m_strict(strictParsing) |
|
130 |
, m_important(false) |
|
131 |
, m_id(0) |
|
132 |
, m_styleSheet(0) |
|
133 |
, m_mediaQuery(0) |
|
134 |
, m_valueList(0) |
|
135 |
, m_parsedProperties(static_cast<CSSProperty**>(fastMalloc(32 * sizeof(CSSProperty*)))) |
|
136 |
, m_numParsedProperties(0) |
|
137 |
, m_maxParsedProperties(32) |
|
138 |
, m_inParseShorthand(0) |
|
139 |
, m_currentShorthand(0) |
|
140 |
, m_implicitShorthand(false) |
|
141 |
, m_hasFontFaceOnlyValues(false) |
|
142 |
, m_defaultNamespace(starAtom) |
|
143 |
, m_data(0) |
|
144 |
, yy_start(1) |
|
145 |
, m_floatingMediaQuery(0) |
|
146 |
, m_floatingMediaQueryExp(0) |
|
147 |
, m_floatingMediaQueryExpList(0) |
|
148 |
{ |
|
149 |
#if YYDEBUG > 0 |
|
150 |
cssyydebug = 1; |
|
151 |
#endif |
|
152 |
} |
|
153 |
||
154 |
CSSParser::~CSSParser() |
|
155 |
{ |
|
156 |
clearProperties(); |
|
157 |
fastFree(m_parsedProperties); |
|
158 |
||
159 |
clearVariables(); |
|
160 |
||
161 |
delete m_valueList; |
|
162 |
||
163 |
fastFree(m_data); |
|
164 |
||
165 |
if (m_floatingMediaQueryExpList) { |
|
166 |
deleteAllValues(*m_floatingMediaQueryExpList); |
|
167 |
delete m_floatingMediaQueryExpList; |
|
168 |
} |
|
169 |
delete m_floatingMediaQueryExp; |
|
170 |
delete m_floatingMediaQuery; |
|
171 |
fastDeleteAllValues(m_floatingSelectors); |
|
172 |
deleteAllValues(m_floatingValueLists); |
|
173 |
deleteAllValues(m_floatingFunctions); |
|
174 |
deleteAllValues(m_reusableSelectorVector); |
|
175 |
} |
|
176 |
||
177 |
void CSSParserString::lower() |
|
178 |
{ |
|
179 |
// FIXME: If we need Unicode lowercasing here, then we probably want the real kind |
|
180 |
// that can potentially change the length of the string rather than the character |
|
181 |
// by character kind. If we don't need Unicode lowercasing, it would be good to |
|
182 |
// simplify this function. |
|
183 |
||
184 |
if (charactersAreAllASCII(characters, length)) { |
|
185 |
// Fast case for all-ASCII. |
|
186 |
for (int i = 0; i < length; i++) |
|
187 |
characters[i] = toASCIILower(characters[i]); |
|
188 |
} else { |
|
189 |
for (int i = 0; i < length; i++) |
|
190 |
characters[i] = Unicode::toLower(characters[i]); |
|
191 |
} |
|
192 |
} |
|
193 |
||
194 |
void CSSParser::setupParser(const char* prefix, const String& string, const char* suffix) |
|
195 |
{ |
|
196 |
int length = string.length() + strlen(prefix) + strlen(suffix) + 2; |
|
197 |
||
198 |
fastFree(m_data); |
|
199 |
m_data = static_cast<UChar*>(fastMalloc(length * sizeof(UChar))); |
|
200 |
for (unsigned i = 0; i < strlen(prefix); i++) |
|
201 |
m_data[i] = prefix[i]; |
|
202 |
||
203 |
memcpy(m_data + strlen(prefix), string.characters(), string.length() * sizeof(UChar)); |
|
204 |
||
205 |
unsigned start = strlen(prefix) + string.length(); |
|
206 |
unsigned end = start + strlen(suffix); |
|
207 |
for (unsigned i = start; i < end; i++) |
|
208 |
m_data[i] = suffix[i - start]; |
|
209 |
||
210 |
m_data[length - 1] = 0; |
|
211 |
m_data[length - 2] = 0; |
|
212 |
||
213 |
yy_hold_char = 0; |
|
214 |
yyleng = 0; |
|
215 |
yytext = yy_c_buf_p = m_data; |
|
216 |
yy_hold_char = *yy_c_buf_p; |
|
217 |
} |
|
218 |
||
219 |
void CSSParser::parseSheet(CSSStyleSheet* sheet, const String& string) |
|
220 |
{ |
|
221 |
m_styleSheet = sheet; |
|
222 |
m_defaultNamespace = starAtom; // Reset the default namespace. |
|
223 |
||
224 |
setupParser("", string, ""); |
|
225 |
cssyyparse(this); |
|
226 |
m_rule = 0; |
|
227 |
} |
|
228 |
||
229 |
PassRefPtr<CSSRule> CSSParser::parseRule(CSSStyleSheet* sheet, const String& string) |
|
230 |
{ |
|
231 |
m_styleSheet = sheet; |
|
232 |
setupParser("@-webkit-rule{", string, "} "); |
|
233 |
cssyyparse(this); |
|
234 |
return m_rule.release(); |
|
235 |
} |
|
236 |
||
237 |
PassRefPtr<CSSRule> CSSParser::parseKeyframeRule(CSSStyleSheet *sheet, const String &string) |
|
238 |
{ |
|
239 |
m_styleSheet = sheet; |
|
240 |
setupParser("@-webkit-keyframe-rule{ ", string, "} "); |
|
241 |
cssyyparse(this); |
|
242 |
return m_keyframe.release(); |
|
243 |
} |
|
244 |
||
245 |
bool CSSParser::parseValue(CSSMutableStyleDeclaration* declaration, int id, const String& string, bool important) |
|
246 |
{ |
|
247 |
ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet()); |
|
248 |
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet()); |
|
249 |
||
250 |
setupParser("@-webkit-value{", string, "} "); |
|
251 |
||
252 |
m_id = id; |
|
253 |
m_important = important; |
|
254 |
||
255 |
cssyyparse(this); |
|
256 |
||
257 |
m_rule = 0; |
|
258 |
||
259 |
bool ok = false; |
|
260 |
if (m_hasFontFaceOnlyValues) |
|
261 |
deleteFontFaceOnlyValues(); |
|
262 |
if (m_numParsedProperties) { |
|
263 |
ok = true; |
|
264 |
declaration->addParsedProperties(m_parsedProperties, m_numParsedProperties); |
|
265 |
clearProperties(); |
|
266 |
} |
|
267 |
||
268 |
return ok; |
|
269 |
} |
|
270 |
||
271 |
// color will only be changed when string contains a valid css color, making it |
|
272 |
// possible to set up a default color. |
|
273 |
bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict) |
|
274 |
{ |
|
275 |
color = 0; |
|
276 |
CSSParser parser(true); |
|
277 |
||
278 |
// First try creating a color specified by name or the "#" syntax. |
|
279 |
if (!parser.parseColor(string, color, strict)) { |
|
280 |
RefPtr<CSSMutableStyleDeclaration> dummyStyleDeclaration = CSSMutableStyleDeclaration::create(); |
|
281 |
||
282 |
// Now try to create a color from the rgb() or rgba() syntax. |
|
283 |
if (parser.parseColor(dummyStyleDeclaration.get(), string)) { |
|
284 |
CSSValue* value = parser.m_parsedProperties[0]->value(); |
|
285 |
if (value->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) { |
|
286 |
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value); |
|
287 |
color = primitiveValue->getRGBA32Value(); |
|
288 |
} |
|
289 |
} else |
|
290 |
return false; |
|
291 |
} |
|
292 |
||
293 |
return true; |
|
294 |
} |
|
295 |
||
296 |
bool CSSParser::parseColor(CSSMutableStyleDeclaration* declaration, const String& string) |
|
297 |
{ |
|
298 |
ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet()); |
|
299 |
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet()); |
|
300 |
||
301 |
setupParser("@-webkit-decls{color:", string, "} "); |
|
302 |
cssyyparse(this); |
|
303 |
m_rule = 0; |
|
304 |
||
305 |
return (m_numParsedProperties && m_parsedProperties[0]->m_id == CSSPropertyColor); |
|
306 |
} |
|
307 |
||
308 |
void CSSParser::parseSelector(const String& string, Document* doc, CSSSelectorList& selectorList) |
|
309 |
{ |
|
310 |
RefPtr<CSSStyleSheet> dummyStyleSheet = CSSStyleSheet::create(doc); |
|
311 |
||
312 |
m_styleSheet = dummyStyleSheet.get(); |
|
313 |
m_selectorListForParseSelector = &selectorList; |
|
314 |
||
315 |
setupParser("@-webkit-selector{", string, "}"); |
|
316 |
||
317 |
cssyyparse(this); |
|
318 |
||
319 |
m_selectorListForParseSelector = 0; |
|
320 |
} |
|
321 |
||
322 |
bool CSSParser::parseDeclaration(CSSMutableStyleDeclaration* declaration, const String& string) |
|
323 |
{ |
|
324 |
ASSERT(!declaration->stylesheet() || declaration->stylesheet()->isCSSStyleSheet()); |
|
325 |
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet()); |
|
326 |
||
327 |
setupParser("@-webkit-decls{", string, "} "); |
|
328 |
cssyyparse(this); |
|
329 |
m_rule = 0; |
|
330 |
||
331 |
bool ok = false; |
|
332 |
if (m_hasFontFaceOnlyValues) |
|
333 |
deleteFontFaceOnlyValues(); |
|
334 |
if (m_numParsedProperties) { |
|
335 |
ok = true; |
|
336 |
declaration->addParsedProperties(m_parsedProperties, m_numParsedProperties); |
|
337 |
clearProperties(); |
|
338 |
} |
|
339 |
||
340 |
return ok; |
|
341 |
} |
|
342 |
||
343 |
bool CSSParser::parseMediaQuery(MediaList* queries, const String& string) |
|
344 |
{ |
|
345 |
if (string.isEmpty()) |
|
346 |
return true; |
|
347 |
||
348 |
m_mediaQuery = 0; |
|
349 |
// can't use { because tokenizer state switches from mediaquery to initial state when it sees { token. |
|
350 |
// instead insert one " " (which is WHITESPACE in CSSGrammar.y) |
|
351 |
setupParser("@-webkit-mediaquery ", string, "} "); |
|
352 |
cssyyparse(this); |
|
353 |
||
354 |
bool ok = false; |
|
355 |
if (m_mediaQuery) { |
|
356 |
ok = true; |
|
357 |
queries->appendMediaQuery(m_mediaQuery); |
|
358 |
m_mediaQuery = 0; |
|
359 |
} |
|
360 |
||
361 |
return ok; |
|
362 |
} |
|
363 |
||
364 |
||
365 |
void CSSParser::addProperty(int propId, PassRefPtr<CSSValue> value, bool important) |
|
366 |
{ |
|
367 |
auto_ptr<CSSProperty> prop(new CSSProperty(propId, value, important, m_currentShorthand, m_implicitShorthand)); |
|
368 |
if (m_numParsedProperties >= m_maxParsedProperties) { |
|
369 |
m_maxParsedProperties += 32; |
|
370 |
if (m_maxParsedProperties > UINT_MAX / sizeof(CSSProperty*)) |
|
371 |
return; |
|
372 |
m_parsedProperties = static_cast<CSSProperty**>(fastRealloc(m_parsedProperties, |
|
373 |
m_maxParsedProperties * sizeof(CSSProperty*))); |
|
374 |
} |
|
375 |
m_parsedProperties[m_numParsedProperties++] = prop.release(); |
|
376 |
} |
|
377 |
||
378 |
void CSSParser::rollbackLastProperties(int num) |
|
379 |
{ |
|
380 |
ASSERT(num >= 0); |
|
381 |
ASSERT(m_numParsedProperties >= static_cast<unsigned>(num)); |
|
382 |
||
383 |
for (int i = 0; i < num; ++i) |
|
384 |
delete m_parsedProperties[--m_numParsedProperties]; |
|
385 |
} |
|
386 |
||
387 |
void CSSParser::clearProperties() |
|
388 |
{ |
|
389 |
for (unsigned i = 0; i < m_numParsedProperties; i++) |
|
390 |
delete m_parsedProperties[i]; |
|
391 |
m_numParsedProperties = 0; |
|
392 |
m_hasFontFaceOnlyValues = false; |
|
393 |
} |
|
394 |
||
395 |
Document* CSSParser::document() const |
|
396 |
{ |
|
397 |
StyleBase* root = m_styleSheet; |
|
398 |
Document* doc = 0; |
|
399 |
while (root && root->parent()) |
|
400 |
root = root->parent(); |
|
401 |
if (root && root->isCSSStyleSheet()) |
|
402 |
doc = static_cast<CSSStyleSheet*>(root)->doc(); |
|
403 |
return doc; |
|
404 |
} |
|
405 |
||
406 |
bool CSSParser::validUnit(CSSParserValue* value, Units unitflags, bool strict) |
|
407 |
{ |
|
408 |
bool b = false; |
|
409 |
switch (value->unit) { |
|
410 |
case CSSPrimitiveValue::CSS_NUMBER: |
|
411 |
b = (unitflags & FNumber); |
|
412 |
if (!b && ((unitflags & (FLength | FAngle | FTime)) && (value->fValue == 0 || !strict))) { |
|
413 |
value->unit = (unitflags & FLength) ? CSSPrimitiveValue::CSS_PX : |
|
414 |
((unitflags & FAngle) ? CSSPrimitiveValue::CSS_DEG : CSSPrimitiveValue::CSS_MS); |
|
415 |
b = true; |
|
416 |
} |
|
417 |
if (!b && (unitflags & FInteger) && value->isInt) |
|
418 |
b = true; |
|
419 |
break; |
|
420 |
case CSSPrimitiveValue::CSS_PERCENTAGE: |
|
421 |
b = (unitflags & FPercent); |
|
422 |
break; |
|
423 |
case CSSParserValue::Q_EMS: |
|
424 |
case CSSPrimitiveValue::CSS_EMS: |
|
425 |
case CSSPrimitiveValue::CSS_REMS: |
|
426 |
case CSSPrimitiveValue::CSS_EXS: |
|
427 |
case CSSPrimitiveValue::CSS_PX: |
|
428 |
case CSSPrimitiveValue::CSS_CM: |
|
429 |
case CSSPrimitiveValue::CSS_MM: |
|
430 |
case CSSPrimitiveValue::CSS_IN: |
|
431 |
case CSSPrimitiveValue::CSS_PT: |
|
432 |
case CSSPrimitiveValue::CSS_PC: |
|
433 |
b = (unitflags & FLength); |
|
434 |
break; |
|
435 |
case CSSPrimitiveValue::CSS_MS: |
|
436 |
case CSSPrimitiveValue::CSS_S: |
|
437 |
b = (unitflags & FTime); |
|
438 |
break; |
|
439 |
case CSSPrimitiveValue::CSS_DEG: |
|
440 |
case CSSPrimitiveValue::CSS_RAD: |
|
441 |
case CSSPrimitiveValue::CSS_GRAD: |
|
442 |
case CSSPrimitiveValue::CSS_TURN: |
|
443 |
b = (unitflags & FAngle); |
|
444 |
break; |
|
445 |
case CSSPrimitiveValue::CSS_HZ: |
|
446 |
case CSSPrimitiveValue::CSS_KHZ: |
|
447 |
case CSSPrimitiveValue::CSS_DIMENSION: |
|
448 |
default: |
|
449 |
break; |
|
450 |
} |
|
451 |
if (b && unitflags & FNonNeg && value->fValue < 0) |
|
452 |
b = false; |
|
453 |
return b; |
|
454 |
} |
|
455 |
||
456 |
static int unitFromString(CSSParserValue* value) |
|
457 |
{ |
|
458 |
if (value->unit != CSSPrimitiveValue::CSS_IDENT || value->id) |
|
459 |
return 0; |
|
460 |
||
461 |
if (equal(value->string, "em")) |
|
462 |
return CSSPrimitiveValue::CSS_EMS; |
|
463 |
if (equal(value->string, "rem")) |
|
464 |
return CSSPrimitiveValue::CSS_REMS; |
|
465 |
if (equal(value->string, "ex")) |
|
466 |
return CSSPrimitiveValue::CSS_EXS; |
|
467 |
if (equal(value->string, "px")) |
|
468 |
return CSSPrimitiveValue::CSS_PX; |
|
469 |
if (equal(value->string, "cm")) |
|
470 |
return CSSPrimitiveValue::CSS_CM; |
|
471 |
if (equal(value->string, "mm")) |
|
472 |
return CSSPrimitiveValue::CSS_MM; |
|
473 |
if (equal(value->string, "in")) |
|
474 |
return CSSPrimitiveValue::CSS_IN; |
|
475 |
if (equal(value->string, "pt")) |
|
476 |
return CSSPrimitiveValue::CSS_PT; |
|
477 |
if (equal(value->string, "pc")) |
|
478 |
return CSSPrimitiveValue::CSS_PC; |
|
479 |
if (equal(value->string, "deg")) |
|
480 |
return CSSPrimitiveValue::CSS_DEG; |
|
481 |
if (equal(value->string, "rad")) |
|
482 |
return CSSPrimitiveValue::CSS_RAD; |
|
483 |
if (equal(value->string, "grad")) |
|
484 |
return CSSPrimitiveValue::CSS_GRAD; |
|
485 |
if (equal(value->string, "turn")) |
|
486 |
return CSSPrimitiveValue::CSS_TURN; |
|
487 |
if (equal(value->string, "ms")) |
|
488 |
return CSSPrimitiveValue::CSS_MS; |
|
489 |
if (equal(value->string, "s")) |
|
490 |
return CSSPrimitiveValue::CSS_S; |
|
491 |
if (equal(value->string, "Hz")) |
|
492 |
return CSSPrimitiveValue::CSS_HZ; |
|
493 |
if (equal(value->string, "kHz")) |
|
494 |
return CSSPrimitiveValue::CSS_KHZ; |
|
495 |
||
496 |
return 0; |
|
497 |
} |
|
498 |
||
499 |
void CSSParser::checkForOrphanedUnits() |
|
500 |
{ |
|
501 |
if (m_strict || inShorthand()) |
|
502 |
return; |
|
503 |
||
504 |
// The purpose of this code is to implement the WinIE quirk that allows unit types to be separated from their numeric values |
|
505 |
// by whitespace, so e.g., width: 20 px instead of width:20px. This is invalid CSS, so we don't do this in strict mode. |
|
506 |
CSSParserValue* numericVal = 0; |
|
507 |
unsigned size = m_valueList->size(); |
|
508 |
for (unsigned i = 0; i < size; i++) { |
|
509 |
CSSParserValue* value = m_valueList->valueAt(i); |
|
510 |
||
511 |
if (numericVal) { |
|
512 |
// Change the unit type of the numeric val to match. |
|
513 |
int unit = unitFromString(value); |
|
514 |
if (unit) { |
|
515 |
numericVal->unit = unit; |
|
516 |
numericVal = 0; |
|
517 |
||
518 |
// Now delete the bogus unit value. |
|
519 |
m_valueList->deleteValueAt(i); |
|
520 |
i--; // We're safe even though |i| is unsigned, since we only hit this code if we had a previous numeric value (so |i| is always > 0 here). |
|
521 |
size--; |
|
522 |
continue; |
|
523 |
} |
|
524 |
} |
|
525 |
||
526 |
numericVal = (value->unit == CSSPrimitiveValue::CSS_NUMBER) ? value : 0; |
|
527 |
} |
|
528 |
} |
|
529 |
||
530 |
bool CSSParser::parseValue(int propId, bool important) |
|
531 |
{ |
|
532 |
if (!m_valueList) |
|
533 |
return false; |
|
534 |
||
535 |
CSSParserValue *value = m_valueList->current(); |
|
536 |
||
537 |
if (!value) |
|
538 |
return false; |
|
539 |
||
540 |
int id = value->id; |
|
541 |
||
542 |
// In quirks mode, we will look for units that have been incorrectly separated from the number they belong to |
|
543 |
// by a space. We go ahead and associate the unit with the number even though it is invalid CSS. |
|
544 |
checkForOrphanedUnits(); |
|
545 |
||
546 |
int num = inShorthand() ? 1 : m_valueList->size(); |
|
547 |
||
548 |
if (id == CSSValueInherit) { |
|
549 |
if (num != 1) |
|
550 |
return false; |
|
551 |
addProperty(propId, CSSInheritedValue::create(), important); |
|
552 |
return true; |
|
553 |
} |
|
554 |
else if (id == CSSValueInitial) { |
|
555 |
if (num != 1) |
|
556 |
return false; |
|
557 |
addProperty(propId, CSSInitialValue::createExplicit(), important); |
|
558 |
return true; |
|
559 |
} |
|
560 |
||
561 |
// If we have any variables, then we don't parse the list of values yet. We add them to the declaration |
|
562 |
// as unresolved, and allow them to be parsed later. The parse is considered "successful" for now, even though |
|
563 |
// it might ultimately fail once the variable has been resolved. |
|
564 |
if (!inShorthand() && checkForVariables(m_valueList)) { |
|
565 |
addUnresolvedProperty(propId, important); |
|
566 |
return true; |
|
567 |
} |
|
568 |
||
569 |
bool valid_primitive = false; |
|
570 |
RefPtr<CSSValue> parsedValue; |
|
571 |
||
572 |
switch (static_cast<CSSPropertyID>(propId)) { |
|
573 |
/* The comment to the left defines all valid value of this properties as defined |
|
574 |
* in CSS 2, Appendix F. Property index |
|
575 |
*/ |
|
576 |
||
577 |
/* All the CSS properties are not supported by the renderer at the moment. |
|
578 |
* Note that all the CSS2 Aural properties are only checked, if CSS_AURAL is defined |
|
579 |
* (see parseAuralValues). As we don't support them at all this seems reasonable. |
|
580 |
*/ |
|
581 |
||
582 |
case CSSPropertySize: // <length>{1,2} | auto | portrait | landscape | inherit |
|
583 |
case CSSPropertyQuotes: // [<string> <string>]+ | none | inherit |
|
584 |
if (id) |
|
585 |
valid_primitive = true; |
|
586 |
break; |
|
587 |
case CSSPropertyUnicodeBidi: // normal | embed | bidi-override | inherit |
|
588 |
if (id == CSSValueNormal || |
|
589 |
id == CSSValueEmbed || |
|
590 |
id == CSSValueBidiOverride) |
|
591 |
valid_primitive = true; |
|
592 |
break; |
|
593 |
||
594 |
case CSSPropertyPosition: // static | relative | absolute | fixed | inherit |
|
595 |
if (id == CSSValueStatic || |
|
596 |
id == CSSValueRelative || |
|
597 |
id == CSSValueAbsolute || |
|
598 |
id == CSSValueFixed) |
|
599 |
valid_primitive = true; |
|
600 |
break; |
|
601 |
||
602 |
case CSSPropertyPageBreakAfter: // auto | always | avoid | left | right | inherit |
|
603 |
case CSSPropertyPageBreakBefore: |
|
604 |
case CSSPropertyWebkitColumnBreakAfter: |
|
605 |
case CSSPropertyWebkitColumnBreakBefore: |
|
606 |
if (id == CSSValueAuto || |
|
607 |
id == CSSValueAlways || |
|
608 |
id == CSSValueAvoid || |
|
609 |
id == CSSValueLeft || |
|
610 |
id == CSSValueRight) |
|
611 |
valid_primitive = true; |
|
612 |
break; |
|
613 |
||
614 |
case CSSPropertyPageBreakInside: // avoid | auto | inherit |
|
615 |
case CSSPropertyWebkitColumnBreakInside: |
|
616 |
if (id == CSSValueAuto || id == CSSValueAvoid) |
|
617 |
valid_primitive = true; |
|
618 |
break; |
|
619 |
||
620 |
case CSSPropertyEmptyCells: // show | hide | inherit |
|
621 |
if (id == CSSValueShow || |
|
622 |
id == CSSValueHide) |
|
623 |
valid_primitive = true; |
|
624 |
break; |
|
625 |
||
626 |
case CSSPropertyContent: // [ <string> | <uri> | <counter> | attr(X) | open-quote | |
|
627 |
// close-quote | no-open-quote | no-close-quote ]+ | inherit |
|
628 |
return parseContent(propId, important); |
|
629 |
||
630 |
case CSSPropertyWhiteSpace: // normal | pre | nowrap | inherit |
|
631 |
if (id == CSSValueNormal || |
|
632 |
id == CSSValuePre || |
|
633 |
id == CSSValuePreWrap || |
|
634 |
id == CSSValuePreLine || |
|
635 |
id == CSSValueNowrap) |
|
636 |
valid_primitive = true; |
|
637 |
break; |
|
638 |
||
639 |
case CSSPropertyClip: // <shape> | auto | inherit |
|
640 |
if (id == CSSValueAuto) |
|
641 |
valid_primitive = true; |
|
642 |
else if (value->unit == CSSParserValue::Function) |
|
643 |
return parseShape(propId, important); |
|
644 |
break; |
|
645 |
||
646 |
/* Start of supported CSS properties with validation. This is needed for parseShorthand to work |
|
647 |
* correctly and allows optimization in WebCore::applyRule(..) |
|
648 |
*/ |
|
649 |
case CSSPropertyCaptionSide: // top | bottom | left | right | inherit |
|
650 |
if (id == CSSValueLeft || id == CSSValueRight || |
|
651 |
id == CSSValueTop || id == CSSValueBottom) |
|
652 |
valid_primitive = true; |
|
653 |
break; |
|
654 |
||
655 |
case CSSPropertyBorderCollapse: // collapse | separate | inherit |
|
656 |
if (id == CSSValueCollapse || id == CSSValueSeparate) |
|
657 |
valid_primitive = true; |
|
658 |
break; |
|
659 |
||
660 |
case CSSPropertyVisibility: // visible | hidden | collapse | inherit |
|
661 |
if (id == CSSValueVisible || id == CSSValueHidden || id == CSSValueCollapse) |
|
662 |
valid_primitive = true; |
|
663 |
break; |
|
664 |
||
665 |
case CSSPropertyOverflow: { |
|
666 |
ShorthandScope scope(this, propId); |
|
667 |
if (num != 1 || !parseValue(CSSPropertyOverflowX, important)) |
|
668 |
return false; |
|
669 |
CSSValue* value = m_parsedProperties[m_numParsedProperties - 1]->value(); |
|
670 |
addProperty(CSSPropertyOverflowY, value, important); |
|
671 |
return true; |
|
672 |
} |
|
673 |
case CSSPropertyOverflowX: |
|
674 |
case CSSPropertyOverflowY: // visible | hidden | scroll | auto | marquee | overlay | inherit |
|
675 |
if (id == CSSValueVisible || id == CSSValueHidden || id == CSSValueScroll || id == CSSValueAuto || |
|
676 |
id == CSSValueOverlay || id == CSSValueWebkitMarquee) |
|
677 |
valid_primitive = true; |
|
678 |
break; |
|
679 |
||
680 |
case CSSPropertyListStylePosition: // inside | outside | inherit |
|
681 |
if (id == CSSValueInside || id == CSSValueOutside) |
|
682 |
valid_primitive = true; |
|
683 |
break; |
|
684 |
||
685 |
case CSSPropertyListStyleType: |
|
686 |
// disc | circle | square | decimal | decimal-leading-zero | lower-roman | |
|
687 |
// upper-roman | lower-greek | lower-alpha | lower-latin | upper-alpha | |
|
688 |
// upper-latin | hebrew | armenian | georgian | cjk-ideographic | hiragana | |
|
689 |
// katakana | hiragana-iroha | katakana-iroha | none | inherit |
|
690 |
if ((id >= CSSValueDisc && id <= CSSValueKatakanaIroha) || id == CSSValueNone) |
|
691 |
valid_primitive = true; |
|
692 |
break; |
|
693 |
||
694 |
case CSSPropertyDisplay: |
|
695 |
// inline | block | list-item | run-in | inline-block | table | |
|
696 |
// inline-table | table-row-group | table-header-group | table-footer-group | table-row | |
|
697 |
// table-column-group | table-column | table-cell | table-caption | box | inline-box | none | inherit |
|
698 |
#if ENABLE(WCSS) |
|
699 |
if ((id >= CSSValueInline && id <= CSSValueWapMarquee) || id == CSSValueNone) |
|
700 |
#else |
|
701 |
if ((id >= CSSValueInline && id <= CSSValueWebkitInlineBox) || id == CSSValueNone) |
|
702 |
#endif |
|
703 |
valid_primitive = true; |
|
704 |
break; |
|
705 |
||
706 |
case CSSPropertyDirection: // ltr | rtl | inherit |
|
707 |
if (id == CSSValueLtr || id == CSSValueRtl) |
|
708 |
valid_primitive = true; |
|
709 |
break; |
|
710 |
||
711 |
case CSSPropertyTextTransform: // capitalize | uppercase | lowercase | none | inherit |
|
712 |
if ((id >= CSSValueCapitalize && id <= CSSValueLowercase) || id == CSSValueNone) |
|
713 |
valid_primitive = true; |
|
714 |
break; |
|
715 |
||
716 |
case CSSPropertyFloat: // left | right | none | inherit + center for buggy CSS |
|
717 |
if (id == CSSValueLeft || id == CSSValueRight || |
|
718 |
id == CSSValueNone || id == CSSValueCenter) |
|
719 |
valid_primitive = true; |
|
720 |
break; |
|
721 |
||
722 |
case CSSPropertyClear: // none | left | right | both | inherit |
|
723 |
if (id == CSSValueNone || id == CSSValueLeft || |
|
724 |
id == CSSValueRight|| id == CSSValueBoth) |
|
725 |
valid_primitive = true; |
|
726 |
break; |
|
727 |
||
728 |
case CSSPropertyTextAlign: |
|
729 |
// left | right | center | justify | webkit_left | webkit_right | webkit_center | start | end | <string> | inherit |
|
730 |
if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitCenter) || id == CSSValueStart || id == CSSValueEnd || |
|
731 |
value->unit == CSSPrimitiveValue::CSS_STRING) |
|
732 |
valid_primitive = true; |
|
733 |
break; |
|
734 |
||
735 |
case CSSPropertyOutlineStyle: // (<border-style> except hidden) | auto | inherit |
|
736 |
if (id == CSSValueAuto || id == CSSValueNone || (id >= CSSValueInset && id <= CSSValueDouble)) |
|
737 |
valid_primitive = true; |
|
738 |
break; |
|
739 |
||
740 |
case CSSPropertyBorderTopStyle: //// <border-style> | inherit |
|
741 |
case CSSPropertyBorderRightStyle: // Defined as: none | hidden | dotted | dashed | |
|
742 |
case CSSPropertyBorderBottomStyle: // solid | double | groove | ridge | inset | outset |
|
743 |
case CSSPropertyBorderLeftStyle: |
|
744 |
case CSSPropertyWebkitColumnRuleStyle: |
|
745 |
if (id >= CSSValueNone && id <= CSSValueDouble) |
|
746 |
valid_primitive = true; |
|
747 |
break; |
|
748 |
||
749 |
case CSSPropertyFontWeight: // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit |
|
750 |
return parseFontWeight(important); |
|
751 |
||
752 |
case CSSPropertyBorderSpacing: { |
|
753 |
const int properties[2] = { CSSPropertyWebkitBorderHorizontalSpacing, |
|
754 |
CSSPropertyWebkitBorderVerticalSpacing }; |
|
755 |
if (num == 1) { |
|
756 |
ShorthandScope scope(this, CSSPropertyBorderSpacing); |
|
757 |
if (!parseValue(properties[0], important)) |
|
758 |
return false; |
|
759 |
CSSValue* value = m_parsedProperties[m_numParsedProperties-1]->value(); |
|
760 |
addProperty(properties[1], value, important); |
|
761 |
return true; |
|
762 |
} |
|
763 |
else if (num == 2) { |
|
764 |
ShorthandScope scope(this, CSSPropertyBorderSpacing); |
|
765 |
if (!parseValue(properties[0], important) || !parseValue(properties[1], important)) |
|
766 |
return false; |
|
767 |
return true; |
|
768 |
} |
|
769 |
return false; |
|
770 |
} |
|
771 |
case CSSPropertyWebkitBorderHorizontalSpacing: |
|
772 |
case CSSPropertyWebkitBorderVerticalSpacing: |
|
773 |
valid_primitive = validUnit(value, FLength|FNonNeg, m_strict); |
|
774 |
break; |
|
775 |
case CSSPropertyOutlineColor: // <color> | invert | inherit |
|
776 |
// Outline color has "invert" as additional keyword. |
|
777 |
// Also, we want to allow the special focus color even in strict parsing mode. |
|
778 |
if (propId == CSSPropertyOutlineColor && (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor)) { |
|
779 |
valid_primitive = true; |
|
780 |
break; |
|
781 |
} |
|
782 |
/* nobreak */ |
|
783 |
case CSSPropertyBackgroundColor: // <color> | inherit |
|
784 |
case CSSPropertyBorderTopColor: // <color> | inherit |
|
785 |
case CSSPropertyBorderRightColor: // <color> | inherit |
|
786 |
case CSSPropertyBorderBottomColor: // <color> | inherit |
|
787 |
case CSSPropertyBorderLeftColor: // <color> | inherit |
|
788 |
case CSSPropertyColor: // <color> | inherit |
|
789 |
case CSSPropertyTextLineThroughColor: // CSS3 text decoration colors |
|
790 |
case CSSPropertyTextUnderlineColor: |
|
791 |
case CSSPropertyTextOverlineColor: |
|
792 |
case CSSPropertyWebkitColumnRuleColor: |
|
793 |
case CSSPropertyWebkitTextFillColor: |
|
794 |
case CSSPropertyWebkitTextStrokeColor: |
|
795 |
if (id == CSSValueWebkitText) |
|
796 |
valid_primitive = true; // Always allow this, even when strict parsing is on, |
|
797 |
// since we use this in our UA sheets. |
|
798 |
else if (id == CSSValueCurrentcolor) |
|
799 |
valid_primitive = true; |
|
800 |
else if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu || |
|
801 |
(id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && !m_strict)) { |
|
802 |
valid_primitive = true; |
|
803 |
} else { |
|
804 |
parsedValue = parseColor(); |
|
805 |
if (parsedValue) |
|
806 |
m_valueList->next(); |
|
807 |
} |
|
808 |
break; |
|
809 |
||
810 |
case CSSPropertyCursor: { |
|
811 |
// [<uri>,]* [ auto | crosshair | default | pointer | progress | move | e-resize | ne-resize | |
|
812 |
// nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | ew-resize | |
|
813 |
// ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | text | wait | help | |
|
814 |
// vertical-text | cell | context-menu | alias | copy | no-drop | not-allowed | -webkit-zoom-in |
|
815 |
// -webkit-zoom-in | -webkit-zoom-out | all-scroll | -webkit-grab | -webkit-grabbing ] ] | inherit |
|
816 |
RefPtr<CSSValueList> list; |
|
817 |
while (value && value->unit == CSSPrimitiveValue::CSS_URI) { |
|
818 |
if (!list) |
|
819 |
list = CSSValueList::createCommaSeparated(); |
|
820 |
String uri = value->string; |
|
821 |
Vector<int> coords; |
|
822 |
value = m_valueList->next(); |
|
823 |
while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) { |
|
824 |
coords.append(int(value->fValue)); |
|
825 |
value = m_valueList->next(); |
|
826 |
} |
|
827 |
IntPoint hotspot; |
|
828 |
int nrcoords = coords.size(); |
|
829 |
if (nrcoords > 0 && nrcoords != 2) |
|
830 |
return false; |
|
831 |
if (nrcoords == 2) |
|
832 |
hotspot = IntPoint(coords[0], coords[1]); |
|
833 |
||
834 |
if (!uri.isNull() && m_styleSheet) { |
|
835 |
// FIXME: The completeURL call should be done when using the CSSCursorImageValue, |
|
836 |
// not when creating it. |
|
837 |
list->append(CSSCursorImageValue::create(m_styleSheet->completeURL(uri), hotspot)); |
|
838 |
} |
|
839 |
||
840 |
if ((m_strict && !value) || (value && !(value->unit == CSSParserValue::Operator && value->iValue == ','))) |
|
841 |
return false; |
|
842 |
value = m_valueList->next(); // comma |
|
843 |
} |
|
844 |
if (list) { |
|
845 |
if (!value) { // no value after url list (MSIE 5 compatibility) |
|
846 |
if (list->length() != 1) |
|
847 |
return false; |
|
848 |
} else if (!m_strict && value->id == CSSValueHand) // MSIE 5 compatibility :/ |
|
849 |
list->append(CSSPrimitiveValue::createIdentifier(CSSValuePointer)); |
|
850 |
else if (value && ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)) |
|
851 |
list->append(CSSPrimitiveValue::createIdentifier(value->id)); |
|
852 |
m_valueList->next(); |
|
853 |
parsedValue = list.release(); |
|
854 |
break; |
|
855 |
} |
|
856 |
id = value->id; |
|
857 |
if (!m_strict && value->id == CSSValueHand) { // MSIE 5 compatibility :/ |
|
858 |
id = CSSValuePointer; |
|
859 |
valid_primitive = true; |
|
860 |
} else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone) |
|
861 |
valid_primitive = true; |
|
862 |
break; |
|
863 |
} |
|
864 |
||
865 |
case CSSPropertyBackgroundAttachment: |
|
866 |
case CSSPropertyBackgroundClip: |
|
867 |
case CSSPropertyWebkitBackgroundClip: |
|
868 |
case CSSPropertyWebkitBackgroundComposite: |
|
869 |
case CSSPropertyBackgroundImage: |
|
870 |
case CSSPropertyBackgroundOrigin: |
|
871 |
case CSSPropertyWebkitBackgroundOrigin: |
|
872 |
case CSSPropertyBackgroundPosition: |
|
873 |
case CSSPropertyBackgroundPositionX: |
|
874 |
case CSSPropertyBackgroundPositionY: |
|
875 |
case CSSPropertyBackgroundSize: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
876 |
case CSSPropertyWebkitBackgroundSize: |
0 | 877 |
case CSSPropertyBackgroundRepeat: |
878 |
case CSSPropertyBackgroundRepeatX: |
|
879 |
case CSSPropertyBackgroundRepeatY: |
|
880 |
case CSSPropertyWebkitMaskAttachment: |
|
881 |
case CSSPropertyWebkitMaskClip: |
|
882 |
case CSSPropertyWebkitMaskComposite: |
|
883 |
case CSSPropertyWebkitMaskImage: |
|
884 |
case CSSPropertyWebkitMaskOrigin: |
|
885 |
case CSSPropertyWebkitMaskPosition: |
|
886 |
case CSSPropertyWebkitMaskPositionX: |
|
887 |
case CSSPropertyWebkitMaskPositionY: |
|
888 |
case CSSPropertyWebkitMaskSize: |
|
889 |
case CSSPropertyWebkitMaskRepeat: |
|
890 |
case CSSPropertyWebkitMaskRepeatX: |
|
891 |
case CSSPropertyWebkitMaskRepeatY: { |
|
892 |
RefPtr<CSSValue> val1; |
|
893 |
RefPtr<CSSValue> val2; |
|
894 |
int propId1, propId2; |
|
895 |
bool result = false; |
|
896 |
if (parseFillProperty(propId, propId1, propId2, val1, val2)) { |
|
897 |
OwnPtr<ShorthandScope> shorthandScope; |
|
898 |
if (propId == CSSPropertyBackgroundPosition || |
|
899 |
propId == CSSPropertyBackgroundRepeat || |
|
900 |
propId == CSSPropertyWebkitMaskPosition || |
|
901 |
propId == CSSPropertyWebkitMaskRepeat) { |
|
902 |
shorthandScope.set(new ShorthandScope(this, propId)); |
|
903 |
} |
|
904 |
addProperty(propId1, val1.release(), important); |
|
905 |
if (val2) |
|
906 |
addProperty(propId2, val2.release(), important); |
|
907 |
result = true; |
|
908 |
} |
|
909 |
m_implicitShorthand = false; |
|
910 |
return result; |
|
911 |
} |
|
912 |
case CSSPropertyListStyleImage: // <uri> | none | inherit |
|
913 |
if (id == CSSValueNone) { |
|
914 |
parsedValue = CSSImageValue::create(); |
|
915 |
m_valueList->next(); |
|
916 |
} else if (value->unit == CSSPrimitiveValue::CSS_URI) { |
|
917 |
if (m_styleSheet) { |
|
918 |
// FIXME: The completeURL call should be done when using the CSSImageValue, |
|
919 |
// not when creating it. |
|
920 |
parsedValue = CSSImageValue::create(m_styleSheet->completeURL(value->string)); |
|
921 |
m_valueList->next(); |
|
922 |
} |
|
923 |
} else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-gradient(")) { |
|
924 |
if (parseGradient(parsedValue)) |
|
925 |
m_valueList->next(); |
|
926 |
else |
|
927 |
return false; |
|
928 |
} |
|
929 |
break; |
|
930 |
||
931 |
case CSSPropertyWebkitTextStrokeWidth: |
|
932 |
case CSSPropertyOutlineWidth: // <border-width> | inherit |
|
933 |
case CSSPropertyBorderTopWidth: //// <border-width> | inherit |
|
934 |
case CSSPropertyBorderRightWidth: // Which is defined as |
|
935 |
case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length> |
|
936 |
case CSSPropertyBorderLeftWidth: |
|
937 |
case CSSPropertyWebkitColumnRuleWidth: |
|
938 |
if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick) |
|
939 |
valid_primitive = true; |
|
940 |
else |
|
941 |
valid_primitive = validUnit(value, FLength, m_strict); |
|
942 |
break; |
|
943 |
||
944 |
case CSSPropertyLetterSpacing: // normal | <length> | inherit |
|
945 |
case CSSPropertyWordSpacing: // normal | <length> | inherit |
|
946 |
if (id == CSSValueNormal) |
|
947 |
valid_primitive = true; |
|
948 |
else |
|
949 |
valid_primitive = validUnit(value, FLength, m_strict); |
|
950 |
break; |
|
951 |
||
952 |
case CSSPropertyWordBreak: // normal | break-all | break-word (this is a custom extension) |
|
953 |
if (id == CSSValueNormal || id == CSSValueBreakAll || id == CSSValueBreakWord) |
|
954 |
valid_primitive = true; |
|
955 |
break; |
|
956 |
||
957 |
case CSSPropertyWordWrap: // normal | break-word |
|
958 |
if (id == CSSValueNormal || id == CSSValueBreakWord) |
|
959 |
valid_primitive = true; |
|
960 |
break; |
|
961 |
||
962 |
case CSSPropertyTextIndent: // <length> | <percentage> | inherit |
|
963 |
case CSSPropertyPaddingTop: //// <padding-width> | inherit |
|
964 |
case CSSPropertyPaddingRight: // Which is defined as |
|
965 |
case CSSPropertyPaddingBottom: // <length> | <percentage> |
|
966 |
case CSSPropertyPaddingLeft: //// |
|
967 |
case CSSPropertyWebkitPaddingStart: |
|
968 |
valid_primitive = (!id && validUnit(value, FLength|FPercent, m_strict)); |
|
969 |
break; |
|
970 |
||
971 |
case CSSPropertyMaxHeight: // <length> | <percentage> | none | inherit |
|
972 |
case CSSPropertyMaxWidth: // <length> | <percentage> | none | inherit |
|
973 |
if (id == CSSValueNone || id == CSSValueIntrinsic || id == CSSValueMinIntrinsic) { |
|
974 |
valid_primitive = true; |
|
975 |
break; |
|
976 |
} |
|
977 |
/* nobreak */ |
|
978 |
case CSSPropertyMinHeight: // <length> | <percentage> | inherit |
|
979 |
case CSSPropertyMinWidth: // <length> | <percentage> | inherit |
|
980 |
if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic) |
|
981 |
valid_primitive = true; |
|
982 |
else |
|
983 |
valid_primitive = (!id && validUnit(value, FLength|FPercent|FNonNeg, m_strict)); |
|
984 |
break; |
|
985 |
||
986 |
case CSSPropertyFontSize: |
|
987 |
// <absolute-size> | <relative-size> | <length> | <percentage> | inherit |
|
988 |
if (id >= CSSValueXxSmall && id <= CSSValueLarger) |
|
989 |
valid_primitive = true; |
|
990 |
else |
|
991 |
valid_primitive = (validUnit(value, FLength|FPercent|FNonNeg, m_strict)); |
|
992 |
break; |
|
993 |
||
994 |
case CSSPropertyFontStyle: // normal | italic | oblique | inherit |
|
995 |
return parseFontStyle(important); |
|
996 |
||
997 |
case CSSPropertyFontVariant: // normal | small-caps | inherit |
|
998 |
return parseFontVariant(important); |
|
999 |
||
1000 |
case CSSPropertyVerticalAlign: |
|
1001 |
// baseline | sub | super | top | text-top | middle | bottom | text-bottom | |
|
1002 |
// <percentage> | <length> | inherit |
|
1003 |
||
1004 |
if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle) |
|
1005 |
valid_primitive = true; |
|
1006 |
else |
|
1007 |
valid_primitive = (!id && validUnit(value, FLength|FPercent, m_strict)); |
|
1008 |
break; |
|
1009 |
||
1010 |
case CSSPropertyHeight: // <length> | <percentage> | auto | inherit |
|
1011 |
case CSSPropertyWidth: // <length> | <percentage> | auto | inherit |
|
1012 |
if (id == CSSValueAuto || id == CSSValueIntrinsic || id == CSSValueMinIntrinsic) |
|
1013 |
valid_primitive = true; |
|
1014 |
else |
|
1015 |
// ### handle multilength case where we allow relative units |
|
1016 |
valid_primitive = (!id && validUnit(value, FLength|FPercent|FNonNeg, m_strict)); |
|
1017 |
break; |
|
1018 |
||
1019 |
case CSSPropertyBottom: // <length> | <percentage> | auto | inherit |
|
1020 |
case CSSPropertyLeft: // <length> | <percentage> | auto | inherit |
|
1021 |
case CSSPropertyRight: // <length> | <percentage> | auto | inherit |
|
1022 |
case CSSPropertyTop: // <length> | <percentage> | auto | inherit |
|
1023 |
case CSSPropertyMarginTop: //// <margin-width> | inherit |
|
1024 |
case CSSPropertyMarginRight: // Which is defined as |
|
1025 |
case CSSPropertyMarginBottom: // <length> | <percentage> | auto | inherit |
|
1026 |
case CSSPropertyMarginLeft: //// |
|
1027 |
case CSSPropertyWebkitMarginStart: |
|
1028 |
if (id == CSSValueAuto) |
|
1029 |
valid_primitive = true; |
|
1030 |
else |
|
1031 |
valid_primitive = (!id && validUnit(value, FLength|FPercent, m_strict)); |
|
1032 |
break; |
|
1033 |
||
1034 |
case CSSPropertyZIndex: // auto | <integer> | inherit |
|
1035 |
if (id == CSSValueAuto) { |
|
1036 |
valid_primitive = true; |
|
1037 |
break; |
|
1038 |
} |
|
1039 |
/* nobreak */ |
|
1040 |
case CSSPropertyOrphans: // <integer> | inherit |
|
1041 |
case CSSPropertyWidows: // <integer> | inherit |
|
1042 |
// ### not supported later on |
|
1043 |
valid_primitive = (!id && validUnit(value, FInteger, false)); |
|
1044 |
break; |
|
1045 |
||
1046 |
case CSSPropertyLineHeight: // normal | <number> | <length> | <percentage> | inherit |
|
1047 |
if (id == CSSValueNormal) |
|
1048 |
valid_primitive = true; |
|
1049 |
else |
|
1050 |
valid_primitive = (!id && validUnit(value, FNumber|FLength|FPercent|FNonNeg, m_strict)); |
|
1051 |
break; |
|
1052 |
case CSSPropertyCounterIncrement: // [ <identifier> <integer>? ]+ | none | inherit |
|
1053 |
if (id != CSSValueNone) |
|
1054 |
return parseCounter(propId, 1, important); |
|
1055 |
valid_primitive = true; |
|
1056 |
break; |
|
1057 |
case CSSPropertyCounterReset: // [ <identifier> <integer>? ]+ | none | inherit |
|
1058 |
if (id != CSSValueNone) |
|
1059 |
return parseCounter(propId, 0, important); |
|
1060 |
valid_primitive = true; |
|
1061 |
break; |
|
1062 |
case CSSPropertyFontFamily: |
|
1063 |
// [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-family>] | inherit |
|
1064 |
{ |
|
1065 |
parsedValue = parseFontFamily(); |
|
1066 |
break; |
|
1067 |
} |
|
1068 |
||
1069 |
case CSSPropertyTextDecoration: |
|
1070 |
case CSSPropertyWebkitTextDecorationsInEffect: |
|
1071 |
// none | [ underline || overline || line-through || blink ] | inherit |
|
1072 |
if (id == CSSValueNone) { |
|
1073 |
valid_primitive = true; |
|
1074 |
} else { |
|
1075 |
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); |
|
1076 |
bool is_valid = true; |
|
1077 |
while (is_valid && value) { |
|
1078 |
switch (value->id) { |
|
1079 |
case CSSValueBlink: |
|
1080 |
break; |
|
1081 |
case CSSValueUnderline: |
|
1082 |
case CSSValueOverline: |
|
1083 |
case CSSValueLineThrough: |
|
1084 |
list->append(CSSPrimitiveValue::createIdentifier(value->id)); |
|
1085 |
break; |
|
1086 |
default: |
|
1087 |
is_valid = false; |
|
1088 |
} |
|
1089 |
value = m_valueList->next(); |
|
1090 |
} |
|
1091 |
if (list->length() && is_valid) { |
|
1092 |
parsedValue = list.release(); |
|
1093 |
m_valueList->next(); |
|
1094 |
} |
|
1095 |
} |
|
1096 |
break; |
|
1097 |
||
1098 |
case CSSPropertyZoom: // normal | reset | document | <number> | <percentage> | inherit |
|
1099 |
if (id == CSSValueNormal || id == CSSValueReset || id == CSSValueDocument) |
|
1100 |
valid_primitive = true; |
|
1101 |
else |
|
1102 |
valid_primitive = (!id && validUnit(value, FNumber | FPercent | FNonNeg, true)); |
|
1103 |
break; |
|
1104 |
||
1105 |
case CSSPropertyTableLayout: // auto | fixed | inherit |
|
1106 |
if (id == CSSValueAuto || id == CSSValueFixed) |
|
1107 |
valid_primitive = true; |
|
1108 |
break; |
|
1109 |
||
1110 |
case CSSPropertySrc: // Only used within @font-face, so cannot use inherit | initial or be !important. This is a list of urls or local references. |
|
1111 |
return parseFontFaceSrc(); |
|
1112 |
||
1113 |
case CSSPropertyUnicodeRange: |
|
1114 |
return parseFontFaceUnicodeRange(); |
|
1115 |
||
1116 |
/* CSS3 properties */ |
|
1117 |
case CSSPropertyWebkitAppearance: |
|
1118 |
if ((id >= CSSValueCheckbox && id <= CSSValueTextarea) || id == CSSValueNone) |
|
1119 |
valid_primitive = true; |
|
1120 |
break; |
|
1121 |
||
1122 |
case CSSPropertyWebkitBinding: |
|
1123 |
#if ENABLE(XBL) |
|
1124 |
if (id == CSSValueNone) |
|
1125 |
valid_primitive = true; |
|
1126 |
else { |
|
1127 |
RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated(); |
|
1128 |
CSSParserValue* val; |
|
1129 |
RefPtr<CSSValue> parsedValue; |
|
1130 |
while ((val = m_valueList->current())) { |
|
1131 |
if (val->unit == CSSPrimitiveValue::CSS_URI && m_styleSheet) { |
|
1132 |
// FIXME: The completeURL call should be done when using the CSSPrimitiveValue, |
|
1133 |
// not when creating it. |
|
1134 |
parsedValue = CSSPrimitiveValue::create(m_styleSheet->completeURL(val->string), CSSPrimitiveValue::CSS_URI); |
|
1135 |
} |
|
1136 |
if (!parsedValue) |
|
1137 |
break; |
|
1138 |
||
1139 |
// FIXME: We can't use release() here since we might hit this path twice |
|
1140 |
// but that logic seems wrong to me to begin with, we convert all non-uri values |
|
1141 |
// into the last seen URI value!? |
|
1142 |
// -webkit-binding: url(foo.xml), 1, 2; (if that were valid) is treated as: |
|
1143 |
// -webkit-binding: url(foo.xml), url(foo.xml), url(foo.xml); !? |
|
1144 |
values->append(parsedValue.get()); |
|
1145 |
m_valueList->next(); |
|
1146 |
} |
|
1147 |
if (!values->length()) |
|
1148 |
return false; |
|
1149 |
||
1150 |
addProperty(propId, values.release(), important); |
|
1151 |
m_valueList->next(); |
|
1152 |
return true; |
|
1153 |
} |
|
1154 |
#endif |
|
1155 |
break; |
|
1156 |
case CSSPropertyWebkitBorderImage: |
|
1157 |
case CSSPropertyWebkitMaskBoxImage: |
|
1158 |
if (id == CSSValueNone) |
|
1159 |
valid_primitive = true; |
|
1160 |
else { |
|
1161 |
RefPtr<CSSValue> result; |
|
1162 |
if (parseBorderImage(propId, important, result)) { |
|
1163 |
addProperty(propId, result, important); |
|
1164 |
return true; |
|
1165 |
} |
|
1166 |
} |
|
1167 |
break; |
|
1168 |
case CSSPropertyBorderTopRightRadius: |
|
1169 |
case CSSPropertyBorderTopLeftRadius: |
|
1170 |
case CSSPropertyBorderBottomLeftRadius: |
|
1171 |
case CSSPropertyBorderBottomRightRadius: { |
|
1172 |
if (num != 1 && num != 2) |
|
1173 |
return false; |
|
1174 |
valid_primitive = validUnit(value, FLength, m_strict); |
|
1175 |
if (!valid_primitive) |
|
1176 |
return false; |
|
1177 |
RefPtr<CSSPrimitiveValue> parsedValue1 = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); |
|
1178 |
RefPtr<CSSPrimitiveValue> parsedValue2; |
|
1179 |
if (num == 2) { |
|
1180 |
value = m_valueList->next(); |
|
1181 |
valid_primitive = validUnit(value, FLength, m_strict); |
|
1182 |
if (!valid_primitive) |
|
1183 |
return false; |
|
1184 |
parsedValue2 = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); |
|
1185 |
} else |
|
1186 |
parsedValue2 = parsedValue1; |
|
1187 |
||
1188 |
RefPtr<Pair> pair = Pair::create(parsedValue1.release(), parsedValue2.release()); |
|
1189 |
RefPtr<CSSPrimitiveValue> val = CSSPrimitiveValue::create(pair.release()); |
|
1190 |
addProperty(propId, val.release(), important); |
|
1191 |
return true; |
|
1192 |
} |
|
1193 |
case CSSPropertyBorderRadius: |
|
1194 |
case CSSPropertyWebkitBorderRadius: |
|
1195 |
return parseBorderRadius(propId, important); |
|
1196 |
case CSSPropertyOutlineOffset: |
|
1197 |
valid_primitive = validUnit(value, FLength, m_strict); |
|
1198 |
break; |
|
1199 |
case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3 |
|
1200 |
case CSSPropertyWebkitBoxShadow: |
|
1201 |
if (id == CSSValueNone) |
|
1202 |
valid_primitive = true; |
|
1203 |
else |
|
1204 |
return parseShadow(propId, important); |
|
1205 |
break; |
|
1206 |
case CSSPropertyWebkitBoxReflect: |
|
1207 |
if (id == CSSValueNone) |
|
1208 |
valid_primitive = true; |
|
1209 |
else |
|
1210 |
return parseReflect(propId, important); |
|
1211 |
break; |
|
1212 |
case CSSPropertyOpacity: |
|
1213 |
valid_primitive = validUnit(value, FNumber, m_strict); |
|
1214 |
break; |
|
1215 |
case CSSPropertyWebkitBoxAlign: |
|
1216 |
if (id == CSSValueStretch || id == CSSValueStart || id == CSSValueEnd || |
|
1217 |
id == CSSValueCenter || id == CSSValueBaseline) |
|
1218 |
valid_primitive = true; |
|
1219 |
break; |
|
1220 |
case CSSPropertyWebkitBoxDirection: |
|
1221 |
if (id == CSSValueNormal || id == CSSValueReverse) |
|
1222 |
valid_primitive = true; |
|
1223 |
break; |
|
1224 |
case CSSPropertyWebkitBoxLines: |
|
1225 |
if (id == CSSValueSingle || id == CSSValueMultiple) |
|
1226 |
valid_primitive = true; |
|
1227 |
break; |
|
1228 |
case CSSPropertyWebkitBoxOrient: |
|
1229 |
if (id == CSSValueHorizontal || id == CSSValueVertical || |
|
1230 |
id == CSSValueInlineAxis || id == CSSValueBlockAxis) |
|
1231 |
valid_primitive = true; |
|
1232 |
break; |
|
1233 |
case CSSPropertyWebkitBoxPack: |
|
1234 |
if (id == CSSValueStart || id == CSSValueEnd || |
|
1235 |
id == CSSValueCenter || id == CSSValueJustify) |
|
1236 |
valid_primitive = true; |
|
1237 |
break; |
|
1238 |
case CSSPropertyWebkitBoxFlex: |
|
1239 |
valid_primitive = validUnit(value, FNumber, m_strict); |
|
1240 |
break; |
|
1241 |
case CSSPropertyWebkitBoxFlexGroup: |
|
1242 |
case CSSPropertyWebkitBoxOrdinalGroup: |
|
1243 |
valid_primitive = validUnit(value, FInteger|FNonNeg, true); |
|
1244 |
break; |
|
1245 |
case CSSPropertyWebkitBoxSizing: |
|
1246 |
valid_primitive = id == CSSValueBorderBox || id == CSSValueContentBox; |
|
1247 |
break; |
|
1248 |
case CSSPropertyWebkitMarquee: { |
|
1249 |
const int properties[5] = { CSSPropertyWebkitMarqueeDirection, CSSPropertyWebkitMarqueeIncrement, |
|
1250 |
CSSPropertyWebkitMarqueeRepetition, |
|
1251 |
CSSPropertyWebkitMarqueeStyle, CSSPropertyWebkitMarqueeSpeed }; |
|
1252 |
return parseShorthand(propId, properties, 5, important); |
|
1253 |
} |
|
1254 |
case CSSPropertyWebkitMarqueeDirection: |
|
1255 |
if (id == CSSValueForwards || id == CSSValueBackwards || id == CSSValueAhead || |
|
1256 |
id == CSSValueReverse || id == CSSValueLeft || id == CSSValueRight || id == CSSValueDown || |
|
1257 |
id == CSSValueUp || id == CSSValueAuto) |
|
1258 |
valid_primitive = true; |
|
1259 |
break; |
|
1260 |
case CSSPropertyWebkitMarqueeIncrement: |
|
1261 |
if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium) |
|
1262 |
valid_primitive = true; |
|
1263 |
else |
|
1264 |
valid_primitive = validUnit(value, FLength|FPercent, m_strict); |
|
1265 |
break; |
|
1266 |
case CSSPropertyWebkitMarqueeStyle: |
|
1267 |
if (id == CSSValueNone || id == CSSValueSlide || id == CSSValueScroll || id == CSSValueAlternate) |
|
1268 |
valid_primitive = true; |
|
1269 |
break; |
|
1270 |
case CSSPropertyWebkitMarqueeRepetition: |
|
1271 |
if (id == CSSValueInfinite) |
|
1272 |
valid_primitive = true; |
|
1273 |
else |
|
1274 |
valid_primitive = validUnit(value, FInteger|FNonNeg, m_strict); |
|
1275 |
break; |
|
1276 |
case CSSPropertyWebkitMarqueeSpeed: |
|
1277 |
if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast) |
|
1278 |
valid_primitive = true; |
|
1279 |
else |
|
1280 |
valid_primitive = validUnit(value, FTime|FInteger|FNonNeg, m_strict); |
|
1281 |
break; |
|
1282 |
#if ENABLE(WCSS) |
|
1283 |
case CSSPropertyWapMarqueeDir: |
|
1284 |
if (id == CSSValueLtr || id == CSSValueRtl) |
|
1285 |
valid_primitive = true; |
|
1286 |
break; |
|
1287 |
case CSSPropertyWapMarqueeStyle: |
|
1288 |
if (id == CSSValueNone || id == CSSValueSlide || id == CSSValueScroll || id == CSSValueAlternate) |
|
1289 |
valid_primitive = true; |
|
1290 |
break; |
|
1291 |
case CSSPropertyWapMarqueeLoop: |
|
1292 |
if (id == CSSValueInfinite) |
|
1293 |
valid_primitive = true; |
|
1294 |
else |
|
1295 |
valid_primitive = validUnit(value, FInteger | FNonNeg, m_strict); |
|
1296 |
break; |
|
1297 |
case CSSPropertyWapMarqueeSpeed: |
|
1298 |
if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast) |
|
1299 |
valid_primitive = true; |
|
1300 |
else |
|
1301 |
valid_primitive = validUnit(value, FTime | FInteger | FNonNeg, m_strict); |
|
1302 |
break; |
|
1303 |
#endif |
|
1304 |
case CSSPropertyWebkitUserDrag: // auto | none | element |
|
1305 |
if (id == CSSValueAuto || id == CSSValueNone || id == CSSValueElement) |
|
1306 |
valid_primitive = true; |
|
1307 |
break; |
|
1308 |
case CSSPropertyWebkitUserModify: // read-only | read-write |
|
1309 |
if (id == CSSValueReadOnly || id == CSSValueReadWrite || id == CSSValueReadWritePlaintextOnly) |
|
1310 |
valid_primitive = true; |
|
1311 |
break; |
|
1312 |
case CSSPropertyWebkitUserSelect: // auto | none | text |
|
1313 |
if (id == CSSValueAuto || id == CSSValueNone || id == CSSValueText) |
|
1314 |
valid_primitive = true; |
|
1315 |
break; |
|
1316 |
case CSSPropertyTextOverflow: // clip | ellipsis |
|
1317 |
if (id == CSSValueClip || id == CSSValueEllipsis) |
|
1318 |
valid_primitive = true; |
|
1319 |
break; |
|
1320 |
case CSSPropertyWebkitTransform: |
|
1321 |
if (id == CSSValueNone) |
|
1322 |
valid_primitive = true; |
|
1323 |
else { |
|
1324 |
PassRefPtr<CSSValue> val = parseTransform(); |
|
1325 |
if (val) { |
|
1326 |
addProperty(propId, val, important); |
|
1327 |
return true; |
|
1328 |
} |
|
1329 |
return false; |
|
1330 |
} |
|
1331 |
break; |
|
1332 |
case CSSPropertyWebkitTransformOrigin: |
|
1333 |
case CSSPropertyWebkitTransformOriginX: |
|
1334 |
case CSSPropertyWebkitTransformOriginY: |
|
1335 |
case CSSPropertyWebkitTransformOriginZ: { |
|
1336 |
RefPtr<CSSValue> val1; |
|
1337 |
RefPtr<CSSValue> val2; |
|
1338 |
RefPtr<CSSValue> val3; |
|
1339 |
int propId1, propId2, propId3; |
|
1340 |
if (parseTransformOrigin(propId, propId1, propId2, propId3, val1, val2, val3)) { |
|
1341 |
addProperty(propId1, val1.release(), important); |
|
1342 |
if (val2) |
|
1343 |
addProperty(propId2, val2.release(), important); |
|
1344 |
if (val3) |
|
1345 |
addProperty(propId3, val3.release(), important); |
|
1346 |
return true; |
|
1347 |
} |
|
1348 |
return false; |
|
1349 |
} |
|
1350 |
case CSSPropertyWebkitTransformStyle: |
|
1351 |
if (value->id == CSSValueFlat || value->id == CSSValuePreserve3d) |
|
1352 |
valid_primitive = true; |
|
1353 |
break; |
|
1354 |
case CSSPropertyWebkitBackfaceVisibility: |
|
1355 |
if (value->id == CSSValueVisible || value->id == CSSValueHidden) |
|
1356 |
valid_primitive = true; |
|
1357 |
break; |
|
1358 |
case CSSPropertyWebkitPerspective: |
|
1359 |
if (id == CSSValueNone) |
|
1360 |
valid_primitive = true; |
|
1361 |
else { |
|
1362 |
// Accepting valueless numbers is a quirk of the -webkit prefixed version of the property. |
|
1363 |
if (validUnit(value, FNumber|FLength|FNonNeg, m_strict)) { |
|
1364 |
RefPtr<CSSValue> val = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); |
|
1365 |
if (val) { |
|
1366 |
addProperty(propId, val.release(), important); |
|
1367 |
return true; |
|
1368 |
} |
|
1369 |
return false; |
|
1370 |
} |
|
1371 |
} |
|
1372 |
break; |
|
1373 |
case CSSPropertyWebkitPerspectiveOrigin: |
|
1374 |
case CSSPropertyWebkitPerspectiveOriginX: |
|
1375 |
case CSSPropertyWebkitPerspectiveOriginY: { |
|
1376 |
RefPtr<CSSValue> val1; |
|
1377 |
RefPtr<CSSValue> val2; |
|
1378 |
int propId1, propId2; |
|
1379 |
if (parsePerspectiveOrigin(propId, propId1, propId2, val1, val2)) { |
|
1380 |
addProperty(propId1, val1.release(), important); |
|
1381 |
if (val2) |
|
1382 |
addProperty(propId2, val2.release(), important); |
|
1383 |
return true; |
|
1384 |
} |
|
1385 |
return false; |
|
1386 |
} |
|
1387 |
case CSSPropertyWebkitAnimationDelay: |
|
1388 |
case CSSPropertyWebkitAnimationDirection: |
|
1389 |
case CSSPropertyWebkitAnimationDuration: |
|
1390 |
case CSSPropertyWebkitAnimationName: |
|
1391 |
case CSSPropertyWebkitAnimationPlayState: |
|
1392 |
case CSSPropertyWebkitAnimationIterationCount: |
|
1393 |
case CSSPropertyWebkitAnimationTimingFunction: |
|
1394 |
case CSSPropertyWebkitTransitionDelay: |
|
1395 |
case CSSPropertyWebkitTransitionDuration: |
|
1396 |
case CSSPropertyWebkitTransitionTimingFunction: |
|
1397 |
case CSSPropertyWebkitTransitionProperty: { |
|
1398 |
RefPtr<CSSValue> val; |
|
1399 |
if (parseAnimationProperty(propId, val)) { |
|
1400 |
addProperty(propId, val.release(), important); |
|
1401 |
return true; |
|
1402 |
} |
|
1403 |
return false; |
|
1404 |
} |
|
1405 |
case CSSPropertyWebkitMarginCollapse: { |
|
1406 |
const int properties[2] = { CSSPropertyWebkitMarginTopCollapse, |
|
1407 |
CSSPropertyWebkitMarginBottomCollapse }; |
|
1408 |
if (num == 1) { |
|
1409 |
ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse); |
|
1410 |
if (!parseValue(properties[0], important)) |
|
1411 |
return false; |
|
1412 |
CSSValue* value = m_parsedProperties[m_numParsedProperties-1]->value(); |
|
1413 |
addProperty(properties[1], value, important); |
|
1414 |
return true; |
|
1415 |
} |
|
1416 |
else if (num == 2) { |
|
1417 |
ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse); |
|
1418 |
if (!parseValue(properties[0], important) || !parseValue(properties[1], important)) |
|
1419 |
return false; |
|
1420 |
return true; |
|
1421 |
} |
|
1422 |
return false; |
|
1423 |
} |
|
1424 |
case CSSPropertyWebkitMarginTopCollapse: |
|
1425 |
case CSSPropertyWebkitMarginBottomCollapse: |
|
1426 |
if (id == CSSValueCollapse || id == CSSValueSeparate || id == CSSValueDiscard) |
|
1427 |
valid_primitive = true; |
|
1428 |
break; |
|
1429 |
case CSSPropertyTextLineThroughMode: |
|
1430 |
case CSSPropertyTextOverlineMode: |
|
1431 |
case CSSPropertyTextUnderlineMode: |
|
1432 |
if (id == CSSValueContinuous || id == CSSValueSkipWhiteSpace) |
|
1433 |
valid_primitive = true; |
|
1434 |
break; |
|
1435 |
case CSSPropertyTextLineThroughStyle: |
|
1436 |
case CSSPropertyTextOverlineStyle: |
|
1437 |
case CSSPropertyTextUnderlineStyle: |
|
1438 |
if (id == CSSValueNone || id == CSSValueSolid || id == CSSValueDouble || |
|
1439 |
id == CSSValueDashed || id == CSSValueDotDash || id == CSSValueDotDotDash || |
|
1440 |
id == CSSValueWave) |
|
1441 |
valid_primitive = true; |
|
1442 |
break; |
|
1443 |
case CSSPropertyTextRendering: // auto | optimizeSpeed | optimizeLegibility | geometricPrecision |
|
1444 |
if (id == CSSValueAuto || id == CSSValueOptimizespeed || id == CSSValueOptimizelegibility |
|
1445 |
|| id == CSSValueGeometricprecision) |
|
1446 |
valid_primitive = true; |
|
1447 |
break; |
|
1448 |
case CSSPropertyTextLineThroughWidth: |
|
1449 |
case CSSPropertyTextOverlineWidth: |
|
1450 |
case CSSPropertyTextUnderlineWidth: |
|
1451 |
if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin || |
|
1452 |
id == CSSValueMedium || id == CSSValueThick) |
|
1453 |
valid_primitive = true; |
|
1454 |
else |
|
1455 |
valid_primitive = !id && validUnit(value, FNumber|FLength|FPercent, m_strict); |
|
1456 |
break; |
|
1457 |
case CSSPropertyResize: // none | both | horizontal | vertical | auto |
|
1458 |
if (id == CSSValueNone || id == CSSValueBoth || id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValueAuto) |
|
1459 |
valid_primitive = true; |
|
1460 |
break; |
|
1461 |
case CSSPropertyWebkitColumnCount: |
|
1462 |
if (id == CSSValueAuto) |
|
1463 |
valid_primitive = true; |
|
1464 |
else |
|
1465 |
valid_primitive = !id && validUnit(value, FInteger | FNonNeg, false); |
|
1466 |
break; |
|
1467 |
case CSSPropertyWebkitColumnGap: // normal | <length> |
|
1468 |
if (id == CSSValueNormal) |
|
1469 |
valid_primitive = true; |
|
1470 |
else |
|
1471 |
valid_primitive = validUnit(value, FLength | FNonNeg, m_strict); |
|
1472 |
break; |
|
1473 |
case CSSPropertyWebkitColumnWidth: // auto | <length> |
|
1474 |
if (id == CSSValueAuto) |
|
1475 |
valid_primitive = true; |
|
1476 |
else // Always parse this property in strict mode, since it would be ambiguous otherwise when used in the 'columns' shorthand property. |
|
1477 |
valid_primitive = validUnit(value, FLength, true); |
|
1478 |
break; |
|
1479 |
case CSSPropertyPointerEvents: |
|
1480 |
// none | visiblePainted | visibleFill | visibleStroke | visible | |
|
1481 |
// painted | fill | stroke | auto | all | inherit |
|
1482 |
if (id == CSSValueVisible || id == CSSValueNone || id == CSSValueAll || id == CSSValueAuto || |
|
1483 |
(id >= CSSValueVisiblepainted && id <= CSSValueStroke)) |
|
1484 |
valid_primitive = true; |
|
1485 |
break; |
|
1486 |
||
1487 |
// End of CSS3 properties |
|
1488 |
||
1489 |
// Apple specific properties. These will never be standardized and are purely to |
|
1490 |
// support custom WebKit-based Apple applications. |
|
1491 |
case CSSPropertyWebkitLineClamp: |
|
1492 |
valid_primitive = (!id && validUnit(value, FPercent, false)); |
|
1493 |
break; |
|
1494 |
case CSSPropertyWebkitTextSizeAdjust: |
|
1495 |
if (id == CSSValueAuto || id == CSSValueNone) |
|
1496 |
valid_primitive = true; |
|
1497 |
break; |
|
1498 |
case CSSPropertyWebkitRtlOrdering: |
|
1499 |
if (id == CSSValueLogical || id == CSSValueVisual) |
|
1500 |
valid_primitive = true; |
|
1501 |
break; |
|
1502 |
||
1503 |
case CSSPropertyWebkitFontSizeDelta: // <length> |
|
1504 |
valid_primitive = validUnit(value, FLength, m_strict); |
|
1505 |
break; |
|
1506 |
||
1507 |
case CSSPropertyWebkitNbspMode: // normal | space |
|
1508 |
if (id == CSSValueNormal || id == CSSValueSpace) |
|
1509 |
valid_primitive = true; |
|
1510 |
break; |
|
1511 |
||
1512 |
case CSSPropertyWebkitLineBreak: // normal | after-white-space |
|
1513 |
if (id == CSSValueNormal || id == CSSValueAfterWhiteSpace) |
|
1514 |
valid_primitive = true; |
|
1515 |
break; |
|
1516 |
||
1517 |
case CSSPropertyWebkitMatchNearestMailBlockquoteColor: // normal | match |
|
1518 |
if (id == CSSValueNormal || id == CSSValueMatch) |
|
1519 |
valid_primitive = true; |
|
1520 |
break; |
|
1521 |
||
1522 |
case CSSPropertyWebkitHighlight: |
|
1523 |
if (id == CSSValueNone || value->unit == CSSPrimitiveValue::CSS_STRING) |
|
1524 |
valid_primitive = true; |
|
1525 |
break; |
|
1526 |
||
1527 |
case CSSPropertyWebkitBorderFit: |
|
1528 |
if (id == CSSValueBorder || id == CSSValueLines) |
|
1529 |
valid_primitive = true; |
|
1530 |
break; |
|
1531 |
||
1532 |
case CSSPropertyWebkitTextSecurity: |
|
1533 |
// disc | circle | square | none | inherit |
|
1534 |
if (id == CSSValueDisc || id == CSSValueCircle || id == CSSValueSquare|| id == CSSValueNone) |
|
1535 |
valid_primitive = true; |
|
1536 |
break; |
|
1537 |
||
1538 |
case CSSPropertyWebkitFontSmoothing: |
|
1539 |
if (id == CSSValueAuto || id == CSSValueNone |
|
1540 |
|| id == CSSValueAntialiased || id == CSSValueSubpixelAntialiased) |
|
1541 |
valid_primitive = true; |
|
1542 |
break; |
|
1543 |
||
1544 |
#if ENABLE(DASHBOARD_SUPPORT) |
|
1545 |
case CSSPropertyWebkitDashboardRegion: // <dashboard-region> | <dashboard-region> |
|
1546 |
if (value->unit == CSSParserValue::Function || id == CSSValueNone) |
|
1547 |
return parseDashboardRegions(propId, important); |
|
1548 |
break; |
|
1549 |
#endif |
|
1550 |
// End Apple-specific properties |
|
1551 |
||
1552 |
/* shorthand properties */ |
|
1553 |
case CSSPropertyBackground: { |
|
1554 |
// Position must come before color in this array because a plain old "0" is a legal color |
|
1555 |
// in quirks mode but it's usually the X coordinate of a position. |
|
1556 |
// FIXME: Add CSSPropertyBackgroundSize to the shorthand. |
|
1557 |
const int properties[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat, |
|
1558 |
CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition, CSSPropertyBackgroundOrigin, |
|
1559 |
CSSPropertyBackgroundColor }; |
|
1560 |
return parseFillShorthand(propId, properties, 6, important); |
|
1561 |
} |
|
1562 |
case CSSPropertyWebkitMask: { |
|
1563 |
const int properties[] = { CSSPropertyWebkitMaskImage, CSSPropertyWebkitMaskRepeat, |
|
1564 |
CSSPropertyWebkitMaskAttachment, CSSPropertyWebkitMaskPosition, |
|
1565 |
CSSPropertyWebkitMaskOrigin }; |
|
1566 |
return parseFillShorthand(propId, properties, 5, important); |
|
1567 |
} |
|
1568 |
case CSSPropertyBorder: |
|
1569 |
// [ 'border-width' || 'border-style' || <color> ] | inherit |
|
1570 |
{ |
|
1571 |
const int properties[3] = { CSSPropertyBorderWidth, CSSPropertyBorderStyle, |
|
1572 |
CSSPropertyBorderColor }; |
|
1573 |
return parseShorthand(propId, properties, 3, important); |
|
1574 |
} |
|
1575 |
case CSSPropertyBorderTop: |
|
1576 |
// [ 'border-top-width' || 'border-style' || <color> ] | inherit |
|
1577 |
{ |
|
1578 |
const int properties[3] = { CSSPropertyBorderTopWidth, CSSPropertyBorderTopStyle, |
|
1579 |
CSSPropertyBorderTopColor}; |
|
1580 |
return parseShorthand(propId, properties, 3, important); |
|
1581 |
} |
|
1582 |
case CSSPropertyBorderRight: |
|
1583 |
// [ 'border-right-width' || 'border-style' || <color> ] | inherit |
|
1584 |
{ |
|
1585 |
const int properties[3] = { CSSPropertyBorderRightWidth, CSSPropertyBorderRightStyle, |
|
1586 |
CSSPropertyBorderRightColor }; |
|
1587 |
return parseShorthand(propId, properties, 3, important); |
|
1588 |
} |
|
1589 |
case CSSPropertyBorderBottom: |
|
1590 |
// [ 'border-bottom-width' || 'border-style' || <color> ] | inherit |
|
1591 |
{ |
|
1592 |
const int properties[3] = { CSSPropertyBorderBottomWidth, CSSPropertyBorderBottomStyle, |
|
1593 |
CSSPropertyBorderBottomColor }; |
|
1594 |
return parseShorthand(propId, properties, 3, important); |
|
1595 |
} |
|
1596 |
case CSSPropertyBorderLeft: |
|
1597 |
// [ 'border-left-width' || 'border-style' || <color> ] | inherit |
|
1598 |
{ |
|
1599 |
const int properties[3] = { CSSPropertyBorderLeftWidth, CSSPropertyBorderLeftStyle, |
|
1600 |
CSSPropertyBorderLeftColor }; |
|
1601 |
return parseShorthand(propId, properties, 3, important); |
|
1602 |
} |
|
1603 |
case CSSPropertyOutline: |
|
1604 |
// [ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit |
|
1605 |
{ |
|
1606 |
const int properties[3] = { CSSPropertyOutlineWidth, CSSPropertyOutlineStyle, |
|
1607 |
CSSPropertyOutlineColor }; |
|
1608 |
return parseShorthand(propId, properties, 3, important); |
|
1609 |
} |
|
1610 |
case CSSPropertyBorderColor: |
|
1611 |
// <color>{1,4} | inherit |
|
1612 |
{ |
|
1613 |
const int properties[4] = { CSSPropertyBorderTopColor, CSSPropertyBorderRightColor, |
|
1614 |
CSSPropertyBorderBottomColor, CSSPropertyBorderLeftColor }; |
|
1615 |
return parse4Values(propId, properties, important); |
|
1616 |
} |
|
1617 |
case CSSPropertyBorderWidth: |
|
1618 |
// <border-width>{1,4} | inherit |
|
1619 |
{ |
|
1620 |
const int properties[4] = { CSSPropertyBorderTopWidth, CSSPropertyBorderRightWidth, |
|
1621 |
CSSPropertyBorderBottomWidth, CSSPropertyBorderLeftWidth }; |
|
1622 |
return parse4Values(propId, properties, important); |
|
1623 |
} |
|
1624 |
case CSSPropertyBorderStyle: |
|
1625 |
// <border-style>{1,4} | inherit |
|
1626 |
{ |
|
1627 |
const int properties[4] = { CSSPropertyBorderTopStyle, CSSPropertyBorderRightStyle, |
|
1628 |
CSSPropertyBorderBottomStyle, CSSPropertyBorderLeftStyle }; |
|
1629 |
return parse4Values(propId, properties, important); |
|
1630 |
} |
|
1631 |
case CSSPropertyMargin: |
|
1632 |
// <margin-width>{1,4} | inherit |
|
1633 |
{ |
|
1634 |
const int properties[4] = { CSSPropertyMarginTop, CSSPropertyMarginRight, |
|
1635 |
CSSPropertyMarginBottom, CSSPropertyMarginLeft }; |
|
1636 |
return parse4Values(propId, properties, important); |
|
1637 |
} |
|
1638 |
case CSSPropertyPadding: |
|
1639 |
// <padding-width>{1,4} | inherit |
|
1640 |
{ |
|
1641 |
const int properties[4] = { CSSPropertyPaddingTop, CSSPropertyPaddingRight, |
|
1642 |
CSSPropertyPaddingBottom, CSSPropertyPaddingLeft }; |
|
1643 |
return parse4Values(propId, properties, important); |
|
1644 |
} |
|
1645 |
case CSSPropertyFont: |
|
1646 |
// [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? |
|
1647 |
// 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit |
|
1648 |
if (id >= CSSValueCaption && id <= CSSValueStatusBar) |
|
1649 |
valid_primitive = true; |
|
1650 |
else |
|
1651 |
return parseFont(important); |
|
1652 |
break; |
|
1653 |
case CSSPropertyListStyle: |
|
1654 |
{ |
|
1655 |
const int properties[3] = { CSSPropertyListStyleType, CSSPropertyListStylePosition, |
|
1656 |
CSSPropertyListStyleImage }; |
|
1657 |
return parseShorthand(propId, properties, 3, important); |
|
1658 |
} |
|
1659 |
case CSSPropertyWebkitColumns: { |
|
1660 |
const int properties[2] = { CSSPropertyWebkitColumnWidth, CSSPropertyWebkitColumnCount }; |
|
1661 |
return parseShorthand(propId, properties, 2, important); |
|
1662 |
} |
|
1663 |
case CSSPropertyWebkitColumnRule: { |
|
1664 |
const int properties[3] = { CSSPropertyWebkitColumnRuleWidth, CSSPropertyWebkitColumnRuleStyle, |
|
1665 |
CSSPropertyWebkitColumnRuleColor }; |
|
1666 |
return parseShorthand(propId, properties, 3, important); |
|
1667 |
} |
|
1668 |
case CSSPropertyWebkitTextStroke: { |
|
1669 |
const int properties[2] = { CSSPropertyWebkitTextStrokeWidth, CSSPropertyWebkitTextStrokeColor }; |
|
1670 |
return parseShorthand(propId, properties, 2, important); |
|
1671 |
} |
|
1672 |
case CSSPropertyWebkitAnimation: |
|
1673 |
return parseAnimationShorthand(important); |
|
1674 |
case CSSPropertyWebkitTransition: |
|
1675 |
return parseTransitionShorthand(important); |
|
1676 |
case CSSPropertyInvalid: |
|
1677 |
return false; |
|
1678 |
case CSSPropertyFontStretch: |
|
1679 |
case CSSPropertyPage: |
|
1680 |
case CSSPropertyTextLineThrough: |
|
1681 |
case CSSPropertyTextOverline: |
|
1682 |
case CSSPropertyTextUnderline: |
|
1683 |
case CSSPropertyWebkitVariableDeclarationBlock: |
|
1684 |
return false; |
|
1685 |
#if ENABLE(SVG) |
|
1686 |
default: |
|
1687 |
return parseSVGValue(propId, important); |
|
1688 |
#endif |
|
1689 |
} |
|
1690 |
||
1691 |
if (valid_primitive) { |
|
1692 |
if (id != 0) |
|
1693 |
parsedValue = CSSPrimitiveValue::createIdentifier(id); |
|
1694 |
else if (value->unit == CSSPrimitiveValue::CSS_STRING) |
|
1695 |
parsedValue = CSSPrimitiveValue::create(value->string, (CSSPrimitiveValue::UnitTypes) value->unit); |
|
1696 |
else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ) |
|
1697 |
parsedValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit); |
|
1698 |
else if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS) |
|
1699 |
parsedValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit); |
|
1700 |
else if (value->unit >= CSSParserValue::Q_EMS) |
|
1701 |
parsedValue = CSSQuirkPrimitiveValue::create(value->fValue, CSSPrimitiveValue::CSS_EMS); |
|
1702 |
m_valueList->next(); |
|
1703 |
} |
|
1704 |
if (parsedValue) { |
|
1705 |
if (!m_valueList->current() || inShorthand()) { |
|
1706 |
addProperty(propId, parsedValue.release(), important); |
|
1707 |
return true; |
|
1708 |
} |
|
1709 |
} |
|
1710 |
return false; |
|
1711 |
} |
|
1712 |
||
1713 |
void CSSParser::addFillValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval) |
|
1714 |
{ |
|
1715 |
if (lval) { |
|
1716 |
if (lval->isValueList()) |
|
1717 |
static_cast<CSSValueList*>(lval.get())->append(rval); |
|
1718 |
else { |
|
1719 |
PassRefPtr<CSSValue> oldlVal(lval.release()); |
|
1720 |
PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); |
|
1721 |
list->append(oldlVal); |
|
1722 |
list->append(rval); |
|
1723 |
lval = list; |
|
1724 |
} |
|
1725 |
} |
|
1726 |
else |
|
1727 |
lval = rval; |
|
1728 |
} |
|
1729 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1730 |
static bool parseBackgroundClip(CSSParserValue* parserValue, RefPtr<CSSValue>& cssValue) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1731 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1732 |
if (parserValue->id == CSSValueBorderBox || parserValue->id == CSSValuePaddingBox || parserValue->id == CSSValueWebkitText) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1733 |
cssValue = CSSPrimitiveValue::createIdentifier(parserValue->id); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1734 |
return true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1735 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1736 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1737 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1738 |
|
0 | 1739 |
const int cMaxFillProperties = 9; |
1740 |
||
1741 |
bool CSSParser::parseFillShorthand(int propId, const int* properties, int numProperties, bool important) |
|
1742 |
{ |
|
1743 |
ASSERT(numProperties <= cMaxFillProperties); |
|
1744 |
if (numProperties > cMaxFillProperties) |
|
1745 |
return false; |
|
1746 |
||
1747 |
ShorthandScope scope(this, propId); |
|
1748 |
||
1749 |
bool parsedProperty[cMaxFillProperties] = { false }; |
|
1750 |
RefPtr<CSSValue> values[cMaxFillProperties]; |
|
1751 |
RefPtr<CSSValue> clipValue; |
|
1752 |
RefPtr<CSSValue> positionYValue; |
|
1753 |
RefPtr<CSSValue> repeatYValue; |
|
1754 |
int i; |
|
1755 |
||
1756 |
while (m_valueList->current()) { |
|
1757 |
CSSParserValue* val = m_valueList->current(); |
|
1758 |
if (val->unit == CSSParserValue::Operator && val->iValue == ',') { |
|
1759 |
// We hit the end. Fill in all remaining values with the initial value. |
|
1760 |
m_valueList->next(); |
|
1761 |
for (i = 0; i < numProperties; ++i) { |
|
1762 |
if (properties[i] == CSSPropertyBackgroundColor && parsedProperty[i]) |
|
1763 |
// Color is not allowed except as the last item in a list for backgrounds. |
|
1764 |
// Reject the entire property. |
|
1765 |
return false; |
|
1766 |
||
1767 |
if (!parsedProperty[i] && properties[i] != CSSPropertyBackgroundColor) { |
|
1768 |
addFillValue(values[i], CSSInitialValue::createImplicit()); |
|
1769 |
if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition) |
|
1770 |
addFillValue(positionYValue, CSSInitialValue::createImplicit()); |
|
1771 |
if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat) |
|
1772 |
addFillValue(repeatYValue, CSSInitialValue::createImplicit()); |
|
1773 |
if ((properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) && !parsedProperty[i]) { |
|
1774 |
// If background-origin wasn't present, then reset background-clip also. |
|
1775 |
addFillValue(clipValue, CSSInitialValue::createImplicit()); |
|
1776 |
} |
|
1777 |
} |
|
1778 |
parsedProperty[i] = false; |
|
1779 |
} |
|
1780 |
if (!m_valueList->current()) |
|
1781 |
break; |
|
1782 |
} |
|
1783 |
||
1784 |
bool found = false; |
|
1785 |
for (i = 0; !found && i < numProperties; ++i) { |
|
1786 |
if (!parsedProperty[i]) { |
|
1787 |
RefPtr<CSSValue> val1; |
|
1788 |
RefPtr<CSSValue> val2; |
|
1789 |
int propId1, propId2; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1790 |
CSSParserValue* parserValue = m_valueList->current(); |
0 | 1791 |
if (parseFillProperty(properties[i], propId1, propId2, val1, val2)) { |
1792 |
parsedProperty[i] = found = true; |
|
1793 |
addFillValue(values[i], val1.release()); |
|
1794 |
if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition) |
|
1795 |
addFillValue(positionYValue, val2.release()); |
|
1796 |
if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat) |
|
1797 |
addFillValue(repeatYValue, val2.release()); |
|
1798 |
if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) { |
|
1799 |
// Reparse the value as a clip, and see if we succeed. |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1800 |
if (parseBackgroundClip(parserValue, val1)) |
0 | 1801 |
addFillValue(clipValue, val1.release()); // The property parsed successfully. |
1802 |
else |
|
1803 |
addFillValue(clipValue, CSSInitialValue::createImplicit()); // Some value was used for origin that is not supported by clip. Just reset clip instead. |
|
1804 |
} |
|
1805 |
} |
|
1806 |
} |
|
1807 |
} |
|
1808 |
||
1809 |
// if we didn't find at least one match, this is an |
|
1810 |
// invalid shorthand and we have to ignore it |
|
1811 |
if (!found) |
|
1812 |
return false; |
|
1813 |
} |
|
1814 |
||
1815 |
// Fill in any remaining properties with the initial value. |
|
1816 |
for (i = 0; i < numProperties; ++i) { |
|
1817 |
if (!parsedProperty[i]) { |
|
1818 |
addFillValue(values[i], CSSInitialValue::createImplicit()); |
|
1819 |
if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition) |
|
1820 |
addFillValue(positionYValue, CSSInitialValue::createImplicit()); |
|
1821 |
if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat) |
|
1822 |
addFillValue(repeatYValue, CSSInitialValue::createImplicit()); |
|
1823 |
if ((properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) && !parsedProperty[i]) { |
|
1824 |
// If background-origin wasn't present, then reset background-clip also. |
|
1825 |
addFillValue(clipValue, CSSInitialValue::createImplicit()); |
|
1826 |
} |
|
1827 |
} |
|
1828 |
} |
|
1829 |
||
1830 |
// Now add all of the properties we found. |
|
1831 |
for (i = 0; i < numProperties; i++) { |
|
1832 |
if (properties[i] == CSSPropertyBackgroundPosition) { |
|
1833 |
addProperty(CSSPropertyBackgroundPositionX, values[i].release(), important); |
|
1834 |
// it's OK to call positionYValue.release() since we only see CSSPropertyBackgroundPosition once |
|
1835 |
addProperty(CSSPropertyBackgroundPositionY, positionYValue.release(), important); |
|
1836 |
} else if (properties[i] == CSSPropertyWebkitMaskPosition) { |
|
1837 |
addProperty(CSSPropertyWebkitMaskPositionX, values[i].release(), important); |
|
1838 |
// it's OK to call positionYValue.release() since we only see CSSPropertyWebkitMaskPosition once |
|
1839 |
addProperty(CSSPropertyWebkitMaskPositionY, positionYValue.release(), important); |
|
1840 |
} else if (properties[i] == CSSPropertyBackgroundRepeat) { |
|
1841 |
addProperty(CSSPropertyBackgroundRepeatX, values[i].release(), important); |
|
1842 |
// it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once |
|
1843 |
addProperty(CSSPropertyBackgroundRepeatY, repeatYValue.release(), important); |
|
1844 |
} else if (properties[i] == CSSPropertyWebkitMaskRepeat) { |
|
1845 |
addProperty(CSSPropertyWebkitMaskRepeatX, values[i].release(), important); |
|
1846 |
// it's OK to call repeatYValue.release() since we only see CSSPropertyBackgroundPosition once |
|
1847 |
addProperty(CSSPropertyWebkitMaskRepeatY, repeatYValue.release(), important); |
|
1848 |
} else |
|
1849 |
addProperty(properties[i], values[i].release(), important); |
|
1850 |
||
1851 |
// Add in clip values when we hit the corresponding origin property. |
|
1852 |
if (properties[i] == CSSPropertyBackgroundOrigin) |
|
1853 |
addProperty(CSSPropertyBackgroundClip, clipValue.release(), important); |
|
1854 |
else if (properties[i] == CSSPropertyWebkitMaskOrigin) |
|
1855 |
addProperty(CSSPropertyWebkitMaskClip, clipValue.release(), important); |
|
1856 |
} |
|
1857 |
||
1858 |
return true; |
|
1859 |
} |
|
1860 |
||
1861 |
void CSSParser::addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval) |
|
1862 |
{ |
|
1863 |
if (lval) { |
|
1864 |
if (lval->isValueList()) |
|
1865 |
static_cast<CSSValueList*>(lval.get())->append(rval); |
|
1866 |
else { |
|
1867 |
PassRefPtr<CSSValue> oldVal(lval.release()); |
|
1868 |
PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); |
|
1869 |
list->append(oldVal); |
|
1870 |
list->append(rval); |
|
1871 |
lval = list; |
|
1872 |
} |
|
1873 |
} |
|
1874 |
else |
|
1875 |
lval = rval; |
|
1876 |
} |
|
1877 |
||
1878 |
bool CSSParser::parseAnimationShorthand(bool important) |
|
1879 |
{ |
|
1880 |
const int properties[] = { CSSPropertyWebkitAnimationName, |
|
1881 |
CSSPropertyWebkitAnimationDuration, |
|
1882 |
CSSPropertyWebkitAnimationTimingFunction, |
|
1883 |
CSSPropertyWebkitAnimationDelay, |
|
1884 |
CSSPropertyWebkitAnimationIterationCount, |
|
1885 |
CSSPropertyWebkitAnimationDirection }; |
|
1886 |
const int numProperties = sizeof(properties) / sizeof(properties[0]); |
|
1887 |
||
1888 |
ShorthandScope scope(this, CSSPropertyWebkitAnimation); |
|
1889 |
||
1890 |
bool parsedProperty[numProperties] = { false }; // compiler will repeat false as necessary |
|
1891 |
RefPtr<CSSValue> values[numProperties]; |
|
1892 |
||
1893 |
int i; |
|
1894 |
while (m_valueList->current()) { |
|
1895 |
CSSParserValue* val = m_valueList->current(); |
|
1896 |
if (val->unit == CSSParserValue::Operator && val->iValue == ',') { |
|
1897 |
// We hit the end. Fill in all remaining values with the initial value. |
|
1898 |
m_valueList->next(); |
|
1899 |
for (i = 0; i < numProperties; ++i) { |
|
1900 |
if (!parsedProperty[i]) |
|
1901 |
addAnimationValue(values[i], CSSInitialValue::createImplicit()); |
|
1902 |
parsedProperty[i] = false; |
|
1903 |
} |
|
1904 |
if (!m_valueList->current()) |
|
1905 |
break; |
|
1906 |
} |
|
1907 |
||
1908 |
bool found = false; |
|
1909 |
for (i = 0; !found && i < numProperties; ++i) { |
|
1910 |
if (!parsedProperty[i]) { |
|
1911 |
RefPtr<CSSValue> val; |
|
1912 |
if (parseAnimationProperty(properties[i], val)) { |
|
1913 |
parsedProperty[i] = found = true; |
|
1914 |
addAnimationValue(values[i], val.release()); |
|
1915 |
} |
|
1916 |
} |
|
1917 |
} |
|
1918 |
||
1919 |
// if we didn't find at least one match, this is an |
|
1920 |
// invalid shorthand and we have to ignore it |
|
1921 |
if (!found) |
|
1922 |
return false; |
|
1923 |
} |
|
1924 |
||
1925 |
// Fill in any remaining properties with the initial value. |
|
1926 |
for (i = 0; i < numProperties; ++i) { |
|
1927 |
if (!parsedProperty[i]) |
|
1928 |
addAnimationValue(values[i], CSSInitialValue::createImplicit()); |
|
1929 |
} |
|
1930 |
||
1931 |
// Now add all of the properties we found. |
|
1932 |
for (i = 0; i < numProperties; i++) |
|
1933 |
addProperty(properties[i], values[i].release(), important); |
|
1934 |
||
1935 |
return true; |
|
1936 |
} |
|
1937 |
||
1938 |
bool CSSParser::parseTransitionShorthand(bool important) |
|
1939 |
{ |
|
1940 |
const int properties[] = { CSSPropertyWebkitTransitionProperty, |
|
1941 |
CSSPropertyWebkitTransitionDuration, |
|
1942 |
CSSPropertyWebkitTransitionTimingFunction, |
|
1943 |
CSSPropertyWebkitTransitionDelay }; |
|
1944 |
const int numProperties = sizeof(properties) / sizeof(properties[0]); |
|
1945 |
||
1946 |
ShorthandScope scope(this, CSSPropertyWebkitTransition); |
|
1947 |
||
1948 |
bool parsedProperty[numProperties] = { false }; // compiler will repeat false as necessary |
|
1949 |
RefPtr<CSSValue> values[numProperties]; |
|
1950 |
||
1951 |
int i; |
|
1952 |
while (m_valueList->current()) { |
|
1953 |
CSSParserValue* val = m_valueList->current(); |
|
1954 |
if (val->unit == CSSParserValue::Operator && val->iValue == ',') { |
|
1955 |
// We hit the end. Fill in all remaining values with the initial value. |
|
1956 |
m_valueList->next(); |
|
1957 |
for (i = 0; i < numProperties; ++i) { |
|
1958 |
if (!parsedProperty[i]) |
|
1959 |
addAnimationValue(values[i], CSSInitialValue::createImplicit()); |
|
1960 |
parsedProperty[i] = false; |
|
1961 |
} |
|
1962 |
if (!m_valueList->current()) |
|
1963 |
break; |
|
1964 |
} |
|
1965 |
||
1966 |
bool found = false; |
|
1967 |
for (i = 0; !found && i < numProperties; ++i) { |
|
1968 |
if (!parsedProperty[i]) { |
|
1969 |
RefPtr<CSSValue> val; |
|
1970 |
if (parseAnimationProperty(properties[i], val)) { |
|
1971 |
parsedProperty[i] = found = true; |
|
1972 |
addAnimationValue(values[i], val.release()); |
|
1973 |
} |
|
1974 |
} |
|
1975 |
} |
|
1976 |
||
1977 |
// if we didn't find at least one match, this is an |
|
1978 |
// invalid shorthand and we have to ignore it |
|
1979 |
if (!found) |
|
1980 |
return false; |
|
1981 |
} |
|
1982 |
||
1983 |
// Fill in any remaining properties with the initial value. |
|
1984 |
for (i = 0; i < numProperties; ++i) { |
|
1985 |
if (!parsedProperty[i]) |
|
1986 |
addAnimationValue(values[i], CSSInitialValue::createImplicit()); |
|
1987 |
} |
|
1988 |
||
1989 |
// Now add all of the properties we found. |
|
1990 |
for (i = 0; i < numProperties; i++) |
|
1991 |
addProperty(properties[i], values[i].release(), important); |
|
1992 |
||
1993 |
return true; |
|
1994 |
} |
|
1995 |
||
1996 |
bool CSSParser::parseShorthand(int propId, const int *properties, int numProperties, bool important) |
|
1997 |
{ |
|
1998 |
// We try to match as many properties as possible |
|
1999 |
// We set up an array of booleans to mark which property has been found, |
|
2000 |
// and we try to search for properties until it makes no longer any sense. |
|
2001 |
ShorthandScope scope(this, propId); |
|
2002 |
||
2003 |
bool found = false; |
|
2004 |
bool fnd[6]; // Trust me ;) |
|
2005 |
for (int i = 0; i < numProperties; i++) |
|
2006 |
fnd[i] = false; |
|
2007 |
||
2008 |
while (m_valueList->current()) { |
|
2009 |
found = false; |
|
2010 |
for (int propIndex = 0; !found && propIndex < numProperties; ++propIndex) { |
|
2011 |
if (!fnd[propIndex]) { |
|
2012 |
if (parseValue(properties[propIndex], important)) |
|
2013 |
fnd[propIndex] = found = true; |
|
2014 |
} |
|
2015 |
} |
|
2016 |
||
2017 |
// if we didn't find at least one match, this is an |
|
2018 |
// invalid shorthand and we have to ignore it |
|
2019 |
if (!found) |
|
2020 |
return false; |
|
2021 |
} |
|
2022 |
||
2023 |
// Fill in any remaining properties with the initial value. |
|
2024 |
m_implicitShorthand = true; |
|
2025 |
for (int i = 0; i < numProperties; ++i) { |
|
2026 |
if (!fnd[i]) |
|
2027 |
addProperty(properties[i], CSSInitialValue::createImplicit(), important); |
|
2028 |
} |
|
2029 |
m_implicitShorthand = false; |
|
2030 |
||
2031 |
return true; |
|
2032 |
} |
|
2033 |
||
2034 |
bool CSSParser::parse4Values(int propId, const int *properties, bool important) |
|
2035 |
{ |
|
2036 |
/* From the CSS 2 specs, 8.3 |
|
2037 |
* If there is only one value, it applies to all sides. If there are two values, the top and |
|
2038 |
* bottom margins are set to the first value and the right and left margins are set to the second. |
|
2039 |
* If there are three values, the top is set to the first value, the left and right are set to the |
|
2040 |
* second, and the bottom is set to the third. If there are four values, they apply to the top, |
|
2041 |
* right, bottom, and left, respectively. |
|
2042 |
*/ |
|
2043 |
||
2044 |
int num = inShorthand() ? 1 : m_valueList->size(); |
|
2045 |
||
2046 |
ShorthandScope scope(this, propId); |
|
2047 |
||
2048 |
// the order is top, right, bottom, left |
|
2049 |
switch (num) { |
|
2050 |
case 1: { |
|
2051 |
if (!parseValue(properties[0], important)) |
|
2052 |
return false; |
|
2053 |
CSSValue *value = m_parsedProperties[m_numParsedProperties-1]->value(); |
|
2054 |
m_implicitShorthand = true; |
|
2055 |
addProperty(properties[1], value, important); |
|
2056 |
addProperty(properties[2], value, important); |
|
2057 |
addProperty(properties[3], value, important); |
|
2058 |
m_implicitShorthand = false; |
|
2059 |
break; |
|
2060 |
} |
|
2061 |
case 2: { |
|
2062 |
if (!parseValue(properties[0], important) || !parseValue(properties[1], important)) |
|
2063 |
return false; |
|
2064 |
CSSValue *value = m_parsedProperties[m_numParsedProperties-2]->value(); |
|
2065 |
m_implicitShorthand = true; |
|
2066 |
addProperty(properties[2], value, important); |
|
2067 |
value = m_parsedProperties[m_numParsedProperties-2]->value(); |
|
2068 |
addProperty(properties[3], value, important); |
|
2069 |
m_implicitShorthand = false; |
|
2070 |
break; |
|
2071 |
} |
|
2072 |
case 3: { |
|
2073 |
if (!parseValue(properties[0], important) || !parseValue(properties[1], important) || !parseValue(properties[2], important)) |
|
2074 |
return false; |
|
2075 |
CSSValue *value = m_parsedProperties[m_numParsedProperties-2]->value(); |
|
2076 |
m_implicitShorthand = true; |
|
2077 |
addProperty(properties[3], value, important); |
|
2078 |
m_implicitShorthand = false; |
|
2079 |
break; |
|
2080 |
} |
|
2081 |
case 4: { |
|
2082 |
if (!parseValue(properties[0], important) || !parseValue(properties[1], important) || |
|
2083 |
!parseValue(properties[2], important) || !parseValue(properties[3], important)) |
|
2084 |
return false; |
|
2085 |
break; |
|
2086 |
} |
|
2087 |
default: { |
|
2088 |
return false; |
|
2089 |
} |
|
2090 |
} |
|
2091 |
||
2092 |
return true; |
|
2093 |
} |
|
2094 |
||
2095 |
// [ <string> | <uri> | <counter> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit |
|
2096 |
// in CSS 2.1 this got somewhat reduced: |
|
2097 |
// [ <string> | attr(X) | open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit |
|
2098 |
bool CSSParser::parseContent(int propId, bool important) |
|
2099 |
{ |
|
2100 |
RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated(); |
|
2101 |
||
2102 |
while (CSSParserValue* val = m_valueList->current()) { |
|
2103 |
RefPtr<CSSValue> parsedValue; |
|
2104 |
if (val->unit == CSSPrimitiveValue::CSS_URI && m_styleSheet) { |
|
2105 |
// url |
|
2106 |
// FIXME: The completeURL call should be done when using the CSSImageValue, |
|
2107 |
// not when creating it. |
|
2108 |
parsedValue = CSSImageValue::create(m_styleSheet->completeURL(val->string)); |
|
2109 |
} else if (val->unit == CSSParserValue::Function) { |
|
2110 |
// attr(X) | counter(X [,Y]) | counters(X, Y, [,Z]) | -webkit-gradient(...) |
|
2111 |
CSSParserValueList* args = val->function->args; |
|
2112 |
if (!args) |
|
2113 |
return false; |
|
2114 |
if (equalIgnoringCase(val->function->name, "attr(")) { |
|
2115 |
parsedValue = parseAttr(args); |
|
2116 |
if (!parsedValue) |
|
2117 |
return false; |
|
2118 |
} else if (equalIgnoringCase(val->function->name, "counter(")) { |
|
2119 |
parsedValue = parseCounterContent(args, false); |
|
2120 |
if (!parsedValue) |
|
2121 |
return false; |
|
2122 |
} else if (equalIgnoringCase(val->function->name, "counters(")) { |
|
2123 |
parsedValue = parseCounterContent(args, true); |
|
2124 |
if (!parsedValue) |
|
2125 |
return false; |
|
2126 |
} else if (equalIgnoringCase(val->function->name, "-webkit-gradient(")) { |
|
2127 |
if (!parseGradient(parsedValue)) |
|
2128 |
return false; |
|
2129 |
} else if (equalIgnoringCase(val->function->name, "-webkit-canvas(")) { |
|
2130 |
if (!parseCanvas(parsedValue)) |
|
2131 |
return false; |
|
2132 |
} else |
|
2133 |
return false; |
|
2134 |
} else if (val->unit == CSSPrimitiveValue::CSS_IDENT) { |
|
2135 |
// open-quote |
|
2136 |
// close-quote |
|
2137 |
// no-open-quote |
|
2138 |
// no-close-quote |
|
2139 |
// FIXME: These are not yet implemented (http://bugs.webkit.org/show_bug.cgi?id=6503). |
|
2140 |
} else if (val->unit == CSSPrimitiveValue::CSS_STRING) { |
|
2141 |
parsedValue = CSSPrimitiveValue::create(val->string, CSSPrimitiveValue::CSS_STRING); |
|
2142 |
} |
|
2143 |
if (!parsedValue) |
|
2144 |
break; |
|
2145 |
values->append(parsedValue.release()); |
|
2146 |
m_valueList->next(); |
|
2147 |
} |
|
2148 |
||
2149 |
if (values->length()) { |
|
2150 |
addProperty(propId, values.release(), important); |
|
2151 |
m_valueList->next(); |
|
2152 |
return true; |
|
2153 |
} |
|
2154 |
||
2155 |
return false; |
|
2156 |
} |
|
2157 |
||
2158 |
PassRefPtr<CSSValue> CSSParser::parseAttr(CSSParserValueList* args) |
|
2159 |
{ |
|
2160 |
if (args->size() != 1) |
|
2161 |
return 0; |
|
2162 |
||
2163 |
CSSParserValue* a = args->current(); |
|
2164 |
||
2165 |
if (a->unit != CSSPrimitiveValue::CSS_IDENT) |
|
2166 |
return 0; |
|
2167 |
||
2168 |
String attrName = a->string; |
|
2169 |
// CSS allows identifiers with "-" at the start, like "-webkit-mask-image". |
|
2170 |
// But HTML attribute names can't have those characters, and we should not |
|
2171 |
// even parse them inside attr(). |
|
2172 |
if (attrName[0] == '-') |
|
2173 |
return 0; |
|
2174 |
||
2175 |
if (document() && document()->isHTMLDocument()) |
|
2176 |
attrName = attrName.lower(); |
|
2177 |
||
2178 |
return CSSPrimitiveValue::create(attrName, CSSPrimitiveValue::CSS_ATTR); |
|
2179 |
} |
|
2180 |
||
2181 |
PassRefPtr<CSSValue> CSSParser::parseBackgroundColor() |
|
2182 |
{ |
|
2183 |
int id = m_valueList->current()->id; |
|
2184 |
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu || id == CSSValueCurrentcolor || |
|
2185 |
(id >= CSSValueGrey && id < CSSValueWebkitText && !m_strict)) |
|
2186 |
return CSSPrimitiveValue::createIdentifier(id); |
|
2187 |
return parseColor(); |
|
2188 |
} |
|
2189 |
||
2190 |
bool CSSParser::parseFillImage(RefPtr<CSSValue>& value) |
|
2191 |
{ |
|
2192 |
if (m_valueList->current()->id == CSSValueNone) { |
|
2193 |
value = CSSImageValue::create(); |
|
2194 |
return true; |
|
2195 |
} |
|
2196 |
if (m_valueList->current()->unit == CSSPrimitiveValue::CSS_URI) { |
|
2197 |
// FIXME: The completeURL call should be done when using the CSSImageValue, |
|
2198 |
// not when creating it. |
|
2199 |
if (m_styleSheet) |
|
2200 |
value = CSSImageValue::create(m_styleSheet->completeURL(m_valueList->current()->string)); |
|
2201 |
return true; |
|
2202 |
} |
|
2203 |
||
2204 |
if (m_valueList->current()->unit == CSSParserValue::Function) { |
|
2205 |
if (equalIgnoringCase(m_valueList->current()->function->name, "-webkit-gradient(")) |
|
2206 |
return parseGradient(value); |
|
2207 |
if (equalIgnoringCase(m_valueList->current()->function->name, "-webkit-canvas(")) |
|
2208 |
return parseCanvas(value); |
|
2209 |
} |
|
2210 |
||
2211 |
return false; |
|
2212 |
} |
|
2213 |
||
2214 |
PassRefPtr<CSSValue> CSSParser::parseFillPositionXY(bool& xFound, bool& yFound) |
|
2215 |
{ |
|
2216 |
int id = m_valueList->current()->id; |
|
2217 |
if (id == CSSValueLeft || id == CSSValueTop || id == CSSValueRight || id == CSSValueBottom || id == CSSValueCenter) { |
|
2218 |
int percent = 0; |
|
2219 |
if (id == CSSValueLeft || id == CSSValueRight) { |
|
2220 |
if (xFound) |
|
2221 |
return 0; |
|
2222 |
xFound = true; |
|
2223 |
if (id == CSSValueRight) |
|
2224 |
percent = 100; |
|
2225 |
} |
|
2226 |
else if (id == CSSValueTop || id == CSSValueBottom) { |
|
2227 |
if (yFound) |
|
2228 |
return 0; |
|
2229 |
yFound = true; |
|
2230 |
if (id == CSSValueBottom) |
|
2231 |
percent = 100; |
|
2232 |
} |
|
2233 |
else if (id == CSSValueCenter) |
|
2234 |
// Center is ambiguous, so we're not sure which position we've found yet, an x or a y. |
|
2235 |
percent = 50; |
|
2236 |
return CSSPrimitiveValue::create(percent, CSSPrimitiveValue::CSS_PERCENTAGE); |
|
2237 |
} |
|
2238 |
if (validUnit(m_valueList->current(), FPercent|FLength, m_strict)) |
|
2239 |
return CSSPrimitiveValue::create(m_valueList->current()->fValue, |
|
2240 |
(CSSPrimitiveValue::UnitTypes)m_valueList->current()->unit); |
|
2241 |
||
2242 |
return 0; |
|
2243 |
} |
|
2244 |
||
2245 |
void CSSParser::parseFillPosition(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2) |
|
2246 |
{ |
|
2247 |
CSSParserValue* value = m_valueList->current(); |
|
2248 |
||
2249 |
// Parse the first value. We're just making sure that it is one of the valid keywords or a percentage/length. |
|
2250 |
bool value1IsX = false, value1IsY = false; |
|
2251 |
value1 = parseFillPositionXY(value1IsX, value1IsY); |
|
2252 |
if (!value1) |
|
2253 |
return; |
|
2254 |
||
2255 |
// It only takes one value for background-position to be correctly parsed if it was specified in a shorthand (since we |
|
2256 |
// can assume that any other values belong to the rest of the shorthand). If we're not parsing a shorthand, though, the |
|
2257 |
// value was explicitly specified for our property. |
|
2258 |
value = m_valueList->next(); |
|
2259 |
||
2260 |
// First check for the comma. If so, we are finished parsing this value or value pair. |
|
2261 |
if (value && value->unit == CSSParserValue::Operator && value->iValue == ',') |
|
2262 |
value = 0; |
|
2263 |
||
2264 |
bool value2IsX = false, value2IsY = false; |
|
2265 |
if (value) { |
|
2266 |
value2 = parseFillPositionXY(value2IsX, value2IsY); |
|
2267 |
if (value2) |
|
2268 |
m_valueList->next(); |
|
2269 |
else { |
|
2270 |
if (!inShorthand()) { |
|
2271 |
value1.clear(); |
|
2272 |
return; |
|
2273 |
} |
|
2274 |
} |
|
2275 |
} |
|
2276 |
||
2277 |
if (!value2) |
|
2278 |
// Only one value was specified. If that value was not a keyword, then it sets the x position, and the y position |
|
2279 |
// is simply 50%. This is our default. |
|
2280 |
// For keywords, the keyword was either an x-keyword (left/right), a y-keyword (top/bottom), or an ambiguous keyword (center). |
|
2281 |
// For left/right/center, the default of 50% in the y is still correct. |
|
2282 |
value2 = CSSPrimitiveValue::create(50, CSSPrimitiveValue::CSS_PERCENTAGE); |
|
2283 |
||
2284 |
if (value1IsY || value2IsX) |
|
2285 |
value1.swap(value2); |
|
2286 |
} |
|
2287 |
||
2288 |
void CSSParser::parseFillRepeat(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2) |
|
2289 |
{ |
|
2290 |
CSSParserValue* value = m_valueList->current(); |
|
2291 |
||
2292 |
int id = m_valueList->current()->id; |
|
2293 |
if (id == CSSValueRepeatX) { |
|
2294 |
m_implicitShorthand = true; |
|
2295 |
value1 = CSSPrimitiveValue::createIdentifier(CSSValueRepeat); |
|
2296 |
value2 = CSSPrimitiveValue::createIdentifier(CSSValueNoRepeat); |
|
2297 |
m_valueList->next(); |
|
2298 |
return; |
|
2299 |
} |
|
2300 |
if (id == CSSValueRepeatY) { |
|
2301 |
m_implicitShorthand = true; |
|
2302 |
value1 = CSSPrimitiveValue::createIdentifier(CSSValueNoRepeat); |
|
2303 |
value2 = CSSPrimitiveValue::createIdentifier(CSSValueRepeat); |
|
2304 |
m_valueList->next(); |
|
2305 |
return; |
|
2306 |
} |
|
2307 |
if (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRound || id == CSSValueSpace) |
|
2308 |
value1 = CSSPrimitiveValue::createIdentifier(id); |
|
2309 |
else { |
|
2310 |
value1 = 0; |
|
2311 |
return; |
|
2312 |
} |
|
2313 |
||
2314 |
value = m_valueList->next(); |
|
2315 |
||
2316 |
// First check for the comma. If so, we are finished parsing this value or value pair. |
|
2317 |
if (value && value->unit == CSSParserValue::Operator && value->iValue == ',') |
|
2318 |
value = 0; |
|
2319 |
||
2320 |
if (value) |
|
2321 |
id = m_valueList->current()->id; |
|
2322 |
||
2323 |
if (value && (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRound || id == CSSValueSpace)) { |
|
2324 |
value2 = CSSPrimitiveValue::createIdentifier(id); |
|
2325 |
m_valueList->next(); |
|
2326 |
} else { |
|
2327 |
// If only one value was specified, value2 is the same as value1. |
|
2328 |
m_implicitShorthand = true; |
|
2329 |
value2 = CSSPrimitiveValue::createIdentifier(static_cast<CSSPrimitiveValue*>(value1.get())->getIdent()); |
|
2330 |
} |
|
2331 |
} |
|
2332 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2333 |
PassRefPtr<CSSValue> CSSParser::parseFillSize(int propId, bool& allowComma) |
0 | 2334 |
{ |
2335 |
allowComma = true; |
|
2336 |
CSSParserValue* value = m_valueList->current(); |
|
2337 |
||
2338 |
if (value->id == CSSValueContain || value->id == CSSValueCover) |
|
2339 |
return CSSPrimitiveValue::createIdentifier(value->id); |
|
2340 |
||
2341 |
RefPtr<CSSPrimitiveValue> parsedValue1; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2342 |
|
0 | 2343 |
if (value->id == CSSValueAuto) |
2344 |
parsedValue1 = CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_UNKNOWN); |
|
2345 |
else { |
|
2346 |
if (!validUnit(value, FLength|FPercent, m_strict)) |
|
2347 |
return 0; |
|
2348 |
parsedValue1 = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); |
|
2349 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2350 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2351 |
CSSPropertyID property = static_cast<CSSPropertyID>(propId); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2352 |
RefPtr<CSSPrimitiveValue> parsedValue2; |
0 | 2353 |
if ((value = m_valueList->next())) { |
2354 |
if (value->id == CSSValueAuto) |
|
2355 |
parsedValue2 = CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_UNKNOWN); |
|
2356 |
else if (value->unit == CSSParserValue::Operator && value->iValue == ',') |
|
2357 |
allowComma = false; |
|
2358 |
else { |
|
2359 |
if (!validUnit(value, FLength|FPercent, m_strict)) |
|
2360 |
return 0; |
|
2361 |
parsedValue2 = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); |
|
2362 |
} |
|
2363 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2364 |
if (!parsedValue2) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2365 |
if (property == CSSPropertyWebkitBackgroundSize || property == CSSPropertyWebkitMaskSize) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2366 |
parsedValue2 = parsedValue1; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2367 |
else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2368 |
parsedValue2 = CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_UNKNOWN); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2369 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2370 |
|
0 | 2371 |
return CSSPrimitiveValue::create(Pair::create(parsedValue1.release(), parsedValue2.release())); |
2372 |
} |
|
2373 |
||
2374 |
bool CSSParser::parseFillProperty(int propId, int& propId1, int& propId2, |
|
2375 |
RefPtr<CSSValue>& retValue1, RefPtr<CSSValue>& retValue2) |
|
2376 |
{ |
|
2377 |
RefPtr<CSSValueList> values; |
|
2378 |
RefPtr<CSSValueList> values2; |
|
2379 |
CSSParserValue* val; |
|
2380 |
RefPtr<CSSValue> value; |
|
2381 |
RefPtr<CSSValue> value2; |
|
2382 |
||
2383 |
bool allowComma = false; |
|
2384 |
||
2385 |
retValue1 = retValue2 = 0; |
|
2386 |
propId1 = propId; |
|
2387 |
propId2 = propId; |
|
2388 |
if (propId == CSSPropertyBackgroundPosition) { |
|
2389 |
propId1 = CSSPropertyBackgroundPositionX; |
|
2390 |
propId2 = CSSPropertyBackgroundPositionY; |
|
2391 |
} else if (propId == CSSPropertyWebkitMaskPosition) { |
|
2392 |
propId1 = CSSPropertyWebkitMaskPositionX; |
|
2393 |
propId2 = CSSPropertyWebkitMaskPositionY; |
|
2394 |
} else if (propId == CSSPropertyBackgroundRepeat) { |
|
2395 |
propId1 = CSSPropertyBackgroundRepeatX; |
|
2396 |
propId2 = CSSPropertyBackgroundRepeatY; |
|
2397 |
} else if (propId == CSSPropertyWebkitMaskRepeat) { |
|
2398 |
propId1 = CSSPropertyWebkitMaskRepeatX; |
|
2399 |
propId2 = CSSPropertyWebkitMaskRepeatY; |
|
2400 |
} |
|
2401 |
||
2402 |
while ((val = m_valueList->current())) { |
|
2403 |
RefPtr<CSSValue> currValue; |
|
2404 |
RefPtr<CSSValue> currValue2; |
|
2405 |
||
2406 |
if (allowComma) { |
|
2407 |
if (val->unit != CSSParserValue::Operator || val->iValue != ',') |
|
2408 |
return false; |
|
2409 |
m_valueList->next(); |
|
2410 |
allowComma = false; |
|
2411 |
} else { |
|
2412 |
allowComma = true; |
|
2413 |
switch (propId) { |
|
2414 |
case CSSPropertyBackgroundColor: |
|
2415 |
currValue = parseBackgroundColor(); |
|
2416 |
if (currValue) |
|
2417 |
m_valueList->next(); |
|
2418 |
break; |
|
2419 |
case CSSPropertyBackgroundAttachment: |
|
2420 |
case CSSPropertyWebkitMaskAttachment: |
|
2421 |
if (val->id == CSSValueScroll || val->id == CSSValueFixed || val->id == CSSValueLocal) { |
|
2422 |
currValue = CSSPrimitiveValue::createIdentifier(val->id); |
|
2423 |
m_valueList->next(); |
|
2424 |
} |
|
2425 |
break; |
|
2426 |
case CSSPropertyBackgroundImage: |
|
2427 |
case CSSPropertyWebkitMaskImage: |
|
2428 |
if (parseFillImage(currValue)) |
|
2429 |
m_valueList->next(); |
|
2430 |
break; |
|
2431 |
case CSSPropertyWebkitBackgroundClip: |
|
2432 |
case CSSPropertyWebkitBackgroundOrigin: |
|
2433 |
case CSSPropertyWebkitMaskClip: |
|
2434 |
case CSSPropertyWebkitMaskOrigin: |
|
2435 |
// The first three values here are deprecated and do not apply to the version of the property that has |
|
2436 |
// the -webkit- prefix removed. |
|
2437 |
if (val->id == CSSValueBorder || val->id == CSSValuePadding || val->id == CSSValueContent || |
|
2438 |
val->id == CSSValueBorderBox || val->id == CSSValuePaddingBox || val->id == CSSValueContentBox || |
|
2439 |
((propId == CSSPropertyWebkitBackgroundClip || propId == CSSPropertyWebkitMaskClip) && |
|
2440 |
(val->id == CSSValueText || val->id == CSSValueWebkitText))) { |
|
2441 |
currValue = CSSPrimitiveValue::createIdentifier(val->id); |
|
2442 |
m_valueList->next(); |
|
2443 |
} |
|
2444 |
break; |
|
2445 |
case CSSPropertyBackgroundClip: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2446 |
if (parseBackgroundClip(val, currValue)) |
0 | 2447 |
m_valueList->next(); |
2448 |
break; |
|
2449 |
case CSSPropertyBackgroundOrigin: |
|
2450 |
if (val->id == CSSValueBorderBox || val->id == CSSValuePaddingBox || val->id == CSSValueContentBox) { |
|
2451 |
currValue = CSSPrimitiveValue::createIdentifier(val->id); |
|
2452 |
m_valueList->next(); |
|
2453 |
} |
|
2454 |
break; |
|
2455 |
case CSSPropertyBackgroundPosition: |
|
2456 |
case CSSPropertyWebkitMaskPosition: |
|
2457 |
parseFillPosition(currValue, currValue2); |
|
2458 |
// parseFillPosition advances the m_valueList pointer |
|
2459 |
break; |
|
2460 |
case CSSPropertyBackgroundPositionX: |
|
2461 |
case CSSPropertyWebkitMaskPositionX: { |
|
2462 |
bool xFound = false, yFound = true; |
|
2463 |
currValue = parseFillPositionXY(xFound, yFound); |
|
2464 |
if (currValue) |
|
2465 |
m_valueList->next(); |
|
2466 |
break; |
|
2467 |
} |
|
2468 |
case CSSPropertyBackgroundPositionY: |
|
2469 |
case CSSPropertyWebkitMaskPositionY: { |
|
2470 |
bool xFound = true, yFound = false; |
|
2471 |
currValue = parseFillPositionXY(xFound, yFound); |
|
2472 |
if (currValue) |
|
2473 |
m_valueList->next(); |
|
2474 |
break; |
|
2475 |
} |
|
2476 |
case CSSPropertyWebkitBackgroundComposite: |
|
2477 |
case CSSPropertyWebkitMaskComposite: |
|
2478 |
if ((val->id >= CSSValueClear && val->id <= CSSValuePlusLighter) || val->id == CSSValueHighlight) { |
|
2479 |
currValue = CSSPrimitiveValue::createIdentifier(val->id); |
|
2480 |
m_valueList->next(); |
|
2481 |
} |
|
2482 |
break; |
|
2483 |
case CSSPropertyBackgroundRepeat: |
|
2484 |
case CSSPropertyWebkitMaskRepeat: |
|
2485 |
parseFillRepeat(currValue, currValue2); |
|
2486 |
// parseFillRepeat advances the m_valueList pointer |
|
2487 |
break; |
|
2488 |
case CSSPropertyBackgroundSize: |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2489 |
case CSSPropertyWebkitBackgroundSize: |
0 | 2490 |
case CSSPropertyWebkitMaskSize: { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2491 |
currValue = parseFillSize(propId, allowComma); |
0 | 2492 |
if (currValue) |
2493 |
m_valueList->next(); |
|
2494 |
break; |
|
2495 |
} |
|
2496 |
} |
|
2497 |
if (!currValue) |
|
2498 |
return false; |
|
2499 |
||
2500 |
if (value && !values) { |
|
2501 |
values = CSSValueList::createCommaSeparated(); |
|
2502 |
values->append(value.release()); |
|
2503 |
} |
|
2504 |
||
2505 |
if (value2 && !values2) { |
|
2506 |
values2 = CSSValueList::createCommaSeparated(); |
|
2507 |
values2->append(value2.release()); |
|
2508 |
} |
|
2509 |
||
2510 |
if (values) |
|
2511 |
values->append(currValue.release()); |
|
2512 |
else |
|
2513 |
value = currValue.release(); |
|
2514 |
if (currValue2) { |
|
2515 |
if (values2) |
|
2516 |
values2->append(currValue2.release()); |
|
2517 |
else |
|
2518 |
value2 = currValue2.release(); |
|
2519 |
} |
|
2520 |
} |
|
2521 |
||
2522 |
// When parsing any fill shorthand property, we let it handle building up the lists for all |
|
2523 |
// properties. |
|
2524 |
if (inShorthand()) |
|
2525 |
break; |
|
2526 |
} |
|
2527 |
||
2528 |
if (values && values->length()) { |
|
2529 |
retValue1 = values.release(); |
|
2530 |
if (values2 && values2->length()) |
|
2531 |
retValue2 = values2.release(); |
|
2532 |
return true; |
|
2533 |
} |
|
2534 |
if (value) { |
|
2535 |
retValue1 = value.release(); |
|
2536 |
retValue2 = value2.release(); |
|
2537 |
return true; |
|
2538 |
} |
|
2539 |
return false; |
|
2540 |
} |
|
2541 |
||
2542 |
PassRefPtr<CSSValue> CSSParser::parseAnimationDelay() |
|
2543 |
{ |
|
2544 |
CSSParserValue* value = m_valueList->current(); |
|
2545 |
if (validUnit(value, FTime, m_strict)) |
|
2546 |
return CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); |
|
2547 |
return 0; |
|
2548 |
} |
|
2549 |
||
2550 |
PassRefPtr<CSSValue> CSSParser::parseAnimationDirection() |
|
2551 |
{ |
|
2552 |
CSSParserValue* value = m_valueList->current(); |
|
2553 |
if (value->id == CSSValueNormal || value->id == CSSValueAlternate) |
|
2554 |
return CSSPrimitiveValue::createIdentifier(value->id); |
|
2555 |
return 0; |
|
2556 |
} |
|
2557 |
||
2558 |
PassRefPtr<CSSValue> CSSParser::parseAnimationDuration() |
|
2559 |
{ |
|
2560 |
CSSParserValue* value = m_valueList->current(); |
|
2561 |
if (validUnit(value, FTime|FNonNeg, m_strict)) |
|
2562 |
return CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); |
|
2563 |
return 0; |
|
2564 |
} |
|
2565 |
||
2566 |
PassRefPtr<CSSValue> CSSParser::parseAnimationIterationCount() |
|
2567 |
{ |
|
2568 |
CSSParserValue* value = m_valueList->current(); |
|
2569 |
if (value->id == CSSValueInfinite) |
|
2570 |
return CSSPrimitiveValue::createIdentifier(value->id); |
|
2571 |
if (validUnit(value, FInteger|FNonNeg, m_strict)) |
|
2572 |
return CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); |
|
2573 |
return 0; |
|
2574 |
} |
|
2575 |
||
2576 |
PassRefPtr<CSSValue> CSSParser::parseAnimationName() |
|
2577 |
{ |
|
2578 |
CSSParserValue* value = m_valueList->current(); |
|
2579 |
if (value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT) { |
|
2580 |
if (value->id == CSSValueNone || (value->unit == CSSPrimitiveValue::CSS_STRING && equalIgnoringCase(value->string, "none"))) { |
|
2581 |
return CSSPrimitiveValue::createIdentifier(CSSValueNone); |
|
2582 |
} else { |
|
2583 |
return CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_STRING); |
|
2584 |
} |
|
2585 |
} |
|
2586 |
return 0; |
|
2587 |
} |
|
2588 |
||
2589 |
PassRefPtr<CSSValue> CSSParser::parseAnimationPlayState() |
|
2590 |
{ |
|
2591 |
CSSParserValue* value = m_valueList->current(); |
|
2592 |
if (value->id == CSSValueRunning || value->id == CSSValuePaused) |
|
2593 |
return CSSPrimitiveValue::createIdentifier(value->id); |
|
2594 |
return 0; |
|
2595 |
} |
|
2596 |
||
2597 |
PassRefPtr<CSSValue> CSSParser::parseAnimationProperty() |
|
2598 |
{ |
|
2599 |
CSSParserValue* value = m_valueList->current(); |
|
2600 |
if (value->unit != CSSPrimitiveValue::CSS_IDENT) |
|
2601 |
return 0; |
|
2602 |
int result = cssPropertyID(value->string); |
|
2603 |
if (result) |
|
2604 |
return CSSPrimitiveValue::createIdentifier(result); |
|
2605 |
if (equalIgnoringCase(value->string, "all")) |
|
2606 |
return CSSPrimitiveValue::createIdentifier(CSSValueAll); |
|
2607 |
if (equalIgnoringCase(value->string, "none")) |
|
2608 |
return CSSPrimitiveValue::createIdentifier(CSSValueNone); |
|
2609 |
return 0; |
|
2610 |
} |
|
2611 |
||
2612 |
void CSSParser::parseTransformOriginShorthand(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& value2, RefPtr<CSSValue>& value3) |
|
2613 |
{ |
|
2614 |
parseFillPosition(value1, value2); |
|
2615 |
||
2616 |
// now get z |
|
2617 |
if (m_valueList->current() && validUnit(m_valueList->current(), FLength, m_strict)) |
|
2618 |
value3 = CSSPrimitiveValue::create(m_valueList->current()->fValue, |
|
2619 |
(CSSPrimitiveValue::UnitTypes)m_valueList->current()->unit); |
|
2620 |
if (value3) |
|
2621 |
m_valueList->next(); |
|
2622 |
} |
|
2623 |
||
2624 |
bool CSSParser::parseTimingFunctionValue(CSSParserValueList*& args, double& result) |
|
2625 |
{ |
|
2626 |
CSSParserValue* v = args->current(); |
|
2627 |
if (!validUnit(v, FNumber, m_strict)) |
|
2628 |
return false; |
|
2629 |
result = v->fValue; |
|
2630 |
if (result < 0 || result > 1.0) |
|
2631 |
return false; |
|
2632 |
v = args->next(); |
|
2633 |
if (!v) |
|
2634 |
// The last number in the function has no comma after it, so we're done. |
|
2635 |
return true; |
|
2636 |
if (v->unit != CSSParserValue::Operator && v->iValue != ',') |
|
2637 |
return false; |
|
2638 |
v = args->next(); |
|
2639 |
return true; |
|
2640 |
} |
|
2641 |
||
2642 |
PassRefPtr<CSSValue> CSSParser::parseAnimationTimingFunction() |
|
2643 |
{ |
|
2644 |
CSSParserValue* value = m_valueList->current(); |
|
2645 |
if (value->id == CSSValueEase || value->id == CSSValueLinear || value->id == CSSValueEaseIn || value->id == CSSValueEaseOut || value->id == CSSValueEaseInOut) |
|
2646 |
return CSSPrimitiveValue::createIdentifier(value->id); |
|
2647 |
||
2648 |
// We must be a function. |
|
2649 |
if (value->unit != CSSParserValue::Function) |
|
2650 |
return 0; |
|
2651 |
||
2652 |
// The only timing function we accept for now is a cubic bezier function. 4 points must be specified. |
|
2653 |
CSSParserValueList* args = value->function->args; |
|
2654 |
if (!equalIgnoringCase(value->function->name, "cubic-bezier(") || !args || args->size() != 7) |
|
2655 |
return 0; |
|
2656 |
||
2657 |
// There are two points specified. The values must be between 0 and 1. |
|
2658 |
double x1, y1, x2, y2; |
|
2659 |
||
2660 |
if (!parseTimingFunctionValue(args, x1)) |
|
2661 |
return 0; |
|
2662 |
if (!parseTimingFunctionValue(args, y1)) |
|
2663 |
return 0; |
|
2664 |
if (!parseTimingFunctionValue(args, x2)) |
|
2665 |
return 0; |
|
2666 |
if (!parseTimingFunctionValue(args, y2)) |
|
2667 |
return 0; |
|
2668 |
||
2669 |
return CSSTimingFunctionValue::create(x1, y1, x2, y2); |
|
2670 |
} |
|
2671 |
||
2672 |
bool CSSParser::parseAnimationProperty(int propId, RefPtr<CSSValue>& result) |
|
2673 |
{ |
|
2674 |
RefPtr<CSSValueList> values; |
|
2675 |
CSSParserValue* val; |
|
2676 |
RefPtr<CSSValue> value; |
|
2677 |
bool allowComma = false; |
|
2678 |
||
2679 |
result = 0; |
|
2680 |
||
2681 |
while ((val = m_valueList->current())) { |
|
2682 |
RefPtr<CSSValue> currValue; |
|
2683 |
if (allowComma) { |
|
2684 |
if (val->unit != CSSParserValue::Operator || val->iValue != ',') |
|
2685 |
return false; |
|
2686 |
m_valueList->next(); |
|
2687 |
allowComma = false; |
|
2688 |
} |
|
2689 |
else { |
|
2690 |
switch (propId) { |
|
2691 |
case CSSPropertyWebkitAnimationDelay: |
|
2692 |
case CSSPropertyWebkitTransitionDelay: |
|
2693 |
currValue = parseAnimationDelay(); |
|
2694 |
if (currValue) |
|
2695 |
m_valueList->next(); |
|
2696 |
break; |
|
2697 |
case CSSPropertyWebkitAnimationDirection: |
|
2698 |
currValue = parseAnimationDirection(); |
|
2699 |
if (currValue) |
|
2700 |
m_valueList->next(); |
|
2701 |
break; |
|
2702 |
case CSSPropertyWebkitAnimationDuration: |
|
2703 |
case CSSPropertyWebkitTransitionDuration: |
|
2704 |
currValue = parseAnimationDuration(); |
|
2705 |
if (currValue) |
|
2706 |
m_valueList->next(); |
|
2707 |
break; |
|
2708 |
case CSSPropertyWebkitAnimationIterationCount: |
|
2709 |
currValue = parseAnimationIterationCount(); |
|
2710 |
if (currValue) |
|
2711 |
m_valueList->next(); |
|
2712 |
break; |
|
2713 |
case CSSPropertyWebkitAnimationName: |
|
2714 |
currValue = parseAnimationName(); |
|
2715 |
if (currValue) |
|
2716 |
m_valueList->next(); |
|
2717 |
break; |
|
2718 |
case CSSPropertyWebkitAnimationPlayState: |
|
2719 |
currValue = parseAnimationPlayState(); |
|
2720 |
if (currValue) |
|
2721 |
m_valueList->next(); |
|
2722 |
break; |
|
2723 |
case CSSPropertyWebkitTransitionProperty: |
|
2724 |
currValue = parseAnimationProperty(); |
|
2725 |
if (currValue) |
|
2726 |
m_valueList->next(); |
|
2727 |
break; |
|
2728 |
case CSSPropertyWebkitAnimationTimingFunction: |
|
2729 |
case CSSPropertyWebkitTransitionTimingFunction: |
|
2730 |
currValue = parseAnimationTimingFunction(); |
|
2731 |
if (currValue) |
|
2732 |
m_valueList->next(); |
|
2733 |
break; |
|
2734 |
} |
|
2735 |
||
2736 |
if (!currValue) |
|
2737 |
return false; |
|
2738 |
||
2739 |
if (value && !values) { |
|
2740 |
values = CSSValueList::createCommaSeparated(); |
|
2741 |
values->append(value.release()); |
|
2742 |
} |
|
2743 |
||
2744 |
if (values) |
|
2745 |
values->append(currValue.release()); |
|
2746 |
else |
|
2747 |
value = currValue.release(); |
|
2748 |
||
2749 |
allowComma = true; |
|
2750 |
} |
|
2751 |
||
2752 |
// When parsing the 'transition' shorthand property, we let it handle building up the lists for all |
|
2753 |
// properties. |
|
2754 |
if (inShorthand()) |
|
2755 |
break; |
|
2756 |
} |
|
2757 |
||
2758 |
if (values && values->length()) { |
|
2759 |
result = values.release(); |
|
2760 |
return true; |
|
2761 |
} |
|
2762 |
if (value) { |
|
2763 |
result = value.release(); |
|
2764 |
return true; |
|
2765 |
} |
|
2766 |
return false; |
|
2767 |
} |
|
2768 |
||
2769 |
||
2770 |
||
2771 |
#if ENABLE(DASHBOARD_SUPPORT) |
|
2772 |
||
2773 |
#define DASHBOARD_REGION_NUM_PARAMETERS 6 |
|
2774 |
#define DASHBOARD_REGION_SHORT_NUM_PARAMETERS 2 |
|
2775 |
||
2776 |
static CSSParserValue* skipCommaInDashboardRegion(CSSParserValueList *args) |
|
2777 |
{ |
|
2778 |
if (args->size() == (DASHBOARD_REGION_NUM_PARAMETERS*2-1) || |
|
2779 |
args->size() == (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1)) { |
|
2780 |
CSSParserValue* current = args->current(); |
|
2781 |
if (current->unit == CSSParserValue::Operator && current->iValue == ',') |
|
2782 |
return args->next(); |
|
2783 |
} |
|
2784 |
return args->current(); |
|
2785 |
} |
|
2786 |
||
2787 |
bool CSSParser::parseDashboardRegions(int propId, bool important) |
|
2788 |
{ |
|
2789 |
bool valid = true; |
|
2790 |
||
2791 |
CSSParserValue* value = m_valueList->current(); |
|
2792 |
||
2793 |
if (value->id == CSSValueNone) { |
|
2794 |
if (m_valueList->next()) |
|
2795 |
return false; |
|
2796 |
addProperty(propId, CSSPrimitiveValue::createIdentifier(value->id), important); |
|
2797 |
return valid; |
|
2798 |
} |
|
2799 |
||
2800 |
RefPtr<DashboardRegion> firstRegion = DashboardRegion::create(); |
|
2801 |
DashboardRegion* region = 0; |
|
2802 |
||
2803 |
while (value) { |
|
2804 |
if (region == 0) { |
|
2805 |
region = firstRegion.get(); |
|
2806 |
} else { |
|
2807 |
RefPtr<DashboardRegion> nextRegion = DashboardRegion::create(); |
|
2808 |
region->m_next = nextRegion; |
|
2809 |
region = nextRegion.get(); |
|
2810 |
} |
|
2811 |
||
2812 |
if (value->unit != CSSParserValue::Function) { |
|
2813 |
valid = false; |
|
2814 |
break; |
|
2815 |
} |
|
2816 |
||
2817 |
// Commas count as values, so allow: |
|
2818 |
// dashboard-region(label, type, t, r, b, l) or dashboard-region(label type t r b l) |
|
2819 |
// dashboard-region(label, type, t, r, b, l) or dashboard-region(label type t r b l) |
|
2820 |
// also allow |
|
2821 |
// dashboard-region(label, type) or dashboard-region(label type) |
|
2822 |
// dashboard-region(label, type) or dashboard-region(label type) |
|
2823 |
CSSParserValueList* args = value->function->args; |
|
2824 |
if (!equalIgnoringCase(value->function->name, "dashboard-region(") || !args) { |
|
2825 |
valid = false; |
|
2826 |
break; |
|
2827 |
} |
|
2828 |
||
2829 |
int numArgs = args->size(); |
|
2830 |
if ((numArgs != DASHBOARD_REGION_NUM_PARAMETERS && numArgs != (DASHBOARD_REGION_NUM_PARAMETERS*2-1)) && |
|
2831 |
(numArgs != DASHBOARD_REGION_SHORT_NUM_PARAMETERS && numArgs != (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1))) { |
|
2832 |
valid = false; |
|
2833 |
break; |
|
2834 |
} |
|
2835 |
||
2836 |
// First arg is a label. |
|
2837 |
CSSParserValue* arg = args->current(); |
|
2838 |
if (arg->unit != CSSPrimitiveValue::CSS_IDENT) { |
|
2839 |
valid = false; |
|
2840 |
break; |
|
2841 |
} |
|
2842 |
||
2843 |
region->m_label = arg->string; |
|
2844 |
||
2845 |
// Second arg is a type. |
|
2846 |
arg = args->next(); |
|
2847 |
arg = skipCommaInDashboardRegion(args); |
|
2848 |
if (arg->unit != CSSPrimitiveValue::CSS_IDENT) { |
|
2849 |
valid = false; |
|
2850 |
break; |
|
2851 |
} |
|
2852 |
||
2853 |
if (equalIgnoringCase(arg->string, "circle")) |
|
2854 |
region->m_isCircle = true; |
|
2855 |
else if (equalIgnoringCase(arg->string, "rectangle")) |
|
2856 |
region->m_isRectangle = true; |
|
2857 |
else { |
|
2858 |
valid = false; |
|
2859 |
break; |
|
2860 |
} |
|
2861 |
||
2862 |
region->m_geometryType = arg->string; |
|
2863 |
||
2864 |
if (numArgs == DASHBOARD_REGION_SHORT_NUM_PARAMETERS || numArgs == (DASHBOARD_REGION_SHORT_NUM_PARAMETERS*2-1)) { |
|
2865 |
// This originally used CSSValueInvalid by accident. It might be more logical to use something else. |
|
2866 |
RefPtr<CSSPrimitiveValue> amount = CSSPrimitiveValue::createIdentifier(CSSValueInvalid); |
|
2867 |
||
2868 |
region->setTop(amount); |
|
2869 |
region->setRight(amount); |
|
2870 |
region->setBottom(amount); |
|
2871 |
region->setLeft(amount); |
|
2872 |
} else { |
|
2873 |
// Next four arguments must be offset numbers |
|
2874 |
int i; |
|
2875 |
for (i = 0; i < 4; i++) { |
|
2876 |
arg = args->next(); |
|
2877 |
arg = skipCommaInDashboardRegion(args); |
|
2878 |
||
2879 |
valid = arg->id == CSSValueAuto || validUnit(arg, FLength, m_strict); |
|
2880 |
if (!valid) |
|
2881 |
break; |
|
2882 |
||
2883 |
RefPtr<CSSPrimitiveValue> amount = arg->id == CSSValueAuto ? |
|
2884 |
CSSPrimitiveValue::createIdentifier(CSSValueAuto) : |
|
2885 |
CSSPrimitiveValue::create(arg->fValue, (CSSPrimitiveValue::UnitTypes) arg->unit); |
|
2886 |
||
2887 |
if (i == 0) |
|
2888 |
region->setTop(amount); |
|
2889 |
else if (i == 1) |
|
2890 |
region->setRight(amount); |
|
2891 |
else if (i == 2) |
|
2892 |
region->setBottom(amount); |
|
2893 |
else |
|
2894 |
region->setLeft(amount); |
|
2895 |
} |
|
2896 |
} |
|
2897 |
||
2898 |
if (args->next()) |
|
2899 |
return false; |
|
2900 |
||
2901 |
value = m_valueList->next(); |
|
2902 |
} |
|
2903 |
||
2904 |
if (valid) |
|
2905 |
addProperty(propId, CSSPrimitiveValue::create(firstRegion.release()), important); |
|
2906 |
||
2907 |
return valid; |
|
2908 |
} |
|
2909 |
||
2910 |
#endif /* ENABLE(DASHBOARD_SUPPORT) */ |
|
2911 |
||
2912 |
PassRefPtr<CSSValue> CSSParser::parseCounterContent(CSSParserValueList* args, bool counters) |
|
2913 |
{ |
|
2914 |
unsigned numArgs = args->size(); |
|
2915 |
if (counters && numArgs != 3 && numArgs != 5) |
|
2916 |
return 0; |
|
2917 |
if (!counters && numArgs != 1 && numArgs != 3) |
|
2918 |
return 0; |
|
2919 |
||
2920 |
CSSParserValue* i = args->current(); |
|
2921 |
if (i->unit != CSSPrimitiveValue::CSS_IDENT) |
|
2922 |
return 0; |
|
2923 |
RefPtr<CSSPrimitiveValue> identifier = CSSPrimitiveValue::create(i->string, CSSPrimitiveValue::CSS_STRING); |
|
2924 |
||
2925 |
RefPtr<CSSPrimitiveValue> separator; |
|
2926 |
if (!counters) |
|
2927 |
separator = CSSPrimitiveValue::create(String(), CSSPrimitiveValue::CSS_STRING); |
|
2928 |
else { |
|
2929 |
i = args->next(); |
|
2930 |
if (i->unit != CSSParserValue::Operator || i->iValue != ',') |
|
2931 |
return 0; |
|
2932 |
||
2933 |
i = args->next(); |
|
2934 |
if (i->unit != CSSPrimitiveValue::CSS_STRING) |
|
2935 |
return 0; |
|
2936 |
||
2937 |
separator = CSSPrimitiveValue::create(i->string, (CSSPrimitiveValue::UnitTypes) i->unit); |
|
2938 |
} |
|
2939 |
||
2940 |
RefPtr<CSSPrimitiveValue> listStyle; |
|
2941 |
i = args->next(); |
|
2942 |
if (!i) // Make the list style default decimal |
|
2943 |
listStyle = CSSPrimitiveValue::create(CSSValueDecimal - CSSValueDisc, CSSPrimitiveValue::CSS_NUMBER); |
|
2944 |
else { |
|
2945 |
if (i->unit != CSSParserValue::Operator || i->iValue != ',') |
|
2946 |
return 0; |
|
2947 |
||
2948 |
i = args->next(); |
|
2949 |
if (i->unit != CSSPrimitiveValue::CSS_IDENT) |
|
2950 |
return 0; |
|
2951 |
||
2952 |
short ls = 0; |
|
2953 |
if (i->id == CSSValueNone) |
|
2954 |
ls = CSSValueKatakanaIroha - CSSValueDisc + 1; |
|
2955 |
else if (i->id >= CSSValueDisc && i->id <= CSSValueKatakanaIroha) |
|
2956 |
ls = i->id - CSSValueDisc; |
|
2957 |
else |
|
2958 |
return 0; |
|
2959 |
||
2960 |
listStyle = CSSPrimitiveValue::create(ls, (CSSPrimitiveValue::UnitTypes) i->unit); |
|
2961 |
} |
|
2962 |
||
2963 |
return CSSPrimitiveValue::create(Counter::create(identifier.release(), listStyle.release(), separator.release())); |
|
2964 |
} |
|
2965 |
||
2966 |
bool CSSParser::parseShape(int propId, bool important) |
|
2967 |
{ |
|
2968 |
CSSParserValue* value = m_valueList->current(); |
|
2969 |
CSSParserValueList* args = value->function->args; |
|
2970 |
||
2971 |
if (!equalIgnoringCase(value->function->name, "rect(") || !args) |
|
2972 |
return false; |
|
2973 |
||
2974 |
// rect(t, r, b, l) || rect(t r b l) |
|
2975 |
if (args->size() != 4 && args->size() != 7) |
|
2976 |
return false; |
|
2977 |
RefPtr<Rect> rect = Rect::create(); |
|
2978 |
bool valid = true; |
|
2979 |
int i = 0; |
|
2980 |
CSSParserValue* a = args->current(); |
|
2981 |
while (a) { |
|
2982 |
valid = a->id == CSSValueAuto || validUnit(a, FLength, m_strict); |
|
2983 |
if (!valid) |
|
2984 |
break; |
|
2985 |
RefPtr<CSSPrimitiveValue> length = a->id == CSSValueAuto ? |
|
2986 |
CSSPrimitiveValue::createIdentifier(CSSValueAuto) : |
|
2987 |
CSSPrimitiveValue::create(a->fValue, (CSSPrimitiveValue::UnitTypes) a->unit); |
|
2988 |
if (i == 0) |
|
2989 |
rect->setTop(length); |
|
2990 |
else if (i == 1) |
|
2991 |
rect->setRight(length); |
|
2992 |
else if (i == 2) |
|
2993 |
rect->setBottom(length); |
|
2994 |
else |
|
2995 |
rect->setLeft(length); |
|
2996 |
a = args->next(); |
|
2997 |
if (a && args->size() == 7) { |
|
2998 |
if (a->unit == CSSParserValue::Operator && a->iValue == ',') { |
|
2999 |
a = args->next(); |
|
3000 |
} else { |
|
3001 |
valid = false; |
|
3002 |
break; |
|
3003 |
} |
|
3004 |
} |
|
3005 |
i++; |
|
3006 |
} |
|
3007 |
if (valid) { |
|
3008 |
addProperty(propId, CSSPrimitiveValue::create(rect.release()), important); |
|
3009 |
m_valueList->next(); |
|
3010 |
return true; |
|
3011 |
} |
|
3012 |
return false; |
|
3013 |
} |
|
3014 |
||
3015 |
// [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? 'font-family' |
|
3016 |
bool CSSParser::parseFont(bool important) |
|
3017 |
{ |
|
3018 |
bool valid = true; |
|
3019 |
CSSParserValue *value = m_valueList->current(); |
|
3020 |
RefPtr<FontValue> font = FontValue::create(); |
|
3021 |
// optional font-style, font-variant and font-weight |
|
3022 |
while (value) { |
|
3023 |
int id = value->id; |
|
3024 |
if (id) { |
|
3025 |
if (id == CSSValueNormal) { |
|
3026 |
// do nothing, it's the inital value for all three |
|
3027 |
} else if (id == CSSValueItalic || id == CSSValueOblique) { |
|
3028 |
if (font->style) |
|
3029 |
return false; |
|
3030 |
font->style = CSSPrimitiveValue::createIdentifier(id); |
|
3031 |
} else if (id == CSSValueSmallCaps) { |
|
3032 |
if (font->variant) |
|
3033 |
return false; |
|
3034 |
font->variant = CSSPrimitiveValue::createIdentifier(id); |
|
3035 |
} else if (id >= CSSValueBold && id <= CSSValueLighter) { |
|
3036 |
if (font->weight) |
|
3037 |
return false; |
|
3038 |
font->weight = CSSPrimitiveValue::createIdentifier(id); |
|
3039 |
} else { |
|
3040 |
valid = false; |
|
3041 |
} |
|
3042 |
} else if (!font->weight && validUnit(value, FInteger|FNonNeg, true)) { |
|
3043 |
int weight = (int)value->fValue; |
|
3044 |
int val = 0; |
|
3045 |
if (weight == 100) |
|
3046 |
val = CSSValue100; |
|
3047 |
else if (weight == 200) |
|
3048 |
val = CSSValue200; |
|
3049 |
else if (weight == 300) |
|
3050 |
val = CSSValue300; |
|
3051 |
else if (weight == 400) |
|
3052 |
val = CSSValue400; |
|
3053 |
else if (weight == 500) |
|
3054 |
val = CSSValue500; |
|
3055 |
else if (weight == 600) |
|
3056 |
val = CSSValue600; |
|
3057 |
else if (weight == 700) |
|
3058 |
val = CSSValue700; |
|
3059 |
else if (weight == 800) |
|
3060 |
val = CSSValue800; |
|
3061 |
else if (weight == 900) |
|
3062 |
val = CSSValue900; |
|
3063 |
||
3064 |
if (val) |
|
3065 |
font->weight = CSSPrimitiveValue::createIdentifier(val); |
|
3066 |
else |
|
3067 |
valid = false; |
|
3068 |
} else { |
|
3069 |
valid = false; |
|
3070 |
} |
|
3071 |
if (!valid) |
|
3072 |
break; |
|
3073 |
value = m_valueList->next(); |
|
3074 |
} |
|
3075 |
if (!value) |
|
3076 |
return false; |
|
3077 |
||
3078 |
// set undefined values to default |
|
3079 |
if (!font->style) |
|
3080 |
font->style = CSSPrimitiveValue::createIdentifier(CSSValueNormal); |
|
3081 |
if (!font->variant) |
|
3082 |
font->variant = CSSPrimitiveValue::createIdentifier(CSSValueNormal); |
|
3083 |
if (!font->weight) |
|
3084 |
font->weight = CSSPrimitiveValue::createIdentifier(CSSValueNormal); |
|
3085 |
||
3086 |
// now a font size _must_ come |
|
3087 |
// <absolute-size> | <relative-size> | <length> | <percentage> | inherit |
|
3088 |
if (value->id >= CSSValueXxSmall && value->id <= CSSValueLarger) |
|
3089 |
font->size = CSSPrimitiveValue::createIdentifier(value->id); |
|
3090 |
else if (validUnit(value, FLength|FPercent|FNonNeg, m_strict)) |
|
3091 |
font->size = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit); |
|
3092 |
value = m_valueList->next(); |
|
3093 |
if (!font->size || !value) |
|
3094 |
return false; |
|
3095 |
||
3096 |
if (value->unit == CSSParserValue::Operator && value->iValue == '/') { |
|
3097 |
// line-height |
|
3098 |
value = m_valueList->next(); |
|
3099 |
if (!value) |
|
3100 |
return false; |
|
3101 |
if (value->id == CSSValueNormal) { |
|
3102 |
// default value, nothing to do |
|
3103 |
} else if (validUnit(value, FNumber|FLength|FPercent|FNonNeg, m_strict)) |
|
3104 |
font->lineHeight = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit); |
|
3105 |
else |
|
3106 |
return false; |
|
3107 |
value = m_valueList->next(); |
|
3108 |
if (!value) |
|
3109 |
return false; |
|
3110 |
} |
|
3111 |
||
3112 |
if (!font->lineHeight) |
|
3113 |
font->lineHeight = CSSPrimitiveValue::createIdentifier(CSSValueNormal); |
|
3114 |
||
3115 |
// font family must come now |
|
3116 |
font->family = parseFontFamily(); |
|
3117 |
||
3118 |
if (m_valueList->current() || !font->family) |
|
3119 |
return false; |
|
3120 |
||
3121 |
addProperty(CSSPropertyFont, font.release(), important); |
|
3122 |
return true; |
|
3123 |
} |
|
3124 |
||
3125 |
PassRefPtr<CSSValueList> CSSParser::parseFontFamily() |
|
3126 |
{ |
|
3127 |
RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); |
|
3128 |
CSSParserValue* value = m_valueList->current(); |
|
3129 |
||
3130 |
FontFamilyValue* currFamily = 0; |
|
3131 |
while (value) { |
|
3132 |
CSSParserValue* nextValue = m_valueList->next(); |
|
3133 |
bool nextValBreaksFont = !nextValue || |
|
3134 |
(nextValue->unit == CSSParserValue::Operator && nextValue->iValue == ','); |
|
3135 |
bool nextValIsFontName = nextValue && |
|
3136 |
((nextValue->id >= CSSValueSerif && nextValue->id <= CSSValueWebkitBody) || |
|
3137 |
(nextValue->unit == CSSPrimitiveValue::CSS_STRING || nextValue->unit == CSSPrimitiveValue::CSS_IDENT)); |
|
3138 |
||
3139 |
if (value->id >= CSSValueSerif && value->id <= CSSValueWebkitBody) { |
|
3140 |
if (currFamily) |
|
3141 |
currFamily->appendSpaceSeparated(value->string.characters, value->string.length); |
|
3142 |
else if (nextValBreaksFont || !nextValIsFontName) |
|
3143 |
list->append(CSSPrimitiveValue::createIdentifier(value->id)); |
|
3144 |
else { |
|
3145 |
RefPtr<FontFamilyValue> newFamily = FontFamilyValue::create(value->string); |
|
3146 |
currFamily = newFamily.get(); |
|
3147 |
list->append(newFamily.release()); |
|
3148 |
} |
|
3149 |
} else if (value->unit == CSSPrimitiveValue::CSS_STRING) { |
|
3150 |
// Strings never share in a family name. |
|
3151 |
currFamily = 0; |
|
3152 |
list->append(FontFamilyValue::create(value->string)); |
|
3153 |
} else if (value->unit == CSSPrimitiveValue::CSS_IDENT) { |
|
3154 |
if (currFamily) |
|
3155 |
currFamily->appendSpaceSeparated(value->string.characters, value->string.length); |
|
3156 |
else if (nextValBreaksFont || !nextValIsFontName) |
|
3157 |
list->append(FontFamilyValue::create(value->string)); |
|
3158 |
else { |
|
3159 |
RefPtr<FontFamilyValue> newFamily = FontFamilyValue::create(value->string); |
|
3160 |
currFamily = newFamily.get(); |
|
3161 |
list->append(newFamily.release()); |
|
3162 |
} |
|
3163 |
} else { |
|
3164 |
break; |
|
3165 |
} |
|
3166 |
||
3167 |
if (!nextValue) |
|
3168 |
break; |
|
3169 |
||
3170 |
if (nextValBreaksFont) { |
|
3171 |
value = m_valueList->next(); |
|
3172 |
currFamily = 0; |
|
3173 |
} |
|
3174 |
else if (nextValIsFontName) |
|
3175 |
value = nextValue; |
|
3176 |
else |
|
3177 |
break; |
|
3178 |
} |
|
3179 |
if (!list->length()) |
|
3180 |
list = 0; |
|
3181 |
return list.release(); |
|
3182 |
} |
|
3183 |
||
3184 |
bool CSSParser::parseFontStyle(bool important) |
|
3185 |
{ |
|
3186 |
RefPtr<CSSValueList> values; |
|
3187 |
if (m_valueList->size() > 1) |
|
3188 |
values = CSSValueList::createCommaSeparated(); |
|
3189 |
CSSParserValue* val; |
|
3190 |
bool expectComma = false; |
|
3191 |
while ((val = m_valueList->current())) { |
|
3192 |
RefPtr<CSSPrimitiveValue> parsedValue; |
|
3193 |
if (!expectComma) { |
|
3194 |
expectComma = true; |
|
3195 |
if (val->id == CSSValueNormal || val->id == CSSValueItalic || val->id == CSSValueOblique) |
|
3196 |
parsedValue = CSSPrimitiveValue::createIdentifier(val->id); |
|
3197 |
else if (val->id == CSSValueAll && !values) { |
|
3198 |
// 'all' is only allowed in @font-face and with no other values. Make a value list to |
|
3199 |
// indicate that we are in the @font-face case. |
|
3200 |
values = CSSValueList::createCommaSeparated(); |
|
3201 |
parsedValue = CSSPrimitiveValue::createIdentifier(val->id); |
|
3202 |
} |
|
3203 |
} else if (val->unit == CSSParserValue::Operator && val->iValue == ',') { |
|
3204 |
expectComma = false; |
|
3205 |
m_valueList->next(); |
|
3206 |
continue; |
|
3207 |
} |
|
3208 |
||
3209 |
if (!parsedValue) |
|
3210 |
return false; |
|
3211 |
||
3212 |
m_valueList->next(); |
|
3213 |
||
3214 |
if (values) |
|
3215 |
values->append(parsedValue.release()); |
|
3216 |
else { |
|
3217 |
addProperty(CSSPropertyFontStyle, parsedValue.release(), important); |
|
3218 |
return true; |
|
3219 |
} |
|
3220 |
} |
|
3221 |
||
3222 |
if (values && values->length()) { |
|
3223 |
m_hasFontFaceOnlyValues = true; |
|
3224 |
addProperty(CSSPropertyFontStyle, values.release(), important); |
|
3225 |
return true; |
|
3226 |
} |
|
3227 |
||
3228 |
return false; |
|
3229 |
} |
|
3230 |
||
3231 |
bool CSSParser::parseFontVariant(bool important) |
|
3232 |
{ |
|
3233 |
RefPtr<CSSValueList> values; |
|
3234 |
if (m_valueList->size() > 1) |
|
3235 |
values = CSSValueList::createCommaSeparated(); |
|
3236 |
CSSParserValue* val; |
|
3237 |
bool expectComma = false; |
|
3238 |
while ((val = m_valueList->current())) { |
|
3239 |
RefPtr<CSSPrimitiveValue> parsedValue; |
|
3240 |
if (!expectComma) { |
|
3241 |
expectComma = true; |
|
3242 |
if (val->id == CSSValueNormal || val->id == CSSValueSmallCaps) |
|
3243 |
parsedValue = CSSPrimitiveValue::createIdentifier(val->id); |
|
3244 |
else if (val->id == CSSValueAll && !values) { |
|
3245 |
// 'all' is only allowed in @font-face and with no other values. Make a value list to |
|
3246 |
// indicate that we are in the @font-face case. |
|
3247 |
values = CSSValueList::createCommaSeparated(); |
|
3248 |
parsedValue = CSSPrimitiveValue::createIdentifier(val->id); |
|
3249 |
} |
|
3250 |
} else if (val->unit == CSSParserValue::Operator && val->iValue == ',') { |
|
3251 |
expectComma = false; |
|
3252 |
m_valueList->next(); |
|
3253 |
continue; |
|
3254 |
} |
|
3255 |
||
3256 |
if (!parsedValue) |
|
3257 |
return false; |
|
3258 |
||
3259 |
m_valueList->next(); |
|
3260 |
||
3261 |
if (values) |
|
3262 |
values->append(parsedValue.release()); |
|
3263 |
else { |
|
3264 |
addProperty(CSSPropertyFontVariant, parsedValue.release(), important); |
|
3265 |
return true; |
|
3266 |
} |
|
3267 |
} |
|
3268 |
||
3269 |
if (values && values->length()) { |
|
3270 |
m_hasFontFaceOnlyValues = true; |
|
3271 |
addProperty(CSSPropertyFontVariant, values.release(), important); |
|
3272 |
return true; |
|
3273 |
} |
|
3274 |
||
3275 |
return false; |
|
3276 |
} |
|
3277 |
||
3278 |
bool CSSParser::parseFontWeight(bool important) |
|
3279 |
{ |
|
3280 |
RefPtr<CSSValueList> values; |
|
3281 |
if (m_valueList->size() > 1) |
|
3282 |
values = CSSValueList::createCommaSeparated(); |
|
3283 |
CSSParserValue* val; |
|
3284 |
bool expectComma = false; |
|
3285 |
while ((val = m_valueList->current())) { |
|
3286 |
RefPtr<CSSPrimitiveValue> parsedValue; |
|
3287 |
if (!expectComma) { |
|
3288 |
expectComma = true; |
|
3289 |
if (val->unit == CSSPrimitiveValue::CSS_IDENT) { |
|
3290 |
if (val->id >= CSSValueNormal && val->id <= CSSValue900) |
|
3291 |
parsedValue = CSSPrimitiveValue::createIdentifier(val->id); |
|
3292 |
else if (val->id == CSSValueAll && !values) { |
|
3293 |
// 'all' is only allowed in @font-face and with no other values. Make a value list to |
|
3294 |
// indicate that we are in the @font-face case. |
|
3295 |
values = CSSValueList::createCommaSeparated(); |
|
3296 |
parsedValue = CSSPrimitiveValue::createIdentifier(val->id); |
|
3297 |
} |
|
3298 |
} else if (validUnit(val, FInteger | FNonNeg, false)) { |
|
3299 |
int weight = static_cast<int>(val->fValue); |
|
3300 |
if (!(weight % 100) && weight >= 100 && weight <= 900) |
|
3301 |
parsedValue = CSSPrimitiveValue::createIdentifier(CSSValue100 + weight / 100 - 1); |
|
3302 |
} |
|
3303 |
} else if (val->unit == CSSParserValue::Operator && val->iValue == ',') { |
|
3304 |
expectComma = false; |
|
3305 |
m_valueList->next(); |
|
3306 |
continue; |
|
3307 |
} |
|
3308 |
||
3309 |
if (!parsedValue) |
|
3310 |
return false; |
|
3311 |
||
3312 |
m_valueList->next(); |
|
3313 |
||
3314 |
if (values) |
|
3315 |
values->append(parsedValue.release()); |
|
3316 |
else { |
|
3317 |
addProperty(CSSPropertyFontWeight, parsedValue.release(), important); |
|
3318 |
return true; |
|
3319 |
} |
|
3320 |
} |
|
3321 |
||
3322 |
if (values && values->length()) { |
|
3323 |
m_hasFontFaceOnlyValues = true; |
|
3324 |
addProperty(CSSPropertyFontWeight, values.release(), important); |
|
3325 |
return true; |
|
3326 |
} |
|
3327 |
||
3328 |
return false; |
|
3329 |
} |
|
3330 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3331 |
static bool isValidFormatFunction(CSSParserValue* val) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3332 |
{ |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3333 |
CSSParserValueList* args = val->function->args; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3334 |
return equalIgnoringCase(val->function->name, "format(") && (args->current()->unit == CSSPrimitiveValue::CSS_STRING || args->current()->unit == CSSPrimitiveValue::CSS_IDENT); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3335 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3336 |
|
0 | 3337 |
bool CSSParser::parseFontFaceSrc() |
3338 |
{ |
|
3339 |
RefPtr<CSSValueList> values(CSSValueList::createCommaSeparated()); |
|
3340 |
CSSParserValue* val; |
|
3341 |
bool expectComma = false; |
|
3342 |
bool allowFormat = false; |
|
3343 |
bool failed = false; |
|
3344 |
RefPtr<CSSFontFaceSrcValue> uriValue; |
|
3345 |
while ((val = m_valueList->current())) { |
|
3346 |
RefPtr<CSSFontFaceSrcValue> parsedValue; |
|
3347 |
if (val->unit == CSSPrimitiveValue::CSS_URI && !expectComma && m_styleSheet) { |
|
3348 |
// FIXME: The completeURL call should be done when using the CSSFontFaceSrcValue, |
|
3349 |
// not when creating it. |
|
3350 |
parsedValue = CSSFontFaceSrcValue::create(m_styleSheet->completeURL(val->string)); |
|
3351 |
uriValue = parsedValue; |
|
3352 |
allowFormat = true; |
|
3353 |
expectComma = true; |
|
3354 |
} else if (val->unit == CSSParserValue::Function) { |
|
3355 |
// There are two allowed functions: local() and format(). |
|
3356 |
CSSParserValueList* args = val->function->args; |
|
3357 |
if (args && args->size() == 1) { |
|
3358 |
if (equalIgnoringCase(val->function->name, "local(") && !expectComma) { |
|
3359 |
expectComma = true; |
|
3360 |
allowFormat = false; |
|
3361 |
CSSParserValue* a = args->current(); |
|
3362 |
uriValue.clear(); |
|
3363 |
parsedValue = CSSFontFaceSrcValue::createLocal(a->string); |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3364 |
} else if (allowFormat && uriValue && isValidFormatFunction(val)) { |
0 | 3365 |
expectComma = true; |
3366 |
allowFormat = false; |
|
3367 |
uriValue->setFormat(args->current()->string); |
|
3368 |
uriValue.clear(); |
|
3369 |
m_valueList->next(); |
|
3370 |
continue; |
|
3371 |
} |
|
3372 |
} |
|
3373 |
} else if (val->unit == CSSParserValue::Operator && val->iValue == ',' && expectComma) { |
|
3374 |
expectComma = false; |
|
3375 |
allowFormat = false; |
|
3376 |
uriValue.clear(); |
|
3377 |
m_valueList->next(); |
|
3378 |
continue; |
|
3379 |
} |
|
3380 |
||
3381 |
if (parsedValue) |
|
3382 |
values->append(parsedValue.release()); |
|
3383 |
else { |
|
3384 |
failed = true; |
|
3385 |
break; |
|
3386 |
} |
|
3387 |
m_valueList->next(); |
|
3388 |
} |
|
3389 |
||
3390 |
if (values->length() && !failed) { |
|
3391 |
addProperty(CSSPropertySrc, values.release(), m_important); |
|
3392 |
m_valueList->next(); |
|
3393 |
return true; |
|
3394 |
} |
|
3395 |
||
3396 |
return false; |
|
3397 |
} |
|
3398 |
||
3399 |
bool CSSParser::parseFontFaceUnicodeRange() |
|
3400 |
{ |
|
3401 |
RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated(); |
|
3402 |
CSSParserValue* currentValue; |
|
3403 |
bool failed = false; |
|
3404 |
while ((currentValue = m_valueList->current())) { |
|
3405 |
if (m_valueList->current()->unit != CSSPrimitiveValue::CSS_UNICODE_RANGE) { |
|
3406 |
failed = true; |
|
3407 |
break; |
|
3408 |
} |
|
3409 |
||
3410 |
String rangeString = m_valueList->current()->string; |
|
3411 |
UChar32 from = 0; |
|
3412 |
UChar32 to = 0; |
|
3413 |
unsigned length = rangeString.length(); |
|
3414 |
||
3415 |
if (length < 3) { |
|
3416 |
failed = true; |
|
3417 |
break; |
|
3418 |
} |
|
3419 |
||
3420 |
unsigned i = 2; |
|
3421 |
while (i < length) { |
|
3422 |
UChar c = rangeString[i]; |
|
3423 |
if (c == '-' || c == '?') |
|
3424 |
break; |
|
3425 |
from *= 16; |
|
3426 |
if (c >= '0' && c <= '9') |
|
3427 |
from += c - '0'; |
|
3428 |
else if (c >= 'A' && c <= 'F') |
|
3429 |
from += 10 + c - 'A'; |
|
3430 |
else if (c >= 'a' && c <= 'f') |
|
3431 |
from += 10 + c - 'a'; |
|
3432 |
else { |
|
3433 |
failed = true; |
|
3434 |
break; |
|
3435 |
} |
|
3436 |
i++; |
|
3437 |
} |
|
3438 |
if (failed) |
|
3439 |
break; |
|
3440 |
||
3441 |
if (i == length) |
|
3442 |
to = from; |
|
3443 |
else if (rangeString[i] == '?') { |
|
3444 |
unsigned span = 1; |
|
3445 |
while (i < length && rangeString[i] == '?') { |
|
3446 |
span *= 16; |
|
3447 |
from *= 16; |
|
3448 |
i++; |
|
3449 |
} |
|
3450 |
if (i < length) |
|
3451 |
failed = true; |
|
3452 |
to = from + span - 1; |
|
3453 |
} else { |
|
3454 |
if (length < i + 2) { |
|
3455 |
failed = true; |
|
3456 |
break; |
|
3457 |
} |
|
3458 |
i++; |
|
3459 |
while (i < length) { |
|
3460 |
UChar c = rangeString[i]; |
|
3461 |
to *= 16; |
|
3462 |
if (c >= '0' && c <= '9') |
|
3463 |
to += c - '0'; |
|
3464 |
else if (c >= 'A' && c <= 'F') |
|
3465 |
to += 10 + c - 'A'; |
|
3466 |
else if (c >= 'a' && c <= 'f') |
|
3467 |
to += 10 + c - 'a'; |
|
3468 |
else { |
|
3469 |
failed = true; |
|
3470 |
break; |
|
3471 |
} |
|
3472 |
i++; |
|
3473 |
} |
|
3474 |
if (failed) |
|
3475 |
break; |
|
3476 |
} |
|
3477 |
values->append(CSSUnicodeRangeValue::create(from, to)); |
|
3478 |
m_valueList->next(); |
|
3479 |
} |
|
3480 |
if (failed || !values->length()) |
|
3481 |
return false; |
|
3482 |
addProperty(CSSPropertyUnicodeRange, values.release(), m_important); |
|
3483 |
return true; |
|
3484 |
} |
|
3485 |
||
3486 |
bool CSSParser::parseColor(const String &name, RGBA32& rgb, bool strict) |
|
3487 |
{ |
|
3488 |
if (!strict && Color::parseHexColor(name, rgb)) |
|
3489 |
return true; |
|
3490 |
||
3491 |
// try a little harder |
|
3492 |
Color tc; |
|
3493 |
tc.setNamedColor(name); |
|
3494 |
if (tc.isValid()) { |
|
3495 |
rgb = tc.rgb(); |
|
3496 |
return true; |
|
3497 |
} |
|
3498 |
||
3499 |
return false; |
|
3500 |
} |
|
3501 |
||
3502 |
bool CSSParser::parseColorParameters(CSSParserValue* value, int* colorArray, bool parseAlpha) |
|
3503 |
{ |
|
3504 |
CSSParserValueList* args = value->function->args; |
|
3505 |
CSSParserValue* v = args->current(); |
|
3506 |
Units unitType = FUnknown; |
|
3507 |
// Get the first value and its type |
|
3508 |
if (validUnit(v, FInteger, true)) |
|
3509 |
unitType = FInteger; |
|
3510 |
else if (validUnit(v, FPercent, true)) |
|
3511 |
unitType = FPercent; |
|
3512 |
else |
|
3513 |
return false; |
|
3514 |
colorArray[0] = static_cast<int>(v->fValue * (v->unit == CSSPrimitiveValue::CSS_PERCENTAGE ? 256.0 / 100.0 : 1.0)); |
|
3515 |
for (int i = 1; i < 3; i++) { |
|
3516 |
v = args->next(); |
|
3517 |
if (v->unit != CSSParserValue::Operator && v->iValue != ',') |
|
3518 |
return false; |
|
3519 |
v = args->next(); |
|
3520 |
if (!validUnit(v, unitType, true)) |
|
3521 |
return false; |
|
3522 |
colorArray[i] = static_cast<int>(v->fValue * (v->unit == CSSPrimitiveValue::CSS_PERCENTAGE ? 256.0 / 100.0 : 1.0)); |
|
3523 |
} |
|
3524 |
if (parseAlpha) { |
|
3525 |
v = args->next(); |
|
3526 |
if (v->unit != CSSParserValue::Operator && v->iValue != ',') |
|
3527 |
return false; |
|
3528 |
v = args->next(); |
|
3529 |
if (!validUnit(v, FNumber, true)) |
|
3530 |
return false; |
|
3531 |
colorArray[3] = static_cast<int>(max(0.0, min(1.0, v->fValue)) * 255); |
|
3532 |
} |
|
3533 |
return true; |
|
3534 |
} |
|
3535 |
||
3536 |
// The CSS3 specification defines the format of a HSL color as |
|
3537 |
// hsl(<number>, <percent>, <percent>) |
|
3538 |
// and with alpha, the format is |
|
3539 |
// hsla(<number>, <percent>, <percent>, <number>) |
|
3540 |
// The first value, HUE, is in an angle with a value between 0 and 360 |
|
3541 |
bool CSSParser::parseHSLParameters(CSSParserValue* value, double* colorArray, bool parseAlpha) |
|
3542 |
{ |
|
3543 |
CSSParserValueList* args = value->function->args; |
|
3544 |
CSSParserValue* v = args->current(); |
|
3545 |
// Get the first value |
|
3546 |
if (!validUnit(v, FNumber, true)) |
|
3547 |
return false; |
|
3548 |
// normalize the Hue value and change it to be between 0 and 1.0 |
|
3549 |
colorArray[0] = (((static_cast<int>(v->fValue) % 360) + 360) % 360) / 360.0; |
|
3550 |
for (int i = 1; i < 3; i++) { |
|
3551 |
v = args->next(); |
|
3552 |
if (v->unit != CSSParserValue::Operator && v->iValue != ',') |
|
3553 |
return false; |
|
3554 |
v = args->next(); |
|
3555 |
if (!validUnit(v, FPercent, true)) |
|
3556 |
return false; |
|
3557 |
colorArray[i] = max(0.0, min(100.0, v->fValue)) / 100.0; // needs to be value between 0 and 1.0 |
|
3558 |
} |
|
3559 |
if (parseAlpha) { |
|
3560 |
v = args->next(); |
|
3561 |
if (v->unit != CSSParserValue::Operator && v->iValue != ',') |
|
3562 |
return false; |
|
3563 |
v = args->next(); |
|
3564 |
if (!validUnit(v, FNumber, true)) |
|
3565 |
return false; |
|
3566 |
colorArray[3] = max(0.0, min(1.0, v->fValue)); |
|
3567 |
} |
|
3568 |
return true; |
|
3569 |
} |
|
3570 |
||
3571 |
PassRefPtr<CSSPrimitiveValue> CSSParser::parseColor(CSSParserValue* value) |
|
3572 |
{ |
|
3573 |
RGBA32 c = Color::transparent; |
|
3574 |
if (!parseColorFromValue(value ? value : m_valueList->current(), c)) |
|
3575 |
return 0; |
|
3576 |
return CSSPrimitiveValue::createColor(c); |
|
3577 |
} |
|
3578 |
||
3579 |
bool CSSParser::parseColorFromValue(CSSParserValue* value, RGBA32& c, bool svg) |
|
3580 |
{ |
|
3581 |
if (!m_strict && value->unit == CSSPrimitiveValue::CSS_NUMBER && |
|
3582 |
value->fValue >= 0. && value->fValue < 1000000.) { |
|
3583 |
String str = String::format("%06d", (int)(value->fValue+.5)); |
|
3584 |
if (!CSSParser::parseColor(str, c, m_strict)) |
|
3585 |
return false; |
|
3586 |
} else if (value->unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR || |
|
3587 |
value->unit == CSSPrimitiveValue::CSS_IDENT || |
|
3588 |
(!m_strict && value->unit == CSSPrimitiveValue::CSS_DIMENSION)) { |
|
3589 |
if (!CSSParser::parseColor(value->string, c, m_strict && value->unit == CSSPrimitiveValue::CSS_IDENT)) |
|
3590 |
return false; |
|
3591 |
} else if (value->unit == CSSParserValue::Function && |
|
3592 |
value->function->args != 0 && |
|
3593 |
value->function->args->size() == 5 /* rgb + two commas */ && |
|
3594 |
equalIgnoringCase(value->function->name, "rgb(")) { |
|
3595 |
int colorValues[3]; |
|
3596 |
if (!parseColorParameters(value, colorValues, false)) |
|
3597 |
return false; |
|
3598 |
c = makeRGB(colorValues[0], colorValues[1], colorValues[2]); |
|
3599 |
} else if (!svg) { |
|
3600 |
if (value->unit == CSSParserValue::Function && |
|
3601 |
value->function->args != 0 && |
|
3602 |
value->function->args->size() == 7 /* rgba + three commas */ && |
|
3603 |
equalIgnoringCase(value->function->name, "rgba(")) { |
|
3604 |
int colorValues[4]; |
|
3605 |
if (!parseColorParameters(value, colorValues, true)) |
|
3606 |
return false; |
|
3607 |
c = makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]); |
|
3608 |
} else if (value->unit == CSSParserValue::Function && |
|
3609 |
value->function->args != 0 && |
|
3610 |
value->function->args->size() == 5 /* hsl + two commas */ && |
|
3611 |
equalIgnoringCase(value->function->name, "hsl(")) { |
|
3612 |
double colorValues[3]; |
|
3613 |
if (!parseHSLParameters(value, colorValues, false)) |
|
3614 |
return false; |
|
3615 |
c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0); |
|
3616 |
} else if (value->unit == CSSParserValue::Function && |
|
3617 |
value->function->args != 0 && |
|
3618 |
value->function->args->size() == 7 /* hsla + three commas */ && |
|
3619 |
equalIgnoringCase(value->function->name, "hsla(")) { |
|
3620 |
double colorValues[4]; |
|
3621 |
if (!parseHSLParameters(value, colorValues, true)) |
|
3622 |
return false; |
|
3623 |
c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]); |
|
3624 |
} else |
|
3625 |
return false; |
|
3626 |
} else |
|
3627 |
return false; |
|
3628 |
||
3629 |
return true; |
|
3630 |
} |
|
3631 |
||
3632 |
// This class tracks parsing state for shadow values. If it goes out of scope (e.g., due to an early return) |
|
3633 |
// without the allowBreak bit being set, then it will clean up all of the objects and destroy them. |
|
3634 |
struct ShadowParseContext { |
|
3635 |
ShadowParseContext(CSSPropertyID prop) |
|
3636 |
: property(prop) |
|
3637 |
, allowX(true) |
|
3638 |
, allowY(false) |
|
3639 |
, allowBlur(false) |
|
3640 |
, allowSpread(false) |
|
3641 |
, allowColor(true) |
|
3642 |
, allowStyle(prop == CSSPropertyWebkitBoxShadow) |
|
3643 |
, allowBreak(true) |
|
3644 |
{ |
|
3645 |
} |
|
3646 |
||
3647 |
bool allowLength() { return allowX || allowY || allowBlur || allowSpread; } |
|
3648 |
||
3649 |
void commitValue() |
|
3650 |
{ |
|
3651 |
// Handle the ,, case gracefully by doing nothing. |
|
3652 |
if (x || y || blur || spread || color || style) { |
|
3653 |
if (!values) |
|
3654 |
values = CSSValueList::createCommaSeparated(); |
|
3655 |
||
3656 |
// Construct the current shadow value and add it to the list. |
|
3657 |
values->append(ShadowValue::create(x.release(), y.release(), blur.release(), spread.release(), style.release(), color.release())); |
|
3658 |
} |
|
3659 |
||
3660 |
// Now reset for the next shadow value. |
|
3661 |
x = 0; |
|
3662 |
y = 0; |
|
3663 |
blur = 0; |
|
3664 |
spread = 0; |
|
3665 |
style = 0; |
|
3666 |
color = 0; |
|
3667 |
||
3668 |
allowX = true; |
|
3669 |
allowColor = true; |
|
3670 |
allowBreak = true; |
|
3671 |
allowY = false; |
|
3672 |
allowBlur = false; |
|
3673 |
allowSpread = false; |
|
3674 |
allowStyle = property == CSSPropertyWebkitBoxShadow; |
|
3675 |
} |
|
3676 |
||
3677 |
void commitLength(CSSParserValue* v) |
|
3678 |
{ |
|
3679 |
RefPtr<CSSPrimitiveValue> val = CSSPrimitiveValue::create(v->fValue, (CSSPrimitiveValue::UnitTypes)v->unit); |
|
3680 |
||
3681 |
if (allowX) { |
|
3682 |
x = val.release(); |
|
3683 |
allowX = false; |
|
3684 |
allowY = true; |
|
3685 |
allowColor = false; |
|
3686 |
allowStyle = false; |
|
3687 |
allowBreak = false; |
|
3688 |
} else if (allowY) { |
|
3689 |
y = val.release(); |
|
3690 |
allowY = false; |
|
3691 |
allowBlur = true; |
|
3692 |
allowColor = true; |
|
3693 |
allowStyle = property == CSSPropertyWebkitBoxShadow; |
|
3694 |
allowBreak = true; |
|
3695 |
} else if (allowBlur) { |
|
3696 |
blur = val.release(); |
|
3697 |
allowBlur = false; |
|
3698 |
allowSpread = property == CSSPropertyWebkitBoxShadow; |
|
3699 |
} else if (allowSpread) { |
|
3700 |
spread = val.release(); |
|
3701 |
allowSpread = false; |
|
3702 |
} |
|
3703 |
} |
|
3704 |
||
3705 |
void commitColor(PassRefPtr<CSSPrimitiveValue> val) |
|
3706 |
{ |
|
3707 |
color = val; |
|
3708 |
allowColor = false; |
|
3709 |
if (allowX) { |
|
3710 |
allowStyle = false; |
|
3711 |
allowBreak = false; |
|
3712 |
} else { |
|
3713 |
allowBlur = false; |
|
3714 |
allowSpread = false; |
|
3715 |
allowStyle = property == CSSPropertyWebkitBoxShadow; |
|
3716 |
} |
|
3717 |
} |
|
3718 |
||
3719 |
void commitStyle(CSSParserValue* v) |
|
3720 |
{ |
|
3721 |
style = CSSPrimitiveValue::createIdentifier(v->id); |
|
3722 |
allowStyle = false; |
|
3723 |
if (allowX) |
|
3724 |
allowBreak = false; |
|
3725 |
else { |
|
3726 |
allowBlur = false; |
|
3727 |
allowSpread = false; |
|
3728 |
allowColor = false; |
|
3729 |
} |
|
3730 |
} |
|
3731 |
||
3732 |
CSSPropertyID property; |
|
3733 |
||
3734 |
RefPtr<CSSValueList> values; |
|
3735 |
RefPtr<CSSPrimitiveValue> x; |
|
3736 |
RefPtr<CSSPrimitiveValue> y; |
|
3737 |
RefPtr<CSSPrimitiveValue> blur; |
|
3738 |
RefPtr<CSSPrimitiveValue> spread; |
|
3739 |
RefPtr<CSSPrimitiveValue> style; |
|
3740 |
RefPtr<CSSPrimitiveValue> color; |
|
3741 |
||
3742 |
bool allowX; |
|
3743 |
bool allowY; |
|
3744 |
bool allowBlur; |
|
3745 |
bool allowSpread; |
|
3746 |
bool allowColor; |
|
3747 |
bool allowStyle; |
|
3748 |
bool allowBreak; |
|
3749 |
}; |
|
3750 |
||
3751 |
bool CSSParser::parseShadow(int propId, bool important) |
|
3752 |
{ |
|
3753 |
ShadowParseContext context(static_cast<CSSPropertyID>(propId)); |
|
3754 |
CSSParserValue* val; |
|
3755 |
while ((val = m_valueList->current())) { |
|
3756 |
// Check for a comma break first. |
|
3757 |
if (val->unit == CSSParserValue::Operator) { |
|
3758 |
if (val->iValue != ',' || !context.allowBreak) |
|
3759 |
// Other operators aren't legal or we aren't done with the current shadow |
|
3760 |
// value. Treat as invalid. |
|
3761 |
return false; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3762 |
#if ENABLE(SVG) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3763 |
// -webkit-shadow does not support multiple values. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3764 |
if (static_cast<CSSPropertyID>(propId) == CSSPropertyWebkitShadow) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3765 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3766 |
#endif |
0 | 3767 |
// The value is good. Commit it. |
3768 |
context.commitValue(); |
|
3769 |
} else if (validUnit(val, FLength, true)) { |
|
3770 |
// We required a length and didn't get one. Invalid. |
|
3771 |
if (!context.allowLength()) |
|
3772 |
return false; |
|
3773 |
||
3774 |
// A length is allowed here. Construct the value and add it. |
|
3775 |
context.commitLength(val); |
|
3776 |
} else if (val->id == CSSValueInset) { |
|
3777 |
if (!context.allowStyle) |
|
3778 |
return false; |
|
3779 |
||
3780 |
context.commitStyle(val); |
|
3781 |
} else { |
|
3782 |
// The only other type of value that's ok is a color value. |
|
3783 |
RefPtr<CSSPrimitiveValue> parsedColor; |
|
3784 |
bool isColor = ((val->id >= CSSValueAqua && val->id <= CSSValueWindowtext) || val->id == CSSValueMenu || |
|
3785 |
(val->id >= CSSValueWebkitFocusRingColor && val->id <= CSSValueWebkitText && !m_strict)); |
|
3786 |
if (isColor) { |
|
3787 |
if (!context.allowColor) |
|
3788 |
return false; |
|
3789 |
parsedColor = CSSPrimitiveValue::createIdentifier(val->id); |
|
3790 |
} |
|
3791 |
||
3792 |
if (!parsedColor) |
|
3793 |
// It's not built-in. Try to parse it as a color. |
|
3794 |
parsedColor = parseColor(val); |
|
3795 |
||
3796 |
if (!parsedColor || !context.allowColor) |
|
3797 |
return false; // This value is not a color or length and is invalid or |
|
3798 |
// it is a color, but a color isn't allowed at this point. |
|
3799 |
||
3800 |
context.commitColor(parsedColor.release()); |
|
3801 |
} |
|
3802 |
||
3803 |
m_valueList->next(); |
|
3804 |
} |
|
3805 |
||
3806 |
if (context.allowBreak) { |
|
3807 |
context.commitValue(); |
|
3808 |
if (context.values->length()) { |
|
3809 |
addProperty(propId, context.values.release(), important); |
|
3810 |
m_valueList->next(); |
|
3811 |
return true; |
|
3812 |
} |
|
3813 |
} |
|
3814 |
||
3815 |
return false; |
|
3816 |
} |
|
3817 |
||
3818 |
bool CSSParser::parseReflect(int propId, bool important) |
|
3819 |
{ |
|
3820 |
// box-reflect: <direction> <offset> <mask> |
|
3821 |
||
3822 |
// Direction comes first. |
|
3823 |
CSSParserValue* val = m_valueList->current(); |
|
3824 |
CSSReflectionDirection direction; |
|
3825 |
switch (val->id) { |
|
3826 |
case CSSValueAbove: |
|
3827 |
direction = ReflectionAbove; |
|
3828 |
break; |
|
3829 |
case CSSValueBelow: |
|
3830 |
direction = ReflectionBelow; |
|
3831 |
break; |
|
3832 |
case CSSValueLeft: |
|
3833 |
direction = ReflectionLeft; |
|
3834 |
break; |
|
3835 |
case CSSValueRight: |
|
3836 |
direction = ReflectionRight; |
|
3837 |
break; |
|
3838 |
default: |
|
3839 |
return false; |
|
3840 |
} |
|
3841 |
||
3842 |
// The offset comes next. |
|
3843 |
val = m_valueList->next(); |
|
3844 |
RefPtr<CSSPrimitiveValue> offset; |
|
3845 |
if (!val) |
|
3846 |
offset = CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX); |
|
3847 |
else { |
|
3848 |
if (!validUnit(val, FLength | FPercent, m_strict)) |
|
3849 |
return false; |
|
3850 |
offset = CSSPrimitiveValue::create(val->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(val->unit)); |
|
3851 |
} |
|
3852 |
||
3853 |
// Now for the mask. |
|
3854 |
RefPtr<CSSValue> mask; |
|
3855 |
val = m_valueList->next(); |
|
3856 |
if (val) { |
|
3857 |
if (!parseBorderImage(propId, important, mask)) |
|
3858 |
return false; |
|
3859 |
} |
|
3860 |
||
3861 |
RefPtr<CSSReflectValue> reflectValue = CSSReflectValue::create(direction, offset.release(), mask.release()); |
|
3862 |
addProperty(propId, reflectValue.release(), important); |
|
3863 |
m_valueList->next(); |
|
3864 |
return true; |
|
3865 |
} |
|
3866 |
||
3867 |
struct BorderImageParseContext { |
|
3868 |
BorderImageParseContext() |
|
3869 |
: m_allowBreak(false) |
|
3870 |
, m_allowNumber(false) |
|
3871 |
, m_allowSlash(false) |
|
3872 |
, m_allowWidth(false) |
|
3873 |
, m_allowRule(false) |
|
3874 |
, m_borderTop(0) |
|
3875 |
, m_borderRight(0) |
|
3876 |
, m_borderBottom(0) |
|
3877 |
, m_borderLeft(0) |
|
3878 |
, m_horizontalRule(0) |
|
3879 |
, m_verticalRule(0) |
|
3880 |
{} |
|
3881 |
||
3882 |
bool allowBreak() const { return m_allowBreak; } |
|
3883 |
bool allowNumber() const { return m_allowNumber; } |
|
3884 |
bool allowSlash() const { return m_allowSlash; } |
|
3885 |
bool allowWidth() const { return m_allowWidth; } |
|
3886 |
bool allowRule() const { return m_allowRule; } |
|
3887 |
||
3888 |
void commitImage(PassRefPtr<CSSValue> image) { m_image = image; m_allowNumber = true; } |
|
3889 |
void commitNumber(CSSParserValue* v) |
|
3890 |
{ |
|
3891 |
PassRefPtr<CSSPrimitiveValue> val = CSSPrimitiveValue::create(v->fValue, (CSSPrimitiveValue::UnitTypes)v->unit); |
|
3892 |
if (!m_top) |
|
3893 |
m_top = val; |
|
3894 |
else if (!m_right) |
|
3895 |
m_right = val; |
|
3896 |
else if (!m_bottom) |
|
3897 |
m_bottom = val; |
|
3898 |
else { |
|
3899 |
ASSERT(!m_left); |
|
3900 |
m_left = val; |
|
3901 |
} |
|
3902 |
||
3903 |
m_allowBreak = m_allowSlash = m_allowRule = true; |
|
3904 |
m_allowNumber = !m_left; |
|
3905 |
} |
|
3906 |
void commitSlash() { m_allowBreak = m_allowSlash = m_allowNumber = false; m_allowWidth = true; } |
|
3907 |
void commitWidth(CSSParserValue* val) |
|
3908 |
{ |
|
3909 |
if (!m_borderTop) |
|
3910 |
m_borderTop = val; |
|
3911 |
else if (!m_borderRight) |
|
3912 |
m_borderRight = val; |
|
3913 |
else if (!m_borderBottom) |
|
3914 |
m_borderBottom = val; |
|
3915 |
else { |
|
3916 |
ASSERT(!m_borderLeft); |
|
3917 |
m_borderLeft = val; |
|
3918 |
} |
|
3919 |
||
3920 |
m_allowBreak = m_allowRule = true; |
|
3921 |
m_allowWidth = !m_borderLeft; |
|
3922 |
} |
|
3923 |
void commitRule(int keyword) |
|
3924 |
{ |
|
3925 |
if (!m_horizontalRule) |
|
3926 |
m_horizontalRule = keyword; |
|
3927 |
else if (!m_verticalRule) |
|
3928 |
m_verticalRule = keyword; |
|
3929 |
m_allowRule = !m_verticalRule; |
|
3930 |
} |
|
3931 |
PassRefPtr<CSSValue> commitBorderImage(CSSParser* p, bool important) |
|
3932 |
{ |
|
3933 |
// We need to clone and repeat values for any omissions. |
|
3934 |
if (!m_right) { |
|
3935 |
m_right = CSSPrimitiveValue::create(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType()); |
|
3936 |
m_bottom = CSSPrimitiveValue::create(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType()); |
|
3937 |
m_left = CSSPrimitiveValue::create(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType()); |
|
3938 |
} |
|
3939 |
if (!m_bottom) { |
|
3940 |
m_bottom = CSSPrimitiveValue::create(m_top->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_top->primitiveType()); |
|
3941 |
m_left = CSSPrimitiveValue::create(m_right->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_right->primitiveType()); |
|
3942 |
} |
|
3943 |
if (!m_left) |
|
3944 |
m_left = CSSPrimitiveValue::create(m_right->getDoubleValue(), (CSSPrimitiveValue::UnitTypes)m_right->primitiveType()); |
|
3945 |
||
3946 |
// Now build a rect value to hold all four of our primitive values. |
|
3947 |
RefPtr<Rect> rect = Rect::create(); |
|
3948 |
rect->setTop(m_top); |
|
3949 |
rect->setRight(m_right); |
|
3950 |
rect->setBottom(m_bottom); |
|
3951 |
rect->setLeft(m_left); |
|
3952 |
||
3953 |
// Fill in STRETCH as the default if it wasn't specified. |
|
3954 |
if (!m_horizontalRule) |
|
3955 |
m_horizontalRule = CSSValueStretch; |
|
3956 |
||
3957 |
// The vertical rule should match the horizontal rule if unspecified. |
|
3958 |
if (!m_verticalRule) |
|
3959 |
m_verticalRule = m_horizontalRule; |
|
3960 |
||
3961 |
// Now we have to deal with the border widths. The best way to deal with these is to actually put these values into a value |
|
3962 |
// list and then make our parsing machinery do the parsing. |
|
3963 |
if (m_borderTop) { |
|
3964 |
CSSParserValueList newList; |
|
3965 |
newList.addValue(*m_borderTop); |
|
3966 |
if (m_borderRight) |
|
3967 |
newList.addValue(*m_borderRight); |
|
3968 |
if (m_borderBottom) |
|
3969 |
newList.addValue(*m_borderBottom); |
|
3970 |
if (m_borderLeft) |
|
3971 |
newList.addValue(*m_borderLeft); |
|
3972 |
CSSParserValueList* oldList = p->m_valueList; |
|
3973 |
p->m_valueList = &newList; |
|
3974 |
p->parseValue(CSSPropertyBorderWidth, important); |
|
3975 |
p->m_valueList = oldList; |
|
3976 |
} |
|
3977 |
||
3978 |
// Make our new border image value now. |
|
3979 |
return CSSBorderImageValue::create(m_image, rect.release(), m_horizontalRule, m_verticalRule); |
|
3980 |
} |
|
3981 |
||
3982 |
bool m_allowBreak; |
|
3983 |
bool m_allowNumber; |
|
3984 |
bool m_allowSlash; |
|
3985 |
bool m_allowWidth; |
|
3986 |
bool m_allowRule; |
|
3987 |
||
3988 |
RefPtr<CSSValue> m_image; |
|
3989 |
||
3990 |
RefPtr<CSSPrimitiveValue> m_top; |
|
3991 |
RefPtr<CSSPrimitiveValue> m_right; |
|
3992 |
RefPtr<CSSPrimitiveValue> m_bottom; |
|
3993 |
RefPtr<CSSPrimitiveValue> m_left; |
|
3994 |
||
3995 |
CSSParserValue* m_borderTop; |
|
3996 |
CSSParserValue* m_borderRight; |
|
3997 |
CSSParserValue* m_borderBottom; |
|
3998 |
CSSParserValue* m_borderLeft; |
|
3999 |
||
4000 |
int m_horizontalRule; |
|
4001 |
int m_verticalRule; |
|
4002 |
}; |
|
4003 |
||
4004 |
bool CSSParser::parseBorderImage(int propId, bool important, RefPtr<CSSValue>& result) |
|
4005 |
{ |
|
4006 |
// Look for an image initially. If the first value is not a URI, then we're done. |
|
4007 |
BorderImageParseContext context; |
|
4008 |
CSSParserValue* val = m_valueList->current(); |
|
4009 |
if (val->unit == CSSPrimitiveValue::CSS_URI && m_styleSheet) { |
|
4010 |
// FIXME: The completeURL call should be done when using the CSSImageValue, |
|
4011 |
// not when creating it. |
|
4012 |
context.commitImage(CSSImageValue::create(m_styleSheet->completeURL(val->string))); |
|
4013 |
} else if (val->unit == CSSParserValue::Function) { |
|
4014 |
RefPtr<CSSValue> value; |
|
4015 |
if ((equalIgnoringCase(val->function->name, "-webkit-gradient(") && parseGradient(value)) || |
|
4016 |
(equalIgnoringCase(val->function->name, "-webkit-canvas(") && parseCanvas(value))) |
|
4017 |
context.commitImage(value); |
|
4018 |
else |
|
4019 |
return false; |
|
4020 |
} else |
|
4021 |
return false; |
|
4022 |
||
4023 |
while ((val = m_valueList->next())) { |
|
4024 |
if (context.allowNumber() && validUnit(val, FInteger|FNonNeg|FPercent, true)) { |
|
4025 |
context.commitNumber(val); |
|
4026 |
} else if (propId == CSSPropertyWebkitBorderImage && context.allowSlash() && val->unit == CSSParserValue::Operator && val->iValue == '/') { |
|
4027 |
context.commitSlash(); |
|
4028 |
} else if (context.allowWidth() && |
|
4029 |
(val->id == CSSValueThin || val->id == CSSValueMedium || val->id == CSSValueThick || validUnit(val, FLength, m_strict))) { |
|
4030 |
context.commitWidth(val); |
|
4031 |
} else if (context.allowRule() && |
|
4032 |
(val->id == CSSValueStretch || val->id == CSSValueRound || val->id == CSSValueRepeat)) { |
|
4033 |
context.commitRule(val->id); |
|
4034 |
} else { |
|
4035 |
// Something invalid was encountered. |
|
4036 |
return false; |
|
4037 |
} |
|
4038 |
} |
|
4039 |
||
4040 |
if (context.allowNumber() && propId != CSSPropertyWebkitBorderImage) { |
|
4041 |
// Allow the slices to be omitted for images that don't fit to a border. We just set the slices to be 0. |
|
4042 |
context.m_top = CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_NUMBER); |
|
4043 |
context.m_allowBreak = true; |
|
4044 |
} |
|
4045 |
||
4046 |
if (context.allowBreak()) { |
|
4047 |
// Need to fully commit as a single value. |
|
4048 |
result = context.commitBorderImage(this, important); |
|
4049 |
return true; |
|
4050 |
} |
|
4051 |
||
4052 |
return false; |
|
4053 |
} |
|
4054 |
||
4055 |
static void completeBorderRadii(RefPtr<CSSPrimitiveValue> radii[4]) |
|
4056 |
{ |
|
4057 |
if (radii[3]) |
|
4058 |
return; |
|
4059 |
if (!radii[2]) { |
|
4060 |
if (!radii[1]) |
|
4061 |
radii[1] = radii[0]; |
|
4062 |
radii[2] = radii[0]; |
|
4063 |
} |
|
4064 |
radii[3] = radii[1]; |
|
4065 |
} |
|
4066 |
||
4067 |
bool CSSParser::parseBorderRadius(int propId, bool important) |
|
4068 |
{ |
|
4069 |
unsigned num = m_valueList->size(); |
|
4070 |
if (num > 9) |
|
4071 |
return false; |
|
4072 |
||
4073 |
RefPtr<CSSPrimitiveValue> radii[2][4]; |
|
4074 |
||
4075 |
unsigned indexAfterSlash = 0; |
|
4076 |
for (unsigned i = 0; i < num; ++i) { |
|
4077 |
CSSParserValue* value = m_valueList->valueAt(i); |
|
4078 |
if (value->unit == CSSParserValue::Operator) { |
|
4079 |
if (value->iValue != '/') |
|
4080 |
return false; |
|
4081 |
||
4082 |
if (!i || indexAfterSlash || i + 1 == num || num > i + 5) |
|
4083 |
return false; |
|
4084 |
||
4085 |
indexAfterSlash = i + 1; |
|
4086 |
completeBorderRadii(radii[0]); |
|
4087 |
continue; |
|
4088 |
} |
|
4089 |
||
4090 |
if (i - indexAfterSlash >= 4) |
|
4091 |
return false; |
|
4092 |
||
4093 |
if (!validUnit(value, FLength, m_strict)) |
|
4094 |
return false; |
|
4095 |
||
4096 |
RefPtr<CSSPrimitiveValue> radius = CSSPrimitiveValue::create(value->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(value->unit)); |
|
4097 |
||
4098 |
if (!indexAfterSlash) { |
|
4099 |
radii[0][i] = radius; |
|
4100 |
||
4101 |
// Legacy syntax: -webkit-border-radius: l1 l2; is equivalent to border-radius: l1 / l2; |
|
4102 |
if (num == 2 && propId == CSSPropertyWebkitBorderRadius) { |
|
4103 |
indexAfterSlash = 1; |
|
4104 |
completeBorderRadii(radii[0]); |
|
4105 |
} |
|
4106 |
} else |
|
4107 |
radii[1][i - indexAfterSlash] = radius.release(); |
|
4108 |
} |
|
4109 |
||
4110 |
if (!indexAfterSlash) { |
|
4111 |
completeBorderRadii(radii[0]); |
|
4112 |
for (unsigned i = 0; i < 4; ++i) |
|
4113 |
radii[1][i] = radii[0][i]; |
|
4114 |
} else |
|
4115 |
completeBorderRadii(radii[1]); |
|
4116 |
||
4117 |
addProperty(CSSPropertyBorderTopLeftRadius, CSSPrimitiveValue::create(Pair::create(radii[0][0].release(), radii[1][0].release())), important); |
|
4118 |
addProperty(CSSPropertyBorderTopRightRadius, CSSPrimitiveValue::create(Pair::create(radii[0][1].release(), radii[1][1].release())), important); |
|
4119 |
addProperty(CSSPropertyBorderBottomRightRadius, CSSPrimitiveValue::create(Pair::create(radii[0][2].release(), radii[1][2].release())), important); |
|
4120 |
addProperty(CSSPropertyBorderBottomLeftRadius, CSSPrimitiveValue::create(Pair::create(radii[0][3].release(), radii[1][3].release())), important); |
|
4121 |
return true; |
|
4122 |
} |
|
4123 |
||
4124 |
bool CSSParser::parseCounter(int propId, int defaultValue, bool important) |
|
4125 |
{ |
|
4126 |
enum { ID, VAL } state = ID; |
|
4127 |
||
4128 |
RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); |
|
4129 |
RefPtr<CSSPrimitiveValue> counterName; |
|
4130 |
||
4131 |
while (true) { |
|
4132 |
CSSParserValue* val = m_valueList->current(); |
|
4133 |
switch (state) { |
|
4134 |
case ID: |
|
4135 |
if (val && val->unit == CSSPrimitiveValue::CSS_IDENT) { |
|
4136 |
counterName = CSSPrimitiveValue::create(val->string, CSSPrimitiveValue::CSS_STRING); |
|
4137 |
state = VAL; |
|
4138 |
m_valueList->next(); |
|
4139 |
continue; |
|
4140 |
} |
|
4141 |
break; |
|
4142 |
case VAL: { |
|
4143 |
int i = defaultValue; |
|
4144 |
if (val && val->unit == CSSPrimitiveValue::CSS_NUMBER) { |
|
4145 |
i = (int)val->fValue; |
|
4146 |
m_valueList->next(); |
|
4147 |
} |
|
4148 |
||
4149 |
list->append(CSSPrimitiveValue::create(Pair::create(counterName.release(), |
|
4150 |
CSSPrimitiveValue::create(i, CSSPrimitiveValue::CSS_NUMBER)))); |
|
4151 |
state = ID; |
|
4152 |
continue; |
|
4153 |
} |
|
4154 |
} |
|
4155 |
break; |
|
4156 |
} |
|
4157 |
||
4158 |
if (list->length() > 0) { |
|
4159 |
addProperty(propId, list.release(), important); |
|
4160 |
return true; |
|
4161 |
} |
|
4162 |
||
4163 |
return false; |
|
4164 |
} |
|
4165 |
||
4166 |
static PassRefPtr<CSSPrimitiveValue> parseGradientPoint(CSSParserValue* a, bool horizontal) |
|
4167 |
{ |
|
4168 |
RefPtr<CSSPrimitiveValue> result; |
|
4169 |
if (a->unit == CSSPrimitiveValue::CSS_IDENT) { |
|
4170 |
if ((equalIgnoringCase(a->string, "left") && horizontal) || |
|
4171 |
(equalIgnoringCase(a->string, "top") && !horizontal)) |
|
4172 |
result = CSSPrimitiveValue::create(0., CSSPrimitiveValue::CSS_PERCENTAGE); |
|
4173 |
else if ((equalIgnoringCase(a->string, "right") && horizontal) || |
|
4174 |
(equalIgnoringCase(a->string, "bottom") && !horizontal)) |
|
4175 |
result = CSSPrimitiveValue::create(100., CSSPrimitiveValue::CSS_PERCENTAGE); |
|
4176 |
else if (equalIgnoringCase(a->string, "center")) |
|
4177 |
result = CSSPrimitiveValue::create(50., CSSPrimitiveValue::CSS_PERCENTAGE); |
|
4178 |
} else if (a->unit == CSSPrimitiveValue::CSS_NUMBER || a->unit == CSSPrimitiveValue::CSS_PERCENTAGE) |
|
4179 |
result = CSSPrimitiveValue::create(a->fValue, (CSSPrimitiveValue::UnitTypes)a->unit); |
|
4180 |
return result; |
|
4181 |
} |
|
4182 |
||
4183 |
static bool parseGradientColorStop(CSSParser* p, CSSParserValue* a, CSSGradientColorStop& stop) |
|
4184 |
{ |
|
4185 |
if (a->unit != CSSParserValue::Function) |
|
4186 |
return false; |
|
4187 |
||
4188 |
if (!equalIgnoringCase(a->function->name, "from(") && |
|
4189 |
!equalIgnoringCase(a->function->name, "to(") && |
|
4190 |
!equalIgnoringCase(a->function->name, "color-stop(")) |
|
4191 |
return false; |
|
4192 |
||
4193 |
CSSParserValueList* args = a->function->args; |
|
4194 |
if (!args) |
|
4195 |
return false; |
|
4196 |
||
4197 |
if (equalIgnoringCase(a->function->name, "from(") || |
|
4198 |
equalIgnoringCase(a->function->name, "to(")) { |
|
4199 |
// The "from" and "to" stops expect 1 argument. |
|
4200 |
if (args->size() != 1) |
|
4201 |
return false; |
|
4202 |
||
4203 |
if (equalIgnoringCase(a->function->name, "from(")) |
|
4204 |
stop.m_stop = 0.f; |
|
4205 |
else |
|
4206 |
stop.m_stop = 1.f; |
|
4207 |
||
4208 |
int id = args->current()->id; |
|
4209 |
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu) |
|
4210 |
stop.m_color = CSSPrimitiveValue::createIdentifier(id); |
|
4211 |
else |
|
4212 |
stop.m_color = p->parseColor(args->current()); |
|
4213 |
if (!stop.m_color) |
|
4214 |
return false; |
|
4215 |
} |
|
4216 |
||
4217 |
// The "color-stop" function expects 3 arguments. |
|
4218 |
if (equalIgnoringCase(a->function->name, "color-stop(")) { |
|
4219 |
if (args->size() != 3) |
|
4220 |
return false; |
|
4221 |
||
4222 |
CSSParserValue* stopArg = args->current(); |
|
4223 |
if (stopArg->unit == CSSPrimitiveValue::CSS_PERCENTAGE) |
|
4224 |
stop.m_stop = (float)stopArg->fValue / 100.f; |
|
4225 |
else if (stopArg->unit == CSSPrimitiveValue::CSS_NUMBER) |
|
4226 |
stop.m_stop = (float)stopArg->fValue; |
|
4227 |
else |
|
4228 |
return false; |
|
4229 |
||
4230 |
stopArg = args->next(); |
|
4231 |
if (stopArg->unit != CSSParserValue::Operator || stopArg->iValue != ',') |
|
4232 |
return false; |
|
4233 |
||
4234 |
stopArg = args->next(); |
|
4235 |
int id = stopArg->id; |
|
4236 |
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu) |
|
4237 |
stop.m_color = CSSPrimitiveValue::createIdentifier(id); |
|
4238 |
else |
|
4239 |
stop.m_color = p->parseColor(stopArg); |
|
4240 |
if (!stop.m_color) |
|
4241 |
return false; |
|
4242 |
} |
|
4243 |
||
4244 |
return true; |
|
4245 |
} |
|
4246 |
||
4247 |
bool CSSParser::parseGradient(RefPtr<CSSValue>& gradient) |
|
4248 |
{ |
|
4249 |
RefPtr<CSSGradientValue> result = CSSGradientValue::create(); |
|
4250 |
||
4251 |
// Walk the arguments. |
|
4252 |
CSSParserValueList* args = m_valueList->current()->function->args; |
|
4253 |
if (!args || args->size() == 0) |
|
4254 |
return false; |
|
4255 |
||
4256 |
// The first argument is the gradient type. It is an identifier. |
|
4257 |
CSSParserValue* a = args->current(); |
|
4258 |
if (!a || a->unit != CSSPrimitiveValue::CSS_IDENT) |
|
4259 |
return false; |
|
4260 |
if (equalIgnoringCase(a->string, "linear")) |
|
4261 |
result->setType(CSSLinearGradient); |
|
4262 |
else if (equalIgnoringCase(a->string, "radial")) |
|
4263 |
result->setType(CSSRadialGradient); |
|
4264 |
else |
|
4265 |
return false; |
|
4266 |
||
4267 |
// Comma. |
|
4268 |
a = args->next(); |
|
4269 |
if (!a || a->unit != CSSParserValue::Operator || a->iValue != ',') |
|
4270 |
return false; |
|
4271 |
||
4272 |
// Next comes the starting point for the gradient as an x y pair. There is no |
|
4273 |
// comma between the x and the y values. |
|
4274 |
// First X. It can be left, right, number or percent. |
|
4275 |
a = args->next(); |
|
4276 |
if (!a) |
|
4277 |
return false; |
|
4278 |
RefPtr<CSSPrimitiveValue> point = parseGradientPoint(a, true); |
|
4279 |
if (!point) |
|
4280 |
return false; |
|
4281 |
result->setFirstX(point.release()); |
|
4282 |
||
4283 |
// First Y. It can be top, bottom, number or percent. |
|
4284 |
a = args->next(); |
|
4285 |
if (!a) |
|
4286 |
return false; |
|
4287 |
point = parseGradientPoint(a, false); |
|
4288 |
if (!point) |
|
4289 |
return false; |
|
4290 |
result->setFirstY(point.release()); |
|
4291 |
||
4292 |
// Comma after the first point. |
|
4293 |
a = args->next(); |
|
4294 |
if (!a || a->unit != CSSParserValue::Operator || a->iValue != ',') |
|
4295 |
return false; |
|
4296 |
||
4297 |
// For radial gradients only, we now expect a numeric radius. |
|
4298 |
if (result->type() == CSSRadialGradient) { |
|
4299 |
a = args->next(); |
|
4300 |
if (!a || a->unit != CSSPrimitiveValue::CSS_NUMBER) |
|
4301 |
return false; |
|
4302 |
result->setFirstRadius(CSSPrimitiveValue::create(a->fValue, CSSPrimitiveValue::CSS_NUMBER)); |
|
4303 |
||
4304 |
// Comma after the first radius. |
|
4305 |
a = args->next(); |
|
4306 |
if (!a || a->unit != CSSParserValue::Operator || a->iValue != ',') |
|
4307 |
return false; |
|
4308 |
} |
|
4309 |
||
4310 |
// Next is the ending point for the gradient as an x, y pair. |
|
4311 |
// Second X. It can be left, right, number or percent. |
|
4312 |
a = args->next(); |
|
4313 |
if (!a) |
|
4314 |
return false; |
|
4315 |
point = parseGradientPoint(a, true); |
|
4316 |
if (!point) |
|
4317 |
return false; |
|
4318 |
result->setSecondX(point.release()); |
|
4319 |
||
4320 |
// Second Y. It can be top, bottom, number or percent. |
|
4321 |
a = args->next(); |
|
4322 |
if (!a) |
|
4323 |
return false; |
|
4324 |
point = parseGradientPoint(a, false); |
|
4325 |
if (!point) |
|
4326 |
return false; |
|
4327 |
result->setSecondY(point.release()); |
|
4328 |
||
4329 |
// For radial gradients only, we now expect the second radius. |
|
4330 |
if (result->type() == CSSRadialGradient) { |
|
4331 |
// Comma after the second point. |
|
4332 |
a = args->next(); |
|
4333 |
if (!a || a->unit != CSSParserValue::Operator || a->iValue != ',') |
|
4334 |
return false; |
|
4335 |
||
4336 |
a = args->next(); |
|
4337 |
if (!a || a->unit != CSSPrimitiveValue::CSS_NUMBER) |
|
4338 |
return false; |
|
4339 |
result->setSecondRadius(CSSPrimitiveValue::create(a->fValue, CSSPrimitiveValue::CSS_NUMBER)); |
|
4340 |
} |
|
4341 |
||
4342 |
// We now will accept any number of stops (0 or more). |
|
4343 |
a = args->next(); |
|
4344 |
while (a) { |
|
4345 |
// Look for the comma before the next stop. |
|
4346 |
if (a->unit != CSSParserValue::Operator || a->iValue != ',') |
|
4347 |
return false; |
|
4348 |
||
4349 |
// Now examine the stop itself. |
|
4350 |
a = args->next(); |
|
4351 |
if (!a) |
|
4352 |
return false; |
|
4353 |
||
4354 |
// The function name needs to be one of "from", "to", or "color-stop." |
|
4355 |
CSSGradientColorStop stop; |
|
4356 |
if (!parseGradientColorStop(this, a, stop)) |
|
4357 |
return false; |
|
4358 |
result->addStop(stop); |
|
4359 |
||
4360 |
// Advance |
|
4361 |
a = args->next(); |
|
4362 |
} |
|
4363 |
||
4364 |
gradient = result.release(); |
|
4365 |
return true; |
|
4366 |
} |
|
4367 |
||
4368 |
bool CSSParser::parseCanvas(RefPtr<CSSValue>& canvas) |
|
4369 |
{ |
|
4370 |
RefPtr<CSSCanvasValue> result = CSSCanvasValue::create(); |
|
4371 |
||
4372 |
// Walk the arguments. |
|
4373 |
CSSParserValueList* args = m_valueList->current()->function->args; |
|
4374 |
if (!args || args->size() != 1) |
|
4375 |
return false; |
|
4376 |
||
4377 |
// The first argument is the canvas name. It is an identifier. |
|
4378 |
CSSParserValue* a = args->current(); |
|
4379 |
if (!a || a->unit != CSSPrimitiveValue::CSS_IDENT) |
|
4380 |
return false; |
|
4381 |
result->setName(a->string); |
|
4382 |
canvas = result; |
|
4383 |
return true; |
|
4384 |
} |
|
4385 |
||
4386 |
class TransformOperationInfo { |
|
4387 |
public: |
|
4388 |
TransformOperationInfo(const CSSParserString& name) |
|
4389 |
: m_type(WebKitCSSTransformValue::UnknownTransformOperation) |
|
4390 |
, m_argCount(1) |
|
4391 |
, m_allowSingleArgument(false) |
|
4392 |
, m_unit(CSSParser::FUnknown) |
|
4393 |
{ |
|
4394 |
if (equalIgnoringCase(name, "scale(") || equalIgnoringCase(name, "scalex(") || equalIgnoringCase(name, "scaley(") || equalIgnoringCase(name, "scalez(")) { |
|
4395 |
m_unit = CSSParser::FNumber; |
|
4396 |
if (equalIgnoringCase(name, "scale(")) |
|
4397 |
m_type = WebKitCSSTransformValue::ScaleTransformOperation; |
|
4398 |
else if (equalIgnoringCase(name, "scalex(")) |
|
4399 |
m_type = WebKitCSSTransformValue::ScaleXTransformOperation; |
|
4400 |
else if (equalIgnoringCase(name, "scaley(")) |
|
4401 |
m_type = WebKitCSSTransformValue::ScaleYTransformOperation; |
|
4402 |
else |
|
4403 |
m_type = WebKitCSSTransformValue::ScaleZTransformOperation; |
|
4404 |
} else if (equalIgnoringCase(name, "scale3d(")) { |
|
4405 |
m_type = WebKitCSSTransformValue::Scale3DTransformOperation; |
|
4406 |
m_argCount = 5; |
|
4407 |
m_unit = CSSParser::FNumber; |
|
4408 |
} else if (equalIgnoringCase(name, "rotate(")) { |
|
4409 |
m_type = WebKitCSSTransformValue::RotateTransformOperation; |
|
4410 |
m_unit = CSSParser::FAngle; |
|
4411 |
} else if (equalIgnoringCase(name, "rotatex(") || |
|
4412 |
equalIgnoringCase(name, "rotatey(") || |
|
4413 |
equalIgnoringCase(name, "rotatez(")) { |
|
4414 |
m_unit = CSSParser::FAngle; |
|
4415 |
if (equalIgnoringCase(name, "rotatex(")) |
|
4416 |
m_type = WebKitCSSTransformValue::RotateXTransformOperation; |
|
4417 |
else if (equalIgnoringCase(name, "rotatey(")) |
|
4418 |
m_type = WebKitCSSTransformValue::RotateYTransformOperation; |
|
4419 |
else |
|
4420 |
m_type = WebKitCSSTransformValue::RotateZTransformOperation; |
|
4421 |
} else if (equalIgnoringCase(name, "rotate3d(")) { |
|
4422 |
m_type = WebKitCSSTransformValue::Rotate3DTransformOperation; |
|
4423 |
m_argCount = 7; |
|
4424 |
m_unit = CSSParser::FNumber; |
|
4425 |
} else if (equalIgnoringCase(name, "skew(") || equalIgnoringCase(name, "skewx(") || equalIgnoringCase(name, "skewy(")) { |
|
4426 |
m_unit = CSSParser::FAngle; |
|
4427 |
if (equalIgnoringCase(name, "skew(")) |
|
4428 |
m_type = WebKitCSSTransformValue::SkewTransformOperation; |
|
4429 |
else if (equalIgnoringCase(name, "skewx(")) |
|
4430 |
m_type = WebKitCSSTransformValue::SkewXTransformOperation; |
|
4431 |
else |
|
4432 |
m_type = WebKitCSSTransformValue::SkewYTransformOperation; |
|
4433 |
} else if (equalIgnoringCase(name, "translate(") || equalIgnoringCase(name, "translatex(") || equalIgnoringCase(name, "translatey(") || equalIgnoringCase(name, "translatez(")) { |
|
4434 |
m_unit = CSSParser::FLength | CSSParser::FPercent; |
|
4435 |
if (equalIgnoringCase(name, "translate(")) |
|
4436 |
m_type = WebKitCSSTransformValue::TranslateTransformOperation; |
|
4437 |
else if (equalIgnoringCase(name, "translatex(")) |
|
4438 |
m_type = WebKitCSSTransformValue::TranslateXTransformOperation; |
|
4439 |
else if (equalIgnoringCase(name, "translatey(")) |
|
4440 |
m_type = WebKitCSSTransformValue::TranslateYTransformOperation; |
|
4441 |
else |
|
4442 |
m_type = WebKitCSSTransformValue::TranslateZTransformOperation; |
|
4443 |
} else if (equalIgnoringCase(name, "translate3d(")) { |
|
4444 |
m_type = WebKitCSSTransformValue::Translate3DTransformOperation; |
|
4445 |
m_argCount = 5; |
|
4446 |
m_unit = CSSParser::FLength | CSSParser::FPercent; |
|
4447 |
} else if (equalIgnoringCase(name, "matrix(")) { |
|
4448 |
m_type = WebKitCSSTransformValue::MatrixTransformOperation; |
|
4449 |
m_argCount = 11; |
|
4450 |
m_unit = CSSParser::FNumber; |
|
4451 |
} else if (equalIgnoringCase(name, "matrix3d(")) { |
|
4452 |
m_type = WebKitCSSTransformValue::Matrix3DTransformOperation; |
|
4453 |
m_argCount = 31; |
|
4454 |
m_unit = CSSParser::FNumber; |
|
4455 |
} else if (equalIgnoringCase(name, "perspective(")) { |
|
4456 |
m_type = WebKitCSSTransformValue::PerspectiveTransformOperation; |
|
4457 |
m_unit = CSSParser::FNumber; |
|
4458 |
} |
|
4459 |
||
4460 |
if (equalIgnoringCase(name, "scale(") || equalIgnoringCase(name, "skew(") || equalIgnoringCase(name, "translate(")) { |
|
4461 |
m_allowSingleArgument = true; |
|
4462 |
m_argCount = 3; |
|
4463 |
} |
|
4464 |
} |
|
4465 |
||
4466 |
WebKitCSSTransformValue::TransformOperationType type() const { return m_type; } |
|
4467 |
unsigned argCount() const { return m_argCount; } |
|
4468 |
CSSParser::Units unit() const { return m_unit; } |
|
4469 |
||
4470 |
bool unknown() const { return m_type == WebKitCSSTransformValue::UnknownTransformOperation; } |
|
4471 |
bool hasCorrectArgCount(unsigned argCount) { return m_argCount == argCount || (m_allowSingleArgument && argCount == 1); } |
|
4472 |
||
4473 |
private: |
|
4474 |
WebKitCSSTransformValue::TransformOperationType m_type; |
|
4475 |
unsigned m_argCount; |
|
4476 |
bool m_allowSingleArgument; |
|
4477 |
CSSParser::Units m_unit; |
|
4478 |
}; |
|
4479 |
||
4480 |
PassRefPtr<CSSValueList> CSSParser::parseTransform() |
|
4481 |
{ |
|
4482 |
if (!m_valueList) |
|
4483 |
return 0; |
|
4484 |
||
4485 |
// The transform is a list of functional primitives that specify transform operations. |
|
4486 |
// We collect a list of WebKitCSSTransformValues, where each value specifies a single operation. |
|
4487 |
RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); |
|
4488 |
for (CSSParserValue* value = m_valueList->current(); value; value = m_valueList->next()) { |
|
4489 |
if (value->unit != CSSParserValue::Function || !value->function) |
|
4490 |
return 0; |
|
4491 |
||
4492 |
// Every primitive requires at least one argument. |
|
4493 |
CSSParserValueList* args = value->function->args; |
|
4494 |
if (!args) |
|
4495 |
return 0; |
|
4496 |
||
4497 |
// See if the specified primitive is one we understand. |
|
4498 |
TransformOperationInfo info(value->function->name); |
|
4499 |
if (info.unknown()) |
|
4500 |
return 0; |
|
4501 |
||
4502 |
if (!info.hasCorrectArgCount(args->size())) |
|
4503 |
return 0; |
|
4504 |
||
4505 |
// Create the new WebKitCSSTransformValue for this operation and add it to our list. |
|
4506 |
RefPtr<WebKitCSSTransformValue> transformValue = WebKitCSSTransformValue::create(info.type()); |
|
4507 |
list->append(transformValue); |
|
4508 |
||
4509 |
// Snag our values. |
|
4510 |
CSSParserValue* a = args->current(); |
|
4511 |
unsigned argNumber = 0; |
|
4512 |
while (a) { |
|
4513 |
CSSParser::Units unit = info.unit(); |
|
4514 |
||
4515 |
// 4th param of rotate3d() is an angle rather than a bare number, validate it as such |
|
4516 |
if (info.type() == WebKitCSSTransformValue::Rotate3DTransformOperation && argNumber == 3) { |
|
4517 |
if (!validUnit(a, FAngle, true)) |
|
4518 |
return 0; |
|
4519 |
} else if (!validUnit(a, unit, true)) |
|
4520 |
return 0; |
|
4521 |
||
4522 |
// Add the value to the current transform operation. |
|
4523 |
transformValue->append(CSSPrimitiveValue::create(a->fValue, (CSSPrimitiveValue::UnitTypes) a->unit)); |
|
4524 |
||
4525 |
a = args->next(); |
|
4526 |
if (!a) |
|
4527 |
break; |
|
4528 |
if (a->unit != CSSParserValue::Operator || a->iValue != ',') |
|
4529 |
return 0; |
|
4530 |
a = args->next(); |
|
4531 |
||
4532 |
argNumber++; |
|
4533 |
} |
|
4534 |
} |
|
4535 |
||
4536 |
return list.release(); |
|
4537 |
} |
|
4538 |
||
4539 |
bool CSSParser::parseTransformOrigin(int propId, int& propId1, int& propId2, int& propId3, RefPtr<CSSValue>& value, RefPtr<CSSValue>& value2, RefPtr<CSSValue>& value3) |
|
4540 |
{ |
|
4541 |
propId1 = propId; |
|
4542 |
propId2 = propId; |
|
4543 |
propId3 = propId; |
|
4544 |
if (propId == CSSPropertyWebkitTransformOrigin) { |
|
4545 |
propId1 = CSSPropertyWebkitTransformOriginX; |
|
4546 |
propId2 = CSSPropertyWebkitTransformOriginY; |
|
4547 |
propId3 = CSSPropertyWebkitTransformOriginZ; |
|
4548 |
} |
|
4549 |
||
4550 |
switch (propId) { |
|
4551 |
case CSSPropertyWebkitTransformOrigin: |
|
4552 |
parseTransformOriginShorthand(value, value2, value3); |
|
4553 |
// parseTransformOriginShorthand advances the m_valueList pointer |
|
4554 |
break; |
|
4555 |
case CSSPropertyWebkitTransformOriginX: { |
|
4556 |
bool xFound = false, yFound = true; |
|
4557 |
value = parseFillPositionXY(xFound, yFound); |
|
4558 |
if (value) |
|
4559 |
m_valueList->next(); |
|
4560 |
break; |
|
4561 |
} |
|
4562 |
case CSSPropertyWebkitTransformOriginY: { |
|
4563 |
bool xFound = true, yFound = false; |
|
4564 |
value = parseFillPositionXY(xFound, yFound); |
|
4565 |
if (value) |
|
4566 |
m_valueList->next(); |
|
4567 |
break; |
|
4568 |
} |
|
4569 |
case CSSPropertyWebkitTransformOriginZ: { |
|
4570 |
if (validUnit(m_valueList->current(), FLength, m_strict)) |
|
4571 |
value = CSSPrimitiveValue::create(m_valueList->current()->fValue, (CSSPrimitiveValue::UnitTypes)m_valueList->current()->unit); |
|
4572 |
if (value) |
|
4573 |
m_valueList->next(); |
|
4574 |
break; |
|
4575 |
} |
|
4576 |
} |
|
4577 |
||
4578 |
return value; |
|
4579 |
} |
|
4580 |
||
4581 |
bool CSSParser::parsePerspectiveOrigin(int propId, int& propId1, int& propId2, RefPtr<CSSValue>& value, RefPtr<CSSValue>& value2) |
|
4582 |
{ |
|
4583 |
propId1 = propId; |
|
4584 |
propId2 = propId; |
|
4585 |
if (propId == CSSPropertyWebkitPerspectiveOrigin) { |
|
4586 |
propId1 = CSSPropertyWebkitPerspectiveOriginX; |
|
4587 |
propId2 = CSSPropertyWebkitPerspectiveOriginY; |
|
4588 |
} |
|
4589 |
||
4590 |
switch (propId) { |
|
4591 |
case CSSPropertyWebkitPerspectiveOrigin: |
|
4592 |
parseFillPosition(value, value2); |
|
4593 |
break; |
|
4594 |
case CSSPropertyWebkitPerspectiveOriginX: { |
|
4595 |
bool xFound = false, yFound = true; |
|
4596 |
value = parseFillPositionXY(xFound, yFound); |
|
4597 |
if (value) |
|
4598 |
m_valueList->next(); |
|
4599 |
break; |
|
4600 |
} |
|
4601 |
case CSSPropertyWebkitPerspectiveOriginY: { |
|
4602 |
bool xFound = true, yFound = false; |
|
4603 |
value = parseFillPositionXY(xFound, yFound); |
|
4604 |
if (value) |
|
4605 |
m_valueList->next(); |
|
4606 |
break; |
|
4607 |
} |
|
4608 |
} |
|
4609 |
||
4610 |
return value; |
|
4611 |
} |
|
4612 |
||
4613 |
static inline int yyerror(const char*) { return 1; } |
|
4614 |
||
4615 |
#define END_TOKEN 0 |
|
4616 |
||
4617 |
#include "CSSGrammar.h" |
|
4618 |
||
4619 |
int CSSParser::lex(void* yylvalWithoutType) |
|
4620 |
{ |
|
4621 |
YYSTYPE* yylval = static_cast<YYSTYPE*>(yylvalWithoutType); |
|
4622 |
int token = lex(); |
|
4623 |
int length; |
|
4624 |
UChar* t = text(&length); |
|
4625 |
||
4626 |
switch (token) { |
|
4627 |
case WHITESPACE: |
|
4628 |
case SGML_CD: |
|
4629 |
case INCLUDES: |
|
4630 |
case DASHMATCH: |
|
4631 |
break; |
|
4632 |
||
4633 |
case URI: |
|
4634 |
case STRING: |
|
4635 |
case IDENT: |
|
4636 |
case NTH: |
|
4637 |
case HEX: |
|
4638 |
case IDSEL: |
|
4639 |
case DIMEN: |
|
4640 |
case UNICODERANGE: |
|
4641 |
case FUNCTION: |
|
4642 |
case NOTFUNCTION: |
|
4643 |
case VARCALL: |
|
4644 |
yylval->string.characters = t; |
|
4645 |
yylval->string.length = length; |
|
4646 |
break; |
|
4647 |
||
4648 |
case IMPORT_SYM: |
|
4649 |
case PAGE_SYM: |
|
4650 |
case MEDIA_SYM: |
|
4651 |
case FONT_FACE_SYM: |
|
4652 |
case CHARSET_SYM: |
|
4653 |
case NAMESPACE_SYM: |
|
4654 |
case WEBKIT_KEYFRAMES_SYM: |
|
4655 |
||
4656 |
case IMPORTANT_SYM: |
|
4657 |
break; |
|
4658 |
||
4659 |
case QEMS: |
|
4660 |
length--; |
|
4661 |
case GRADS: |
|
4662 |
case TURNS: |
|
4663 |
length--; |
|
4664 |
case DEGS: |
|
4665 |
case RADS: |
|
4666 |
case KHERZ: |
|
4667 |
case REMS: |
|
4668 |
length--; |
|
4669 |
case MSECS: |
|
4670 |
case HERZ: |
|
4671 |
case EMS: |
|
4672 |
case EXS: |
|
4673 |
case PXS: |
|
4674 |
case CMS: |
|
4675 |
case MMS: |
|
4676 |
case INS: |
|
4677 |
case PTS: |
|
4678 |
case PCS: |
|
4679 |
length--; |
|
4680 |
case SECS: |
|
4681 |
case PERCENTAGE: |
|
4682 |
length--; |
|
4683 |
case FLOATTOKEN: |
|
4684 |
case INTEGER: |
|
4685 |
yylval->number = charactersToDouble(t, length); |
|
4686 |
break; |
|
4687 |
||
4688 |
default: |
|
4689 |
break; |
|
4690 |
} |
|
4691 |
||
4692 |
return token; |
|
4693 |
} |
|
4694 |
||
4695 |
static inline bool isCSSWhitespace(UChar c) |
|
4696 |
{ |
|
4697 |
return c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\f'; |
|
4698 |
} |
|
4699 |
||
4700 |
UChar* CSSParser::text(int *length) |
|
4701 |
{ |
|
4702 |
UChar* start = yytext; |
|
4703 |
int l = yyleng; |
|
4704 |
switch (yyTok) { |
|
4705 |
case STRING: |
|
4706 |
l--; |
|
4707 |
/* nobreak */ |
|
4708 |
case HEX: |
|
4709 |
case IDSEL: |
|
4710 |
start++; |
|
4711 |
l--; |
|
4712 |
break; |
|
4713 |
case URI: |
|
4714 |
// "url("{w}{string}{w}")" |
|
4715 |
// "url("{w}{url}{w}")" |
|
4716 |
// strip "url(" and ")" |
|
4717 |
start += 4; |
|
4718 |
l -= 5; |
|
4719 |
// strip {w} |
|
4720 |
while (l && isCSSWhitespace(*start)) { |
|
4721 |
++start; |
|
4722 |
--l; |
|
4723 |
} |
|
4724 |
while (l && isCSSWhitespace(start[l - 1])) |
|
4725 |
--l; |
|
4726 |
if (l && (*start == '"' || *start == '\'')) { |
|
4727 |
ASSERT(l >= 2 && start[l - 1] == *start); |
|
4728 |
++start; |
|
4729 |
l -= 2; |
|
4730 |
} |
|
4731 |
break; |
|
4732 |
case VARCALL: |
|
4733 |
// "-webkit-var("{w}{ident}{w}")" |
|
4734 |
// strip "-webkit-var(" and ")" |
|
4735 |
start += 12; |
|
4736 |
l -= 13; |
|
4737 |
// strip {w} |
|
4738 |
while (l && isCSSWhitespace(*start)) { |
|
4739 |
++start; |
|
4740 |
--l; |
|
4741 |
} |
|
4742 |
while (l && isCSSWhitespace(start[l - 1])) |
|
4743 |
--l; |
|
4744 |
break; |
|
4745 |
default: |
|
4746 |
break; |
|
4747 |
} |
|
4748 |
||
4749 |
// process escapes |
|
4750 |
UChar* out = start; |
|
4751 |
UChar* escape = 0; |
|
4752 |
||
4753 |
for (int i = 0; i < l; i++) { |
|
4754 |
UChar* current = start + i; |
|
4755 |
if (escape == current - 1) { |
|
4756 |
if (isASCIIHexDigit(*current)) |
|
4757 |
continue; |
|
4758 |
if (yyTok == STRING && |
|
4759 |
(*current == '\n' || *current == '\r' || *current == '\f')) { |
|
4760 |
// ### handle \r\n case |
|
4761 |
if (*current != '\r') |
|
4762 |
escape = 0; |
|
4763 |
continue; |
|
4764 |
} |
|
4765 |
// in all other cases copy the char to output |
|
4766 |
// ### |
|
4767 |
*out++ = *current; |
|
4768 |
escape = 0; |
|
4769 |
continue; |
|
4770 |
} |
|
4771 |
if (escape == current - 2 && yyTok == STRING && |
|
4772 |
*(current-1) == '\r' && *current == '\n') { |
|
4773 |
escape = 0; |
|
4774 |
continue; |
|
4775 |
} |
|
4776 |
if (escape > current - 7 && isASCIIHexDigit(*current)) |
|
4777 |
continue; |
|
4778 |
if (escape) { |
|
4779 |
// add escaped char |
|
4780 |
unsigned uc = 0; |
|
4781 |
escape++; |
|
4782 |
while (escape < current) { |
|
4783 |
uc *= 16; |
|
4784 |
uc += toASCIIHexValue(*escape); |
|
4785 |
escape++; |
|
4786 |
} |
|
4787 |
// can't handle chars outside ucs2 |
|
4788 |
if (uc > 0xffff) |
|
4789 |
uc = 0xfffd; |
|
4790 |
*out++ = uc; |
|
4791 |
escape = 0; |
|
4792 |
if (isCSSWhitespace(*current)) |
|
4793 |
continue; |
|
4794 |
} |
|
4795 |
if (!escape && *current == '\\') { |
|
4796 |
escape = current; |
|
4797 |
continue; |
|
4798 |
} |
|
4799 |
*out++ = *current; |
|
4800 |
} |
|
4801 |
if (escape) { |
|
4802 |
// add escaped char |
|
4803 |
unsigned uc = 0; |
|
4804 |
escape++; |
|
4805 |
while (escape < start+l) { |
|
4806 |
uc *= 16; |
|
4807 |
uc += toASCIIHexValue(*escape); |
|
4808 |
escape++; |
|
4809 |
} |
|
4810 |
// can't handle chars outside ucs2 |
|
4811 |
if (uc > 0xffff) |
|
4812 |
uc = 0xfffd; |
|
4813 |
*out++ = uc; |
|
4814 |
} |
|
4815 |
||
4816 |
*length = out - start; |
|
4817 |
return start; |
|
4818 |
} |
|
4819 |
||
4820 |
CSSSelector* CSSParser::createFloatingSelector() |
|
4821 |
{ |
|
4822 |
CSSSelector* selector = fastNew<CSSSelector>(); |
|
4823 |
m_floatingSelectors.add(selector); |
|
4824 |
return selector; |
|
4825 |
} |
|
4826 |
||
4827 |
CSSSelector* CSSParser::sinkFloatingSelector(CSSSelector* selector) |
|
4828 |
{ |
|
4829 |
if (selector) { |
|
4830 |
ASSERT(m_floatingSelectors.contains(selector)); |
|
4831 |
m_floatingSelectors.remove(selector); |
|
4832 |
} |
|
4833 |
return selector; |
|
4834 |
} |
|
4835 |
||
4836 |
CSSParserValueList* CSSParser::createFloatingValueList() |
|
4837 |
{ |
|
4838 |
CSSParserValueList* list = new CSSParserValueList; |
|
4839 |
m_floatingValueLists.add(list); |
|
4840 |
return list; |
|
4841 |
} |
|
4842 |
||
4843 |
CSSParserValueList* CSSParser::sinkFloatingValueList(CSSParserValueList* list) |
|
4844 |
{ |
|
4845 |
if (list) { |
|
4846 |
ASSERT(m_floatingValueLists.contains(list)); |
|
4847 |
m_floatingValueLists.remove(list); |
|
4848 |
} |
|
4849 |
return list; |
|
4850 |
} |
|
4851 |
||
4852 |
CSSParserFunction* CSSParser::createFloatingFunction() |
|
4853 |
{ |
|
4854 |
CSSParserFunction* function = new CSSParserFunction; |
|
4855 |
m_floatingFunctions.add(function); |
|
4856 |
return function; |
|
4857 |
} |
|
4858 |
||
4859 |
CSSParserFunction* CSSParser::sinkFloatingFunction(CSSParserFunction* function) |
|
4860 |
{ |
|
4861 |
if (function) { |
|
4862 |
ASSERT(m_floatingFunctions.contains(function)); |
|
4863 |
m_floatingFunctions.remove(function); |
|
4864 |
} |
|
4865 |
return function; |
|
4866 |
} |
|
4867 |
||
4868 |
CSSParserValue& CSSParser::sinkFloatingValue(CSSParserValue& value) |
|
4869 |
{ |
|
4870 |
if (value.unit == CSSParserValue::Function) { |
|
4871 |
ASSERT(m_floatingFunctions.contains(value.function)); |
|
4872 |
m_floatingFunctions.remove(value.function); |
|
4873 |
} |
|
4874 |
return value; |
|
4875 |
} |
|
4876 |
||
4877 |
MediaQueryExp* CSSParser::createFloatingMediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* values) |
|
4878 |
{ |
|
4879 |
delete m_floatingMediaQueryExp; |
|
4880 |
m_floatingMediaQueryExp = new MediaQueryExp(mediaFeature, values); |
|
4881 |
return m_floatingMediaQueryExp; |
|
4882 |
} |
|
4883 |
||
4884 |
MediaQueryExp* CSSParser::sinkFloatingMediaQueryExp(MediaQueryExp* e) |
|
4885 |
{ |
|
4886 |
ASSERT(e == m_floatingMediaQueryExp); |
|
4887 |
m_floatingMediaQueryExp = 0; |
|
4888 |
return e; |
|
4889 |
} |
|
4890 |
||
4891 |
Vector<MediaQueryExp*>* CSSParser::createFloatingMediaQueryExpList() |
|
4892 |
{ |
|
4893 |
if (m_floatingMediaQueryExpList) { |
|
4894 |
deleteAllValues(*m_floatingMediaQueryExpList); |
|
4895 |
delete m_floatingMediaQueryExpList; |
|
4896 |
} |
|
4897 |
m_floatingMediaQueryExpList = new Vector<MediaQueryExp*>; |
|
4898 |
return m_floatingMediaQueryExpList; |
|
4899 |
} |
|
4900 |
||
4901 |
Vector<MediaQueryExp*>* CSSParser::sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>* l) |
|
4902 |
{ |
|
4903 |
ASSERT(l == m_floatingMediaQueryExpList); |
|
4904 |
m_floatingMediaQueryExpList = 0; |
|
4905 |
return l; |
|
4906 |
} |
|
4907 |
||
4908 |
MediaQuery* CSSParser::createFloatingMediaQuery(MediaQuery::Restrictor r, const String& mediaType, Vector<MediaQueryExp*>* exprs) |
|
4909 |
{ |
|
4910 |
delete m_floatingMediaQuery; |
|
4911 |
m_floatingMediaQuery = new MediaQuery(r, mediaType, exprs); |
|
4912 |
return m_floatingMediaQuery; |
|
4913 |
} |
|
4914 |
||
4915 |
MediaQuery* CSSParser::createFloatingMediaQuery(Vector<MediaQueryExp*>* exprs) |
|
4916 |
{ |
|
4917 |
return createFloatingMediaQuery(MediaQuery::None, "all", exprs); |
|
4918 |
} |
|
4919 |
||
4920 |
MediaQuery* CSSParser::sinkFloatingMediaQuery(MediaQuery* mq) |
|
4921 |
{ |
|
4922 |
ASSERT(mq == m_floatingMediaQuery); |
|
4923 |
m_floatingMediaQuery = 0; |
|
4924 |
return mq; |
|
4925 |
} |
|
4926 |
||
4927 |
MediaList* CSSParser::createMediaList() |
|
4928 |
{ |
|
4929 |
RefPtr<MediaList> list = MediaList::create(); |
|
4930 |
MediaList* result = list.get(); |
|
4931 |
m_parsedStyleObjects.append(list.release()); |
|
4932 |
return result; |
|
4933 |
} |
|
4934 |
||
4935 |
CSSRule* CSSParser::createCharsetRule(const CSSParserString& charset) |
|
4936 |
{ |
|
4937 |
if (!m_styleSheet) |
|
4938 |
return 0; |
|
4939 |
RefPtr<CSSCharsetRule> rule = CSSCharsetRule::create(m_styleSheet, charset); |
|
4940 |
CSSCharsetRule* result = rule.get(); |
|
4941 |
m_parsedStyleObjects.append(rule.release()); |
|
4942 |
return result; |
|
4943 |
} |
|
4944 |
||
4945 |
CSSRule* CSSParser::createImportRule(const CSSParserString& url, MediaList* media) |
|
4946 |
{ |
|
4947 |
if (!media || !m_styleSheet) |
|
4948 |
return 0; |
|
4949 |
RefPtr<CSSImportRule> rule = CSSImportRule::create(m_styleSheet, url, media); |
|
4950 |
CSSImportRule* result = rule.get(); |
|
4951 |
m_parsedStyleObjects.append(rule.release()); |
|
4952 |
return result; |
|
4953 |
} |
|
4954 |
||
4955 |
CSSRule* CSSParser::createMediaRule(MediaList* media, CSSRuleList* rules) |
|
4956 |
{ |
|
4957 |
if (!media || !rules || !m_styleSheet) |
|
4958 |
return 0; |
|
4959 |
RefPtr<CSSMediaRule> rule = CSSMediaRule::create(m_styleSheet, media, rules); |
|
4960 |
CSSMediaRule* result = rule.get(); |
|
4961 |
m_parsedStyleObjects.append(rule.release()); |
|
4962 |
return result; |
|
4963 |
} |
|
4964 |
||
4965 |
CSSRuleList* CSSParser::createRuleList() |
|
4966 |
{ |
|
4967 |
RefPtr<CSSRuleList> list = CSSRuleList::create(); |
|
4968 |
CSSRuleList* listPtr = list.get(); |
|
4969 |
||
4970 |
m_parsedRuleLists.append(list.release()); |
|
4971 |
return listPtr; |
|
4972 |
} |
|
4973 |
||
4974 |
WebKitCSSKeyframesRule* CSSParser::createKeyframesRule() |
|
4975 |
{ |
|
4976 |
RefPtr<WebKitCSSKeyframesRule> rule = WebKitCSSKeyframesRule::create(m_styleSheet); |
|
4977 |
WebKitCSSKeyframesRule* rulePtr = rule.get(); |
|
4978 |
m_parsedStyleObjects.append(rule.release()); |
|
4979 |
return rulePtr; |
|
4980 |
} |
|
4981 |
||
4982 |
CSSRule* CSSParser::createStyleRule(Vector<CSSSelector*>* selectors) |
|
4983 |
{ |
|
4984 |
CSSStyleRule* result = 0; |
|
4985 |
if (selectors) { |
|
4986 |
RefPtr<CSSStyleRule> rule = CSSStyleRule::create(m_styleSheet); |
|
4987 |
rule->adoptSelectorVector(*selectors); |
|
4988 |
if (m_hasFontFaceOnlyValues) |
|
4989 |
deleteFontFaceOnlyValues(); |
|
4990 |
rule->setDeclaration(CSSMutableStyleDeclaration::create(rule.get(), m_parsedProperties, m_numParsedProperties)); |
|
4991 |
result = rule.get(); |
|
4992 |
m_parsedStyleObjects.append(rule.release()); |
|
4993 |
} |
|
4994 |
clearProperties(); |
|
4995 |
return result; |
|
4996 |
} |
|
4997 |
||
4998 |
CSSRule* CSSParser::createFontFaceRule() |
|
4999 |
{ |
|
5000 |
RefPtr<CSSFontFaceRule> rule = CSSFontFaceRule::create(m_styleSheet); |
|
5001 |
for (unsigned i = 0; i < m_numParsedProperties; ++i) { |
|
5002 |
CSSProperty* property = m_parsedProperties[i]; |
|
5003 |
int id = property->id(); |
|
5004 |
if ((id == CSSPropertyFontWeight || id == CSSPropertyFontStyle || id == CSSPropertyFontVariant) && property->value()->isPrimitiveValue()) { |
|
5005 |
RefPtr<CSSValue> value = property->m_value.release(); |
|
5006 |
property->m_value = CSSValueList::createCommaSeparated(); |
|
5007 |
static_cast<CSSValueList*>(property->m_value.get())->append(value.release()); |
|
5008 |
} |
|
5009 |
} |
|
5010 |
rule->setDeclaration(CSSMutableStyleDeclaration::create(rule.get(), m_parsedProperties, m_numParsedProperties)); |
|
5011 |
clearProperties(); |
|
5012 |
CSSFontFaceRule* result = rule.get(); |
|
5013 |
m_parsedStyleObjects.append(rule.release()); |
|
5014 |
return result; |
|
5015 |
} |
|
5016 |
||
5017 |
#if !ENABLE(CSS_VARIABLES) |
|
5018 |
||
5019 |
CSSRule* CSSParser::createVariablesRule(MediaList*, bool) |
|
5020 |
{ |
|
5021 |
return 0; |
|
5022 |
} |
|
5023 |
||
5024 |
bool CSSParser::addVariable(const CSSParserString&, CSSParserValueList*) |
|
5025 |
{ |
|
5026 |
return false; |
|
5027 |
} |
|
5028 |
||
5029 |
bool CSSParser::addVariableDeclarationBlock(const CSSParserString&) |
|
5030 |
{ |
|
5031 |
return false; |
|
5032 |
} |
|
5033 |
||
5034 |
#else |
|
5035 |
||
5036 |
CSSRule* CSSParser::createVariablesRule(MediaList* mediaList, bool variablesKeyword) |
|
5037 |
{ |
|
5038 |
RefPtr<CSSVariablesRule> rule = CSSVariablesRule::create(m_styleSheet, mediaList, variablesKeyword); |
|
5039 |
rule->setDeclaration(CSSVariablesDeclaration::create(rule.get(), m_variableNames, m_variableValues)); |
|
5040 |
clearVariables(); |
|
5041 |
CSSRule* result = rule.get(); |
|
5042 |
m_parsedStyleObjects.append(rule.release()); |
|
5043 |
return result; |
|
5044 |
} |
|
5045 |
||
5046 |
bool CSSParser::addVariable(const CSSParserString& name, CSSParserValueList* valueList) |
|
5047 |
{ |
|
5048 |
if (checkForVariables(valueList)) { |
|
5049 |
delete valueList; |
|
5050 |
return false; |
|
5051 |
} |
|
5052 |
m_variableNames.append(String(name)); |
|
5053 |
m_variableValues.append(CSSValueList::createFromParserValueList(valueList)); |
|
5054 |
return true; |
|
5055 |
} |
|
5056 |
||
5057 |
bool CSSParser::addVariableDeclarationBlock(const CSSParserString&) |
|
5058 |
{ |
|
5059 |
// FIXME: Disabling declarations as variable values for now since they no longer have a common base class with CSSValues. |
|
5060 |
#if 0 |
|
5061 |
m_variableNames.append(String(name)); |
|
5062 |
m_variableValues.append(CSSMutableStyleDeclaration::create(0, m_parsedProperties, m_numParsedProperties)); |
|
5063 |
clearProperties(); |
|
5064 |
#endif |
|
5065 |
return true; |
|
5066 |
} |
|
5067 |
||
5068 |
#endif |
|
5069 |
||
5070 |
void CSSParser::clearVariables() |
|
5071 |
{ |
|
5072 |
m_variableNames.clear(); |
|
5073 |
m_variableValues.clear(); |
|
5074 |
} |
|
5075 |
||
5076 |
bool CSSParser::parseVariable(CSSVariablesDeclaration* declaration, const String& variableName, const String& variableValue) |
|
5077 |
{ |
|
5078 |
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet()); |
|
5079 |
||
5080 |
String nameValuePair = variableName + ": "; |
|
5081 |
nameValuePair += variableValue; |
|
5082 |
||
5083 |
setupParser("@-webkit-variables-decls{", nameValuePair, "} "); |
|
5084 |
cssyyparse(this); |
|
5085 |
m_rule = 0; |
|
5086 |
||
5087 |
bool ok = false; |
|
5088 |
if (m_variableNames.size()) { |
|
5089 |
ok = true; |
|
5090 |
declaration->addParsedVariable(variableName, m_variableValues[0]); |
|
5091 |
} |
|
5092 |
||
5093 |
clearVariables(); |
|
5094 |
||
5095 |
return ok; |
|
5096 |
} |
|
5097 |
||
5098 |
void CSSParser::parsePropertyWithResolvedVariables(int propId, bool isImportant, CSSMutableStyleDeclaration* declaration, CSSParserValueList* list) |
|
5099 |
{ |
|
5100 |
m_valueList = list; |
|
5101 |
m_styleSheet = static_cast<CSSStyleSheet*>(declaration->stylesheet()); |
|
5102 |
||
5103 |
if (parseValue(propId, isImportant)) |
|
5104 |
declaration->addParsedProperties(m_parsedProperties, m_numParsedProperties); |
|
5105 |
||
5106 |
clearProperties(); |
|
5107 |
m_valueList = 0; |
|
5108 |
} |
|
5109 |
||
5110 |
bool CSSParser::checkForVariables(CSSParserValueList* valueList) |
|
5111 |
{ |
|
5112 |
if (!valueList || !valueList->containsVariables()) |
|
5113 |
return false; |
|
5114 |
||
5115 |
bool hasVariables = false; |
|
5116 |
for (unsigned i = 0; i < valueList->size(); ++i) { |
|
5117 |
if (valueList->valueAt(i)->isVariable()) { |
|
5118 |
hasVariables = true; |
|
5119 |
break; |
|
5120 |
} |
|
5121 |
||
5122 |
if (valueList->valueAt(i)->unit == CSSParserValue::Function && checkForVariables(valueList->valueAt(i)->function->args)) { |
|
5123 |
hasVariables = true; |
|
5124 |
break; |
|
5125 |
} |
|
5126 |
} |
|
5127 |
||
5128 |
return hasVariables; |
|
5129 |
} |
|
5130 |
||
5131 |
void CSSParser::addUnresolvedProperty(int propId, bool important) |
|
5132 |
{ |
|
5133 |
RefPtr<CSSVariableDependentValue> val = CSSVariableDependentValue::create(CSSValueList::createFromParserValueList(m_valueList)); |
|
5134 |
addProperty(propId, val.release(), important); |
|
5135 |
} |
|
5136 |
||
5137 |
void CSSParser::deleteFontFaceOnlyValues() |
|
5138 |
{ |
|
5139 |
ASSERT(m_hasFontFaceOnlyValues); |
|
5140 |
int deletedProperties = 0; |
|
5141 |
||
5142 |
for (unsigned i = 0; i < m_numParsedProperties; ++i) { |
|
5143 |
CSSProperty* property = m_parsedProperties[i]; |
|
5144 |
int id = property->id(); |
|
5145 |
if ((id == CSSPropertyFontWeight || id == CSSPropertyFontStyle || id == CSSPropertyFontVariant) && property->value()->isValueList()) { |
|
5146 |
delete property; |
|
5147 |
deletedProperties++; |
|
5148 |
} else if (deletedProperties) |
|
5149 |
m_parsedProperties[i - deletedProperties] = m_parsedProperties[i]; |
|
5150 |
} |
|
5151 |
||
5152 |
m_numParsedProperties -= deletedProperties; |
|
5153 |
} |
|
5154 |
||
5155 |
WebKitCSSKeyframeRule* CSSParser::createKeyframeRule(CSSParserValueList* keys) |
|
5156 |
{ |
|
5157 |
// Create a key string from the passed keys |
|
5158 |
String keyString; |
|
5159 |
for (unsigned i = 0; i < keys->size(); ++i) { |
|
5160 |
float key = (float) keys->valueAt(i)->fValue; |
|
5161 |
if (i != 0) |
|
5162 |
keyString += ","; |
|
5163 |
keyString += String::number(key); |
|
5164 |
keyString += "%"; |
|
5165 |
} |
|
5166 |
||
5167 |
RefPtr<WebKitCSSKeyframeRule> keyframe = WebKitCSSKeyframeRule::create(m_styleSheet); |
|
5168 |
keyframe->setKeyText(keyString); |
|
5169 |
keyframe->setDeclaration(CSSMutableStyleDeclaration::create(0, m_parsedProperties, m_numParsedProperties)); |
|
5170 |
||
5171 |
clearProperties(); |
|
5172 |
||
5173 |
WebKitCSSKeyframeRule* keyframePtr = keyframe.get(); |
|
5174 |
m_parsedStyleObjects.append(keyframe.release()); |
|
5175 |
return keyframePtr; |
|
5176 |
} |
|
5177 |
||
5178 |
static int cssPropertyID(const UChar* propertyName, unsigned length) |
|
5179 |
{ |
|
5180 |
if (!length) |
|
5181 |
return 0; |
|
5182 |
if (length > maxCSSPropertyNameLength) |
|
5183 |
return 0; |
|
5184 |
||
5185 |
char buffer[maxCSSPropertyNameLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character |
|
5186 |
||
5187 |
for (unsigned i = 0; i != length; ++i) { |
|
5188 |
UChar c = propertyName[i]; |
|
5189 |
if (c == 0 || c >= 0x7F) |
|
5190 |
return 0; // illegal character |
|
5191 |
buffer[i] = toASCIILower(c); |
|
5192 |
} |
|
5193 |
buffer[length] = '\0'; |
|
5194 |
||
5195 |
const char* name = buffer; |
|
5196 |
if (buffer[0] == '-') { |
|
5197 |
// If the prefix is -apple- or -khtml-, change it to -webkit-. |
|
5198 |
// This makes the string one character longer. |
|
5199 |
if (hasPrefix(buffer, length, "-apple-") || hasPrefix(buffer, length, "-khtml-")) { |
|
5200 |
memmove(buffer + 7, buffer + 6, length + 1 - 6); |
|
5201 |
memcpy(buffer, "-webkit", 7); |
|
5202 |
++length; |
|
5203 |
} |
|
5204 |
||
5205 |
if (hasPrefix(buffer, length, "-webkit")) { |
|
5206 |
if (strcmp(buffer, "-webkit-opacity") == 0) { |
|
5207 |
// Honor -webkit-opacity as a synonym for opacity. |
|
5208 |
// This was the only syntax that worked in Safari 1.1, and may be in use on some websites and widgets. |
|
5209 |
const char* const opacity = "opacity"; |
|
5210 |
name = opacity; |
|
5211 |
length = strlen(opacity); |
|
5212 |
} else if (hasPrefix(buffer + 7, length - 7, "-border-")) { |
|
5213 |
// -webkit-border-*-*-radius worked in Safari 4 and earlier. -webkit-border-radius syntax |
|
5214 |
// differs from border-radius, so it is remains as a distinct property. |
|
5215 |
if (!strcmp(buffer + 15, "top-left-radius") |
|
5216 |
|| !strcmp(buffer + 15, "top-right-radius") |
|
5217 |
|| !strcmp(buffer + 15, "bottom-right-radius") |
|
5218 |
|| !strcmp(buffer + 15, "bottom-left-radius")) { |
|
5219 |
name = buffer + 8; |
|
5220 |
length -= 8; |
|
5221 |
} |
|
5222 |
} |
|
5223 |
} |
|
5224 |
} |
|
5225 |
||
5226 |
const props* hashTableEntry = findProp(name, length); |
|
5227 |
return hashTableEntry ? hashTableEntry->id : 0; |
|
5228 |
} |
|
5229 |
||
5230 |
int cssPropertyID(const String& string) |
|
5231 |
{ |
|
5232 |
return cssPropertyID(string.characters(), string.length()); |
|
5233 |
} |
|
5234 |
||
5235 |
int cssPropertyID(const CSSParserString& string) |
|
5236 |
{ |
|
5237 |
return cssPropertyID(string.characters, string.length); |
|
5238 |
} |
|
5239 |
||
5240 |
int cssValueKeywordID(const CSSParserString& string) |
|
5241 |
{ |
|
5242 |
unsigned length = string.length; |
|
5243 |
if (!length) |
|
5244 |
return 0; |
|
5245 |
if (length > maxCSSValueKeywordLength) |
|
5246 |
return 0; |
|
5247 |
||
5248 |
char buffer[maxCSSValueKeywordLength + 1 + 1]; // 1 to turn "apple"/"khtml" into "webkit", 1 for null character |
|
5249 |
||
5250 |
for (unsigned i = 0; i != length; ++i) { |
|
5251 |
UChar c = string.characters[i]; |
|
5252 |
if (c == 0 || c >= 0x7F) |
|
5253 |
return 0; // illegal character |
|
5254 |
buffer[i] = WTF::toASCIILower(c); |
|
5255 |
} |
|
5256 |
buffer[length] = '\0'; |
|
5257 |
||
5258 |
if (buffer[0] == '-') { |
|
5259 |
// If the prefix is -apple- or -khtml-, change it to -webkit-. |
|
5260 |
// This makes the string one character longer. |
|
5261 |
if (hasPrefix(buffer, length, "-apple-") || hasPrefix(buffer, length, "-khtml-")) { |
|
5262 |
memmove(buffer + 7, buffer + 6, length + 1 - 6); |
|
5263 |
memcpy(buffer, "-webkit", 7); |
|
5264 |
++length; |
|
5265 |
} |
|
5266 |
} |
|
5267 |
||
5268 |
const css_value* hashTableEntry = findValue(buffer, length); |
|
5269 |
return hashTableEntry ? hashTableEntry->id : 0; |
|
5270 |
} |
|
5271 |
||
5272 |
#define YY_DECL int CSSParser::lex() |
|
5273 |
#define yyconst const |
|
5274 |
typedef int yy_state_type; |
|
5275 |
typedef unsigned YY_CHAR; |
|
5276 |
// The following line makes sure we treat non-Latin-1 Unicode characters correctly. |
|
5277 |
#define YY_SC_TO_UI(c) (c > 0xff ? 0xff : c) |
|
5278 |
#define YY_DO_BEFORE_ACTION \ |
|
5279 |
yytext = yy_bp; \ |
|
5280 |
yyleng = (int) (yy_cp - yy_bp); \ |
|
5281 |
yy_hold_char = *yy_cp; \ |
|
5282 |
*yy_cp = 0; \ |
|
5283 |
yy_c_buf_p = yy_cp; |
|
5284 |
#define YY_BREAK break; |
|
5285 |
#define ECHO |
|
5286 |
#define YY_RULE_SETUP |
|
5287 |
#define INITIAL 0 |
|
5288 |
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) |
|
5289 |
#define yyterminate() yyTok = END_TOKEN; return yyTok |
|
5290 |
#define YY_FATAL_ERROR(a) |
|
5291 |
// The following line is needed to build the tokenizer with a condition stack. |
|
5292 |
// The macro is used in the tokenizer grammar with lines containing |
|
5293 |
// BEGIN(mediaqueries) and BEGIN(initial). yy_start acts as index to |
|
5294 |
// tokenizer transition table, and 'mediaqueries' and 'initial' are |
|
5295 |
// offset multipliers that specify which transitions are active |
|
5296 |
// in the tokenizer during in each condition (tokenizer state). |
|
5297 |
#define BEGIN yy_start = 1 + 2 * |
|
5298 |
||
5299 |
#include "tokenizer.cpp" |
|
5300 |
||
5301 |
} |