| OLD | NEW |
| (Empty) |
| 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, 2010, 2011, 2012 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.torchmo
bile.com/) | |
| 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. | |
| 9 * Copyright (C) 2012 Intel Corporation. All rights reserved. | |
| 10 * | |
| 11 * This library is free software; you can redistribute it and/or | |
| 12 * modify it under the terms of the GNU Library General Public | |
| 13 * License as published by the Free Software Foundation; either | |
| 14 * version 2 of the License, or (at your option) any later version. | |
| 15 * | |
| 16 * This library is distributed in the hope that it will be useful, | |
| 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 19 * Library General Public License for more details. | |
| 20 * | |
| 21 * You should have received a copy of the GNU Library General Public License | |
| 22 * along with this library; see the file COPYING.LIB. If not, write to | |
| 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 24 * Boston, MA 02110-1301, USA. | |
| 25 */ | |
| 26 | |
| 27 #include "config.h" | |
| 28 #include "core/css/CSSParser.h" | |
| 29 | |
| 30 #include "CSSValueKeywords.h" | |
| 31 #include "RuntimeEnabledFeatures.h" | |
| 32 #include "StylePropertyShorthand.h" | |
| 33 #include "core/css/CSSArrayFunctionValue.h" | |
| 34 #include "core/css/CSSAspectRatioValue.h" | |
| 35 #include "core/css/CSSBasicShapes.h" | |
| 36 #include "core/css/CSSBorderImage.h" | |
| 37 #include "core/css/CSSCanvasValue.h" | |
| 38 #include "core/css/CSSCrossfadeValue.h" | |
| 39 #include "core/css/CSSCursorImageValue.h" | |
| 40 #include "core/css/CSSFontFaceSrcValue.h" | |
| 41 #include "core/css/CSSFontFeatureValue.h" | |
| 42 #include "core/css/CSSFunctionValue.h" | |
| 43 #include "core/css/CSSGradientValue.h" | |
| 44 #include "core/css/CSSGridLineNamesValue.h" | |
| 45 #include "core/css/CSSGridTemplateValue.h" | |
| 46 #include "core/css/CSSImageSetValue.h" | |
| 47 #include "core/css/CSSImageValue.h" | |
| 48 #include "core/css/CSSInheritedValue.h" | |
| 49 #include "core/css/CSSInitialValue.h" | |
| 50 #include "core/css/CSSKeyframeRule.h" | |
| 51 #include "core/css/CSSKeyframesRule.h" | |
| 52 #include "core/css/CSSLineBoxContainValue.h" | |
| 53 #include "core/css/CSSMixFunctionValue.h" | |
| 54 #include "core/css/CSSPrimitiveValue.h" | |
| 55 #include "core/css/CSSPropertySourceData.h" | |
| 56 #include "core/css/CSSReflectValue.h" | |
| 57 #include "core/css/CSSSVGDocumentValue.h" | |
| 58 #include "core/css/CSSSelector.h" | |
| 59 #include "core/css/CSSShaderValue.h" | |
| 60 #include "core/css/CSSShadowValue.h" | |
| 61 #include "core/css/CSSStyleSheet.h" | |
| 62 #include "core/css/CSSTimingFunctionValue.h" | |
| 63 #include "core/css/CSSTransformValue.h" | |
| 64 #include "core/css/CSSUnicodeRangeValue.h" | |
| 65 #include "core/css/CSSValueList.h" | |
| 66 #include "core/css/CSSValuePool.h" | |
| 67 #include "core/css/CSSVariableValue.h" | |
| 68 #include "core/css/Counter.h" | |
| 69 #include "core/css/HashTools.h" | |
| 70 #include "core/css/MediaList.h" | |
| 71 #include "core/css/MediaQueryExp.h" | |
| 72 #include "core/css/Pair.h" | |
| 73 #include "core/css/Rect.h" | |
| 74 #include "core/css/StylePropertySet.h" | |
| 75 #include "core/css/StyleRule.h" | |
| 76 #include "core/css/StyleRuleImport.h" | |
| 77 #include "core/css/StyleSheetContents.h" | |
| 78 #include "core/css/parser/CSSParserIdioms.h" | |
| 79 #include "core/dom/Document.h" | |
| 80 #include "core/frame/FrameHost.h" | |
| 81 #include "core/frame/PageConsole.h" | |
| 82 #include "core/frame/Settings.h" | |
| 83 #include "core/html/parser/HTMLParserIdioms.h" | |
| 84 #include "core/inspector/InspectorInstrumentation.h" | |
| 85 #include "core/rendering/RenderTheme.h" | |
| 86 #include "core/svg/SVGParserUtilities.h" | |
| 87 #include "platform/FloatConversion.h" | |
| 88 #include "wtf/BitArray.h" | |
| 89 #include "wtf/HexNumber.h" | |
| 90 #include "wtf/text/StringBuffer.h" | |
| 91 #include "wtf/text/StringBuilder.h" | |
| 92 #include "wtf/text/StringImpl.h" | |
| 93 #include "wtf/text/TextEncoding.h" | |
| 94 #include <limits.h> | |
| 95 | |
| 96 #define YYDEBUG 0 | |
| 97 | |
| 98 #if YYDEBUG > 0 | |
| 99 extern int cssyydebug; | |
| 100 #endif | |
| 101 | |
| 102 extern int cssyyparse(WebCore::CSSParser*); | |
| 103 | |
| 104 using namespace std; | |
| 105 using namespace WTF; | |
| 106 | |
| 107 namespace WebCore { | |
| 108 | |
| 109 static const unsigned INVALID_NUM_PARSED_PROPERTIES = UINT_MAX; | |
| 110 static const double MAX_SCALE = 1000000; | |
| 111 | |
| 112 template <unsigned N> | |
| 113 static bool equal(const CSSParserString& a, const char (&b)[N]) | |
| 114 { | |
| 115 unsigned length = N - 1; // Ignore the trailing null character | |
| 116 if (a.length() != length) | |
| 117 return false; | |
| 118 | |
| 119 return a.is8Bit() ? WTF::equal(a.characters8(), reinterpret_cast<const LChar
*>(b), length) : WTF::equal(a.characters16(), reinterpret_cast<const LChar*>(b),
length); | |
| 120 } | |
| 121 | |
| 122 template <unsigned N> | |
| 123 static bool equalIgnoringCase(const CSSParserString& a, const char (&b)[N]) | |
| 124 { | |
| 125 unsigned length = N - 1; // Ignore the trailing null character | |
| 126 if (a.length() != length) | |
| 127 return false; | |
| 128 | |
| 129 return a.is8Bit() ? WTF::equalIgnoringCase(b, a.characters8(), length) : WTF
::equalIgnoringCase(b, a.characters16(), length); | |
| 130 } | |
| 131 | |
| 132 template <unsigned N> | |
| 133 static bool equalIgnoringCase(CSSParserValue* value, const char (&b)[N]) | |
| 134 { | |
| 135 ASSERT(value->unit == CSSPrimitiveValue::CSS_IDENT || value->unit == CSSPrim
itiveValue::CSS_STRING); | |
| 136 return equalIgnoringCase(value->string, b); | |
| 137 } | |
| 138 | |
| 139 static PassRefPtr<CSSPrimitiveValue> createPrimitiveValuePair(PassRefPtr<CSSPrim
itiveValue> first, PassRefPtr<CSSPrimitiveValue> second, Pair::IdenticalValuesPo
licy identicalValuesPolicy = Pair::DropIdenticalValues) | |
| 140 { | |
| 141 return cssValuePool().createValue(Pair::create(first, second, identicalValue
sPolicy)); | |
| 142 } | |
| 143 | |
| 144 class AnimationParseContext { | |
| 145 public: | |
| 146 AnimationParseContext() | |
| 147 : m_animationPropertyKeywordAllowed(true) | |
| 148 , m_firstAnimationCommitted(false) | |
| 149 , m_hasSeenAnimationPropertyKeyword(false) | |
| 150 { | |
| 151 } | |
| 152 | |
| 153 void commitFirstAnimation() | |
| 154 { | |
| 155 m_firstAnimationCommitted = true; | |
| 156 } | |
| 157 | |
| 158 bool hasCommittedFirstAnimation() const | |
| 159 { | |
| 160 return m_firstAnimationCommitted; | |
| 161 } | |
| 162 | |
| 163 void commitAnimationPropertyKeyword() | |
| 164 { | |
| 165 m_animationPropertyKeywordAllowed = false; | |
| 166 } | |
| 167 | |
| 168 bool animationPropertyKeywordAllowed() const | |
| 169 { | |
| 170 return m_animationPropertyKeywordAllowed; | |
| 171 } | |
| 172 | |
| 173 bool hasSeenAnimationPropertyKeyword() const | |
| 174 { | |
| 175 return m_hasSeenAnimationPropertyKeyword; | |
| 176 } | |
| 177 | |
| 178 void sawAnimationPropertyKeyword() | |
| 179 { | |
| 180 m_hasSeenAnimationPropertyKeyword = true; | |
| 181 } | |
| 182 | |
| 183 private: | |
| 184 bool m_animationPropertyKeywordAllowed; | |
| 185 bool m_firstAnimationCommitted; | |
| 186 bool m_hasSeenAnimationPropertyKeyword; | |
| 187 }; | |
| 188 | |
| 189 CSSParser::CSSParser(const CSSParserContext& context, UseCounter* counter) | |
| 190 : m_context(context) | |
| 191 , m_important(false) | |
| 192 , m_id(CSSPropertyInvalid) | |
| 193 , m_styleSheet(0) | |
| 194 , m_supportsCondition(false) | |
| 195 , m_selectorListForParseSelector(0) | |
| 196 , m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES) | |
| 197 , m_inParseShorthand(0) | |
| 198 , m_currentShorthand(CSSPropertyInvalid) | |
| 199 , m_implicitShorthand(false) | |
| 200 , m_hasFontFaceOnlyValues(false) | |
| 201 , m_hadSyntacticallyValidCSSRule(false) | |
| 202 , m_logErrors(false) | |
| 203 , m_ignoreErrors(false) | |
| 204 , m_inFilterRule(false) | |
| 205 , m_defaultNamespace(starAtom) | |
| 206 , m_observer(0) | |
| 207 , m_source(0) | |
| 208 , m_ruleHeaderType(CSSRuleSourceData::UNKNOWN_RULE) | |
| 209 , m_allowImportRules(true) | |
| 210 , m_allowNamespaceDeclarations(true) | |
| 211 , m_inViewport(false) | |
| 212 , m_useCounter(counter) | |
| 213 , m_tokenizer(*this) | |
| 214 { | |
| 215 #if YYDEBUG > 0 | |
| 216 cssyydebug = 1; | |
| 217 #endif | |
| 218 CSSPropertySourceData::init(); | |
| 219 } | |
| 220 | |
| 221 CSSParser::~CSSParser() | |
| 222 { | |
| 223 clearProperties(); | |
| 224 | |
| 225 deleteAllValues(m_floatingSelectors); | |
| 226 deleteAllValues(m_floatingSelectorVectors); | |
| 227 deleteAllValues(m_floatingValueLists); | |
| 228 deleteAllValues(m_floatingFunctions); | |
| 229 } | |
| 230 | |
| 231 void CSSParser::setupParser(const char* prefix, unsigned prefixLength, const Str
ing& string, const char* suffix, unsigned suffixLength) | |
| 232 { | |
| 233 m_tokenizer.setupTokenizer(prefix, prefixLength, string, suffix, suffixLengt
h); | |
| 234 m_ruleHasHeader = true; | |
| 235 } | |
| 236 | |
| 237 void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, cons
t TextPosition& startPosition, CSSParserObserver* observer, bool logErrors) | |
| 238 { | |
| 239 setStyleSheet(sheet); | |
| 240 m_defaultNamespace = starAtom; // Reset the default namespace. | |
| 241 TemporaryChange<CSSParserObserver*> scopedObsever(m_observer, observer); | |
| 242 m_logErrors = logErrors && sheet->singleOwnerDocument() && !sheet->baseURL()
.isEmpty() && sheet->singleOwnerDocument()->frameHost(); | |
| 243 m_ignoreErrors = false; | |
| 244 m_tokenizer.m_lineNumber = 0; | |
| 245 m_startPosition = startPosition; | |
| 246 m_source = &string; | |
| 247 m_tokenizer.m_internal = false; | |
| 248 setupParser("", string, ""); | |
| 249 cssyyparse(this); | |
| 250 sheet->shrinkToFit(); | |
| 251 m_source = 0; | |
| 252 m_rule = 0; | |
| 253 m_lineEndings.clear(); | |
| 254 m_ignoreErrors = false; | |
| 255 m_logErrors = false; | |
| 256 m_tokenizer.m_internal = true; | |
| 257 } | |
| 258 | |
| 259 PassRefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const
String& string) | |
| 260 { | |
| 261 setStyleSheet(sheet); | |
| 262 m_allowNamespaceDeclarations = false; | |
| 263 setupParser("@-internal-rule ", string, ""); | |
| 264 cssyyparse(this); | |
| 265 return m_rule.release(); | |
| 266 } | |
| 267 | |
| 268 PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet
, const String& string) | |
| 269 { | |
| 270 setStyleSheet(sheet); | |
| 271 setupParser("@-internal-keyframe-rule ", string, ""); | |
| 272 cssyyparse(this); | |
| 273 return m_keyframe.release(); | |
| 274 } | |
| 275 | |
| 276 PassOwnPtr<Vector<double> > CSSParser::parseKeyframeKeyList(const String& string
) | |
| 277 { | |
| 278 setupParser("@-internal-keyframe-key-list ", string, ""); | |
| 279 cssyyparse(this); | |
| 280 ASSERT(m_valueList); | |
| 281 return StyleKeyframe::createKeyList(m_valueList.get()); | |
| 282 } | |
| 283 | |
| 284 bool CSSParser::parseSupportsCondition(const String& string) | |
| 285 { | |
| 286 m_supportsCondition = false; | |
| 287 setupParser("@-internal-supports-condition ", string, ""); | |
| 288 cssyyparse(this); | |
| 289 return m_supportsCondition; | |
| 290 } | |
| 291 | |
| 292 static inline bool isColorPropertyID(CSSPropertyID propertyId) | |
| 293 { | |
| 294 switch (propertyId) { | |
| 295 case CSSPropertyColor: | |
| 296 case CSSPropertyBackgroundColor: | |
| 297 case CSSPropertyBorderBottomColor: | |
| 298 case CSSPropertyBorderLeftColor: | |
| 299 case CSSPropertyBorderRightColor: | |
| 300 case CSSPropertyBorderTopColor: | |
| 301 case CSSPropertyOutlineColor: | |
| 302 case CSSPropertyTextLineThroughColor: | |
| 303 case CSSPropertyTextOverlineColor: | |
| 304 case CSSPropertyTextUnderlineColor: | |
| 305 case CSSPropertyWebkitBorderAfterColor: | |
| 306 case CSSPropertyWebkitBorderBeforeColor: | |
| 307 case CSSPropertyWebkitBorderEndColor: | |
| 308 case CSSPropertyWebkitBorderStartColor: | |
| 309 case CSSPropertyWebkitColumnRuleColor: | |
| 310 case CSSPropertyWebkitTextEmphasisColor: | |
| 311 case CSSPropertyWebkitTextFillColor: | |
| 312 case CSSPropertyWebkitTextStrokeColor: | |
| 313 return true; | |
| 314 case CSSPropertyTextDecorationColor: | |
| 315 return RuntimeEnabledFeatures::css3TextDecorationsEnabled(); | |
| 316 default: | |
| 317 return false; | |
| 318 } | |
| 319 } | |
| 320 | |
| 321 static bool parseColorValue(MutableStylePropertySet* declaration, CSSPropertyID
propertyId, const String& string, bool important, CSSParserMode cssParserMode) | |
| 322 { | |
| 323 ASSERT(!string.isEmpty()); | |
| 324 bool quirksMode = isQuirksModeBehavior(cssParserMode); | |
| 325 if (!isColorPropertyID(propertyId)) | |
| 326 return false; | |
| 327 CSSParserString cssString; | |
| 328 cssString.init(string); | |
| 329 CSSValueID valueID = cssValueKeywordID(cssString); | |
| 330 bool validPrimitive = false; | |
| 331 if (valueID == CSSValueWebkitText) { | |
| 332 validPrimitive = true; | |
| 333 } else if (valueID == CSSValueCurrentcolor) { | |
| 334 validPrimitive = true; | |
| 335 } else if ((valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || val
ueID == CSSValueMenu | |
| 336 || (quirksMode && valueID >= CSSValueWebkitFocusRingColor && valueID < C
SSValueWebkitText)) { | |
| 337 validPrimitive = true; | |
| 338 } | |
| 339 | |
| 340 if (validPrimitive) { | |
| 341 RefPtr<CSSValue> value = cssValuePool().createIdentifierValue(valueID); | |
| 342 declaration->addParsedProperty(CSSProperty(propertyId, value.release(),
important)); | |
| 343 return true; | |
| 344 } | |
| 345 RGBA32 color; | |
| 346 if (!CSSParser::fastParseColor(color, string, !quirksMode && string[0] != '#
')) | |
| 347 return false; | |
| 348 RefPtr<CSSValue> value = cssValuePool().createColorValue(color); | |
| 349 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), impo
rtant)); | |
| 350 return true; | |
| 351 } | |
| 352 | |
| 353 static inline bool isSimpleLengthPropertyID(CSSPropertyID propertyId, bool& acce
ptsNegativeNumbers) | |
| 354 { | |
| 355 switch (propertyId) { | |
| 356 case CSSPropertyFontSize: | |
| 357 case CSSPropertyHeight: | |
| 358 case CSSPropertyWidth: | |
| 359 case CSSPropertyMinHeight: | |
| 360 case CSSPropertyMinWidth: | |
| 361 case CSSPropertyPaddingBottom: | |
| 362 case CSSPropertyPaddingLeft: | |
| 363 case CSSPropertyPaddingRight: | |
| 364 case CSSPropertyPaddingTop: | |
| 365 case CSSPropertyWebkitLogicalWidth: | |
| 366 case CSSPropertyWebkitLogicalHeight: | |
| 367 case CSSPropertyWebkitMinLogicalWidth: | |
| 368 case CSSPropertyWebkitMinLogicalHeight: | |
| 369 case CSSPropertyWebkitPaddingAfter: | |
| 370 case CSSPropertyWebkitPaddingBefore: | |
| 371 case CSSPropertyWebkitPaddingEnd: | |
| 372 case CSSPropertyWebkitPaddingStart: | |
| 373 acceptsNegativeNumbers = false; | |
| 374 return true; | |
| 375 case CSSPropertyShapeMargin: | |
| 376 case CSSPropertyShapePadding: | |
| 377 acceptsNegativeNumbers = false; | |
| 378 return RuntimeEnabledFeatures::cssShapesEnabled(); | |
| 379 case CSSPropertyBottom: | |
| 380 case CSSPropertyLeft: | |
| 381 case CSSPropertyMarginBottom: | |
| 382 case CSSPropertyMarginLeft: | |
| 383 case CSSPropertyMarginRight: | |
| 384 case CSSPropertyMarginTop: | |
| 385 case CSSPropertyRight: | |
| 386 case CSSPropertyTop: | |
| 387 case CSSPropertyWebkitMarginAfter: | |
| 388 case CSSPropertyWebkitMarginBefore: | |
| 389 case CSSPropertyWebkitMarginEnd: | |
| 390 case CSSPropertyWebkitMarginStart: | |
| 391 acceptsNegativeNumbers = true; | |
| 392 return true; | |
| 393 default: | |
| 394 return false; | |
| 395 } | |
| 396 } | |
| 397 | |
| 398 template <typename CharacterType> | |
| 399 static inline bool parseSimpleLength(const CharacterType* characters, unsigned l
ength, CSSPrimitiveValue::UnitTypes& unit, double& number) | |
| 400 { | |
| 401 if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[leng
th - 1] | 0x20) == 'x') { | |
| 402 length -= 2; | |
| 403 unit = CSSPrimitiveValue::CSS_PX; | |
| 404 } else if (length > 1 && characters[length - 1] == '%') { | |
| 405 length -= 1; | |
| 406 unit = CSSPrimitiveValue::CSS_PERCENTAGE; | |
| 407 } | |
| 408 | |
| 409 // We rely on charactersToDouble for validation as well. The function | |
| 410 // will set "ok" to "false" if the entire passed-in character range does | |
| 411 // not represent a double. | |
| 412 bool ok; | |
| 413 number = charactersToDouble(characters, length, &ok); | |
| 414 return ok; | |
| 415 } | |
| 416 | |
| 417 static bool parseSimpleLengthValue(MutableStylePropertySet* declaration, CSSProp
ertyID propertyId, const String& string, bool important, CSSParserMode cssParser
Mode) | |
| 418 { | |
| 419 ASSERT(!string.isEmpty()); | |
| 420 bool acceptsNegativeNumbers; | |
| 421 | |
| 422 // In @viewport, width and height are shorthands, not simple length values. | |
| 423 if (isCSSViewportParsingEnabledForMode(cssParserMode) || !isSimpleLengthProp
ertyID(propertyId, acceptsNegativeNumbers)) | |
| 424 return false; | |
| 425 | |
| 426 unsigned length = string.length(); | |
| 427 double number; | |
| 428 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER; | |
| 429 | |
| 430 if (string.is8Bit()) { | |
| 431 if (!parseSimpleLength(string.characters8(), length, unit, number)) | |
| 432 return false; | |
| 433 } else { | |
| 434 if (!parseSimpleLength(string.characters16(), length, unit, number)) | |
| 435 return false; | |
| 436 } | |
| 437 | |
| 438 if (unit == CSSPrimitiveValue::CSS_NUMBER) { | |
| 439 bool quirksMode = isQuirksModeBehavior(cssParserMode); | |
| 440 if (number && !quirksMode) | |
| 441 return false; | |
| 442 unit = CSSPrimitiveValue::CSS_PX; | |
| 443 } | |
| 444 if (number < 0 && !acceptsNegativeNumbers) | |
| 445 return false; | |
| 446 | |
| 447 RefPtr<CSSValue> value = cssValuePool().createValue(number, unit); | |
| 448 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), impo
rtant)); | |
| 449 return true; | |
| 450 } | |
| 451 | |
| 452 static inline bool isValidKeywordPropertyAndValue(CSSPropertyID propertyId, int
valueID, const CSSParserContext& parserContext) | |
| 453 { | |
| 454 if (!valueID) | |
| 455 return false; | |
| 456 | |
| 457 switch (propertyId) { | |
| 458 case CSSPropertyBorderCollapse: // collapse | separate | inherit | |
| 459 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate) | |
| 460 return true; | |
| 461 break; | |
| 462 case CSSPropertyBorderTopStyle: // <border-style> | inherit | |
| 463 case CSSPropertyBorderRightStyle: // Defined as: none | hidden | dotted | da
shed | | |
| 464 case CSSPropertyBorderBottomStyle: // solid | double | groove | ridge | inse
t | outset | |
| 465 case CSSPropertyBorderLeftStyle: | |
| 466 case CSSPropertyWebkitBorderAfterStyle: | |
| 467 case CSSPropertyWebkitBorderBeforeStyle: | |
| 468 case CSSPropertyWebkitBorderEndStyle: | |
| 469 case CSSPropertyWebkitBorderStartStyle: | |
| 470 case CSSPropertyWebkitColumnRuleStyle: | |
| 471 if (valueID >= CSSValueNone && valueID <= CSSValueDouble) | |
| 472 return true; | |
| 473 break; | |
| 474 case CSSPropertyBoxSizing: | |
| 475 if (valueID == CSSValueBorderBox || valueID == CSSValueContentBox) | |
| 476 return true; | |
| 477 break; | |
| 478 case CSSPropertyCaptionSide: // top | bottom | left | right | inherit | |
| 479 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CS
SValueTop || valueID == CSSValueBottom) | |
| 480 return true; | |
| 481 break; | |
| 482 case CSSPropertyClear: // none | left | right | both | inherit | |
| 483 if (valueID == CSSValueNone || valueID == CSSValueLeft || valueID == CSS
ValueRight || valueID == CSSValueBoth) | |
| 484 return true; | |
| 485 break; | |
| 486 case CSSPropertyDirection: // ltr | rtl | inherit | |
| 487 if (valueID == CSSValueLtr || valueID == CSSValueRtl) | |
| 488 return true; | |
| 489 break; | |
| 490 case CSSPropertyDisplay: | |
| 491 // inline | block | list-item | inline-block | table | | |
| 492 // inline-table | table-row-group | table-header-group | table-footer-gr
oup | table-row | | |
| 493 // table-column-group | table-column | table-cell | table-caption | -web
kit-box | -webkit-inline-box | none | inherit | |
| 494 // flex | inline-flex | -webkit-flex | -webkit-inline-flex | grid | inli
ne-grid | lazy-block | |
| 495 if ((valueID >= CSSValueInline && valueID <= CSSValueInlineFlex) || valu
eID == CSSValueWebkitFlex || valueID == CSSValueWebkitInlineFlex || valueID == C
SSValueNone) | |
| 496 return true; | |
| 497 if (valueID == CSSValueGrid || valueID == CSSValueInlineGrid) | |
| 498 return RuntimeEnabledFeatures::cssGridLayoutEnabled(); | |
| 499 break; | |
| 500 | |
| 501 case CSSPropertyEmptyCells: // show | hide | inherit | |
| 502 if (valueID == CSSValueShow || valueID == CSSValueHide) | |
| 503 return true; | |
| 504 break; | |
| 505 case CSSPropertyFloat: // left | right | none | center (for buggy CSS, maps
to none) | |
| 506 if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CS
SValueNone || valueID == CSSValueCenter) | |
| 507 return true; | |
| 508 break; | |
| 509 case CSSPropertyFontStyle: // normal | italic | oblique | inherit | |
| 510 if (valueID == CSSValueNormal || valueID == CSSValueItalic || valueID ==
CSSValueOblique) | |
| 511 return true; | |
| 512 break; | |
| 513 case CSSPropertyImageRendering: // auto | optimizeContrast | |
| 514 if (valueID == CSSValueAuto || valueID == CSSValueWebkitOptimizeContrast
) | |
| 515 return true; | |
| 516 break; | |
| 517 case CSSPropertyIsolation: // auto | isolate | |
| 518 if (valueID == CSSValueAuto || valueID == CSSValueIsolate) | |
| 519 return RuntimeEnabledFeatures::cssCompositingEnabled(); | |
| 520 break; | |
| 521 case CSSPropertyListStylePosition: // inside | outside | inherit | |
| 522 if (valueID == CSSValueInside || valueID == CSSValueOutside) | |
| 523 return true; | |
| 524 break; | |
| 525 case CSSPropertyListStyleType: | |
| 526 // See section CSS_PROP_LIST_STYLE_TYPE of file CSSValueKeywords.in | |
| 527 // for the list of supported list-style-types. | |
| 528 if ((valueID >= CSSValueDisc && valueID <= CSSValueKatakanaIroha) || val
ueID == CSSValueNone) | |
| 529 return true; | |
| 530 break; | |
| 531 case CSSPropertyObjectFit: | |
| 532 if (RuntimeEnabledFeatures::objectFitPositionEnabled()) { | |
| 533 if (valueID == CSSValueFill || valueID == CSSValueContain || valueID
== CSSValueCover || valueID == CSSValueNone || valueID == CSSValueScaleDown) | |
| 534 return true; | |
| 535 } | |
| 536 break; | |
| 537 case CSSPropertyOutlineStyle: // (<border-style> except hidden) | auto | inh
erit | |
| 538 if (valueID == CSSValueAuto || valueID == CSSValueNone || (valueID >= CS
SValueInset && valueID <= CSSValueDouble)) | |
| 539 return true; | |
| 540 break; | |
| 541 case CSSPropertyOverflowWrap: // normal | break-word | |
| 542 case CSSPropertyWordWrap: | |
| 543 if (valueID == CSSValueNormal || valueID == CSSValueBreakWord) | |
| 544 return true; | |
| 545 break; | |
| 546 case CSSPropertyOverflowX: // visible | hidden | scroll | auto | overlay | i
nherit | |
| 547 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID =
= CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay) | |
| 548 return true; | |
| 549 break; | |
| 550 case CSSPropertyOverflowY: // visible | hidden | scroll | auto | overlay | i
nherit | -webkit-paged-x | -webkit-paged-y | |
| 551 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID =
= CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay || val
ueID == CSSValueWebkitPagedX || valueID == CSSValueWebkitPagedY) | |
| 552 return true; | |
| 553 break; | |
| 554 case CSSPropertyPageBreakAfter: // auto | always | avoid | left | right | in
herit | |
| 555 case CSSPropertyPageBreakBefore: | |
| 556 case CSSPropertyWebkitColumnBreakAfter: | |
| 557 case CSSPropertyWebkitColumnBreakBefore: | |
| 558 if (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == C
SSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight) | |
| 559 return true; | |
| 560 break; | |
| 561 case CSSPropertyPageBreakInside: // avoid | auto | inherit | |
| 562 case CSSPropertyWebkitColumnBreakInside: | |
| 563 if (valueID == CSSValueAuto || valueID == CSSValueAvoid) | |
| 564 return true; | |
| 565 break; | |
| 566 case CSSPropertyPointerEvents: | |
| 567 // none | visiblePainted | visibleFill | visibleStroke | visible | | |
| 568 // painted | fill | stroke | auto | all | bounding-box | inherit | |
| 569 if (valueID == CSSValueVisible || valueID == CSSValueNone || valueID ==
CSSValueAll || valueID == CSSValueAuto || (valueID >= CSSValueVisiblepainted &&
valueID <= CSSValueBoundingBox)) | |
| 570 return true; | |
| 571 break; | |
| 572 case CSSPropertyPosition: // static | relative | absolute | fixed | sticky |
inherit | |
| 573 if (valueID == CSSValueStatic || valueID == CSSValueRelative || valueID
== CSSValueAbsolute || valueID == CSSValueFixed | |
| 574 || (RuntimeEnabledFeatures::cssStickyPositionEnabled() && valueID ==
CSSValueSticky)) | |
| 575 return true; | |
| 576 break; | |
| 577 case CSSPropertyResize: // none | both | horizontal | vertical | auto | |
| 578 if (valueID == CSSValueNone || valueID == CSSValueBoth || valueID == CSS
ValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueAuto) | |
| 579 return true; | |
| 580 break; | |
| 581 case CSSPropertySpeak: // none | normal | spell-out | digits | literal-punct
uation | no-punctuation | inherit | |
| 582 if (valueID == CSSValueNone || valueID == CSSValueNormal || valueID == C
SSValueSpellOut || valueID == CSSValueDigits || valueID == CSSValueLiteralPunctu
ation || valueID == CSSValueNoPunctuation) | |
| 583 return true; | |
| 584 break; | |
| 585 case CSSPropertyTableLayout: // auto | fixed | inherit | |
| 586 if (valueID == CSSValueAuto || valueID == CSSValueFixed) | |
| 587 return true; | |
| 588 break; | |
| 589 case CSSPropertyTextAlignLast: | |
| 590 // auto | start | end | left | right | center | justify | |
| 591 if (RuntimeEnabledFeatures::css3TextEnabled() | |
| 592 && ((valueID >= CSSValueLeft && valueID <= CSSValueJustify) || value
ID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueAuto)) | |
| 593 return true; | |
| 594 break; | |
| 595 case CSSPropertyTextJustify: | |
| 596 // auto | none | inter-word | distribute | |
| 597 if (RuntimeEnabledFeatures::css3TextEnabled() | |
| 598 && (valueID == CSSValueInterWord || valueID == CSSValueDistribute ||
valueID == CSSValueAuto || valueID == CSSValueNone)) | |
| 599 return true; | |
| 600 break; | |
| 601 case CSSPropertyTextLineThroughMode: | |
| 602 case CSSPropertyTextOverlineMode: | |
| 603 case CSSPropertyTextUnderlineMode: | |
| 604 if (valueID == CSSValueContinuous || valueID == CSSValueSkipWhiteSpace) | |
| 605 return true; | |
| 606 break; | |
| 607 case CSSPropertyTextLineThroughStyle: | |
| 608 case CSSPropertyTextOverlineStyle: | |
| 609 case CSSPropertyTextUnderlineStyle: | |
| 610 if (valueID == CSSValueNone || valueID == CSSValueSolid || valueID == CS
SValueDouble || valueID == CSSValueDashed || valueID == CSSValueDotDash || value
ID == CSSValueDotDotDash || valueID == CSSValueWave) | |
| 611 return true; | |
| 612 break; | |
| 613 case CSSPropertyTextOverflow: // clip | ellipsis | |
| 614 if (valueID == CSSValueClip || valueID == CSSValueEllipsis) | |
| 615 return true; | |
| 616 break; | |
| 617 case CSSPropertyTextRendering: // auto | optimizeSpeed | optimizeLegibility
| geometricPrecision | |
| 618 if (valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || value
ID == CSSValueOptimizelegibility || valueID == CSSValueGeometricprecision) | |
| 619 return true; | |
| 620 break; | |
| 621 case CSSPropertyTextTransform: // capitalize | uppercase | lowercase | none
| inherit | |
| 622 if ((valueID >= CSSValueCapitalize && valueID <= CSSValueLowercase) || v
alueID == CSSValueNone) | |
| 623 return true; | |
| 624 break; | |
| 625 case CSSPropertyTouchActionDelay: // none | script | |
| 626 if (RuntimeEnabledFeatures::cssTouchActionEnabled() && (valueID == CSSVa
lueScript || valueID == CSSValueNone)) | |
| 627 return true; | |
| 628 break; | |
| 629 case CSSPropertyVisibility: // visible | hidden | collapse | inherit | |
| 630 if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID =
= CSSValueCollapse) | |
| 631 return true; | |
| 632 break; | |
| 633 case CSSPropertyWebkitAppearance: | |
| 634 if ((valueID >= CSSValueCheckbox && valueID <= CSSValueTextarea) || valu
eID == CSSValueNone) | |
| 635 return true; | |
| 636 break; | |
| 637 case CSSPropertyWebkitBackfaceVisibility: | |
| 638 if (valueID == CSSValueVisible || valueID == CSSValueHidden) | |
| 639 return true; | |
| 640 break; | |
| 641 case CSSPropertyMixBlendMode: | |
| 642 if (RuntimeEnabledFeatures::cssCompositingEnabled() && (valueID == CSSVa
lueNormal || valueID == CSSValueMultiply || valueID == CSSValueScreen | |
| 643 || valueID == CSSValueOverlay || valueID == CSSValueDarken || valueI
D == CSSValueLighten || valueID == CSSValueColorDodge | |
| 644 || valueID == CSSValueColorBurn || valueID == CSSValueHardLight || v
alueID == CSSValueSoftLight || valueID == CSSValueDifference | |
| 645 || valueID == CSSValueExclusion || valueID == CSSValueHue || valueID
== CSSValueSaturation || valueID == CSSValueColor | |
| 646 || valueID == CSSValueLuminosity)) | |
| 647 return true; | |
| 648 break; | |
| 649 case CSSPropertyWebkitBorderFit: | |
| 650 if (valueID == CSSValueBorder || valueID == CSSValueLines) | |
| 651 return true; | |
| 652 break; | |
| 653 case CSSPropertyWebkitBoxAlign: | |
| 654 if (valueID == CSSValueStretch || valueID == CSSValueStart || valueID ==
CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline) | |
| 655 return true; | |
| 656 break; | |
| 657 case CSSPropertyWebkitBoxDecorationBreak: | |
| 658 if (valueID == CSSValueClone || valueID == CSSValueSlice) | |
| 659 return true; | |
| 660 break; | |
| 661 case CSSPropertyWebkitBoxDirection: | |
| 662 if (valueID == CSSValueNormal || valueID == CSSValueReverse) | |
| 663 return true; | |
| 664 break; | |
| 665 case CSSPropertyWebkitBoxLines: | |
| 666 if (valueID == CSSValueSingle || valueID == CSSValueMultiple) | |
| 667 return true; | |
| 668 break; | |
| 669 case CSSPropertyWebkitBoxOrient: | |
| 670 if (valueID == CSSValueHorizontal || valueID == CSSValueVertical || valu
eID == CSSValueInlineAxis || valueID == CSSValueBlockAxis) | |
| 671 return true; | |
| 672 break; | |
| 673 case CSSPropertyWebkitBoxPack: | |
| 674 if (valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSS
ValueCenter || valueID == CSSValueJustify) | |
| 675 return true; | |
| 676 break; | |
| 677 case CSSPropertyInternalCallback: | |
| 678 // This property is only injected programmatically, not parsed from styl
esheets. | |
| 679 return false; | |
| 680 case CSSPropertyColumnFill: | |
| 681 if (RuntimeEnabledFeatures::regionBasedColumnsEnabled()) { | |
| 682 if (valueID == CSSValueAuto || valueID == CSSValueBalance) | |
| 683 return true; | |
| 684 } | |
| 685 break; | |
| 686 case CSSPropertyAlignContent: | |
| 687 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || value
ID == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSp
aceAround || valueID == CSSValueStretch) | |
| 688 return true; | |
| 689 break; | |
| 690 case CSSPropertyAlignItems: | |
| 691 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueI
D == CSSValueCenter || valueID == CSSValueBaseline || valueID == CSSValueStretch
) | |
| 692 return true; | |
| 693 break; | |
| 694 case CSSPropertyAlignSelf: | |
| 695 if (valueID == CSSValueAuto || valueID == CSSValueFlexStart || valueID =
= CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline ||
valueID == CSSValueStretch) | |
| 696 return true; | |
| 697 break; | |
| 698 case CSSPropertyFlexDirection: | |
| 699 if (valueID == CSSValueRow || valueID == CSSValueRowReverse || valueID =
= CSSValueColumn || valueID == CSSValueColumnReverse) | |
| 700 return true; | |
| 701 break; | |
| 702 case CSSPropertyFlexWrap: | |
| 703 if (valueID == CSSValueNowrap || valueID == CSSValueWrap || valueID == C
SSValueWrapReverse) | |
| 704 return true; | |
| 705 break; | |
| 706 case CSSPropertyJustifyContent: | |
| 707 if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueI
D == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSpa
ceAround) | |
| 708 return true; | |
| 709 break; | |
| 710 case CSSPropertyFontKerning: | |
| 711 if (valueID == CSSValueAuto || valueID == CSSValueNormal || valueID == C
SSValueNone) | |
| 712 return true; | |
| 713 break; | |
| 714 case CSSPropertyWebkitFontSmoothing: | |
| 715 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSS
ValueAntialiased || valueID == CSSValueSubpixelAntialiased) | |
| 716 return true; | |
| 717 break; | |
| 718 case CSSPropertyGridAutoFlow: | |
| 719 if (valueID == CSSValueNone || valueID == CSSValueRow || valueID == CSSV
alueColumn) | |
| 720 return RuntimeEnabledFeatures::cssGridLayoutEnabled(); | |
| 721 break; | |
| 722 case CSSPropertyWebkitLineAlign: | |
| 723 if (valueID == CSSValueNone || valueID == CSSValueEdges) | |
| 724 return true; | |
| 725 break; | |
| 726 case CSSPropertyWebkitLineBreak: // auto | loose | normal | strict | after-w
hite-space | |
| 727 if (valueID == CSSValueAuto || valueID == CSSValueLoose || valueID == CS
SValueNormal || valueID == CSSValueStrict || valueID == CSSValueAfterWhiteSpace) | |
| 728 return true; | |
| 729 break; | |
| 730 case CSSPropertyWebkitLineSnap: | |
| 731 if (valueID == CSSValueNone || valueID == CSSValueBaseline || valueID ==
CSSValueContain) | |
| 732 return true; | |
| 733 break; | |
| 734 case CSSPropertyWebkitMarginAfterCollapse: | |
| 735 case CSSPropertyWebkitMarginBeforeCollapse: | |
| 736 case CSSPropertyWebkitMarginBottomCollapse: | |
| 737 case CSSPropertyWebkitMarginTopCollapse: | |
| 738 if (valueID == CSSValueCollapse || valueID == CSSValueSeparate || valueI
D == CSSValueDiscard) | |
| 739 return true; | |
| 740 break; | |
| 741 case CSSPropertyInternalMarqueeDirection: | |
| 742 if (valueID == CSSValueForwards || valueID == CSSValueBackwards || value
ID == CSSValueAhead || valueID == CSSValueReverse || valueID == CSSValueLeft ||
valueID == CSSValueRight || valueID == CSSValueDown | |
| 743 || valueID == CSSValueUp || valueID == CSSValueAuto) | |
| 744 return true; | |
| 745 break; | |
| 746 case CSSPropertyInternalMarqueeStyle: | |
| 747 if (valueID == CSSValueNone || valueID == CSSValueSlide || valueID == CS
SValueScroll || valueID == CSSValueAlternate) | |
| 748 return true; | |
| 749 break; | |
| 750 case CSSPropertyWebkitPrintColorAdjust: | |
| 751 if (valueID == CSSValueExact || valueID == CSSValueEconomy) | |
| 752 return true; | |
| 753 break; | |
| 754 case CSSPropertyWebkitRegionBreakAfter: | |
| 755 case CSSPropertyWebkitRegionBreakBefore: | |
| 756 if (RuntimeEnabledFeatures::cssRegionsEnabled() && (valueID == CSSValueA
uto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSVa
lueLeft || valueID == CSSValueRight)) | |
| 757 return true; | |
| 758 break; | |
| 759 case CSSPropertyWebkitRegionBreakInside: | |
| 760 if (RuntimeEnabledFeatures::cssRegionsEnabled() && (valueID == CSSValueA
uto || valueID == CSSValueAvoid)) | |
| 761 return true; | |
| 762 break; | |
| 763 case CSSPropertyWebkitRegionFragment: | |
| 764 if (RuntimeEnabledFeatures::cssRegionsEnabled() && (valueID == CSSValueA
uto || valueID == CSSValueBreak)) | |
| 765 return true; | |
| 766 break; | |
| 767 case CSSPropertyWebkitRtlOrdering: | |
| 768 if (valueID == CSSValueLogical || valueID == CSSValueVisual) | |
| 769 return true; | |
| 770 break; | |
| 771 | |
| 772 case CSSPropertyWebkitRubyPosition: | |
| 773 if (valueID == CSSValueBefore || valueID == CSSValueAfter) | |
| 774 return true; | |
| 775 break; | |
| 776 | |
| 777 case CSSPropertyWebkitTextCombine: | |
| 778 if (valueID == CSSValueNone || valueID == CSSValueHorizontal) | |
| 779 return true; | |
| 780 break; | |
| 781 case CSSPropertyWebkitTextEmphasisPosition: | |
| 782 if (valueID == CSSValueOver || valueID == CSSValueUnder) | |
| 783 return true; | |
| 784 break; | |
| 785 case CSSPropertyWebkitTextSecurity: | |
| 786 // disc | circle | square | none | inherit | |
| 787 if (valueID == CSSValueDisc || valueID == CSSValueCircle || valueID == C
SSValueSquare || valueID == CSSValueNone) | |
| 788 return true; | |
| 789 break; | |
| 790 case CSSPropertyWebkitTransformStyle: | |
| 791 if (valueID == CSSValueFlat || valueID == CSSValuePreserve3d) | |
| 792 return true; | |
| 793 break; | |
| 794 case CSSPropertyWebkitUserDrag: // auto | none | element | |
| 795 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSS
ValueElement) | |
| 796 return true; | |
| 797 break; | |
| 798 case CSSPropertyWebkitUserModify: // read-only | read-write | |
| 799 if (valueID == CSSValueReadOnly || valueID == CSSValueReadWrite || value
ID == CSSValueReadWritePlaintextOnly) | |
| 800 return true; | |
| 801 break; | |
| 802 case CSSPropertyWebkitUserSelect: // auto | none | text | all | |
| 803 if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSS
ValueText || valueID == CSSValueAll) | |
| 804 return true; | |
| 805 break; | |
| 806 case CSSPropertyWebkitWrapFlow: | |
| 807 if (!RuntimeEnabledFeatures::cssExclusionsEnabled()) | |
| 808 return false; | |
| 809 if (valueID == CSSValueAuto || valueID == CSSValueBoth || valueID == CSS
ValueStart || valueID == CSSValueEnd || valueID == CSSValueMaximum || valueID ==
CSSValueClear) | |
| 810 return true; | |
| 811 break; | |
| 812 case CSSPropertyWebkitWrapThrough: | |
| 813 if (!RuntimeEnabledFeatures::cssExclusionsEnabled()) | |
| 814 return false; | |
| 815 if (valueID == CSSValueWrap || valueID == CSSValueNone) | |
| 816 return true; | |
| 817 break; | |
| 818 case CSSPropertyWebkitWritingMode: | |
| 819 if (valueID >= CSSValueHorizontalTb && valueID <= CSSValueHorizontalBt) | |
| 820 return true; | |
| 821 break; | |
| 822 case CSSPropertyWhiteSpace: // normal | pre | nowrap | inherit | |
| 823 if (valueID == CSSValueNormal || valueID == CSSValuePre || valueID == CS
SValuePreWrap || valueID == CSSValuePreLine || valueID == CSSValueNowrap) | |
| 824 return true; | |
| 825 break; | |
| 826 case CSSPropertyWordBreak: // normal | break-all | break-word (this is a cus
tom extension) | |
| 827 if (valueID == CSSValueNormal || valueID == CSSValueBreakAll || valueID
== CSSValueBreakWord) | |
| 828 return true; | |
| 829 break; | |
| 830 default: | |
| 831 ASSERT_NOT_REACHED(); | |
| 832 return false; | |
| 833 } | |
| 834 return false; | |
| 835 } | |
| 836 | |
| 837 static inline bool isKeywordPropertyID(CSSPropertyID propertyId) | |
| 838 { | |
| 839 switch (propertyId) { | |
| 840 case CSSPropertyMixBlendMode: | |
| 841 case CSSPropertyIsolation: | |
| 842 case CSSPropertyBorderBottomStyle: | |
| 843 case CSSPropertyBorderCollapse: | |
| 844 case CSSPropertyBorderLeftStyle: | |
| 845 case CSSPropertyBorderRightStyle: | |
| 846 case CSSPropertyBorderTopStyle: | |
| 847 case CSSPropertyBoxSizing: | |
| 848 case CSSPropertyCaptionSide: | |
| 849 case CSSPropertyClear: | |
| 850 case CSSPropertyDirection: | |
| 851 case CSSPropertyDisplay: | |
| 852 case CSSPropertyEmptyCells: | |
| 853 case CSSPropertyFloat: | |
| 854 case CSSPropertyFontStyle: | |
| 855 case CSSPropertyImageRendering: | |
| 856 case CSSPropertyListStylePosition: | |
| 857 case CSSPropertyListStyleType: | |
| 858 case CSSPropertyObjectFit: | |
| 859 case CSSPropertyOutlineStyle: | |
| 860 case CSSPropertyOverflowWrap: | |
| 861 case CSSPropertyOverflowX: | |
| 862 case CSSPropertyOverflowY: | |
| 863 case CSSPropertyPageBreakAfter: | |
| 864 case CSSPropertyPageBreakBefore: | |
| 865 case CSSPropertyPageBreakInside: | |
| 866 case CSSPropertyPointerEvents: | |
| 867 case CSSPropertyPosition: | |
| 868 case CSSPropertyResize: | |
| 869 case CSSPropertySpeak: | |
| 870 case CSSPropertyTableLayout: | |
| 871 case CSSPropertyTextAlignLast: | |
| 872 case CSSPropertyTextJustify: | |
| 873 case CSSPropertyTextLineThroughMode: | |
| 874 case CSSPropertyTextLineThroughStyle: | |
| 875 case CSSPropertyTextOverflow: | |
| 876 case CSSPropertyTextOverlineMode: | |
| 877 case CSSPropertyTextOverlineStyle: | |
| 878 case CSSPropertyTextRendering: | |
| 879 case CSSPropertyTextTransform: | |
| 880 case CSSPropertyTextUnderlineMode: | |
| 881 case CSSPropertyTextUnderlineStyle: | |
| 882 case CSSPropertyTouchActionDelay: | |
| 883 case CSSPropertyVisibility: | |
| 884 case CSSPropertyWebkitAppearance: | |
| 885 case CSSPropertyWebkitBackfaceVisibility: | |
| 886 case CSSPropertyWebkitBorderAfterStyle: | |
| 887 case CSSPropertyWebkitBorderBeforeStyle: | |
| 888 case CSSPropertyWebkitBorderEndStyle: | |
| 889 case CSSPropertyWebkitBorderFit: | |
| 890 case CSSPropertyWebkitBorderStartStyle: | |
| 891 case CSSPropertyWebkitBoxAlign: | |
| 892 case CSSPropertyWebkitBoxDecorationBreak: | |
| 893 case CSSPropertyWebkitBoxDirection: | |
| 894 case CSSPropertyWebkitBoxLines: | |
| 895 case CSSPropertyWebkitBoxOrient: | |
| 896 case CSSPropertyWebkitBoxPack: | |
| 897 case CSSPropertyInternalCallback: | |
| 898 case CSSPropertyWebkitColumnBreakAfter: | |
| 899 case CSSPropertyWebkitColumnBreakBefore: | |
| 900 case CSSPropertyWebkitColumnBreakInside: | |
| 901 case CSSPropertyColumnFill: | |
| 902 case CSSPropertyWebkitColumnRuleStyle: | |
| 903 case CSSPropertyAlignContent: | |
| 904 case CSSPropertyAlignItems: | |
| 905 case CSSPropertyAlignSelf: | |
| 906 case CSSPropertyFlexDirection: | |
| 907 case CSSPropertyFlexWrap: | |
| 908 case CSSPropertyJustifyContent: | |
| 909 case CSSPropertyFontKerning: | |
| 910 case CSSPropertyWebkitFontSmoothing: | |
| 911 case CSSPropertyGridAutoFlow: | |
| 912 case CSSPropertyWebkitLineAlign: | |
| 913 case CSSPropertyWebkitLineBreak: | |
| 914 case CSSPropertyWebkitLineSnap: | |
| 915 case CSSPropertyWebkitMarginAfterCollapse: | |
| 916 case CSSPropertyWebkitMarginBeforeCollapse: | |
| 917 case CSSPropertyWebkitMarginBottomCollapse: | |
| 918 case CSSPropertyWebkitMarginTopCollapse: | |
| 919 case CSSPropertyInternalMarqueeDirection: | |
| 920 case CSSPropertyInternalMarqueeStyle: | |
| 921 case CSSPropertyWebkitPrintColorAdjust: | |
| 922 case CSSPropertyWebkitRegionBreakAfter: | |
| 923 case CSSPropertyWebkitRegionBreakBefore: | |
| 924 case CSSPropertyWebkitRegionBreakInside: | |
| 925 case CSSPropertyWebkitRegionFragment: | |
| 926 case CSSPropertyWebkitRtlOrdering: | |
| 927 case CSSPropertyWebkitRubyPosition: | |
| 928 case CSSPropertyWebkitTextCombine: | |
| 929 case CSSPropertyWebkitTextEmphasisPosition: | |
| 930 case CSSPropertyWebkitTextSecurity: | |
| 931 case CSSPropertyWebkitTransformStyle: | |
| 932 case CSSPropertyWebkitUserDrag: | |
| 933 case CSSPropertyWebkitUserModify: | |
| 934 case CSSPropertyWebkitUserSelect: | |
| 935 case CSSPropertyWebkitWrapFlow: | |
| 936 case CSSPropertyWebkitWrapThrough: | |
| 937 case CSSPropertyWebkitWritingMode: | |
| 938 case CSSPropertyWhiteSpace: | |
| 939 case CSSPropertyWordBreak: | |
| 940 case CSSPropertyWordWrap: | |
| 941 return true; | |
| 942 default: | |
| 943 return false; | |
| 944 } | |
| 945 } | |
| 946 | |
| 947 static bool parseKeywordValue(MutableStylePropertySet* declaration, CSSPropertyI
D propertyId, const String& string, bool important, const CSSParserContext& pars
erContext) | |
| 948 { | |
| 949 ASSERT(!string.isEmpty()); | |
| 950 | |
| 951 if (!isKeywordPropertyID(propertyId)) { | |
| 952 // All properties accept the values of "initial" and "inherit". | |
| 953 String lowerCaseString = string.lower(); | |
| 954 if (lowerCaseString != "initial" && lowerCaseString != "inherit") | |
| 955 return false; | |
| 956 | |
| 957 // Parse initial/inherit shorthands using the CSSParser. | |
| 958 if (shorthandForProperty(propertyId).length()) | |
| 959 return false; | |
| 960 } | |
| 961 | |
| 962 CSSParserString cssString; | |
| 963 cssString.init(string); | |
| 964 CSSValueID valueID = cssValueKeywordID(cssString); | |
| 965 | |
| 966 if (!valueID) | |
| 967 return false; | |
| 968 | |
| 969 RefPtr<CSSValue> value; | |
| 970 if (valueID == CSSValueInherit) | |
| 971 value = cssValuePool().createInheritedValue(); | |
| 972 else if (valueID == CSSValueInitial) | |
| 973 value = cssValuePool().createExplicitInitialValue(); | |
| 974 else if (isValidKeywordPropertyAndValue(propertyId, valueID, parserContext)) | |
| 975 value = cssValuePool().createIdentifierValue(valueID); | |
| 976 else | |
| 977 return false; | |
| 978 | |
| 979 declaration->addParsedProperty(CSSProperty(propertyId, value.release(), impo
rtant)); | |
| 980 return true; | |
| 981 } | |
| 982 | |
| 983 template <typename CharType> | |
| 984 static bool parseTransformTranslateArguments(CharType*& pos, CharType* end, unsi
gned expectedCount, CSSTransformValue* transformValue) | |
| 985 { | |
| 986 while (expectedCount) { | |
| 987 size_t delimiter = WTF::find(pos, end - pos, expectedCount == 1 ? ')' :
','); | |
| 988 if (delimiter == kNotFound) | |
| 989 return false; | |
| 990 unsigned argumentLength = static_cast<unsigned>(delimiter); | |
| 991 CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER; | |
| 992 double number; | |
| 993 if (!parseSimpleLength(pos, argumentLength, unit, number)) | |
| 994 return false; | |
| 995 if (unit != CSSPrimitiveValue::CSS_PX && (number || unit != CSSPrimitive
Value::CSS_NUMBER)) | |
| 996 return false; | |
| 997 transformValue->append(cssValuePool().createValue(number, CSSPrimitiveVa
lue::CSS_PX)); | |
| 998 pos += argumentLength + 1; | |
| 999 --expectedCount; | |
| 1000 } | |
| 1001 return true; | |
| 1002 } | |
| 1003 | |
| 1004 template <typename CharType> | |
| 1005 static PassRefPtr<CSSTransformValue> parseTranslateTransformValue(CharType*& pos
, CharType* end) | |
| 1006 { | |
| 1007 static const int shortestValidTransformStringLength = 12; | |
| 1008 | |
| 1009 if (end - pos < shortestValidTransformStringLength) | |
| 1010 return 0; | |
| 1011 | |
| 1012 if ((pos[0] != 't' && pos[0] != 'T') | |
| 1013 || (pos[1] != 'r' && pos[1] != 'R') | |
| 1014 || (pos[2] != 'a' && pos[2] != 'A') | |
| 1015 || (pos[3] != 'n' && pos[3] != 'N') | |
| 1016 || (pos[4] != 's' && pos[4] != 'S') | |
| 1017 || (pos[5] != 'l' && pos[5] != 'L') | |
| 1018 || (pos[6] != 'a' && pos[6] != 'A') | |
| 1019 || (pos[7] != 't' && pos[7] != 'T') | |
| 1020 || (pos[8] != 'e' && pos[8] != 'E')) | |
| 1021 return 0; | |
| 1022 | |
| 1023 CSSTransformValue::TransformOperationType transformType; | |
| 1024 unsigned expectedArgumentCount = 1; | |
| 1025 unsigned argumentStart = 11; | |
| 1026 if ((pos[9] == 'x' || pos[9] == 'X') && pos[10] == '(') { | |
| 1027 transformType = CSSTransformValue::TranslateXTransformOperation; | |
| 1028 } else if ((pos[9] == 'y' || pos[9] == 'Y') && pos[10] == '(') { | |
| 1029 transformType = CSSTransformValue::TranslateYTransformOperation; | |
| 1030 } else if ((pos[9] == 'z' || pos[9] == 'Z') && pos[10] == '(') { | |
| 1031 transformType = CSSTransformValue::TranslateZTransformOperation; | |
| 1032 } else if (pos[9] == '(') { | |
| 1033 transformType = CSSTransformValue::TranslateTransformOperation; | |
| 1034 expectedArgumentCount = 2; | |
| 1035 argumentStart = 10; | |
| 1036 } else if (pos[9] == '3' && (pos[10] == 'd' || pos[10] == 'D') && pos[11] ==
'(') { | |
| 1037 transformType = CSSTransformValue::Translate3DTransformOperation; | |
| 1038 expectedArgumentCount = 3; | |
| 1039 argumentStart = 12; | |
| 1040 } else { | |
| 1041 return 0; | |
| 1042 } | |
| 1043 pos += argumentStart; | |
| 1044 | |
| 1045 RefPtr<CSSTransformValue> transformValue = CSSTransformValue::create(transfo
rmType); | |
| 1046 if (!parseTransformTranslateArguments(pos, end, expectedArgumentCount, trans
formValue.get())) | |
| 1047 return 0; | |
| 1048 return transformValue.release(); | |
| 1049 } | |
| 1050 | |
| 1051 template <typename CharType> | |
| 1052 static PassRefPtr<CSSValueList> parseTranslateTransformList(CharType*& pos, Char
Type* end) | |
| 1053 { | |
| 1054 RefPtr<CSSValueList> transformList; | |
| 1055 while (pos < end) { | |
| 1056 while (isCSSSpace(*pos) && pos < end) | |
| 1057 ++pos; | |
| 1058 RefPtr<CSSTransformValue> transformValue = parseTranslateTransformValue(
pos, end); | |
| 1059 if (!transformValue) | |
| 1060 return 0; | |
| 1061 if (!transformList) | |
| 1062 transformList = CSSValueList::createSpaceSeparated(); | |
| 1063 transformList->append(transformValue.release()); | |
| 1064 if (pos < end) { | |
| 1065 if (isCSSSpace(*pos)) | |
| 1066 return 0; | |
| 1067 } | |
| 1068 } | |
| 1069 return transformList.release(); | |
| 1070 } | |
| 1071 | |
| 1072 static bool parseTranslateTransform(MutableStylePropertySet* properties, CSSProp
ertyID propertyID, const String& string, bool important) | |
| 1073 { | |
| 1074 if (propertyID != CSSPropertyWebkitTransform) | |
| 1075 return false; | |
| 1076 if (string.isEmpty()) | |
| 1077 return false; | |
| 1078 RefPtr<CSSValueList> transformList; | |
| 1079 if (string.is8Bit()) { | |
| 1080 const LChar* pos = string.characters8(); | |
| 1081 const LChar* end = pos + string.length(); | |
| 1082 transformList = parseTranslateTransformList(pos, end); | |
| 1083 if (!transformList) | |
| 1084 return false; | |
| 1085 } else { | |
| 1086 const UChar* pos = string.characters16(); | |
| 1087 const UChar* end = pos + string.length(); | |
| 1088 transformList = parseTranslateTransformList(pos, end); | |
| 1089 if (!transformList) | |
| 1090 return false; | |
| 1091 } | |
| 1092 properties->addParsedProperty(CSSProperty(CSSPropertyWebkitTransform, transf
ormList.release(), important)); | |
| 1093 return true; | |
| 1094 } | |
| 1095 | |
| 1096 PassRefPtr<CSSValueList> CSSParser::parseFontFaceValue(const AtomicString& strin
g) | |
| 1097 { | |
| 1098 if (string.isEmpty()) | |
| 1099 return 0; | |
| 1100 RefPtr<MutableStylePropertySet> dummyStyle = MutableStylePropertySet::create
(); | |
| 1101 if (!parseValue(dummyStyle.get(), CSSPropertyFontFamily, string, false, HTML
QuirksMode, 0)) | |
| 1102 return 0; | |
| 1103 | |
| 1104 RefPtr<CSSValue> fontFamily = dummyStyle->getPropertyCSSValue(CSSPropertyFon
tFamily); | |
| 1105 if (!fontFamily->isValueList()) | |
| 1106 return 0; | |
| 1107 | |
| 1108 return toCSSValueList(dummyStyle->getPropertyCSSValue(CSSPropertyFontFamily)
.get()); | |
| 1109 } | |
| 1110 | |
| 1111 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID p
ropertyID, const String& string, bool important, const Document& document) | |
| 1112 { | |
| 1113 ASSERT(!string.isEmpty()); | |
| 1114 | |
| 1115 CSSParserContext context(document); | |
| 1116 | |
| 1117 if (parseSimpleLengthValue(declaration, propertyID, string, important, conte
xt.mode())) | |
| 1118 return true; | |
| 1119 if (parseColorValue(declaration, propertyID, string, important, context.mode
())) | |
| 1120 return true; | |
| 1121 if (parseKeywordValue(declaration, propertyID, string, important, context)) | |
| 1122 return true; | |
| 1123 | |
| 1124 CSSParser parser(context, UseCounter::getFrom(&document)); | |
| 1125 return parser.parseValue(declaration, propertyID, string, important, static_
cast<StyleSheetContents*>(0)); | |
| 1126 } | |
| 1127 | |
| 1128 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID p
ropertyID, const String& string, bool important, CSSParserMode cssParserMode, St
yleSheetContents* contextStyleSheet) | |
| 1129 { | |
| 1130 ASSERT(!string.isEmpty()); | |
| 1131 if (parseSimpleLengthValue(declaration, propertyID, string, important, cssPa
rserMode)) | |
| 1132 return true; | |
| 1133 if (parseColorValue(declaration, propertyID, string, important, cssParserMod
e)) | |
| 1134 return true; | |
| 1135 | |
| 1136 CSSParserContext context(cssParserMode); | |
| 1137 if (contextStyleSheet) { | |
| 1138 context = contextStyleSheet->parserContext(); | |
| 1139 context.setMode(cssParserMode); | |
| 1140 } | |
| 1141 | |
| 1142 if (parseKeywordValue(declaration, propertyID, string, important, context)) | |
| 1143 return true; | |
| 1144 if (parseTranslateTransform(declaration, propertyID, string, important)) | |
| 1145 return true; | |
| 1146 | |
| 1147 CSSParser parser(context); | |
| 1148 return parser.parseValue(declaration, propertyID, string, important, context
StyleSheet); | |
| 1149 } | |
| 1150 | |
| 1151 bool CSSParser::parseValue(MutableStylePropertySet* declaration, CSSPropertyID p
ropertyID, const String& string, bool important, StyleSheetContents* contextStyl
eSheet) | |
| 1152 { | |
| 1153 // FIXME: Check RuntimeCSSEnabled::isPropertyEnabled or isValueEnabledForPro
perty. | |
| 1154 | |
| 1155 if (m_useCounter) | |
| 1156 m_useCounter->count(m_context, propertyID); | |
| 1157 | |
| 1158 setStyleSheet(contextStyleSheet); | |
| 1159 | |
| 1160 setupParser("@-internal-value ", string, ""); | |
| 1161 | |
| 1162 m_id = propertyID; | |
| 1163 m_important = important; | |
| 1164 | |
| 1165 { | |
| 1166 StyleDeclarationScope scope(this, declaration); | |
| 1167 cssyyparse(this); | |
| 1168 } | |
| 1169 | |
| 1170 m_rule = 0; | |
| 1171 m_id = CSSPropertyInvalid; | |
| 1172 | |
| 1173 bool ok = false; | |
| 1174 if (m_hasFontFaceOnlyValues) | |
| 1175 deleteFontFaceOnlyValues(); | |
| 1176 if (!m_parsedProperties.isEmpty()) { | |
| 1177 ok = true; | |
| 1178 declaration->addParsedProperties(m_parsedProperties); | |
| 1179 clearProperties(); | |
| 1180 } | |
| 1181 | |
| 1182 return ok; | |
| 1183 } | |
| 1184 | |
| 1185 // The color will only be changed when string contains a valid CSS color, so cal
lers | |
| 1186 // can set it to a default color and ignore the boolean result. | |
| 1187 bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict) | |
| 1188 { | |
| 1189 // First try creating a color specified by name, rgba(), rgb() or "#" syntax
. | |
| 1190 if (fastParseColor(color, string, strict)) | |
| 1191 return true; | |
| 1192 | |
| 1193 CSSParser parser(HTMLStandardMode); | |
| 1194 | |
| 1195 // In case the fast-path parser didn't understand the color, try the full pa
rser. | |
| 1196 if (!parser.parseColor(string)) | |
| 1197 return false; | |
| 1198 | |
| 1199 CSSValue* value = parser.m_parsedProperties.first().value(); | |
| 1200 if (!value->isPrimitiveValue()) | |
| 1201 return false; | |
| 1202 | |
| 1203 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); | |
| 1204 if (!primitiveValue->isRGBColor()) | |
| 1205 return false; | |
| 1206 | |
| 1207 color = primitiveValue->getRGBA32Value(); | |
| 1208 return true; | |
| 1209 } | |
| 1210 | |
| 1211 bool CSSParser::parseColor(const String& string) | |
| 1212 { | |
| 1213 setupParser("@-internal-decls color:", string, ""); | |
| 1214 cssyyparse(this); | |
| 1215 m_rule = 0; | |
| 1216 | |
| 1217 return !m_parsedProperties.isEmpty() && m_parsedProperties.first().id() == C
SSPropertyColor; | |
| 1218 } | |
| 1219 | |
| 1220 bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document*
document) | |
| 1221 { | |
| 1222 if (!document) | |
| 1223 return false; | |
| 1224 | |
| 1225 CSSParserString cssColor; | |
| 1226 cssColor.init(string); | |
| 1227 CSSValueID id = cssValueKeywordID(cssColor); | |
| 1228 if (id <= 0) | |
| 1229 return false; | |
| 1230 | |
| 1231 color = RenderTheme::theme().systemColor(id).rgb(); | |
| 1232 return true; | |
| 1233 } | |
| 1234 | |
| 1235 void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorLis
t) | |
| 1236 { | |
| 1237 m_selectorListForParseSelector = &selectorList; | |
| 1238 | |
| 1239 setupParser("@-internal-selector ", string, ""); | |
| 1240 | |
| 1241 cssyyparse(this); | |
| 1242 | |
| 1243 m_selectorListForParseSelector = 0; | |
| 1244 } | |
| 1245 | |
| 1246 PassRefPtr<ImmutableStylePropertySet> CSSParser::parseInlineStyleDeclaration(con
st String& string, Element* element) | |
| 1247 { | |
| 1248 Document& document = element->document(); | |
| 1249 CSSParserContext context = document.elementSheet()->contents()->parserContex
t(); | |
| 1250 context.setMode((element->isHTMLElement() && !document.inQuirksMode()) ? HTM
LStandardMode : HTMLQuirksMode); | |
| 1251 return CSSParser(context, UseCounter::getFrom(&document)).parseDeclaration(s
tring, document.elementSheet()->contents()); | |
| 1252 } | |
| 1253 | |
| 1254 PassRefPtr<ImmutableStylePropertySet> CSSParser::parseDeclaration(const String&
string, StyleSheetContents* contextStyleSheet) | |
| 1255 { | |
| 1256 setStyleSheet(contextStyleSheet); | |
| 1257 | |
| 1258 setupParser("@-internal-decls ", string, ""); | |
| 1259 cssyyparse(this); | |
| 1260 m_rule = 0; | |
| 1261 | |
| 1262 if (m_hasFontFaceOnlyValues) | |
| 1263 deleteFontFaceOnlyValues(); | |
| 1264 | |
| 1265 RefPtr<ImmutableStylePropertySet> style = createStylePropertySet(); | |
| 1266 clearProperties(); | |
| 1267 return style.release(); | |
| 1268 } | |
| 1269 | |
| 1270 | |
| 1271 bool CSSParser::parseDeclaration(MutableStylePropertySet* declaration, const Str
ing& string, CSSParserObserver* observer, StyleSheetContents* contextStyleSheet) | |
| 1272 { | |
| 1273 setStyleSheet(contextStyleSheet); | |
| 1274 | |
| 1275 TemporaryChange<CSSParserObserver*> scopedObsever(m_observer, observer); | |
| 1276 | |
| 1277 setupParser("@-internal-decls ", string, ""); | |
| 1278 if (m_observer) { | |
| 1279 m_observer->startRuleHeader(CSSRuleSourceData::STYLE_RULE, 0); | |
| 1280 m_observer->endRuleHeader(1); | |
| 1281 m_observer->startRuleBody(0); | |
| 1282 } | |
| 1283 | |
| 1284 { | |
| 1285 StyleDeclarationScope scope(this, declaration); | |
| 1286 cssyyparse(this); | |
| 1287 } | |
| 1288 | |
| 1289 m_rule = 0; | |
| 1290 | |
| 1291 bool ok = false; | |
| 1292 if (m_hasFontFaceOnlyValues) | |
| 1293 deleteFontFaceOnlyValues(); | |
| 1294 if (!m_parsedProperties.isEmpty()) { | |
| 1295 ok = true; | |
| 1296 declaration->addParsedProperties(m_parsedProperties); | |
| 1297 clearProperties(); | |
| 1298 } | |
| 1299 | |
| 1300 if (m_observer) | |
| 1301 m_observer->endRuleBody(string.length(), false); | |
| 1302 | |
| 1303 return ok; | |
| 1304 } | |
| 1305 | |
| 1306 PassRefPtr<MediaQuerySet> CSSParser::parseMediaQueryList(const String& string) | |
| 1307 { | |
| 1308 ASSERT(!m_mediaList); | |
| 1309 | |
| 1310 // can't use { because tokenizer state switches from mediaquery to initial s
tate when it sees { token. | |
| 1311 // instead insert one " " (which is caught by maybe_space in CSSGrammar.y) | |
| 1312 setupParser("@-internal-medialist ", string, ""); | |
| 1313 cssyyparse(this); | |
| 1314 | |
| 1315 ASSERT(m_mediaList); | |
| 1316 return m_mediaList.release(); | |
| 1317 } | |
| 1318 | |
| 1319 static inline void filterProperties(bool important, const CSSParser::ParsedPrope
rtyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitAr
ray<numCSSProperties>& seenProperties, HashSet<AtomicString>& seenVariables) | |
| 1320 { | |
| 1321 // Add properties in reverse order so that highest priority definitions are
reached first. Duplicate definitions can then be ignored when found. | |
| 1322 for (int i = input.size() - 1; i >= 0; --i) { | |
| 1323 const CSSProperty& property = input[i]; | |
| 1324 if (property.isImportant() != important) | |
| 1325 continue; | |
| 1326 if (property.id() == CSSPropertyVariable) { | |
| 1327 const AtomicString& name = toCSSVariableValue(property.value())->nam
e(); | |
| 1328 if (!seenVariables.add(name).isNewEntry) | |
| 1329 continue; | |
| 1330 output[--unusedEntries] = property; | |
| 1331 continue; | |
| 1332 } | |
| 1333 const unsigned propertyIDIndex = property.id() - firstCSSProperty; | |
| 1334 if (seenProperties.get(propertyIDIndex)) | |
| 1335 continue; | |
| 1336 seenProperties.set(propertyIDIndex); | |
| 1337 output[--unusedEntries] = property; | |
| 1338 } | |
| 1339 } | |
| 1340 | |
| 1341 PassRefPtr<ImmutableStylePropertySet> CSSParser::createStylePropertySet() | |
| 1342 { | |
| 1343 BitArray<numCSSProperties> seenProperties; | |
| 1344 size_t unusedEntries = m_parsedProperties.size(); | |
| 1345 Vector<CSSProperty, 256> results(unusedEntries); | |
| 1346 | |
| 1347 // Important properties have higher priority, so add them first. Duplicate d
efinitions can then be ignored when found. | |
| 1348 HashSet<AtomicString> seenVariables; | |
| 1349 filterProperties(true, m_parsedProperties, results, unusedEntries, seenPrope
rties, seenVariables); | |
| 1350 filterProperties(false, m_parsedProperties, results, unusedEntries, seenProp
erties, seenVariables); | |
| 1351 if (unusedEntries) | |
| 1352 results.remove(0, unusedEntries); | |
| 1353 | |
| 1354 CSSParserMode mode = inViewport() ? CSSViewportRuleMode : m_context.mode(); | |
| 1355 | |
| 1356 return ImmutableStylePropertySet::create(results.data(), results.size(), mod
e); | |
| 1357 } | |
| 1358 | |
| 1359 void CSSParser::addPropertyWithPrefixingVariant(CSSPropertyID propId, PassRefPtr
<CSSValue> value, bool important, bool implicit) | |
| 1360 { | |
| 1361 RefPtr<CSSValue> val = value.get(); | |
| 1362 addProperty(propId, value, important, implicit); | |
| 1363 | |
| 1364 CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propId); | |
| 1365 if (prefixingVariant == propId) | |
| 1366 return; | |
| 1367 | |
| 1368 if (m_currentShorthand) { | |
| 1369 // We can't use ShorthandScope here as we can already be inside one (e.g
we are parsing CSSTransition). | |
| 1370 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand); | |
| 1371 addProperty(prefixingVariant, val.release(), important, implicit); | |
| 1372 m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand); | |
| 1373 } else { | |
| 1374 addProperty(prefixingVariant, val.release(), important, implicit); | |
| 1375 } | |
| 1376 } | |
| 1377 | |
| 1378 void CSSParser::addProperty(CSSPropertyID propId, PassRefPtr<CSSValue> value, bo
ol important, bool implicit) | |
| 1379 { | |
| 1380 CSSPrimitiveValue* primitiveValue = value->isPrimitiveValue() ? toCSSPrimiti
veValue(value.get()) : 0; | |
| 1381 // This property doesn't belong to a shorthand or is a CSS variable (which w
ill be resolved later). | |
| 1382 if (!m_currentShorthand || (primitiveValue && primitiveValue->isVariableName
())) { | |
| 1383 m_parsedProperties.append(CSSProperty(propId, value, important, false, C
SSPropertyInvalid, m_implicitShorthand || implicit)); | |
| 1384 return; | |
| 1385 } | |
| 1386 | |
| 1387 Vector<StylePropertyShorthand, 4> shorthands; | |
| 1388 getMatchingShorthandsForLonghand(propId, &shorthands); | |
| 1389 // The longhand does not belong to multiple shorthands. | |
| 1390 if (shorthands.size() == 1) | |
| 1391 m_parsedProperties.append(CSSProperty(propId, value, important, true, CS
SPropertyInvalid, m_implicitShorthand || implicit)); | |
| 1392 else | |
| 1393 m_parsedProperties.append(CSSProperty(propId, value, important, true, in
dexOfShorthandForLonghand(m_currentShorthand, shorthands), m_implicitShorthand |
| implicit)); | |
| 1394 } | |
| 1395 | |
| 1396 void CSSParser::rollbackLastProperties(int num) | |
| 1397 { | |
| 1398 ASSERT(num >= 0); | |
| 1399 ASSERT(m_parsedProperties.size() >= static_cast<unsigned>(num)); | |
| 1400 m_parsedProperties.shrink(m_parsedProperties.size() - num); | |
| 1401 } | |
| 1402 | |
| 1403 void CSSParser::clearProperties() | |
| 1404 { | |
| 1405 m_parsedProperties.clear(); | |
| 1406 m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES; | |
| 1407 m_hasFontFaceOnlyValues = false; | |
| 1408 } | |
| 1409 | |
| 1410 KURL CSSParser::completeURL(const String& url) const | |
| 1411 { | |
| 1412 return m_context.completeURL(url); | |
| 1413 } | |
| 1414 | |
| 1415 bool CSSParser::validCalculationUnit(CSSParserValue* value, Units unitflags, Rel
easeParsedCalcValueCondition releaseCalc) | |
| 1416 { | |
| 1417 bool mustBeNonNegative = unitflags & FNonNeg; | |
| 1418 | |
| 1419 if (!parseCalculation(value, mustBeNonNegative ? ValueRangeNonNegative : Val
ueRangeAll)) | |
| 1420 return false; | |
| 1421 | |
| 1422 bool b = false; | |
| 1423 switch (m_parsedCalculation->category()) { | |
| 1424 case CalcLength: | |
| 1425 b = (unitflags & FLength); | |
| 1426 break; | |
| 1427 case CalcPercent: | |
| 1428 b = (unitflags & FPercent); | |
| 1429 if (b && mustBeNonNegative && m_parsedCalculation->isNegative()) | |
| 1430 b = false; | |
| 1431 break; | |
| 1432 case CalcNumber: | |
| 1433 b = (unitflags & FNumber); | |
| 1434 if (!b && (unitflags & FInteger) && m_parsedCalculation->isInt()) | |
| 1435 b = true; | |
| 1436 if (b && mustBeNonNegative && m_parsedCalculation->isNegative()) | |
| 1437 b = false; | |
| 1438 break; | |
| 1439 case CalcPercentLength: | |
| 1440 b = (unitflags & FPercent) && (unitflags & FLength); | |
| 1441 break; | |
| 1442 case CalcPercentNumber: | |
| 1443 b = (unitflags & FPercent) && (unitflags & FNumber); | |
| 1444 break; | |
| 1445 case CalcVariable: | |
| 1446 b = true; | |
| 1447 break; | |
| 1448 case CalcOther: | |
| 1449 break; | |
| 1450 } | |
| 1451 if (!b || releaseCalc == ReleaseParsedCalcValue) | |
| 1452 m_parsedCalculation.release(); | |
| 1453 return b; | |
| 1454 } | |
| 1455 | |
| 1456 inline bool CSSParser::shouldAcceptUnitLessValues(CSSParserValue* value, Units u
nitflags, CSSParserMode cssParserMode) | |
| 1457 { | |
| 1458 // Quirks mode and presentation attributes accept unit less values. | |
| 1459 return (unitflags & (FLength | FAngle | FTime)) && (!value->fValue || isUnit
LessLengthParsingEnabledForMode(cssParserMode)); | |
| 1460 } | |
| 1461 | |
| 1462 bool CSSParser::validUnit(CSSParserValue* value, Units unitflags, CSSParserMode
cssParserMode, ReleaseParsedCalcValueCondition releaseCalc) | |
| 1463 { | |
| 1464 if (isCalculation(value)) | |
| 1465 return validCalculationUnit(value, unitflags, releaseCalc); | |
| 1466 | |
| 1467 bool b = false; | |
| 1468 switch (value->unit) { | |
| 1469 case CSSPrimitiveValue::CSS_VARIABLE_NAME: | |
| 1470 // Variables are checked at the point they are dereferenced because unit
type is not available here. | |
| 1471 b = true; | |
| 1472 break; | |
| 1473 case CSSPrimitiveValue::CSS_NUMBER: | |
| 1474 b = (unitflags & FNumber); | |
| 1475 if (!b && shouldAcceptUnitLessValues(value, unitflags, cssParserMode)) { | |
| 1476 value->unit = (unitflags & FLength) ? CSSPrimitiveValue::CSS_PX : | |
| 1477 ((unitflags & FAngle) ? CSSPrimitiveValue::CSS_DEG : C
SSPrimitiveValue::CSS_MS); | |
| 1478 b = true; | |
| 1479 } | |
| 1480 if (!b && (unitflags & FInteger) && value->isInt) | |
| 1481 b = true; | |
| 1482 if (!b && (unitflags & FPositiveInteger) && value->isInt && value->fValu
e > 0) | |
| 1483 b = true; | |
| 1484 break; | |
| 1485 case CSSPrimitiveValue::CSS_PERCENTAGE: | |
| 1486 b = (unitflags & FPercent); | |
| 1487 break; | |
| 1488 case CSSParserValue::Q_EMS: | |
| 1489 case CSSPrimitiveValue::CSS_EMS: | |
| 1490 case CSSPrimitiveValue::CSS_REMS: | |
| 1491 case CSSPrimitiveValue::CSS_CHS: | |
| 1492 case CSSPrimitiveValue::CSS_EXS: | |
| 1493 case CSSPrimitiveValue::CSS_PX: | |
| 1494 case CSSPrimitiveValue::CSS_CM: | |
| 1495 case CSSPrimitiveValue::CSS_MM: | |
| 1496 case CSSPrimitiveValue::CSS_IN: | |
| 1497 case CSSPrimitiveValue::CSS_PT: | |
| 1498 case CSSPrimitiveValue::CSS_PC: | |
| 1499 case CSSPrimitiveValue::CSS_VW: | |
| 1500 case CSSPrimitiveValue::CSS_VH: | |
| 1501 case CSSPrimitiveValue::CSS_VMIN: | |
| 1502 case CSSPrimitiveValue::CSS_VMAX: | |
| 1503 b = (unitflags & FLength); | |
| 1504 break; | |
| 1505 case CSSPrimitiveValue::CSS_MS: | |
| 1506 case CSSPrimitiveValue::CSS_S: | |
| 1507 b = (unitflags & FTime); | |
| 1508 break; | |
| 1509 case CSSPrimitiveValue::CSS_DEG: | |
| 1510 case CSSPrimitiveValue::CSS_RAD: | |
| 1511 case CSSPrimitiveValue::CSS_GRAD: | |
| 1512 case CSSPrimitiveValue::CSS_TURN: | |
| 1513 b = (unitflags & FAngle); | |
| 1514 break; | |
| 1515 case CSSPrimitiveValue::CSS_DPPX: | |
| 1516 case CSSPrimitiveValue::CSS_DPI: | |
| 1517 case CSSPrimitiveValue::CSS_DPCM: | |
| 1518 b = (unitflags & FResolution); | |
| 1519 break; | |
| 1520 case CSSPrimitiveValue::CSS_HZ: | |
| 1521 case CSSPrimitiveValue::CSS_KHZ: | |
| 1522 case CSSPrimitiveValue::CSS_DIMENSION: | |
| 1523 default: | |
| 1524 break; | |
| 1525 } | |
| 1526 if (b && unitflags & FNonNeg && value->fValue < 0) | |
| 1527 b = false; | |
| 1528 return b; | |
| 1529 } | |
| 1530 | |
| 1531 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSP
arserValue* value) | |
| 1532 { | |
| 1533 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME) | |
| 1534 return createPrimitiveVariableNameValue(value); | |
| 1535 | |
| 1536 if (m_parsedCalculation) { | |
| 1537 ASSERT(isCalculation(value)); | |
| 1538 return CSSPrimitiveValue::create(m_parsedCalculation.release()); | |
| 1539 } | |
| 1540 | |
| 1541 ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPr
imitiveValue::CSS_KHZ) | |
| 1542 || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrim
itiveValue::CSS_CHS) | |
| 1543 || (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimit
iveValue::CSS_VMAX) | |
| 1544 || (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrim
itiveValue::CSS_DPCM)); | |
| 1545 return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveVal
ue::UnitTypes>(value->unit)); | |
| 1546 } | |
| 1547 | |
| 1548 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveStringValue(CSSPa
rserValue* value) | |
| 1549 { | |
| 1550 ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPri
mitiveValue::CSS_IDENT); | |
| 1551 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRI
NG); | |
| 1552 } | |
| 1553 | |
| 1554 inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveVariableNameValue
(CSSParserValue* value) | |
| 1555 { | |
| 1556 ASSERT(value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME); | |
| 1557 return CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_VARIA
BLE_NAME); | |
| 1558 } | |
| 1559 | |
| 1560 static inline bool isComma(CSSParserValue* value) | |
| 1561 { | |
| 1562 return value && value->unit == CSSParserValue::Operator && value->iValue ==
','; | |
| 1563 } | |
| 1564 | |
| 1565 static inline bool isForwardSlashOperator(CSSParserValue* value) | |
| 1566 { | |
| 1567 ASSERT(value); | |
| 1568 return value->unit == CSSParserValue::Operator && value->iValue == '/'; | |
| 1569 } | |
| 1570 | |
| 1571 static bool isGeneratedImageValue(CSSParserValue* val) | |
| 1572 { | |
| 1573 if (val->unit != CSSParserValue::Function) | |
| 1574 return false; | |
| 1575 | |
| 1576 return equalIgnoringCase(val->function->name, "-webkit-gradient(") | |
| 1577 || equalIgnoringCase(val->function->name, "-webkit-linear-gradient(") | |
| 1578 || equalIgnoringCase(val->function->name, "linear-gradient(") | |
| 1579 || equalIgnoringCase(val->function->name, "-webkit-repeating-linear-grad
ient(") | |
| 1580 || equalIgnoringCase(val->function->name, "repeating-linear-gradient(") | |
| 1581 || equalIgnoringCase(val->function->name, "-webkit-radial-gradient(") | |
| 1582 || equalIgnoringCase(val->function->name, "radial-gradient(") | |
| 1583 || equalIgnoringCase(val->function->name, "-webkit-repeating-radial-grad
ient(") | |
| 1584 || equalIgnoringCase(val->function->name, "repeating-radial-gradient(") | |
| 1585 || equalIgnoringCase(val->function->name, "-webkit-canvas(") | |
| 1586 || equalIgnoringCase(val->function->name, "-webkit-cross-fade("); | |
| 1587 } | |
| 1588 | |
| 1589 bool CSSParser::validWidthOrHeight(CSSParserValue* value) | |
| 1590 { | |
| 1591 int id = value->id; | |
| 1592 if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueW
ebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAva
ilable || id == CSSValueWebkitFitContent) | |
| 1593 return true; | |
| 1594 return !id && validUnit(value, FLength | FPercent | FNonNeg); | |
| 1595 } | |
| 1596 | |
| 1597 inline PassRefPtr<CSSPrimitiveValue> CSSParser::parseValidPrimitive(CSSValueID i
dentifier, CSSParserValue* value) | |
| 1598 { | |
| 1599 if (identifier) | |
| 1600 return cssValuePool().createIdentifierValue(identifier); | |
| 1601 if (value->unit == CSSPrimitiveValue::CSS_STRING) | |
| 1602 return createPrimitiveStringValue(value); | |
| 1603 if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimit
iveValue::CSS_KHZ) | |
| 1604 return createPrimitiveNumericValue(value); | |
| 1605 if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiv
eValue::CSS_CHS) | |
| 1606 return createPrimitiveNumericValue(value); | |
| 1607 if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveV
alue::CSS_VMAX) | |
| 1608 return createPrimitiveNumericValue(value); | |
| 1609 if (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiv
eValue::CSS_DPCM) | |
| 1610 return createPrimitiveNumericValue(value); | |
| 1611 if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME) | |
| 1612 return createPrimitiveVariableNameValue(value); | |
| 1613 if (value->unit >= CSSParserValue::Q_EMS) | |
| 1614 return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPr
imitiveValue::CSS_EMS); | |
| 1615 if (isCalculation(value)) | |
| 1616 return CSSPrimitiveValue::create(m_parsedCalculation.release()); | |
| 1617 | |
| 1618 return 0; | |
| 1619 } | |
| 1620 | |
| 1621 void CSSParser::addExpandedPropertyForValue(CSSPropertyID propId, PassRefPtr<CSS
Value> prpValue, bool important) | |
| 1622 { | |
| 1623 const StylePropertyShorthand& shorthand = shorthandForProperty(propId); | |
| 1624 unsigned shorthandLength = shorthand.length(); | |
| 1625 if (!shorthandLength) { | |
| 1626 addProperty(propId, prpValue, important); | |
| 1627 return; | |
| 1628 } | |
| 1629 | |
| 1630 RefPtr<CSSValue> value = prpValue; | |
| 1631 ShorthandScope scope(this, propId); | |
| 1632 const CSSPropertyID* longhands = shorthand.properties(); | |
| 1633 for (unsigned i = 0; i < shorthandLength; ++i) | |
| 1634 addProperty(longhands[i], value, important); | |
| 1635 } | |
| 1636 | |
| 1637 void CSSParser::setCurrentProperty(CSSPropertyID propId) | |
| 1638 { | |
| 1639 m_id = propId; | |
| 1640 } | |
| 1641 | |
| 1642 bool CSSParser::parseValue(CSSPropertyID propId, bool important) | |
| 1643 { | |
| 1644 if (!isInternalPropertyAndValueParsingEnabledForMode(m_context.mode()) && is
InternalProperty(propId)) | |
| 1645 return false; | |
| 1646 | |
| 1647 // We don't count the UA style sheet in our statistics. | |
| 1648 if (m_useCounter) | |
| 1649 m_useCounter->count(m_context, propId); | |
| 1650 | |
| 1651 if (!m_valueList) | |
| 1652 return false; | |
| 1653 | |
| 1654 CSSParserValue* value = m_valueList->current(); | |
| 1655 | |
| 1656 if (!value) | |
| 1657 return false; | |
| 1658 | |
| 1659 if (inViewport()) { | |
| 1660 // Allow @viewport rules from UA stylesheets even if the feature is disa
bled. | |
| 1661 if (!RuntimeEnabledFeatures::cssViewportEnabled() && !isUASheetBehavior(
m_context.mode())) | |
| 1662 return false; | |
| 1663 | |
| 1664 return parseViewportProperty(propId, important); | |
| 1665 } | |
| 1666 | |
| 1667 // Note: m_parsedCalculation is used to pass the calc value to validUnit and
then cleared at the end of this function. | |
| 1668 // FIXME: This is to avoid having to pass parsedCalc to all validUnit caller
s. | |
| 1669 ASSERT(!m_parsedCalculation); | |
| 1670 | |
| 1671 CSSValueID id = value->id; | |
| 1672 | |
| 1673 int num = inShorthand() ? 1 : m_valueList->size(); | |
| 1674 | |
| 1675 if (id == CSSValueInherit) { | |
| 1676 if (num != 1) | |
| 1677 return false; | |
| 1678 addExpandedPropertyForValue(propId, cssValuePool().createInheritedValue(
), important); | |
| 1679 return true; | |
| 1680 } | |
| 1681 else if (id == CSSValueInitial) { | |
| 1682 if (num != 1) | |
| 1683 return false; | |
| 1684 addExpandedPropertyForValue(propId, cssValuePool().createExplicitInitial
Value(), important); | |
| 1685 return true; | |
| 1686 } | |
| 1687 | |
| 1688 if (!id && value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME && num == 1)
{ | |
| 1689 addProperty(propId, createPrimitiveVariableNameValue(value), important); | |
| 1690 m_valueList->next(); | |
| 1691 return true; | |
| 1692 } | |
| 1693 ASSERT(propId != CSSPropertyVariable); | |
| 1694 | |
| 1695 if (isKeywordPropertyID(propId)) { | |
| 1696 if (!isValidKeywordPropertyAndValue(propId, id, m_context)) | |
| 1697 return false; | |
| 1698 if (m_valueList->next() && !inShorthand()) | |
| 1699 return false; | |
| 1700 addProperty(propId, cssValuePool().createIdentifierValue(id), important)
; | |
| 1701 return true; | |
| 1702 } | |
| 1703 | |
| 1704 bool validPrimitive = false; | |
| 1705 RefPtr<CSSValue> parsedValue; | |
| 1706 | |
| 1707 switch (propId) { | |
| 1708 case CSSPropertySize: // <length>{1,2} | auto | [ <page-size
> || [ portrait | landscape] ] | |
| 1709 return parseSize(propId, important); | |
| 1710 | |
| 1711 case CSSPropertyQuotes: // [<string> <string>]+ | none | inher
it | |
| 1712 if (id) | |
| 1713 validPrimitive = true; | |
| 1714 else | |
| 1715 return parseQuotes(propId, important); | |
| 1716 break; | |
| 1717 case CSSPropertyUnicodeBidi: // normal | embed | bidi-override | isolate | i
solate-override | plaintext | inherit | |
| 1718 if (id == CSSValueNormal | |
| 1719 || id == CSSValueEmbed | |
| 1720 || id == CSSValueBidiOverride | |
| 1721 || id == CSSValueWebkitIsolate | |
| 1722 || id == CSSValueWebkitIsolateOverride | |
| 1723 || id == CSSValueWebkitPlaintext) | |
| 1724 validPrimitive = true; | |
| 1725 break; | |
| 1726 | |
| 1727 case CSSPropertyContent: // [ <string> | <uri> | <counter> | at
tr(X) | open-quote | | |
| 1728 // close-quote | no-open-quote | no-close-quote ]+ | inherit | |
| 1729 return parseContent(propId, important); | |
| 1730 | |
| 1731 case CSSPropertyClip: // <shape> | auto | inherit | |
| 1732 if (id == CSSValueAuto) | |
| 1733 validPrimitive = true; | |
| 1734 else if (value->unit == CSSParserValue::Function) | |
| 1735 return parseClipShape(propId, important); | |
| 1736 break; | |
| 1737 | |
| 1738 /* Start of supported CSS properties with validation. This is needed for par
seShorthand to work | |
| 1739 * correctly and allows optimization in WebCore::applyRule(..) | |
| 1740 */ | |
| 1741 case CSSPropertyOverflow: { | |
| 1742 ShorthandScope scope(this, propId); | |
| 1743 if (num != 1 || !parseValue(CSSPropertyOverflowY, important)) | |
| 1744 return false; | |
| 1745 | |
| 1746 RefPtr<CSSValue> overflowXValue; | |
| 1747 | |
| 1748 // FIXME: -webkit-paged-x or -webkit-paged-y only apply to overflow-y. I
f this value has been | |
| 1749 // set using the shorthand, then for now overflow-x will default to auto
, but once we implement | |
| 1750 // pagination controls, it should default to hidden. If the overflow-y v
alue is anything but | |
| 1751 // paged-x or paged-y, then overflow-x and overflow-y should have the sa
me value. | |
| 1752 if (id == CSSValueWebkitPagedX || id == CSSValueWebkitPagedY) | |
| 1753 overflowXValue = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 1754 else | |
| 1755 overflowXValue = m_parsedProperties.last().value(); | |
| 1756 addProperty(CSSPropertyOverflowX, overflowXValue.release(), important); | |
| 1757 return true; | |
| 1758 } | |
| 1759 | |
| 1760 case CSSPropertyTextAlign: | |
| 1761 // left | right | center | justify | -webkit-left | -webkit-right | -web
kit-center | -webkit-match-parent | |
| 1762 // | start | end | <string> | inherit | -webkit-auto (converted to start
) | |
| 1763 if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id
== CSSValueStart || id == CSSValueEnd | |
| 1764 || value->unit == CSSPrimitiveValue::CSS_STRING) | |
| 1765 validPrimitive = true; | |
| 1766 break; | |
| 1767 | |
| 1768 case CSSPropertyFontWeight: { // normal | bold | bolder | lighter | 100 | 2
00 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit | |
| 1769 if (m_valueList->size() != 1) | |
| 1770 return false; | |
| 1771 return parseFontWeight(important); | |
| 1772 } | |
| 1773 case CSSPropertyBorderSpacing: { | |
| 1774 if (num == 1) { | |
| 1775 ShorthandScope scope(this, CSSPropertyBorderSpacing); | |
| 1776 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important)
) | |
| 1777 return false; | |
| 1778 CSSValue* value = m_parsedProperties.last().value(); | |
| 1779 addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important
); | |
| 1780 return true; | |
| 1781 } | |
| 1782 else if (num == 2) { | |
| 1783 ShorthandScope scope(this, CSSPropertyBorderSpacing); | |
| 1784 if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important)
|| !parseValue(CSSPropertyWebkitBorderVerticalSpacing, important)) | |
| 1785 return false; | |
| 1786 return true; | |
| 1787 } | |
| 1788 return false; | |
| 1789 } | |
| 1790 case CSSPropertyWebkitBorderHorizontalSpacing: | |
| 1791 case CSSPropertyWebkitBorderVerticalSpacing: | |
| 1792 validPrimitive = validUnit(value, FLength | FNonNeg); | |
| 1793 break; | |
| 1794 case CSSPropertyOutlineColor: // <color> | invert | inherit | |
| 1795 // Outline color has "invert" as additional keyword. | |
| 1796 // Also, we want to allow the special focus color even in HTML Standard
parsing mode. | |
| 1797 if (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor) { | |
| 1798 validPrimitive = true; | |
| 1799 break; | |
| 1800 } | |
| 1801 /* nobreak */ | |
| 1802 case CSSPropertyBackgroundColor: // <color> | inherit | |
| 1803 case CSSPropertyBorderTopColor: // <color> | inherit | |
| 1804 case CSSPropertyBorderRightColor: | |
| 1805 case CSSPropertyBorderBottomColor: | |
| 1806 case CSSPropertyBorderLeftColor: | |
| 1807 case CSSPropertyWebkitBorderStartColor: | |
| 1808 case CSSPropertyWebkitBorderEndColor: | |
| 1809 case CSSPropertyWebkitBorderBeforeColor: | |
| 1810 case CSSPropertyWebkitBorderAfterColor: | |
| 1811 case CSSPropertyColor: // <color> | inherit | |
| 1812 case CSSPropertyTextDecorationColor: // CSS3 text decoration colors | |
| 1813 case CSSPropertyTextLineThroughColor: | |
| 1814 case CSSPropertyTextUnderlineColor: | |
| 1815 case CSSPropertyTextOverlineColor: | |
| 1816 case CSSPropertyWebkitColumnRuleColor: | |
| 1817 case CSSPropertyWebkitTextEmphasisColor: | |
| 1818 case CSSPropertyWebkitTextFillColor: | |
| 1819 case CSSPropertyWebkitTextStrokeColor: | |
| 1820 if (propId == CSSPropertyTextDecorationColor | |
| 1821 && !RuntimeEnabledFeatures::css3TextDecorationsEnabled()) | |
| 1822 return false; | |
| 1823 | |
| 1824 if ((id >= CSSValueAqua && id <= CSSValueWebkitText) || id == CSSValueMe
nu) { | |
| 1825 validPrimitive = isValueAllowedInMode(id, m_context.mode()); | |
| 1826 } else { | |
| 1827 parsedValue = parseColor(); | |
| 1828 if (parsedValue) | |
| 1829 m_valueList->next(); | |
| 1830 } | |
| 1831 break; | |
| 1832 | |
| 1833 case CSSPropertyCursor: { | |
| 1834 // Grammar defined by CSS3 UI and modified by CSS4 images: | |
| 1835 // [ [<image> [<x> <y>]?,]* | |
| 1836 // [ auto | crosshair | default | pointer | progress | move | e-resize |
ne-resize | | |
| 1837 // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize |
ew-resize | | |
| 1838 // ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | tex
t | wait | help | | |
| 1839 // vertical-text | cell | context-menu | alias | copy | no-drop | not-al
lowed | -webkit-zoom-in | |
| 1840 // -webkit-zoom-out | all-scroll | -webkit-grab | -webkit-grabbing ] ] |
inherit | |
| 1841 RefPtr<CSSValueList> list; | |
| 1842 while (value) { | |
| 1843 RefPtr<CSSValue> image = 0; | |
| 1844 if (value->unit == CSSPrimitiveValue::CSS_URI) { | |
| 1845 String uri = value->string; | |
| 1846 if (!uri.isNull()) | |
| 1847 image = CSSImageValue::create(completeURL(uri)); | |
| 1848 } else if (value->unit == CSSParserValue::Function && equalIgnoringC
ase(value->function->name, "-webkit-image-set(")) { | |
| 1849 image = parseImageSet(m_valueList.get()); | |
| 1850 if (!image) | |
| 1851 break; | |
| 1852 } else | |
| 1853 break; | |
| 1854 | |
| 1855 Vector<int> coords; | |
| 1856 value = m_valueList->next(); | |
| 1857 while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) { | |
| 1858 coords.append(int(value->fValue)); | |
| 1859 value = m_valueList->next(); | |
| 1860 } | |
| 1861 bool hasHotSpot = false; | |
| 1862 IntPoint hotSpot(-1, -1); | |
| 1863 int nrcoords = coords.size(); | |
| 1864 if (nrcoords > 0 && nrcoords != 2) | |
| 1865 return false; | |
| 1866 if (nrcoords == 2) { | |
| 1867 hasHotSpot = true; | |
| 1868 hotSpot = IntPoint(coords[0], coords[1]); | |
| 1869 } | |
| 1870 | |
| 1871 if (!list) | |
| 1872 list = CSSValueList::createCommaSeparated(); | |
| 1873 | |
| 1874 if (image) | |
| 1875 list->append(CSSCursorImageValue::create(image, hasHotSpot, hotS
pot)); | |
| 1876 | |
| 1877 if (!value || !(value->unit == CSSParserValue::Operator && value->iV
alue == ',')) | |
| 1878 return false; | |
| 1879 value = m_valueList->next(); // comma | |
| 1880 } | |
| 1881 if (list) { | |
| 1882 if (!value) | |
| 1883 return false; | |
| 1884 if (inQuirksMode() && value->id == CSSValueHand) // MSIE 5 compatibi
lity :/ | |
| 1885 list->append(cssValuePool().createIdentifierValue(CSSValuePointe
r)); | |
| 1886 else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGr
abbing) || value->id == CSSValueCopy || value->id == CSSValueNone) | |
| 1887 list->append(cssValuePool().createIdentifierValue(value->id)); | |
| 1888 m_valueList->next(); | |
| 1889 parsedValue = list.release(); | |
| 1890 break; | |
| 1891 } else if (value) { | |
| 1892 id = value->id; | |
| 1893 if (inQuirksMode() && value->id == CSSValueHand) { // MSIE 5 compati
bility :/ | |
| 1894 id = CSSValuePointer; | |
| 1895 validPrimitive = true; | |
| 1896 } else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkit
Grabbing) || value->id == CSSValueCopy || value->id == CSSValueNone) | |
| 1897 validPrimitive = true; | |
| 1898 } else { | |
| 1899 ASSERT_NOT_REACHED(); | |
| 1900 return false; | |
| 1901 } | |
| 1902 break; | |
| 1903 } | |
| 1904 | |
| 1905 case CSSPropertyBackgroundBlendMode: | |
| 1906 case CSSPropertyBackgroundAttachment: | |
| 1907 case CSSPropertyBackgroundClip: | |
| 1908 case CSSPropertyWebkitBackgroundClip: | |
| 1909 case CSSPropertyWebkitBackgroundComposite: | |
| 1910 case CSSPropertyBackgroundImage: | |
| 1911 case CSSPropertyBackgroundOrigin: | |
| 1912 case CSSPropertyMaskSourceType: | |
| 1913 case CSSPropertyWebkitBackgroundOrigin: | |
| 1914 case CSSPropertyBackgroundPosition: | |
| 1915 case CSSPropertyBackgroundPositionX: | |
| 1916 case CSSPropertyBackgroundPositionY: | |
| 1917 case CSSPropertyBackgroundSize: | |
| 1918 case CSSPropertyWebkitBackgroundSize: | |
| 1919 case CSSPropertyBackgroundRepeat: | |
| 1920 case CSSPropertyBackgroundRepeatX: | |
| 1921 case CSSPropertyBackgroundRepeatY: | |
| 1922 case CSSPropertyWebkitMaskClip: | |
| 1923 case CSSPropertyWebkitMaskComposite: | |
| 1924 case CSSPropertyWebkitMaskImage: | |
| 1925 case CSSPropertyWebkitMaskOrigin: | |
| 1926 case CSSPropertyWebkitMaskPosition: | |
| 1927 case CSSPropertyWebkitMaskPositionX: | |
| 1928 case CSSPropertyWebkitMaskPositionY: | |
| 1929 case CSSPropertyWebkitMaskSize: | |
| 1930 case CSSPropertyWebkitMaskRepeat: | |
| 1931 case CSSPropertyWebkitMaskRepeatX: | |
| 1932 case CSSPropertyWebkitMaskRepeatY: | |
| 1933 { | |
| 1934 RefPtr<CSSValue> val1; | |
| 1935 RefPtr<CSSValue> val2; | |
| 1936 CSSPropertyID propId1, propId2; | |
| 1937 bool result = false; | |
| 1938 if (parseFillProperty(propId, propId1, propId2, val1, val2)) { | |
| 1939 OwnPtr<ShorthandScope> shorthandScope; | |
| 1940 if (propId == CSSPropertyBackgroundPosition || | |
| 1941 propId == CSSPropertyBackgroundRepeat || | |
| 1942 propId == CSSPropertyWebkitMaskPosition || | |
| 1943 propId == CSSPropertyWebkitMaskRepeat) { | |
| 1944 shorthandScope = adoptPtr(new ShorthandScope(this, propId)); | |
| 1945 } | |
| 1946 addProperty(propId1, val1.release(), important); | |
| 1947 if (val2) | |
| 1948 addProperty(propId2, val2.release(), important); | |
| 1949 result = true; | |
| 1950 } | |
| 1951 m_implicitShorthand = false; | |
| 1952 return result; | |
| 1953 } | |
| 1954 case CSSPropertyObjectPosition: | |
| 1955 return RuntimeEnabledFeatures::objectFitPositionEnabled() && parseObject
Position(important); | |
| 1956 case CSSPropertyListStyleImage: // <uri> | none | inherit | |
| 1957 case CSSPropertyBorderImageSource: | |
| 1958 case CSSPropertyWebkitMaskBoxImageSource: | |
| 1959 if (id == CSSValueNone) { | |
| 1960 parsedValue = cssValuePool().createIdentifierValue(CSSValueNone); | |
| 1961 m_valueList->next(); | |
| 1962 } else if (value->unit == CSSPrimitiveValue::CSS_URI) { | |
| 1963 parsedValue = CSSImageValue::create(completeURL(value->string)); | |
| 1964 m_valueList->next(); | |
| 1965 } else if (isGeneratedImageValue(value)) { | |
| 1966 if (parseGeneratedImage(m_valueList.get(), parsedValue)) | |
| 1967 m_valueList->next(); | |
| 1968 else | |
| 1969 return false; | |
| 1970 } | |
| 1971 else if (value->unit == CSSParserValue::Function && equalIgnoringCase(va
lue->function->name, "-webkit-image-set(")) { | |
| 1972 parsedValue = parseImageSet(m_valueList.get()); | |
| 1973 if (!parsedValue) | |
| 1974 return false; | |
| 1975 m_valueList->next(); | |
| 1976 } | |
| 1977 break; | |
| 1978 | |
| 1979 case CSSPropertyWebkitTextStrokeWidth: | |
| 1980 case CSSPropertyOutlineWidth: // <border-width> | inherit | |
| 1981 case CSSPropertyBorderTopWidth: //// <border-width> | inherit | |
| 1982 case CSSPropertyBorderRightWidth: // Which is defined as | |
| 1983 case CSSPropertyBorderBottomWidth: // thin | medium | thick | <length> | |
| 1984 case CSSPropertyBorderLeftWidth: | |
| 1985 case CSSPropertyWebkitBorderStartWidth: | |
| 1986 case CSSPropertyWebkitBorderEndWidth: | |
| 1987 case CSSPropertyWebkitBorderBeforeWidth: | |
| 1988 case CSSPropertyWebkitBorderAfterWidth: | |
| 1989 case CSSPropertyWebkitColumnRuleWidth: | |
| 1990 if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick) | |
| 1991 validPrimitive = true; | |
| 1992 else | |
| 1993 validPrimitive = validUnit(value, FLength | FNonNeg); | |
| 1994 break; | |
| 1995 | |
| 1996 case CSSPropertyLetterSpacing: // normal | <length> | inherit | |
| 1997 case CSSPropertyWordSpacing: // normal | <length> | inherit | |
| 1998 if (id == CSSValueNormal) | |
| 1999 validPrimitive = true; | |
| 2000 else | |
| 2001 validPrimitive = validUnit(value, FLength); | |
| 2002 break; | |
| 2003 | |
| 2004 case CSSPropertyTextIndent: | |
| 2005 parsedValue = parseTextIndent(); | |
| 2006 break; | |
| 2007 | |
| 2008 case CSSPropertyPaddingTop: //// <padding-width> | inherit | |
| 2009 case CSSPropertyPaddingRight: // Which is defined as | |
| 2010 case CSSPropertyPaddingBottom: // <length> | <percentage> | |
| 2011 case CSSPropertyPaddingLeft: //// | |
| 2012 case CSSPropertyWebkitPaddingStart: | |
| 2013 case CSSPropertyWebkitPaddingEnd: | |
| 2014 case CSSPropertyWebkitPaddingBefore: | |
| 2015 case CSSPropertyWebkitPaddingAfter: | |
| 2016 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg))
; | |
| 2017 break; | |
| 2018 | |
| 2019 case CSSPropertyMaxWidth: | |
| 2020 case CSSPropertyWebkitMaxLogicalWidth: | |
| 2021 case CSSPropertyMaxHeight: | |
| 2022 case CSSPropertyWebkitMaxLogicalHeight: | |
| 2023 validPrimitive = (id == CSSValueNone || validWidthOrHeight(value)); | |
| 2024 break; | |
| 2025 | |
| 2026 case CSSPropertyMinWidth: | |
| 2027 case CSSPropertyWebkitMinLogicalWidth: | |
| 2028 case CSSPropertyMinHeight: | |
| 2029 case CSSPropertyWebkitMinLogicalHeight: | |
| 2030 validPrimitive = validWidthOrHeight(value); | |
| 2031 break; | |
| 2032 | |
| 2033 case CSSPropertyWidth: | |
| 2034 case CSSPropertyWebkitLogicalWidth: | |
| 2035 case CSSPropertyHeight: | |
| 2036 case CSSPropertyWebkitLogicalHeight: | |
| 2037 validPrimitive = (id == CSSValueAuto || validWidthOrHeight(value)); | |
| 2038 break; | |
| 2039 | |
| 2040 case CSSPropertyFontSize: | |
| 2041 return parseFontSize(important); | |
| 2042 | |
| 2043 case CSSPropertyFontVariant: // normal | small-caps | inherit | |
| 2044 return parseFontVariant(important); | |
| 2045 | |
| 2046 case CSSPropertyVerticalAlign: | |
| 2047 // baseline | sub | super | top | text-top | middle | bottom | text-bott
om | | |
| 2048 // <percentage> | <length> | inherit | |
| 2049 | |
| 2050 if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle) | |
| 2051 validPrimitive = true; | |
| 2052 else | |
| 2053 validPrimitive = (!id && validUnit(value, FLength | FPercent)); | |
| 2054 break; | |
| 2055 | |
| 2056 case CSSPropertyBottom: // <length> | <percentage> | auto | in
herit | |
| 2057 case CSSPropertyLeft: // <length> | <percentage> | auto | in
herit | |
| 2058 case CSSPropertyRight: // <length> | <percentage> | auto | in
herit | |
| 2059 case CSSPropertyTop: // <length> | <percentage> | auto | in
herit | |
| 2060 case CSSPropertyMarginTop: //// <margin-width> | inherit | |
| 2061 case CSSPropertyMarginRight: // Which is defined as | |
| 2062 case CSSPropertyMarginBottom: // <length> | <percentage> | auto | i
nherit | |
| 2063 case CSSPropertyMarginLeft: //// | |
| 2064 case CSSPropertyWebkitMarginStart: | |
| 2065 case CSSPropertyWebkitMarginEnd: | |
| 2066 case CSSPropertyWebkitMarginBefore: | |
| 2067 case CSSPropertyWebkitMarginAfter: | |
| 2068 if (id == CSSValueAuto) | |
| 2069 validPrimitive = true; | |
| 2070 else | |
| 2071 validPrimitive = (!id && validUnit(value, FLength | FPercent)); | |
| 2072 break; | |
| 2073 | |
| 2074 case CSSPropertyOrphans: // <integer> | inherit | auto (We've added support
for auto for backwards compatibility) | |
| 2075 case CSSPropertyWidows: // <integer> | inherit | auto (Ditto) | |
| 2076 if (id == CSSValueAuto) | |
| 2077 validPrimitive = true; | |
| 2078 else | |
| 2079 validPrimitive = (!id && validUnit(value, FPositiveInteger, HTMLQuir
ksMode)); | |
| 2080 break; | |
| 2081 | |
| 2082 case CSSPropertyZIndex: // auto | <integer> | inherit | |
| 2083 if (id == CSSValueAuto) | |
| 2084 validPrimitive = true; | |
| 2085 else | |
| 2086 validPrimitive = (!id && validUnit(value, FInteger, HTMLQuirksMode))
; | |
| 2087 break; | |
| 2088 | |
| 2089 case CSSPropertyLineHeight: | |
| 2090 return parseLineHeight(important); | |
| 2091 case CSSPropertyCounterIncrement: // [ <identifier> <integer>? ]+ | none
| inherit | |
| 2092 if (id != CSSValueNone) | |
| 2093 return parseCounter(propId, 1, important); | |
| 2094 validPrimitive = true; | |
| 2095 break; | |
| 2096 case CSSPropertyCounterReset: // [ <identifier> <integer>? ]+ | none
| inherit | |
| 2097 if (id != CSSValueNone) | |
| 2098 return parseCounter(propId, 0, important); | |
| 2099 validPrimitive = true; | |
| 2100 break; | |
| 2101 case CSSPropertyFontFamily: | |
| 2102 // [[ <family-name> | <generic-family> ],]* [<family-name> | <generic-fa
mily>] | inherit | |
| 2103 { | |
| 2104 parsedValue = parseFontFamily(); | |
| 2105 break; | |
| 2106 } | |
| 2107 | |
| 2108 case CSSPropertyTextDecoration: | |
| 2109 // Fall through 'text-decoration-line' parsing if CSS 3 Text Decoration | |
| 2110 // is disabled to match CSS 2.1 rules for parsing 'text-decoration'. | |
| 2111 if (RuntimeEnabledFeatures::css3TextDecorationsEnabled()) { | |
| 2112 // [ <text-decoration-line> || <text-decoration-style> || <text-deco
ration-color> ] | inherit | |
| 2113 return parseShorthand(CSSPropertyTextDecoration, textDecorationShort
hand(), important); | |
| 2114 } | |
| 2115 case CSSPropertyWebkitTextDecorationsInEffect: | |
| 2116 case CSSPropertyTextDecorationLine: | |
| 2117 // none | [ underline || overline || line-through || blink ] | inherit | |
| 2118 return parseTextDecoration(propId, important); | |
| 2119 | |
| 2120 case CSSPropertyTextDecorationStyle: | |
| 2121 // solid | double | dotted | dashed | wavy | |
| 2122 if (RuntimeEnabledFeatures::css3TextDecorationsEnabled() | |
| 2123 && (id == CSSValueSolid || id == CSSValueDouble || id == CSSValueDot
ted || id == CSSValueDashed || id == CSSValueWavy)) | |
| 2124 validPrimitive = true; | |
| 2125 break; | |
| 2126 | |
| 2127 case CSSPropertyTextUnderlinePosition: | |
| 2128 // auto | under | inherit | |
| 2129 if (RuntimeEnabledFeatures::css3TextDecorationsEnabled()) | |
| 2130 return parseTextUnderlinePosition(important); | |
| 2131 return false; | |
| 2132 | |
| 2133 case CSSPropertyZoom: // normal | reset | document | <number> | <pe
rcentage> | inherit | |
| 2134 if (id == CSSValueNormal || id == CSSValueReset || id == CSSValueDocumen
t) | |
| 2135 validPrimitive = true; | |
| 2136 else | |
| 2137 validPrimitive = (!id && validUnit(value, FNumber | FPercent | FNonN
eg, HTMLStandardMode)); | |
| 2138 break; | |
| 2139 | |
| 2140 case CSSPropertySrc: // Only used within @font-face and @-webkit-filter, so
cannot use inherit | initial or be !important. This is a list of urls or local r
eferences. | |
| 2141 if (m_inFilterRule) | |
| 2142 return parseFilterRuleSrc(); | |
| 2143 return parseFontFaceSrc(); | |
| 2144 | |
| 2145 case CSSPropertyUnicodeRange: | |
| 2146 return parseFontFaceUnicodeRange(); | |
| 2147 | |
| 2148 /* CSS3 properties */ | |
| 2149 | |
| 2150 case CSSPropertyBorderImage: | |
| 2151 case CSSPropertyWebkitMaskBoxImage: | |
| 2152 return parseBorderImageShorthand(propId, important); | |
| 2153 case CSSPropertyWebkitBorderImage: { | |
| 2154 if (RefPtr<CSSValue> result = parseBorderImage(propId)) { | |
| 2155 addProperty(propId, result, important); | |
| 2156 return true; | |
| 2157 } | |
| 2158 return false; | |
| 2159 } | |
| 2160 | |
| 2161 case CSSPropertyBorderImageOutset: | |
| 2162 case CSSPropertyWebkitMaskBoxImageOutset: { | |
| 2163 RefPtr<CSSPrimitiveValue> result; | |
| 2164 if (parseBorderImageOutset(result)) { | |
| 2165 addProperty(propId, result, important); | |
| 2166 return true; | |
| 2167 } | |
| 2168 break; | |
| 2169 } | |
| 2170 case CSSPropertyBorderImageRepeat: | |
| 2171 case CSSPropertyWebkitMaskBoxImageRepeat: { | |
| 2172 RefPtr<CSSValue> result; | |
| 2173 if (parseBorderImageRepeat(result)) { | |
| 2174 addProperty(propId, result, important); | |
| 2175 return true; | |
| 2176 } | |
| 2177 break; | |
| 2178 } | |
| 2179 case CSSPropertyBorderImageSlice: | |
| 2180 case CSSPropertyWebkitMaskBoxImageSlice: { | |
| 2181 RefPtr<CSSBorderImageSliceValue> result; | |
| 2182 if (parseBorderImageSlice(propId, result)) { | |
| 2183 addProperty(propId, result, important); | |
| 2184 return true; | |
| 2185 } | |
| 2186 break; | |
| 2187 } | |
| 2188 case CSSPropertyBorderImageWidth: | |
| 2189 case CSSPropertyWebkitMaskBoxImageWidth: { | |
| 2190 RefPtr<CSSPrimitiveValue> result; | |
| 2191 if (parseBorderImageWidth(result)) { | |
| 2192 addProperty(propId, result, important); | |
| 2193 return true; | |
| 2194 } | |
| 2195 break; | |
| 2196 } | |
| 2197 case CSSPropertyBorderTopRightRadius: | |
| 2198 case CSSPropertyBorderTopLeftRadius: | |
| 2199 case CSSPropertyBorderBottomLeftRadius: | |
| 2200 case CSSPropertyBorderBottomRightRadius: { | |
| 2201 if (num != 1 && num != 2) | |
| 2202 return false; | |
| 2203 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg); | |
| 2204 if (!validPrimitive) | |
| 2205 return false; | |
| 2206 RefPtr<CSSPrimitiveValue> parsedValue1 = createPrimitiveNumericValue(val
ue); | |
| 2207 RefPtr<CSSPrimitiveValue> parsedValue2; | |
| 2208 if (num == 2) { | |
| 2209 value = m_valueList->next(); | |
| 2210 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg); | |
| 2211 if (!validPrimitive) | |
| 2212 return false; | |
| 2213 parsedValue2 = createPrimitiveNumericValue(value); | |
| 2214 } else | |
| 2215 parsedValue2 = parsedValue1; | |
| 2216 | |
| 2217 addProperty(propId, createPrimitiveValuePair(parsedValue1.release(), par
sedValue2.release()), important); | |
| 2218 return true; | |
| 2219 } | |
| 2220 case CSSPropertyTabSize: | |
| 2221 validPrimitive = validUnit(value, FInteger | FNonNeg); | |
| 2222 break; | |
| 2223 case CSSPropertyWebkitAspectRatio: | |
| 2224 return parseAspectRatio(important); | |
| 2225 case CSSPropertyBorderRadius: | |
| 2226 case CSSPropertyWebkitBorderRadius: | |
| 2227 return parseBorderRadius(propId, important); | |
| 2228 case CSSPropertyOutlineOffset: | |
| 2229 validPrimitive = validUnit(value, FLength); | |
| 2230 break; | |
| 2231 case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS
3, so treat as CSS3 | |
| 2232 case CSSPropertyBoxShadow: | |
| 2233 case CSSPropertyWebkitBoxShadow: | |
| 2234 if (id == CSSValueNone) | |
| 2235 validPrimitive = true; | |
| 2236 else { | |
| 2237 RefPtr<CSSValueList> shadowValueList = parseShadow(m_valueList.get()
, propId); | |
| 2238 if (shadowValueList) { | |
| 2239 addProperty(propId, shadowValueList.release(), important); | |
| 2240 m_valueList->next(); | |
| 2241 return true; | |
| 2242 } | |
| 2243 return false; | |
| 2244 } | |
| 2245 break; | |
| 2246 case CSSPropertyWebkitBoxReflect: | |
| 2247 if (id == CSSValueNone) | |
| 2248 validPrimitive = true; | |
| 2249 else | |
| 2250 return parseReflect(propId, important); | |
| 2251 break; | |
| 2252 case CSSPropertyOpacity: | |
| 2253 validPrimitive = validUnit(value, FNumber); | |
| 2254 break; | |
| 2255 case CSSPropertyWebkitBoxFlex: | |
| 2256 validPrimitive = validUnit(value, FNumber); | |
| 2257 break; | |
| 2258 case CSSPropertyWebkitBoxFlexGroup: | |
| 2259 validPrimitive = validUnit(value, FInteger | FNonNeg, HTMLStandardMode); | |
| 2260 break; | |
| 2261 case CSSPropertyWebkitBoxOrdinalGroup: | |
| 2262 validPrimitive = validUnit(value, FInteger | FNonNeg, HTMLStandardMode)
&& value->fValue; | |
| 2263 break; | |
| 2264 case CSSPropertyWebkitFilter: | |
| 2265 if (id == CSSValueNone) | |
| 2266 validPrimitive = true; | |
| 2267 else { | |
| 2268 RefPtr<CSSValue> val = parseFilter(); | |
| 2269 if (val) { | |
| 2270 addProperty(propId, val, important); | |
| 2271 return true; | |
| 2272 } | |
| 2273 return false; | |
| 2274 } | |
| 2275 break; | |
| 2276 case CSSPropertyFlex: { | |
| 2277 ShorthandScope scope(this, propId); | |
| 2278 if (id == CSSValueNone) { | |
| 2279 addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(0, CSSPr
imitiveValue::CSS_NUMBER), important); | |
| 2280 addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(0, CSS
PrimitiveValue::CSS_NUMBER), important); | |
| 2281 addProperty(CSSPropertyFlexBasis, cssValuePool().createIdentifierVal
ue(CSSValueAuto), important); | |
| 2282 return true; | |
| 2283 } | |
| 2284 return parseFlex(m_valueList.get(), important); | |
| 2285 } | |
| 2286 case CSSPropertyFlexBasis: | |
| 2287 // FIXME: Support intrinsic dimensions too. | |
| 2288 if (id == CSSValueAuto) | |
| 2289 validPrimitive = true; | |
| 2290 else | |
| 2291 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonN
eg)); | |
| 2292 break; | |
| 2293 case CSSPropertyFlexGrow: | |
| 2294 case CSSPropertyFlexShrink: | |
| 2295 validPrimitive = validUnit(value, FNumber | FNonNeg); | |
| 2296 break; | |
| 2297 case CSSPropertyOrder: | |
| 2298 if (validUnit(value, FInteger, HTMLStandardMode)) { | |
| 2299 if (value->unit != CSSPrimitiveValue::CSS_VARIABLE_NAME) { | |
| 2300 // We restrict the smallest value to int min + 2 because we use
int min and int min + 1 as special values in a hash set. | |
| 2301 parsedValue = cssValuePool().createValue(max(static_cast<double>
(std::numeric_limits<int>::min() + 2), value->fValue), | |
| 2302 static_cast<CSSPrimitiveValue::UnitTypes>(value->unit)); | |
| 2303 m_valueList->next(); | |
| 2304 } else { | |
| 2305 validPrimitive = true; | |
| 2306 } | |
| 2307 } | |
| 2308 break; | |
| 2309 case CSSPropertyInternalMarqueeIncrement: | |
| 2310 if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium) | |
| 2311 validPrimitive = true; | |
| 2312 else | |
| 2313 validPrimitive = validUnit(value, FLength | FPercent); | |
| 2314 break; | |
| 2315 case CSSPropertyInternalMarqueeRepetition: | |
| 2316 if (id == CSSValueInfinite) | |
| 2317 validPrimitive = true; | |
| 2318 else | |
| 2319 validPrimitive = validUnit(value, FInteger | FNonNeg); | |
| 2320 break; | |
| 2321 case CSSPropertyInternalMarqueeSpeed: | |
| 2322 if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast) | |
| 2323 validPrimitive = true; | |
| 2324 else | |
| 2325 validPrimitive = validUnit(value, FTime | FInteger | FNonNeg); | |
| 2326 break; | |
| 2327 case CSSPropertyWebkitFlowInto: | |
| 2328 if (!RuntimeEnabledFeatures::cssRegionsEnabled()) | |
| 2329 return false; | |
| 2330 return parseFlowThread(propId, important); | |
| 2331 case CSSPropertyWebkitFlowFrom: | |
| 2332 if (!RuntimeEnabledFeatures::cssRegionsEnabled()) | |
| 2333 return false; | |
| 2334 return parseRegionThread(propId, important); | |
| 2335 case CSSPropertyWebkitTransform: | |
| 2336 if (id == CSSValueNone) | |
| 2337 validPrimitive = true; | |
| 2338 else { | |
| 2339 RefPtr<CSSValue> transformValue = parseTransform(); | |
| 2340 if (transformValue) { | |
| 2341 addProperty(propId, transformValue.release(), important); | |
| 2342 return true; | |
| 2343 } | |
| 2344 return false; | |
| 2345 } | |
| 2346 break; | |
| 2347 case CSSPropertyWebkitTransformOrigin: | |
| 2348 case CSSPropertyWebkitTransformOriginX: | |
| 2349 case CSSPropertyWebkitTransformOriginY: | |
| 2350 case CSSPropertyWebkitTransformOriginZ: { | |
| 2351 RefPtr<CSSValue> val1; | |
| 2352 RefPtr<CSSValue> val2; | |
| 2353 RefPtr<CSSValue> val3; | |
| 2354 CSSPropertyID propId1, propId2, propId3; | |
| 2355 if (parseTransformOrigin(propId, propId1, propId2, propId3, val1, val2,
val3)) { | |
| 2356 addProperty(propId1, val1.release(), important); | |
| 2357 if (val2) | |
| 2358 addProperty(propId2, val2.release(), important); | |
| 2359 if (val3) | |
| 2360 addProperty(propId3, val3.release(), important); | |
| 2361 return true; | |
| 2362 } | |
| 2363 return false; | |
| 2364 } | |
| 2365 case CSSPropertyWebkitPerspective: | |
| 2366 if (id == CSSValueNone) | |
| 2367 validPrimitive = true; | |
| 2368 else { | |
| 2369 // Accepting valueless numbers is a quirk of the -webkit prefixed ve
rsion of the property. | |
| 2370 if (validUnit(value, FNumber | FLength | FNonNeg)) { | |
| 2371 RefPtr<CSSValue> val = createPrimitiveNumericValue(value); | |
| 2372 if (val) { | |
| 2373 addProperty(propId, val.release(), important); | |
| 2374 return true; | |
| 2375 } | |
| 2376 return false; | |
| 2377 } | |
| 2378 } | |
| 2379 break; | |
| 2380 case CSSPropertyWebkitPerspectiveOrigin: | |
| 2381 case CSSPropertyWebkitPerspectiveOriginX: | |
| 2382 case CSSPropertyWebkitPerspectiveOriginY: { | |
| 2383 RefPtr<CSSValue> val1; | |
| 2384 RefPtr<CSSValue> val2; | |
| 2385 CSSPropertyID propId1, propId2; | |
| 2386 if (parsePerspectiveOrigin(propId, propId1, propId2, val1, val2)) { | |
| 2387 addProperty(propId1, val1.release(), important); | |
| 2388 if (val2) | |
| 2389 addProperty(propId2, val2.release(), important); | |
| 2390 return true; | |
| 2391 } | |
| 2392 return false; | |
| 2393 } | |
| 2394 case CSSPropertyAnimationDelay: | |
| 2395 case CSSPropertyAnimationDirection: | |
| 2396 case CSSPropertyAnimationDuration: | |
| 2397 case CSSPropertyAnimationFillMode: | |
| 2398 case CSSPropertyAnimationName: | |
| 2399 case CSSPropertyAnimationPlayState: | |
| 2400 case CSSPropertyAnimationIterationCount: | |
| 2401 case CSSPropertyAnimationTimingFunction: | |
| 2402 if (!RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled()) | |
| 2403 break; | |
| 2404 case CSSPropertyWebkitAnimationDelay: | |
| 2405 case CSSPropertyWebkitAnimationDirection: | |
| 2406 case CSSPropertyWebkitAnimationDuration: | |
| 2407 case CSSPropertyWebkitAnimationFillMode: | |
| 2408 case CSSPropertyWebkitAnimationName: | |
| 2409 case CSSPropertyWebkitAnimationPlayState: | |
| 2410 case CSSPropertyWebkitAnimationIterationCount: | |
| 2411 case CSSPropertyWebkitAnimationTimingFunction: | |
| 2412 case CSSPropertyTransitionDelay: | |
| 2413 case CSSPropertyTransitionDuration: | |
| 2414 case CSSPropertyTransitionTimingFunction: | |
| 2415 case CSSPropertyTransitionProperty: | |
| 2416 case CSSPropertyWebkitTransitionDelay: | |
| 2417 case CSSPropertyWebkitTransitionDuration: | |
| 2418 case CSSPropertyWebkitTransitionTimingFunction: | |
| 2419 case CSSPropertyWebkitTransitionProperty: { | |
| 2420 RefPtr<CSSValue> val; | |
| 2421 AnimationParseContext context; | |
| 2422 if (parseAnimationProperty(propId, val, context)) { | |
| 2423 addPropertyWithPrefixingVariant(propId, val.release(), important); | |
| 2424 return true; | |
| 2425 } | |
| 2426 return false; | |
| 2427 } | |
| 2428 | |
| 2429 case CSSPropertyGridAutoColumns: | |
| 2430 case CSSPropertyGridAutoRows: | |
| 2431 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) | |
| 2432 return false; | |
| 2433 parsedValue = parseGridTrackSize(*m_valueList); | |
| 2434 break; | |
| 2435 | |
| 2436 case CSSPropertyGridDefinitionColumns: | |
| 2437 case CSSPropertyGridDefinitionRows: | |
| 2438 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) | |
| 2439 return false; | |
| 2440 return parseGridTrackList(propId, important); | |
| 2441 | |
| 2442 case CSSPropertyGridColumnEnd: | |
| 2443 case CSSPropertyGridColumnStart: | |
| 2444 case CSSPropertyGridRowEnd: | |
| 2445 case CSSPropertyGridRowStart: | |
| 2446 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) | |
| 2447 return false; | |
| 2448 parsedValue = parseGridPosition(); | |
| 2449 break; | |
| 2450 | |
| 2451 case CSSPropertyGridColumn: | |
| 2452 case CSSPropertyGridRow: | |
| 2453 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) | |
| 2454 return false; | |
| 2455 return parseGridItemPositionShorthand(propId, important); | |
| 2456 | |
| 2457 case CSSPropertyGridArea: | |
| 2458 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) | |
| 2459 return false; | |
| 2460 return parseGridAreaShorthand(important); | |
| 2461 | |
| 2462 case CSSPropertyGridTemplate: | |
| 2463 if (!RuntimeEnabledFeatures::cssGridLayoutEnabled()) | |
| 2464 return false; | |
| 2465 parsedValue = parseGridTemplate(); | |
| 2466 break; | |
| 2467 | |
| 2468 case CSSPropertyWebkitMarginCollapse: { | |
| 2469 if (num == 1) { | |
| 2470 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse); | |
| 2471 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], imp
ortant)) | |
| 2472 return false; | |
| 2473 CSSValue* value = m_parsedProperties.last().value(); | |
| 2474 addProperty(webkitMarginCollapseShorthand().properties()[1], value,
important); | |
| 2475 return true; | |
| 2476 } | |
| 2477 else if (num == 2) { | |
| 2478 ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse); | |
| 2479 if (!parseValue(webkitMarginCollapseShorthand().properties()[0], imp
ortant) || !parseValue(webkitMarginCollapseShorthand().properties()[1], importan
t)) | |
| 2480 return false; | |
| 2481 return true; | |
| 2482 } | |
| 2483 return false; | |
| 2484 } | |
| 2485 case CSSPropertyTextLineThroughWidth: | |
| 2486 case CSSPropertyTextOverlineWidth: | |
| 2487 case CSSPropertyTextUnderlineWidth: | |
| 2488 if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin || | |
| 2489 id == CSSValueMedium || id == CSSValueThick) | |
| 2490 validPrimitive = true; | |
| 2491 else | |
| 2492 validPrimitive = !id && validUnit(value, FNumber | FLength | FPercen
t); | |
| 2493 break; | |
| 2494 case CSSPropertyWebkitColumnCount: | |
| 2495 parsedValue = parseColumnCount(); | |
| 2496 break; | |
| 2497 case CSSPropertyWebkitColumnGap: // normal | <length> | |
| 2498 if (id == CSSValueNormal) | |
| 2499 validPrimitive = true; | |
| 2500 else | |
| 2501 validPrimitive = validUnit(value, FLength | FNonNeg); | |
| 2502 break; | |
| 2503 case CSSPropertyWebkitColumnAxis: | |
| 2504 if (id == CSSValueHorizontal || id == CSSValueVertical || id == CSSValue
Auto) | |
| 2505 validPrimitive = true; | |
| 2506 break; | |
| 2507 case CSSPropertyWebkitColumnProgression: | |
| 2508 if (id == CSSValueNormal || id == CSSValueReverse) | |
| 2509 validPrimitive = true; | |
| 2510 break; | |
| 2511 case CSSPropertyWebkitColumnSpan: // none | all | 1 (will be dropped in the
unprefixed property) | |
| 2512 if (id == CSSValueAll || id == CSSValueNone) | |
| 2513 validPrimitive = true; | |
| 2514 else | |
| 2515 validPrimitive = validUnit(value, FNumber | FNonNeg) && value->fValu
e == 1; | |
| 2516 break; | |
| 2517 case CSSPropertyWebkitColumnWidth: // auto | <length> | |
| 2518 parsedValue = parseColumnWidth(); | |
| 2519 break; | |
| 2520 // End of CSS3 properties | |
| 2521 | |
| 2522 // Apple specific properties. These will never be standardized and are pure
ly to | |
| 2523 // support custom WebKit-based Apple applications. | |
| 2524 case CSSPropertyWebkitLineClamp: | |
| 2525 // When specifying number of lines, don't allow 0 as a valid value | |
| 2526 // When specifying either type of unit, require non-negative integers | |
| 2527 validPrimitive = (!id && (value->unit == CSSPrimitiveValue::CSS_PERCENTA
GE || value->fValue) && validUnit(value, FInteger | FPercent | FNonNeg, HTMLQuir
ksMode)); | |
| 2528 break; | |
| 2529 | |
| 2530 case CSSPropertyWebkitFontSizeDelta: // <length> | |
| 2531 validPrimitive = validUnit(value, FLength); | |
| 2532 break; | |
| 2533 | |
| 2534 case CSSPropertyWebkitHighlight: | |
| 2535 if (id == CSSValueNone || value->unit == CSSPrimitiveValue::CSS_STRING) | |
| 2536 validPrimitive = true; | |
| 2537 break; | |
| 2538 | |
| 2539 case CSSPropertyWebkitHyphenateCharacter: | |
| 2540 if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING) | |
| 2541 validPrimitive = true; | |
| 2542 break; | |
| 2543 | |
| 2544 case CSSPropertyWebkitLineGrid: | |
| 2545 if (id == CSSValueNone) | |
| 2546 validPrimitive = true; | |
| 2547 else if (value->unit == CSSPrimitiveValue::CSS_IDENT) { | |
| 2548 String lineGridValue = String(value->string); | |
| 2549 if (!lineGridValue.isEmpty()) { | |
| 2550 addProperty(propId, cssValuePool().createValue(lineGridValue, CS
SPrimitiveValue::CSS_STRING), important); | |
| 2551 return true; | |
| 2552 } | |
| 2553 } | |
| 2554 break; | |
| 2555 case CSSPropertyWebkitLocale: | |
| 2556 if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING) | |
| 2557 validPrimitive = true; | |
| 2558 break; | |
| 2559 | |
| 2560 // End Apple-specific properties | |
| 2561 | |
| 2562 case CSSPropertyWebkitAppRegion: | |
| 2563 if (id >= CSSValueDrag && id <= CSSValueNoDrag) | |
| 2564 validPrimitive = true; | |
| 2565 break; | |
| 2566 | |
| 2567 case CSSPropertyWebkitTapHighlightColor: | |
| 2568 if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMe
nu | |
| 2569 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText &&
inQuirksMode())) { | |
| 2570 validPrimitive = true; | |
| 2571 } else { | |
| 2572 parsedValue = parseColor(); | |
| 2573 if (parsedValue) | |
| 2574 m_valueList->next(); | |
| 2575 } | |
| 2576 break; | |
| 2577 | |
| 2578 /* shorthand properties */ | |
| 2579 case CSSPropertyBackground: { | |
| 2580 // Position must come before color in this array because a plain old "0"
is a legal color | |
| 2581 // in quirks mode but it's usually the X coordinate of a position. | |
| 2582 const CSSPropertyID properties[] = { CSSPropertyBackgroundImage, CSSProp
ertyBackgroundRepeat, | |
| 2583 CSSPropertyBackgroundAttachment, CSSPropertyB
ackgroundPosition, CSSPropertyBackgroundOrigin, | |
| 2584 CSSPropertyBackgroundClip, CSSPropertyBackgro
undColor, CSSPropertyBackgroundSize }; | |
| 2585 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(propertie
s), important); | |
| 2586 } | |
| 2587 case CSSPropertyWebkitMask: { | |
| 2588 const CSSPropertyID properties[] = { CSSPropertyWebkitMaskImage, CSSProp
ertyWebkitMaskRepeat, | |
| 2589 CSSPropertyWebkitMaskPosition, CSSPropertyWebkitMaskOrigin, CSSPrope
rtyWebkitMaskClip, CSSPropertyWebkitMaskSize }; | |
| 2590 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(propertie
s), important); | |
| 2591 } | |
| 2592 case CSSPropertyBorder: | |
| 2593 // [ 'border-width' || 'border-style' || <color> ] | inherit | |
| 2594 { | |
| 2595 if (parseShorthand(propId, parsingShorthandForProperty(CSSPropertyBorder
), important)) { | |
| 2596 // The CSS3 Borders and Backgrounds specification says that border a
lso resets border-image. It's as | |
| 2597 // though a value of none was specified for the image. | |
| 2598 addExpandedPropertyForValue(CSSPropertyBorderImage, cssValuePool().c
reateImplicitInitialValue(), important); | |
| 2599 return true; | |
| 2600 } | |
| 2601 return false; | |
| 2602 } | |
| 2603 case CSSPropertyBorderTop: | |
| 2604 // [ 'border-top-width' || 'border-style' || <color> ] | inherit | |
| 2605 return parseShorthand(propId, borderTopShorthand(), important); | |
| 2606 case CSSPropertyBorderRight: | |
| 2607 // [ 'border-right-width' || 'border-style' || <color> ] | inherit | |
| 2608 return parseShorthand(propId, borderRightShorthand(), important); | |
| 2609 case CSSPropertyBorderBottom: | |
| 2610 // [ 'border-bottom-width' || 'border-style' || <color> ] | inherit | |
| 2611 return parseShorthand(propId, borderBottomShorthand(), important); | |
| 2612 case CSSPropertyBorderLeft: | |
| 2613 // [ 'border-left-width' || 'border-style' || <color> ] | inherit | |
| 2614 return parseShorthand(propId, borderLeftShorthand(), important); | |
| 2615 case CSSPropertyWebkitBorderStart: | |
| 2616 return parseShorthand(propId, webkitBorderStartShorthand(), important); | |
| 2617 case CSSPropertyWebkitBorderEnd: | |
| 2618 return parseShorthand(propId, webkitBorderEndShorthand(), important); | |
| 2619 case CSSPropertyWebkitBorderBefore: | |
| 2620 return parseShorthand(propId, webkitBorderBeforeShorthand(), important); | |
| 2621 case CSSPropertyWebkitBorderAfter: | |
| 2622 return parseShorthand(propId, webkitBorderAfterShorthand(), important); | |
| 2623 case CSSPropertyOutline: | |
| 2624 // [ 'outline-color' || 'outline-style' || 'outline-width' ] | inherit | |
| 2625 return parseShorthand(propId, outlineShorthand(), important); | |
| 2626 case CSSPropertyBorderColor: | |
| 2627 // <color>{1,4} | inherit | |
| 2628 return parse4Values(propId, borderColorShorthand().properties(), importa
nt); | |
| 2629 case CSSPropertyBorderWidth: | |
| 2630 // <border-width>{1,4} | inherit | |
| 2631 return parse4Values(propId, borderWidthShorthand().properties(), importa
nt); | |
| 2632 case CSSPropertyBorderStyle: | |
| 2633 // <border-style>{1,4} | inherit | |
| 2634 return parse4Values(propId, borderStyleShorthand().properties(), importa
nt); | |
| 2635 case CSSPropertyMargin: | |
| 2636 // <margin-width>{1,4} | inherit | |
| 2637 return parse4Values(propId, marginShorthand().properties(), important); | |
| 2638 case CSSPropertyPadding: | |
| 2639 // <padding-width>{1,4} | inherit | |
| 2640 return parse4Values(propId, paddingShorthand().properties(), important); | |
| 2641 case CSSPropertyFlexFlow: | |
| 2642 return parseShorthand(propId, flexFlowShorthand(), important); | |
| 2643 case CSSPropertyFont: | |
| 2644 // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [
/ 'line-height' ]? | |
| 2645 // 'font-family' ] | caption | icon | menu | message-box | small-caption
| status-bar | inherit | |
| 2646 if (id >= CSSValueCaption && id <= CSSValueStatusBar) | |
| 2647 validPrimitive = true; | |
| 2648 else | |
| 2649 return parseFont(important); | |
| 2650 break; | |
| 2651 case CSSPropertyListStyle: | |
| 2652 return parseShorthand(propId, listStyleShorthand(), important); | |
| 2653 case CSSPropertyWebkitColumns: | |
| 2654 return parseColumnsShorthand(important); | |
| 2655 case CSSPropertyWebkitColumnRule: | |
| 2656 return parseShorthand(propId, webkitColumnRuleShorthand(), important); | |
| 2657 case CSSPropertyWebkitTextStroke: | |
| 2658 return parseShorthand(propId, webkitTextStrokeShorthand(), important); | |
| 2659 case CSSPropertyAnimation: | |
| 2660 if (!RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled()) | |
| 2661 break; | |
| 2662 case CSSPropertyWebkitAnimation: | |
| 2663 return parseAnimationShorthand(propId, important); | |
| 2664 case CSSPropertyTransition: | |
| 2665 case CSSPropertyWebkitTransition: | |
| 2666 return parseTransitionShorthand(propId, important); | |
| 2667 case CSSPropertyInvalid: | |
| 2668 return false; | |
| 2669 case CSSPropertyPage: | |
| 2670 return parsePage(propId, important); | |
| 2671 case CSSPropertyFontStretch: | |
| 2672 return false; | |
| 2673 // CSS Text Layout Module Level 3: Vertical writing support | |
| 2674 case CSSPropertyWebkitTextEmphasis: | |
| 2675 return parseShorthand(propId, webkitTextEmphasisShorthand(), important); | |
| 2676 | |
| 2677 case CSSPropertyWebkitTextEmphasisStyle: | |
| 2678 return parseTextEmphasisStyle(important); | |
| 2679 | |
| 2680 case CSSPropertyWebkitTextOrientation: | |
| 2681 // FIXME: For now just support sideways, sideways-right, upright and ver
tical-right. | |
| 2682 if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSVa
lueVerticalRight || id == CSSValueUpright) | |
| 2683 validPrimitive = true; | |
| 2684 break; | |
| 2685 | |
| 2686 case CSSPropertyWebkitLineBoxContain: | |
| 2687 if (id == CSSValueNone) | |
| 2688 validPrimitive = true; | |
| 2689 else | |
| 2690 return parseLineBoxContain(important); | |
| 2691 break; | |
| 2692 case CSSPropertyWebkitFontFeatureSettings: | |
| 2693 if (id == CSSValueNormal) | |
| 2694 validPrimitive = true; | |
| 2695 else | |
| 2696 return parseFontFeatureSettings(important); | |
| 2697 break; | |
| 2698 | |
| 2699 case CSSPropertyWebkitFontVariantLigatures: | |
| 2700 if (id == CSSValueNormal) | |
| 2701 validPrimitive = true; | |
| 2702 else | |
| 2703 return parseFontVariantLigatures(important); | |
| 2704 break; | |
| 2705 case CSSPropertyWebkitClipPath: | |
| 2706 if (id == CSSValueNone) { | |
| 2707 validPrimitive = true; | |
| 2708 } else if (value->unit == CSSParserValue::Function) { | |
| 2709 parsedValue = parseBasicShape(); | |
| 2710 } else if (value->unit == CSSPrimitiveValue::CSS_URI) { | |
| 2711 parsedValue = CSSPrimitiveValue::create(value->string, CSSPrimitiveV
alue::CSS_URI); | |
| 2712 addProperty(propId, parsedValue.release(), important); | |
| 2713 return true; | |
| 2714 } | |
| 2715 break; | |
| 2716 case CSSPropertyShapeInside: | |
| 2717 case CSSPropertyShapeOutside: | |
| 2718 parsedValue = parseShapeProperty(propId); | |
| 2719 break; | |
| 2720 case CSSPropertyShapeMargin: | |
| 2721 case CSSPropertyShapePadding: | |
| 2722 validPrimitive = (RuntimeEnabledFeatures::cssShapesEnabled() && !id && v
alidUnit(value, FLength | FNonNeg)); | |
| 2723 break; | |
| 2724 case CSSPropertyShapeImageThreshold: | |
| 2725 validPrimitive = (RuntimeEnabledFeatures::cssShapesEnabled() && !id && v
alidUnit(value, FNumber)); | |
| 2726 break; | |
| 2727 | |
| 2728 case CSSPropertyTouchAction: | |
| 2729 // auto | none | [pan-x || pan-y] | |
| 2730 return parseTouchAction(important); | |
| 2731 | |
| 2732 case CSSPropertyBorderBottomStyle: | |
| 2733 case CSSPropertyBorderCollapse: | |
| 2734 case CSSPropertyBorderLeftStyle: | |
| 2735 case CSSPropertyBorderRightStyle: | |
| 2736 case CSSPropertyBorderTopStyle: | |
| 2737 case CSSPropertyBoxSizing: | |
| 2738 case CSSPropertyCaptionSide: | |
| 2739 case CSSPropertyClear: | |
| 2740 case CSSPropertyDirection: | |
| 2741 case CSSPropertyDisplay: | |
| 2742 case CSSPropertyEmptyCells: | |
| 2743 case CSSPropertyFloat: | |
| 2744 case CSSPropertyFontStyle: | |
| 2745 case CSSPropertyImageRendering: | |
| 2746 case CSSPropertyListStylePosition: | |
| 2747 case CSSPropertyListStyleType: | |
| 2748 case CSSPropertyObjectFit: | |
| 2749 case CSSPropertyOutlineStyle: | |
| 2750 case CSSPropertyOverflowWrap: | |
| 2751 case CSSPropertyOverflowX: | |
| 2752 case CSSPropertyOverflowY: | |
| 2753 case CSSPropertyPageBreakAfter: | |
| 2754 case CSSPropertyPageBreakBefore: | |
| 2755 case CSSPropertyPageBreakInside: | |
| 2756 case CSSPropertyPointerEvents: | |
| 2757 case CSSPropertyPosition: | |
| 2758 case CSSPropertyResize: | |
| 2759 case CSSPropertySpeak: | |
| 2760 case CSSPropertyTableLayout: | |
| 2761 case CSSPropertyTextAlignLast: | |
| 2762 case CSSPropertyTextJustify: | |
| 2763 case CSSPropertyTextLineThroughMode: | |
| 2764 case CSSPropertyTextLineThroughStyle: | |
| 2765 case CSSPropertyTextOverflow: | |
| 2766 case CSSPropertyTextOverlineMode: | |
| 2767 case CSSPropertyTextOverlineStyle: | |
| 2768 case CSSPropertyTextRendering: | |
| 2769 case CSSPropertyTextTransform: | |
| 2770 case CSSPropertyTextUnderlineMode: | |
| 2771 case CSSPropertyTextUnderlineStyle: | |
| 2772 case CSSPropertyTouchActionDelay: | |
| 2773 case CSSPropertyVariable: | |
| 2774 case CSSPropertyVisibility: | |
| 2775 case CSSPropertyWebkitAppearance: | |
| 2776 case CSSPropertyWebkitBackfaceVisibility: | |
| 2777 case CSSPropertyWebkitBorderAfterStyle: | |
| 2778 case CSSPropertyWebkitBorderBeforeStyle: | |
| 2779 case CSSPropertyWebkitBorderEndStyle: | |
| 2780 case CSSPropertyWebkitBorderFit: | |
| 2781 case CSSPropertyWebkitBorderStartStyle: | |
| 2782 case CSSPropertyWebkitBoxAlign: | |
| 2783 case CSSPropertyWebkitBoxDecorationBreak: | |
| 2784 case CSSPropertyWebkitBoxDirection: | |
| 2785 case CSSPropertyWebkitBoxLines: | |
| 2786 case CSSPropertyWebkitBoxOrient: | |
| 2787 case CSSPropertyWebkitBoxPack: | |
| 2788 case CSSPropertyInternalCallback: | |
| 2789 case CSSPropertyWebkitColumnBreakAfter: | |
| 2790 case CSSPropertyWebkitColumnBreakBefore: | |
| 2791 case CSSPropertyWebkitColumnBreakInside: | |
| 2792 case CSSPropertyColumnFill: | |
| 2793 case CSSPropertyWebkitColumnRuleStyle: | |
| 2794 case CSSPropertyAlignContent: | |
| 2795 case CSSPropertyAlignItems: | |
| 2796 case CSSPropertyAlignSelf: | |
| 2797 case CSSPropertyFlexDirection: | |
| 2798 case CSSPropertyFlexWrap: | |
| 2799 case CSSPropertyJustifyContent: | |
| 2800 case CSSPropertyFontKerning: | |
| 2801 case CSSPropertyWebkitFontSmoothing: | |
| 2802 case CSSPropertyGridAutoFlow: | |
| 2803 case CSSPropertyWebkitLineAlign: | |
| 2804 case CSSPropertyWebkitLineBreak: | |
| 2805 case CSSPropertyWebkitLineSnap: | |
| 2806 case CSSPropertyWebkitMarginAfterCollapse: | |
| 2807 case CSSPropertyWebkitMarginBeforeCollapse: | |
| 2808 case CSSPropertyWebkitMarginBottomCollapse: | |
| 2809 case CSSPropertyWebkitMarginTopCollapse: | |
| 2810 case CSSPropertyInternalMarqueeDirection: | |
| 2811 case CSSPropertyInternalMarqueeStyle: | |
| 2812 case CSSPropertyWebkitPrintColorAdjust: | |
| 2813 case CSSPropertyWebkitRegionBreakAfter: | |
| 2814 case CSSPropertyWebkitRegionBreakBefore: | |
| 2815 case CSSPropertyWebkitRegionBreakInside: | |
| 2816 case CSSPropertyWebkitRegionFragment: | |
| 2817 case CSSPropertyWebkitRtlOrdering: | |
| 2818 case CSSPropertyWebkitRubyPosition: | |
| 2819 case CSSPropertyWebkitTextCombine: | |
| 2820 case CSSPropertyWebkitTextEmphasisPosition: | |
| 2821 case CSSPropertyWebkitTextSecurity: | |
| 2822 case CSSPropertyWebkitTransformStyle: | |
| 2823 case CSSPropertyWebkitUserDrag: | |
| 2824 case CSSPropertyWebkitUserModify: | |
| 2825 case CSSPropertyWebkitUserSelect: | |
| 2826 case CSSPropertyWebkitWrapFlow: | |
| 2827 case CSSPropertyWebkitWrapThrough: | |
| 2828 case CSSPropertyWebkitWritingMode: | |
| 2829 case CSSPropertyWhiteSpace: | |
| 2830 case CSSPropertyWordBreak: | |
| 2831 case CSSPropertyWordWrap: | |
| 2832 case CSSPropertyMixBlendMode: | |
| 2833 case CSSPropertyIsolation: | |
| 2834 // These properties should be handled before in isValidKeywordPropertyAn
dValue(). | |
| 2835 ASSERT_NOT_REACHED(); | |
| 2836 return false; | |
| 2837 // Properties below are validated inside parseViewportProperty, because we | |
| 2838 // check for parser state. We need to invalidate if someone adds them outsid
e | |
| 2839 // a @viewport rule. | |
| 2840 case CSSPropertyMaxZoom: | |
| 2841 case CSSPropertyMinZoom: | |
| 2842 case CSSPropertyOrientation: | |
| 2843 case CSSPropertyUserZoom: | |
| 2844 validPrimitive = false; | |
| 2845 break; | |
| 2846 default: | |
| 2847 return parseSVGValue(propId, important); | |
| 2848 } | |
| 2849 | |
| 2850 if (validPrimitive) { | |
| 2851 parsedValue = parseValidPrimitive(id, value); | |
| 2852 m_valueList->next(); | |
| 2853 } | |
| 2854 ASSERT(!m_parsedCalculation); | |
| 2855 if (parsedValue) { | |
| 2856 if (!m_valueList->current() || inShorthand()) { | |
| 2857 addProperty(propId, parsedValue.release(), important); | |
| 2858 return true; | |
| 2859 } | |
| 2860 } | |
| 2861 return false; | |
| 2862 } | |
| 2863 | |
| 2864 void CSSParser::addFillValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval) | |
| 2865 { | |
| 2866 if (lval) { | |
| 2867 if (lval->isBaseValueList()) | |
| 2868 toCSSValueList(lval.get())->append(rval); | |
| 2869 else { | |
| 2870 PassRefPtr<CSSValue> oldlVal(lval.release()); | |
| 2871 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated()
; | |
| 2872 list->append(oldlVal); | |
| 2873 list->append(rval); | |
| 2874 lval = list; | |
| 2875 } | |
| 2876 } | |
| 2877 else | |
| 2878 lval = rval; | |
| 2879 } | |
| 2880 | |
| 2881 static bool parseBackgroundClip(CSSParserValue* parserValue, RefPtr<CSSValue>& c
ssValue) | |
| 2882 { | |
| 2883 if (parserValue->id == CSSValueBorderBox || parserValue->id == CSSValuePaddi
ngBox | |
| 2884 || parserValue->id == CSSValueContentBox || parserValue->id == CSSValueW
ebkitText) { | |
| 2885 cssValue = cssValuePool().createIdentifierValue(parserValue->id); | |
| 2886 return true; | |
| 2887 } | |
| 2888 return false; | |
| 2889 } | |
| 2890 | |
| 2891 bool CSSParser::useLegacyBackgroundSizeShorthandBehavior() const | |
| 2892 { | |
| 2893 return m_context.useLegacyBackgroundSizeShorthandBehavior(); | |
| 2894 } | |
| 2895 | |
| 2896 const int cMaxFillProperties = 9; | |
| 2897 | |
| 2898 bool CSSParser::parseFillShorthand(CSSPropertyID propId, const CSSPropertyID* pr
operties, int numProperties, bool important) | |
| 2899 { | |
| 2900 ASSERT(numProperties <= cMaxFillProperties); | |
| 2901 if (numProperties > cMaxFillProperties) | |
| 2902 return false; | |
| 2903 | |
| 2904 ShorthandScope scope(this, propId); | |
| 2905 | |
| 2906 bool parsedProperty[cMaxFillProperties] = { false }; | |
| 2907 RefPtr<CSSValue> values[cMaxFillProperties]; | |
| 2908 RefPtr<CSSValue> clipValue; | |
| 2909 RefPtr<CSSValue> positionYValue; | |
| 2910 RefPtr<CSSValue> repeatYValue; | |
| 2911 bool foundClip = false; | |
| 2912 int i; | |
| 2913 bool foundPositionCSSProperty = false; | |
| 2914 | |
| 2915 while (m_valueList->current()) { | |
| 2916 CSSParserValue* val = m_valueList->current(); | |
| 2917 if (val->unit == CSSParserValue::Operator && val->iValue == ',') { | |
| 2918 // We hit the end. Fill in all remaining values with the initial va
lue. | |
| 2919 m_valueList->next(); | |
| 2920 for (i = 0; i < numProperties; ++i) { | |
| 2921 if (properties[i] == CSSPropertyBackgroundColor && parsedPropert
y[i]) | |
| 2922 // Color is not allowed except as the last item in a list fo
r backgrounds. | |
| 2923 // Reject the entire property. | |
| 2924 return false; | |
| 2925 | |
| 2926 if (!parsedProperty[i] && properties[i] != CSSPropertyBackground
Color) { | |
| 2927 addFillValue(values[i], cssValuePool().createImplicitInitial
Value()); | |
| 2928 if (properties[i] == CSSPropertyBackgroundPosition || proper
ties[i] == CSSPropertyWebkitMaskPosition) | |
| 2929 addFillValue(positionYValue, cssValuePool().createImplic
itInitialValue()); | |
| 2930 if (properties[i] == CSSPropertyBackgroundRepeat || properti
es[i] == CSSPropertyWebkitMaskRepeat) | |
| 2931 addFillValue(repeatYValue, cssValuePool().createImplicit
InitialValue()); | |
| 2932 if ((properties[i] == CSSPropertyBackgroundOrigin || propert
ies[i] == CSSPropertyWebkitMaskOrigin) && !parsedProperty[i]) { | |
| 2933 // If background-origin wasn't present, then reset backg
round-clip also. | |
| 2934 addFillValue(clipValue, cssValuePool().createImplicitIni
tialValue()); | |
| 2935 } | |
| 2936 } | |
| 2937 parsedProperty[i] = false; | |
| 2938 } | |
| 2939 if (!m_valueList->current()) | |
| 2940 break; | |
| 2941 } | |
| 2942 | |
| 2943 bool sizeCSSPropertyExpected = false; | |
| 2944 if (isForwardSlashOperator(val) && foundPositionCSSProperty) { | |
| 2945 sizeCSSPropertyExpected = true; | |
| 2946 m_valueList->next(); | |
| 2947 } | |
| 2948 | |
| 2949 foundPositionCSSProperty = false; | |
| 2950 bool found = false; | |
| 2951 for (i = 0; !found && i < numProperties; ++i) { | |
| 2952 | |
| 2953 if (sizeCSSPropertyExpected && (properties[i] != CSSPropertyBackgrou
ndSize && properties[i] != CSSPropertyWebkitMaskSize)) | |
| 2954 continue; | |
| 2955 if (!sizeCSSPropertyExpected && (properties[i] == CSSPropertyBackgro
undSize || properties[i] == CSSPropertyWebkitMaskSize)) | |
| 2956 continue; | |
| 2957 | |
| 2958 if (!parsedProperty[i]) { | |
| 2959 RefPtr<CSSValue> val1; | |
| 2960 RefPtr<CSSValue> val2; | |
| 2961 CSSPropertyID propId1, propId2; | |
| 2962 CSSParserValue* parserValue = m_valueList->current(); | |
| 2963 // parseFillProperty() may modify m_implicitShorthand, so we MUS
T reset it | |
| 2964 // before EACH return below. | |
| 2965 if (parseFillProperty(properties[i], propId1, propId2, val1, val
2)) { | |
| 2966 parsedProperty[i] = found = true; | |
| 2967 addFillValue(values[i], val1.release()); | |
| 2968 if (properties[i] == CSSPropertyBackgroundPosition || proper
ties[i] == CSSPropertyWebkitMaskPosition) | |
| 2969 addFillValue(positionYValue, val2.release()); | |
| 2970 if (properties[i] == CSSPropertyBackgroundRepeat || properti
es[i] == CSSPropertyWebkitMaskRepeat) | |
| 2971 addFillValue(repeatYValue, val2.release()); | |
| 2972 if (properties[i] == CSSPropertyBackgroundOrigin || properti
es[i] == CSSPropertyWebkitMaskOrigin) { | |
| 2973 // Reparse the value as a clip, and see if we succeed. | |
| 2974 if (parseBackgroundClip(parserValue, val1)) | |
| 2975 addFillValue(clipValue, val1.release()); // The prop
erty parsed successfully. | |
| 2976 else | |
| 2977 addFillValue(clipValue, cssValuePool().createImplici
tInitialValue()); // Some value was used for origin that is not supported by cli
p. Just reset clip instead. | |
| 2978 } | |
| 2979 if (properties[i] == CSSPropertyBackgroundClip || properties
[i] == CSSPropertyWebkitMaskClip) { | |
| 2980 // Update clipValue | |
| 2981 addFillValue(clipValue, val1.release()); | |
| 2982 foundClip = true; | |
| 2983 } | |
| 2984 if (properties[i] == CSSPropertyBackgroundPosition || proper
ties[i] == CSSPropertyWebkitMaskPosition) | |
| 2985 foundPositionCSSProperty = true; | |
| 2986 } | |
| 2987 } | |
| 2988 } | |
| 2989 | |
| 2990 // if we didn't find at least one match, this is an | |
| 2991 // invalid shorthand and we have to ignore it | |
| 2992 if (!found) { | |
| 2993 m_implicitShorthand = false; | |
| 2994 return false; | |
| 2995 } | |
| 2996 } | |
| 2997 | |
| 2998 // Now add all of the properties we found. | |
| 2999 for (i = 0; i < numProperties; i++) { | |
| 3000 // Fill in any remaining properties with the initial value. | |
| 3001 if (!parsedProperty[i]) { | |
| 3002 addFillValue(values[i], cssValuePool().createImplicitInitialValue())
; | |
| 3003 if (properties[i] == CSSPropertyBackgroundPosition || properties[i]
== CSSPropertyWebkitMaskPosition) | |
| 3004 addFillValue(positionYValue, cssValuePool().createImplicitInitia
lValue()); | |
| 3005 if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] ==
CSSPropertyWebkitMaskRepeat) | |
| 3006 addFillValue(repeatYValue, cssValuePool().createImplicitInitialV
alue()); | |
| 3007 if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] ==
CSSPropertyWebkitMaskOrigin) { | |
| 3008 // If background-origin wasn't present, then reset background-cl
ip also. | |
| 3009 addFillValue(clipValue, cssValuePool().createImplicitInitialValu
e()); | |
| 3010 } | |
| 3011 } | |
| 3012 if (properties[i] == CSSPropertyBackgroundPosition) { | |
| 3013 addProperty(CSSPropertyBackgroundPositionX, values[i].release(), imp
ortant); | |
| 3014 // it's OK to call positionYValue.release() since we only see CSSPro
pertyBackgroundPosition once | |
| 3015 addProperty(CSSPropertyBackgroundPositionY, positionYValue.release()
, important); | |
| 3016 } else if (properties[i] == CSSPropertyWebkitMaskPosition) { | |
| 3017 addProperty(CSSPropertyWebkitMaskPositionX, values[i].release(), imp
ortant); | |
| 3018 // it's OK to call positionYValue.release() since we only see CSSPro
pertyWebkitMaskPosition once | |
| 3019 addProperty(CSSPropertyWebkitMaskPositionY, positionYValue.release()
, important); | |
| 3020 } else if (properties[i] == CSSPropertyBackgroundRepeat) { | |
| 3021 addProperty(CSSPropertyBackgroundRepeatX, values[i].release(), impor
tant); | |
| 3022 // it's OK to call repeatYValue.release() since we only see CSSPrope
rtyBackgroundPosition once | |
| 3023 addProperty(CSSPropertyBackgroundRepeatY, repeatYValue.release(), im
portant); | |
| 3024 } else if (properties[i] == CSSPropertyWebkitMaskRepeat) { | |
| 3025 addProperty(CSSPropertyWebkitMaskRepeatX, values[i].release(), impor
tant); | |
| 3026 // it's OK to call repeatYValue.release() since we only see CSSPrope
rtyBackgroundPosition once | |
| 3027 addProperty(CSSPropertyWebkitMaskRepeatY, repeatYValue.release(), im
portant); | |
| 3028 } else if ((properties[i] == CSSPropertyBackgroundClip || properties[i]
== CSSPropertyWebkitMaskClip) && !foundClip) | |
| 3029 // Value is already set while updating origin | |
| 3030 continue; | |
| 3031 else if (properties[i] == CSSPropertyBackgroundSize && !parsedProperty[i
] && useLegacyBackgroundSizeShorthandBehavior()) | |
| 3032 continue; | |
| 3033 else | |
| 3034 addProperty(properties[i], values[i].release(), important); | |
| 3035 | |
| 3036 // Add in clip values when we hit the corresponding origin property. | |
| 3037 if (properties[i] == CSSPropertyBackgroundOrigin && !foundClip) | |
| 3038 addProperty(CSSPropertyBackgroundClip, clipValue.release(), importan
t); | |
| 3039 else if (properties[i] == CSSPropertyWebkitMaskOrigin && !foundClip) | |
| 3040 addProperty(CSSPropertyWebkitMaskClip, clipValue.release(), importan
t); | |
| 3041 } | |
| 3042 | |
| 3043 m_implicitShorthand = false; | |
| 3044 return true; | |
| 3045 } | |
| 3046 | |
| 3047 void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr
<CSSParserValueList> value, bool important) | |
| 3048 { | |
| 3049 // When CSSGrammar.y encounters an invalid declaration it passes null for th
e CSSParserValueList, just bail. | |
| 3050 if (!value) | |
| 3051 return; | |
| 3052 | |
| 3053 static const unsigned prefixLength = sizeof("var-") - 1; | |
| 3054 | |
| 3055 ASSERT(name.length() > prefixLength); | |
| 3056 AtomicString variableName = name.atomicSubstring(prefixLength, name.length()
- prefixLength); | |
| 3057 | |
| 3058 StringBuilder builder; | |
| 3059 for (unsigned i = 0, size = value->size(); i < size; i++) { | |
| 3060 if (i) | |
| 3061 builder.append(' '); | |
| 3062 RefPtr<CSSValue> cssValue = value->valueAt(i)->createCSSValue(); | |
| 3063 if (!cssValue) | |
| 3064 return; | |
| 3065 builder.append(cssValue->cssText()); | |
| 3066 } | |
| 3067 | |
| 3068 addProperty(CSSPropertyVariable, CSSVariableValue::create(variableName, buil
der.toString()), important, false); | |
| 3069 } | |
| 3070 | |
| 3071 void CSSParser::addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> r
val) | |
| 3072 { | |
| 3073 if (lval) { | |
| 3074 if (lval->isValueList()) | |
| 3075 toCSSValueList(lval.get())->append(rval); | |
| 3076 else { | |
| 3077 PassRefPtr<CSSValue> oldVal(lval.release()); | |
| 3078 PassRefPtr<CSSValueList> list = CSSValueList::createCommaSeparated()
; | |
| 3079 list->append(oldVal); | |
| 3080 list->append(rval); | |
| 3081 lval = list; | |
| 3082 } | |
| 3083 } | |
| 3084 else | |
| 3085 lval = rval; | |
| 3086 } | |
| 3087 | |
| 3088 bool CSSParser::parseAnimationShorthand(CSSPropertyID propId, bool important) | |
| 3089 { | |
| 3090 const StylePropertyShorthand& animationProperties = parsingShorthandForPrope
rty(propId); | |
| 3091 const unsigned numProperties = 8; | |
| 3092 | |
| 3093 // The list of properties in the shorthand should be the same | |
| 3094 // length as the list with animation name in last position, even though they
are | |
| 3095 // in a different order. | |
| 3096 ASSERT(numProperties == animationProperties.length()); | |
| 3097 ASSERT(numProperties == shorthandForProperty(propId).length()); | |
| 3098 | |
| 3099 ShorthandScope scope(this, propId); | |
| 3100 | |
| 3101 bool parsedProperty[numProperties] = { false }; | |
| 3102 AnimationParseContext context; | |
| 3103 RefPtr<CSSValue> values[numProperties]; | |
| 3104 | |
| 3105 unsigned i; | |
| 3106 while (m_valueList->current()) { | |
| 3107 CSSParserValue* val = m_valueList->current(); | |
| 3108 if (val->unit == CSSParserValue::Operator && val->iValue == ',') { | |
| 3109 // We hit the end. Fill in all remaining values with the initial va
lue. | |
| 3110 m_valueList->next(); | |
| 3111 for (i = 0; i < numProperties; ++i) { | |
| 3112 if (!parsedProperty[i]) | |
| 3113 addAnimationValue(values[i], cssValuePool().createImplicitIn
itialValue()); | |
| 3114 parsedProperty[i] = false; | |
| 3115 } | |
| 3116 if (!m_valueList->current()) | |
| 3117 break; | |
| 3118 context.commitFirstAnimation(); | |
| 3119 } | |
| 3120 | |
| 3121 bool found = false; | |
| 3122 for (i = 0; i < numProperties; ++i) { | |
| 3123 if (!parsedProperty[i]) { | |
| 3124 RefPtr<CSSValue> val; | |
| 3125 if (parseAnimationProperty(animationProperties.properties()[i],
val, context)) { | |
| 3126 parsedProperty[i] = found = true; | |
| 3127 addAnimationValue(values[i], val.release()); | |
| 3128 break; | |
| 3129 } | |
| 3130 } | |
| 3131 } | |
| 3132 | |
| 3133 // if we didn't find at least one match, this is an | |
| 3134 // invalid shorthand and we have to ignore it | |
| 3135 if (!found) | |
| 3136 return false; | |
| 3137 } | |
| 3138 | |
| 3139 for (i = 0; i < numProperties; ++i) { | |
| 3140 // If we didn't find the property, set an intial value. | |
| 3141 if (!parsedProperty[i]) | |
| 3142 addAnimationValue(values[i], cssValuePool().createImplicitInitialVal
ue()); | |
| 3143 | |
| 3144 addProperty(animationProperties.properties()[i], values[i].release(), im
portant); | |
| 3145 } | |
| 3146 | |
| 3147 return true; | |
| 3148 } | |
| 3149 | |
| 3150 bool CSSParser::parseTransitionShorthand(CSSPropertyID propId, bool important) | |
| 3151 { | |
| 3152 const unsigned numProperties = 4; | |
| 3153 const StylePropertyShorthand& shorthand = shorthandForProperty(propId); | |
| 3154 ASSERT(numProperties == shorthand.length()); | |
| 3155 | |
| 3156 ShorthandScope scope(this, propId); | |
| 3157 | |
| 3158 bool parsedProperty[numProperties] = { false }; | |
| 3159 AnimationParseContext context; | |
| 3160 RefPtr<CSSValue> values[numProperties]; | |
| 3161 | |
| 3162 unsigned i; | |
| 3163 while (m_valueList->current()) { | |
| 3164 CSSParserValue* val = m_valueList->current(); | |
| 3165 if (val->unit == CSSParserValue::Operator && val->iValue == ',') { | |
| 3166 // We hit the end. Fill in all remaining values with the initial val
ue. | |
| 3167 m_valueList->next(); | |
| 3168 for (i = 0; i < numProperties; ++i) { | |
| 3169 if (!parsedProperty[i]) | |
| 3170 addAnimationValue(values[i], cssValuePool().createImplicitIn
itialValue()); | |
| 3171 parsedProperty[i] = false; | |
| 3172 } | |
| 3173 if (!m_valueList->current()) | |
| 3174 break; | |
| 3175 context.commitFirstAnimation(); | |
| 3176 } | |
| 3177 | |
| 3178 bool found = false; | |
| 3179 for (i = 0; !found && i < numProperties; ++i) { | |
| 3180 if (!parsedProperty[i]) { | |
| 3181 RefPtr<CSSValue> val; | |
| 3182 if (parseAnimationProperty(shorthand.properties()[i], val, conte
xt)) { | |
| 3183 parsedProperty[i] = found = true; | |
| 3184 addAnimationValue(values[i], val.release()); | |
| 3185 } | |
| 3186 | |
| 3187 // There are more values to process but 'none' or 'all' were alr
eady defined as the animation property, the declaration becomes invalid. | |
| 3188 if (!context.animationPropertyKeywordAllowed() && context.hasCom
mittedFirstAnimation()) | |
| 3189 return false; | |
| 3190 } | |
| 3191 } | |
| 3192 | |
| 3193 // if we didn't find at least one match, this is an | |
| 3194 // invalid shorthand and we have to ignore it | |
| 3195 if (!found) | |
| 3196 return false; | |
| 3197 } | |
| 3198 | |
| 3199 // Fill in any remaining properties with the initial value. | |
| 3200 for (i = 0; i < numProperties; ++i) { | |
| 3201 if (!parsedProperty[i]) | |
| 3202 addAnimationValue(values[i], cssValuePool().createImplicitInitialVal
ue()); | |
| 3203 } | |
| 3204 | |
| 3205 // Now add all of the properties we found. | |
| 3206 for (i = 0; i < numProperties; i++) | |
| 3207 addPropertyWithPrefixingVariant(shorthand.properties()[i], values[i].rel
ease(), important); | |
| 3208 | |
| 3209 return true; | |
| 3210 } | |
| 3211 | |
| 3212 PassRefPtr<CSSValue> CSSParser::parseColumnWidth() | |
| 3213 { | |
| 3214 CSSParserValue* value = m_valueList->current(); | |
| 3215 // Always parse lengths in strict mode here, since it would be ambiguous oth
erwise when used in | |
| 3216 // the 'columns' shorthand property. | |
| 3217 if (value->id == CSSValueAuto | |
| 3218 || (validUnit(value, FLength | FNonNeg, HTMLStandardMode) && value->fVal
ue)) { | |
| 3219 RefPtr<CSSValue> parsedValue = parseValidPrimitive(value->id, value); | |
| 3220 m_valueList->next(); | |
| 3221 return parsedValue; | |
| 3222 } | |
| 3223 return 0; | |
| 3224 } | |
| 3225 | |
| 3226 PassRefPtr<CSSValue> CSSParser::parseColumnCount() | |
| 3227 { | |
| 3228 CSSParserValue* value = m_valueList->current(); | |
| 3229 if (value->id == CSSValueAuto | |
| 3230 || (!value->id && validUnit(value, FPositiveInteger, HTMLQuirksMode))) { | |
| 3231 RefPtr<CSSValue> parsedValue = parseValidPrimitive(value->id, value); | |
| 3232 m_valueList->next(); | |
| 3233 return parsedValue; | |
| 3234 } | |
| 3235 return 0; | |
| 3236 } | |
| 3237 | |
| 3238 bool CSSParser::parseColumnsShorthand(bool important) | |
| 3239 { | |
| 3240 RefPtr <CSSValue> columnWidth; | |
| 3241 RefPtr <CSSValue> columnCount; | |
| 3242 bool hasPendingExplicitAuto = false; | |
| 3243 | |
| 3244 for (unsigned propertiesParsed = 0; CSSParserValue* value = m_valueList->cur
rent(); propertiesParsed++) { | |
| 3245 if (propertiesParsed >= 2) | |
| 3246 return false; // Too many values for this shorthand. Invalid declara
tion. | |
| 3247 if (!propertiesParsed && value->id == CSSValueAuto) { | |
| 3248 // 'auto' is a valid value for any of the two longhands, and at this
point we | |
| 3249 // don't know which one(s) it is meant for. We need to see if there
are other | |
| 3250 // values first. | |
| 3251 m_valueList->next(); | |
| 3252 hasPendingExplicitAuto = true; | |
| 3253 } else { | |
| 3254 if (!columnWidth) { | |
| 3255 if ((columnWidth = parseColumnWidth())) | |
| 3256 continue; | |
| 3257 } | |
| 3258 if (!columnCount) { | |
| 3259 if ((columnCount = parseColumnCount())) | |
| 3260 continue; | |
| 3261 } | |
| 3262 // If we didn't find at least one match, this is an | |
| 3263 // invalid shorthand and we have to ignore it. | |
| 3264 return false; | |
| 3265 } | |
| 3266 } | |
| 3267 if (hasPendingExplicitAuto) { | |
| 3268 // Time to assign the previously skipped 'auto' value to a property. If
both properties are | |
| 3269 // unassigned at this point (i.e. 'columns:auto'), it doesn't matter tha
t much which one we | |
| 3270 // set (although it does make a slight difference to web-inspector). The
one we don't set | |
| 3271 // here will get an implicit 'auto' value further down. | |
| 3272 if (!columnWidth) { | |
| 3273 columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 3274 } else { | |
| 3275 ASSERT(!columnCount); | |
| 3276 columnCount = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 3277 } | |
| 3278 } | |
| 3279 ASSERT(columnCount || columnWidth); | |
| 3280 | |
| 3281 // Any unassigned property at this point will become implicit 'auto'. | |
| 3282 if (columnWidth) | |
| 3283 addProperty(CSSPropertyWebkitColumnWidth, columnWidth, important); | |
| 3284 else | |
| 3285 addProperty(CSSPropertyWebkitColumnWidth, cssValuePool().createIdentifie
rValue(CSSValueAuto), important, true /* implicit */); | |
| 3286 if (columnCount) | |
| 3287 addProperty(CSSPropertyWebkitColumnCount, columnCount, important); | |
| 3288 else | |
| 3289 addProperty(CSSPropertyWebkitColumnCount, cssValuePool().createIdentifie
rValue(CSSValueAuto), important, true /* implicit */); | |
| 3290 return true; | |
| 3291 } | |
| 3292 | |
| 3293 bool CSSParser::parseShorthand(CSSPropertyID propId, const StylePropertyShorthan
d& shorthand, bool important) | |
| 3294 { | |
| 3295 // We try to match as many properties as possible | |
| 3296 // We set up an array of booleans to mark which property has been found, | |
| 3297 // and we try to search for properties until it makes no longer any sense. | |
| 3298 ShorthandScope scope(this, propId); | |
| 3299 | |
| 3300 bool found = false; | |
| 3301 unsigned propertiesParsed = 0; | |
| 3302 bool propertyFound[6] = { false, false, false, false, false, false }; // 6 i
s enough size. | |
| 3303 | |
| 3304 while (m_valueList->current()) { | |
| 3305 found = false; | |
| 3306 for (unsigned propIndex = 0; !found && propIndex < shorthand.length(); +
+propIndex) { | |
| 3307 if (!propertyFound[propIndex] && parseValue(shorthand.properties()[p
ropIndex], important)) { | |
| 3308 propertyFound[propIndex] = found = true; | |
| 3309 propertiesParsed++; | |
| 3310 } | |
| 3311 } | |
| 3312 | |
| 3313 // if we didn't find at least one match, this is an | |
| 3314 // invalid shorthand and we have to ignore it | |
| 3315 if (!found) | |
| 3316 return false; | |
| 3317 } | |
| 3318 | |
| 3319 if (propertiesParsed == shorthand.length()) | |
| 3320 return true; | |
| 3321 | |
| 3322 // Fill in any remaining properties with the initial value. | |
| 3323 ImplicitScope implicitScope(this, PropertyImplicit); | |
| 3324 const StylePropertyShorthand* const* const propertiesForInitialization = sho
rthand.propertiesForInitialization(); | |
| 3325 for (unsigned i = 0; i < shorthand.length(); ++i) { | |
| 3326 if (propertyFound[i]) | |
| 3327 continue; | |
| 3328 | |
| 3329 if (propertiesForInitialization) { | |
| 3330 const StylePropertyShorthand& initProperties = *(propertiesForInitia
lization[i]); | |
| 3331 for (unsigned propIndex = 0; propIndex < initProperties.length(); ++
propIndex) | |
| 3332 addProperty(initProperties.properties()[propIndex], cssValuePool
().createImplicitInitialValue(), important); | |
| 3333 } else | |
| 3334 addProperty(shorthand.properties()[i], cssValuePool().createImplicit
InitialValue(), important); | |
| 3335 } | |
| 3336 | |
| 3337 return true; | |
| 3338 } | |
| 3339 | |
| 3340 bool CSSParser::parse4Values(CSSPropertyID propId, const CSSPropertyID *properti
es, bool important) | |
| 3341 { | |
| 3342 /* From the CSS 2 specs, 8.3 | |
| 3343 * If there is only one value, it applies to all sides. If there are two val
ues, the top and | |
| 3344 * bottom margins are set to the first value and the right and left margins
are set to the second. | |
| 3345 * If there are three values, the top is set to the first value, the left an
d right are set to the | |
| 3346 * second, and the bottom is set to the third. If there are four values, the
y apply to the top, | |
| 3347 * right, bottom, and left, respectively. | |
| 3348 */ | |
| 3349 | |
| 3350 int num = inShorthand() ? 1 : m_valueList->size(); | |
| 3351 | |
| 3352 ShorthandScope scope(this, propId); | |
| 3353 | |
| 3354 // the order is top, right, bottom, left | |
| 3355 switch (num) { | |
| 3356 case 1: { | |
| 3357 if (!parseValue(properties[0], important)) | |
| 3358 return false; | |
| 3359 CSSValue* value = m_parsedProperties.last().value(); | |
| 3360 ImplicitScope implicitScope(this, PropertyImplicit); | |
| 3361 addProperty(properties[1], value, important); | |
| 3362 addProperty(properties[2], value, important); | |
| 3363 addProperty(properties[3], value, important); | |
| 3364 break; | |
| 3365 } | |
| 3366 case 2: { | |
| 3367 if (!parseValue(properties[0], important) || !parseValue(properties[
1], important)) | |
| 3368 return false; | |
| 3369 CSSValue* value = m_parsedProperties[m_parsedProperties.size() - 2].
value(); | |
| 3370 ImplicitScope implicitScope(this, PropertyImplicit); | |
| 3371 addProperty(properties[2], value, important); | |
| 3372 value = m_parsedProperties[m_parsedProperties.size() - 2].value(); | |
| 3373 addProperty(properties[3], value, important); | |
| 3374 break; | |
| 3375 } | |
| 3376 case 3: { | |
| 3377 if (!parseValue(properties[0], important) || !parseValue(properties[
1], important) || !parseValue(properties[2], important)) | |
| 3378 return false; | |
| 3379 CSSValue* value = m_parsedProperties[m_parsedProperties.size() - 2].
value(); | |
| 3380 ImplicitScope implicitScope(this, PropertyImplicit); | |
| 3381 addProperty(properties[3], value, important); | |
| 3382 break; | |
| 3383 } | |
| 3384 case 4: { | |
| 3385 if (!parseValue(properties[0], important) || !parseValue(properties[
1], important) || | |
| 3386 !parseValue(properties[2], important) || !parseValue(properties[
3], important)) | |
| 3387 return false; | |
| 3388 break; | |
| 3389 } | |
| 3390 default: { | |
| 3391 return false; | |
| 3392 } | |
| 3393 } | |
| 3394 | |
| 3395 return true; | |
| 3396 } | |
| 3397 | |
| 3398 // auto | <identifier> | |
| 3399 bool CSSParser::parsePage(CSSPropertyID propId, bool important) | |
| 3400 { | |
| 3401 ASSERT(propId == CSSPropertyPage); | |
| 3402 | |
| 3403 if (m_valueList->size() != 1) | |
| 3404 return false; | |
| 3405 | |
| 3406 CSSParserValue* value = m_valueList->current(); | |
| 3407 if (!value) | |
| 3408 return false; | |
| 3409 | |
| 3410 if (value->id == CSSValueAuto) { | |
| 3411 addProperty(propId, cssValuePool().createIdentifierValue(value->id), imp
ortant); | |
| 3412 return true; | |
| 3413 } else if (value->id == 0 && value->unit == CSSPrimitiveValue::CSS_IDENT) { | |
| 3414 addProperty(propId, createPrimitiveStringValue(value), important); | |
| 3415 return true; | |
| 3416 } | |
| 3417 return false; | |
| 3418 } | |
| 3419 | |
| 3420 // <length>{1,2} | auto | [ <page-size> || [ portrait | landscape] ] | |
| 3421 bool CSSParser::parseSize(CSSPropertyID propId, bool important) | |
| 3422 { | |
| 3423 ASSERT(propId == CSSPropertySize); | |
| 3424 | |
| 3425 if (m_valueList->size() > 2) | |
| 3426 return false; | |
| 3427 | |
| 3428 CSSParserValue* value = m_valueList->current(); | |
| 3429 if (!value) | |
| 3430 return false; | |
| 3431 | |
| 3432 RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated(); | |
| 3433 | |
| 3434 // First parameter. | |
| 3435 SizeParameterType paramType = parseSizeParameter(parsedValues.get(), value,
None); | |
| 3436 if (paramType == None) | |
| 3437 return false; | |
| 3438 | |
| 3439 // Second parameter, if any. | |
| 3440 value = m_valueList->next(); | |
| 3441 if (value) { | |
| 3442 paramType = parseSizeParameter(parsedValues.get(), value, paramType); | |
| 3443 if (paramType == None) | |
| 3444 return false; | |
| 3445 } | |
| 3446 | |
| 3447 addProperty(propId, parsedValues.release(), important); | |
| 3448 return true; | |
| 3449 } | |
| 3450 | |
| 3451 CSSParser::SizeParameterType CSSParser::parseSizeParameter(CSSValueList* parsedV
alues, CSSParserValue* value, SizeParameterType prevParamType) | |
| 3452 { | |
| 3453 switch (value->id) { | |
| 3454 case CSSValueAuto: | |
| 3455 if (prevParamType == None) { | |
| 3456 parsedValues->append(cssValuePool().createIdentifierValue(value->id)
); | |
| 3457 return Auto; | |
| 3458 } | |
| 3459 return None; | |
| 3460 case CSSValueLandscape: | |
| 3461 case CSSValuePortrait: | |
| 3462 if (prevParamType == None || prevParamType == PageSize) { | |
| 3463 parsedValues->append(cssValuePool().createIdentifierValue(value->id)
); | |
| 3464 return Orientation; | |
| 3465 } | |
| 3466 return None; | |
| 3467 case CSSValueA3: | |
| 3468 case CSSValueA4: | |
| 3469 case CSSValueA5: | |
| 3470 case CSSValueB4: | |
| 3471 case CSSValueB5: | |
| 3472 case CSSValueLedger: | |
| 3473 case CSSValueLegal: | |
| 3474 case CSSValueLetter: | |
| 3475 if (prevParamType == None || prevParamType == Orientation) { | |
| 3476 // Normalize to Page Size then Orientation order by prepending. | |
| 3477 // This is not specified by the CSS3 Paged Media specification, but
for simpler processing later (StyleResolver::applyPageSizeProperty). | |
| 3478 parsedValues->prepend(cssValuePool().createIdentifierValue(value->id
)); | |
| 3479 return PageSize; | |
| 3480 } | |
| 3481 return None; | |
| 3482 case 0: | |
| 3483 if (validUnit(value, FLength | FNonNeg) && (prevParamType == None || pre
vParamType == Length)) { | |
| 3484 parsedValues->append(createPrimitiveNumericValue(value)); | |
| 3485 return Length; | |
| 3486 } | |
| 3487 return None; | |
| 3488 default: | |
| 3489 return None; | |
| 3490 } | |
| 3491 } | |
| 3492 | |
| 3493 // [ <string> <string> ]+ | inherit | none | |
| 3494 // inherit and none are handled in parseValue. | |
| 3495 bool CSSParser::parseQuotes(CSSPropertyID propId, bool important) | |
| 3496 { | |
| 3497 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated(); | |
| 3498 while (CSSParserValue* val = m_valueList->current()) { | |
| 3499 RefPtr<CSSValue> parsedValue; | |
| 3500 if (val->unit == CSSPrimitiveValue::CSS_STRING) | |
| 3501 parsedValue = CSSPrimitiveValue::create(val->string, CSSPrimitiveVal
ue::CSS_STRING); | |
| 3502 else | |
| 3503 break; | |
| 3504 values->append(parsedValue.release()); | |
| 3505 m_valueList->next(); | |
| 3506 } | |
| 3507 if (values->length()) { | |
| 3508 addProperty(propId, values.release(), important); | |
| 3509 m_valueList->next(); | |
| 3510 return true; | |
| 3511 } | |
| 3512 return false; | |
| 3513 } | |
| 3514 | |
| 3515 // [ <string> | <uri> | <counter> | attr(X) | open-quote | close-quote | no-open
-quote | no-close-quote ]+ | inherit | |
| 3516 // in CSS 2.1 this got somewhat reduced: | |
| 3517 // [ <string> | attr(X) | open-quote | close-quote | no-open-quote | no-close-qu
ote ]+ | inherit | |
| 3518 bool CSSParser::parseContent(CSSPropertyID propId, bool important) | |
| 3519 { | |
| 3520 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated(); | |
| 3521 | |
| 3522 while (CSSParserValue* val = m_valueList->current()) { | |
| 3523 RefPtr<CSSValue> parsedValue; | |
| 3524 if (val->unit == CSSPrimitiveValue::CSS_URI) { | |
| 3525 // url | |
| 3526 parsedValue = CSSImageValue::create(completeURL(val->string)); | |
| 3527 } else if (val->unit == CSSParserValue::Function) { | |
| 3528 // attr(X) | counter(X [,Y]) | counters(X, Y, [,Z]) | -webkit-gradie
nt(...) | |
| 3529 CSSParserValueList* args = val->function->args.get(); | |
| 3530 if (!args) | |
| 3531 return false; | |
| 3532 if (equalIgnoringCase(val->function->name, "attr(")) { | |
| 3533 parsedValue = parseAttr(args); | |
| 3534 if (!parsedValue) | |
| 3535 return false; | |
| 3536 } else if (equalIgnoringCase(val->function->name, "counter(")) { | |
| 3537 parsedValue = parseCounterContent(args, false); | |
| 3538 if (!parsedValue) | |
| 3539 return false; | |
| 3540 } else if (equalIgnoringCase(val->function->name, "counters(")) { | |
| 3541 parsedValue = parseCounterContent(args, true); | |
| 3542 if (!parsedValue) | |
| 3543 return false; | |
| 3544 } else if (equalIgnoringCase(val->function->name, "-webkit-image-set
(")) { | |
| 3545 parsedValue = parseImageSet(m_valueList.get()); | |
| 3546 if (!parsedValue) | |
| 3547 return false; | |
| 3548 } else if (isGeneratedImageValue(val)) { | |
| 3549 if (!parseGeneratedImage(m_valueList.get(), parsedValue)) | |
| 3550 return false; | |
| 3551 } else | |
| 3552 return false; | |
| 3553 } else if (val->unit == CSSPrimitiveValue::CSS_IDENT) { | |
| 3554 // open-quote | |
| 3555 // close-quote | |
| 3556 // no-open-quote | |
| 3557 // no-close-quote | |
| 3558 // inherit | |
| 3559 // FIXME: These are not yet implemented (http://bugs.webkit.org/show
_bug.cgi?id=6503). | |
| 3560 // none | |
| 3561 // normal | |
| 3562 switch (val->id) { | |
| 3563 case CSSValueOpenQuote: | |
| 3564 case CSSValueCloseQuote: | |
| 3565 case CSSValueNoOpenQuote: | |
| 3566 case CSSValueNoCloseQuote: | |
| 3567 case CSSValueNone: | |
| 3568 case CSSValueNormal: | |
| 3569 parsedValue = cssValuePool().createIdentifierValue(val->id); | |
| 3570 default: | |
| 3571 break; | |
| 3572 } | |
| 3573 } else if (val->unit == CSSPrimitiveValue::CSS_STRING) { | |
| 3574 parsedValue = createPrimitiveStringValue(val); | |
| 3575 } | |
| 3576 if (!parsedValue) | |
| 3577 break; | |
| 3578 values->append(parsedValue.release()); | |
| 3579 m_valueList->next(); | |
| 3580 } | |
| 3581 | |
| 3582 if (values->length()) { | |
| 3583 addProperty(propId, values.release(), important); | |
| 3584 m_valueList->next(); | |
| 3585 return true; | |
| 3586 } | |
| 3587 | |
| 3588 return false; | |
| 3589 } | |
| 3590 | |
| 3591 PassRefPtr<CSSValue> CSSParser::parseAttr(CSSParserValueList* args) | |
| 3592 { | |
| 3593 if (args->size() != 1) | |
| 3594 return 0; | |
| 3595 | |
| 3596 CSSParserValue* a = args->current(); | |
| 3597 | |
| 3598 if (a->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 3599 return 0; | |
| 3600 | |
| 3601 String attrName = a->string; | |
| 3602 // CSS allows identifiers with "-" at the start, like "-webkit-mask-image". | |
| 3603 // But HTML attribute names can't have those characters, and we should not | |
| 3604 // even parse them inside attr(). | |
| 3605 if (attrName[0] == '-') | |
| 3606 return 0; | |
| 3607 | |
| 3608 if (m_context.isHTMLDocument()) | |
| 3609 attrName = attrName.lower(); | |
| 3610 | |
| 3611 return cssValuePool().createValue(attrName, CSSPrimitiveValue::CSS_ATTR); | |
| 3612 } | |
| 3613 | |
| 3614 PassRefPtr<CSSValue> CSSParser::parseBackgroundColor() | |
| 3615 { | |
| 3616 CSSValueID id = m_valueList->current()->id; | |
| 3617 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowt
ext) || id == CSSValueMenu || id == CSSValueCurrentcolor || | |
| 3618 (id >= CSSValueGrey && id < CSSValueWebkitText && inQuirksMode())) | |
| 3619 return cssValuePool().createIdentifierValue(id); | |
| 3620 return parseColor(); | |
| 3621 } | |
| 3622 | |
| 3623 bool CSSParser::parseFillImage(CSSParserValueList* valueList, RefPtr<CSSValue>&
value) | |
| 3624 { | |
| 3625 if (valueList->current()->id == CSSValueNone) { | |
| 3626 value = cssValuePool().createIdentifierValue(CSSValueNone); | |
| 3627 return true; | |
| 3628 } | |
| 3629 if (valueList->current()->unit == CSSPrimitiveValue::CSS_URI) { | |
| 3630 value = CSSImageValue::create(completeURL(valueList->current()->string))
; | |
| 3631 return true; | |
| 3632 } | |
| 3633 | |
| 3634 if (isGeneratedImageValue(valueList->current())) | |
| 3635 return parseGeneratedImage(valueList, value); | |
| 3636 | |
| 3637 if (valueList->current()->unit == CSSParserValue::Function && equalIgnoringC
ase(valueList->current()->function->name, "-webkit-image-set(")) { | |
| 3638 value = parseImageSet(m_valueList.get()); | |
| 3639 if (value) | |
| 3640 return true; | |
| 3641 } | |
| 3642 | |
| 3643 return false; | |
| 3644 } | |
| 3645 | |
| 3646 PassRefPtr<CSSValue> CSSParser::parseFillPositionX(CSSParserValueList* valueList
) | |
| 3647 { | |
| 3648 int id = valueList->current()->id; | |
| 3649 if (id == CSSValueLeft || id == CSSValueRight || id == CSSValueCenter) { | |
| 3650 int percent = 0; | |
| 3651 if (id == CSSValueRight) | |
| 3652 percent = 100; | |
| 3653 else if (id == CSSValueCenter) | |
| 3654 percent = 50; | |
| 3655 return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCEN
TAGE); | |
| 3656 } | |
| 3657 if (validUnit(valueList->current(), FPercent | FLength)) | |
| 3658 return createPrimitiveNumericValue(valueList->current()); | |
| 3659 return 0; | |
| 3660 } | |
| 3661 | |
| 3662 PassRefPtr<CSSValue> CSSParser::parseFillPositionY(CSSParserValueList* valueList
) | |
| 3663 { | |
| 3664 int id = valueList->current()->id; | |
| 3665 if (id == CSSValueTop || id == CSSValueBottom || id == CSSValueCenter) { | |
| 3666 int percent = 0; | |
| 3667 if (id == CSSValueBottom) | |
| 3668 percent = 100; | |
| 3669 else if (id == CSSValueCenter) | |
| 3670 percent = 50; | |
| 3671 return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCEN
TAGE); | |
| 3672 } | |
| 3673 if (validUnit(valueList->current(), FPercent | FLength)) | |
| 3674 return createPrimitiveNumericValue(valueList->current()); | |
| 3675 return 0; | |
| 3676 } | |
| 3677 | |
| 3678 PassRefPtr<CSSPrimitiveValue> CSSParser::parseFillPositionComponent(CSSParserVal
ueList* valueList, unsigned& cumulativeFlags, FillPositionFlag& individualFlag,
FillPositionParsingMode parsingMode) | |
| 3679 { | |
| 3680 CSSValueID id = valueList->current()->id; | |
| 3681 if (id == CSSValueLeft || id == CSSValueTop || id == CSSValueRight || id ==
CSSValueBottom || id == CSSValueCenter) { | |
| 3682 int percent = 0; | |
| 3683 if (id == CSSValueLeft || id == CSSValueRight) { | |
| 3684 if (cumulativeFlags & XFillPosition) | |
| 3685 return 0; | |
| 3686 cumulativeFlags |= XFillPosition; | |
| 3687 individualFlag = XFillPosition; | |
| 3688 if (id == CSSValueRight) | |
| 3689 percent = 100; | |
| 3690 } | |
| 3691 else if (id == CSSValueTop || id == CSSValueBottom) { | |
| 3692 if (cumulativeFlags & YFillPosition) | |
| 3693 return 0; | |
| 3694 cumulativeFlags |= YFillPosition; | |
| 3695 individualFlag = YFillPosition; | |
| 3696 if (id == CSSValueBottom) | |
| 3697 percent = 100; | |
| 3698 } else if (id == CSSValueCenter) { | |
| 3699 // Center is ambiguous, so we're not sure which position we've found
yet, an x or a y. | |
| 3700 percent = 50; | |
| 3701 cumulativeFlags |= AmbiguousFillPosition; | |
| 3702 individualFlag = AmbiguousFillPosition; | |
| 3703 } | |
| 3704 | |
| 3705 if (parsingMode == ResolveValuesAsKeyword) | |
| 3706 return cssValuePool().createIdentifierValue(id); | |
| 3707 | |
| 3708 return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCEN
TAGE); | |
| 3709 } | |
| 3710 if (validUnit(valueList->current(), FPercent | FLength)) { | |
| 3711 if (!cumulativeFlags) { | |
| 3712 cumulativeFlags |= XFillPosition; | |
| 3713 individualFlag = XFillPosition; | |
| 3714 } else if (cumulativeFlags & (XFillPosition | AmbiguousFillPosition)) { | |
| 3715 cumulativeFlags |= YFillPosition; | |
| 3716 individualFlag = YFillPosition; | |
| 3717 } else { | |
| 3718 if (m_parsedCalculation) | |
| 3719 m_parsedCalculation.release(); | |
| 3720 return 0; | |
| 3721 } | |
| 3722 return createPrimitiveNumericValue(valueList->current()); | |
| 3723 } | |
| 3724 return 0; | |
| 3725 } | |
| 3726 | |
| 3727 static bool isValueConflictingWithCurrentEdge(int value1, int value2) | |
| 3728 { | |
| 3729 if ((value1 == CSSValueLeft || value1 == CSSValueRight) && (value2 == CSSVal
ueLeft || value2 == CSSValueRight)) | |
| 3730 return true; | |
| 3731 | |
| 3732 if ((value1 == CSSValueTop || value1 == CSSValueBottom) && (value2 == CSSVal
ueTop || value2 == CSSValueBottom)) | |
| 3733 return true; | |
| 3734 | |
| 3735 return false; | |
| 3736 } | |
| 3737 | |
| 3738 static bool isFillPositionKeyword(CSSValueID value) | |
| 3739 { | |
| 3740 return value == CSSValueLeft || value == CSSValueTop || value == CSSValueBot
tom || value == CSSValueRight || value == CSSValueCenter; | |
| 3741 } | |
| 3742 | |
| 3743 void CSSParser::parse4ValuesFillPosition(CSSParserValueList* valueList, RefPtr<C
SSValue>& value1, RefPtr<CSSValue>& value2, PassRefPtr<CSSPrimitiveValue> parsed
Value1, PassRefPtr<CSSPrimitiveValue> parsedValue2) | |
| 3744 { | |
| 3745 // [ left | right ] [ <percentage] | <length> ] && [ top | bottom ] [ <perce
ntage> | <length> ] | |
| 3746 // In the case of 4 values <position> requires the second value to be a leng
th or a percentage. | |
| 3747 if (isFillPositionKeyword(parsedValue2->getValueID())) | |
| 3748 return; | |
| 3749 | |
| 3750 unsigned cumulativeFlags = 0; | |
| 3751 FillPositionFlag value3Flag = InvalidFillPosition; | |
| 3752 RefPtr<CSSPrimitiveValue> value3 = parseFillPositionComponent(valueList, cum
ulativeFlags, value3Flag, ResolveValuesAsKeyword); | |
| 3753 if (!value3) | |
| 3754 return; | |
| 3755 | |
| 3756 CSSValueID ident1 = parsedValue1->getValueID(); | |
| 3757 CSSValueID ident3 = value3->getValueID(); | |
| 3758 | |
| 3759 if (ident1 == CSSValueCenter) | |
| 3760 return; | |
| 3761 | |
| 3762 if (!isFillPositionKeyword(ident3) || ident3 == CSSValueCenter) | |
| 3763 return; | |
| 3764 | |
| 3765 // We need to check if the values are not conflicting, e.g. they are not on
the same edge. It is | |
| 3766 // needed as the second call to parseFillPositionComponent was on purpose no
t checking it. In the | |
| 3767 // case of two values top 20px is invalid but in the case of 4 values it bec
omes valid. | |
| 3768 if (isValueConflictingWithCurrentEdge(ident1, ident3)) | |
| 3769 return; | |
| 3770 | |
| 3771 valueList->next(); | |
| 3772 | |
| 3773 cumulativeFlags = 0; | |
| 3774 FillPositionFlag value4Flag = InvalidFillPosition; | |
| 3775 RefPtr<CSSPrimitiveValue> value4 = parseFillPositionComponent(valueList, cum
ulativeFlags, value4Flag, ResolveValuesAsKeyword); | |
| 3776 if (!value4) | |
| 3777 return; | |
| 3778 | |
| 3779 // 4th value must be a length or a percentage. | |
| 3780 if (isFillPositionKeyword(value4->getValueID())) | |
| 3781 return; | |
| 3782 | |
| 3783 value1 = createPrimitiveValuePair(parsedValue1, parsedValue2); | |
| 3784 value2 = createPrimitiveValuePair(value3, value4); | |
| 3785 | |
| 3786 if (ident1 == CSSValueTop || ident1 == CSSValueBottom) | |
| 3787 value1.swap(value2); | |
| 3788 | |
| 3789 valueList->next(); | |
| 3790 } | |
| 3791 void CSSParser::parse3ValuesFillPosition(CSSParserValueList* valueList, RefPtr<C
SSValue>& value1, RefPtr<CSSValue>& value2, PassRefPtr<CSSPrimitiveValue> parsed
Value1, PassRefPtr<CSSPrimitiveValue> parsedValue2) | |
| 3792 { | |
| 3793 unsigned cumulativeFlags = 0; | |
| 3794 FillPositionFlag value3Flag = InvalidFillPosition; | |
| 3795 RefPtr<CSSPrimitiveValue> value3 = parseFillPositionComponent(valueList, cum
ulativeFlags, value3Flag, ResolveValuesAsKeyword); | |
| 3796 | |
| 3797 // value3 is not an expected value, we return. | |
| 3798 if (!value3) | |
| 3799 return; | |
| 3800 | |
| 3801 valueList->next(); | |
| 3802 | |
| 3803 bool swapNeeded = false; | |
| 3804 CSSValueID ident1 = parsedValue1->getValueID(); | |
| 3805 CSSValueID ident2 = parsedValue2->getValueID(); | |
| 3806 CSSValueID ident3 = value3->getValueID(); | |
| 3807 | |
| 3808 CSSValueID firstPositionKeyword; | |
| 3809 CSSValueID secondPositionKeyword; | |
| 3810 | |
| 3811 if (ident1 == CSSValueCenter) { | |
| 3812 // <position> requires the first 'center' to be followed by a keyword. | |
| 3813 if (!isFillPositionKeyword(ident2)) | |
| 3814 return; | |
| 3815 | |
| 3816 // If 'center' is the first keyword then the last one needs to be a leng
th. | |
| 3817 if (isFillPositionKeyword(ident3)) | |
| 3818 return; | |
| 3819 | |
| 3820 firstPositionKeyword = CSSValueLeft; | |
| 3821 if (ident2 == CSSValueLeft || ident2 == CSSValueRight) { | |
| 3822 firstPositionKeyword = CSSValueTop; | |
| 3823 swapNeeded = true; | |
| 3824 } | |
| 3825 value1 = createPrimitiveValuePair(cssValuePool().createIdentifierValue(f
irstPositionKeyword), cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERC
ENTAGE)); | |
| 3826 value2 = createPrimitiveValuePair(parsedValue2, value3); | |
| 3827 } else if (ident3 == CSSValueCenter) { | |
| 3828 if (isFillPositionKeyword(ident2)) | |
| 3829 return; | |
| 3830 | |
| 3831 secondPositionKeyword = CSSValueTop; | |
| 3832 if (ident1 == CSSValueTop || ident1 == CSSValueBottom) { | |
| 3833 secondPositionKeyword = CSSValueLeft; | |
| 3834 swapNeeded = true; | |
| 3835 } | |
| 3836 value1 = createPrimitiveValuePair(parsedValue1, parsedValue2); | |
| 3837 value2 = createPrimitiveValuePair(cssValuePool().createIdentifierValue(s
econdPositionKeyword), cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PER
CENTAGE)); | |
| 3838 } else { | |
| 3839 RefPtr<CSSPrimitiveValue> firstPositionValue; | |
| 3840 RefPtr<CSSPrimitiveValue> secondPositionValue; | |
| 3841 | |
| 3842 if (isFillPositionKeyword(ident2)) { | |
| 3843 // To match CSS grammar, we should only accept: [ center | left | ri
ght | bottom | top ] [ left | right | top | bottom ] [ <percentage> | <length> ]
. | |
| 3844 ASSERT(ident2 != CSSValueCenter); | |
| 3845 | |
| 3846 if (isFillPositionKeyword(ident3)) | |
| 3847 return; | |
| 3848 | |
| 3849 secondPositionValue = value3; | |
| 3850 secondPositionKeyword = ident2; | |
| 3851 firstPositionValue = cssValuePool().createValue(0, CSSPrimitiveValue
::CSS_PERCENTAGE); | |
| 3852 } else { | |
| 3853 // Per CSS, we should only accept: [ right | left | top | bottom ] [
<percentage> | <length> ] [ center | left | right | bottom | top ]. | |
| 3854 if (!isFillPositionKeyword(ident3)) | |
| 3855 return; | |
| 3856 | |
| 3857 firstPositionValue = parsedValue2; | |
| 3858 secondPositionKeyword = ident3; | |
| 3859 secondPositionValue = cssValuePool().createValue(0, CSSPrimitiveValu
e::CSS_PERCENTAGE); | |
| 3860 } | |
| 3861 | |
| 3862 if (isValueConflictingWithCurrentEdge(ident1, secondPositionKeyword)) | |
| 3863 return; | |
| 3864 | |
| 3865 value1 = createPrimitiveValuePair(parsedValue1, firstPositionValue); | |
| 3866 value2 = createPrimitiveValuePair(cssValuePool().createIdentifierValue(s
econdPositionKeyword), secondPositionValue); | |
| 3867 } | |
| 3868 | |
| 3869 if (ident1 == CSSValueTop || ident1 == CSSValueBottom || swapNeeded) | |
| 3870 value1.swap(value2); | |
| 3871 | |
| 3872 #ifndef NDEBUG | |
| 3873 CSSPrimitiveValue* first = toCSSPrimitiveValue(value1.get()); | |
| 3874 CSSPrimitiveValue* second = toCSSPrimitiveValue(value2.get()); | |
| 3875 ident1 = first->getPairValue()->first()->getValueID(); | |
| 3876 ident2 = second->getPairValue()->first()->getValueID(); | |
| 3877 ASSERT(ident1 == CSSValueLeft || ident1 == CSSValueRight); | |
| 3878 ASSERT(ident2 == CSSValueBottom || ident2 == CSSValueTop); | |
| 3879 #endif | |
| 3880 } | |
| 3881 | |
| 3882 inline bool CSSParser::isPotentialPositionValue(CSSParserValue* value) | |
| 3883 { | |
| 3884 return isFillPositionKeyword(value->id) || validUnit(value, FPercent | FLeng
th, ReleaseParsedCalcValue); | |
| 3885 } | |
| 3886 | |
| 3887 void CSSParser::parseFillPosition(CSSParserValueList* valueList, RefPtr<CSSValue
>& value1, RefPtr<CSSValue>& value2) | |
| 3888 { | |
| 3889 unsigned numberOfValues = 0; | |
| 3890 for (unsigned i = valueList->currentIndex(); i < valueList->size(); ++i, ++n
umberOfValues) { | |
| 3891 CSSParserValue* current = valueList->valueAt(i); | |
| 3892 if (isComma(current) || !current || isForwardSlashOperator(current) || !
isPotentialPositionValue(current)) | |
| 3893 break; | |
| 3894 } | |
| 3895 | |
| 3896 if (numberOfValues > 4) | |
| 3897 return; | |
| 3898 | |
| 3899 // If we are parsing two values, we can safely call the CSS 2.1 parsing func
tion and return. | |
| 3900 if (numberOfValues <= 2) { | |
| 3901 parse2ValuesFillPosition(valueList, value1, value2); | |
| 3902 return; | |
| 3903 } | |
| 3904 | |
| 3905 ASSERT(numberOfValues > 2 && numberOfValues <= 4); | |
| 3906 | |
| 3907 CSSParserValue* value = valueList->current(); | |
| 3908 | |
| 3909 // <position> requires the first value to be a background keyword. | |
| 3910 if (!isFillPositionKeyword(value->id)) | |
| 3911 return; | |
| 3912 | |
| 3913 // Parse the first value. We're just making sure that it is one of the valid
keywords or a percentage/length. | |
| 3914 unsigned cumulativeFlags = 0; | |
| 3915 FillPositionFlag value1Flag = InvalidFillPosition; | |
| 3916 FillPositionFlag value2Flag = InvalidFillPosition; | |
| 3917 value1 = parseFillPositionComponent(valueList, cumulativeFlags, value1Flag,
ResolveValuesAsKeyword); | |
| 3918 if (!value1) | |
| 3919 return; | |
| 3920 | |
| 3921 value = valueList->next(); | |
| 3922 | |
| 3923 // In case we are parsing more than two values, relax the check inside of pa
rseFillPositionComponent. top 20px is | |
| 3924 // a valid start for <position>. | |
| 3925 cumulativeFlags = AmbiguousFillPosition; | |
| 3926 value2 = parseFillPositionComponent(valueList, cumulativeFlags, value2Flag,
ResolveValuesAsKeyword); | |
| 3927 if (value2) | |
| 3928 valueList->next(); | |
| 3929 else { | |
| 3930 value1.clear(); | |
| 3931 return; | |
| 3932 } | |
| 3933 | |
| 3934 RefPtr<CSSPrimitiveValue> parsedValue1 = toCSSPrimitiveValue(value1.get()); | |
| 3935 RefPtr<CSSPrimitiveValue> parsedValue2 = toCSSPrimitiveValue(value2.get()); | |
| 3936 | |
| 3937 value1.clear(); | |
| 3938 value2.clear(); | |
| 3939 | |
| 3940 // Per CSS3 syntax, <position> can't have 'center' as its second keyword as
we have more arguments to follow. | |
| 3941 if (parsedValue2->getValueID() == CSSValueCenter) | |
| 3942 return; | |
| 3943 | |
| 3944 if (numberOfValues == 3) | |
| 3945 parse3ValuesFillPosition(valueList, value1, value2, parsedValue1.release
(), parsedValue2.release()); | |
| 3946 else | |
| 3947 parse4ValuesFillPosition(valueList, value1, value2, parsedValue1.release
(), parsedValue2.release()); | |
| 3948 } | |
| 3949 | |
| 3950 void CSSParser::parse2ValuesFillPosition(CSSParserValueList* valueList, RefPtr<C
SSValue>& value1, RefPtr<CSSValue>& value2) | |
| 3951 { | |
| 3952 CSSParserValue* value = valueList->current(); | |
| 3953 | |
| 3954 // Parse the first value. We're just making sure that it is one of the vali
d keywords or a percentage/length. | |
| 3955 unsigned cumulativeFlags = 0; | |
| 3956 FillPositionFlag value1Flag = InvalidFillPosition; | |
| 3957 FillPositionFlag value2Flag = InvalidFillPosition; | |
| 3958 value1 = parseFillPositionComponent(valueList, cumulativeFlags, value1Flag); | |
| 3959 if (!value1) | |
| 3960 return; | |
| 3961 | |
| 3962 // It only takes one value for background-position to be correctly parsed if
it was specified in a shorthand (since we | |
| 3963 // can assume that any other values belong to the rest of the shorthand). I
f we're not parsing a shorthand, though, the | |
| 3964 // value was explicitly specified for our property. | |
| 3965 value = valueList->next(); | |
| 3966 | |
| 3967 // First check for the comma. If so, we are finished parsing this value or
value pair. | |
| 3968 if (isComma(value)) | |
| 3969 value = 0; | |
| 3970 | |
| 3971 if (value) { | |
| 3972 value2 = parseFillPositionComponent(valueList, cumulativeFlags, value2Fl
ag); | |
| 3973 if (value2) | |
| 3974 valueList->next(); | |
| 3975 else { | |
| 3976 if (!inShorthand()) { | |
| 3977 value1.clear(); | |
| 3978 return; | |
| 3979 } | |
| 3980 } | |
| 3981 } | |
| 3982 | |
| 3983 if (!value2) | |
| 3984 // Only one value was specified. If that value was not a keyword, then i
t sets the x position, and the y position | |
| 3985 // is simply 50%. This is our default. | |
| 3986 // For keywords, the keyword was either an x-keyword (left/right), a y-k
eyword (top/bottom), or an ambiguous keyword (center). | |
| 3987 // For left/right/center, the default of 50% in the y is still correct. | |
| 3988 value2 = cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAG
E); | |
| 3989 | |
| 3990 if (value1Flag == YFillPosition || value2Flag == XFillPosition) | |
| 3991 value1.swap(value2); | |
| 3992 } | |
| 3993 | |
| 3994 void CSSParser::parseFillRepeat(RefPtr<CSSValue>& value1, RefPtr<CSSValue>& valu
e2) | |
| 3995 { | |
| 3996 CSSValueID id = m_valueList->current()->id; | |
| 3997 if (id == CSSValueRepeatX) { | |
| 3998 m_implicitShorthand = true; | |
| 3999 value1 = cssValuePool().createIdentifierValue(CSSValueRepeat); | |
| 4000 value2 = cssValuePool().createIdentifierValue(CSSValueNoRepeat); | |
| 4001 m_valueList->next(); | |
| 4002 return; | |
| 4003 } | |
| 4004 if (id == CSSValueRepeatY) { | |
| 4005 m_implicitShorthand = true; | |
| 4006 value1 = cssValuePool().createIdentifierValue(CSSValueNoRepeat); | |
| 4007 value2 = cssValuePool().createIdentifierValue(CSSValueRepeat); | |
| 4008 m_valueList->next(); | |
| 4009 return; | |
| 4010 } | |
| 4011 if (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRound ||
id == CSSValueSpace) | |
| 4012 value1 = cssValuePool().createIdentifierValue(id); | |
| 4013 else { | |
| 4014 value1 = 0; | |
| 4015 return; | |
| 4016 } | |
| 4017 | |
| 4018 CSSParserValue* value = m_valueList->next(); | |
| 4019 | |
| 4020 // Parse the second value if one is available | |
| 4021 if (value && !isComma(value)) { | |
| 4022 id = value->id; | |
| 4023 if (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRoun
d || id == CSSValueSpace) { | |
| 4024 value2 = cssValuePool().createIdentifierValue(id); | |
| 4025 m_valueList->next(); | |
| 4026 return; | |
| 4027 } | |
| 4028 } | |
| 4029 | |
| 4030 // If only one value was specified, value2 is the same as value1. | |
| 4031 m_implicitShorthand = true; | |
| 4032 value2 = cssValuePool().createIdentifierValue(toCSSPrimitiveValue(value1.get
())->getValueID()); | |
| 4033 } | |
| 4034 | |
| 4035 PassRefPtr<CSSValue> CSSParser::parseFillSize(CSSPropertyID propId, bool& allowC
omma) | |
| 4036 { | |
| 4037 allowComma = true; | |
| 4038 CSSParserValue* value = m_valueList->current(); | |
| 4039 | |
| 4040 if (value->id == CSSValueContain || value->id == CSSValueCover) | |
| 4041 return cssValuePool().createIdentifierValue(value->id); | |
| 4042 | |
| 4043 RefPtr<CSSPrimitiveValue> parsedValue1; | |
| 4044 | |
| 4045 if (value->id == CSSValueAuto) | |
| 4046 parsedValue1 = cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 4047 else { | |
| 4048 if (!validUnit(value, FLength | FPercent)) | |
| 4049 return 0; | |
| 4050 parsedValue1 = createPrimitiveNumericValue(value); | |
| 4051 } | |
| 4052 | |
| 4053 RefPtr<CSSPrimitiveValue> parsedValue2; | |
| 4054 if ((value = m_valueList->next())) { | |
| 4055 if (value->unit == CSSParserValue::Operator && value->iValue == ',') | |
| 4056 allowComma = false; | |
| 4057 else if (value->id != CSSValueAuto) { | |
| 4058 if (!validUnit(value, FLength | FPercent)) { | |
| 4059 if (!inShorthand()) | |
| 4060 return 0; | |
| 4061 // We need to rewind the value list, so that when it is advanced
we'll end up back at this value. | |
| 4062 m_valueList->previous(); | |
| 4063 } else | |
| 4064 parsedValue2 = createPrimitiveNumericValue(value); | |
| 4065 } | |
| 4066 } else if (!parsedValue2 && propId == CSSPropertyWebkitBackgroundSize) { | |
| 4067 // For backwards compatibility we set the second value to the first if i
t is omitted. | |
| 4068 // We only need to do this for -webkit-background-size. It should be saf
e to let masks match | |
| 4069 // the real property. | |
| 4070 parsedValue2 = parsedValue1; | |
| 4071 } | |
| 4072 | |
| 4073 if (!parsedValue2) | |
| 4074 return parsedValue1; | |
| 4075 return createPrimitiveValuePair(parsedValue1.release(), parsedValue2.release
()); | |
| 4076 } | |
| 4077 | |
| 4078 bool CSSParser::parseFillProperty(CSSPropertyID propId, CSSPropertyID& propId1,
CSSPropertyID& propId2, | |
| 4079 RefPtr<CSSValue>& retValue1, RefPtr<CSSValue>&
retValue2) | |
| 4080 { | |
| 4081 RefPtr<CSSValueList> values; | |
| 4082 RefPtr<CSSValueList> values2; | |
| 4083 CSSParserValue* val; | |
| 4084 RefPtr<CSSValue> value; | |
| 4085 RefPtr<CSSValue> value2; | |
| 4086 | |
| 4087 bool allowComma = false; | |
| 4088 | |
| 4089 retValue1 = retValue2 = 0; | |
| 4090 propId1 = propId; | |
| 4091 propId2 = propId; | |
| 4092 if (propId == CSSPropertyBackgroundPosition) { | |
| 4093 propId1 = CSSPropertyBackgroundPositionX; | |
| 4094 propId2 = CSSPropertyBackgroundPositionY; | |
| 4095 } else if (propId == CSSPropertyWebkitMaskPosition) { | |
| 4096 propId1 = CSSPropertyWebkitMaskPositionX; | |
| 4097 propId2 = CSSPropertyWebkitMaskPositionY; | |
| 4098 } else if (propId == CSSPropertyBackgroundRepeat) { | |
| 4099 propId1 = CSSPropertyBackgroundRepeatX; | |
| 4100 propId2 = CSSPropertyBackgroundRepeatY; | |
| 4101 } else if (propId == CSSPropertyWebkitMaskRepeat) { | |
| 4102 propId1 = CSSPropertyWebkitMaskRepeatX; | |
| 4103 propId2 = CSSPropertyWebkitMaskRepeatY; | |
| 4104 } | |
| 4105 | |
| 4106 while ((val = m_valueList->current())) { | |
| 4107 RefPtr<CSSValue> currValue; | |
| 4108 RefPtr<CSSValue> currValue2; | |
| 4109 | |
| 4110 if (allowComma) { | |
| 4111 if (!isComma(val)) | |
| 4112 return false; | |
| 4113 m_valueList->next(); | |
| 4114 allowComma = false; | |
| 4115 } else { | |
| 4116 allowComma = true; | |
| 4117 switch (propId) { | |
| 4118 case CSSPropertyBackgroundColor: | |
| 4119 currValue = parseBackgroundColor(); | |
| 4120 if (currValue) | |
| 4121 m_valueList->next(); | |
| 4122 break; | |
| 4123 case CSSPropertyBackgroundAttachment: | |
| 4124 if (val->id == CSSValueScroll || val->id == CSSValueFixed ||
val->id == CSSValueLocal) { | |
| 4125 currValue = cssValuePool().createIdentifierValue(val->id
); | |
| 4126 m_valueList->next(); | |
| 4127 } | |
| 4128 break; | |
| 4129 case CSSPropertyBackgroundImage: | |
| 4130 case CSSPropertyWebkitMaskImage: | |
| 4131 if (parseFillImage(m_valueList.get(), currValue)) | |
| 4132 m_valueList->next(); | |
| 4133 break; | |
| 4134 case CSSPropertyWebkitBackgroundClip: | |
| 4135 case CSSPropertyWebkitBackgroundOrigin: | |
| 4136 case CSSPropertyWebkitMaskClip: | |
| 4137 case CSSPropertyWebkitMaskOrigin: | |
| 4138 // The first three values here are deprecated and do not app
ly to the version of the property that has | |
| 4139 // the -webkit- prefix removed. | |
| 4140 if (val->id == CSSValueBorder || val->id == CSSValuePadding
|| val->id == CSSValueContent || | |
| 4141 val->id == CSSValueBorderBox || val->id == CSSValuePaddi
ngBox || val->id == CSSValueContentBox || | |
| 4142 ((propId == CSSPropertyWebkitBackgroundClip || propId ==
CSSPropertyWebkitMaskClip) && | |
| 4143 (val->id == CSSValueText || val->id == CSSValueWebkitTe
xt))) { | |
| 4144 currValue = cssValuePool().createIdentifierValue(val->id
); | |
| 4145 m_valueList->next(); | |
| 4146 } | |
| 4147 break; | |
| 4148 case CSSPropertyBackgroundClip: | |
| 4149 if (parseBackgroundClip(val, currValue)) | |
| 4150 m_valueList->next(); | |
| 4151 break; | |
| 4152 case CSSPropertyBackgroundOrigin: | |
| 4153 if (val->id == CSSValueBorderBox || val->id == CSSValuePaddi
ngBox || val->id == CSSValueContentBox) { | |
| 4154 currValue = cssValuePool().createIdentifierValue(val->id
); | |
| 4155 m_valueList->next(); | |
| 4156 } | |
| 4157 break; | |
| 4158 case CSSPropertyBackgroundPosition: | |
| 4159 case CSSPropertyWebkitMaskPosition: | |
| 4160 parseFillPosition(m_valueList.get(), currValue, currValue2); | |
| 4161 // parseFillPosition advances the m_valueList pointer. | |
| 4162 break; | |
| 4163 case CSSPropertyBackgroundPositionX: | |
| 4164 case CSSPropertyWebkitMaskPositionX: { | |
| 4165 currValue = parseFillPositionX(m_valueList.get()); | |
| 4166 if (currValue) | |
| 4167 m_valueList->next(); | |
| 4168 break; | |
| 4169 } | |
| 4170 case CSSPropertyBackgroundPositionY: | |
| 4171 case CSSPropertyWebkitMaskPositionY: { | |
| 4172 currValue = parseFillPositionY(m_valueList.get()); | |
| 4173 if (currValue) | |
| 4174 m_valueList->next(); | |
| 4175 break; | |
| 4176 } | |
| 4177 case CSSPropertyWebkitBackgroundComposite: | |
| 4178 case CSSPropertyWebkitMaskComposite: | |
| 4179 if (val->id >= CSSValueClear && val->id <= CSSValuePlusLight
er) { | |
| 4180 currValue = cssValuePool().createIdentifierValue(val->id
); | |
| 4181 m_valueList->next(); | |
| 4182 } | |
| 4183 break; | |
| 4184 case CSSPropertyBackgroundBlendMode: | |
| 4185 if (RuntimeEnabledFeatures::cssCompositingEnabled() && (val-
>id == CSSValueNormal || val->id == CSSValueMultiply | |
| 4186 || val->id == CSSValueScreen || val->id == CSSValueOverl
ay || val->id == CSSValueDarken | |
| 4187 || val->id == CSSValueLighten || val->id == CSSValueCol
orDodge || val->id == CSSValueColorBurn | |
| 4188 || val->id == CSSValueHardLight || val->id == CSSValueSo
ftLight || val->id == CSSValueDifference | |
| 4189 || val->id == CSSValueExclusion || val->id == CSSValueHu
e || val->id == CSSValueSaturation | |
| 4190 || val->id == CSSValueColor || val->id == CSSValueLumino
sity)) { | |
| 4191 currValue = cssValuePool().createIdentifierValue(val->id
); | |
| 4192 m_valueList->next(); | |
| 4193 } | |
| 4194 break; | |
| 4195 case CSSPropertyBackgroundRepeat: | |
| 4196 case CSSPropertyWebkitMaskRepeat: | |
| 4197 parseFillRepeat(currValue, currValue2); | |
| 4198 // parseFillRepeat advances the m_valueList pointer | |
| 4199 break; | |
| 4200 case CSSPropertyBackgroundSize: | |
| 4201 case CSSPropertyWebkitBackgroundSize: | |
| 4202 case CSSPropertyWebkitMaskSize: { | |
| 4203 currValue = parseFillSize(propId, allowComma); | |
| 4204 if (currValue) | |
| 4205 m_valueList->next(); | |
| 4206 break; | |
| 4207 } | |
| 4208 case CSSPropertyMaskSourceType: { | |
| 4209 if (RuntimeEnabledFeatures::cssMaskSourceTypeEnabled()) { | |
| 4210 if (val->id == CSSValueAuto || val->id == CSSValueAlpha
|| val->id == CSSValueLuminance) { | |
| 4211 currValue = cssValuePool().createIdentifierValue(val
->id); | |
| 4212 m_valueList->next(); | |
| 4213 } else { | |
| 4214 currValue = 0; | |
| 4215 } | |
| 4216 } | |
| 4217 break; | |
| 4218 } | |
| 4219 default: | |
| 4220 break; | |
| 4221 } | |
| 4222 if (!currValue) | |
| 4223 return false; | |
| 4224 | |
| 4225 if (value && !values) { | |
| 4226 values = CSSValueList::createCommaSeparated(); | |
| 4227 values->append(value.release()); | |
| 4228 } | |
| 4229 | |
| 4230 if (value2 && !values2) { | |
| 4231 values2 = CSSValueList::createCommaSeparated(); | |
| 4232 values2->append(value2.release()); | |
| 4233 } | |
| 4234 | |
| 4235 if (values) | |
| 4236 values->append(currValue.release()); | |
| 4237 else | |
| 4238 value = currValue.release(); | |
| 4239 if (currValue2) { | |
| 4240 if (values2) | |
| 4241 values2->append(currValue2.release()); | |
| 4242 else | |
| 4243 value2 = currValue2.release(); | |
| 4244 } | |
| 4245 } | |
| 4246 | |
| 4247 // When parsing any fill shorthand property, we let it handle building u
p the lists for all | |
| 4248 // properties. | |
| 4249 if (inShorthand()) | |
| 4250 break; | |
| 4251 } | |
| 4252 | |
| 4253 if (values && values->length()) { | |
| 4254 retValue1 = values.release(); | |
| 4255 if (values2 && values2->length()) | |
| 4256 retValue2 = values2.release(); | |
| 4257 return true; | |
| 4258 } | |
| 4259 if (value) { | |
| 4260 retValue1 = value.release(); | |
| 4261 retValue2 = value2.release(); | |
| 4262 return true; | |
| 4263 } | |
| 4264 return false; | |
| 4265 } | |
| 4266 | |
| 4267 PassRefPtr<CSSValue> CSSParser::parseAnimationDelay() | |
| 4268 { | |
| 4269 CSSParserValue* value = m_valueList->current(); | |
| 4270 if (validUnit(value, FTime)) | |
| 4271 return createPrimitiveNumericValue(value); | |
| 4272 return 0; | |
| 4273 } | |
| 4274 | |
| 4275 PassRefPtr<CSSValue> CSSParser::parseAnimationDirection() | |
| 4276 { | |
| 4277 CSSParserValue* value = m_valueList->current(); | |
| 4278 if (value->id == CSSValueNormal || value->id == CSSValueAlternate || value->
id == CSSValueReverse || value->id == CSSValueAlternateReverse) | |
| 4279 return cssValuePool().createIdentifierValue(value->id); | |
| 4280 return 0; | |
| 4281 } | |
| 4282 | |
| 4283 PassRefPtr<CSSValue> CSSParser::parseAnimationDuration() | |
| 4284 { | |
| 4285 CSSParserValue* value = m_valueList->current(); | |
| 4286 if (validUnit(value, FTime | FNonNeg)) | |
| 4287 return createPrimitiveNumericValue(value); | |
| 4288 return 0; | |
| 4289 } | |
| 4290 | |
| 4291 PassRefPtr<CSSValue> CSSParser::parseAnimationFillMode() | |
| 4292 { | |
| 4293 CSSParserValue* value = m_valueList->current(); | |
| 4294 if (value->id == CSSValueNone || value->id == CSSValueForwards || value->id
== CSSValueBackwards || value->id == CSSValueBoth) | |
| 4295 return cssValuePool().createIdentifierValue(value->id); | |
| 4296 return 0; | |
| 4297 } | |
| 4298 | |
| 4299 PassRefPtr<CSSValue> CSSParser::parseAnimationIterationCount() | |
| 4300 { | |
| 4301 CSSParserValue* value = m_valueList->current(); | |
| 4302 if (value->id == CSSValueInfinite) | |
| 4303 return cssValuePool().createIdentifierValue(value->id); | |
| 4304 if (validUnit(value, FNumber | FNonNeg)) | |
| 4305 return createPrimitiveNumericValue(value); | |
| 4306 return 0; | |
| 4307 } | |
| 4308 | |
| 4309 PassRefPtr<CSSValue> CSSParser::parseAnimationName() | |
| 4310 { | |
| 4311 CSSParserValue* value = m_valueList->current(); | |
| 4312 if (value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimit
iveValue::CSS_IDENT) { | |
| 4313 if (value->id == CSSValueNone || (value->unit == CSSPrimitiveValue::CSS_
STRING && equalIgnoringCase(value, "none"))) { | |
| 4314 return cssValuePool().createIdentifierValue(CSSValueNone); | |
| 4315 } else { | |
| 4316 return createPrimitiveStringValue(value); | |
| 4317 } | |
| 4318 } | |
| 4319 return 0; | |
| 4320 } | |
| 4321 | |
| 4322 PassRefPtr<CSSValue> CSSParser::parseAnimationPlayState() | |
| 4323 { | |
| 4324 CSSParserValue* value = m_valueList->current(); | |
| 4325 if (value->id == CSSValueRunning || value->id == CSSValuePaused) | |
| 4326 return cssValuePool().createIdentifierValue(value->id); | |
| 4327 return 0; | |
| 4328 } | |
| 4329 | |
| 4330 PassRefPtr<CSSValue> CSSParser::parseAnimationProperty(AnimationParseContext& co
ntext) | |
| 4331 { | |
| 4332 CSSParserValue* value = m_valueList->current(); | |
| 4333 if (value->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 4334 return 0; | |
| 4335 CSSPropertyID result = cssPropertyID(value->string); | |
| 4336 if (result) | |
| 4337 return cssValuePool().createIdentifierValue(result); | |
| 4338 if (equalIgnoringCase(value, "all")) { | |
| 4339 context.sawAnimationPropertyKeyword(); | |
| 4340 return cssValuePool().createIdentifierValue(CSSValueAll); | |
| 4341 } | |
| 4342 if (equalIgnoringCase(value, "none")) { | |
| 4343 context.commitAnimationPropertyKeyword(); | |
| 4344 context.sawAnimationPropertyKeyword(); | |
| 4345 return cssValuePool().createIdentifierValue(CSSValueNone); | |
| 4346 } | |
| 4347 return 0; | |
| 4348 } | |
| 4349 | |
| 4350 bool CSSParser::parseTransformOriginShorthand(RefPtr<CSSValue>& value1, RefPtr<C
SSValue>& value2, RefPtr<CSSValue>& value3) | |
| 4351 { | |
| 4352 parse2ValuesFillPosition(m_valueList.get(), value1, value2); | |
| 4353 | |
| 4354 // now get z | |
| 4355 if (m_valueList->current()) { | |
| 4356 if (validUnit(m_valueList->current(), FLength)) { | |
| 4357 value3 = createPrimitiveNumericValue(m_valueList->current()); | |
| 4358 m_valueList->next(); | |
| 4359 return true; | |
| 4360 } | |
| 4361 return false; | |
| 4362 } | |
| 4363 value3 = cssValuePool().createImplicitInitialValue(); | |
| 4364 return true; | |
| 4365 } | |
| 4366 | |
| 4367 bool CSSParser::parseCubicBezierTimingFunctionValue(CSSParserValueList*& args, d
ouble& result) | |
| 4368 { | |
| 4369 CSSParserValue* v = args->current(); | |
| 4370 if (!validUnit(v, FNumber)) | |
| 4371 return false; | |
| 4372 result = v->fValue; | |
| 4373 v = args->next(); | |
| 4374 if (!v) | |
| 4375 // The last number in the function has no comma after it, so we're done. | |
| 4376 return true; | |
| 4377 if (!isComma(v)) | |
| 4378 return false; | |
| 4379 args->next(); | |
| 4380 return true; | |
| 4381 } | |
| 4382 | |
| 4383 PassRefPtr<CSSValue> CSSParser::parseAnimationTimingFunction() | |
| 4384 { | |
| 4385 CSSParserValue* value = m_valueList->current(); | |
| 4386 if (value->id == CSSValueEase || value->id == CSSValueLinear || value->id ==
CSSValueEaseIn || value->id == CSSValueEaseOut | |
| 4387 || value->id == CSSValueEaseInOut || value->id == CSSValueStepStart || v
alue->id == CSSValueStepEnd) | |
| 4388 return cssValuePool().createIdentifierValue(value->id); | |
| 4389 | |
| 4390 // We must be a function. | |
| 4391 if (value->unit != CSSParserValue::Function) | |
| 4392 return 0; | |
| 4393 | |
| 4394 CSSParserValueList* args = value->function->args.get(); | |
| 4395 | |
| 4396 if (equalIgnoringCase(value->function->name, "steps(")) { | |
| 4397 // For steps, 1 or 2 params must be specified (comma-separated) | |
| 4398 if (!args || (args->size() != 1 && args->size() != 3)) | |
| 4399 return 0; | |
| 4400 | |
| 4401 // There are two values. | |
| 4402 int numSteps; | |
| 4403 bool stepAtStart = false; | |
| 4404 | |
| 4405 CSSParserValue* v = args->current(); | |
| 4406 if (!validUnit(v, FInteger)) | |
| 4407 return 0; | |
| 4408 numSteps = clampToInteger(v->fValue); | |
| 4409 if (numSteps < 1) | |
| 4410 return 0; | |
| 4411 v = args->next(); | |
| 4412 | |
| 4413 if (v) { | |
| 4414 // There is a comma so we need to parse the second value | |
| 4415 if (!isComma(v)) | |
| 4416 return 0; | |
| 4417 v = args->next(); | |
| 4418 if (v->id != CSSValueStart && v->id != CSSValueEnd) | |
| 4419 return 0; | |
| 4420 stepAtStart = v->id == CSSValueStart; | |
| 4421 } | |
| 4422 | |
| 4423 return CSSStepsTimingFunctionValue::create(numSteps, stepAtStart); | |
| 4424 } | |
| 4425 | |
| 4426 if (equalIgnoringCase(value->function->name, "cubic-bezier(")) { | |
| 4427 // For cubic bezier, 4 values must be specified. | |
| 4428 if (!args || args->size() != 7) | |
| 4429 return 0; | |
| 4430 | |
| 4431 // There are two points specified. The x values must be between 0 and 1
but the y values can exceed this range. | |
| 4432 double x1, y1, x2, y2; | |
| 4433 | |
| 4434 if (!parseCubicBezierTimingFunctionValue(args, x1)) | |
| 4435 return 0; | |
| 4436 if (x1 < 0 || x1 > 1) | |
| 4437 return 0; | |
| 4438 if (!parseCubicBezierTimingFunctionValue(args, y1)) | |
| 4439 return 0; | |
| 4440 if (!parseCubicBezierTimingFunctionValue(args, x2)) | |
| 4441 return 0; | |
| 4442 if (x2 < 0 || x2 > 1) | |
| 4443 return 0; | |
| 4444 if (!parseCubicBezierTimingFunctionValue(args, y2)) | |
| 4445 return 0; | |
| 4446 | |
| 4447 return CSSCubicBezierTimingFunctionValue::create(x1, y1, x2, y2); | |
| 4448 } | |
| 4449 | |
| 4450 return 0; | |
| 4451 } | |
| 4452 | |
| 4453 bool CSSParser::parseAnimationProperty(CSSPropertyID propId, RefPtr<CSSValue>& r
esult, AnimationParseContext& context) | |
| 4454 { | |
| 4455 RefPtr<CSSValueList> values; | |
| 4456 CSSParserValue* val; | |
| 4457 RefPtr<CSSValue> value; | |
| 4458 bool allowComma = false; | |
| 4459 | |
| 4460 result = 0; | |
| 4461 | |
| 4462 while ((val = m_valueList->current())) { | |
| 4463 RefPtr<CSSValue> currValue; | |
| 4464 if (allowComma) { | |
| 4465 if (!isComma(val)) | |
| 4466 return false; | |
| 4467 m_valueList->next(); | |
| 4468 allowComma = false; | |
| 4469 } | |
| 4470 else { | |
| 4471 switch (propId) { | |
| 4472 case CSSPropertyAnimationDelay: | |
| 4473 case CSSPropertyWebkitAnimationDelay: | |
| 4474 case CSSPropertyTransitionDelay: | |
| 4475 case CSSPropertyWebkitTransitionDelay: | |
| 4476 currValue = parseAnimationDelay(); | |
| 4477 if (currValue) | |
| 4478 m_valueList->next(); | |
| 4479 break; | |
| 4480 case CSSPropertyAnimationDirection: | |
| 4481 case CSSPropertyWebkitAnimationDirection: | |
| 4482 currValue = parseAnimationDirection(); | |
| 4483 if (currValue) | |
| 4484 m_valueList->next(); | |
| 4485 break; | |
| 4486 case CSSPropertyAnimationDuration: | |
| 4487 case CSSPropertyWebkitAnimationDuration: | |
| 4488 case CSSPropertyTransitionDuration: | |
| 4489 case CSSPropertyWebkitTransitionDuration: | |
| 4490 currValue = parseAnimationDuration(); | |
| 4491 if (currValue) | |
| 4492 m_valueList->next(); | |
| 4493 break; | |
| 4494 case CSSPropertyAnimationFillMode: | |
| 4495 case CSSPropertyWebkitAnimationFillMode: | |
| 4496 currValue = parseAnimationFillMode(); | |
| 4497 if (currValue) | |
| 4498 m_valueList->next(); | |
| 4499 break; | |
| 4500 case CSSPropertyAnimationIterationCount: | |
| 4501 case CSSPropertyWebkitAnimationIterationCount: | |
| 4502 currValue = parseAnimationIterationCount(); | |
| 4503 if (currValue) | |
| 4504 m_valueList->next(); | |
| 4505 break; | |
| 4506 case CSSPropertyAnimationName: | |
| 4507 case CSSPropertyWebkitAnimationName: | |
| 4508 currValue = parseAnimationName(); | |
| 4509 if (currValue) | |
| 4510 m_valueList->next(); | |
| 4511 break; | |
| 4512 case CSSPropertyAnimationPlayState: | |
| 4513 case CSSPropertyWebkitAnimationPlayState: | |
| 4514 currValue = parseAnimationPlayState(); | |
| 4515 if (currValue) | |
| 4516 m_valueList->next(); | |
| 4517 break; | |
| 4518 case CSSPropertyTransitionProperty: | |
| 4519 case CSSPropertyWebkitTransitionProperty: | |
| 4520 currValue = parseAnimationProperty(context); | |
| 4521 if (value && !context.animationPropertyKeywordAllowed()) | |
| 4522 return false; | |
| 4523 if (currValue) | |
| 4524 m_valueList->next(); | |
| 4525 break; | |
| 4526 case CSSPropertyAnimationTimingFunction: | |
| 4527 case CSSPropertyWebkitAnimationTimingFunction: | |
| 4528 case CSSPropertyTransitionTimingFunction: | |
| 4529 case CSSPropertyWebkitTransitionTimingFunction: | |
| 4530 currValue = parseAnimationTimingFunction(); | |
| 4531 if (currValue) | |
| 4532 m_valueList->next(); | |
| 4533 break; | |
| 4534 default: | |
| 4535 ASSERT_NOT_REACHED(); | |
| 4536 return false; | |
| 4537 } | |
| 4538 | |
| 4539 if (!currValue) | |
| 4540 return false; | |
| 4541 | |
| 4542 if (value && !values) { | |
| 4543 values = CSSValueList::createCommaSeparated(); | |
| 4544 values->append(value.release()); | |
| 4545 } | |
| 4546 | |
| 4547 if (values) | |
| 4548 values->append(currValue.release()); | |
| 4549 else | |
| 4550 value = currValue.release(); | |
| 4551 | |
| 4552 allowComma = true; | |
| 4553 } | |
| 4554 | |
| 4555 // When parsing the 'transition' shorthand property, we let it handle bu
ilding up the lists for all | |
| 4556 // properties. | |
| 4557 if (inShorthand()) | |
| 4558 break; | |
| 4559 } | |
| 4560 | |
| 4561 if (values && values->length()) { | |
| 4562 result = values.release(); | |
| 4563 return true; | |
| 4564 } | |
| 4565 if (value) { | |
| 4566 result = value.release(); | |
| 4567 return true; | |
| 4568 } | |
| 4569 return false; | |
| 4570 } | |
| 4571 | |
| 4572 // The function parses [ <integer> || <string> ] in <grid-line> (which can be st
and alone or with 'span'). | |
| 4573 bool CSSParser::parseIntegerOrStringFromGridPosition(RefPtr<CSSPrimitiveValue>&
numericValue, RefPtr<CSSPrimitiveValue>& gridLineName) | |
| 4574 { | |
| 4575 CSSParserValue* value = m_valueList->current(); | |
| 4576 if (validUnit(value, FInteger) && value->fValue) { | |
| 4577 numericValue = createPrimitiveNumericValue(value); | |
| 4578 value = m_valueList->next(); | |
| 4579 if (value && value->unit == CSSPrimitiveValue::CSS_STRING) { | |
| 4580 gridLineName = createPrimitiveStringValue(m_valueList->current()); | |
| 4581 m_valueList->next(); | |
| 4582 } | |
| 4583 return true; | |
| 4584 } | |
| 4585 | |
| 4586 if (value->unit == CSSPrimitiveValue::CSS_STRING) { | |
| 4587 gridLineName = createPrimitiveStringValue(m_valueList->current()); | |
| 4588 value = m_valueList->next(); | |
| 4589 if (value && validUnit(value, FInteger) && value->fValue) { | |
| 4590 numericValue = createPrimitiveNumericValue(value); | |
| 4591 m_valueList->next(); | |
| 4592 } | |
| 4593 return true; | |
| 4594 } | |
| 4595 | |
| 4596 return false; | |
| 4597 } | |
| 4598 | |
| 4599 PassRefPtr<CSSValue> CSSParser::parseGridPosition() | |
| 4600 { | |
| 4601 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | |
| 4602 | |
| 4603 CSSParserValue* value = m_valueList->current(); | |
| 4604 if (value->id == CSSValueAuto) { | |
| 4605 m_valueList->next(); | |
| 4606 return cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 4607 } | |
| 4608 | |
| 4609 if (value->id != CSSValueSpan && value->unit == CSSPrimitiveValue::CSS_IDENT
) { | |
| 4610 m_valueList->next(); | |
| 4611 return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_
STRING); | |
| 4612 } | |
| 4613 | |
| 4614 RefPtr<CSSPrimitiveValue> numericValue; | |
| 4615 RefPtr<CSSPrimitiveValue> gridLineName; | |
| 4616 bool hasSeenSpanKeyword = false; | |
| 4617 | |
| 4618 if (parseIntegerOrStringFromGridPosition(numericValue, gridLineName)) { | |
| 4619 value = m_valueList->current(); | |
| 4620 if (value && value->id == CSSValueSpan) { | |
| 4621 hasSeenSpanKeyword = true; | |
| 4622 m_valueList->next(); | |
| 4623 } | |
| 4624 } else if (value->id == CSSValueSpan) { | |
| 4625 hasSeenSpanKeyword = true; | |
| 4626 if (m_valueList->next()) | |
| 4627 parseIntegerOrStringFromGridPosition(numericValue, gridLineName); | |
| 4628 } | |
| 4629 | |
| 4630 // Check that we have consumed all the value list. For shorthands, the parse
r will pass | |
| 4631 // the whole value list (including the opposite position). | |
| 4632 if (m_valueList->current() && !isForwardSlashOperator(m_valueList->current()
)) | |
| 4633 return 0; | |
| 4634 | |
| 4635 // If we didn't parse anything, this is not a valid grid position. | |
| 4636 if (!hasSeenSpanKeyword && !gridLineName && !numericValue) | |
| 4637 return 0; | |
| 4638 | |
| 4639 // Negative numbers are not allowed for span (but are for <integer>). | |
| 4640 if (hasSeenSpanKeyword && numericValue && numericValue->getIntValue() < 0) | |
| 4641 return 0; | |
| 4642 | |
| 4643 RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated(); | |
| 4644 if (hasSeenSpanKeyword) | |
| 4645 values->append(cssValuePool().createIdentifierValue(CSSValueSpan)); | |
| 4646 if (numericValue) | |
| 4647 values->append(numericValue.release()); | |
| 4648 if (gridLineName) | |
| 4649 values->append(gridLineName.release()); | |
| 4650 ASSERT(values->length()); | |
| 4651 return values.release(); | |
| 4652 } | |
| 4653 | |
| 4654 static PassRefPtr<CSSValue> gridMissingGridPositionValue(CSSValue* value) | |
| 4655 { | |
| 4656 if (value->isPrimitiveValue() && toCSSPrimitiveValue(value)->isString()) | |
| 4657 return value; | |
| 4658 | |
| 4659 return cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 4660 } | |
| 4661 | |
| 4662 bool CSSParser::parseGridItemPositionShorthand(CSSPropertyID shorthandId, bool i
mportant) | |
| 4663 { | |
| 4664 ShorthandScope scope(this, shorthandId); | |
| 4665 const StylePropertyShorthand& shorthand = shorthandForProperty(shorthandId); | |
| 4666 ASSERT(shorthand.length() == 2); | |
| 4667 | |
| 4668 RefPtr<CSSValue> startValue = parseGridPosition(); | |
| 4669 if (!startValue) | |
| 4670 return false; | |
| 4671 | |
| 4672 RefPtr<CSSValue> endValue; | |
| 4673 if (m_valueList->current()) { | |
| 4674 if (!isForwardSlashOperator(m_valueList->current())) | |
| 4675 return false; | |
| 4676 | |
| 4677 if (!m_valueList->next()) | |
| 4678 return false; | |
| 4679 | |
| 4680 endValue = parseGridPosition(); | |
| 4681 if (!endValue || m_valueList->current()) | |
| 4682 return false; | |
| 4683 } else { | |
| 4684 endValue = gridMissingGridPositionValue(startValue.get()); | |
| 4685 } | |
| 4686 | |
| 4687 addProperty(shorthand.properties()[0], startValue, important); | |
| 4688 addProperty(shorthand.properties()[1], endValue, important); | |
| 4689 return true; | |
| 4690 } | |
| 4691 | |
| 4692 bool CSSParser::parseGridAreaShorthand(bool important) | |
| 4693 { | |
| 4694 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | |
| 4695 | |
| 4696 ShorthandScope scope(this, CSSPropertyGridArea); | |
| 4697 const StylePropertyShorthand& shorthand = gridAreaShorthand(); | |
| 4698 ASSERT_UNUSED(shorthand, shorthand.length() == 4); | |
| 4699 | |
| 4700 RefPtr<CSSValue> rowStartValue = parseGridPosition(); | |
| 4701 if (!rowStartValue) | |
| 4702 return false; | |
| 4703 | |
| 4704 RefPtr<CSSValue> columnStartValue; | |
| 4705 if (!parseSingleGridAreaLonghand(columnStartValue)) | |
| 4706 return false; | |
| 4707 | |
| 4708 RefPtr<CSSValue> rowEndValue; | |
| 4709 if (!parseSingleGridAreaLonghand(rowEndValue)) | |
| 4710 return false; | |
| 4711 | |
| 4712 RefPtr<CSSValue> columnEndValue; | |
| 4713 if (!parseSingleGridAreaLonghand(columnEndValue)) | |
| 4714 return false; | |
| 4715 | |
| 4716 if (!columnStartValue) | |
| 4717 columnStartValue = gridMissingGridPositionValue(rowStartValue.get()); | |
| 4718 | |
| 4719 if (!rowEndValue) | |
| 4720 rowEndValue = gridMissingGridPositionValue(rowStartValue.get()); | |
| 4721 | |
| 4722 if (!columnEndValue) | |
| 4723 columnEndValue = gridMissingGridPositionValue(columnStartValue.get()); | |
| 4724 | |
| 4725 addProperty(CSSPropertyGridRowStart, rowStartValue, important); | |
| 4726 addProperty(CSSPropertyGridColumnStart, columnStartValue, important); | |
| 4727 addProperty(CSSPropertyGridRowEnd, rowEndValue, important); | |
| 4728 addProperty(CSSPropertyGridColumnEnd, columnEndValue, important); | |
| 4729 return true; | |
| 4730 } | |
| 4731 | |
| 4732 bool CSSParser::parseSingleGridAreaLonghand(RefPtr<CSSValue>& property) | |
| 4733 { | |
| 4734 if (!m_valueList->current()) | |
| 4735 return true; | |
| 4736 | |
| 4737 if (!isForwardSlashOperator(m_valueList->current())) | |
| 4738 return false; | |
| 4739 | |
| 4740 if (!m_valueList->next()) | |
| 4741 return false; | |
| 4742 | |
| 4743 property = parseGridPosition(); | |
| 4744 return true; | |
| 4745 } | |
| 4746 | |
| 4747 void CSSParser::parseGridLineNames(CSSParserValueList* parserValueList, CSSValue
List& valueList) | |
| 4748 { | |
| 4749 ASSERT(parserValueList->current() && parserValueList->current()->unit == CSS
ParserValue::ValueList); | |
| 4750 | |
| 4751 CSSParserValueList* identList = parserValueList->current()->valueList; | |
| 4752 if (!identList->size()) { | |
| 4753 parserValueList->next(); | |
| 4754 return; | |
| 4755 } | |
| 4756 | |
| 4757 RefPtr<CSSGridLineNamesValue> lineNames = CSSGridLineNamesValue::create(); | |
| 4758 while (CSSParserValue* identValue = identList->current()) { | |
| 4759 ASSERT(identValue->unit == CSSPrimitiveValue::CSS_IDENT); | |
| 4760 RefPtr<CSSPrimitiveValue> lineName = createPrimitiveStringValue(identVal
ue); | |
| 4761 lineNames->append(lineName.release()); | |
| 4762 identList->next(); | |
| 4763 } | |
| 4764 valueList.append(lineNames.release()); | |
| 4765 | |
| 4766 parserValueList->next(); | |
| 4767 } | |
| 4768 | |
| 4769 bool CSSParser::parseGridTrackList(CSSPropertyID propId, bool important) | |
| 4770 { | |
| 4771 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | |
| 4772 | |
| 4773 CSSParserValue* value = m_valueList->current(); | |
| 4774 if (value->id == CSSValueNone) { | |
| 4775 if (m_valueList->next()) | |
| 4776 return false; | |
| 4777 | |
| 4778 addProperty(propId, cssValuePool().createIdentifierValue(value->id), imp
ortant); | |
| 4779 return true; | |
| 4780 } | |
| 4781 | |
| 4782 RefPtr<CSSValueList> values = CSSValueList::createSpaceSeparated(); | |
| 4783 // Handle leading <ident>*. | |
| 4784 value = m_valueList->current(); | |
| 4785 if (value && value->unit == CSSParserValue::ValueList) | |
| 4786 parseGridLineNames(m_valueList.get(), *values); | |
| 4787 | |
| 4788 bool seenTrackSizeOrRepeatFunction = false; | |
| 4789 while (CSSParserValue* currentValue = m_valueList->current()) { | |
| 4790 if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase(
currentValue->function->name, "repeat(")) { | |
| 4791 if (!parseGridTrackRepeatFunction(*values)) | |
| 4792 return false; | |
| 4793 seenTrackSizeOrRepeatFunction = true; | |
| 4794 } else { | |
| 4795 RefPtr<CSSValue> value = parseGridTrackSize(*m_valueList); | |
| 4796 if (!value) | |
| 4797 return false; | |
| 4798 values->append(value); | |
| 4799 seenTrackSizeOrRepeatFunction = true; | |
| 4800 } | |
| 4801 // This will handle the trailing <ident>* in the grammar. | |
| 4802 value = m_valueList->current(); | |
| 4803 if (value && value->unit == CSSParserValue::ValueList) | |
| 4804 parseGridLineNames(m_valueList.get(), *values); | |
| 4805 } | |
| 4806 | |
| 4807 // We should have found a <track-size> or else it is not a valid <track-list
> | |
| 4808 if (!seenTrackSizeOrRepeatFunction) | |
| 4809 return false; | |
| 4810 | |
| 4811 addProperty(propId, values.release(), important); | |
| 4812 return true; | |
| 4813 } | |
| 4814 | |
| 4815 bool CSSParser::parseGridTrackRepeatFunction(CSSValueList& list) | |
| 4816 { | |
| 4817 CSSParserValueList* arguments = m_valueList->current()->function->args.get()
; | |
| 4818 if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0),
FPositiveInteger) || !isComma(arguments->valueAt(1))) | |
| 4819 return false; | |
| 4820 | |
| 4821 ASSERT_WITH_SECURITY_IMPLICATION(arguments->valueAt(0)->fValue > 0); | |
| 4822 size_t repetitions = arguments->valueAt(0)->fValue; | |
| 4823 RefPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceSeparated(); | |
| 4824 arguments->next(); // Skip the repetition count. | |
| 4825 arguments->next(); // Skip the comma. | |
| 4826 | |
| 4827 // Handle leading <ident>*. | |
| 4828 CSSParserValue* currentValue = arguments->current(); | |
| 4829 if (currentValue && currentValue->unit == CSSParserValue::ValueList) | |
| 4830 parseGridLineNames(arguments, *repeatedValues); | |
| 4831 | |
| 4832 while (arguments->current()) { | |
| 4833 RefPtr<CSSValue> trackSize = parseGridTrackSize(*arguments); | |
| 4834 if (!trackSize) | |
| 4835 return false; | |
| 4836 | |
| 4837 repeatedValues->append(trackSize); | |
| 4838 | |
| 4839 // This takes care of any trailing <ident>* in the grammar. | |
| 4840 currentValue = arguments->current(); | |
| 4841 if (currentValue && currentValue->unit == CSSParserValue::ValueList) | |
| 4842 parseGridLineNames(arguments, *repeatedValues); | |
| 4843 } | |
| 4844 | |
| 4845 for (size_t i = 0; i < repetitions; ++i) { | |
| 4846 for (size_t j = 0; j < repeatedValues->length(); ++j) | |
| 4847 list.append(repeatedValues->itemWithoutBoundsCheck(j)); | |
| 4848 } | |
| 4849 | |
| 4850 // parseGridTrackSize iterated over the repeat arguments, move to the next v
alue. | |
| 4851 m_valueList->next(); | |
| 4852 return true; | |
| 4853 } | |
| 4854 | |
| 4855 PassRefPtr<CSSValue> CSSParser::parseGridTrackSize(CSSParserValueList& inputList
) | |
| 4856 { | |
| 4857 ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled()); | |
| 4858 | |
| 4859 CSSParserValue* currentValue = inputList.current(); | |
| 4860 inputList.next(); | |
| 4861 | |
| 4862 if (currentValue->id == CSSValueAuto) | |
| 4863 return cssValuePool().createIdentifierValue(CSSValueAuto); | |
| 4864 | |
| 4865 if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase(curr
entValue->function->name, "minmax(")) { | |
| 4866 // The spec defines the following grammar: minmax( <track-breadth> , <tr
ack-breadth> ) | |
| 4867 CSSParserValueList* arguments = currentValue->function->args.get(); | |
| 4868 if (!arguments || arguments->size() != 3 || !isComma(arguments->valueAt(
1))) | |
| 4869 return 0; | |
| 4870 | |
| 4871 RefPtr<CSSPrimitiveValue> minTrackBreadth = parseGridBreadth(arguments->
valueAt(0)); | |
| 4872 if (!minTrackBreadth) | |
| 4873 return 0; | |
| 4874 | |
| 4875 RefPtr<CSSPrimitiveValue> maxTrackBreadth = parseGridBreadth(arguments->
valueAt(2)); | |
| 4876 if (!maxTrackBreadth) | |
| 4877 return 0; | |
| 4878 | |
| 4879 RefPtr<CSSValueList> parsedArguments = CSSValueList::createCommaSeparate
d(); | |
| 4880 parsedArguments->append(minTrackBreadth); | |
| 4881 parsedArguments->append(maxTrackBreadth); | |
| 4882 return CSSFunctionValue::create("minmax(", parsedArguments); | |
| 4883 } | |
| 4884 | |
| 4885 return parseGridBreadth(currentValue); | |
| 4886 } | |
| 4887 | |
| 4888 PassRefPtr<CSSPrimitiveValue> CSSParser::parseGridBreadth(CSSParserValue* curren
tValue) | |
| 4889 { | |
| 4890 if (currentValue->id == CSSValueMinContent || currentValue->id == CSSValueMa
xContent) | |
| 4891 return cssValuePool().createIdentifierValue(currentValue->id); | |
| 4892 | |
| 4893 if (currentValue->unit == CSSPrimitiveValue::CSS_FR) { | |
| 4894 double flexValue = currentValue->fValue; | |
| 4895 | |
| 4896 // Fractional unit is a non-negative dimension. | |
| 4897 if (flexValue <= 0) | |
| 4898 return 0; | |
| 4899 | |
| 4900 return cssValuePool().createValue(flexValue, CSSPrimitiveValue::CSS_FR); | |
| 4901 } | |
| 4902 | |
| 4903 if (!validUnit(currentValue, FNonNeg | FLength | FPercent)) | |
| 4904 return 0; | |
| 4905 | |
| 4906 return createPrimitiveNumericValue(currentValue); | |
| 4907 } | |
| 4908 | |
| 4909 PassRefPtr<CSSValue> CSSParser::parseGridTemplate() | |
| 4910 { | |
| 4911 NamedGridAreaMap gridAreaMap; | |
| 4912 size_t rowCount = 0; | |
| 4913 size_t columnCount = 0; | |
| 4914 | |
| 4915 while (CSSParserValue* currentValue = m_valueList->current()) { | |
| 4916 if (currentValue->unit != CSSPrimitiveValue::CSS_STRING) | |
| 4917 return 0; | |
| 4918 | |
| 4919 String gridRowNames = currentValue->string; | |
| 4920 if (!gridRowNames.length()) | |
| 4921 return 0; | |
| 4922 | |
| 4923 Vector<String> columnNames; | |
| 4924 gridRowNames.split(' ', columnNames); | |
| 4925 | |
| 4926 if (!columnCount) { | |
| 4927 columnCount = columnNames.size(); | |
| 4928 ASSERT(columnCount); | |
| 4929 } else if (columnCount != columnNames.size()) { | |
| 4930 // The declaration is invalid is all the rows don't have the number
of columns. | |
| 4931 return 0; | |
| 4932 } | |
| 4933 | |
| 4934 for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) { | |
| 4935 const String& gridAreaName = columnNames[currentCol]; | |
| 4936 | |
| 4937 // Unamed areas are always valid (we consider them to be 1x1). | |
| 4938 if (gridAreaName == ".") | |
| 4939 continue; | |
| 4940 | |
| 4941 // We handle several grid areas with the same name at once to simpli
fy the validation code. | |
| 4942 size_t lookAheadCol; | |
| 4943 for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++
lookAheadCol) { | |
| 4944 if (columnNames[lookAheadCol + 1] != gridAreaName) | |
| 4945 break; | |
| 4946 } | |
| 4947 | |
| 4948 NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaNam
e); | |
| 4949 if (gridAreaIt == gridAreaMap.end()) { | |
| 4950 gridAreaMap.add(gridAreaName, GridCoordinate(GridSpan(rowCount,
rowCount), GridSpan(currentCol, lookAheadCol))); | |
| 4951 } else { | |
| 4952 GridCoordinate& gridCoordinate = gridAreaIt->value; | |
| 4953 | |
| 4954 // The following checks test that the grid area is a single fill
ed-in rectangle. | |
| 4955 // 1. The new row is adjacent to the previously parsed row. | |
| 4956 if (rowCount != gridCoordinate.rows.initialPositionIndex + 1) | |
| 4957 return 0; | |
| 4958 | |
| 4959 // 2. The new area starts at the same position as the previously
parsed area. | |
| 4960 if (currentCol != gridCoordinate.columns.initialPositionIndex) | |
| 4961 return 0; | |
| 4962 | |
| 4963 // 3. The new area ends at the same position as the previously p
arsed area. | |
| 4964 if (lookAheadCol != gridCoordinate.columns.finalPositionIndex) | |
| 4965 return 0; | |
| 4966 | |
| 4967 ++gridCoordinate.rows.finalPositionIndex; | |
| 4968 } | |
| 4969 currentCol = lookAheadCol; | |
| 4970 } | |
| 4971 | |
| 4972 ++rowCount; | |
| 4973 m_valueList->next(); | |
| 4974 } | |
| 4975 | |
| 4976 if (!rowCount || !columnCount) | |
| 4977 return 0; | |
| 4978 | |
| 4979 return CSSGridTemplateValue::create(gridAreaMap, rowCount, columnCount); | |
| 4980 } | |
| 4981 | |
| 4982 PassRefPtr<CSSValue> CSSParser::parseCounterContent(CSSParserValueList* args, bo
ol counters) | |
| 4983 { | |
| 4984 unsigned numArgs = args->size(); | |
| 4985 if (counters && numArgs != 3 && numArgs != 5) | |
| 4986 return 0; | |
| 4987 if (!counters && numArgs != 1 && numArgs != 3) | |
| 4988 return 0; | |
| 4989 | |
| 4990 CSSParserValue* i = args->current(); | |
| 4991 if (i->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 4992 return 0; | |
| 4993 RefPtr<CSSPrimitiveValue> identifier = createPrimitiveStringValue(i); | |
| 4994 | |
| 4995 RefPtr<CSSPrimitiveValue> separator; | |
| 4996 if (!counters) | |
| 4997 separator = cssValuePool().createValue(String(), CSSPrimitiveValue::CSS_
STRING); | |
| 4998 else { | |
| 4999 i = args->next(); | |
| 5000 if (i->unit != CSSParserValue::Operator || i->iValue != ',') | |
| 5001 return 0; | |
| 5002 | |
| 5003 i = args->next(); | |
| 5004 if (i->unit != CSSPrimitiveValue::CSS_STRING) | |
| 5005 return 0; | |
| 5006 | |
| 5007 separator = createPrimitiveStringValue(i); | |
| 5008 } | |
| 5009 | |
| 5010 RefPtr<CSSPrimitiveValue> listStyle; | |
| 5011 i = args->next(); | |
| 5012 if (!i) // Make the list style default decimal | |
| 5013 listStyle = cssValuePool().createIdentifierValue(CSSValueDecimal); | |
| 5014 else { | |
| 5015 if (i->unit != CSSParserValue::Operator || i->iValue != ',') | |
| 5016 return 0; | |
| 5017 | |
| 5018 i = args->next(); | |
| 5019 if (i->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 5020 return 0; | |
| 5021 | |
| 5022 CSSValueID listStyleID = CSSValueInvalid; | |
| 5023 if (i->id == CSSValueNone || (i->id >= CSSValueDisc && i->id <= CSSValue
KatakanaIroha)) | |
| 5024 listStyleID = i->id; | |
| 5025 else | |
| 5026 return 0; | |
| 5027 | |
| 5028 listStyle = cssValuePool().createIdentifierValue(listStyleID); | |
| 5029 } | |
| 5030 | |
| 5031 return cssValuePool().createValue(Counter::create(identifier.release(), list
Style.release(), separator.release())); | |
| 5032 } | |
| 5033 | |
| 5034 bool CSSParser::parseClipShape(CSSPropertyID propId, bool important) | |
| 5035 { | |
| 5036 CSSParserValue* value = m_valueList->current(); | |
| 5037 CSSParserValueList* args = value->function->args.get(); | |
| 5038 | |
| 5039 if (!equalIgnoringCase(value->function->name, "rect(") || !args) | |
| 5040 return false; | |
| 5041 | |
| 5042 // rect(t, r, b, l) || rect(t r b l) | |
| 5043 if (args->size() != 4 && args->size() != 7) | |
| 5044 return false; | |
| 5045 RefPtr<Rect> rect = Rect::create(); | |
| 5046 bool valid = true; | |
| 5047 int i = 0; | |
| 5048 CSSParserValue* a = args->current(); | |
| 5049 while (a) { | |
| 5050 valid = a->id == CSSValueAuto || validUnit(a, FLength); | |
| 5051 if (!valid) | |
| 5052 break; | |
| 5053 RefPtr<CSSPrimitiveValue> length = a->id == CSSValueAuto ? | |
| 5054 cssValuePool().createIdentifierValue(CSSValueAuto) : | |
| 5055 createPrimitiveNumericValue(a); | |
| 5056 if (i == 0) | |
| 5057 rect->setTop(length); | |
| 5058 else if (i == 1) | |
| 5059 rect->setRight(length); | |
| 5060 else if (i == 2) | |
| 5061 rect->setBottom(length); | |
| 5062 else | |
| 5063 rect->setLeft(length); | |
| 5064 a = args->next(); | |
| 5065 if (a && args->size() == 7) { | |
| 5066 if (a->unit == CSSParserValue::Operator && a->iValue == ',') { | |
| 5067 a = args->next(); | |
| 5068 } else { | |
| 5069 valid = false; | |
| 5070 break; | |
| 5071 } | |
| 5072 } | |
| 5073 i++; | |
| 5074 } | |
| 5075 if (valid) { | |
| 5076 addProperty(propId, cssValuePool().createValue(rect.release()), importan
t); | |
| 5077 m_valueList->next(); | |
| 5078 return true; | |
| 5079 } | |
| 5080 return false; | |
| 5081 } | |
| 5082 | |
| 5083 PassRefPtr<CSSBasicShape> CSSParser::parseBasicShapeRectangle(CSSParserValueList
* args) | |
| 5084 { | |
| 5085 ASSERT(args); | |
| 5086 | |
| 5087 // rect(x, y, width, height, [[rx], ry]) | |
| 5088 if (args->size() != 7 && args->size() != 9 && args->size() != 11) | |
| 5089 return 0; | |
| 5090 | |
| 5091 RefPtr<CSSBasicShapeRectangle> shape = CSSBasicShapeRectangle::create(); | |
| 5092 | |
| 5093 unsigned argumentNumber = 0; | |
| 5094 CSSParserValue* argument = args->current(); | |
| 5095 while (argument) { | |
| 5096 Units unitFlags = FLength | FPercent; | |
| 5097 if (argumentNumber > 1) { | |
| 5098 // Arguments width, height, rx, and ry cannot be negative. | |
| 5099 unitFlags = unitFlags | FNonNeg; | |
| 5100 } | |
| 5101 if (!validUnit(argument, unitFlags)) | |
| 5102 return 0; | |
| 5103 | |
| 5104 RefPtr<CSSPrimitiveValue> length = createPrimitiveNumericValue(argument)
; | |
| 5105 ASSERT(argumentNumber < 6); | |
| 5106 switch (argumentNumber) { | |
| 5107 case 0: | |
| 5108 shape->setX(length); | |
| 5109 break; | |
| 5110 case 1: | |
| 5111 shape->setY(length); | |
| 5112 break; | |
| 5113 case 2: | |
| 5114 shape->setWidth(length); | |
| 5115 break; | |
| 5116 case 3: | |
| 5117 shape->setHeight(length); | |
| 5118 break; | |
| 5119 case 4: | |
| 5120 shape->setRadiusX(length); | |
| 5121 break; | |
| 5122 case 5: | |
| 5123 shape->setRadiusY(length); | |
| 5124 break; | |
| 5125 } | |
| 5126 argument = args->next(); | |
| 5127 if (argument) { | |
| 5128 if (!isComma(argument)) | |
| 5129 return 0; | |
| 5130 | |
| 5131 argument = args->next(); | |
| 5132 } | |
| 5133 argumentNumber++; | |
| 5134 } | |
| 5135 | |
| 5136 if (argumentNumber < 4) | |
| 5137 return 0; | |
| 5138 return shape; | |
| 5139 } | |
| 5140 | |
| 5141 PassRefPtr<CSSBasicShape> CSSParser::parseBasicShapeInsetRectangle(CSSParserValu
eList* args) | |
| 5142 { | |
| 5143 ASSERT(args); | |
| 5144 | |
| 5145 // inset-rectangle(top, right, bottom, left, [[rx], ry]) | |
| 5146 if (args->size() != 7 && args->size() != 9 && args->size() != 11) | |
| 5147 return 0; | |
| 5148 | |
| 5149 RefPtr<CSSBasicShapeInsetRectangle> shape = CSSBasicShapeInsetRectangle::cre
ate(); | |
| 5150 | |
| 5151 unsigned argumentNumber = 0; | |
| 5152 CSSParserValue* argument = args->current(); | |
| 5153 while (argument) { | |
| 5154 Units unitFlags = FLength | FPercent | FNonNeg; | |
| 5155 if (!validUnit(argument, unitFlags)) | |
| 5156 return 0; | |
| 5157 | |
| 5158 RefPtr<CSSPrimitiveValue> length = createPrimitiveNumericValue(argument)
; | |
| 5159 ASSERT(argumentNumber < 6); | |
| 5160 switch (argumentNumber) { | |
| 5161 case 0: | |
| 5162 shape->setTop(length); | |
| 5163 break; | |
| 5164 case 1: | |
| 5165 shape->setRight(length); | |
| 5166 break; | |
| 5167 case 2: | |
| 5168 shape->setBottom(length); | |
| 5169 break; | |
| 5170 case 3: | |
| 5171 shape->setLeft(length); | |
| 5172 break; | |
| 5173 case 4: | |
| 5174 shape->setRadiusX(length); | |
| 5175 break; | |
| 5176 case 5: | |
| 5177 shape->setRadiusY(length); | |
| 5178 break; | |
| 5179 } | |
| 5180 argument = args->next(); | |
| 5181 if (argument) { | |
| 5182 if (!isComma(argument)) | |
| 5183 return 0; | |
| 5184 | |
| 5185 argument = args->next(); | |
| 5186 } | |
| 5187 argumentNumber++; | |
| 5188 } | |
| 5189 | |
| 5190 if (argumentNumber < 4) | |
| 5191 return 0; | |
| 5192 return shape; | |
| 5193 } | |
| 5194 | |
| 5195 PassRefPtr<CSSPrimitiveValue> CSSParser::parseShapeRadius(CSSParserValue* value) | |
| 5196 { | |
| 5197 if (value->id == CSSValueClosestSide || value->id == CSSValueFarthestSide) | |
| 5198 return cssValuePool().createIdentifierValue(value->id); | |
| 5199 | |
| 5200 if (!validUnit(value, FLength | FPercent | FNonNeg)) | |
| 5201 return 0; | |
| 5202 | |
| 5203 return createPrimitiveNumericValue(value); | |
| 5204 } | |
| 5205 | |
| 5206 PassRefPtr<CSSBasicShape> CSSParser::parseBasicShapeCircle(CSSParserValueList* a
rgs) | |
| 5207 { | |
| 5208 ASSERT(args); | |
| 5209 | |
| 5210 // circle(radius) | |
| 5211 // circle(radius at <position> | |
| 5212 // circle(at <position>) | |
| 5213 // where position defines centerX and centerY using a CSS <position> data ty
pe. | |
| 5214 RefPtr<CSSBasicShapeCircle> shape = CSSBasicShapeCircle::create(); | |
| 5215 | |
| 5216 for (CSSParserValue* argument = args->current(); argument; argument = args->
next()) { | |
| 5217 // The call to parseFillPosition below should consume all of the | |
| 5218 // arguments except the first two. Thus, and index greater than one | |
| 5219 // indicates an invalid production. | |
| 5220 if (args->currentIndex() > 1) | |
| 5221 return 0; | |
| 5222 | |
| 5223 if (!args->currentIndex() && argument->id != CSSValueAt) { | |
| 5224 if (RefPtr<CSSPrimitiveValue> radius = parseShapeRadius(argument)) { | |
| 5225 shape->setRadius(radius); | |
| 5226 continue; | |
| 5227 } | |
| 5228 | |
| 5229 return 0; | |
| 5230 } | |
| 5231 | |
| 5232 if (argument->id == CSSValueAt) { | |
| 5233 RefPtr<CSSValue> centerX; | |
| 5234 RefPtr<CSSValue> centerY; | |
| 5235 args->next(); // set list to start of position center | |
| 5236 parseFillPosition(args, centerX, centerY); | |
| 5237 if (centerX && centerY) { | |
| 5238 ASSERT(centerX->isPrimitiveValue()); | |
| 5239 ASSERT(centerY->isPrimitiveValue()); | |
| 5240 shape->setCenterX(toCSSPrimitiveValue(centerX.get())); | |
| 5241 shape->setCenterY(toCSSPrimitiveValue(centerY.get())); | |
| 5242 } else { | |
| 5243 return 0; | |
| 5244 } | |
| 5245 } else { | |
| 5246 return 0; | |
| 5247 } | |
| 5248 } | |
| 5249 | |
| 5250 return shape; | |
| 5251 } | |
| 5252 | |
| 5253 PassRefPtr<CSSBasicShape> CSSParser::parseDeprecatedBasicShapeCircle(CSSParserVa
lueList* args) | |
| 5254 { | |
| 5255 ASSERT(args); | |
| 5256 | |
| 5257 // circle(centerX, centerY, radius) | |
| 5258 if (args->size() != 5) | |
| 5259 return 0; | |
| 5260 | |
| 5261 RefPtr<CSSDeprecatedBasicShapeCircle> shape = CSSDeprecatedBasicShapeCircle:
:create(); | |
| 5262 | |
| 5263 unsigned argumentNumber = 0; | |
| 5264 CSSParserValue* argument = args->current(); | |
| 5265 while (argument) { | |
| 5266 Units unitFlags = FLength | FPercent; | |
| 5267 if (argumentNumber == 2) { | |
| 5268 // Argument radius cannot be negative. | |
| 5269 unitFlags = unitFlags | FNonNeg; | |
| 5270 } | |
| 5271 | |
| 5272 if (!validUnit(argument, unitFlags)) | |
| 5273 return 0; | |
| 5274 | |
| 5275 RefPtr<CSSPrimitiveValue> length = createPrimitiveNumericValue(argument)
; | |
| 5276 ASSERT(argumentNumber < 3); | |
| 5277 switch (argumentNumber) { | |
| 5278 case 0: | |
| 5279 shape->setCenterX(length); | |
| 5280 break; | |
| 5281 case 1: | |
| 5282 shape->setCenterY(length); | |
| 5283 break; | |
| 5284 case 2: | |
| 5285 shape->setRadius(length); | |
| 5286 break; | |
| 5287 } | |
| 5288 | |
| 5289 argument = args->next(); | |
| 5290 if (argument) { | |
| 5291 if (!isComma(argument)) | |
| 5292 return 0; | |
| 5293 argument = args->next(); | |
| 5294 } | |
| 5295 argumentNumber++; | |
| 5296 } | |
| 5297 | |
| 5298 if (argumentNumber < 3) | |
| 5299 return 0; | |
| 5300 return shape; | |
| 5301 } | |
| 5302 | |
| 5303 PassRefPtr<CSSBasicShape> CSSParser::parseBasicShapeEllipse(CSSParserValueList*
args) | |
| 5304 { | |
| 5305 ASSERT(args); | |
| 5306 | |
| 5307 // ellipse(centerX, centerY, radiusX, radiusY) | |
| 5308 if (args->size() != 7) | |
| 5309 return 0; | |
| 5310 | |
| 5311 RefPtr<CSSBasicShapeEllipse> shape = CSSBasicShapeEllipse::create(); | |
| 5312 unsigned argumentNumber = 0; | |
| 5313 CSSParserValue* argument = args->current(); | |
| 5314 while (argument) { | |
| 5315 Units unitFlags = FLength | FPercent; | |
| 5316 if (argumentNumber > 1) { | |
| 5317 // Arguments radiusX and radiusY cannot be negative. | |
| 5318 unitFlags = unitFlags | FNonNeg; | |
| 5319 } | |
| 5320 if (!validUnit(argument, unitFlags)) | |
| 5321 return 0; | |
| 5322 | |
| 5323 RefPtr<CSSPrimitiveValue> length = createPrimitiveNumericValue(argument)
; | |
| 5324 ASSERT(argumentNumber < 4); | |
| 5325 switch (argumentNumber) { | |
| 5326 case 0: | |
| 5327 shape->setCenterX(length); | |
| 5328 break; | |
| 5329 case 1: | |
| 5330 shape->setCenterY(length); | |
| 5331 break; | |
| 5332 case 2: | |
| 5333 shape->setRadiusX(length); | |
| 5334 break; | |
| 5335 case 3: | |
| 5336 shape->setRadiusY(length); | |
| 5337 break; | |
| 5338 } | |
| 5339 | |
| 5340 argument = args->next(); | |
| 5341 if (argument) { | |
| 5342 if (!isComma(argument)) | |
| 5343 return 0; | |
| 5344 argument = args->next(); | |
| 5345 } | |
| 5346 argumentNumber++; | |
| 5347 } | |
| 5348 | |
| 5349 if (argumentNumber < 4) | |
| 5350 return 0; | |
| 5351 return shape; | |
| 5352 } | |
| 5353 | |
| 5354 PassRefPtr<CSSBasicShape> CSSParser::parseBasicShapePolygon(CSSParserValueList*
args) | |
| 5355 { | |
| 5356 ASSERT(args); | |
| 5357 | |
| 5358 unsigned size = args->size(); | |
| 5359 if (!size) | |
| 5360 return 0; | |
| 5361 | |
| 5362 RefPtr<CSSBasicShapePolygon> shape = CSSBasicShapePolygon::create(); | |
| 5363 | |
| 5364 CSSParserValue* argument = args->current(); | |
| 5365 if (argument->id == CSSValueEvenodd || argument->id == CSSValueNonzero) { | |
| 5366 shape->setWindRule(argument->id == CSSValueEvenodd ? RULE_EVENODD : RULE
_NONZERO); | |
| 5367 | |
| 5368 if (!isComma(args->next())) | |
| 5369 return 0; | |
| 5370 | |
| 5371 argument = args->next(); | |
| 5372 size -= 2; | |
| 5373 } | |
| 5374 | |
| 5375 // <length> <length>, ... <length> <length> -> each pair has 3 elements exce
pt the last one | |
| 5376 if (!size || (size % 3) - 2) | |
| 5377 return 0; | |
| 5378 | |
| 5379 CSSParserValue* argumentX = argument; | |
| 5380 while (argumentX) { | |
| 5381 if (!validUnit(argumentX, FLength | FPercent)) | |
| 5382 return 0; | |
| 5383 | |
| 5384 CSSParserValue* argumentY = args->next(); | |
| 5385 if (!argumentY || !validUnit(argumentY, FLength | FPercent)) | |
| 5386 return 0; | |
| 5387 | |
| 5388 RefPtr<CSSPrimitiveValue> xLength = createPrimitiveNumericValue(argument
X); | |
| 5389 RefPtr<CSSPrimitiveValue> yLength = createPrimitiveNumericValue(argument
Y); | |
| 5390 | |
| 5391 shape->appendPoint(xLength.release(), yLength.release()); | |
| 5392 | |
| 5393 CSSParserValue* commaOrNull = args->next(); | |
| 5394 if (!commaOrNull) | |
| 5395 argumentX = 0; | |
| 5396 else if (!isComma(commaOrNull)) | |
| 5397 return 0; | |
| 5398 else | |
| 5399 argumentX = args->next(); | |
| 5400 } | |
| 5401 | |
| 5402 return shape; | |
| 5403 } | |
| 5404 | |
| 5405 static bool isBoxValue(CSSValueID valueId) | |
| 5406 { | |
| 5407 switch (valueId) { | |
| 5408 case CSSValueContentBox: | |
| 5409 case CSSValuePaddingBox: | |
| 5410 case CSSValueBorderBox: | |
| 5411 case CSSValueMarginBox: | |
| 5412 return true; | |
| 5413 default: | |
| 5414 break; | |
| 5415 } | |
| 5416 | |
| 5417 return false; | |
| 5418 } | |
| 5419 | |
| 5420 // FIXME This function is temporary to allow for an orderly transition between | |
| 5421 // the new CSS Shapes circle and ellipse syntax. It will be removed when the | |
| 5422 // old syntax is removed. | |
| 5423 static bool isDeprecatedBasicShape(CSSParserValueList* args) | |
| 5424 { | |
| 5425 for (unsigned i = args->currentIndex(); i < args->size(); ++i) { | |
| 5426 CSSParserValue* value = args->valueAt(i); | |
| 5427 if (isComma(value)) | |
| 5428 return true; | |
| 5429 } | |
| 5430 | |
| 5431 return false; | |
| 5432 } | |
| 5433 | |
| 5434 PassRefPtr<CSSValue> CSSParser::parseShapeProperty(CSSPropertyID propId) | |
| 5435 { | |
| 5436 if (!RuntimeEnabledFeatures::cssShapesEnabled()) | |
| 5437 return 0; | |
| 5438 | |
| 5439 CSSParserValue* value = m_valueList->current(); | |
| 5440 CSSValueID valueId = value->id; | |
| 5441 RefPtr<CSSPrimitiveValue> boxValue; | |
| 5442 RefPtr<CSSPrimitiveValue> shapeValue; | |
| 5443 | |
| 5444 if (valueId == CSSValueAuto | |
| 5445 || (valueId == CSSValueOutsideShape && propId == CSSPropertyShapeInside)
) { | |
| 5446 RefPtr<CSSPrimitiveValue> keywordValue = parseValidPrimitive(valueId, va
lue); | |
| 5447 m_valueList->next(); | |
| 5448 return keywordValue.release(); | |
| 5449 } | |
| 5450 | |
| 5451 if (value->unit == CSSPrimitiveValue::CSS_URI) { | |
| 5452 RefPtr<CSSImageValue> imageValue = CSSImageValue::create(completeURL(val
ue->string)); | |
| 5453 m_valueList->next(); | |
| 5454 return imageValue.release(); | |
| 5455 } | |
| 5456 | |
| 5457 if (value->unit == CSSParserValue::Function) { | |
| 5458 shapeValue = parseBasicShape(); | |
| 5459 if (!shapeValue) | |
| 5460 return 0; | |
| 5461 } else if (isBoxValue(valueId)) { | |
| 5462 boxValue = parseValidPrimitive(valueId, value); | |
| 5463 m_valueList->next(); | |
| 5464 } else { | |
| 5465 return 0; | |
| 5466 } | |
| 5467 | |
| 5468 ASSERT(shapeValue || boxValue); | |
| 5469 value = m_valueList->current(); | |
| 5470 | |
| 5471 if (value) { | |
| 5472 valueId = value->id; | |
| 5473 if (boxValue && value->unit == CSSParserValue::Function) { | |
| 5474 shapeValue = parseBasicShape(); | |
| 5475 if (!shapeValue) | |
| 5476 return 0; | |
| 5477 } else if (shapeValue && isBoxValue(valueId)) { | |
| 5478 boxValue = parseValidPrimitive(valueId, value); | |
| 5479 m_valueList->next(); | |
| 5480 } else { | |
| 5481 return 0; | |
| 5482 } | |
| 5483 | |
| 5484 ASSERT(shapeValue && boxValue); | |
| 5485 shapeValue->getShapeValue()->setLayoutBox(boxValue.release()); | |
| 5486 } | |
| 5487 | |
| 5488 if (shapeValue) | |
| 5489 return shapeValue.release(); | |
| 5490 return boxValue.release(); | |
| 5491 } | |
| 5492 | |
| 5493 PassRefPtr<CSSPrimitiveValue> CSSParser::parseBasicShape() | |
| 5494 { | |
| 5495 CSSParserValue* value = m_valueList->current(); | |
| 5496 ASSERT(value->unit == CSSParserValue::Function); | |
| 5497 CSSParserValueList* args = value->function->args.get(); | |
| 5498 | |
| 5499 if (!args) | |
| 5500 return 0; | |
| 5501 | |
| 5502 RefPtr<CSSBasicShape> shape; | |
| 5503 if (equalIgnoringCase(value->function->name, "rectangle(")) | |
| 5504 shape = parseBasicShapeRectangle(args); | |
| 5505 else if (equalIgnoringCase(value->function->name, "circle(")) | |
| 5506 if (isDeprecatedBasicShape(args)) | |
| 5507 shape = parseDeprecatedBasicShapeCircle(args); | |
| 5508 else | |
| 5509 shape = parseBasicShapeCircle(args); | |
| 5510 else if (equalIgnoringCase(value->function->name, "ellipse(")) | |
| 5511 shape = parseBasicShapeEllipse(args); | |
| 5512 else if (equalIgnoringCase(value->function->name, "polygon(")) | |
| 5513 shape = parseBasicShapePolygon(args); | |
| 5514 else if (equalIgnoringCase(value->function->name, "inset-rectangle(")) | |
| 5515 shape = parseBasicShapeInsetRectangle(args); | |
| 5516 | |
| 5517 if (!shape) | |
| 5518 return 0; | |
| 5519 | |
| 5520 m_valueList->next(); | |
| 5521 return cssValuePool().createValue(shape.release()); | |
| 5522 } | |
| 5523 | |
| 5524 // [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-he
ight' ]? 'font-family' | |
| 5525 bool CSSParser::parseFont(bool important) | |
| 5526 { | |
| 5527 // Let's check if there is an inherit or initial somewhere in the shorthand. | |
| 5528 for (unsigned i = 0; i < m_valueList->size(); ++i) { | |
| 5529 if (m_valueList->valueAt(i)->id == CSSValueInherit || m_valueList->value
At(i)->id == CSSValueInitial) | |
| 5530 return false; | |
| 5531 } | |
| 5532 | |
| 5533 ShorthandScope scope(this, CSSPropertyFont); | |
| 5534 // Optional font-style, font-variant and font-weight. | |
| 5535 bool fontStyleParsed = false; | |
| 5536 bool fontVariantParsed = false; | |
| 5537 bool fontWeightParsed = false; | |
| 5538 CSSParserValue* value; | |
| 5539 while ((value = m_valueList->current())) { | |
| 5540 if (!fontStyleParsed && isValidKeywordPropertyAndValue(CSSPropertyFontSt
yle, value->id, m_context)) { | |
| 5541 addProperty(CSSPropertyFontStyle, cssValuePool().createIdentifierVal
ue(value->id), important); | |
| 5542 fontStyleParsed = true; | |
| 5543 } else if (!fontVariantParsed && (value->id == CSSValueNormal || value->
id == CSSValueSmallCaps)) { | |
| 5544 // Font variant in the shorthand is particular, it only accepts norm
al or small-caps. | |
| 5545 addProperty(CSSPropertyFontVariant, cssValuePool().createIdentifierV
alue(value->id), important); | |
| 5546 fontVariantParsed = true; | |
| 5547 } else if (!fontWeightParsed && parseFontWeight(important)) | |
| 5548 fontWeightParsed = true; | |
| 5549 else | |
| 5550 break; | |
| 5551 m_valueList->next(); | |
| 5552 } | |
| 5553 | |
| 5554 if (!value) | |
| 5555 return false; | |
| 5556 | |
| 5557 if (!fontStyleParsed) | |
| 5558 addProperty(CSSPropertyFontStyle, cssValuePool().createIdentifierValue(C
SSValueNormal), important, true); | |
| 5559 if (!fontVariantParsed) | |
| 5560 addProperty(CSSPropertyFontVariant, cssValuePool().createIdentifierValue
(CSSValueNormal), important, true); | |
| 5561 if (!fontWeightParsed) | |
| 5562 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue(
CSSValueNormal), important, true); | |
| 5563 | |
| 5564 // Now a font size _must_ come. | |
| 5565 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit | |
| 5566 if (!parseFontSize(important)) | |
| 5567 return false; | |
| 5568 | |
| 5569 value = m_valueList->current(); | |
| 5570 if (!value) | |
| 5571 return false; | |
| 5572 | |
| 5573 if (isForwardSlashOperator(value)) { | |
| 5574 // The line-height property. | |
| 5575 value = m_valueList->next(); | |
| 5576 if (!value) | |
| 5577 return false; | |
| 5578 if (!parseLineHeight(important)) | |
| 5579 return false; | |
| 5580 } else | |
| 5581 addProperty(CSSPropertyLineHeight, cssValuePool().createIdentifierValue(
CSSValueNormal), important, true); | |
| 5582 | |
| 5583 // Font family must come now. | |
| 5584 RefPtr<CSSValue> parsedFamilyValue = parseFontFamily(); | |
| 5585 if (!parsedFamilyValue) | |
| 5586 return false; | |
| 5587 | |
| 5588 addProperty(CSSPropertyFontFamily, parsedFamilyValue.release(), important); | |
| 5589 | |
| 5590 // FIXME: http://www.w3.org/TR/2011/WD-css3-fonts-20110324/#font-prop requir
es that | |
| 5591 // "font-stretch", "font-size-adjust", and "font-kerning" be reset to their
initial values | |
| 5592 // but we don't seem to support them at the moment. They should also be adde
d here once implemented. | |
| 5593 if (m_valueList->current()) | |
| 5594 return false; | |
| 5595 | |
| 5596 return true; | |
| 5597 } | |
| 5598 | |
| 5599 class FontFamilyValueBuilder { | |
| 5600 public: | |
| 5601 FontFamilyValueBuilder(CSSValueList* list) | |
| 5602 : m_list(list) | |
| 5603 { | |
| 5604 } | |
| 5605 | |
| 5606 void add(const CSSParserString& string) | |
| 5607 { | |
| 5608 if (!m_builder.isEmpty()) | |
| 5609 m_builder.append(' '); | |
| 5610 | |
| 5611 if (string.is8Bit()) { | |
| 5612 m_builder.append(string.characters8(), string.length()); | |
| 5613 return; | |
| 5614 } | |
| 5615 | |
| 5616 m_builder.append(string.characters16(), string.length()); | |
| 5617 } | |
| 5618 | |
| 5619 void commit() | |
| 5620 { | |
| 5621 if (m_builder.isEmpty()) | |
| 5622 return; | |
| 5623 m_list->append(cssValuePool().createFontFamilyValue(m_builder.toString()
)); | |
| 5624 m_builder.clear(); | |
| 5625 } | |
| 5626 | |
| 5627 private: | |
| 5628 StringBuilder m_builder; | |
| 5629 CSSValueList* m_list; | |
| 5630 }; | |
| 5631 | |
| 5632 PassRefPtr<CSSValueList> CSSParser::parseFontFamily() | |
| 5633 { | |
| 5634 RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); | |
| 5635 CSSParserValue* value = m_valueList->current(); | |
| 5636 | |
| 5637 FontFamilyValueBuilder familyBuilder(list.get()); | |
| 5638 bool inFamily = false; | |
| 5639 | |
| 5640 while (value) { | |
| 5641 CSSParserValue* nextValue = m_valueList->next(); | |
| 5642 bool nextValBreaksFont = !nextValue || | |
| 5643 (nextValue->unit == CSSParserValue::Operator &&
nextValue->iValue == ','); | |
| 5644 bool nextValIsFontName = nextValue && | |
| 5645 ((nextValue->id >= CSSValueSerif && nextValue->id <= CSSValueWebkitB
ody) || | |
| 5646 (nextValue->unit == CSSPrimitiveValue::CSS_STRING || nextValue->unit
== CSSPrimitiveValue::CSS_IDENT)); | |
| 5647 | |
| 5648 bool valueIsKeyword = value->id == CSSValueInitial || value->id == CSSVa
lueInherit || value->id == CSSValueDefault; | |
| 5649 if (valueIsKeyword && !inFamily) { | |
| 5650 if (nextValBreaksFont) | |
| 5651 value = m_valueList->next(); | |
| 5652 else if (nextValIsFontName) | |
| 5653 value = nextValue; | |
| 5654 continue; | |
| 5655 } | |
| 5656 | |
| 5657 if (value->id >= CSSValueSerif && value->id <= CSSValueWebkitBody) { | |
| 5658 if (inFamily) | |
| 5659 familyBuilder.add(value->string); | |
| 5660 else if (nextValBreaksFont || !nextValIsFontName) | |
| 5661 list->append(cssValuePool().createIdentifierValue(value->id)); | |
| 5662 else { | |
| 5663 familyBuilder.commit(); | |
| 5664 familyBuilder.add(value->string); | |
| 5665 inFamily = true; | |
| 5666 } | |
| 5667 } else if (value->unit == CSSPrimitiveValue::CSS_STRING) { | |
| 5668 // Strings never share in a family name. | |
| 5669 inFamily = false; | |
| 5670 familyBuilder.commit(); | |
| 5671 list->append(cssValuePool().createFontFamilyValue(value->string)); | |
| 5672 } else if (value->unit == CSSPrimitiveValue::CSS_IDENT) { | |
| 5673 if (inFamily) | |
| 5674 familyBuilder.add(value->string); | |
| 5675 else if (nextValBreaksFont || !nextValIsFontName) | |
| 5676 list->append(cssValuePool().createFontFamilyValue(value->string)
); | |
| 5677 else { | |
| 5678 familyBuilder.commit(); | |
| 5679 familyBuilder.add(value->string); | |
| 5680 inFamily = true; | |
| 5681 } | |
| 5682 } else { | |
| 5683 break; | |
| 5684 } | |
| 5685 | |
| 5686 if (!nextValue) | |
| 5687 break; | |
| 5688 | |
| 5689 if (nextValBreaksFont) { | |
| 5690 value = m_valueList->next(); | |
| 5691 familyBuilder.commit(); | |
| 5692 inFamily = false; | |
| 5693 } | |
| 5694 else if (nextValIsFontName) | |
| 5695 value = nextValue; | |
| 5696 else | |
| 5697 break; | |
| 5698 } | |
| 5699 familyBuilder.commit(); | |
| 5700 | |
| 5701 if (!list->length()) | |
| 5702 list = 0; | |
| 5703 return list.release(); | |
| 5704 } | |
| 5705 | |
| 5706 bool CSSParser::parseLineHeight(bool important) | |
| 5707 { | |
| 5708 CSSParserValue* value = m_valueList->current(); | |
| 5709 CSSValueID id = value->id; | |
| 5710 bool validPrimitive = false; | |
| 5711 // normal | <number> | <length> | <percentage> | inherit | |
| 5712 if (id == CSSValueNormal) | |
| 5713 validPrimitive = true; | |
| 5714 else | |
| 5715 validPrimitive = (!id && validUnit(value, FNumber | FLength | FPercent |
FNonNeg)); | |
| 5716 if (validPrimitive && (!m_valueList->next() || inShorthand())) | |
| 5717 addProperty(CSSPropertyLineHeight, parseValidPrimitive(id, value), impor
tant); | |
| 5718 return validPrimitive; | |
| 5719 } | |
| 5720 | |
| 5721 bool CSSParser::parseFontSize(bool important) | |
| 5722 { | |
| 5723 CSSParserValue* value = m_valueList->current(); | |
| 5724 CSSValueID id = value->id; | |
| 5725 bool validPrimitive = false; | |
| 5726 // <absolute-size> | <relative-size> | <length> | <percentage> | inherit | |
| 5727 if (id >= CSSValueXxSmall && id <= CSSValueLarger) | |
| 5728 validPrimitive = true; | |
| 5729 else | |
| 5730 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg); | |
| 5731 if (validPrimitive && (!m_valueList->next() || inShorthand())) | |
| 5732 addProperty(CSSPropertyFontSize, parseValidPrimitive(id, value), importa
nt); | |
| 5733 return validPrimitive; | |
| 5734 } | |
| 5735 | |
| 5736 bool CSSParser::parseFontVariant(bool important) | |
| 5737 { | |
| 5738 RefPtr<CSSValueList> values; | |
| 5739 if (m_valueList->size() > 1) | |
| 5740 values = CSSValueList::createCommaSeparated(); | |
| 5741 CSSParserValue* val; | |
| 5742 bool expectComma = false; | |
| 5743 while ((val = m_valueList->current())) { | |
| 5744 RefPtr<CSSPrimitiveValue> parsedValue; | |
| 5745 if (!expectComma) { | |
| 5746 expectComma = true; | |
| 5747 if (val->id == CSSValueNormal || val->id == CSSValueSmallCaps) | |
| 5748 parsedValue = cssValuePool().createIdentifierValue(val->id); | |
| 5749 else if (val->id == CSSValueAll && !values) { | |
| 5750 // 'all' is only allowed in @font-face and with no other values.
Make a value list to | |
| 5751 // indicate that we are in the @font-face case. | |
| 5752 values = CSSValueList::createCommaSeparated(); | |
| 5753 parsedValue = cssValuePool().createIdentifierValue(val->id); | |
| 5754 } | |
| 5755 } else if (val->unit == CSSParserValue::Operator && val->iValue == ',')
{ | |
| 5756 expectComma = false; | |
| 5757 m_valueList->next(); | |
| 5758 continue; | |
| 5759 } | |
| 5760 | |
| 5761 if (!parsedValue) | |
| 5762 return false; | |
| 5763 | |
| 5764 m_valueList->next(); | |
| 5765 | |
| 5766 if (values) | |
| 5767 values->append(parsedValue.release()); | |
| 5768 else { | |
| 5769 addProperty(CSSPropertyFontVariant, parsedValue.release(), important
); | |
| 5770 return true; | |
| 5771 } | |
| 5772 } | |
| 5773 | |
| 5774 if (values && values->length()) { | |
| 5775 m_hasFontFaceOnlyValues = true; | |
| 5776 addProperty(CSSPropertyFontVariant, values.release(), important); | |
| 5777 return true; | |
| 5778 } | |
| 5779 | |
| 5780 return false; | |
| 5781 } | |
| 5782 | |
| 5783 bool CSSParser::parseFontWeight(bool important) | |
| 5784 { | |
| 5785 CSSParserValue* value = m_valueList->current(); | |
| 5786 if ((value->id >= CSSValueNormal) && (value->id <= CSSValue900)) { | |
| 5787 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue(
value->id), important); | |
| 5788 return true; | |
| 5789 } | |
| 5790 if (validUnit(value, FInteger | FNonNeg, HTMLQuirksMode)) { | |
| 5791 int weight = static_cast<int>(value->fValue); | |
| 5792 if (!(weight % 100) && weight >= 100 && weight <= 900) { | |
| 5793 addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierVa
lue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)), important); | |
| 5794 return true; | |
| 5795 } | |
| 5796 } | |
| 5797 return false; | |
| 5798 } | |
| 5799 | |
| 5800 bool CSSParser::parseFontFaceSrcURI(CSSValueList* valueList) | |
| 5801 { | |
| 5802 RefPtr<CSSFontFaceSrcValue> uriValue(CSSFontFaceSrcValue::create(completeURL
(m_valueList->current()->string))); | |
| 5803 | |
| 5804 CSSParserValue* value = m_valueList->next(); | |
| 5805 if (!value) { | |
| 5806 valueList->append(uriValue.release()); | |
| 5807 return true; | |
| 5808 } | |
| 5809 if (value->unit == CSSParserValue::Operator && value->iValue == ',') { | |
| 5810 m_valueList->next(); | |
| 5811 valueList->append(uriValue.release()); | |
| 5812 return true; | |
| 5813 } | |
| 5814 | |
| 5815 if (value->unit != CSSParserValue::Function || !equalIgnoringCase(value->fun
ction->name, "format(")) | |
| 5816 return false; | |
| 5817 | |
| 5818 // FIXME: http://www.w3.org/TR/2011/WD-css3-fonts-20111004/ says that format
() contains a comma-separated list of strings, | |
| 5819 // but CSSFontFaceSrcValue stores only one format. Allowing one format for n
ow. | |
| 5820 CSSParserValueList* args = value->function->args.get(); | |
| 5821 if (!args || args->size() != 1 || (args->current()->unit != CSSPrimitiveValu
e::CSS_STRING && args->current()->unit != CSSPrimitiveValue::CSS_IDENT)) | |
| 5822 return false; | |
| 5823 uriValue->setFormat(args->current()->string); | |
| 5824 valueList->append(uriValue.release()); | |
| 5825 value = m_valueList->next(); | |
| 5826 if (value && value->unit == CSSParserValue::Operator && value->iValue == ','
) | |
| 5827 m_valueList->next(); | |
| 5828 return true; | |
| 5829 } | |
| 5830 | |
| 5831 bool CSSParser::parseFontFaceSrcLocal(CSSValueList* valueList) | |
| 5832 { | |
| 5833 CSSParserValueList* args = m_valueList->current()->function->args.get(); | |
| 5834 if (!args || !args->size()) | |
| 5835 return false; | |
| 5836 | |
| 5837 if (args->size() == 1 && args->current()->unit == CSSPrimitiveValue::CSS_STR
ING) | |
| 5838 valueList->append(CSSFontFaceSrcValue::createLocal(args->current()->stri
ng)); | |
| 5839 else if (args->current()->unit == CSSPrimitiveValue::CSS_IDENT) { | |
| 5840 StringBuilder builder; | |
| 5841 for (CSSParserValue* localValue = args->current(); localValue; localValu
e = args->next()) { | |
| 5842 if (localValue->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 5843 return false; | |
| 5844 if (!builder.isEmpty()) | |
| 5845 builder.append(' '); | |
| 5846 builder.append(localValue->string); | |
| 5847 } | |
| 5848 valueList->append(CSSFontFaceSrcValue::createLocal(builder.toString())); | |
| 5849 } else | |
| 5850 return false; | |
| 5851 | |
| 5852 if (CSSParserValue* value = m_valueList->next()) { | |
| 5853 if (value->unit == CSSParserValue::Operator && value->iValue == ',') | |
| 5854 m_valueList->next(); | |
| 5855 } | |
| 5856 return true; | |
| 5857 } | |
| 5858 | |
| 5859 bool CSSParser::parseFontFaceSrc() | |
| 5860 { | |
| 5861 RefPtr<CSSValueList> values(CSSValueList::createCommaSeparated()); | |
| 5862 | |
| 5863 while (CSSParserValue* value = m_valueList->current()) { | |
| 5864 if (value->unit == CSSPrimitiveValue::CSS_URI) { | |
| 5865 if (!parseFontFaceSrcURI(values.get())) | |
| 5866 return false; | |
| 5867 } else if (value->unit == CSSParserValue::Function && equalIgnoringCase(
value->function->name, "local(")) { | |
| 5868 if (!parseFontFaceSrcLocal(values.get())) | |
| 5869 return false; | |
| 5870 } else | |
| 5871 return false; | |
| 5872 } | |
| 5873 if (!values->length()) | |
| 5874 return false; | |
| 5875 | |
| 5876 addProperty(CSSPropertySrc, values.release(), m_important); | |
| 5877 m_valueList->next(); | |
| 5878 return true; | |
| 5879 } | |
| 5880 | |
| 5881 bool CSSParser::parseFontFaceUnicodeRange() | |
| 5882 { | |
| 5883 RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated(); | |
| 5884 bool failed = false; | |
| 5885 bool operatorExpected = false; | |
| 5886 for (; m_valueList->current(); m_valueList->next(), operatorExpected = !oper
atorExpected) { | |
| 5887 if (operatorExpected) { | |
| 5888 if (m_valueList->current()->unit == CSSParserValue::Operator && m_va
lueList->current()->iValue == ',') | |
| 5889 continue; | |
| 5890 failed = true; | |
| 5891 break; | |
| 5892 } | |
| 5893 if (m_valueList->current()->unit != CSSPrimitiveValue::CSS_UNICODE_RANGE
) { | |
| 5894 failed = true; | |
| 5895 break; | |
| 5896 } | |
| 5897 | |
| 5898 String rangeString = m_valueList->current()->string; | |
| 5899 UChar32 from = 0; | |
| 5900 UChar32 to = 0; | |
| 5901 unsigned length = rangeString.length(); | |
| 5902 | |
| 5903 if (length < 3) { | |
| 5904 failed = true; | |
| 5905 break; | |
| 5906 } | |
| 5907 | |
| 5908 unsigned i = 2; | |
| 5909 while (i < length) { | |
| 5910 UChar c = rangeString[i]; | |
| 5911 if (c == '-' || c == '?') | |
| 5912 break; | |
| 5913 from *= 16; | |
| 5914 if (c >= '0' && c <= '9') | |
| 5915 from += c - '0'; | |
| 5916 else if (c >= 'A' && c <= 'F') | |
| 5917 from += 10 + c - 'A'; | |
| 5918 else if (c >= 'a' && c <= 'f') | |
| 5919 from += 10 + c - 'a'; | |
| 5920 else { | |
| 5921 failed = true; | |
| 5922 break; | |
| 5923 } | |
| 5924 i++; | |
| 5925 } | |
| 5926 if (failed) | |
| 5927 break; | |
| 5928 | |
| 5929 if (i == length) | |
| 5930 to = from; | |
| 5931 else if (rangeString[i] == '?') { | |
| 5932 unsigned span = 1; | |
| 5933 while (i < length && rangeString[i] == '?') { | |
| 5934 span *= 16; | |
| 5935 from *= 16; | |
| 5936 i++; | |
| 5937 } | |
| 5938 if (i < length) | |
| 5939 failed = true; | |
| 5940 to = from + span - 1; | |
| 5941 } else { | |
| 5942 if (length < i + 2) { | |
| 5943 failed = true; | |
| 5944 break; | |
| 5945 } | |
| 5946 i++; | |
| 5947 while (i < length) { | |
| 5948 UChar c = rangeString[i]; | |
| 5949 to *= 16; | |
| 5950 if (c >= '0' && c <= '9') | |
| 5951 to += c - '0'; | |
| 5952 else if (c >= 'A' && c <= 'F') | |
| 5953 to += 10 + c - 'A'; | |
| 5954 else if (c >= 'a' && c <= 'f') | |
| 5955 to += 10 + c - 'a'; | |
| 5956 else { | |
| 5957 failed = true; | |
| 5958 break; | |
| 5959 } | |
| 5960 i++; | |
| 5961 } | |
| 5962 if (failed) | |
| 5963 break; | |
| 5964 } | |
| 5965 if (from <= to) | |
| 5966 values->append(CSSUnicodeRangeValue::create(from, to)); | |
| 5967 } | |
| 5968 if (failed || !values->length()) | |
| 5969 return false; | |
| 5970 addProperty(CSSPropertyUnicodeRange, values.release(), m_important); | |
| 5971 return true; | |
| 5972 } | |
| 5973 | |
| 5974 // Returns the number of characters which form a valid double | |
| 5975 // and are terminated by the given terminator character | |
| 5976 template <typename CharacterType> | |
| 5977 static int checkForValidDouble(const CharacterType* string, const CharacterType*
end, const char terminator) | |
| 5978 { | |
| 5979 int length = end - string; | |
| 5980 if (length < 1) | |
| 5981 return 0; | |
| 5982 | |
| 5983 bool decimalMarkSeen = false; | |
| 5984 int processedLength = 0; | |
| 5985 | |
| 5986 for (int i = 0; i < length; ++i) { | |
| 5987 if (string[i] == terminator) { | |
| 5988 processedLength = i; | |
| 5989 break; | |
| 5990 } | |
| 5991 if (!isASCIIDigit(string[i])) { | |
| 5992 if (!decimalMarkSeen && string[i] == '.') | |
| 5993 decimalMarkSeen = true; | |
| 5994 else | |
| 5995 return 0; | |
| 5996 } | |
| 5997 } | |
| 5998 | |
| 5999 if (decimalMarkSeen && processedLength == 1) | |
| 6000 return 0; | |
| 6001 | |
| 6002 return processedLength; | |
| 6003 } | |
| 6004 | |
| 6005 // Returns the number of characters consumed for parsing a valid double | |
| 6006 // terminated by the given terminator character | |
| 6007 template <typename CharacterType> | |
| 6008 static int parseDouble(const CharacterType* string, const CharacterType* end, co
nst char terminator, double& value) | |
| 6009 { | |
| 6010 int length = checkForValidDouble(string, end, terminator); | |
| 6011 if (!length) | |
| 6012 return 0; | |
| 6013 | |
| 6014 int position = 0; | |
| 6015 double localValue = 0; | |
| 6016 | |
| 6017 // The consumed characters here are guaranteed to be | |
| 6018 // ASCII digits with or without a decimal mark | |
| 6019 for (; position < length; ++position) { | |
| 6020 if (string[position] == '.') | |
| 6021 break; | |
| 6022 localValue = localValue * 10 + string[position] - '0'; | |
| 6023 } | |
| 6024 | |
| 6025 if (++position == length) { | |
| 6026 value = localValue; | |
| 6027 return length; | |
| 6028 } | |
| 6029 | |
| 6030 double fraction = 0; | |
| 6031 double scale = 1; | |
| 6032 | |
| 6033 while (position < length && scale < MAX_SCALE) { | |
| 6034 fraction = fraction * 10 + string[position++] - '0'; | |
| 6035 scale *= 10; | |
| 6036 } | |
| 6037 | |
| 6038 value = localValue + fraction / scale; | |
| 6039 return length; | |
| 6040 } | |
| 6041 | |
| 6042 template <typename CharacterType> | |
| 6043 static bool parseColorIntOrPercentage(const CharacterType*& string, const Charac
terType* end, const char terminator, CSSPrimitiveValue::UnitTypes& expect, int&
value) | |
| 6044 { | |
| 6045 const CharacterType* current = string; | |
| 6046 double localValue = 0; | |
| 6047 bool negative = false; | |
| 6048 while (current != end && isHTMLSpace<CharacterType>(*current)) | |
| 6049 current++; | |
| 6050 if (current != end && *current == '-') { | |
| 6051 negative = true; | |
| 6052 current++; | |
| 6053 } | |
| 6054 if (current == end || !isASCIIDigit(*current)) | |
| 6055 return false; | |
| 6056 while (current != end && isASCIIDigit(*current)) { | |
| 6057 double newValue = localValue * 10 + *current++ - '0'; | |
| 6058 if (newValue >= 255) { | |
| 6059 // Clamp values at 255. | |
| 6060 localValue = 255; | |
| 6061 while (current != end && isASCIIDigit(*current)) | |
| 6062 ++current; | |
| 6063 break; | |
| 6064 } | |
| 6065 localValue = newValue; | |
| 6066 } | |
| 6067 | |
| 6068 if (current == end) | |
| 6069 return false; | |
| 6070 | |
| 6071 if (expect == CSSPrimitiveValue::CSS_NUMBER && (*current == '.' || *current
== '%')) | |
| 6072 return false; | |
| 6073 | |
| 6074 if (*current == '.') { | |
| 6075 // We already parsed the integral part, try to parse | |
| 6076 // the fraction part of the percentage value. | |
| 6077 double percentage = 0; | |
| 6078 int numCharactersParsed = parseDouble(current, end, '%', percentage); | |
| 6079 if (!numCharactersParsed) | |
| 6080 return false; | |
| 6081 current += numCharactersParsed; | |
| 6082 if (*current != '%') | |
| 6083 return false; | |
| 6084 localValue += percentage; | |
| 6085 } | |
| 6086 | |
| 6087 if (expect == CSSPrimitiveValue::CSS_PERCENTAGE && *current != '%') | |
| 6088 return false; | |
| 6089 | |
| 6090 if (*current == '%') { | |
| 6091 expect = CSSPrimitiveValue::CSS_PERCENTAGE; | |
| 6092 localValue = localValue / 100.0 * 256.0; | |
| 6093 // Clamp values at 255 for percentages over 100% | |
| 6094 if (localValue > 255) | |
| 6095 localValue = 255; | |
| 6096 current++; | |
| 6097 } else | |
| 6098 expect = CSSPrimitiveValue::CSS_NUMBER; | |
| 6099 | |
| 6100 while (current != end && isHTMLSpace<CharacterType>(*current)) | |
| 6101 current++; | |
| 6102 if (current == end || *current++ != terminator) | |
| 6103 return false; | |
| 6104 // Clamp negative values at zero. | |
| 6105 value = negative ? 0 : static_cast<int>(localValue); | |
| 6106 string = current; | |
| 6107 return true; | |
| 6108 } | |
| 6109 | |
| 6110 template <typename CharacterType> | |
| 6111 static inline bool isTenthAlpha(const CharacterType* string, const int length) | |
| 6112 { | |
| 6113 // "0.X" | |
| 6114 if (length == 3 && string[0] == '0' && string[1] == '.' && isASCIIDigit(stri
ng[2])) | |
| 6115 return true; | |
| 6116 | |
| 6117 // ".X" | |
| 6118 if (length == 2 && string[0] == '.' && isASCIIDigit(string[1])) | |
| 6119 return true; | |
| 6120 | |
| 6121 return false; | |
| 6122 } | |
| 6123 | |
| 6124 template <typename CharacterType> | |
| 6125 static inline bool parseAlphaValue(const CharacterType*& string, const Character
Type* end, const char terminator, int& value) | |
| 6126 { | |
| 6127 while (string != end && isHTMLSpace<CharacterType>(*string)) | |
| 6128 string++; | |
| 6129 | |
| 6130 bool negative = false; | |
| 6131 | |
| 6132 if (string != end && *string == '-') { | |
| 6133 negative = true; | |
| 6134 string++; | |
| 6135 } | |
| 6136 | |
| 6137 value = 0; | |
| 6138 | |
| 6139 int length = end - string; | |
| 6140 if (length < 2) | |
| 6141 return false; | |
| 6142 | |
| 6143 if (string[length - 1] != terminator || !isASCIIDigit(string[length - 2])) | |
| 6144 return false; | |
| 6145 | |
| 6146 if (string[0] != '0' && string[0] != '1' && string[0] != '.') { | |
| 6147 if (checkForValidDouble(string, end, terminator)) { | |
| 6148 value = negative ? 0 : 255; | |
| 6149 string = end; | |
| 6150 return true; | |
| 6151 } | |
| 6152 return false; | |
| 6153 } | |
| 6154 | |
| 6155 if (length == 2 && string[0] != '.') { | |
| 6156 value = !negative && string[0] == '1' ? 255 : 0; | |
| 6157 string = end; | |
| 6158 return true; | |
| 6159 } | |
| 6160 | |
| 6161 if (isTenthAlpha(string, length - 1)) { | |
| 6162 static const int tenthAlphaValues[] = { 0, 25, 51, 76, 102, 127, 153, 17
9, 204, 230 }; | |
| 6163 value = negative ? 0 : tenthAlphaValues[string[length - 2] - '0']; | |
| 6164 string = end; | |
| 6165 return true; | |
| 6166 } | |
| 6167 | |
| 6168 double alpha = 0; | |
| 6169 if (!parseDouble(string, end, terminator, alpha)) | |
| 6170 return false; | |
| 6171 value = negative ? 0 : static_cast<int>(alpha * nextafter(256.0, 0.0)); | |
| 6172 string = end; | |
| 6173 return true; | |
| 6174 } | |
| 6175 | |
| 6176 template <typename CharacterType> | |
| 6177 static inline bool mightBeRGBA(const CharacterType* characters, unsigned length) | |
| 6178 { | |
| 6179 if (length < 5) | |
| 6180 return false; | |
| 6181 return characters[4] == '(' | |
| 6182 && isASCIIAlphaCaselessEqual(characters[0], 'r') | |
| 6183 && isASCIIAlphaCaselessEqual(characters[1], 'g') | |
| 6184 && isASCIIAlphaCaselessEqual(characters[2], 'b') | |
| 6185 && isASCIIAlphaCaselessEqual(characters[3], 'a'); | |
| 6186 } | |
| 6187 | |
| 6188 template <typename CharacterType> | |
| 6189 static inline bool mightBeRGB(const CharacterType* characters, unsigned length) | |
| 6190 { | |
| 6191 if (length < 4) | |
| 6192 return false; | |
| 6193 return characters[3] == '(' | |
| 6194 && isASCIIAlphaCaselessEqual(characters[0], 'r') | |
| 6195 && isASCIIAlphaCaselessEqual(characters[1], 'g') | |
| 6196 && isASCIIAlphaCaselessEqual(characters[2], 'b'); | |
| 6197 } | |
| 6198 | |
| 6199 template <typename CharacterType> | |
| 6200 static inline bool fastParseColorInternal(RGBA32& rgb, const CharacterType* char
acters, unsigned length , bool strict) | |
| 6201 { | |
| 6202 CSSPrimitiveValue::UnitTypes expect = CSSPrimitiveValue::CSS_UNKNOWN; | |
| 6203 | |
| 6204 if (!strict && length >= 3) { | |
| 6205 if (characters[0] == '#') { | |
| 6206 if (Color::parseHexColor(characters + 1, length - 1, rgb)) | |
| 6207 return true; | |
| 6208 } else { | |
| 6209 if (Color::parseHexColor(characters, length, rgb)) | |
| 6210 return true; | |
| 6211 } | |
| 6212 } | |
| 6213 | |
| 6214 // Try rgba() syntax. | |
| 6215 if (mightBeRGBA(characters, length)) { | |
| 6216 const CharacterType* current = characters + 5; | |
| 6217 const CharacterType* end = characters + length; | |
| 6218 int red; | |
| 6219 int green; | |
| 6220 int blue; | |
| 6221 int alpha; | |
| 6222 | |
| 6223 if (!parseColorIntOrPercentage(current, end, ',', expect, red)) | |
| 6224 return false; | |
| 6225 if (!parseColorIntOrPercentage(current, end, ',', expect, green)) | |
| 6226 return false; | |
| 6227 if (!parseColorIntOrPercentage(current, end, ',', expect, blue)) | |
| 6228 return false; | |
| 6229 if (!parseAlphaValue(current, end, ')', alpha)) | |
| 6230 return false; | |
| 6231 if (current != end) | |
| 6232 return false; | |
| 6233 rgb = makeRGBA(red, green, blue, alpha); | |
| 6234 return true; | |
| 6235 } | |
| 6236 | |
| 6237 // Try rgb() syntax. | |
| 6238 if (mightBeRGB(characters, length)) { | |
| 6239 const CharacterType* current = characters + 4; | |
| 6240 const CharacterType* end = characters + length; | |
| 6241 int red; | |
| 6242 int green; | |
| 6243 int blue; | |
| 6244 if (!parseColorIntOrPercentage(current, end, ',', expect, red)) | |
| 6245 return false; | |
| 6246 if (!parseColorIntOrPercentage(current, end, ',', expect, green)) | |
| 6247 return false; | |
| 6248 if (!parseColorIntOrPercentage(current, end, ')', expect, blue)) | |
| 6249 return false; | |
| 6250 if (current != end) | |
| 6251 return false; | |
| 6252 rgb = makeRGB(red, green, blue); | |
| 6253 return true; | |
| 6254 } | |
| 6255 | |
| 6256 return false; | |
| 6257 } | |
| 6258 | |
| 6259 template<typename StringType> | |
| 6260 bool CSSParser::fastParseColor(RGBA32& rgb, const StringType& name, bool strict) | |
| 6261 { | |
| 6262 unsigned length = name.length(); | |
| 6263 bool parseResult; | |
| 6264 | |
| 6265 if (!length) | |
| 6266 return false; | |
| 6267 | |
| 6268 if (name.is8Bit()) | |
| 6269 parseResult = fastParseColorInternal(rgb, name.characters8(), length, st
rict); | |
| 6270 else | |
| 6271 parseResult = fastParseColorInternal(rgb, name.characters16(), length, s
trict); | |
| 6272 | |
| 6273 if (parseResult) | |
| 6274 return true; | |
| 6275 | |
| 6276 // Try named colors. | |
| 6277 Color tc; | |
| 6278 tc.setNamedColor(name); | |
| 6279 if (tc.isValid()) { | |
| 6280 rgb = tc.rgb(); | |
| 6281 return true; | |
| 6282 } | |
| 6283 return false; | |
| 6284 } | |
| 6285 | |
| 6286 inline double CSSParser::parsedDouble(CSSParserValue *v, ReleaseParsedCalcValueC
ondition releaseCalc) | |
| 6287 { | |
| 6288 const double result = m_parsedCalculation ? m_parsedCalculation->doubleValue
() : v->fValue; | |
| 6289 if (releaseCalc == ReleaseParsedCalcValue) | |
| 6290 m_parsedCalculation.release(); | |
| 6291 return result; | |
| 6292 } | |
| 6293 | |
| 6294 bool CSSParser::isCalculation(CSSParserValue* value) | |
| 6295 { | |
| 6296 return (value->unit == CSSParserValue::Function) | |
| 6297 && (equalIgnoringCase(value->function->name, "calc(") | |
| 6298 || equalIgnoringCase(value->function->name, "-webkit-calc(") | |
| 6299 || equalIgnoringCase(value->function->name, "-webkit-min(") | |
| 6300 || equalIgnoringCase(value->function->name, "-webkit-max(")); | |
| 6301 } | |
| 6302 | |
| 6303 inline int CSSParser::colorIntFromValue(CSSParserValue* v) | |
| 6304 { | |
| 6305 bool isPercent; | |
| 6306 | |
| 6307 if (m_parsedCalculation) | |
| 6308 isPercent = m_parsedCalculation->category() == CalcPercent; | |
| 6309 else | |
| 6310 isPercent = v->unit == CSSPrimitiveValue::CSS_PERCENTAGE; | |
| 6311 | |
| 6312 const double value = parsedDouble(v, ReleaseParsedCalcValue); | |
| 6313 | |
| 6314 if (value <= 0.0) | |
| 6315 return 0; | |
| 6316 | |
| 6317 if (isPercent) { | |
| 6318 if (value >= 100.0) | |
| 6319 return 255; | |
| 6320 return static_cast<int>(value * 256.0 / 100.0); | |
| 6321 } | |
| 6322 | |
| 6323 if (value >= 255.0) | |
| 6324 return 255; | |
| 6325 | |
| 6326 return static_cast<int>(value); | |
| 6327 } | |
| 6328 | |
| 6329 bool CSSParser::parseColorParameters(CSSParserValue* value, int* colorArray, boo
l parseAlpha) | |
| 6330 { | |
| 6331 CSSParserValueList* args = value->function->args.get(); | |
| 6332 CSSParserValue* v = args->current(); | |
| 6333 Units unitType = FUnknown; | |
| 6334 // Get the first value and its type | |
| 6335 if (validUnit(v, FInteger, HTMLStandardMode)) | |
| 6336 unitType = FInteger; | |
| 6337 else if (validUnit(v, FPercent, HTMLStandardMode)) | |
| 6338 unitType = FPercent; | |
| 6339 else | |
| 6340 return false; | |
| 6341 | |
| 6342 colorArray[0] = colorIntFromValue(v); | |
| 6343 for (int i = 1; i < 3; i++) { | |
| 6344 v = args->next(); | |
| 6345 if (v->unit != CSSParserValue::Operator && v->iValue != ',') | |
| 6346 return false; | |
| 6347 v = args->next(); | |
| 6348 if (!validUnit(v, unitType, HTMLStandardMode)) | |
| 6349 return false; | |
| 6350 colorArray[i] = colorIntFromValue(v); | |
| 6351 } | |
| 6352 if (parseAlpha) { | |
| 6353 v = args->next(); | |
| 6354 if (v->unit != CSSParserValue::Operator && v->iValue != ',') | |
| 6355 return false; | |
| 6356 v = args->next(); | |
| 6357 if (!validUnit(v, FNumber, HTMLStandardMode)) | |
| 6358 return false; | |
| 6359 const double value = parsedDouble(v, ReleaseParsedCalcValue); | |
| 6360 // Convert the floating pointer number of alpha to an integer in the ran
ge [0, 256), | |
| 6361 // with an equal distribution across all 256 values. | |
| 6362 colorArray[3] = static_cast<int>(max(0.0, min(1.0, value)) * nextafter(2
56.0, 0.0)); | |
| 6363 } | |
| 6364 return true; | |
| 6365 } | |
| 6366 | |
| 6367 // The CSS3 specification defines the format of a HSL color as | |
| 6368 // hsl(<number>, <percent>, <percent>) | |
| 6369 // and with alpha, the format is | |
| 6370 // hsla(<number>, <percent>, <percent>, <number>) | |
| 6371 // The first value, HUE, is in an angle with a value between 0 and 360 | |
| 6372 bool CSSParser::parseHSLParameters(CSSParserValue* value, double* colorArray, bo
ol parseAlpha) | |
| 6373 { | |
| 6374 CSSParserValueList* args = value->function->args.get(); | |
| 6375 CSSParserValue* v = args->current(); | |
| 6376 // Get the first value | |
| 6377 if (!validUnit(v, FNumber, HTMLStandardMode)) | |
| 6378 return false; | |
| 6379 // normalize the Hue value and change it to be between 0 and 1.0 | |
| 6380 colorArray[0] = (((static_cast<int>(parsedDouble(v, ReleaseParsedCalcValue))
% 360) + 360) % 360) / 360.0; | |
| 6381 for (int i = 1; i < 3; i++) { | |
| 6382 v = args->next(); | |
| 6383 if (v->unit != CSSParserValue::Operator && v->iValue != ',') | |
| 6384 return false; | |
| 6385 v = args->next(); | |
| 6386 if (!validUnit(v, FPercent, HTMLStandardMode)) | |
| 6387 return false; | |
| 6388 colorArray[i] = max(0.0, min(100.0, parsedDouble(v, ReleaseParsedCalcVal
ue))) / 100.0; // needs to be value between 0 and 1.0 | |
| 6389 } | |
| 6390 if (parseAlpha) { | |
| 6391 v = args->next(); | |
| 6392 if (v->unit != CSSParserValue::Operator && v->iValue != ',') | |
| 6393 return false; | |
| 6394 v = args->next(); | |
| 6395 if (!validUnit(v, FNumber, HTMLStandardMode)) | |
| 6396 return false; | |
| 6397 colorArray[3] = max(0.0, min(1.0, parsedDouble(v, ReleaseParsedCalcValue
))); | |
| 6398 } | |
| 6399 return true; | |
| 6400 } | |
| 6401 | |
| 6402 PassRefPtr<CSSPrimitiveValue> CSSParser::parseColor(CSSParserValue* value) | |
| 6403 { | |
| 6404 RGBA32 c = Color::transparent; | |
| 6405 if (!parseColorFromValue(value ? value : m_valueList->current(), c)) | |
| 6406 return 0; | |
| 6407 return cssValuePool().createColorValue(c); | |
| 6408 } | |
| 6409 | |
| 6410 bool CSSParser::parseColorFromValue(CSSParserValue* value, RGBA32& c) | |
| 6411 { | |
| 6412 if (inQuirksMode() && value->unit == CSSPrimitiveValue::CSS_NUMBER | |
| 6413 && value->fValue >= 0. && value->fValue < 1000000.) { | |
| 6414 String str = String::format("%06d", static_cast<int>((value->fValue+.5))
); | |
| 6415 // FIXME: This should be strict parsing for SVG as well. | |
| 6416 if (!fastParseColor(c, str, !inQuirksMode())) | |
| 6417 return false; | |
| 6418 } else if (value->unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR || | |
| 6419 value->unit == CSSPrimitiveValue::CSS_IDENT || | |
| 6420 (inQuirksMode() && value->unit == CSSPrimitiveValue::CSS_DIMENSI
ON)) { | |
| 6421 if (!fastParseColor(c, value->string, !inQuirksMode() && value->unit ==
CSSPrimitiveValue::CSS_IDENT)) | |
| 6422 return false; | |
| 6423 } else if (value->unit == CSSParserValue::Function && | |
| 6424 value->function->args != 0 && | |
| 6425 value->function->args->size() == 5 /* rgb + two commas */ && | |
| 6426 equalIgnoringCase(value->function->name, "rgb(")) { | |
| 6427 int colorValues[3]; | |
| 6428 if (!parseColorParameters(value, colorValues, false)) | |
| 6429 return false; | |
| 6430 c = makeRGB(colorValues[0], colorValues[1], colorValues[2]); | |
| 6431 } else { | |
| 6432 if (value->unit == CSSParserValue::Function && | |
| 6433 value->function->args != 0 && | |
| 6434 value->function->args->size() == 7 /* rgba + three commas */ && | |
| 6435 equalIgnoringCase(value->function->name, "rgba(")) { | |
| 6436 int colorValues[4]; | |
| 6437 if (!parseColorParameters(value, colorValues, true)) | |
| 6438 return false; | |
| 6439 c = makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorVa
lues[3]); | |
| 6440 } else if (value->unit == CSSParserValue::Function && | |
| 6441 value->function->args != 0 && | |
| 6442 value->function->args->size() == 5 /* hsl + two commas */ && | |
| 6443 equalIgnoringCase(value->function->name, "hsl(")) { | |
| 6444 double colorValues[3]; | |
| 6445 if (!parseHSLParameters(value, colorValues, false)) | |
| 6446 return false; | |
| 6447 c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2],
1.0); | |
| 6448 } else if (value->unit == CSSParserValue::Function && | |
| 6449 value->function->args != 0 && | |
| 6450 value->function->args->size() == 7 /* hsla + three commas */
&& | |
| 6451 equalIgnoringCase(value->function->name, "hsla(")) { | |
| 6452 double colorValues[4]; | |
| 6453 if (!parseHSLParameters(value, colorValues, true)) | |
| 6454 return false; | |
| 6455 c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2],
colorValues[3]); | |
| 6456 } else | |
| 6457 return false; | |
| 6458 } | |
| 6459 | |
| 6460 return true; | |
| 6461 } | |
| 6462 | |
| 6463 // This class tracks parsing state for shadow values. If it goes out of scope (
e.g., due to an early return) | |
| 6464 // without the allowBreak bit being set, then it will clean up all of the object
s and destroy them. | |
| 6465 struct ShadowParseContext { | |
| 6466 ShadowParseContext(CSSPropertyID prop, CSSParser* parser) | |
| 6467 : property(prop) | |
| 6468 , m_parser(parser) | |
| 6469 , allowX(true) | |
| 6470 , allowY(false) | |
| 6471 , allowBlur(false) | |
| 6472 , allowSpread(false) | |
| 6473 , allowColor(true) | |
| 6474 , allowStyle(prop == CSSPropertyWebkitBoxShadow || prop == CSSPropertyBo
xShadow) | |
| 6475 , allowBreak(true) | |
| 6476 { | |
| 6477 } | |
| 6478 | |
| 6479 bool allowLength() { return allowX || allowY || allowBlur || allowSpread; } | |
| 6480 | |
| 6481 void commitValue() | |
| 6482 { | |
| 6483 // Handle the ,, case gracefully by doing nothing. | |
| 6484 if (x || y || blur || spread || color || style) { | |
| 6485 if (!values) | |
| 6486 values = CSSValueList::createCommaSeparated(); | |
| 6487 | |
| 6488 // Construct the current shadow value and add it to the list. | |
| 6489 values->append(CSSShadowValue::create(x.release(), y.release(), blur
.release(), spread.release(), style.release(), color.release())); | |
| 6490 } | |
| 6491 | |
| 6492 // Now reset for the next shadow value. | |
| 6493 x = 0; | |
| 6494 y = 0; | |
| 6495 blur = 0; | |
| 6496 spread = 0; | |
| 6497 style = 0; | |
| 6498 color = 0; | |
| 6499 | |
| 6500 allowX = true; | |
| 6501 allowColor = true; | |
| 6502 allowBreak = true; | |
| 6503 allowY = false; | |
| 6504 allowBlur = false; | |
| 6505 allowSpread = false; | |
| 6506 allowStyle = property == CSSPropertyWebkitBoxShadow || property == CSSPr
opertyBoxShadow; | |
| 6507 } | |
| 6508 | |
| 6509 void commitLength(CSSParserValue* v) | |
| 6510 { | |
| 6511 RefPtr<CSSPrimitiveValue> val = m_parser->createPrimitiveNumericValue(v)
; | |
| 6512 | |
| 6513 if (allowX) { | |
| 6514 x = val.release(); | |
| 6515 allowX = false; | |
| 6516 allowY = true; | |
| 6517 allowColor = false; | |
| 6518 allowStyle = false; | |
| 6519 allowBreak = false; | |
| 6520 } else if (allowY) { | |
| 6521 y = val.release(); | |
| 6522 allowY = false; | |
| 6523 allowBlur = true; | |
| 6524 allowColor = true; | |
| 6525 allowStyle = property == CSSPropertyWebkitBoxShadow || property == C
SSPropertyBoxShadow; | |
| 6526 allowBreak = true; | |
| 6527 } else if (allowBlur) { | |
| 6528 blur = val.release(); | |
| 6529 allowBlur = false; | |
| 6530 allowSpread = property == CSSPropertyWebkitBoxShadow || property ==
CSSPropertyBoxShadow; | |
| 6531 } else if (allowSpread) { | |
| 6532 spread = val.release(); | |
| 6533 allowSpread = false; | |
| 6534 } | |
| 6535 } | |
| 6536 | |
| 6537 void commitColor(PassRefPtr<CSSPrimitiveValue> val) | |
| 6538 { | |
| 6539 color = val; | |
| 6540 allowColor = false; | |
| 6541 if (allowX) { | |
| 6542 allowStyle = false; | |
| 6543 allowBreak = false; | |
| 6544 } else { | |
| 6545 allowBlur = false; | |
| 6546 allowSpread = false; | |
| 6547 allowStyle = property == CSSPropertyWebkitBoxShadow || property == C
SSPropertyBoxShadow; | |
| 6548 } | |
| 6549 } | |
| 6550 | |
| 6551 void commitStyle(CSSParserValue* v) | |
| 6552 { | |
| 6553 style = cssValuePool().createIdentifierValue(v->id); | |
| 6554 allowStyle = false; | |
| 6555 if (allowX) | |
| 6556 allowBreak = false; | |
| 6557 else { | |
| 6558 allowBlur = false; | |
| 6559 allowSpread = false; | |
| 6560 allowColor = false; | |
| 6561 } | |
| 6562 } | |
| 6563 | |
| 6564 CSSPropertyID property; | |
| 6565 CSSParser* m_parser; | |
| 6566 | |
| 6567 RefPtr<CSSValueList> values; | |
| 6568 RefPtr<CSSPrimitiveValue> x; | |
| 6569 RefPtr<CSSPrimitiveValue> y; | |
| 6570 RefPtr<CSSPrimitiveValue> blur; | |
| 6571 RefPtr<CSSPrimitiveValue> spread; | |
| 6572 RefPtr<CSSPrimitiveValue> style; | |
| 6573 RefPtr<CSSPrimitiveValue> color; | |
| 6574 | |
| 6575 bool allowX; | |
| 6576 bool allowY; | |
| 6577 bool allowBlur; | |
| 6578 bool allowSpread; | |
| 6579 bool allowColor; | |
| 6580 bool allowStyle; // inset or not. | |
| 6581 bool allowBreak; | |
| 6582 }; | |
| 6583 | |
| 6584 PassRefPtr<CSSValueList> CSSParser::parseShadow(CSSParserValueList* valueList, C
SSPropertyID propId) | |
| 6585 { | |
| 6586 ShadowParseContext context(propId, this); | |
| 6587 CSSParserValue* val; | |
| 6588 while ((val = valueList->current())) { | |
| 6589 // Check for a comma break first. | |
| 6590 if (val->unit == CSSParserValue::Operator) { | |
| 6591 if (val->iValue != ',' || !context.allowBreak) | |
| 6592 // Other operators aren't legal or we aren't done with the curre
nt shadow | |
| 6593 // value. Treat as invalid. | |
| 6594 return 0; | |
| 6595 // The value is good. Commit it. | |
| 6596 context.commitValue(); | |
| 6597 } else if (validUnit(val, FLength, HTMLStandardMode)) { | |
| 6598 // We required a length and didn't get one. Invalid. | |
| 6599 if (!context.allowLength()) | |
| 6600 return 0; | |
| 6601 | |
| 6602 // Blur radius must be non-negative. | |
| 6603 if (context.allowBlur && !validUnit(val, FLength | FNonNeg, HTMLStan
dardMode)) | |
| 6604 return 0; | |
| 6605 | |
| 6606 // A length is allowed here. Construct the value and add it. | |
| 6607 context.commitLength(val); | |
| 6608 } else if (val->id == CSSValueInset) { | |
| 6609 if (!context.allowStyle) | |
| 6610 return 0; | |
| 6611 | |
| 6612 context.commitStyle(val); | |
| 6613 } else { | |
| 6614 // The only other type of value that's ok is a color value. | |
| 6615 RefPtr<CSSPrimitiveValue> parsedColor; | |
| 6616 bool isColor = ((val->id >= CSSValueAqua && val->id <= CSSValueWindo
wtext) || val->id == CSSValueMenu | |
| 6617 || (val->id >= CSSValueWebkitFocusRingColor && val->
id <= CSSValueWebkitText && inQuirksMode()) | |
| 6618 || val->id == CSSValueCurrentcolor); | |
| 6619 if (isColor) { | |
| 6620 if (!context.allowColor) | |
| 6621 return 0; | |
| 6622 parsedColor = cssValuePool().createIdentifierValue(val->id); | |
| 6623 } | |
| 6624 | |
| 6625 if (!parsedColor) | |
| 6626 // It's not built-in. Try to parse it as a color. | |
| 6627 parsedColor = parseColor(val); | |
| 6628 | |
| 6629 if (!parsedColor || !context.allowColor) | |
| 6630 return 0; // This value is not a color or length and is invalid
or | |
| 6631 // it is a color, but a color isn't allowed at this po
int. | |
| 6632 | |
| 6633 context.commitColor(parsedColor.release()); | |
| 6634 } | |
| 6635 | |
| 6636 valueList->next(); | |
| 6637 } | |
| 6638 | |
| 6639 if (context.allowBreak) { | |
| 6640 context.commitValue(); | |
| 6641 if (context.values && context.values->length()) | |
| 6642 return context.values.release(); | |
| 6643 } | |
| 6644 | |
| 6645 return 0; | |
| 6646 } | |
| 6647 | |
| 6648 bool CSSParser::parseReflect(CSSPropertyID propId, bool important) | |
| 6649 { | |
| 6650 // box-reflect: <direction> <offset> <mask> | |
| 6651 | |
| 6652 // Direction comes first. | |
| 6653 CSSParserValue* val = m_valueList->current(); | |
| 6654 RefPtr<CSSPrimitiveValue> direction; | |
| 6655 if (val->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME) | |
| 6656 direction = createPrimitiveVariableNameValue(val); | |
| 6657 else | |
| 6658 switch (val->id) { | |
| 6659 case CSSValueAbove: | |
| 6660 case CSSValueBelow: | |
| 6661 case CSSValueLeft: | |
| 6662 case CSSValueRight: | |
| 6663 direction = cssValuePool().createIdentifierValue(val->id); | |
| 6664 break; | |
| 6665 default: | |
| 6666 return false; | |
| 6667 } | |
| 6668 | |
| 6669 // The offset comes next. | |
| 6670 val = m_valueList->next(); | |
| 6671 RefPtr<CSSPrimitiveValue> offset; | |
| 6672 if (!val) | |
| 6673 offset = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PX); | |
| 6674 else { | |
| 6675 if (!validUnit(val, FLength | FPercent)) | |
| 6676 return false; | |
| 6677 offset = createPrimitiveNumericValue(val); | |
| 6678 } | |
| 6679 | |
| 6680 // Now for the mask. | |
| 6681 RefPtr<CSSValue> mask; | |
| 6682 val = m_valueList->next(); | |
| 6683 if (val) { | |
| 6684 mask = parseBorderImage(propId); | |
| 6685 if (!mask) | |
| 6686 return false; | |
| 6687 } | |
| 6688 | |
| 6689 RefPtr<CSSReflectValue> reflectValue = CSSReflectValue::create(direction.rel
ease(), offset.release(), mask.release()); | |
| 6690 addProperty(propId, reflectValue.release(), important); | |
| 6691 m_valueList->next(); | |
| 6692 return true; | |
| 6693 } | |
| 6694 | |
| 6695 bool CSSParser::parseFlex(CSSParserValueList* args, bool important) | |
| 6696 { | |
| 6697 if (!args || !args->size() || args->size() > 3) | |
| 6698 return false; | |
| 6699 static const double unsetValue = -1; | |
| 6700 double flexGrow = unsetValue; | |
| 6701 double flexShrink = unsetValue; | |
| 6702 RefPtr<CSSPrimitiveValue> flexBasis; | |
| 6703 | |
| 6704 while (CSSParserValue* arg = args->current()) { | |
| 6705 if (validUnit(arg, FNumber | FNonNeg)) { | |
| 6706 if (flexGrow == unsetValue) | |
| 6707 flexGrow = arg->fValue; | |
| 6708 else if (flexShrink == unsetValue) | |
| 6709 flexShrink = arg->fValue; | |
| 6710 else if (!arg->fValue) { | |
| 6711 // flex only allows a basis of 0 (sans units) if flex-grow and f
lex-shrink values have already been set. | |
| 6712 flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::CSS
_PX); | |
| 6713 } else { | |
| 6714 // We only allow 3 numbers without units if the last value is 0.
E.g., flex:1 1 1 is invalid. | |
| 6715 return false; | |
| 6716 } | |
| 6717 } else if (!flexBasis && (arg->id == CSSValueAuto || validUnit(arg, FLen
gth | FPercent | FNonNeg))) | |
| 6718 flexBasis = parseValidPrimitive(arg->id, arg); | |
| 6719 else { | |
| 6720 // Not a valid arg for flex. | |
| 6721 return false; | |
| 6722 } | |
| 6723 args->next(); | |
| 6724 } | |
| 6725 | |
| 6726 if (flexGrow == unsetValue) | |
| 6727 flexGrow = 1; | |
| 6728 if (flexShrink == unsetValue) | |
| 6729 flexShrink = 1; | |
| 6730 if (!flexBasis) | |
| 6731 flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PX); | |
| 6732 | |
| 6733 addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(clampToFloat(fle
xGrow), CSSPrimitiveValue::CSS_NUMBER), important); | |
| 6734 addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(clampToFloat(f
lexShrink), CSSPrimitiveValue::CSS_NUMBER), important); | |
| 6735 addProperty(CSSPropertyFlexBasis, flexBasis, important); | |
| 6736 return true; | |
| 6737 } | |
| 6738 | |
| 6739 bool CSSParser::parseObjectPosition(bool important) | |
| 6740 { | |
| 6741 RefPtr<CSSValue> xValue; | |
| 6742 RefPtr<CSSValue> yValue; | |
| 6743 parseFillPosition(m_valueList.get(), xValue, yValue); | |
| 6744 if (!xValue || !yValue) | |
| 6745 return false; | |
| 6746 addProperty( | |
| 6747 CSSPropertyObjectPosition, | |
| 6748 createPrimitiveValuePair(toCSSPrimitiveValue(xValue.get()), toCSSPrimiti
veValue(yValue.get()), Pair::KeepIdenticalValues), | |
| 6749 important); | |
| 6750 return true; | |
| 6751 } | |
| 6752 | |
| 6753 struct BorderImageParseContext { | |
| 6754 BorderImageParseContext() | |
| 6755 : m_canAdvance(false) | |
| 6756 , m_allowCommit(true) | |
| 6757 , m_allowImage(true) | |
| 6758 , m_allowImageSlice(true) | |
| 6759 , m_allowRepeat(true) | |
| 6760 , m_allowForwardSlashOperator(false) | |
| 6761 , m_requireWidth(false) | |
| 6762 , m_requireOutset(false) | |
| 6763 {} | |
| 6764 | |
| 6765 bool canAdvance() const { return m_canAdvance; } | |
| 6766 void setCanAdvance(bool canAdvance) { m_canAdvance = canAdvance; } | |
| 6767 | |
| 6768 bool allowCommit() const { return m_allowCommit; } | |
| 6769 bool allowImage() const { return m_allowImage; } | |
| 6770 bool allowImageSlice() const { return m_allowImageSlice; } | |
| 6771 bool allowRepeat() const { return m_allowRepeat; } | |
| 6772 bool allowForwardSlashOperator() const { return m_allowForwardSlashOperator;
} | |
| 6773 | |
| 6774 bool requireWidth() const { return m_requireWidth; } | |
| 6775 bool requireOutset() const { return m_requireOutset; } | |
| 6776 | |
| 6777 void commitImage(PassRefPtr<CSSValue> image) | |
| 6778 { | |
| 6779 m_image = image; | |
| 6780 m_canAdvance = true; | |
| 6781 m_allowCommit = true; | |
| 6782 m_allowImage = m_allowForwardSlashOperator = m_requireWidth = m_requireO
utset = false; | |
| 6783 m_allowImageSlice = !m_imageSlice; | |
| 6784 m_allowRepeat = !m_repeat; | |
| 6785 } | |
| 6786 void commitImageSlice(PassRefPtr<CSSBorderImageSliceValue> slice) | |
| 6787 { | |
| 6788 m_imageSlice = slice; | |
| 6789 m_canAdvance = true; | |
| 6790 m_allowCommit = m_allowForwardSlashOperator = true; | |
| 6791 m_allowImageSlice = m_requireWidth = m_requireOutset = false; | |
| 6792 m_allowImage = !m_image; | |
| 6793 m_allowRepeat = !m_repeat; | |
| 6794 } | |
| 6795 void commitForwardSlashOperator() | |
| 6796 { | |
| 6797 m_canAdvance = true; | |
| 6798 m_allowCommit = m_allowImage = m_allowImageSlice = m_allowRepeat = m_all
owForwardSlashOperator = false; | |
| 6799 if (!m_borderSlice) { | |
| 6800 m_requireWidth = true; | |
| 6801 m_requireOutset = false; | |
| 6802 } else { | |
| 6803 m_requireOutset = true; | |
| 6804 m_requireWidth = false; | |
| 6805 } | |
| 6806 } | |
| 6807 void commitBorderWidth(PassRefPtr<CSSPrimitiveValue> slice) | |
| 6808 { | |
| 6809 m_borderSlice = slice; | |
| 6810 m_canAdvance = true; | |
| 6811 m_allowCommit = m_allowForwardSlashOperator = true; | |
| 6812 m_allowImageSlice = m_requireWidth = m_requireOutset = false; | |
| 6813 m_allowImage = !m_image; | |
| 6814 m_allowRepeat = !m_repeat; | |
| 6815 } | |
| 6816 void commitBorderOutset(PassRefPtr<CSSPrimitiveValue> outset) | |
| 6817 { | |
| 6818 m_outset = outset; | |
| 6819 m_canAdvance = true; | |
| 6820 m_allowCommit = true; | |
| 6821 m_allowImageSlice = m_allowForwardSlashOperator = m_requireWidth = m_req
uireOutset = false; | |
| 6822 m_allowImage = !m_image; | |
| 6823 m_allowRepeat = !m_repeat; | |
| 6824 } | |
| 6825 void commitRepeat(PassRefPtr<CSSValue> repeat) | |
| 6826 { | |
| 6827 m_repeat = repeat; | |
| 6828 m_canAdvance = true; | |
| 6829 m_allowCommit = true; | |
| 6830 m_allowRepeat = m_allowForwardSlashOperator = m_requireWidth = m_require
Outset = false; | |
| 6831 m_allowImageSlice = !m_imageSlice; | |
| 6832 m_allowImage = !m_image; | |
| 6833 } | |
| 6834 | |
| 6835 PassRefPtr<CSSValue> commitCSSValue() | |
| 6836 { | |
| 6837 return createBorderImageValue(m_image, m_imageSlice, m_borderSlice, m_ou
tset, m_repeat); | |
| 6838 } | |
| 6839 | |
| 6840 void commitMaskBoxImage(CSSParser* parser, bool important) | |
| 6841 { | |
| 6842 commitBorderImageProperty(CSSPropertyWebkitMaskBoxImageSource, parser, m
_image, important); | |
| 6843 commitBorderImageProperty(CSSPropertyWebkitMaskBoxImageSlice, parser, m_
imageSlice, important); | |
| 6844 commitBorderImageProperty(CSSPropertyWebkitMaskBoxImageWidth, parser, m_
borderSlice, important); | |
| 6845 commitBorderImageProperty(CSSPropertyWebkitMaskBoxImageOutset, parser, m
_outset, important); | |
| 6846 commitBorderImageProperty(CSSPropertyWebkitMaskBoxImageRepeat, parser, m
_repeat, important); | |
| 6847 } | |
| 6848 | |
| 6849 void commitBorderImage(CSSParser* parser, bool important) | |
| 6850 { | |
| 6851 commitBorderImageProperty(CSSPropertyBorderImageSource, parser, m_image,
important); | |
| 6852 commitBorderImageProperty(CSSPropertyBorderImageSlice, parser, m_imageSl
ice, important); | |
| 6853 commitBorderImageProperty(CSSPropertyBorderImageWidth, parser, m_borderS
lice, important); | |
| 6854 commitBorderImageProperty(CSSPropertyBorderImageOutset, parser, m_outset
, important); | |
| 6855 commitBorderImageProperty(CSSPropertyBorderImageRepeat, parser, m_repeat
, important); | |
| 6856 } | |
| 6857 | |
| 6858 void commitBorderImageProperty(CSSPropertyID propId, CSSParser* parser, Pass
RefPtr<CSSValue> value, bool important) | |
| 6859 { | |
| 6860 if (value) | |
| 6861 parser->addProperty(propId, value, important); | |
| 6862 else | |
| 6863 parser->addProperty(propId, cssValuePool().createImplicitInitialValu
e(), important, true); | |
| 6864 } | |
| 6865 | |
| 6866 bool m_canAdvance; | |
| 6867 | |
| 6868 bool m_allowCommit; | |
| 6869 bool m_allowImage; | |
| 6870 bool m_allowImageSlice; | |
| 6871 bool m_allowRepeat; | |
| 6872 bool m_allowForwardSlashOperator; | |
| 6873 | |
| 6874 bool m_requireWidth; | |
| 6875 bool m_requireOutset; | |
| 6876 | |
| 6877 RefPtr<CSSValue> m_image; | |
| 6878 RefPtr<CSSBorderImageSliceValue> m_imageSlice; | |
| 6879 RefPtr<CSSPrimitiveValue> m_borderSlice; | |
| 6880 RefPtr<CSSPrimitiveValue> m_outset; | |
| 6881 | |
| 6882 RefPtr<CSSValue> m_repeat; | |
| 6883 }; | |
| 6884 | |
| 6885 static bool buildBorderImageParseContext(CSSParser& parser, CSSPropertyID propId
, BorderImageParseContext& context) | |
| 6886 { | |
| 6887 ShorthandScope scope(&parser, propId); | |
| 6888 while (CSSParserValue* val = parser.m_valueList->current()) { | |
| 6889 context.setCanAdvance(false); | |
| 6890 | |
| 6891 if (!context.canAdvance() && context.allowForwardSlashOperator() && isFo
rwardSlashOperator(val)) | |
| 6892 context.commitForwardSlashOperator(); | |
| 6893 | |
| 6894 if (!context.canAdvance() && context.allowImage()) { | |
| 6895 if (val->unit == CSSPrimitiveValue::CSS_URI) { | |
| 6896 context.commitImage(CSSImageValue::create(parser.m_context.compl
eteURL(val->string))); | |
| 6897 } else if (isGeneratedImageValue(val)) { | |
| 6898 RefPtr<CSSValue> value; | |
| 6899 if (parser.parseGeneratedImage(parser.m_valueList.get(), value)) | |
| 6900 context.commitImage(value.release()); | |
| 6901 else | |
| 6902 return false; | |
| 6903 } else if (val->unit == CSSParserValue::Function && equalIgnoringCas
e(val->function->name, "-webkit-image-set(")) { | |
| 6904 RefPtr<CSSValue> value = parser.parseImageSet(parser.m_valueList
.get()); | |
| 6905 if (value) | |
| 6906 context.commitImage(value.release()); | |
| 6907 else | |
| 6908 return false; | |
| 6909 } else if (val->id == CSSValueNone) | |
| 6910 context.commitImage(cssValuePool().createIdentifierValue(CSSValu
eNone)); | |
| 6911 } | |
| 6912 | |
| 6913 if (!context.canAdvance() && context.allowImageSlice()) { | |
| 6914 RefPtr<CSSBorderImageSliceValue> imageSlice; | |
| 6915 if (parser.parseBorderImageSlice(propId, imageSlice)) | |
| 6916 context.commitImageSlice(imageSlice.release()); | |
| 6917 } | |
| 6918 | |
| 6919 if (!context.canAdvance() && context.allowRepeat()) { | |
| 6920 RefPtr<CSSValue> repeat; | |
| 6921 if (parser.parseBorderImageRepeat(repeat)) | |
| 6922 context.commitRepeat(repeat.release()); | |
| 6923 } | |
| 6924 | |
| 6925 if (!context.canAdvance() && context.requireWidth()) { | |
| 6926 RefPtr<CSSPrimitiveValue> borderSlice; | |
| 6927 if (parser.parseBorderImageWidth(borderSlice)) | |
| 6928 context.commitBorderWidth(borderSlice.release()); | |
| 6929 } | |
| 6930 | |
| 6931 if (!context.canAdvance() && context.requireOutset()) { | |
| 6932 RefPtr<CSSPrimitiveValue> borderOutset; | |
| 6933 if (parser.parseBorderImageOutset(borderOutset)) | |
| 6934 context.commitBorderOutset(borderOutset.release()); | |
| 6935 } | |
| 6936 | |
| 6937 if (!context.canAdvance()) | |
| 6938 return false; | |
| 6939 | |
| 6940 parser.m_valueList->next(); | |
| 6941 } | |
| 6942 | |
| 6943 return context.allowCommit(); | |
| 6944 } | |
| 6945 | |
| 6946 bool CSSParser::parseBorderImageShorthand(CSSPropertyID propId, bool important) | |
| 6947 { | |
| 6948 BorderImageParseContext context; | |
| 6949 if (buildBorderImageParseContext(*this, propId, context)) { | |
| 6950 switch (propId) { | |
| 6951 case CSSPropertyWebkitMaskBoxImage: | |
| 6952 context.commitMaskBoxImage(this, important); | |
| 6953 return true; | |
| 6954 case CSSPropertyBorderImage: | |
| 6955 context.commitBorderImage(this, important); | |
| 6956 return true; | |
| 6957 default: | |
| 6958 ASSERT_NOT_REACHED(); | |
| 6959 return false; | |
| 6960 } | |
| 6961 } | |
| 6962 return false; | |
| 6963 } | |
| 6964 | |
| 6965 PassRefPtr<CSSValue> CSSParser::parseBorderImage(CSSPropertyID propId) | |
| 6966 { | |
| 6967 BorderImageParseContext context; | |
| 6968 if (buildBorderImageParseContext(*this, propId, context)) { | |
| 6969 return context.commitCSSValue(); | |
| 6970 } | |
| 6971 return 0; | |
| 6972 } | |
| 6973 | |
| 6974 static bool isBorderImageRepeatKeyword(int id) | |
| 6975 { | |
| 6976 return id == CSSValueStretch || id == CSSValueRepeat || id == CSSValueSpace
|| id == CSSValueRound; | |
| 6977 } | |
| 6978 | |
| 6979 bool CSSParser::parseBorderImageRepeat(RefPtr<CSSValue>& result) | |
| 6980 { | |
| 6981 RefPtr<CSSPrimitiveValue> firstValue; | |
| 6982 RefPtr<CSSPrimitiveValue> secondValue; | |
| 6983 CSSParserValue* val = m_valueList->current(); | |
| 6984 if (!val) | |
| 6985 return false; | |
| 6986 if (isBorderImageRepeatKeyword(val->id)) | |
| 6987 firstValue = cssValuePool().createIdentifierValue(val->id); | |
| 6988 else | |
| 6989 return false; | |
| 6990 | |
| 6991 val = m_valueList->next(); | |
| 6992 if (val) { | |
| 6993 if (isBorderImageRepeatKeyword(val->id)) | |
| 6994 secondValue = cssValuePool().createIdentifierValue(val->id); | |
| 6995 else if (!inShorthand()) { | |
| 6996 // If we're not parsing a shorthand then we are invalid. | |
| 6997 return false; | |
| 6998 } else { | |
| 6999 // We need to rewind the value list, so that when its advanced we'll | |
| 7000 // end up back at this value. | |
| 7001 m_valueList->previous(); | |
| 7002 secondValue = firstValue; | |
| 7003 } | |
| 7004 } else | |
| 7005 secondValue = firstValue; | |
| 7006 | |
| 7007 result = createPrimitiveValuePair(firstValue, secondValue); | |
| 7008 return true; | |
| 7009 } | |
| 7010 | |
| 7011 class BorderImageSliceParseContext { | |
| 7012 public: | |
| 7013 BorderImageSliceParseContext(CSSParser* parser) | |
| 7014 : m_parser(parser) | |
| 7015 , m_allowNumber(true) | |
| 7016 , m_allowFill(true) | |
| 7017 , m_allowFinalCommit(false) | |
| 7018 , m_fill(false) | |
| 7019 { } | |
| 7020 | |
| 7021 bool allowNumber() const { return m_allowNumber; } | |
| 7022 bool allowFill() const { return m_allowFill; } | |
| 7023 bool allowFinalCommit() const { return m_allowFinalCommit; } | |
| 7024 CSSPrimitiveValue* top() const { return m_top.get(); } | |
| 7025 | |
| 7026 void commitNumber(CSSParserValue* v) | |
| 7027 { | |
| 7028 RefPtr<CSSPrimitiveValue> val = m_parser->createPrimitiveNumericValue(v)
; | |
| 7029 if (!m_top) | |
| 7030 m_top = val; | |
| 7031 else if (!m_right) | |
| 7032 m_right = val; | |
| 7033 else if (!m_bottom) | |
| 7034 m_bottom = val; | |
| 7035 else { | |
| 7036 ASSERT(!m_left); | |
| 7037 m_left = val; | |
| 7038 } | |
| 7039 | |
| 7040 m_allowNumber = !m_left; | |
| 7041 m_allowFinalCommit = true; | |
| 7042 } | |
| 7043 | |
| 7044 void commitFill() { m_fill = true; m_allowFill = false; m_allowNumber = !m_t
op; } | |
| 7045 | |
| 7046 PassRefPtr<CSSBorderImageSliceValue> commitBorderImageSlice() | |
| 7047 { | |
| 7048 // We need to clone and repeat values for any omissions. | |
| 7049 ASSERT(m_top); | |
| 7050 if (!m_right) { | |
| 7051 m_right = m_top; | |
| 7052 m_bottom = m_top; | |
| 7053 m_left = m_top; | |
| 7054 } | |
| 7055 if (!m_bottom) { | |
| 7056 m_bottom = m_top; | |
| 7057 m_left = m_right; | |
| 7058 } | |
| 7059 if (!m_left) | |
| 7060 m_left = m_right; | |
| 7061 | |
| 7062 // Now build a rect value to hold all four of our primitive values. | |
| 7063 RefPtr<Quad> quad = Quad::create(); | |
| 7064 quad->setTop(m_top); | |
| 7065 quad->setRight(m_right); | |
| 7066 quad->setBottom(m_bottom); | |
| 7067 quad->setLeft(m_left); | |
| 7068 | |
| 7069 // Make our new border image value now. | |
| 7070 return CSSBorderImageSliceValue::create(cssValuePool().createValue(quad.
release()), m_fill); | |
| 7071 } | |
| 7072 | |
| 7073 private: | |
| 7074 CSSParser* m_parser; | |
| 7075 | |
| 7076 bool m_allowNumber; | |
| 7077 bool m_allowFill; | |
| 7078 bool m_allowFinalCommit; | |
| 7079 | |
| 7080 RefPtr<CSSPrimitiveValue> m_top; | |
| 7081 RefPtr<CSSPrimitiveValue> m_right; | |
| 7082 RefPtr<CSSPrimitiveValue> m_bottom; | |
| 7083 RefPtr<CSSPrimitiveValue> m_left; | |
| 7084 | |
| 7085 bool m_fill; | |
| 7086 }; | |
| 7087 | |
| 7088 bool CSSParser::parseBorderImageSlice(CSSPropertyID propId, RefPtr<CSSBorderImag
eSliceValue>& result) | |
| 7089 { | |
| 7090 BorderImageSliceParseContext context(this); | |
| 7091 CSSParserValue* val; | |
| 7092 while ((val = m_valueList->current())) { | |
| 7093 // FIXME calc() http://webkit.org/b/16662 : calc is parsed but values ar
e not created yet. | |
| 7094 if (context.allowNumber() && !isCalculation(val) && validUnit(val, FInte
ger | FNonNeg | FPercent, HTMLStandardMode)) { | |
| 7095 context.commitNumber(val); | |
| 7096 } else if (context.allowFill() && val->id == CSSValueFill) | |
| 7097 context.commitFill(); | |
| 7098 else if (!inShorthand()) { | |
| 7099 // If we're not parsing a shorthand then we are invalid. | |
| 7100 return false; | |
| 7101 } else { | |
| 7102 if (context.allowFinalCommit()) { | |
| 7103 // We're going to successfully parse, but we don't want to consu
me this token. | |
| 7104 m_valueList->previous(); | |
| 7105 } | |
| 7106 break; | |
| 7107 } | |
| 7108 m_valueList->next(); | |
| 7109 } | |
| 7110 | |
| 7111 if (context.allowFinalCommit()) { | |
| 7112 // FIXME: For backwards compatibility, -webkit-border-image, -webkit-mas
k-box-image and -webkit-box-reflect have to do a fill by default. | |
| 7113 // FIXME: What do we do with -webkit-box-reflect and -webkit-mask-box-im
age? Probably just have to leave them filling... | |
| 7114 if (propId == CSSPropertyWebkitBorderImage || propId == CSSPropertyWebki
tMaskBoxImage || propId == CSSPropertyWebkitBoxReflect) | |
| 7115 context.commitFill(); | |
| 7116 | |
| 7117 // Need to fully commit as a single value. | |
| 7118 result = context.commitBorderImageSlice(); | |
| 7119 return true; | |
| 7120 } | |
| 7121 | |
| 7122 return false; | |
| 7123 } | |
| 7124 | |
| 7125 class BorderImageQuadParseContext { | |
| 7126 public: | |
| 7127 BorderImageQuadParseContext(CSSParser* parser) | |
| 7128 : m_parser(parser) | |
| 7129 , m_allowNumber(true) | |
| 7130 , m_allowFinalCommit(false) | |
| 7131 { } | |
| 7132 | |
| 7133 bool allowNumber() const { return m_allowNumber; } | |
| 7134 bool allowFinalCommit() const { return m_allowFinalCommit; } | |
| 7135 CSSPrimitiveValue* top() const { return m_top.get(); } | |
| 7136 | |
| 7137 void commitNumber(CSSParserValue* v) | |
| 7138 { | |
| 7139 RefPtr<CSSPrimitiveValue> val; | |
| 7140 if (v->id == CSSValueAuto) | |
| 7141 val = cssValuePool().createIdentifierValue(v->id); | |
| 7142 else | |
| 7143 val = m_parser->createPrimitiveNumericValue(v); | |
| 7144 | |
| 7145 if (!m_top) | |
| 7146 m_top = val; | |
| 7147 else if (!m_right) | |
| 7148 m_right = val; | |
| 7149 else if (!m_bottom) | |
| 7150 m_bottom = val; | |
| 7151 else { | |
| 7152 ASSERT(!m_left); | |
| 7153 m_left = val; | |
| 7154 } | |
| 7155 | |
| 7156 m_allowNumber = !m_left; | |
| 7157 m_allowFinalCommit = true; | |
| 7158 } | |
| 7159 | |
| 7160 void setAllowFinalCommit() { m_allowFinalCommit = true; } | |
| 7161 void setTop(PassRefPtr<CSSPrimitiveValue> val) { m_top = val; } | |
| 7162 | |
| 7163 PassRefPtr<CSSPrimitiveValue> commitBorderImageQuad() | |
| 7164 { | |
| 7165 // We need to clone and repeat values for any omissions. | |
| 7166 ASSERT(m_top); | |
| 7167 if (!m_right) { | |
| 7168 m_right = m_top; | |
| 7169 m_bottom = m_top; | |
| 7170 m_left = m_top; | |
| 7171 } | |
| 7172 if (!m_bottom) { | |
| 7173 m_bottom = m_top; | |
| 7174 m_left = m_right; | |
| 7175 } | |
| 7176 if (!m_left) | |
| 7177 m_left = m_right; | |
| 7178 | |
| 7179 // Now build a quad value to hold all four of our primitive values. | |
| 7180 RefPtr<Quad> quad = Quad::create(); | |
| 7181 quad->setTop(m_top); | |
| 7182 quad->setRight(m_right); | |
| 7183 quad->setBottom(m_bottom); | |
| 7184 quad->setLeft(m_left); | |
| 7185 | |
| 7186 // Make our new value now. | |
| 7187 return cssValuePool().createValue(quad.release()); | |
| 7188 } | |
| 7189 | |
| 7190 private: | |
| 7191 CSSParser* m_parser; | |
| 7192 | |
| 7193 bool m_allowNumber; | |
| 7194 bool m_allowFinalCommit; | |
| 7195 | |
| 7196 RefPtr<CSSPrimitiveValue> m_top; | |
| 7197 RefPtr<CSSPrimitiveValue> m_right; | |
| 7198 RefPtr<CSSPrimitiveValue> m_bottom; | |
| 7199 RefPtr<CSSPrimitiveValue> m_left; | |
| 7200 }; | |
| 7201 | |
| 7202 bool CSSParser::parseBorderImageQuad(Units validUnits, RefPtr<CSSPrimitiveValue>
& result) | |
| 7203 { | |
| 7204 BorderImageQuadParseContext context(this); | |
| 7205 CSSParserValue* val; | |
| 7206 while ((val = m_valueList->current())) { | |
| 7207 if (context.allowNumber() && (validUnit(val, validUnits, HTMLStandardMod
e) || val->id == CSSValueAuto)) { | |
| 7208 context.commitNumber(val); | |
| 7209 } else if (!inShorthand()) { | |
| 7210 // If we're not parsing a shorthand then we are invalid. | |
| 7211 return false; | |
| 7212 } else { | |
| 7213 if (context.allowFinalCommit()) | |
| 7214 m_valueList->previous(); // The shorthand loop will advance back
to this point. | |
| 7215 break; | |
| 7216 } | |
| 7217 m_valueList->next(); | |
| 7218 } | |
| 7219 | |
| 7220 if (context.allowFinalCommit()) { | |
| 7221 // Need to fully commit as a single value. | |
| 7222 result = context.commitBorderImageQuad(); | |
| 7223 return true; | |
| 7224 } | |
| 7225 return false; | |
| 7226 } | |
| 7227 | |
| 7228 bool CSSParser::parseBorderImageWidth(RefPtr<CSSPrimitiveValue>& result) | |
| 7229 { | |
| 7230 return parseBorderImageQuad(FLength | FNumber | FNonNeg | FPercent, result); | |
| 7231 } | |
| 7232 | |
| 7233 bool CSSParser::parseBorderImageOutset(RefPtr<CSSPrimitiveValue>& result) | |
| 7234 { | |
| 7235 return parseBorderImageQuad(FLength | FNumber | FNonNeg, result); | |
| 7236 } | |
| 7237 | |
| 7238 static void completeBorderRadii(RefPtr<CSSPrimitiveValue> radii[4]) | |
| 7239 { | |
| 7240 if (radii[3]) | |
| 7241 return; | |
| 7242 if (!radii[2]) { | |
| 7243 if (!radii[1]) | |
| 7244 radii[1] = radii[0]; | |
| 7245 radii[2] = radii[0]; | |
| 7246 } | |
| 7247 radii[3] = radii[1]; | |
| 7248 } | |
| 7249 | |
| 7250 bool CSSParser::parseBorderRadius(CSSPropertyID propId, bool important) | |
| 7251 { | |
| 7252 unsigned num = m_valueList->size(); | |
| 7253 if (num > 9) | |
| 7254 return false; | |
| 7255 | |
| 7256 ShorthandScope scope(this, propId); | |
| 7257 RefPtr<CSSPrimitiveValue> radii[2][4]; | |
| 7258 | |
| 7259 unsigned indexAfterSlash = 0; | |
| 7260 for (unsigned i = 0; i < num; ++i) { | |
| 7261 CSSParserValue* value = m_valueList->valueAt(i); | |
| 7262 if (value->unit == CSSParserValue::Operator) { | |
| 7263 if (value->iValue != '/') | |
| 7264 return false; | |
| 7265 | |
| 7266 if (!i || indexAfterSlash || i + 1 == num || num > i + 5) | |
| 7267 return false; | |
| 7268 | |
| 7269 indexAfterSlash = i + 1; | |
| 7270 completeBorderRadii(radii[0]); | |
| 7271 continue; | |
| 7272 } | |
| 7273 | |
| 7274 if (i - indexAfterSlash >= 4) | |
| 7275 return false; | |
| 7276 | |
| 7277 if (!validUnit(value, FLength | FPercent | FNonNeg)) | |
| 7278 return false; | |
| 7279 | |
| 7280 RefPtr<CSSPrimitiveValue> radius = createPrimitiveNumericValue(value); | |
| 7281 | |
| 7282 if (!indexAfterSlash) { | |
| 7283 radii[0][i] = radius; | |
| 7284 | |
| 7285 // Legacy syntax: -webkit-border-radius: l1 l2; is equivalent to bor
der-radius: l1 / l2; | |
| 7286 if (num == 2 && propId == CSSPropertyWebkitBorderRadius) { | |
| 7287 indexAfterSlash = 1; | |
| 7288 completeBorderRadii(radii[0]); | |
| 7289 } | |
| 7290 } else | |
| 7291 radii[1][i - indexAfterSlash] = radius.release(); | |
| 7292 } | |
| 7293 | |
| 7294 if (!indexAfterSlash) { | |
| 7295 completeBorderRadii(radii[0]); | |
| 7296 for (unsigned i = 0; i < 4; ++i) | |
| 7297 radii[1][i] = radii[0][i]; | |
| 7298 } else | |
| 7299 completeBorderRadii(radii[1]); | |
| 7300 | |
| 7301 ImplicitScope implicitScope(this, PropertyImplicit); | |
| 7302 addProperty(CSSPropertyBorderTopLeftRadius, createPrimitiveValuePair(radii[0
][0].release(), radii[1][0].release()), important); | |
| 7303 addProperty(CSSPropertyBorderTopRightRadius, createPrimitiveValuePair(radii[
0][1].release(), radii[1][1].release()), important); | |
| 7304 addProperty(CSSPropertyBorderBottomRightRadius, createPrimitiveValuePair(rad
ii[0][2].release(), radii[1][2].release()), important); | |
| 7305 addProperty(CSSPropertyBorderBottomLeftRadius, createPrimitiveValuePair(radi
i[0][3].release(), radii[1][3].release()), important); | |
| 7306 return true; | |
| 7307 } | |
| 7308 | |
| 7309 bool CSSParser::parseAspectRatio(bool important) | |
| 7310 { | |
| 7311 unsigned num = m_valueList->size(); | |
| 7312 if (num == 1 && m_valueList->valueAt(0)->id == CSSValueNone) { | |
| 7313 addProperty(CSSPropertyWebkitAspectRatio, cssValuePool().createIdentifie
rValue(CSSValueNone), important); | |
| 7314 return true; | |
| 7315 } | |
| 7316 | |
| 7317 if (num != 3) | |
| 7318 return false; | |
| 7319 | |
| 7320 CSSParserValue* lvalue = m_valueList->valueAt(0); | |
| 7321 CSSParserValue* op = m_valueList->valueAt(1); | |
| 7322 CSSParserValue* rvalue = m_valueList->valueAt(2); | |
| 7323 | |
| 7324 if (!isForwardSlashOperator(op)) | |
| 7325 return false; | |
| 7326 | |
| 7327 if (!validUnit(lvalue, FNumber | FNonNeg) || !validUnit(rvalue, FNumber | FN
onNeg)) | |
| 7328 return false; | |
| 7329 | |
| 7330 if (!lvalue->fValue || !rvalue->fValue) | |
| 7331 return false; | |
| 7332 | |
| 7333 addProperty(CSSPropertyWebkitAspectRatio, CSSAspectRatioValue::create(narrow
PrecisionToFloat(lvalue->fValue), narrowPrecisionToFloat(rvalue->fValue)), impor
tant); | |
| 7334 | |
| 7335 return true; | |
| 7336 } | |
| 7337 | |
| 7338 bool CSSParser::parseCounter(CSSPropertyID propId, int defaultValue, bool import
ant) | |
| 7339 { | |
| 7340 enum { ID, VAL } state = ID; | |
| 7341 | |
| 7342 RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); | |
| 7343 RefPtr<CSSPrimitiveValue> counterName; | |
| 7344 | |
| 7345 while (true) { | |
| 7346 CSSParserValue* val = m_valueList->current(); | |
| 7347 switch (state) { | |
| 7348 case ID: | |
| 7349 if (val && val->unit == CSSPrimitiveValue::CSS_IDENT) { | |
| 7350 counterName = createPrimitiveStringValue(val); | |
| 7351 state = VAL; | |
| 7352 m_valueList->next(); | |
| 7353 continue; | |
| 7354 } | |
| 7355 break; | |
| 7356 case VAL: { | |
| 7357 int i = defaultValue; | |
| 7358 if (val && val->unit == CSSPrimitiveValue::CSS_NUMBER) { | |
| 7359 i = clampToInteger(val->fValue); | |
| 7360 m_valueList->next(); | |
| 7361 } | |
| 7362 | |
| 7363 list->append(createPrimitiveValuePair(counterName.release(), | |
| 7364 cssValuePool().createValue(i, CSSPrimitiveValue::CSS_NUMBER)
)); | |
| 7365 state = ID; | |
| 7366 continue; | |
| 7367 } | |
| 7368 } | |
| 7369 break; | |
| 7370 } | |
| 7371 | |
| 7372 if (list->length() > 0) { | |
| 7373 addProperty(propId, list.release(), important); | |
| 7374 return true; | |
| 7375 } | |
| 7376 | |
| 7377 return false; | |
| 7378 } | |
| 7379 | |
| 7380 // This should go away once we drop support for -webkit-gradient | |
| 7381 static PassRefPtr<CSSPrimitiveValue> parseDeprecatedGradientPoint(CSSParserValue
* a, bool horizontal) | |
| 7382 { | |
| 7383 RefPtr<CSSPrimitiveValue> result; | |
| 7384 if (a->unit == CSSPrimitiveValue::CSS_IDENT) { | |
| 7385 if ((equalIgnoringCase(a, "left") && horizontal) | |
| 7386 || (equalIgnoringCase(a, "top") && !horizontal)) | |
| 7387 result = cssValuePool().createValue(0., CSSPrimitiveValue::CSS_PERCE
NTAGE); | |
| 7388 else if ((equalIgnoringCase(a, "right") && horizontal) | |
| 7389 || (equalIgnoringCase(a, "bottom") && !horizontal)) | |
| 7390 result = cssValuePool().createValue(100., CSSPrimitiveValue::CSS_PER
CENTAGE); | |
| 7391 else if (equalIgnoringCase(a, "center")) | |
| 7392 result = cssValuePool().createValue(50., CSSPrimitiveValue::CSS_PERC
ENTAGE); | |
| 7393 } else if (a->unit == CSSPrimitiveValue::CSS_NUMBER || a->unit == CSSPrimiti
veValue::CSS_PERCENTAGE) | |
| 7394 result = cssValuePool().createValue(a->fValue, static_cast<CSSPrimitiveV
alue::UnitTypes>(a->unit)); | |
| 7395 return result; | |
| 7396 } | |
| 7397 | |
| 7398 static bool parseDeprecatedGradientColorStop(CSSParser* p, CSSParserValue* a, CS
SGradientColorStop& stop) | |
| 7399 { | |
| 7400 if (a->unit != CSSParserValue::Function) | |
| 7401 return false; | |
| 7402 | |
| 7403 if (!equalIgnoringCase(a->function->name, "from(") && | |
| 7404 !equalIgnoringCase(a->function->name, "to(") && | |
| 7405 !equalIgnoringCase(a->function->name, "color-stop(")) | |
| 7406 return false; | |
| 7407 | |
| 7408 CSSParserValueList* args = a->function->args.get(); | |
| 7409 if (!args) | |
| 7410 return false; | |
| 7411 | |
| 7412 if (equalIgnoringCase(a->function->name, "from(") | |
| 7413 || equalIgnoringCase(a->function->name, "to(")) { | |
| 7414 // The "from" and "to" stops expect 1 argument. | |
| 7415 if (args->size() != 1) | |
| 7416 return false; | |
| 7417 | |
| 7418 if (equalIgnoringCase(a->function->name, "from(")) | |
| 7419 stop.m_position = cssValuePool().createValue(0, CSSPrimitiveValue::C
SS_NUMBER); | |
| 7420 else | |
| 7421 stop.m_position = cssValuePool().createValue(1, CSSPrimitiveValue::C
SS_NUMBER); | |
| 7422 | |
| 7423 CSSValueID id = args->current()->id; | |
| 7424 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWin
dowtext) || id == CSSValueMenu) | |
| 7425 stop.m_color = cssValuePool().createIdentifierValue(id); | |
| 7426 else | |
| 7427 stop.m_color = p->parseColor(args->current()); | |
| 7428 if (!stop.m_color) | |
| 7429 return false; | |
| 7430 } | |
| 7431 | |
| 7432 // The "color-stop" function expects 3 arguments. | |
| 7433 if (equalIgnoringCase(a->function->name, "color-stop(")) { | |
| 7434 if (args->size() != 3) | |
| 7435 return false; | |
| 7436 | |
| 7437 CSSParserValue* stopArg = args->current(); | |
| 7438 if (stopArg->unit == CSSPrimitiveValue::CSS_PERCENTAGE) | |
| 7439 stop.m_position = cssValuePool().createValue(stopArg->fValue / 100,
CSSPrimitiveValue::CSS_NUMBER); | |
| 7440 else if (stopArg->unit == CSSPrimitiveValue::CSS_NUMBER) | |
| 7441 stop.m_position = cssValuePool().createValue(stopArg->fValue, CSSPri
mitiveValue::CSS_NUMBER); | |
| 7442 else | |
| 7443 return false; | |
| 7444 | |
| 7445 stopArg = args->next(); | |
| 7446 if (stopArg->unit != CSSParserValue::Operator || stopArg->iValue != ',') | |
| 7447 return false; | |
| 7448 | |
| 7449 stopArg = args->next(); | |
| 7450 CSSValueID id = stopArg->id; | |
| 7451 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWin
dowtext) || id == CSSValueMenu) | |
| 7452 stop.m_color = cssValuePool().createIdentifierValue(id); | |
| 7453 else | |
| 7454 stop.m_color = p->parseColor(stopArg); | |
| 7455 if (!stop.m_color) | |
| 7456 return false; | |
| 7457 } | |
| 7458 | |
| 7459 return true; | |
| 7460 } | |
| 7461 | |
| 7462 bool CSSParser::parseDeprecatedGradient(CSSParserValueList* valueList, RefPtr<CS
SValue>& gradient) | |
| 7463 { | |
| 7464 // Walk the arguments. | |
| 7465 CSSParserValueList* args = valueList->current()->function->args.get(); | |
| 7466 if (!args || args->size() == 0) | |
| 7467 return false; | |
| 7468 | |
| 7469 // The first argument is the gradient type. It is an identifier. | |
| 7470 CSSGradientType gradientType; | |
| 7471 CSSParserValue* a = args->current(); | |
| 7472 if (!a || a->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 7473 return false; | |
| 7474 if (equalIgnoringCase(a, "linear")) | |
| 7475 gradientType = CSSDeprecatedLinearGradient; | |
| 7476 else if (equalIgnoringCase(a, "radial")) | |
| 7477 gradientType = CSSDeprecatedRadialGradient; | |
| 7478 else | |
| 7479 return false; | |
| 7480 | |
| 7481 RefPtr<CSSGradientValue> result; | |
| 7482 switch (gradientType) { | |
| 7483 case CSSDeprecatedLinearGradient: | |
| 7484 result = CSSLinearGradientValue::create(NonRepeating, gradientType); | |
| 7485 break; | |
| 7486 case CSSDeprecatedRadialGradient: | |
| 7487 result = CSSRadialGradientValue::create(NonRepeating, gradientType); | |
| 7488 break; | |
| 7489 default: | |
| 7490 // The rest of the gradient types shouldn't appear here. | |
| 7491 ASSERT_NOT_REACHED(); | |
| 7492 } | |
| 7493 | |
| 7494 // Comma. | |
| 7495 a = args->next(); | |
| 7496 if (!isComma(a)) | |
| 7497 return false; | |
| 7498 | |
| 7499 // Next comes the starting point for the gradient as an x y pair. There is
no | |
| 7500 // comma between the x and the y values. | |
| 7501 // First X. It can be left, right, number or percent. | |
| 7502 a = args->next(); | |
| 7503 if (!a) | |
| 7504 return false; | |
| 7505 RefPtr<CSSPrimitiveValue> point = parseDeprecatedGradientPoint(a, true); | |
| 7506 if (!point) | |
| 7507 return false; | |
| 7508 result->setFirstX(point.release()); | |
| 7509 | |
| 7510 // First Y. It can be top, bottom, number or percent. | |
| 7511 a = args->next(); | |
| 7512 if (!a) | |
| 7513 return false; | |
| 7514 point = parseDeprecatedGradientPoint(a, false); | |
| 7515 if (!point) | |
| 7516 return false; | |
| 7517 result->setFirstY(point.release()); | |
| 7518 | |
| 7519 // Comma after the first point. | |
| 7520 a = args->next(); | |
| 7521 if (!isComma(a)) | |
| 7522 return false; | |
| 7523 | |
| 7524 // For radial gradients only, we now expect a numeric radius. | |
| 7525 if (gradientType == CSSDeprecatedRadialGradient) { | |
| 7526 a = args->next(); | |
| 7527 if (!a || a->unit != CSSPrimitiveValue::CSS_NUMBER) | |
| 7528 return false; | |
| 7529 toCSSRadialGradientValue(result.get())->setFirstRadius(createPrimitiveNu
mericValue(a)); | |
| 7530 | |
| 7531 // Comma after the first radius. | |
| 7532 a = args->next(); | |
| 7533 if (!isComma(a)) | |
| 7534 return false; | |
| 7535 } | |
| 7536 | |
| 7537 // Next is the ending point for the gradient as an x, y pair. | |
| 7538 // Second X. It can be left, right, number or percent. | |
| 7539 a = args->next(); | |
| 7540 if (!a) | |
| 7541 return false; | |
| 7542 point = parseDeprecatedGradientPoint(a, true); | |
| 7543 if (!point) | |
| 7544 return false; | |
| 7545 result->setSecondX(point.release()); | |
| 7546 | |
| 7547 // Second Y. It can be top, bottom, number or percent. | |
| 7548 a = args->next(); | |
| 7549 if (!a) | |
| 7550 return false; | |
| 7551 point = parseDeprecatedGradientPoint(a, false); | |
| 7552 if (!point) | |
| 7553 return false; | |
| 7554 result->setSecondY(point.release()); | |
| 7555 | |
| 7556 // For radial gradients only, we now expect the second radius. | |
| 7557 if (gradientType == CSSDeprecatedRadialGradient) { | |
| 7558 // Comma after the second point. | |
| 7559 a = args->next(); | |
| 7560 if (!isComma(a)) | |
| 7561 return false; | |
| 7562 | |
| 7563 a = args->next(); | |
| 7564 if (!a || a->unit != CSSPrimitiveValue::CSS_NUMBER) | |
| 7565 return false; | |
| 7566 toCSSRadialGradientValue(result.get())->setSecondRadius(createPrimitiveN
umericValue(a)); | |
| 7567 } | |
| 7568 | |
| 7569 // We now will accept any number of stops (0 or more). | |
| 7570 a = args->next(); | |
| 7571 while (a) { | |
| 7572 // Look for the comma before the next stop. | |
| 7573 if (!isComma(a)) | |
| 7574 return false; | |
| 7575 | |
| 7576 // Now examine the stop itself. | |
| 7577 a = args->next(); | |
| 7578 if (!a) | |
| 7579 return false; | |
| 7580 | |
| 7581 // The function name needs to be one of "from", "to", or "color-stop." | |
| 7582 CSSGradientColorStop stop; | |
| 7583 if (!parseDeprecatedGradientColorStop(this, a, stop)) | |
| 7584 return false; | |
| 7585 result->addStop(stop); | |
| 7586 | |
| 7587 // Advance | |
| 7588 a = args->next(); | |
| 7589 } | |
| 7590 | |
| 7591 gradient = result.release(); | |
| 7592 return true; | |
| 7593 } | |
| 7594 | |
| 7595 static PassRefPtr<CSSPrimitiveValue> valueFromSideKeyword(CSSParserValue* a, boo
l& isHorizontal) | |
| 7596 { | |
| 7597 if (a->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 7598 return 0; | |
| 7599 | |
| 7600 switch (a->id) { | |
| 7601 case CSSValueLeft: | |
| 7602 case CSSValueRight: | |
| 7603 isHorizontal = true; | |
| 7604 break; | |
| 7605 case CSSValueTop: | |
| 7606 case CSSValueBottom: | |
| 7607 isHorizontal = false; | |
| 7608 break; | |
| 7609 default: | |
| 7610 return 0; | |
| 7611 } | |
| 7612 return cssValuePool().createIdentifierValue(a->id); | |
| 7613 } | |
| 7614 | |
| 7615 static PassRefPtr<CSSPrimitiveValue> parseGradientColorOrKeyword(CSSParser* p, C
SSParserValue* value) | |
| 7616 { | |
| 7617 CSSValueID id = value->id; | |
| 7618 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowt
ext) || id == CSSValueMenu || id == CSSValueCurrentcolor) | |
| 7619 return cssValuePool().createIdentifierValue(id); | |
| 7620 | |
| 7621 return p->parseColor(value); | |
| 7622 } | |
| 7623 | |
| 7624 bool CSSParser::parseDeprecatedLinearGradient(CSSParserValueList* valueList, Ref
Ptr<CSSValue>& gradient, CSSGradientRepeat repeating) | |
| 7625 { | |
| 7626 RefPtr<CSSLinearGradientValue> result = CSSLinearGradientValue::create(repea
ting, CSSPrefixedLinearGradient); | |
| 7627 | |
| 7628 // Walk the arguments. | |
| 7629 CSSParserValueList* args = valueList->current()->function->args.get(); | |
| 7630 if (!args || !args->size()) | |
| 7631 return false; | |
| 7632 | |
| 7633 CSSParserValue* a = args->current(); | |
| 7634 if (!a) | |
| 7635 return false; | |
| 7636 | |
| 7637 bool expectComma = false; | |
| 7638 // Look for angle. | |
| 7639 if (validUnit(a, FAngle, HTMLStandardMode)) { | |
| 7640 result->setAngle(createPrimitiveNumericValue(a)); | |
| 7641 | |
| 7642 args->next(); | |
| 7643 expectComma = true; | |
| 7644 } else { | |
| 7645 // Look one or two optional keywords that indicate a side or corner. | |
| 7646 RefPtr<CSSPrimitiveValue> startX, startY; | |
| 7647 | |
| 7648 RefPtr<CSSPrimitiveValue> location; | |
| 7649 bool isHorizontal = false; | |
| 7650 if ((location = valueFromSideKeyword(a, isHorizontal))) { | |
| 7651 if (isHorizontal) | |
| 7652 startX = location; | |
| 7653 else | |
| 7654 startY = location; | |
| 7655 | |
| 7656 if ((a = args->next())) { | |
| 7657 if ((location = valueFromSideKeyword(a, isHorizontal))) { | |
| 7658 if (isHorizontal) { | |
| 7659 if (startX) | |
| 7660 return false; | |
| 7661 startX = location; | |
| 7662 } else { | |
| 7663 if (startY) | |
| 7664 return false; | |
| 7665 startY = location; | |
| 7666 } | |
| 7667 | |
| 7668 args->next(); | |
| 7669 } | |
| 7670 } | |
| 7671 | |
| 7672 expectComma = true; | |
| 7673 } | |
| 7674 | |
| 7675 if (!startX && !startY) | |
| 7676 startY = cssValuePool().createIdentifierValue(CSSValueTop); | |
| 7677 | |
| 7678 result->setFirstX(startX.release()); | |
| 7679 result->setFirstY(startY.release()); | |
| 7680 } | |
| 7681 | |
| 7682 if (!parseGradientColorStops(args, result.get(), expectComma)) | |
| 7683 return false; | |
| 7684 | |
| 7685 if (!result->stopCount()) | |
| 7686 return false; | |
| 7687 | |
| 7688 gradient = result.release(); | |
| 7689 return true; | |
| 7690 } | |
| 7691 | |
| 7692 bool CSSParser::parseDeprecatedRadialGradient(CSSParserValueList* valueList, Ref
Ptr<CSSValue>& gradient, CSSGradientRepeat repeating) | |
| 7693 { | |
| 7694 RefPtr<CSSRadialGradientValue> result = CSSRadialGradientValue::create(repea
ting, CSSPrefixedRadialGradient); | |
| 7695 | |
| 7696 // Walk the arguments. | |
| 7697 CSSParserValueList* args = valueList->current()->function->args.get(); | |
| 7698 if (!args || !args->size()) | |
| 7699 return false; | |
| 7700 | |
| 7701 CSSParserValue* a = args->current(); | |
| 7702 if (!a) | |
| 7703 return false; | |
| 7704 | |
| 7705 bool expectComma = false; | |
| 7706 | |
| 7707 // Optional background-position | |
| 7708 RefPtr<CSSValue> centerX; | |
| 7709 RefPtr<CSSValue> centerY; | |
| 7710 // parse2ValuesFillPosition advances the args next pointer. | |
| 7711 parse2ValuesFillPosition(args, centerX, centerY); | |
| 7712 a = args->current(); | |
| 7713 if (!a) | |
| 7714 return false; | |
| 7715 | |
| 7716 if (centerX || centerY) { | |
| 7717 // Comma | |
| 7718 if (!isComma(a)) | |
| 7719 return false; | |
| 7720 | |
| 7721 a = args->next(); | |
| 7722 if (!a) | |
| 7723 return false; | |
| 7724 } | |
| 7725 | |
| 7726 result->setFirstX(toCSSPrimitiveValue(centerX.get())); | |
| 7727 result->setSecondX(toCSSPrimitiveValue(centerX.get())); | |
| 7728 // CSS3 radial gradients always share the same start and end point. | |
| 7729 result->setFirstY(toCSSPrimitiveValue(centerY.get())); | |
| 7730 result->setSecondY(toCSSPrimitiveValue(centerY.get())); | |
| 7731 | |
| 7732 RefPtr<CSSPrimitiveValue> shapeValue; | |
| 7733 RefPtr<CSSPrimitiveValue> sizeValue; | |
| 7734 | |
| 7735 // Optional shape and/or size in any order. | |
| 7736 for (int i = 0; i < 2; ++i) { | |
| 7737 if (a->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 7738 break; | |
| 7739 | |
| 7740 bool foundValue = false; | |
| 7741 switch (a->id) { | |
| 7742 case CSSValueCircle: | |
| 7743 case CSSValueEllipse: | |
| 7744 shapeValue = cssValuePool().createIdentifierValue(a->id); | |
| 7745 foundValue = true; | |
| 7746 break; | |
| 7747 case CSSValueClosestSide: | |
| 7748 case CSSValueClosestCorner: | |
| 7749 case CSSValueFarthestSide: | |
| 7750 case CSSValueFarthestCorner: | |
| 7751 case CSSValueContain: | |
| 7752 case CSSValueCover: | |
| 7753 sizeValue = cssValuePool().createIdentifierValue(a->id); | |
| 7754 foundValue = true; | |
| 7755 break; | |
| 7756 default: | |
| 7757 break; | |
| 7758 } | |
| 7759 | |
| 7760 if (foundValue) { | |
| 7761 a = args->next(); | |
| 7762 if (!a) | |
| 7763 return false; | |
| 7764 | |
| 7765 expectComma = true; | |
| 7766 } | |
| 7767 } | |
| 7768 | |
| 7769 result->setShape(shapeValue); | |
| 7770 result->setSizingBehavior(sizeValue); | |
| 7771 | |
| 7772 // Or, two lengths or percentages | |
| 7773 RefPtr<CSSPrimitiveValue> horizontalSize; | |
| 7774 RefPtr<CSSPrimitiveValue> verticalSize; | |
| 7775 | |
| 7776 if (!shapeValue && !sizeValue) { | |
| 7777 if (validUnit(a, FLength | FPercent)) { | |
| 7778 horizontalSize = createPrimitiveNumericValue(a); | |
| 7779 a = args->next(); | |
| 7780 if (!a) | |
| 7781 return false; | |
| 7782 | |
| 7783 expectComma = true; | |
| 7784 } | |
| 7785 | |
| 7786 if (validUnit(a, FLength | FPercent)) { | |
| 7787 verticalSize = createPrimitiveNumericValue(a); | |
| 7788 | |
| 7789 a = args->next(); | |
| 7790 if (!a) | |
| 7791 return false; | |
| 7792 expectComma = true; | |
| 7793 } | |
| 7794 } | |
| 7795 | |
| 7796 // Must have neither or both. | |
| 7797 if (!horizontalSize != !verticalSize) | |
| 7798 return false; | |
| 7799 | |
| 7800 result->setEndHorizontalSize(horizontalSize); | |
| 7801 result->setEndVerticalSize(verticalSize); | |
| 7802 | |
| 7803 if (!parseGradientColorStops(args, result.get(), expectComma)) | |
| 7804 return false; | |
| 7805 | |
| 7806 gradient = result.release(); | |
| 7807 return true; | |
| 7808 } | |
| 7809 | |
| 7810 bool CSSParser::parseLinearGradient(CSSParserValueList* valueList, RefPtr<CSSVal
ue>& gradient, CSSGradientRepeat repeating) | |
| 7811 { | |
| 7812 RefPtr<CSSLinearGradientValue> result = CSSLinearGradientValue::create(repea
ting, CSSLinearGradient); | |
| 7813 | |
| 7814 CSSParserValueList* args = valueList->current()->function->args.get(); | |
| 7815 if (!args || !args->size()) | |
| 7816 return false; | |
| 7817 | |
| 7818 CSSParserValue* a = args->current(); | |
| 7819 if (!a) | |
| 7820 return false; | |
| 7821 | |
| 7822 bool expectComma = false; | |
| 7823 // Look for angle. | |
| 7824 if (validUnit(a, FAngle, HTMLStandardMode)) { | |
| 7825 result->setAngle(createPrimitiveNumericValue(a)); | |
| 7826 | |
| 7827 args->next(); | |
| 7828 expectComma = true; | |
| 7829 } else if (a->unit == CSSPrimitiveValue::CSS_IDENT && equalIgnoringCase(a, "
to")) { | |
| 7830 // to [ [left | right] || [top | bottom] ] | |
| 7831 a = args->next(); | |
| 7832 if (!a) | |
| 7833 return false; | |
| 7834 | |
| 7835 RefPtr<CSSPrimitiveValue> endX, endY; | |
| 7836 RefPtr<CSSPrimitiveValue> location; | |
| 7837 bool isHorizontal = false; | |
| 7838 | |
| 7839 location = valueFromSideKeyword(a, isHorizontal); | |
| 7840 if (!location) | |
| 7841 return false; | |
| 7842 | |
| 7843 if (isHorizontal) | |
| 7844 endX = location; | |
| 7845 else | |
| 7846 endY = location; | |
| 7847 | |
| 7848 a = args->next(); | |
| 7849 if (!a) | |
| 7850 return false; | |
| 7851 | |
| 7852 location = valueFromSideKeyword(a, isHorizontal); | |
| 7853 if (location) { | |
| 7854 if (isHorizontal) { | |
| 7855 if (endX) | |
| 7856 return false; | |
| 7857 endX = location; | |
| 7858 } else { | |
| 7859 if (endY) | |
| 7860 return false; | |
| 7861 endY = location; | |
| 7862 } | |
| 7863 | |
| 7864 args->next(); | |
| 7865 } | |
| 7866 | |
| 7867 expectComma = true; | |
| 7868 result->setFirstX(endX.release()); | |
| 7869 result->setFirstY(endY.release()); | |
| 7870 } | |
| 7871 | |
| 7872 if (!parseGradientColorStops(args, result.get(), expectComma)) | |
| 7873 return false; | |
| 7874 | |
| 7875 if (!result->stopCount()) | |
| 7876 return false; | |
| 7877 | |
| 7878 gradient = result.release(); | |
| 7879 return true; | |
| 7880 } | |
| 7881 | |
| 7882 bool CSSParser::parseRadialGradient(CSSParserValueList* valueList, RefPtr<CSSVal
ue>& gradient, CSSGradientRepeat repeating) | |
| 7883 { | |
| 7884 RefPtr<CSSRadialGradientValue> result = CSSRadialGradientValue::create(repea
ting, CSSRadialGradient); | |
| 7885 | |
| 7886 CSSParserValueList* args = valueList->current()->function->args.get(); | |
| 7887 if (!args || !args->size()) | |
| 7888 return false; | |
| 7889 | |
| 7890 CSSParserValue* a = args->current(); | |
| 7891 if (!a) | |
| 7892 return false; | |
| 7893 | |
| 7894 bool expectComma = false; | |
| 7895 | |
| 7896 RefPtr<CSSPrimitiveValue> shapeValue; | |
| 7897 RefPtr<CSSPrimitiveValue> sizeValue; | |
| 7898 RefPtr<CSSPrimitiveValue> horizontalSize; | |
| 7899 RefPtr<CSSPrimitiveValue> verticalSize; | |
| 7900 | |
| 7901 // First part of grammar, the size/shape clause: | |
| 7902 // [ circle || <length> ] | | |
| 7903 // [ ellipse || [ <length> | <percentage> ]{2} ] | | |
| 7904 // [ [ circle | ellipse] || <size-keyword> ] | |
| 7905 for (int i = 0; i < 3; ++i) { | |
| 7906 if (a->unit == CSSPrimitiveValue::CSS_IDENT) { | |
| 7907 bool badIdent = false; | |
| 7908 switch (a->id) { | |
| 7909 case CSSValueCircle: | |
| 7910 case CSSValueEllipse: | |
| 7911 if (shapeValue) | |
| 7912 return false; | |
| 7913 shapeValue = cssValuePool().createIdentifierValue(a->id); | |
| 7914 break; | |
| 7915 case CSSValueClosestSide: | |
| 7916 case CSSValueClosestCorner: | |
| 7917 case CSSValueFarthestSide: | |
| 7918 case CSSValueFarthestCorner: | |
| 7919 if (sizeValue || horizontalSize) | |
| 7920 return false; | |
| 7921 sizeValue = cssValuePool().createIdentifierValue(a->id); | |
| 7922 break; | |
| 7923 default: | |
| 7924 badIdent = true; | |
| 7925 } | |
| 7926 | |
| 7927 if (badIdent) | |
| 7928 break; | |
| 7929 | |
| 7930 a = args->next(); | |
| 7931 if (!a) | |
| 7932 return false; | |
| 7933 } else if (validUnit(a, FLength | FPercent)) { | |
| 7934 | |
| 7935 if (sizeValue || horizontalSize) | |
| 7936 return false; | |
| 7937 horizontalSize = createPrimitiveNumericValue(a); | |
| 7938 | |
| 7939 a = args->next(); | |
| 7940 if (!a) | |
| 7941 return false; | |
| 7942 | |
| 7943 if (validUnit(a, FLength | FPercent)) { | |
| 7944 verticalSize = createPrimitiveNumericValue(a); | |
| 7945 ++i; | |
| 7946 a = args->next(); | |
| 7947 if (!a) | |
| 7948 return false; | |
| 7949 } | |
| 7950 } else | |
| 7951 break; | |
| 7952 } | |
| 7953 | |
| 7954 // You can specify size as a keyword or a length/percentage, not both. | |
| 7955 if (sizeValue && horizontalSize) | |
| 7956 return false; | |
| 7957 // Circles must have 0 or 1 lengths. | |
| 7958 if (shapeValue && shapeValue->getValueID() == CSSValueCircle && verticalSize
) | |
| 7959 return false; | |
| 7960 // Ellipses must have 0 or 2 length/percentages. | |
| 7961 if (shapeValue && shapeValue->getValueID() == CSSValueEllipse && horizontalS
ize && !verticalSize) | |
| 7962 return false; | |
| 7963 // If there's only one size, it must be a length. | |
| 7964 if (!verticalSize && horizontalSize && horizontalSize->isPercentage()) | |
| 7965 return false; | |
| 7966 | |
| 7967 result->setShape(shapeValue); | |
| 7968 result->setSizingBehavior(sizeValue); | |
| 7969 result->setEndHorizontalSize(horizontalSize); | |
| 7970 result->setEndVerticalSize(verticalSize); | |
| 7971 | |
| 7972 // Second part of grammar, the center-position clause: | |
| 7973 // at <position> | |
| 7974 RefPtr<CSSValue> centerX; | |
| 7975 RefPtr<CSSValue> centerY; | |
| 7976 if (a->unit == CSSPrimitiveValue::CSS_IDENT && equalIgnoringCase(a, "at")) { | |
| 7977 a = args->next(); | |
| 7978 if (!a) | |
| 7979 return false; | |
| 7980 | |
| 7981 parseFillPosition(args, centerX, centerY); | |
| 7982 if (!(centerX && centerY)) | |
| 7983 return false; | |
| 7984 | |
| 7985 a = args->current(); | |
| 7986 if (!a) | |
| 7987 return false; | |
| 7988 result->setFirstX(toCSSPrimitiveValue(centerX.get())); | |
| 7989 result->setFirstY(toCSSPrimitiveValue(centerY.get())); | |
| 7990 // Right now, CSS radial gradients have the same start and end centers. | |
| 7991 result->setSecondX(toCSSPrimitiveValue(centerX.get())); | |
| 7992 result->setSecondY(toCSSPrimitiveValue(centerY.get())); | |
| 7993 } | |
| 7994 | |
| 7995 if (shapeValue || sizeValue || horizontalSize || centerX || centerY) | |
| 7996 expectComma = true; | |
| 7997 | |
| 7998 if (!parseGradientColorStops(args, result.get(), expectComma)) | |
| 7999 return false; | |
| 8000 | |
| 8001 gradient = result.release(); | |
| 8002 return true; | |
| 8003 } | |
| 8004 | |
| 8005 bool CSSParser::parseGradientColorStops(CSSParserValueList* valueList, CSSGradie
ntValue* gradient, bool expectComma) | |
| 8006 { | |
| 8007 CSSParserValue* a = valueList->current(); | |
| 8008 | |
| 8009 // Now look for color stops. | |
| 8010 while (a) { | |
| 8011 // Look for the comma before the next stop. | |
| 8012 if (expectComma) { | |
| 8013 if (!isComma(a)) | |
| 8014 return false; | |
| 8015 | |
| 8016 a = valueList->next(); | |
| 8017 if (!a) | |
| 8018 return false; | |
| 8019 } | |
| 8020 | |
| 8021 // <color-stop> = <color> [ <percentage> | <length> ]? | |
| 8022 CSSGradientColorStop stop; | |
| 8023 stop.m_color = parseGradientColorOrKeyword(this, a); | |
| 8024 if (!stop.m_color) | |
| 8025 return false; | |
| 8026 | |
| 8027 a = valueList->next(); | |
| 8028 if (a) { | |
| 8029 if (validUnit(a, FLength | FPercent)) { | |
| 8030 stop.m_position = createPrimitiveNumericValue(a); | |
| 8031 a = valueList->next(); | |
| 8032 } | |
| 8033 } | |
| 8034 | |
| 8035 gradient->addStop(stop); | |
| 8036 expectComma = true; | |
| 8037 } | |
| 8038 | |
| 8039 // Must have 2 or more stops to be valid. | |
| 8040 return gradient->stopCount() >= 2; | |
| 8041 } | |
| 8042 | |
| 8043 bool CSSParser::parseGeneratedImage(CSSParserValueList* valueList, RefPtr<CSSVal
ue>& value) | |
| 8044 { | |
| 8045 CSSParserValue* val = valueList->current(); | |
| 8046 | |
| 8047 if (val->unit != CSSParserValue::Function) | |
| 8048 return false; | |
| 8049 | |
| 8050 if (equalIgnoringCase(val->function->name, "-webkit-gradient(")) | |
| 8051 return parseDeprecatedGradient(valueList, value); | |
| 8052 | |
| 8053 if (equalIgnoringCase(val->function->name, "-webkit-linear-gradient(")) | |
| 8054 return parseDeprecatedLinearGradient(valueList, value, NonRepeating); | |
| 8055 | |
| 8056 if (equalIgnoringCase(val->function->name, "linear-gradient(")) | |
| 8057 return parseLinearGradient(valueList, value, NonRepeating); | |
| 8058 | |
| 8059 if (equalIgnoringCase(val->function->name, "-webkit-repeating-linear-gradien
t(")) | |
| 8060 return parseDeprecatedLinearGradient(valueList, value, Repeating); | |
| 8061 | |
| 8062 if (equalIgnoringCase(val->function->name, "repeating-linear-gradient(")) | |
| 8063 return parseLinearGradient(valueList, value, Repeating); | |
| 8064 | |
| 8065 if (equalIgnoringCase(val->function->name, "-webkit-radial-gradient(")) | |
| 8066 return parseDeprecatedRadialGradient(valueList, value, NonRepeating); | |
| 8067 | |
| 8068 if (equalIgnoringCase(val->function->name, "radial-gradient(")) | |
| 8069 return parseRadialGradient(valueList, value, NonRepeating); | |
| 8070 | |
| 8071 if (equalIgnoringCase(val->function->name, "-webkit-repeating-radial-gradien
t(")) | |
| 8072 return parseDeprecatedRadialGradient(valueList, value, Repeating); | |
| 8073 | |
| 8074 if (equalIgnoringCase(val->function->name, "repeating-radial-gradient(")) | |
| 8075 return parseRadialGradient(valueList, value, Repeating); | |
| 8076 | |
| 8077 if (equalIgnoringCase(val->function->name, "-webkit-canvas(")) | |
| 8078 return parseCanvas(valueList, value); | |
| 8079 | |
| 8080 if (equalIgnoringCase(val->function->name, "-webkit-cross-fade(")) | |
| 8081 return parseCrossfade(valueList, value); | |
| 8082 | |
| 8083 return false; | |
| 8084 } | |
| 8085 | |
| 8086 bool CSSParser::parseCrossfade(CSSParserValueList* valueList, RefPtr<CSSValue>&
crossfade) | |
| 8087 { | |
| 8088 RefPtr<CSSCrossfadeValue> result; | |
| 8089 | |
| 8090 // Walk the arguments. | |
| 8091 CSSParserValueList* args = valueList->current()->function->args.get(); | |
| 8092 if (!args || args->size() != 5) | |
| 8093 return false; | |
| 8094 CSSParserValue* a = args->current(); | |
| 8095 RefPtr<CSSValue> fromImageValue; | |
| 8096 RefPtr<CSSValue> toImageValue; | |
| 8097 | |
| 8098 // The first argument is the "from" image. It is a fill image. | |
| 8099 if (!a || !parseFillImage(args, fromImageValue)) | |
| 8100 return false; | |
| 8101 a = args->next(); | |
| 8102 | |
| 8103 // Skip a comma | |
| 8104 if (!isComma(a)) | |
| 8105 return false; | |
| 8106 a = args->next(); | |
| 8107 | |
| 8108 // The second argument is the "to" image. It is a fill image. | |
| 8109 if (!a || !parseFillImage(args, toImageValue)) | |
| 8110 return false; | |
| 8111 a = args->next(); | |
| 8112 | |
| 8113 // Skip a comma | |
| 8114 if (!isComma(a)) | |
| 8115 return false; | |
| 8116 a = args->next(); | |
| 8117 | |
| 8118 // The third argument is the crossfade value. It is a percentage or a fracti
onal number. | |
| 8119 RefPtr<CSSPrimitiveValue> percentage; | |
| 8120 if (!a) | |
| 8121 return false; | |
| 8122 | |
| 8123 if (a->unit == CSSPrimitiveValue::CSS_PERCENTAGE) | |
| 8124 percentage = cssValuePool().createValue(clampTo<double>(a->fValue / 100,
0, 1), CSSPrimitiveValue::CSS_NUMBER); | |
| 8125 else if (a->unit == CSSPrimitiveValue::CSS_NUMBER) | |
| 8126 percentage = cssValuePool().createValue(clampTo<double>(a->fValue, 0, 1)
, CSSPrimitiveValue::CSS_NUMBER); | |
| 8127 else | |
| 8128 return false; | |
| 8129 | |
| 8130 result = CSSCrossfadeValue::create(fromImageValue, toImageValue); | |
| 8131 result->setPercentage(percentage); | |
| 8132 | |
| 8133 crossfade = result; | |
| 8134 | |
| 8135 return true; | |
| 8136 } | |
| 8137 | |
| 8138 bool CSSParser::parseCanvas(CSSParserValueList* valueList, RefPtr<CSSValue>& can
vas) | |
| 8139 { | |
| 8140 // Walk the arguments. | |
| 8141 CSSParserValueList* args = valueList->current()->function->args.get(); | |
| 8142 if (!args || args->size() != 1) | |
| 8143 return false; | |
| 8144 | |
| 8145 // The first argument is the canvas name. It is an identifier. | |
| 8146 CSSParserValue* value = args->current(); | |
| 8147 if (!value || value->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 8148 return false; | |
| 8149 | |
| 8150 canvas = CSSCanvasValue::create(value->string); | |
| 8151 return true; | |
| 8152 } | |
| 8153 | |
| 8154 PassRefPtr<CSSValue> CSSParser::parseImageSet(CSSParserValueList* valueList) | |
| 8155 { | |
| 8156 CSSParserValue* function = valueList->current(); | |
| 8157 | |
| 8158 if (function->unit != CSSParserValue::Function) | |
| 8159 return 0; | |
| 8160 | |
| 8161 CSSParserValueList* functionArgs = valueList->current()->function->args.get(
); | |
| 8162 if (!functionArgs || !functionArgs->size() || !functionArgs->current()) | |
| 8163 return 0; | |
| 8164 | |
| 8165 RefPtr<CSSImageSetValue> imageSet = CSSImageSetValue::create(); | |
| 8166 | |
| 8167 CSSParserValue* arg = functionArgs->current(); | |
| 8168 while (arg) { | |
| 8169 if (arg->unit != CSSPrimitiveValue::CSS_URI) | |
| 8170 return 0; | |
| 8171 | |
| 8172 RefPtr<CSSImageValue> image = CSSImageValue::create(completeURL(arg->str
ing)); | |
| 8173 imageSet->append(image); | |
| 8174 | |
| 8175 arg = functionArgs->next(); | |
| 8176 if (!arg || arg->unit != CSSPrimitiveValue::CSS_DIMENSION) | |
| 8177 return 0; | |
| 8178 | |
| 8179 double imageScaleFactor = 0; | |
| 8180 const String& string = arg->string; | |
| 8181 unsigned length = string.length(); | |
| 8182 if (!length) | |
| 8183 return 0; | |
| 8184 if (string.is8Bit()) { | |
| 8185 const LChar* start = string.characters8(); | |
| 8186 parseDouble(start, start + length, 'x', imageScaleFactor); | |
| 8187 } else { | |
| 8188 const UChar* start = string.characters16(); | |
| 8189 parseDouble(start, start + length, 'x', imageScaleFactor); | |
| 8190 } | |
| 8191 if (imageScaleFactor <= 0) | |
| 8192 return 0; | |
| 8193 imageSet->append(cssValuePool().createValue(imageScaleFactor, CSSPrimiti
veValue::CSS_NUMBER)); | |
| 8194 | |
| 8195 // If there are no more arguments, we're done. | |
| 8196 arg = functionArgs->next(); | |
| 8197 if (!arg) | |
| 8198 break; | |
| 8199 | |
| 8200 // If there are more arguments, they should be after a comma. | |
| 8201 if (!isComma(arg)) | |
| 8202 return 0; | |
| 8203 | |
| 8204 // Skip the comma and move on to the next argument. | |
| 8205 arg = functionArgs->next(); | |
| 8206 } | |
| 8207 | |
| 8208 return imageSet.release(); | |
| 8209 } | |
| 8210 | |
| 8211 class TransformOperationInfo { | |
| 8212 public: | |
| 8213 TransformOperationInfo(const CSSParserString& name) | |
| 8214 : m_type(CSSTransformValue::UnknownTransformOperation) | |
| 8215 , m_argCount(1) | |
| 8216 , m_allowSingleArgument(false) | |
| 8217 , m_unit(CSSParser::FUnknown) | |
| 8218 { | |
| 8219 const UChar* characters; | |
| 8220 unsigned nameLength = name.length(); | |
| 8221 | |
| 8222 const unsigned longestNameLength = 12; | |
| 8223 UChar characterBuffer[longestNameLength]; | |
| 8224 if (name.is8Bit()) { | |
| 8225 unsigned length = std::min(longestNameLength, nameLength); | |
| 8226 const LChar* characters8 = name.characters8(); | |
| 8227 for (unsigned i = 0; i < length; ++i) | |
| 8228 characterBuffer[i] = characters8[i]; | |
| 8229 characters = characterBuffer; | |
| 8230 } else | |
| 8231 characters = name.characters16(); | |
| 8232 | |
| 8233 SWITCH(characters, nameLength) { | |
| 8234 CASE("skew(") { | |
| 8235 m_unit = CSSParser::FAngle; | |
| 8236 m_type = CSSTransformValue::SkewTransformOperation; | |
| 8237 m_allowSingleArgument = true; | |
| 8238 m_argCount = 3; | |
| 8239 } | |
| 8240 CASE("scale(") { | |
| 8241 m_unit = CSSParser::FNumber; | |
| 8242 m_type = CSSTransformValue::ScaleTransformOperation; | |
| 8243 m_allowSingleArgument = true; | |
| 8244 m_argCount = 3; | |
| 8245 } | |
| 8246 CASE("skewx(") { | |
| 8247 m_unit = CSSParser::FAngle; | |
| 8248 m_type = CSSTransformValue::SkewXTransformOperation; | |
| 8249 } | |
| 8250 CASE("skewy(") { | |
| 8251 m_unit = CSSParser::FAngle; | |
| 8252 m_type = CSSTransformValue::SkewYTransformOperation; | |
| 8253 } | |
| 8254 CASE("matrix(") { | |
| 8255 m_unit = CSSParser::FNumber; | |
| 8256 m_type = CSSTransformValue::MatrixTransformOperation; | |
| 8257 m_argCount = 11; | |
| 8258 } | |
| 8259 CASE("rotate(") { | |
| 8260 m_unit = CSSParser::FAngle; | |
| 8261 m_type = CSSTransformValue::RotateTransformOperation; | |
| 8262 } | |
| 8263 CASE("scalex(") { | |
| 8264 m_unit = CSSParser::FNumber; | |
| 8265 m_type = CSSTransformValue::ScaleXTransformOperation; | |
| 8266 } | |
| 8267 CASE("scaley(") { | |
| 8268 m_unit = CSSParser::FNumber; | |
| 8269 m_type = CSSTransformValue::ScaleYTransformOperation; | |
| 8270 } | |
| 8271 CASE("scalez(") { | |
| 8272 m_unit = CSSParser::FNumber; | |
| 8273 m_type = CSSTransformValue::ScaleZTransformOperation; | |
| 8274 } | |
| 8275 CASE("scale3d(") { | |
| 8276 m_unit = CSSParser::FNumber; | |
| 8277 m_type = CSSTransformValue::Scale3DTransformOperation; | |
| 8278 m_argCount = 5; | |
| 8279 } | |
| 8280 CASE("rotatex(") { | |
| 8281 m_unit = CSSParser::FAngle; | |
| 8282 m_type = CSSTransformValue::RotateXTransformOperation; | |
| 8283 } | |
| 8284 CASE("rotatey(") { | |
| 8285 m_unit = CSSParser::FAngle; | |
| 8286 m_type = CSSTransformValue::RotateYTransformOperation; | |
| 8287 } | |
| 8288 CASE("rotatez(") { | |
| 8289 m_unit = CSSParser::FAngle; | |
| 8290 m_type = CSSTransformValue::RotateZTransformOperation; | |
| 8291 } | |
| 8292 CASE("matrix3d(") { | |
| 8293 m_unit = CSSParser::FNumber; | |
| 8294 m_type = CSSTransformValue::Matrix3DTransformOperation; | |
| 8295 m_argCount = 31; | |
| 8296 } | |
| 8297 CASE("rotate3d(") { | |
| 8298 m_unit = CSSParser::FNumber; | |
| 8299 m_type = CSSTransformValue::Rotate3DTransformOperation; | |
| 8300 m_argCount = 7; | |
| 8301 } | |
| 8302 CASE("translate(") { | |
| 8303 m_unit = CSSParser::FLength | CSSParser::FPercent; | |
| 8304 m_type = CSSTransformValue::TranslateTransformOperation; | |
| 8305 m_allowSingleArgument = true; | |
| 8306 m_argCount = 3; | |
| 8307 } | |
| 8308 CASE("translatex(") { | |
| 8309 m_unit = CSSParser::FLength | CSSParser::FPercent; | |
| 8310 m_type = CSSTransformValue::TranslateXTransformOperation; | |
| 8311 } | |
| 8312 CASE("translatey(") { | |
| 8313 m_unit = CSSParser::FLength | CSSParser::FPercent; | |
| 8314 m_type = CSSTransformValue::TranslateYTransformOperation; | |
| 8315 } | |
| 8316 CASE("translatez(") { | |
| 8317 m_unit = CSSParser::FLength | CSSParser::FPercent; | |
| 8318 m_type = CSSTransformValue::TranslateZTransformOperation; | |
| 8319 } | |
| 8320 CASE("perspective(") { | |
| 8321 m_unit = CSSParser::FNumber; | |
| 8322 m_type = CSSTransformValue::PerspectiveTransformOperation; | |
| 8323 } | |
| 8324 CASE("translate3d(") { | |
| 8325 m_unit = CSSParser::FLength | CSSParser::FPercent; | |
| 8326 m_type = CSSTransformValue::Translate3DTransformOperation; | |
| 8327 m_argCount = 5; | |
| 8328 } | |
| 8329 } | |
| 8330 } | |
| 8331 | |
| 8332 CSSTransformValue::TransformOperationType type() const { return m_type; } | |
| 8333 unsigned argCount() const { return m_argCount; } | |
| 8334 CSSParser::Units unit() const { return m_unit; } | |
| 8335 | |
| 8336 bool unknown() const { return m_type == CSSTransformValue::UnknownTransformO
peration; } | |
| 8337 bool hasCorrectArgCount(unsigned argCount) { return m_argCount == argCount |
| (m_allowSingleArgument && argCount == 1); } | |
| 8338 | |
| 8339 private: | |
| 8340 CSSTransformValue::TransformOperationType m_type; | |
| 8341 unsigned m_argCount; | |
| 8342 bool m_allowSingleArgument; | |
| 8343 CSSParser::Units m_unit; | |
| 8344 }; | |
| 8345 | |
| 8346 PassRefPtr<CSSValueList> CSSParser::parseTransform() | |
| 8347 { | |
| 8348 if (!m_valueList) | |
| 8349 return 0; | |
| 8350 | |
| 8351 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); | |
| 8352 for (CSSParserValue* value = m_valueList->current(); value; value = m_valueL
ist->next()) { | |
| 8353 RefPtr<CSSValue> parsedTransformValue = parseTransformValue(value); | |
| 8354 if (!parsedTransformValue) | |
| 8355 return 0; | |
| 8356 | |
| 8357 list->append(parsedTransformValue.release()); | |
| 8358 } | |
| 8359 | |
| 8360 return list.release(); | |
| 8361 } | |
| 8362 | |
| 8363 PassRefPtr<CSSValue> CSSParser::parseTransformValue(CSSParserValue *value) | |
| 8364 { | |
| 8365 if (value->unit != CSSParserValue::Function || !value->function) | |
| 8366 return 0; | |
| 8367 | |
| 8368 // Every primitive requires at least one argument. | |
| 8369 CSSParserValueList* args = value->function->args.get(); | |
| 8370 if (!args) | |
| 8371 return 0; | |
| 8372 | |
| 8373 // See if the specified primitive is one we understand. | |
| 8374 TransformOperationInfo info(value->function->name); | |
| 8375 if (info.unknown()) | |
| 8376 return 0; | |
| 8377 | |
| 8378 if (!info.hasCorrectArgCount(args->size())) | |
| 8379 return 0; | |
| 8380 | |
| 8381 // The transform is a list of functional primitives that specify transform o
perations. | |
| 8382 // We collect a list of CSSTransformValues, where each value specifies a sin
gle operation. | |
| 8383 | |
| 8384 // Create the new CSSTransformValue for this operation and add it to our lis
t. | |
| 8385 RefPtr<CSSTransformValue> transformValue = CSSTransformValue::create(info.ty
pe()); | |
| 8386 | |
| 8387 // Snag our values. | |
| 8388 CSSParserValue* a = args->current(); | |
| 8389 unsigned argNumber = 0; | |
| 8390 while (a) { | |
| 8391 CSSParser::Units unit = info.unit(); | |
| 8392 | |
| 8393 if (info.type() == CSSTransformValue::Rotate3DTransformOperation && argN
umber == 3) { | |
| 8394 // 4th param of rotate3d() is an angle rather than a bare number, va
lidate it as such | |
| 8395 if (!validUnit(a, FAngle, HTMLStandardMode)) | |
| 8396 return 0; | |
| 8397 } else if (info.type() == CSSTransformValue::Translate3DTransformOperati
on && argNumber == 2) { | |
| 8398 // 3rd param of translate3d() cannot be a percentage | |
| 8399 if (!validUnit(a, FLength, HTMLStandardMode)) | |
| 8400 return 0; | |
| 8401 } else if (info.type() == CSSTransformValue::TranslateZTransformOperatio
n && !argNumber) { | |
| 8402 // 1st param of translateZ() cannot be a percentage | |
| 8403 if (!validUnit(a, FLength, HTMLStandardMode)) | |
| 8404 return 0; | |
| 8405 } else if (info.type() == CSSTransformValue::PerspectiveTransformOperati
on && !argNumber) { | |
| 8406 // 1st param of perspective() must be a non-negative number (depreca
ted) or length. | |
| 8407 if (!validUnit(a, FNumber | FLength | FNonNeg, HTMLStandardMode)) | |
| 8408 return 0; | |
| 8409 } else if (!validUnit(a, unit, HTMLStandardMode)) | |
| 8410 return 0; | |
| 8411 | |
| 8412 // Add the value to the current transform operation. | |
| 8413 transformValue->append(createPrimitiveNumericValue(a)); | |
| 8414 | |
| 8415 a = args->next(); | |
| 8416 if (!a) | |
| 8417 break; | |
| 8418 if (a->unit != CSSParserValue::Operator || a->iValue != ',') | |
| 8419 return 0; | |
| 8420 a = args->next(); | |
| 8421 | |
| 8422 argNumber++; | |
| 8423 } | |
| 8424 | |
| 8425 return transformValue.release(); | |
| 8426 } | |
| 8427 | |
| 8428 bool CSSParser::isBlendMode(CSSValueID valueID) | |
| 8429 { | |
| 8430 return (valueID >= CSSValueMultiply && valueID <= CSSValueLuminosity) | |
| 8431 || valueID == CSSValueNormal | |
| 8432 || valueID == CSSValueOverlay; | |
| 8433 } | |
| 8434 | |
| 8435 bool CSSParser::isCompositeOperator(CSSValueID valueID) | |
| 8436 { | |
| 8437 // FIXME: Add CSSValueDestination and CSSValueLighter when the Compositing s
pec updates. | |
| 8438 return valueID >= CSSValueClear && valueID <= CSSValueXor; | |
| 8439 } | |
| 8440 | |
| 8441 static void filterInfoForName(const CSSParserString& name, CSSFilterValue::Filte
rOperationType& filterType, unsigned& maximumArgumentCount) | |
| 8442 { | |
| 8443 if (equalIgnoringCase(name, "grayscale(")) | |
| 8444 filterType = CSSFilterValue::GrayscaleFilterOperation; | |
| 8445 else if (equalIgnoringCase(name, "sepia(")) | |
| 8446 filterType = CSSFilterValue::SepiaFilterOperation; | |
| 8447 else if (equalIgnoringCase(name, "saturate(")) | |
| 8448 filterType = CSSFilterValue::SaturateFilterOperation; | |
| 8449 else if (equalIgnoringCase(name, "hue-rotate(")) | |
| 8450 filterType = CSSFilterValue::HueRotateFilterOperation; | |
| 8451 else if (equalIgnoringCase(name, "invert(")) | |
| 8452 filterType = CSSFilterValue::InvertFilterOperation; | |
| 8453 else if (equalIgnoringCase(name, "opacity(")) | |
| 8454 filterType = CSSFilterValue::OpacityFilterOperation; | |
| 8455 else if (equalIgnoringCase(name, "brightness(")) | |
| 8456 filterType = CSSFilterValue::BrightnessFilterOperation; | |
| 8457 else if (equalIgnoringCase(name, "contrast(")) | |
| 8458 filterType = CSSFilterValue::ContrastFilterOperation; | |
| 8459 else if (equalIgnoringCase(name, "blur(")) | |
| 8460 filterType = CSSFilterValue::BlurFilterOperation; | |
| 8461 else if (equalIgnoringCase(name, "drop-shadow(")) { | |
| 8462 filterType = CSSFilterValue::DropShadowFilterOperation; | |
| 8463 maximumArgumentCount = 4; // x-offset, y-offset, blur-radius, color --
spread and inset style not allowed. | |
| 8464 } | |
| 8465 else if (equalIgnoringCase(name, "custom(")) | |
| 8466 filterType = CSSFilterValue::CustomFilterOperation; | |
| 8467 } | |
| 8468 | |
| 8469 static bool acceptCommaOperator(CSSParserValueList* argsList) | |
| 8470 { | |
| 8471 if (CSSParserValue* arg = argsList->current()) { | |
| 8472 if (!isComma(arg)) | |
| 8473 return false; | |
| 8474 argsList->next(); | |
| 8475 } | |
| 8476 return true; | |
| 8477 } | |
| 8478 | |
| 8479 PassRefPtr<CSSArrayFunctionValue> CSSParser::parseCustomFilterArrayFunction(CSSP
arserValue* value) | |
| 8480 { | |
| 8481 ASSERT(value->unit == CSSParserValue::Function && value->function); | |
| 8482 | |
| 8483 if (!equalIgnoringCase(value->function->name, "array(")) | |
| 8484 return 0; | |
| 8485 | |
| 8486 CSSParserValueList* arrayArgsParserValueList = value->function->args.get(); | |
| 8487 if (!arrayArgsParserValueList || !arrayArgsParserValueList->size()) | |
| 8488 return 0; | |
| 8489 | |
| 8490 // array() values are comma separated. | |
| 8491 RefPtr<CSSArrayFunctionValue> arrayFunction = CSSArrayFunctionValue::create(
); | |
| 8492 while (true) { | |
| 8493 // We parse pairs <Value, Comma> at each step. | |
| 8494 CSSParserValue* currentParserValue = arrayArgsParserValueList->current()
; | |
| 8495 if (!currentParserValue || !validUnit(currentParserValue, FNumber, HTMLS
tandardMode)) | |
| 8496 return 0; | |
| 8497 | |
| 8498 RefPtr<CSSValue> arrayValue = cssValuePool().createValue(currentParserVa
lue->fValue, CSSPrimitiveValue::CSS_NUMBER); | |
| 8499 arrayFunction->append(arrayValue.release()); | |
| 8500 | |
| 8501 CSSParserValue* nextParserValue = arrayArgsParserValueList->next(); | |
| 8502 if (!nextParserValue) | |
| 8503 break; | |
| 8504 | |
| 8505 if (!isComma(nextParserValue)) | |
| 8506 return 0; | |
| 8507 | |
| 8508 arrayArgsParserValueList->next(); | |
| 8509 } | |
| 8510 | |
| 8511 return arrayFunction; | |
| 8512 } | |
| 8513 | |
| 8514 PassRefPtr<CSSMixFunctionValue> CSSParser::parseMixFunction(CSSParserValue* valu
e) | |
| 8515 { | |
| 8516 ASSERT(value->unit == CSSParserValue::Function && value->function); | |
| 8517 | |
| 8518 if (!equalIgnoringCase(value->function->name, "mix(")) | |
| 8519 return 0; | |
| 8520 | |
| 8521 CSSParserValueList* argsList = value->function->args.get(); | |
| 8522 if (!argsList) | |
| 8523 return 0; | |
| 8524 | |
| 8525 unsigned numArgs = argsList->size(); | |
| 8526 if (numArgs < 1 || numArgs > 3) | |
| 8527 return 0; | |
| 8528 | |
| 8529 RefPtr<CSSMixFunctionValue> mixFunction = CSSMixFunctionValue::create(); | |
| 8530 | |
| 8531 bool hasBlendMode = false; | |
| 8532 bool hasAlphaCompositing = false; | |
| 8533 | |
| 8534 for (CSSParserValue* arg = argsList->current(); arg; arg = argsList->next())
{ | |
| 8535 RefPtr<CSSValue> value; | |
| 8536 | |
| 8537 unsigned argNumber = argsList->currentIndex(); | |
| 8538 if (!argNumber) { | |
| 8539 if (arg->unit == CSSPrimitiveValue::CSS_URI) { | |
| 8540 KURL shaderURL = completeURL(arg->string); | |
| 8541 value = CSSShaderValue::create(shaderURL.string()); | |
| 8542 } | |
| 8543 } else if (argNumber == 1 || argNumber == 2) { | |
| 8544 if (!hasBlendMode && isBlendMode(arg->id)) { | |
| 8545 hasBlendMode = true; | |
| 8546 value = cssValuePool().createIdentifierValue(arg->id); | |
| 8547 } else if (!hasAlphaCompositing && isCompositeOperator(arg->id)) { | |
| 8548 hasAlphaCompositing = true; | |
| 8549 value = cssValuePool().createIdentifierValue(arg->id); | |
| 8550 } | |
| 8551 } | |
| 8552 | |
| 8553 if (!value) | |
| 8554 return 0; | |
| 8555 | |
| 8556 mixFunction->append(value.release()); | |
| 8557 } | |
| 8558 | |
| 8559 return mixFunction; | |
| 8560 } | |
| 8561 | |
| 8562 PassRefPtr<CSSValueList> CSSParser::parseCustomFilterParameters(CSSParserValueLi
st* argsList) | |
| 8563 { | |
| 8564 // | |
| 8565 // params: [<param-def>[,<param-def>*]] | |
| 8566 // param-def: <param-name>wsp<param-value> | |
| 8567 // param-name: <ident> | |
| 8568 // param-value: true|false[wsp+true|false]{0-3} | | |
| 8569 // <number>[wsp+<number>]{0-3} | | |
| 8570 // <array> | | |
| 8571 // <transform> | | |
| 8572 // <texture(<uri>)> | |
| 8573 // array: 'array('<number>[wsp<number>]*')' | |
| 8574 // css-3d-transform: <transform-function>;[<transform-function>]* | |
| 8575 // transform: <css-3d-transform> | <mat> | |
| 8576 // mat: 'mat2('<number>(,<number>){3}')' | | |
| 8577 // 'mat3('<number>(,<number>){8}')' | | |
| 8578 // 'mat4('<number>(,<number>){15}')' ) | |
| 8579 // | |
| 8580 | |
| 8581 RefPtr<CSSValueList> paramList = CSSValueList::createCommaSeparated(); | |
| 8582 | |
| 8583 while (CSSParserValue* arg = argsList->current()) { | |
| 8584 if (arg->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 8585 return 0; | |
| 8586 | |
| 8587 RefPtr<CSSValueList> parameter = CSSValueList::createSpaceSeparated(); | |
| 8588 parameter->append(createPrimitiveStringValue(arg)); | |
| 8589 | |
| 8590 arg = argsList->next(); | |
| 8591 if (!arg) | |
| 8592 return 0; | |
| 8593 | |
| 8594 RefPtr<CSSValue> parameterValue; | |
| 8595 | |
| 8596 if (arg->unit == CSSParserValue::Function && arg->function) { | |
| 8597 // FIXME: Implement parsing for the other parameter types. | |
| 8598 // textures: https://bugs.webkit.org/show_bug.cgi?id=71442 | |
| 8599 // mat2, mat3, mat4: https://bugs.webkit.org/show_bug.cgi?id=71444 | |
| 8600 if (equalIgnoringCase(arg->function->name, "array(")) { | |
| 8601 parameterValue = parseCustomFilterArrayFunction(arg); | |
| 8602 // This parsing step only consumes function arguments, | |
| 8603 // argsList is therefore moved forward explicitely. | |
| 8604 argsList->next(); | |
| 8605 } else | |
| 8606 parameterValue = parseCustomFilterTransform(argsList); | |
| 8607 } else { | |
| 8608 RefPtr<CSSValueList> paramValueList = CSSValueList::createSpaceSepar
ated(); | |
| 8609 arg = argsList->current(); | |
| 8610 while (arg) { | |
| 8611 // If we hit a comma, it means that we finished this parameter's
values. | |
| 8612 if (isComma(arg)) | |
| 8613 break; | |
| 8614 if (!validUnit(arg, FNumber, HTMLStandardMode)) | |
| 8615 return 0; | |
| 8616 paramValueList->append(cssValuePool().createValue(arg->fValue, C
SSPrimitiveValue::CSS_NUMBER)); | |
| 8617 arg = argsList->next(); | |
| 8618 } | |
| 8619 if (!paramValueList->length() || paramValueList->length() > 4) | |
| 8620 return 0; | |
| 8621 parameterValue = paramValueList.release(); | |
| 8622 } | |
| 8623 | |
| 8624 if (!parameterValue || !acceptCommaOperator(argsList)) | |
| 8625 return 0; | |
| 8626 | |
| 8627 parameter->append(parameterValue.release()); | |
| 8628 paramList->append(parameter.release()); | |
| 8629 } | |
| 8630 | |
| 8631 return paramList; | |
| 8632 } | |
| 8633 | |
| 8634 PassRefPtr<CSSFilterValue> CSSParser::parseCustomFilterFunctionWithAtRuleReferen
ceSyntax(CSSParserValue* value) | |
| 8635 { | |
| 8636 // | |
| 8637 // Custom filter function "at-rule reference" syntax: | |
| 8638 // | |
| 8639 // custom(<filter-name>wsp[,wsp<params>]) | |
| 8640 // | |
| 8641 // filter-name: <filter-name> | |
| 8642 // params: See the comment in CSSParser::parseCustomFilterParameters. | |
| 8643 // | |
| 8644 | |
| 8645 ASSERT(value->function); | |
| 8646 | |
| 8647 CSSParserValueList* argsList = value->function->args.get(); | |
| 8648 if (!argsList || !argsList->size()) | |
| 8649 return 0; | |
| 8650 | |
| 8651 // 1. Parse the filter name. | |
| 8652 CSSParserValue* arg = argsList->current(); | |
| 8653 if (arg->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 8654 return 0; | |
| 8655 | |
| 8656 RefPtr<CSSFilterValue> filterValue = CSSFilterValue::create(CSSFilterValue::
CustomFilterOperation); | |
| 8657 | |
| 8658 RefPtr<CSSValue> filterName = createPrimitiveStringValue(arg); | |
| 8659 filterValue->append(filterName); | |
| 8660 argsList->next(); | |
| 8661 | |
| 8662 if (!acceptCommaOperator(argsList)) | |
| 8663 return 0; | |
| 8664 | |
| 8665 // 2. Parse the parameters. | |
| 8666 RefPtr<CSSValueList> paramList = parseCustomFilterParameters(argsList); | |
| 8667 if (!paramList) | |
| 8668 return 0; | |
| 8669 | |
| 8670 if (paramList->length()) | |
| 8671 filterValue->append(paramList.release()); | |
| 8672 | |
| 8673 return filterValue; | |
| 8674 } | |
| 8675 | |
| 8676 // FIXME: The custom filters "inline" syntax is deprecated. We will remove it ev
entually. | |
| 8677 PassRefPtr<CSSFilterValue> CSSParser::parseCustomFilterFunctionWithInlineSyntax(
CSSParserValue* value) | |
| 8678 { | |
| 8679 // | |
| 8680 // Custom filter function "inline" syntax: | |
| 8681 // | |
| 8682 // custom(<vertex-shader>[wsp<fragment-shader>][,<vertex-mesh>][,<params>]) | |
| 8683 // | |
| 8684 // vertexShader: <uri> | none | |
| 8685 // fragmentShader: <uri> | none | mix(<uri> [ <blend-mode> || <alpha-compos
iting> ]?) | |
| 8686 // | |
| 8687 // blend-mode: normal | multiply | screen | overlay | darken | lighten | col
or-dodge | | |
| 8688 // color-burn | hard-light | soft-light | difference | exclusion
| hue | | |
| 8689 // saturation | color | luminosity | |
| 8690 // alpha-compositing: clear | src | dst | src-over | dst-over | src-in | dst
-in | | |
| 8691 // src-out | dst-out | src-atop | dst-atop | xor | plus | |
| 8692 // | |
| 8693 // vertexMesh: +<integer>{1,2}[wsp<box>][wsp'detached'] | |
| 8694 // box: filter-box | border-box | padding-box | content-box | |
| 8695 // | |
| 8696 // params: See the comment in CSSParser::parseCustomFilterParameters. | |
| 8697 // | |
| 8698 | |
| 8699 ASSERT(value->function); | |
| 8700 | |
| 8701 CSSParserValueList* argsList = value->function->args.get(); | |
| 8702 if (!argsList) | |
| 8703 return 0; | |
| 8704 | |
| 8705 RefPtr<CSSFilterValue> filterValue = CSSFilterValue::create(CSSFilterValue::
CustomFilterOperation); | |
| 8706 | |
| 8707 // 1. Parse the shader URLs: <vertex-shader>[wsp<fragment-shader>] | |
| 8708 RefPtr<CSSValueList> shadersList = CSSValueList::createSpaceSeparated(); | |
| 8709 bool hadAtLeastOneCustomShader = false; | |
| 8710 CSSParserValue* arg; | |
| 8711 for (arg = argsList->current(); arg; arg = argsList->next()) { | |
| 8712 RefPtr<CSSValue> value; | |
| 8713 if (arg->id == CSSValueNone) | |
| 8714 value = cssValuePool().createIdentifierValue(CSSValueNone); | |
| 8715 else if (arg->unit == CSSPrimitiveValue::CSS_URI) { | |
| 8716 KURL shaderURL = completeURL(arg->string); | |
| 8717 value = CSSShaderValue::create(shaderURL.string()); | |
| 8718 hadAtLeastOneCustomShader = true; | |
| 8719 } else if (argsList->currentIndex() == 1 && arg->unit == CSSParserValue:
:Function) { | |
| 8720 if (!(value = parseMixFunction(arg))) | |
| 8721 return 0; | |
| 8722 hadAtLeastOneCustomShader = true; | |
| 8723 } | |
| 8724 | |
| 8725 if (!value) | |
| 8726 break; | |
| 8727 shadersList->append(value.release()); | |
| 8728 } | |
| 8729 | |
| 8730 if (!shadersList->length() || !hadAtLeastOneCustomShader || shadersList->len
gth() > 2 || !acceptCommaOperator(argsList)) | |
| 8731 return 0; | |
| 8732 | |
| 8733 filterValue->append(shadersList.release()); | |
| 8734 | |
| 8735 // 2. Parse the mesh size <vertex-mesh> | |
| 8736 RefPtr<CSSValueList> meshSizeList = CSSValueList::createSpaceSeparated(); | |
| 8737 | |
| 8738 for (arg = argsList->current(); arg; arg = argsList->next()) { | |
| 8739 if (!validUnit(arg, FInteger | FNonNeg, HTMLStandardMode)) | |
| 8740 break; | |
| 8741 int integerValue = clampToInteger(arg->fValue); | |
| 8742 // According to the specification we can only accept positive non-zero v
alues. | |
| 8743 if (integerValue < 1) | |
| 8744 return 0; | |
| 8745 meshSizeList->append(cssValuePool().createValue(integerValue, CSSPrimiti
veValue::CSS_NUMBER)); | |
| 8746 } | |
| 8747 | |
| 8748 if (meshSizeList->length() > 2) | |
| 8749 return 0; | |
| 8750 | |
| 8751 // FIXME: For legacy content, we accept the mesh box types. We don't do anyt
hing else with them. | |
| 8752 // Eventually, we'll remove them completely. | |
| 8753 // https://bugs.webkit.org/show_bug.cgi?id=103778 | |
| 8754 if ((arg = argsList->current()) && (arg->id == CSSValueBorderBox || arg->id
== CSSValuePaddingBox | |
| 8755 || arg->id == CSSValueContentBox || arg->id == CSSValueFilterBox)) | |
| 8756 argsList->next(); | |
| 8757 | |
| 8758 if ((arg = argsList->current()) && arg->id == CSSValueDetached) { | |
| 8759 meshSizeList->append(cssValuePool().createIdentifierValue(arg->id)); | |
| 8760 argsList->next(); | |
| 8761 } | |
| 8762 | |
| 8763 if (meshSizeList->length()) { | |
| 8764 if (!acceptCommaOperator(argsList)) | |
| 8765 return 0; | |
| 8766 filterValue->append(meshSizeList.release()); | |
| 8767 } | |
| 8768 | |
| 8769 // 3. Parse the parameters. | |
| 8770 RefPtr<CSSValueList> paramList = parseCustomFilterParameters(argsList); | |
| 8771 if (!paramList) | |
| 8772 return 0; | |
| 8773 | |
| 8774 if (paramList->length()) | |
| 8775 filterValue->append(paramList.release()); | |
| 8776 | |
| 8777 return filterValue; | |
| 8778 } | |
| 8779 | |
| 8780 PassRefPtr<CSSFilterValue> CSSParser::parseCustomFilterFunction(CSSParserValue*
value) | |
| 8781 { | |
| 8782 ASSERT(value->function); | |
| 8783 | |
| 8784 // Look ahead to determine which syntax the custom function is using. | |
| 8785 // Both the at-rule reference syntax and the inline syntax require at least
one argument. | |
| 8786 CSSParserValueList* argsList = value->function->args.get(); | |
| 8787 if (!argsList || !argsList->size()) | |
| 8788 return 0; | |
| 8789 | |
| 8790 // The at-rule reference syntax expects a single ident or an ident followed
by a comma. | |
| 8791 // e.g. custom(my-filter) or custom(my-filter, ...) | |
| 8792 // In contrast, when the inline syntax starts with an ident like "none", it
expects a uri or a mix function next. | |
| 8793 // e.g. custom(none url(...)) or custom(none mix(...) | |
| 8794 bool isAtRuleReferenceSyntax = argsList->valueAt(0)->unit == CSSPrimitiveVal
ue::CSS_IDENT | |
| 8795 && (argsList->size() == 1 || isComma(argsList->valueAt(1))); | |
| 8796 return isAtRuleReferenceSyntax ? parseCustomFilterFunctionWithAtRuleReferenc
eSyntax(value) : parseCustomFilterFunctionWithInlineSyntax(value); | |
| 8797 } | |
| 8798 | |
| 8799 PassRefPtr<CSSValueList> CSSParser::parseCustomFilterTransform(CSSParserValueLis
t* valueList) | |
| 8800 { | |
| 8801 if (!valueList) | |
| 8802 return 0; | |
| 8803 | |
| 8804 // CSS Shaders' custom() transforms are space separated and comma terminated
. | |
| 8805 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); | |
| 8806 for (CSSParserValue* value = valueList->current(); value; value = valueList-
>next()) { | |
| 8807 if (isComma(value)) | |
| 8808 break; | |
| 8809 | |
| 8810 RefPtr<CSSValue> parsedTransformValue = parseTransformValue(value); | |
| 8811 if (!parsedTransformValue) | |
| 8812 return 0; | |
| 8813 | |
| 8814 list->append(parsedTransformValue.release()); | |
| 8815 } | |
| 8816 | |
| 8817 return list.release(); | |
| 8818 } | |
| 8819 | |
| 8820 PassRefPtr<CSSShaderValue> CSSParser::parseFilterRuleSrcUriAndFormat(CSSParserVa
lueList* valueList) | |
| 8821 { | |
| 8822 CSSParserValue* value = valueList->current(); | |
| 8823 ASSERT(value && value->unit == CSSPrimitiveValue::CSS_URI); | |
| 8824 RefPtr<CSSShaderValue> shaderValue = CSSShaderValue::create(completeURL(valu
e->string)); | |
| 8825 | |
| 8826 value = valueList->next(); | |
| 8827 if (value && value->unit == CSSParserValue::Function && equalIgnoringCase(va
lue->function->name, "format(")) { | |
| 8828 CSSParserValueList* args = value->function->args.get(); | |
| 8829 if (!args || args->size() != 1) | |
| 8830 return 0; | |
| 8831 | |
| 8832 CSSParserValue* arg = args->current(); | |
| 8833 if (arg->unit != CSSPrimitiveValue::CSS_STRING) | |
| 8834 return 0; | |
| 8835 | |
| 8836 shaderValue->setFormat(arg->string); | |
| 8837 valueList->next(); | |
| 8838 } | |
| 8839 | |
| 8840 return shaderValue.release(); | |
| 8841 } | |
| 8842 | |
| 8843 bool CSSParser::parseFilterRuleSrc() | |
| 8844 { | |
| 8845 RefPtr<CSSValueList> srcList = CSSValueList::createCommaSeparated(); | |
| 8846 | |
| 8847 CSSParserValue* value = m_valueList->current(); | |
| 8848 while (value) { | |
| 8849 if (value->unit != CSSPrimitiveValue::CSS_URI) | |
| 8850 return false; | |
| 8851 | |
| 8852 RefPtr<CSSShaderValue> shaderValue = parseFilterRuleSrcUriAndFormat(m_va
lueList.get()); | |
| 8853 if (!shaderValue) | |
| 8854 return false; | |
| 8855 srcList->append(shaderValue.release()); | |
| 8856 | |
| 8857 if (!acceptCommaOperator(m_valueList.get())) | |
| 8858 return false; | |
| 8859 | |
| 8860 value = m_valueList->current(); | |
| 8861 } | |
| 8862 | |
| 8863 if (!srcList->length()) | |
| 8864 return false; | |
| 8865 | |
| 8866 addProperty(CSSPropertySrc, srcList.release(), m_important); | |
| 8867 return true; | |
| 8868 } | |
| 8869 | |
| 8870 StyleRuleBase* CSSParser::createFilterRule(const CSSParserString& filterName) | |
| 8871 { | |
| 8872 RefPtr<StyleRuleFilter> rule = StyleRuleFilter::create(filterName); | |
| 8873 rule->setProperties(createStylePropertySet()); | |
| 8874 clearProperties(); | |
| 8875 StyleRuleFilter* result = rule.get(); | |
| 8876 m_parsedRules.append(rule.release()); | |
| 8877 return result; | |
| 8878 } | |
| 8879 | |
| 8880 | |
| 8881 PassRefPtr<CSSFilterValue> CSSParser::parseBuiltinFilterArguments(CSSParserValue
List* args, CSSFilterValue::FilterOperationType filterType) | |
| 8882 { | |
| 8883 RefPtr<CSSFilterValue> filterValue = CSSFilterValue::create(filterType); | |
| 8884 ASSERT(args); | |
| 8885 | |
| 8886 switch (filterType) { | |
| 8887 case CSSFilterValue::GrayscaleFilterOperation: | |
| 8888 case CSSFilterValue::SepiaFilterOperation: | |
| 8889 case CSSFilterValue::SaturateFilterOperation: | |
| 8890 case CSSFilterValue::InvertFilterOperation: | |
| 8891 case CSSFilterValue::OpacityFilterOperation: | |
| 8892 case CSSFilterValue::ContrastFilterOperation: { | |
| 8893 // One optional argument, 0-1 or 0%-100%, if missing use 100%. | |
| 8894 if (args->size() > 1) | |
| 8895 return 0; | |
| 8896 | |
| 8897 if (args->size()) { | |
| 8898 CSSParserValue* value = args->current(); | |
| 8899 if (!validUnit(value, FNumber | FPercent | FNonNeg, HTMLStandardMode
)) | |
| 8900 return 0; | |
| 8901 | |
| 8902 double amount = value->fValue; | |
| 8903 | |
| 8904 // Saturate and Contrast allow values over 100%. | |
| 8905 if (filterType != CSSFilterValue::SaturateFilterOperation | |
| 8906 && filterType != CSSFilterValue::ContrastFilterOperation) { | |
| 8907 double maxAllowed = value->unit == CSSPrimitiveValue::CSS_PERCEN
TAGE ? 100.0 : 1.0; | |
| 8908 if (amount > maxAllowed) | |
| 8909 return 0; | |
| 8910 } | |
| 8911 | |
| 8912 filterValue->append(cssValuePool().createValue(amount, static_cast<C
SSPrimitiveValue::UnitTypes>(value->unit))); | |
| 8913 } | |
| 8914 break; | |
| 8915 } | |
| 8916 case CSSFilterValue::BrightnessFilterOperation: { | |
| 8917 // One optional argument, if missing use 100%. | |
| 8918 if (args->size() > 1) | |
| 8919 return 0; | |
| 8920 | |
| 8921 if (args->size()) { | |
| 8922 CSSParserValue* value = args->current(); | |
| 8923 if (!validUnit(value, FNumber | FPercent, HTMLStandardMode)) | |
| 8924 return 0; | |
| 8925 | |
| 8926 filterValue->append(cssValuePool().createValue(value->fValue, static
_cast<CSSPrimitiveValue::UnitTypes>(value->unit))); | |
| 8927 } | |
| 8928 break; | |
| 8929 } | |
| 8930 case CSSFilterValue::HueRotateFilterOperation: { | |
| 8931 // hue-rotate() takes one optional angle. | |
| 8932 if (args->size() > 1) | |
| 8933 return 0; | |
| 8934 | |
| 8935 if (args->size()) { | |
| 8936 CSSParserValue* argument = args->current(); | |
| 8937 if (!validUnit(argument, FAngle, HTMLStandardMode)) | |
| 8938 return 0; | |
| 8939 | |
| 8940 filterValue->append(createPrimitiveNumericValue(argument)); | |
| 8941 } | |
| 8942 break; | |
| 8943 } | |
| 8944 case CSSFilterValue::BlurFilterOperation: { | |
| 8945 // Blur takes a single length. Zero parameters are allowed. | |
| 8946 if (args->size() > 1) | |
| 8947 return 0; | |
| 8948 | |
| 8949 if (args->size()) { | |
| 8950 CSSParserValue* argument = args->current(); | |
| 8951 if (!validUnit(argument, FLength | FNonNeg, HTMLStandardMode)) | |
| 8952 return 0; | |
| 8953 | |
| 8954 filterValue->append(createPrimitiveNumericValue(argument)); | |
| 8955 } | |
| 8956 break; | |
| 8957 } | |
| 8958 case CSSFilterValue::DropShadowFilterOperation: { | |
| 8959 // drop-shadow() takes a single shadow. | |
| 8960 RefPtr<CSSValueList> shadowValueList = parseShadow(args, CSSPropertyWebk
itFilter); | |
| 8961 if (!shadowValueList || shadowValueList->length() != 1) | |
| 8962 return 0; | |
| 8963 | |
| 8964 filterValue->append((shadowValueList.release())->itemWithoutBoundsCheck(
0)); | |
| 8965 break; | |
| 8966 } | |
| 8967 default: | |
| 8968 ASSERT_NOT_REACHED(); | |
| 8969 } | |
| 8970 return filterValue.release(); | |
| 8971 } | |
| 8972 | |
| 8973 PassRefPtr<CSSValueList> CSSParser::parseFilter() | |
| 8974 { | |
| 8975 if (!m_valueList) | |
| 8976 return 0; | |
| 8977 | |
| 8978 // The filter is a list of functional primitives that specify individual ope
rations. | |
| 8979 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); | |
| 8980 for (CSSParserValue* value = m_valueList->current(); value; value = m_valueL
ist->next()) { | |
| 8981 if (value->unit != CSSPrimitiveValue::CSS_URI && (value->unit != CSSPars
erValue::Function || !value->function)) | |
| 8982 return 0; | |
| 8983 | |
| 8984 CSSFilterValue::FilterOperationType filterType = CSSFilterValue::Unknown
FilterOperation; | |
| 8985 | |
| 8986 // See if the specified primitive is one we understand. | |
| 8987 if (value->unit == CSSPrimitiveValue::CSS_URI) { | |
| 8988 RefPtr<CSSFilterValue> referenceFilterValue = CSSFilterValue::create
(CSSFilterValue::ReferenceFilterOperation); | |
| 8989 list->append(referenceFilterValue); | |
| 8990 referenceFilterValue->append(CSSSVGDocumentValue::create(value->stri
ng)); | |
| 8991 } else { | |
| 8992 const CSSParserString name = value->function->name; | |
| 8993 unsigned maximumArgumentCount = 1; | |
| 8994 | |
| 8995 filterInfoForName(name, filterType, maximumArgumentCount); | |
| 8996 | |
| 8997 if (filterType == CSSFilterValue::UnknownFilterOperation) | |
| 8998 return 0; | |
| 8999 | |
| 9000 if (filterType == CSSFilterValue::CustomFilterOperation) { | |
| 9001 // Make sure parsing fails if custom filters are disabled. | |
| 9002 if (!RuntimeEnabledFeatures::cssCustomFilterEnabled()) | |
| 9003 return 0; | |
| 9004 | |
| 9005 RefPtr<CSSFilterValue> filterValue = parseCustomFilterFunction(v
alue); | |
| 9006 if (!filterValue) | |
| 9007 return 0; | |
| 9008 list->append(filterValue.release()); | |
| 9009 continue; | |
| 9010 } | |
| 9011 CSSParserValueList* args = value->function->args.get(); | |
| 9012 if (!args) | |
| 9013 return 0; | |
| 9014 | |
| 9015 RefPtr<CSSFilterValue> filterValue = parseBuiltinFilterArguments(arg
s, filterType); | |
| 9016 if (!filterValue) | |
| 9017 return 0; | |
| 9018 | |
| 9019 list->append(filterValue); | |
| 9020 } | |
| 9021 } | |
| 9022 | |
| 9023 return list.release(); | |
| 9024 } | |
| 9025 | |
| 9026 static bool validFlowName(const String& flowName) | |
| 9027 { | |
| 9028 return !(equalIgnoringCase(flowName, "auto") | |
| 9029 || equalIgnoringCase(flowName, "default") | |
| 9030 || equalIgnoringCase(flowName, "inherit") | |
| 9031 || equalIgnoringCase(flowName, "initial") | |
| 9032 || equalIgnoringCase(flowName, "none")); | |
| 9033 } | |
| 9034 | |
| 9035 bool CSSParser::parseFlowThread(const String& flowName) | |
| 9036 { | |
| 9037 setupParser("@-internal-decls -webkit-flow-into:", flowName, ""); | |
| 9038 cssyyparse(this); | |
| 9039 | |
| 9040 m_rule = 0; | |
| 9041 | |
| 9042 return ((m_parsedProperties.size() == 1) && (m_parsedProperties.first().id()
== CSSPropertyWebkitFlowInto)); | |
| 9043 } | |
| 9044 | |
| 9045 // none | <ident> | |
| 9046 bool CSSParser::parseFlowThread(CSSPropertyID propId, bool important) | |
| 9047 { | |
| 9048 ASSERT(propId == CSSPropertyWebkitFlowInto); | |
| 9049 ASSERT(RuntimeEnabledFeatures::cssRegionsEnabled()); | |
| 9050 | |
| 9051 if (m_valueList->size() != 1) | |
| 9052 return false; | |
| 9053 | |
| 9054 CSSParserValue* value = m_valueList->current(); | |
| 9055 if (!value) | |
| 9056 return false; | |
| 9057 | |
| 9058 if (value->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 9059 return false; | |
| 9060 | |
| 9061 if (value->id == CSSValueNone) { | |
| 9062 addProperty(propId, cssValuePool().createIdentifierValue(value->id), imp
ortant); | |
| 9063 return true; | |
| 9064 } | |
| 9065 | |
| 9066 String inputProperty = String(value->string); | |
| 9067 if (!inputProperty.isEmpty()) { | |
| 9068 if (!validFlowName(inputProperty)) | |
| 9069 return false; | |
| 9070 addProperty(propId, cssValuePool().createValue(inputProperty, CSSPrimiti
veValue::CSS_STRING), important); | |
| 9071 } else | |
| 9072 addProperty(propId, cssValuePool().createIdentifierValue(CSSValueNone),
important); | |
| 9073 | |
| 9074 return true; | |
| 9075 } | |
| 9076 | |
| 9077 // -webkit-flow-from: none | <ident> | |
| 9078 bool CSSParser::parseRegionThread(CSSPropertyID propId, bool important) | |
| 9079 { | |
| 9080 ASSERT(propId == CSSPropertyWebkitFlowFrom); | |
| 9081 ASSERT(RuntimeEnabledFeatures::cssRegionsEnabled()); | |
| 9082 | |
| 9083 if (m_valueList->size() != 1) | |
| 9084 return false; | |
| 9085 | |
| 9086 CSSParserValue* value = m_valueList->current(); | |
| 9087 if (!value) | |
| 9088 return false; | |
| 9089 | |
| 9090 if (value->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 9091 return false; | |
| 9092 | |
| 9093 if (value->id == CSSValueNone) | |
| 9094 addProperty(propId, cssValuePool().createIdentifierValue(value->id), imp
ortant); | |
| 9095 else { | |
| 9096 String inputProperty = String(value->string); | |
| 9097 if (!inputProperty.isEmpty()) { | |
| 9098 if (!validFlowName(inputProperty)) | |
| 9099 return false; | |
| 9100 addProperty(propId, cssValuePool().createValue(inputProperty, CSSPri
mitiveValue::CSS_STRING), important); | |
| 9101 } else | |
| 9102 addProperty(propId, cssValuePool().createIdentifierValue(CSSValueNon
e), important); | |
| 9103 } | |
| 9104 | |
| 9105 return true; | |
| 9106 } | |
| 9107 | |
| 9108 bool CSSParser::parseTransformOrigin(CSSPropertyID propId, CSSPropertyID& propId
1, CSSPropertyID& propId2, CSSPropertyID& propId3, RefPtr<CSSValue>& value, RefP
tr<CSSValue>& value2, RefPtr<CSSValue>& value3) | |
| 9109 { | |
| 9110 propId1 = propId; | |
| 9111 propId2 = propId; | |
| 9112 propId3 = propId; | |
| 9113 if (propId == CSSPropertyWebkitTransformOrigin) { | |
| 9114 propId1 = CSSPropertyWebkitTransformOriginX; | |
| 9115 propId2 = CSSPropertyWebkitTransformOriginY; | |
| 9116 propId3 = CSSPropertyWebkitTransformOriginZ; | |
| 9117 } | |
| 9118 | |
| 9119 switch (propId) { | |
| 9120 case CSSPropertyWebkitTransformOrigin: | |
| 9121 if (!parseTransformOriginShorthand(value, value2, value3)) | |
| 9122 return false; | |
| 9123 // parseTransformOriginShorthand advances the m_valueList pointer | |
| 9124 break; | |
| 9125 case CSSPropertyWebkitTransformOriginX: { | |
| 9126 value = parseFillPositionX(m_valueList.get()); | |
| 9127 if (value) | |
| 9128 m_valueList->next(); | |
| 9129 break; | |
| 9130 } | |
| 9131 case CSSPropertyWebkitTransformOriginY: { | |
| 9132 value = parseFillPositionY(m_valueList.get()); | |
| 9133 if (value) | |
| 9134 m_valueList->next(); | |
| 9135 break; | |
| 9136 } | |
| 9137 case CSSPropertyWebkitTransformOriginZ: { | |
| 9138 if (validUnit(m_valueList->current(), FLength)) | |
| 9139 value = createPrimitiveNumericValue(m_valueList->current()); | |
| 9140 if (value) | |
| 9141 m_valueList->next(); | |
| 9142 break; | |
| 9143 } | |
| 9144 default: | |
| 9145 ASSERT_NOT_REACHED(); | |
| 9146 return false; | |
| 9147 } | |
| 9148 | |
| 9149 return value; | |
| 9150 } | |
| 9151 | |
| 9152 bool CSSParser::parsePerspectiveOrigin(CSSPropertyID propId, CSSPropertyID& prop
Id1, CSSPropertyID& propId2, RefPtr<CSSValue>& value, RefPtr<CSSValue>& value2) | |
| 9153 { | |
| 9154 propId1 = propId; | |
| 9155 propId2 = propId; | |
| 9156 if (propId == CSSPropertyWebkitPerspectiveOrigin) { | |
| 9157 propId1 = CSSPropertyWebkitPerspectiveOriginX; | |
| 9158 propId2 = CSSPropertyWebkitPerspectiveOriginY; | |
| 9159 } | |
| 9160 | |
| 9161 switch (propId) { | |
| 9162 case CSSPropertyWebkitPerspectiveOrigin: | |
| 9163 if (m_valueList->size() > 2) | |
| 9164 return false; | |
| 9165 parse2ValuesFillPosition(m_valueList.get(), value, value2); | |
| 9166 break; | |
| 9167 case CSSPropertyWebkitPerspectiveOriginX: { | |
| 9168 value = parseFillPositionX(m_valueList.get()); | |
| 9169 if (value) | |
| 9170 m_valueList->next(); | |
| 9171 break; | |
| 9172 } | |
| 9173 case CSSPropertyWebkitPerspectiveOriginY: { | |
| 9174 value = parseFillPositionY(m_valueList.get()); | |
| 9175 if (value) | |
| 9176 m_valueList->next(); | |
| 9177 break; | |
| 9178 } | |
| 9179 default: | |
| 9180 ASSERT_NOT_REACHED(); | |
| 9181 return false; | |
| 9182 } | |
| 9183 | |
| 9184 return value; | |
| 9185 } | |
| 9186 | |
| 9187 bool CSSParser::parseTouchAction(bool important) | |
| 9188 { | |
| 9189 if (!RuntimeEnabledFeatures::cssTouchActionEnabled()) | |
| 9190 return false; | |
| 9191 | |
| 9192 CSSParserValue* value = m_valueList->current(); | |
| 9193 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); | |
| 9194 if (m_valueList->size() == 1 && value && (value->id == CSSValueAuto || value
->id == CSSValueNone)) { | |
| 9195 list->append(cssValuePool().createIdentifierValue(value->id)); | |
| 9196 addProperty(CSSPropertyTouchAction, list.release(), important); | |
| 9197 m_valueList->next(); | |
| 9198 return true; | |
| 9199 } | |
| 9200 | |
| 9201 bool isValid = true; | |
| 9202 while (isValid && value) { | |
| 9203 switch (value->id) { | |
| 9204 case CSSValuePanX: | |
| 9205 case CSSValuePanY: { | |
| 9206 RefPtr<CSSValue> panValue = cssValuePool().createIdentifierValue(val
ue->id); | |
| 9207 if (list->hasValue(panValue.get())) { | |
| 9208 isValid = false; | |
| 9209 break; | |
| 9210 } | |
| 9211 list->append(panValue.release()); | |
| 9212 break; | |
| 9213 } | |
| 9214 default: | |
| 9215 isValid = false; | |
| 9216 break; | |
| 9217 } | |
| 9218 if (isValid) | |
| 9219 value = m_valueList->next(); | |
| 9220 } | |
| 9221 | |
| 9222 if (list->length() && isValid) { | |
| 9223 addProperty(CSSPropertyTouchAction, list.release(), important); | |
| 9224 return true; | |
| 9225 } | |
| 9226 | |
| 9227 return false; | |
| 9228 } | |
| 9229 | |
| 9230 void CSSParser::addTextDecorationProperty(CSSPropertyID propId, PassRefPtr<CSSVa
lue> value, bool important) | |
| 9231 { | |
| 9232 // The text-decoration-line property takes priority over text-decoration, un
less the latter has important priority set. | |
| 9233 if (propId == CSSPropertyTextDecoration && !important && !inShorthand()) { | |
| 9234 for (unsigned i = 0; i < m_parsedProperties.size(); ++i) { | |
| 9235 if (m_parsedProperties[i].id() == CSSPropertyTextDecorationLine) | |
| 9236 return; | |
| 9237 } | |
| 9238 } | |
| 9239 addProperty(propId, value, important); | |
| 9240 } | |
| 9241 | |
| 9242 bool CSSParser::parseTextDecoration(CSSPropertyID propId, bool important) | |
| 9243 { | |
| 9244 if (propId == CSSPropertyTextDecorationLine | |
| 9245 && !RuntimeEnabledFeatures::css3TextDecorationsEnabled()) | |
| 9246 return false; | |
| 9247 | |
| 9248 CSSParserValue* value = m_valueList->current(); | |
| 9249 if (value && value->id == CSSValueNone) { | |
| 9250 addTextDecorationProperty(propId, cssValuePool().createIdentifierValue(C
SSValueNone), important); | |
| 9251 m_valueList->next(); | |
| 9252 return true; | |
| 9253 } | |
| 9254 | |
| 9255 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); | |
| 9256 bool isValid = true; | |
| 9257 while (isValid && value) { | |
| 9258 switch (value->id) { | |
| 9259 case CSSValueUnderline: | |
| 9260 case CSSValueOverline: | |
| 9261 case CSSValueLineThrough: | |
| 9262 case CSSValueBlink: | |
| 9263 list->append(cssValuePool().createIdentifierValue(value->id)); | |
| 9264 break; | |
| 9265 default: | |
| 9266 isValid = false; | |
| 9267 break; | |
| 9268 } | |
| 9269 if (isValid) | |
| 9270 value = m_valueList->next(); | |
| 9271 } | |
| 9272 | |
| 9273 // Values are either valid or in shorthand scope. | |
| 9274 if (list->length() && (isValid || inShorthand())) { | |
| 9275 addTextDecorationProperty(propId, list.release(), important); | |
| 9276 return true; | |
| 9277 } | |
| 9278 | |
| 9279 return false; | |
| 9280 } | |
| 9281 | |
| 9282 bool CSSParser::parseTextUnderlinePosition(bool important) | |
| 9283 { | |
| 9284 // The text-underline-position property has syntax "auto | [ under || [ left
| right ] ]". | |
| 9285 // However, values 'left' and 'right' are not implemented yet, so we will pa
rse syntax | |
| 9286 // "auto | under" for now. | |
| 9287 CSSParserValue* value = m_valueList->current(); | |
| 9288 switch (value->id) { | |
| 9289 case CSSValueAuto: | |
| 9290 case CSSValueUnder: | |
| 9291 if (m_valueList->next()) | |
| 9292 return false; | |
| 9293 addProperty(CSSPropertyTextUnderlinePosition, cssValuePool().createIdent
ifierValue(value->id), important); | |
| 9294 return true; | |
| 9295 default: | |
| 9296 return false; | |
| 9297 } | |
| 9298 } | |
| 9299 | |
| 9300 bool CSSParser::parseTextEmphasisStyle(bool important) | |
| 9301 { | |
| 9302 unsigned valueListSize = m_valueList->size(); | |
| 9303 | |
| 9304 RefPtr<CSSPrimitiveValue> fill; | |
| 9305 RefPtr<CSSPrimitiveValue> shape; | |
| 9306 | |
| 9307 for (CSSParserValue* value = m_valueList->current(); value; value = m_valueL
ist->next()) { | |
| 9308 if (value->unit == CSSPrimitiveValue::CSS_STRING) { | |
| 9309 if (fill || shape || (valueListSize != 1 && !inShorthand())) | |
| 9310 return false; | |
| 9311 addProperty(CSSPropertyWebkitTextEmphasisStyle, createPrimitiveStrin
gValue(value), important); | |
| 9312 m_valueList->next(); | |
| 9313 return true; | |
| 9314 } | |
| 9315 | |
| 9316 if (value->id == CSSValueNone) { | |
| 9317 if (fill || shape || (valueListSize != 1 && !inShorthand())) | |
| 9318 return false; | |
| 9319 addProperty(CSSPropertyWebkitTextEmphasisStyle, cssValuePool().creat
eIdentifierValue(CSSValueNone), important); | |
| 9320 m_valueList->next(); | |
| 9321 return true; | |
| 9322 } | |
| 9323 | |
| 9324 if (value->id == CSSValueOpen || value->id == CSSValueFilled) { | |
| 9325 if (fill) | |
| 9326 return false; | |
| 9327 fill = cssValuePool().createIdentifierValue(value->id); | |
| 9328 } else if (value->id == CSSValueDot || value->id == CSSValueCircle || va
lue->id == CSSValueDoubleCircle || value->id == CSSValueTriangle || value->id ==
CSSValueSesame) { | |
| 9329 if (shape) | |
| 9330 return false; | |
| 9331 shape = cssValuePool().createIdentifierValue(value->id); | |
| 9332 } else if (!inShorthand()) | |
| 9333 return false; | |
| 9334 else | |
| 9335 break; | |
| 9336 } | |
| 9337 | |
| 9338 if (fill && shape) { | |
| 9339 RefPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated()
; | |
| 9340 parsedValues->append(fill.release()); | |
| 9341 parsedValues->append(shape.release()); | |
| 9342 addProperty(CSSPropertyWebkitTextEmphasisStyle, parsedValues.release(),
important); | |
| 9343 return true; | |
| 9344 } | |
| 9345 if (fill) { | |
| 9346 addProperty(CSSPropertyWebkitTextEmphasisStyle, fill.release(), importan
t); | |
| 9347 return true; | |
| 9348 } | |
| 9349 if (shape) { | |
| 9350 addProperty(CSSPropertyWebkitTextEmphasisStyle, shape.release(), importa
nt); | |
| 9351 return true; | |
| 9352 } | |
| 9353 | |
| 9354 return false; | |
| 9355 } | |
| 9356 | |
| 9357 PassRefPtr<CSSValue> CSSParser::parseTextIndent() | |
| 9358 { | |
| 9359 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); | |
| 9360 | |
| 9361 // <length> | <percentage> | inherit | |
| 9362 if (m_valueList->size() == 1) { | |
| 9363 CSSParserValue* value = m_valueList->current(); | |
| 9364 if (!value->id && validUnit(value, FLength | FPercent)) { | |
| 9365 list->append(createPrimitiveNumericValue(value)); | |
| 9366 m_valueList->next(); | |
| 9367 return list.release(); | |
| 9368 } | |
| 9369 } | |
| 9370 | |
| 9371 if (!RuntimeEnabledFeatures::css3TextEnabled()) | |
| 9372 return 0; | |
| 9373 | |
| 9374 // The case where text-indent has only <length>(or <percentage>) value | |
| 9375 // is handled above if statement even though css3TextEnabled() returns true. | |
| 9376 | |
| 9377 // [ [ <length> | <percentage> ] && each-line ] | inherit | |
| 9378 if (m_valueList->size() != 2) | |
| 9379 return 0; | |
| 9380 | |
| 9381 CSSParserValue* firstValue = m_valueList->current(); | |
| 9382 CSSParserValue* secondValue = m_valueList->next(); | |
| 9383 CSSParserValue* lengthOrPercentageValue = 0; | |
| 9384 | |
| 9385 // [ <length> | <percentage> ] each-line | |
| 9386 if (validUnit(firstValue, FLength | FPercent) && secondValue->id == CSSValue
EachLine) | |
| 9387 lengthOrPercentageValue = firstValue; | |
| 9388 // each-line [ <length> | <percentage> ] | |
| 9389 else if (firstValue->id == CSSValueEachLine && validUnit(secondValue, FLengt
h | FPercent)) | |
| 9390 lengthOrPercentageValue = secondValue; | |
| 9391 | |
| 9392 if (lengthOrPercentageValue) { | |
| 9393 list->append(createPrimitiveNumericValue(lengthOrPercentageValue)); | |
| 9394 list->append(cssValuePool().createIdentifierValue(CSSValueEachLine)); | |
| 9395 m_valueList->next(); | |
| 9396 return list.release(); | |
| 9397 } | |
| 9398 | |
| 9399 return 0; | |
| 9400 } | |
| 9401 | |
| 9402 bool CSSParser::parseLineBoxContain(bool important) | |
| 9403 { | |
| 9404 LineBoxContain lineBoxContain = LineBoxContainNone; | |
| 9405 | |
| 9406 for (CSSParserValue* value = m_valueList->current(); value; value = m_valueL
ist->next()) { | |
| 9407 if (value->id == CSSValueBlock) { | |
| 9408 if (lineBoxContain & LineBoxContainBlock) | |
| 9409 return false; | |
| 9410 lineBoxContain |= LineBoxContainBlock; | |
| 9411 } else if (value->id == CSSValueInline) { | |
| 9412 if (lineBoxContain & LineBoxContainInline) | |
| 9413 return false; | |
| 9414 lineBoxContain |= LineBoxContainInline; | |
| 9415 } else if (value->id == CSSValueFont) { | |
| 9416 if (lineBoxContain & LineBoxContainFont) | |
| 9417 return false; | |
| 9418 lineBoxContain |= LineBoxContainFont; | |
| 9419 } else if (value->id == CSSValueGlyphs) { | |
| 9420 if (lineBoxContain & LineBoxContainGlyphs) | |
| 9421 return false; | |
| 9422 lineBoxContain |= LineBoxContainGlyphs; | |
| 9423 } else if (value->id == CSSValueReplaced) { | |
| 9424 if (lineBoxContain & LineBoxContainReplaced) | |
| 9425 return false; | |
| 9426 lineBoxContain |= LineBoxContainReplaced; | |
| 9427 } else if (value->id == CSSValueInlineBox) { | |
| 9428 if (lineBoxContain & LineBoxContainInlineBox) | |
| 9429 return false; | |
| 9430 lineBoxContain |= LineBoxContainInlineBox; | |
| 9431 } else | |
| 9432 return false; | |
| 9433 } | |
| 9434 | |
| 9435 if (!lineBoxContain) | |
| 9436 return false; | |
| 9437 | |
| 9438 addProperty(CSSPropertyWebkitLineBoxContain, CSSLineBoxContainValue::create(
lineBoxContain), important); | |
| 9439 return true; | |
| 9440 } | |
| 9441 | |
| 9442 bool CSSParser::parseFontFeatureTag(CSSValueList* settings) | |
| 9443 { | |
| 9444 // Feature tag name consists of 4-letter characters. | |
| 9445 static const unsigned tagNameLength = 4; | |
| 9446 | |
| 9447 CSSParserValue* value = m_valueList->current(); | |
| 9448 // Feature tag name comes first | |
| 9449 if (value->unit != CSSPrimitiveValue::CSS_STRING) | |
| 9450 return false; | |
| 9451 if (value->string.length() != tagNameLength) | |
| 9452 return false; | |
| 9453 for (unsigned i = 0; i < tagNameLength; ++i) { | |
| 9454 // Limits the range of characters to 0x20-0x7E, following the tag name r
ules defiend in the OpenType specification. | |
| 9455 UChar character = value->string[i]; | |
| 9456 if (character < 0x20 || character > 0x7E) | |
| 9457 return false; | |
| 9458 } | |
| 9459 | |
| 9460 AtomicString tag = value->string; | |
| 9461 int tagValue = 1; | |
| 9462 // Feature tag values could follow: <integer> | on | off | |
| 9463 value = m_valueList->next(); | |
| 9464 if (value) { | |
| 9465 if (value->unit == CSSPrimitiveValue::CSS_NUMBER && value->isInt && valu
e->fValue >= 0) { | |
| 9466 tagValue = clampToInteger(value->fValue); | |
| 9467 if (tagValue < 0) | |
| 9468 return false; | |
| 9469 m_valueList->next(); | |
| 9470 } else if (value->id == CSSValueOn || value->id == CSSValueOff) { | |
| 9471 tagValue = value->id == CSSValueOn; | |
| 9472 m_valueList->next(); | |
| 9473 } | |
| 9474 } | |
| 9475 settings->append(CSSFontFeatureValue::create(tag, tagValue)); | |
| 9476 return true; | |
| 9477 } | |
| 9478 | |
| 9479 bool CSSParser::parseFontFeatureSettings(bool important) | |
| 9480 { | |
| 9481 if (m_valueList->size() == 1 && m_valueList->current()->id == CSSValueNormal
) { | |
| 9482 RefPtr<CSSPrimitiveValue> normalValue = cssValuePool().createIdentifierV
alue(CSSValueNormal); | |
| 9483 m_valueList->next(); | |
| 9484 addProperty(CSSPropertyWebkitFontFeatureSettings, normalValue.release(),
important); | |
| 9485 return true; | |
| 9486 } | |
| 9487 | |
| 9488 RefPtr<CSSValueList> settings = CSSValueList::createCommaSeparated(); | |
| 9489 for (CSSParserValue* value = m_valueList->current(); value; value = m_valueL
ist->next()) { | |
| 9490 if (!parseFontFeatureTag(settings.get())) | |
| 9491 return false; | |
| 9492 | |
| 9493 // If the list isn't parsed fully, the current value should be comma. | |
| 9494 value = m_valueList->current(); | |
| 9495 if (value && !isComma(value)) | |
| 9496 return false; | |
| 9497 } | |
| 9498 if (settings->length()) { | |
| 9499 addProperty(CSSPropertyWebkitFontFeatureSettings, settings.release(), im
portant); | |
| 9500 return true; | |
| 9501 } | |
| 9502 return false; | |
| 9503 } | |
| 9504 | |
| 9505 bool CSSParser::parseFontVariantLigatures(bool important) | |
| 9506 { | |
| 9507 RefPtr<CSSValueList> ligatureValues = CSSValueList::createSpaceSeparated(); | |
| 9508 bool sawCommonLigaturesValue = false; | |
| 9509 bool sawDiscretionaryLigaturesValue = false; | |
| 9510 bool sawHistoricalLigaturesValue = false; | |
| 9511 | |
| 9512 for (CSSParserValue* value = m_valueList->current(); value; value = m_valueL
ist->next()) { | |
| 9513 if (value->unit != CSSPrimitiveValue::CSS_IDENT) | |
| 9514 return false; | |
| 9515 | |
| 9516 switch (value->id) { | |
| 9517 case CSSValueNoCommonLigatures: | |
| 9518 case CSSValueCommonLigatures: | |
| 9519 if (sawCommonLigaturesValue) | |
| 9520 return false; | |
| 9521 sawCommonLigaturesValue = true; | |
| 9522 ligatureValues->append(cssValuePool().createIdentifierValue(value->i
d)); | |
| 9523 break; | |
| 9524 case CSSValueNoDiscretionaryLigatures: | |
| 9525 case CSSValueDiscretionaryLigatures: | |
| 9526 if (sawDiscretionaryLigaturesValue) | |
| 9527 return false; | |
| 9528 sawDiscretionaryLigaturesValue = true; | |
| 9529 ligatureValues->append(cssValuePool().createIdentifierValue(value->i
d)); | |
| 9530 break; | |
| 9531 case CSSValueNoHistoricalLigatures: | |
| 9532 case CSSValueHistoricalLigatures: | |
| 9533 if (sawHistoricalLigaturesValue) | |
| 9534 return false; | |
| 9535 sawHistoricalLigaturesValue = true; | |
| 9536 ligatureValues->append(cssValuePool().createIdentifierValue(value->i
d)); | |
| 9537 break; | |
| 9538 default: | |
| 9539 return false; | |
| 9540 } | |
| 9541 } | |
| 9542 | |
| 9543 if (!ligatureValues->length()) | |
| 9544 return false; | |
| 9545 | |
| 9546 addProperty(CSSPropertyWebkitFontVariantLigatures, ligatureValues.release(),
important); | |
| 9547 return true; | |
| 9548 } | |
| 9549 | |
| 9550 bool CSSParser::parseCalculation(CSSParserValue* value, ValueRange range) | |
| 9551 { | |
| 9552 ASSERT(isCalculation(value)); | |
| 9553 | |
| 9554 CSSParserValueList* args = value->function->args.get(); | |
| 9555 if (!args || !args->size()) | |
| 9556 return false; | |
| 9557 | |
| 9558 ASSERT(!m_parsedCalculation); | |
| 9559 m_parsedCalculation = CSSCalcValue::create(value->function->name, args, rang
e); | |
| 9560 | |
| 9561 if (!m_parsedCalculation) | |
| 9562 return false; | |
| 9563 | |
| 9564 return true; | |
| 9565 } | |
| 9566 | |
| 9567 #define END_TOKEN 0 | |
| 9568 | |
| 9569 void CSSParser::ensureLineEndings() | |
| 9570 { | |
| 9571 if (!m_lineEndings) | |
| 9572 m_lineEndings = lineEndings(*m_source); | |
| 9573 } | |
| 9574 | |
| 9575 CSSParserSelector* CSSParser::createFloatingSelectorWithTagName(const QualifiedN
ame& tagQName) | |
| 9576 { | |
| 9577 CSSParserSelector* selector = new CSSParserSelector(tagQName); | |
| 9578 m_floatingSelectors.append(selector); | |
| 9579 return selector; | |
| 9580 } | |
| 9581 | |
| 9582 CSSParserSelector* CSSParser::createFloatingSelector() | |
| 9583 { | |
| 9584 CSSParserSelector* selector = new CSSParserSelector; | |
| 9585 m_floatingSelectors.append(selector); | |
| 9586 return selector; | |
| 9587 } | |
| 9588 | |
| 9589 PassOwnPtr<CSSParserSelector> CSSParser::sinkFloatingSelector(CSSParserSelector*
selector) | |
| 9590 { | |
| 9591 if (selector) { | |
| 9592 size_t index = m_floatingSelectors.reverseFind(selector); | |
| 9593 ASSERT(index != kNotFound); | |
| 9594 m_floatingSelectors.remove(index); | |
| 9595 } | |
| 9596 return adoptPtr(selector); | |
| 9597 } | |
| 9598 | |
| 9599 Vector<OwnPtr<CSSParserSelector> >* CSSParser::createFloatingSelectorVector() | |
| 9600 { | |
| 9601 Vector<OwnPtr<CSSParserSelector> >* selectorVector = new Vector<OwnPtr<CSSPa
rserSelector> >; | |
| 9602 m_floatingSelectorVectors.append(selectorVector); | |
| 9603 return selectorVector; | |
| 9604 } | |
| 9605 | |
| 9606 PassOwnPtr<Vector<OwnPtr<CSSParserSelector> > > CSSParser::sinkFloatingSelectorV
ector(Vector<OwnPtr<CSSParserSelector> >* selectorVector) | |
| 9607 { | |
| 9608 if (selectorVector) { | |
| 9609 size_t index = m_floatingSelectorVectors.reverseFind(selectorVector); | |
| 9610 ASSERT(index != kNotFound); | |
| 9611 m_floatingSelectorVectors.remove(index); | |
| 9612 } | |
| 9613 return adoptPtr(selectorVector); | |
| 9614 } | |
| 9615 | |
| 9616 CSSParserValueList* CSSParser::createFloatingValueList() | |
| 9617 { | |
| 9618 CSSParserValueList* list = new CSSParserValueList; | |
| 9619 m_floatingValueLists.append(list); | |
| 9620 return list; | |
| 9621 } | |
| 9622 | |
| 9623 PassOwnPtr<CSSParserValueList> CSSParser::sinkFloatingValueList(CSSParserValueLi
st* list) | |
| 9624 { | |
| 9625 if (list) { | |
| 9626 size_t index = m_floatingValueLists.reverseFind(list); | |
| 9627 ASSERT(index != kNotFound); | |
| 9628 m_floatingValueLists.remove(index); | |
| 9629 } | |
| 9630 return adoptPtr(list); | |
| 9631 } | |
| 9632 | |
| 9633 CSSParserFunction* CSSParser::createFloatingFunction() | |
| 9634 { | |
| 9635 CSSParserFunction* function = new CSSParserFunction; | |
| 9636 m_floatingFunctions.append(function); | |
| 9637 return function; | |
| 9638 } | |
| 9639 | |
| 9640 CSSParserFunction* CSSParser::createFloatingFunction(const CSSParserString& name
, PassOwnPtr<CSSParserValueList> args) | |
| 9641 { | |
| 9642 CSSParserFunction* function = createFloatingFunction(); | |
| 9643 function->name = name; | |
| 9644 function->args = args; | |
| 9645 return function; | |
| 9646 } | |
| 9647 | |
| 9648 PassOwnPtr<CSSParserFunction> CSSParser::sinkFloatingFunction(CSSParserFunction*
function) | |
| 9649 { | |
| 9650 if (function) { | |
| 9651 size_t index = m_floatingFunctions.reverseFind(function); | |
| 9652 ASSERT(index != kNotFound); | |
| 9653 m_floatingFunctions.remove(index); | |
| 9654 } | |
| 9655 return adoptPtr(function); | |
| 9656 } | |
| 9657 | |
| 9658 CSSParserValue& CSSParser::sinkFloatingValue(CSSParserValue& value) | |
| 9659 { | |
| 9660 if (value.unit == CSSParserValue::Function) { | |
| 9661 size_t index = m_floatingFunctions.reverseFind(value.function); | |
| 9662 ASSERT(index != kNotFound); | |
| 9663 m_floatingFunctions.remove(index); | |
| 9664 } | |
| 9665 return value; | |
| 9666 } | |
| 9667 | |
| 9668 MediaQueryExp* CSSParser::createFloatingMediaQueryExp(const AtomicString& mediaF
eature, CSSParserValueList* values) | |
| 9669 { | |
| 9670 m_floatingMediaQueryExp = MediaQueryExp::create(mediaFeature, values); | |
| 9671 return m_floatingMediaQueryExp.get(); | |
| 9672 } | |
| 9673 | |
| 9674 PassOwnPtr<MediaQueryExp> CSSParser::sinkFloatingMediaQueryExp(MediaQueryExp* ex
pression) | |
| 9675 { | |
| 9676 ASSERT_UNUSED(expression, expression == m_floatingMediaQueryExp); | |
| 9677 return m_floatingMediaQueryExp.release(); | |
| 9678 } | |
| 9679 | |
| 9680 Vector<OwnPtr<MediaQueryExp> >* CSSParser::createFloatingMediaQueryExpList() | |
| 9681 { | |
| 9682 m_floatingMediaQueryExpList = adoptPtr(new Vector<OwnPtr<MediaQueryExp> >); | |
| 9683 return m_floatingMediaQueryExpList.get(); | |
| 9684 } | |
| 9685 | |
| 9686 PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > CSSParser::sinkFloatingMediaQueryExp
List(Vector<OwnPtr<MediaQueryExp> >* list) | |
| 9687 { | |
| 9688 ASSERT_UNUSED(list, list == m_floatingMediaQueryExpList); | |
| 9689 return m_floatingMediaQueryExpList.release(); | |
| 9690 } | |
| 9691 | |
| 9692 MediaQuery* CSSParser::createFloatingMediaQuery(MediaQuery::Restrictor restricto
r, const AtomicString& mediaType, PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > ex
pressions) | |
| 9693 { | |
| 9694 m_floatingMediaQuery = adoptPtr(new MediaQuery(restrictor, mediaType, expres
sions)); | |
| 9695 return m_floatingMediaQuery.get(); | |
| 9696 } | |
| 9697 | |
| 9698 MediaQuery* CSSParser::createFloatingMediaQuery(PassOwnPtr<Vector<OwnPtr<MediaQu
eryExp> > > expressions) | |
| 9699 { | |
| 9700 return createFloatingMediaQuery(MediaQuery::None, AtomicString("all", Atomic
String::ConstructFromLiteral), expressions); | |
| 9701 } | |
| 9702 | |
| 9703 MediaQuery* CSSParser::createFloatingNotAllQuery() | |
| 9704 { | |
| 9705 return createFloatingMediaQuery(MediaQuery::Not, AtomicString("all", AtomicS
tring::ConstructFromLiteral), sinkFloatingMediaQueryExpList(createFloatingMediaQ
ueryExpList())); | |
| 9706 } | |
| 9707 | |
| 9708 PassOwnPtr<MediaQuery> CSSParser::sinkFloatingMediaQuery(MediaQuery* query) | |
| 9709 { | |
| 9710 ASSERT_UNUSED(query, query == m_floatingMediaQuery); | |
| 9711 return m_floatingMediaQuery.release(); | |
| 9712 } | |
| 9713 | |
| 9714 Vector<RefPtr<StyleKeyframe> >* CSSParser::createFloatingKeyframeVector() | |
| 9715 { | |
| 9716 m_floatingKeyframeVector = adoptPtr(new Vector<RefPtr<StyleKeyframe> >()); | |
| 9717 return m_floatingKeyframeVector.get(); | |
| 9718 } | |
| 9719 | |
| 9720 PassOwnPtr<Vector<RefPtr<StyleKeyframe> > > CSSParser::sinkFloatingKeyframeVecto
r(Vector<RefPtr<StyleKeyframe> >* keyframeVector) | |
| 9721 { | |
| 9722 ASSERT_UNUSED(keyframeVector, m_floatingKeyframeVector == keyframeVector); | |
| 9723 return m_floatingKeyframeVector.release(); | |
| 9724 } | |
| 9725 | |
| 9726 MediaQuerySet* CSSParser::createMediaQuerySet() | |
| 9727 { | |
| 9728 RefPtr<MediaQuerySet> queries = MediaQuerySet::create(); | |
| 9729 MediaQuerySet* result = queries.get(); | |
| 9730 m_parsedMediaQuerySets.append(queries.release()); | |
| 9731 return result; | |
| 9732 } | |
| 9733 | |
| 9734 StyleRuleBase* CSSParser::createImportRule(const CSSParserString& url, MediaQuer
ySet* media) | |
| 9735 { | |
| 9736 if (!media || !m_allowImportRules) | |
| 9737 return 0; | |
| 9738 RefPtr<StyleRuleImport> rule = StyleRuleImport::create(url, media); | |
| 9739 StyleRuleImport* result = rule.get(); | |
| 9740 m_parsedRules.append(rule.release()); | |
| 9741 return result; | |
| 9742 } | |
| 9743 | |
| 9744 StyleRuleBase* CSSParser::createMediaRule(MediaQuerySet* media, RuleList* rules) | |
| 9745 { | |
| 9746 m_allowImportRules = m_allowNamespaceDeclarations = false; | |
| 9747 RefPtr<StyleRuleMedia> rule; | |
| 9748 if (rules) { | |
| 9749 rule = StyleRuleMedia::create(media ? media : MediaQuerySet::create(), *
rules); | |
| 9750 } else { | |
| 9751 RuleList emptyRules; | |
| 9752 rule = StyleRuleMedia::create(media ? media : MediaQuerySet::create(), e
mptyRules); | |
| 9753 } | |
| 9754 StyleRuleMedia* result = rule.get(); | |
| 9755 m_parsedRules.append(rule.release()); | |
| 9756 return result; | |
| 9757 } | |
| 9758 | |
| 9759 StyleRuleBase* CSSParser::createSupportsRule(bool conditionIsSupported, RuleList
* rules) | |
| 9760 { | |
| 9761 m_allowImportRules = m_allowNamespaceDeclarations = false; | |
| 9762 | |
| 9763 RefPtr<CSSRuleSourceData> data = popSupportsRuleData(); | |
| 9764 RefPtr<StyleRuleSupports> rule; | |
| 9765 String conditionText; | |
| 9766 unsigned conditionOffset = data->ruleHeaderRange.start + 9; | |
| 9767 unsigned conditionLength = data->ruleHeaderRange.length() - 9; | |
| 9768 | |
| 9769 if (m_tokenizer.is8BitSource()) | |
| 9770 conditionText = String(m_tokenizer.m_dataStart8.get() + conditionOffset,
conditionLength).stripWhiteSpace(); | |
| 9771 else | |
| 9772 conditionText = String(m_tokenizer.m_dataStart16.get() + conditionOffset
, conditionLength).stripWhiteSpace(); | |
| 9773 | |
| 9774 if (rules) { | |
| 9775 rule = StyleRuleSupports::create(conditionText, conditionIsSupported, *r
ules); | |
| 9776 } else { | |
| 9777 RuleList emptyRules; | |
| 9778 rule = StyleRuleSupports::create(conditionText, conditionIsSupported, em
ptyRules); | |
| 9779 } | |
| 9780 | |
| 9781 StyleRuleSupports* result = rule.get(); | |
| 9782 m_parsedRules.append(rule.release()); | |
| 9783 | |
| 9784 return result; | |
| 9785 } | |
| 9786 | |
| 9787 void CSSParser::markSupportsRuleHeaderStart() | |
| 9788 { | |
| 9789 if (!m_supportsRuleDataStack) | |
| 9790 m_supportsRuleDataStack = adoptPtr(new RuleSourceDataList()); | |
| 9791 | |
| 9792 RefPtr<CSSRuleSourceData> data = CSSRuleSourceData::create(CSSRuleSourceData
::SUPPORTS_RULE); | |
| 9793 data->ruleHeaderRange.start = m_tokenizer.tokenStartOffset(); | |
| 9794 m_supportsRuleDataStack->append(data); | |
| 9795 } | |
| 9796 | |
| 9797 void CSSParser::markSupportsRuleHeaderEnd() | |
| 9798 { | |
| 9799 ASSERT(m_supportsRuleDataStack && !m_supportsRuleDataStack->isEmpty()); | |
| 9800 | |
| 9801 if (m_tokenizer.is8BitSource()) | |
| 9802 m_supportsRuleDataStack->last()->ruleHeaderRange.end = m_tokenizer.token
Start<LChar>() - m_tokenizer.m_dataStart8.get(); | |
| 9803 else | |
| 9804 m_supportsRuleDataStack->last()->ruleHeaderRange.end = m_tokenizer.token
Start<UChar>() - m_tokenizer.m_dataStart16.get(); | |
| 9805 } | |
| 9806 | |
| 9807 PassRefPtr<CSSRuleSourceData> CSSParser::popSupportsRuleData() | |
| 9808 { | |
| 9809 ASSERT(m_supportsRuleDataStack && !m_supportsRuleDataStack->isEmpty()); | |
| 9810 RefPtr<CSSRuleSourceData> data = m_supportsRuleDataStack->last(); | |
| 9811 m_supportsRuleDataStack->removeLast(); | |
| 9812 return data.release(); | |
| 9813 } | |
| 9814 | |
| 9815 CSSParser::RuleList* CSSParser::createRuleList() | |
| 9816 { | |
| 9817 OwnPtr<RuleList> list = adoptPtr(new RuleList); | |
| 9818 RuleList* listPtr = list.get(); | |
| 9819 | |
| 9820 m_parsedRuleLists.append(list.release()); | |
| 9821 return listPtr; | |
| 9822 } | |
| 9823 | |
| 9824 CSSParser::RuleList* CSSParser::appendRule(RuleList* ruleList, StyleRuleBase* ru
le) | |
| 9825 { | |
| 9826 if (rule) { | |
| 9827 if (!ruleList) | |
| 9828 ruleList = createRuleList(); | |
| 9829 ruleList->append(rule); | |
| 9830 } | |
| 9831 return ruleList; | |
| 9832 } | |
| 9833 | |
| 9834 template <typename CharacterType> | |
| 9835 ALWAYS_INLINE static void makeLower(const CharacterType* input, CharacterType* o
utput, unsigned length) | |
| 9836 { | |
| 9837 // FIXME: If we need Unicode lowercasing here, then we probably want the rea
l kind | |
| 9838 // that can potentially change the length of the string rather than the char
acter | |
| 9839 // by character kind. If we don't need Unicode lowercasing, it would be good
to | |
| 9840 // simplify this function. | |
| 9841 | |
| 9842 if (charactersAreAllASCII(input, length)) { | |
| 9843 // Fast case for all-ASCII. | |
| 9844 for (unsigned i = 0; i < length; i++) | |
| 9845 output[i] = toASCIILower(input[i]); | |
| 9846 } else { | |
| 9847 for (unsigned i = 0; i < length; i++) | |
| 9848 output[i] = Unicode::toLower(input[i]); | |
| 9849 } | |
| 9850 } | |
| 9851 | |
| 9852 void CSSParser::tokenToLowerCase(const CSSParserString& token) | |
| 9853 { | |
| 9854 size_t length = token.length(); | |
| 9855 if (m_tokenizer.is8BitSource()) { | |
| 9856 size_t offset = token.characters8() - m_tokenizer.m_dataStart8.get(); | |
| 9857 makeLower(token.characters8(), m_tokenizer.m_dataStart8.get() + offset,
length); | |
| 9858 } else { | |
| 9859 size_t offset = token.characters16() - m_tokenizer.m_dataStart16.get(); | |
| 9860 makeLower(token.characters16(), m_tokenizer.m_dataStart16.get() + offset
, length); | |
| 9861 } | |
| 9862 } | |
| 9863 | |
| 9864 void CSSParser::endInvalidRuleHeader() | |
| 9865 { | |
| 9866 if (m_ruleHeaderType == CSSRuleSourceData::UNKNOWN_RULE) | |
| 9867 return; | |
| 9868 | |
| 9869 CSSParserLocation location; | |
| 9870 location.lineNumber = m_tokenizer.m_lineNumber; | |
| 9871 location.offset = m_ruleHeaderStartOffset; | |
| 9872 if (m_tokenizer.is8BitSource()) | |
| 9873 location.token.init(m_tokenizer.m_dataStart8.get() + m_ruleHeaderStartOf
fset, 0); | |
| 9874 else | |
| 9875 location.token.init(m_tokenizer.m_dataStart16.get() + m_ruleHeaderStartO
ffset, 0); | |
| 9876 | |
| 9877 reportError(location, m_ruleHeaderType == CSSRuleSourceData::STYLE_RULE ? In
validSelectorCSSError : InvalidRuleCSSError); | |
| 9878 | |
| 9879 endRuleHeader(); | |
| 9880 } | |
| 9881 | |
| 9882 void CSSParser::reportError(const CSSParserLocation&, CSSParserError) | |
| 9883 { | |
| 9884 // FIXME: error reporting temporatily disabled. | |
| 9885 } | |
| 9886 | |
| 9887 bool CSSParser::isLoggingErrors() | |
| 9888 { | |
| 9889 return m_logErrors && !m_ignoreErrors; | |
| 9890 } | |
| 9891 | |
| 9892 void CSSParser::logError(const String& message, const CSSParserLocation& locatio
n) | |
| 9893 { | |
| 9894 unsigned lineNumberInStyleSheet; | |
| 9895 unsigned columnNumber = 0; | |
| 9896 if (InspectorInstrumentation::hasFrontends()) { | |
| 9897 ensureLineEndings(); | |
| 9898 TextPosition tokenPosition = TextPosition::fromOffsetAndLineEndings(loca
tion.offset, *m_lineEndings); | |
| 9899 lineNumberInStyleSheet = tokenPosition.m_line.zeroBasedInt(); | |
| 9900 columnNumber = (lineNumberInStyleSheet ? 0 : m_startPosition.m_column.ze
roBasedInt()) + tokenPosition.m_column.zeroBasedInt(); | |
| 9901 } else { | |
| 9902 lineNumberInStyleSheet = location.lineNumber; | |
| 9903 } | |
| 9904 PageConsole& console = m_styleSheet->singleOwnerDocument()->frameHost()->con
sole(); | |
| 9905 console.addMessage(CSSMessageSource, WarningMessageLevel, message, m_styleSh
eet->baseURL().string(), lineNumberInStyleSheet + m_startPosition.m_line.zeroBas
edInt() + 1, columnNumber + 1); | |
| 9906 } | |
| 9907 | |
| 9908 StyleRuleKeyframes* CSSParser::createKeyframesRule(const String& name, PassOwnPt
r<Vector<RefPtr<StyleKeyframe> > > popKeyframes, bool isPrefixed) | |
| 9909 { | |
| 9910 OwnPtr<Vector<RefPtr<StyleKeyframe> > > keyframes = popKeyframes; | |
| 9911 m_allowImportRules = m_allowNamespaceDeclarations = false; | |
| 9912 RefPtr<StyleRuleKeyframes> rule = StyleRuleKeyframes::create(); | |
| 9913 for (size_t i = 0; i < keyframes->size(); ++i) | |
| 9914 rule->parserAppendKeyframe(keyframes->at(i)); | |
| 9915 rule->setName(name); | |
| 9916 rule->setVendorPrefixed(isPrefixed); | |
| 9917 StyleRuleKeyframes* rulePtr = rule.get(); | |
| 9918 m_parsedRules.append(rule.release()); | |
| 9919 return rulePtr; | |
| 9920 } | |
| 9921 | |
| 9922 StyleRuleBase* CSSParser::createStyleRule(Vector<OwnPtr<CSSParserSelector> >* se
lectors) | |
| 9923 { | |
| 9924 StyleRule* result = 0; | |
| 9925 if (selectors) { | |
| 9926 m_allowImportRules = m_allowNamespaceDeclarations = false; | |
| 9927 RefPtr<StyleRule> rule = StyleRule::create(); | |
| 9928 rule->parserAdoptSelectorVector(*selectors); | |
| 9929 if (m_hasFontFaceOnlyValues) | |
| 9930 deleteFontFaceOnlyValues(); | |
| 9931 rule->setProperties(createStylePropertySet()); | |
| 9932 result = rule.get(); | |
| 9933 m_parsedRules.append(rule.release()); | |
| 9934 } | |
| 9935 clearProperties(); | |
| 9936 return result; | |
| 9937 } | |
| 9938 | |
| 9939 StyleRuleBase* CSSParser::createFontFaceRule() | |
| 9940 { | |
| 9941 m_allowImportRules = m_allowNamespaceDeclarations = false; | |
| 9942 for (unsigned i = 0; i < m_parsedProperties.size(); ++i) { | |
| 9943 CSSProperty& property = m_parsedProperties[i]; | |
| 9944 if (property.id() == CSSPropertyFontVariant && property.value()->isPrimi
tiveValue()) | |
| 9945 property.wrapValueInCommaSeparatedList(); | |
| 9946 else if (property.id() == CSSPropertyFontFamily && (!property.value()->i
sValueList() || toCSSValueList(property.value())->length() != 1)) { | |
| 9947 // Unlike font-family property, font-family descriptor in @font-face
rule | |
| 9948 // has to be a value list with exactly one family name. It cannot ha
ve a | |
| 9949 // have 'initial' value and cannot 'inherit' from parent. | |
| 9950 // See http://dev.w3.org/csswg/css3-fonts/#font-family-desc | |
| 9951 clearProperties(); | |
| 9952 return 0; | |
| 9953 } | |
| 9954 } | |
| 9955 RefPtr<StyleRuleFontFace> rule = StyleRuleFontFace::create(); | |
| 9956 rule->setProperties(createStylePropertySet()); | |
| 9957 clearProperties(); | |
| 9958 StyleRuleFontFace* result = rule.get(); | |
| 9959 m_parsedRules.append(rule.release()); | |
| 9960 if (m_styleSheet) | |
| 9961 m_styleSheet->setHasFontFaceRule(true); | |
| 9962 return result; | |
| 9963 } | |
| 9964 | |
| 9965 void CSSParser::addNamespace(const AtomicString& prefix, const AtomicString& uri
) | |
| 9966 { | |
| 9967 if (!m_styleSheet || !m_allowNamespaceDeclarations) | |
| 9968 return; | |
| 9969 m_allowImportRules = false; | |
| 9970 m_styleSheet->parserAddNamespace(prefix, uri); | |
| 9971 if (prefix.isEmpty() && !uri.isNull()) | |
| 9972 m_defaultNamespace = uri; | |
| 9973 } | |
| 9974 | |
| 9975 QualifiedName CSSParser::determineNameInNamespace(const AtomicString& prefix, co
nst AtomicString& localName) | |
| 9976 { | |
| 9977 if (!m_styleSheet) | |
| 9978 return QualifiedName(prefix, localName, m_defaultNamespace); | |
| 9979 return QualifiedName(prefix, localName, m_styleSheet->determineNamespace(pre
fix)); | |
| 9980 } | |
| 9981 | |
| 9982 CSSParserSelector* CSSParser::rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSe
lector* specifiers) | |
| 9983 { | |
| 9984 if (m_defaultNamespace != starAtom || specifiers->needsCrossingTreeScopeBoun
dary()) | |
| 9985 return rewriteSpecifiersWithElementName(nullAtom, starAtom, specifiers,
/*tagIsForNamespaceRule*/true); | |
| 9986 if (CSSParserSelector* distributedPseudoElementSelector = specifiers->findDi
stributedPseudoElementSelector()) { | |
| 9987 specifiers->prependTagSelector(QualifiedName(nullAtom, starAtom, m_defau
ltNamespace), /*tagIsForNamespaceRule*/true); | |
| 9988 return rewriteSpecifiersForShadowDistributed(specifiers, distributedPseu
doElementSelector); | |
| 9989 } | |
| 9990 return specifiers; | |
| 9991 } | |
| 9992 | |
| 9993 CSSParserSelector* CSSParser::rewriteSpecifiersWithElementName(const AtomicStrin
g& namespacePrefix, const AtomicString& elementName, CSSParserSelector* specifie
rs, bool tagIsForNamespaceRule) | |
| 9994 { | |
| 9995 AtomicString determinedNamespace = namespacePrefix != nullAtom && m_styleShe
et ? m_styleSheet->determineNamespace(namespacePrefix) : m_defaultNamespace; | |
| 9996 QualifiedName tag(namespacePrefix, elementName, determinedNamespace); | |
| 9997 | |
| 9998 if (CSSParserSelector* distributedPseudoElementSelector = specifiers->findDi
stributedPseudoElementSelector()) { | |
| 9999 specifiers->prependTagSelector(tag, tagIsForNamespaceRule); | |
| 10000 return rewriteSpecifiersForShadowDistributed(specifiers, distributedPseu
doElementSelector); | |
| 10001 } | |
| 10002 | |
| 10003 if (specifiers->needsCrossingTreeScopeBoundary()) | |
| 10004 return rewriteSpecifiersWithElementNameForCustomPseudoElement(tag, eleme
ntName, specifiers, tagIsForNamespaceRule); | |
| 10005 | |
| 10006 if (specifiers->isContentPseudoElement()) | |
| 10007 return rewriteSpecifiersWithElementNameForContentPseudoElement(tag, elem
entName, specifiers, tagIsForNamespaceRule); | |
| 10008 | |
| 10009 if (tag == anyQName()) | |
| 10010 return specifiers; | |
| 10011 if (!(specifiers->pseudoType() == CSSSelector::PseudoCue)) | |
| 10012 specifiers->prependTagSelector(tag, tagIsForNamespaceRule); | |
| 10013 return specifiers; | |
| 10014 } | |
| 10015 | |
| 10016 CSSParserSelector* CSSParser::rewriteSpecifiersWithElementNameForCustomPseudoEle
ment(const QualifiedName& tag, const AtomicString& elementName, CSSParserSelecto
r* specifiers, bool tagIsForNamespaceRule) | |
| 10017 { | |
| 10018 if (m_useCounter && specifiers->pseudoType() == CSSSelector::PseudoUserAgent
CustomElement) | |
| 10019 m_useCounter->count(UseCounter::CSSPseudoElementUserAgentCustomPseudo); | |
| 10020 | |
| 10021 CSSParserSelector* lastShadowPseudo = specifiers; | |
| 10022 CSSParserSelector* history = specifiers; | |
| 10023 while (history->tagHistory()) { | |
| 10024 history = history->tagHistory(); | |
| 10025 if (history->needsCrossingTreeScopeBoundary() || history->hasShadowPseud
o()) | |
| 10026 lastShadowPseudo = history; | |
| 10027 } | |
| 10028 | |
| 10029 if (lastShadowPseudo->tagHistory()) { | |
| 10030 if (tag != anyQName()) | |
| 10031 lastShadowPseudo->tagHistory()->prependTagSelector(tag, tagIsForName
spaceRule); | |
| 10032 return specifiers; | |
| 10033 } | |
| 10034 | |
| 10035 // For shadow-ID pseudo-elements to be correctly matched, the ShadowPseudo c
ombinator has to be used. | |
| 10036 // We therefore create a new Selector with that combinator here in any case,
even if matching any (host) element in any namespace (i.e. '*'). | |
| 10037 OwnPtr<CSSParserSelector> elementNameSelector = adoptPtr(new CSSParserSelect
or(tag)); | |
| 10038 lastShadowPseudo->setTagHistory(elementNameSelector.release()); | |
| 10039 lastShadowPseudo->setRelation(CSSSelector::ShadowPseudo); | |
| 10040 return specifiers; | |
| 10041 } | |
| 10042 | |
| 10043 CSSParserSelector* CSSParser::rewriteSpecifiersWithElementNameForContentPseudoEl
ement(const QualifiedName& tag, const AtomicString& elementName, CSSParserSelect
or* specifiers, bool tagIsForNamespaceRule) | |
| 10044 { | |
| 10045 CSSParserSelector* last = specifiers; | |
| 10046 CSSParserSelector* history = specifiers; | |
| 10047 while (history->tagHistory()) { | |
| 10048 history = history->tagHistory(); | |
| 10049 if (history->isContentPseudoElement() || history->relationIsAffectedByPs
eudoContent()) | |
| 10050 last = history; | |
| 10051 } | |
| 10052 | |
| 10053 if (last->tagHistory()) { | |
| 10054 if (tag != anyQName()) | |
| 10055 last->tagHistory()->prependTagSelector(tag, tagIsForNamespaceRule); | |
| 10056 return specifiers; | |
| 10057 } | |
| 10058 | |
| 10059 // For shadow-ID pseudo-elements to be correctly matched, the ShadowPseudo c
ombinator has to be used. | |
| 10060 // We therefore create a new Selector with that combinator here in any case,
even if matching any (host) element in any namespace (i.e. '*'). | |
| 10061 OwnPtr<CSSParserSelector> elementNameSelector = adoptPtr(new CSSParserSelect
or(tag)); | |
| 10062 last->setTagHistory(elementNameSelector.release()); | |
| 10063 last->setRelation(CSSSelector::SubSelector); | |
| 10064 return specifiers; | |
| 10065 } | |
| 10066 | |
| 10067 CSSParserSelector* CSSParser::rewriteSpecifiersForShadowDistributed(CSSParserSel
ector* specifiers, CSSParserSelector* distributedPseudoElementSelector) | |
| 10068 { | |
| 10069 if (m_useCounter) | |
| 10070 m_useCounter->count(UseCounter::CSSPseudoElementPrefixedDistributed); | |
| 10071 CSSParserSelector* argumentSelector = distributedPseudoElementSelector->func
tionArgumentSelector(); | |
| 10072 ASSERT(argumentSelector); | |
| 10073 ASSERT(!specifiers->isDistributedPseudoElement()); | |
| 10074 for (CSSParserSelector* end = specifiers; end->tagHistory(); end = end->tagH
istory()) { | |
| 10075 if (end->tagHistory()->isDistributedPseudoElement()) { | |
| 10076 end->clearTagHistory(); | |
| 10077 break; | |
| 10078 } | |
| 10079 } | |
| 10080 CSSParserSelector* end = argumentSelector; | |
| 10081 while (end->tagHistory()) | |
| 10082 end = end->tagHistory(); | |
| 10083 | |
| 10084 switch (end->relation()) { | |
| 10085 case CSSSelector::Child: | |
| 10086 case CSSSelector::Descendant: | |
| 10087 end->setTagHistory(sinkFloatingSelector(specifiers)); | |
| 10088 end->setRelationIsAffectedByPseudoContent(); | |
| 10089 return argumentSelector; | |
| 10090 default: | |
| 10091 return 0; | |
| 10092 } | |
| 10093 } | |
| 10094 | |
| 10095 CSSParserSelector* CSSParser::rewriteSpecifiers(CSSParserSelector* specifiers, C
SSParserSelector* newSpecifier) | |
| 10096 { | |
| 10097 if (newSpecifier->needsCrossingTreeScopeBoundary()) { | |
| 10098 // Unknown pseudo element always goes at the top of selector chain. | |
| 10099 newSpecifier->appendTagHistory(CSSSelector::ShadowPseudo, sinkFloatingSe
lector(specifiers)); | |
| 10100 return newSpecifier; | |
| 10101 } | |
| 10102 if (newSpecifier->isContentPseudoElement()) { | |
| 10103 newSpecifier->appendTagHistory(CSSSelector::SubSelector, sinkFloatingSel
ector(specifiers)); | |
| 10104 return newSpecifier; | |
| 10105 } | |
| 10106 if (specifiers->needsCrossingTreeScopeBoundary()) { | |
| 10107 // Specifiers for unknown pseudo element go right behind it in the chain
. | |
| 10108 specifiers->insertTagHistory(CSSSelector::SubSelector, sinkFloatingSelec
tor(newSpecifier), CSSSelector::ShadowPseudo); | |
| 10109 return specifiers; | |
| 10110 } | |
| 10111 if (specifiers->isContentPseudoElement()) { | |
| 10112 specifiers->insertTagHistory(CSSSelector::SubSelector, sinkFloatingSelec
tor(newSpecifier), CSSSelector::SubSelector); | |
| 10113 return specifiers; | |
| 10114 } | |
| 10115 specifiers->appendTagHistory(CSSSelector::SubSelector, sinkFloatingSelector(
newSpecifier)); | |
| 10116 return specifiers; | |
| 10117 } | |
| 10118 | |
| 10119 StyleRuleBase* CSSParser::createPageRule(PassOwnPtr<CSSParserSelector> pageSelec
tor) | |
| 10120 { | |
| 10121 // FIXME: Margin at-rules are ignored. | |
| 10122 m_allowImportRules = m_allowNamespaceDeclarations = false; | |
| 10123 StyleRulePage* pageRule = 0; | |
| 10124 if (pageSelector) { | |
| 10125 RefPtr<StyleRulePage> rule = StyleRulePage::create(); | |
| 10126 Vector<OwnPtr<CSSParserSelector> > selectorVector; | |
| 10127 selectorVector.append(pageSelector); | |
| 10128 rule->parserAdoptSelectorVector(selectorVector); | |
| 10129 rule->setProperties(createStylePropertySet()); | |
| 10130 pageRule = rule.get(); | |
| 10131 m_parsedRules.append(rule.release()); | |
| 10132 } | |
| 10133 clearProperties(); | |
| 10134 return pageRule; | |
| 10135 } | |
| 10136 | |
| 10137 void CSSParser::setReusableRegionSelectorVector(Vector<OwnPtr<CSSParserSelector>
>* selectors) | |
| 10138 { | |
| 10139 if (selectors) | |
| 10140 m_reusableRegionSelectorVector.swap(*selectors); | |
| 10141 } | |
| 10142 | |
| 10143 StyleRuleBase* CSSParser::createRegionRule(Vector<OwnPtr<CSSParserSelector> >* r
egionSelector, RuleList* rules) | |
| 10144 { | |
| 10145 if (m_useCounter) | |
| 10146 m_useCounter->count(UseCounter::CSSWebkitRegionAtRule); | |
| 10147 | |
| 10148 if (!RuntimeEnabledFeatures::cssRegionsEnabled() || !regionSelector || !rule
s) | |
| 10149 return 0; | |
| 10150 | |
| 10151 m_allowImportRules = m_allowNamespaceDeclarations = false; | |
| 10152 | |
| 10153 RefPtr<StyleRuleRegion> regionRule = StyleRuleRegion::create(regionSelector,
*rules); | |
| 10154 | |
| 10155 StyleRuleRegion* result = regionRule.get(); | |
| 10156 m_parsedRules.append(regionRule.release()); | |
| 10157 if (m_observer) | |
| 10158 m_observer->startEndUnknownRule(); | |
| 10159 | |
| 10160 return result; | |
| 10161 } | |
| 10162 | |
| 10163 StyleRuleBase* CSSParser::createMarginAtRule(CSSSelector::MarginBoxType /* margi
nBox */) | |
| 10164 { | |
| 10165 // FIXME: Implement margin at-rule here, using: | |
| 10166 // - marginBox: margin box | |
| 10167 // - m_parsedProperties: properties at [m_numParsedPropertiesBeforeMa
rginBox, m_parsedProperties.size()] are for this at-rule. | |
| 10168 // Don't forget to also update the action for page symbol in CSSGrammar.y su
ch that margin at-rule data is cleared if page_selector is invalid. | |
| 10169 | |
| 10170 endDeclarationsForMarginBox(); | |
| 10171 return 0; // until this method is implemented. | |
| 10172 } | |
| 10173 | |
| 10174 void CSSParser::startDeclarationsForMarginBox() | |
| 10175 { | |
| 10176 m_numParsedPropertiesBeforeMarginBox = m_parsedProperties.size(); | |
| 10177 } | |
| 10178 | |
| 10179 void CSSParser::endDeclarationsForMarginBox() | |
| 10180 { | |
| 10181 rollbackLastProperties(m_parsedProperties.size() - m_numParsedPropertiesBefo
reMarginBox); | |
| 10182 m_numParsedPropertiesBeforeMarginBox = INVALID_NUM_PARSED_PROPERTIES; | |
| 10183 } | |
| 10184 | |
| 10185 void CSSParser::deleteFontFaceOnlyValues() | |
| 10186 { | |
| 10187 ASSERT(m_hasFontFaceOnlyValues); | |
| 10188 for (unsigned i = 0; i < m_parsedProperties.size();) { | |
| 10189 CSSProperty& property = m_parsedProperties[i]; | |
| 10190 if (property.id() == CSSPropertyFontVariant && property.value()->isValue
List()) { | |
| 10191 m_parsedProperties.remove(i); | |
| 10192 continue; | |
| 10193 } | |
| 10194 ++i; | |
| 10195 } | |
| 10196 } | |
| 10197 | |
| 10198 StyleKeyframe* CSSParser::createKeyframe(CSSParserValueList* keys) | |
| 10199 { | |
| 10200 OwnPtr<Vector<double> > keyVector = StyleKeyframe::createKeyList(keys); | |
| 10201 if (keyVector->isEmpty()) | |
| 10202 return 0; | |
| 10203 | |
| 10204 RefPtr<StyleKeyframe> keyframe = StyleKeyframe::create(); | |
| 10205 keyframe->setKeys(keyVector.release()); | |
| 10206 keyframe->setProperties(createStylePropertySet()); | |
| 10207 | |
| 10208 clearProperties(); | |
| 10209 | |
| 10210 StyleKeyframe* keyframePtr = keyframe.get(); | |
| 10211 m_parsedKeyframes.append(keyframe.release()); | |
| 10212 return keyframePtr; | |
| 10213 } | |
| 10214 | |
| 10215 void CSSParser::invalidBlockHit() | |
| 10216 { | |
| 10217 if (m_styleSheet && !m_hadSyntacticallyValidCSSRule) | |
| 10218 m_styleSheet->setHasSyntacticallyValidCSSHeader(false); | |
| 10219 } | |
| 10220 | |
| 10221 void CSSParser::startRule() | |
| 10222 { | |
| 10223 if (!m_observer) | |
| 10224 return; | |
| 10225 | |
| 10226 ASSERT(m_ruleHasHeader); | |
| 10227 m_ruleHasHeader = false; | |
| 10228 } | |
| 10229 | |
| 10230 void CSSParser::endRule(bool valid) | |
| 10231 { | |
| 10232 if (!m_observer) | |
| 10233 return; | |
| 10234 | |
| 10235 if (m_ruleHasHeader) | |
| 10236 m_observer->endRuleBody(m_tokenizer.safeUserStringTokenOffset(), !valid)
; | |
| 10237 m_ruleHasHeader = true; | |
| 10238 } | |
| 10239 | |
| 10240 void CSSParser::startRuleHeader(CSSRuleSourceData::Type ruleType) | |
| 10241 { | |
| 10242 resumeErrorLogging(); | |
| 10243 m_ruleHeaderType = ruleType; | |
| 10244 m_ruleHeaderStartOffset = m_tokenizer.safeUserStringTokenOffset(); | |
| 10245 m_ruleHeaderStartLineNumber = m_tokenizer.m_tokenStartLineNumber; | |
| 10246 if (m_observer) { | |
| 10247 ASSERT(!m_ruleHasHeader); | |
| 10248 m_observer->startRuleHeader(ruleType, m_ruleHeaderStartOffset); | |
| 10249 m_ruleHasHeader = true; | |
| 10250 } | |
| 10251 } | |
| 10252 | |
| 10253 void CSSParser::endRuleHeader() | |
| 10254 { | |
| 10255 ASSERT(m_ruleHeaderType != CSSRuleSourceData::UNKNOWN_RULE); | |
| 10256 m_ruleHeaderType = CSSRuleSourceData::UNKNOWN_RULE; | |
| 10257 if (m_observer) { | |
| 10258 ASSERT(m_ruleHasHeader); | |
| 10259 m_observer->endRuleHeader(m_tokenizer.safeUserStringTokenOffset()); | |
| 10260 } | |
| 10261 } | |
| 10262 | |
| 10263 void CSSParser::startSelector() | |
| 10264 { | |
| 10265 if (m_observer) | |
| 10266 m_observer->startSelector(m_tokenizer.safeUserStringTokenOffset()); | |
| 10267 } | |
| 10268 | |
| 10269 void CSSParser::endSelector() | |
| 10270 { | |
| 10271 if (m_observer) | |
| 10272 m_observer->endSelector(m_tokenizer.safeUserStringTokenOffset()); | |
| 10273 } | |
| 10274 | |
| 10275 void CSSParser::startRuleBody() | |
| 10276 { | |
| 10277 if (m_observer) | |
| 10278 m_observer->startRuleBody(m_tokenizer.safeUserStringTokenOffset()); | |
| 10279 } | |
| 10280 | |
| 10281 void CSSParser::startProperty() | |
| 10282 { | |
| 10283 resumeErrorLogging(); | |
| 10284 if (m_observer) | |
| 10285 m_observer->startProperty(m_tokenizer.safeUserStringTokenOffset()); | |
| 10286 } | |
| 10287 | |
| 10288 void CSSParser::endProperty(bool isImportantFound, bool isPropertyParsed, CSSPar
serError errorType) | |
| 10289 { | |
| 10290 m_id = CSSPropertyInvalid; | |
| 10291 if (m_observer) | |
| 10292 m_observer->endProperty(isImportantFound, isPropertyParsed, m_tokenizer.
safeUserStringTokenOffset(), errorType); | |
| 10293 } | |
| 10294 | |
| 10295 void CSSParser::startEndUnknownRule() | |
| 10296 { | |
| 10297 if (m_observer) | |
| 10298 m_observer->startEndUnknownRule(); | |
| 10299 } | |
| 10300 | |
| 10301 StyleRuleBase* CSSParser::createViewportRule() | |
| 10302 { | |
| 10303 // Allow @viewport rules from UA stylesheets even if the feature is disabled
. | |
| 10304 if (!RuntimeEnabledFeatures::cssViewportEnabled() && !isUASheetBehavior(m_co
ntext.mode())) | |
| 10305 return 0; | |
| 10306 | |
| 10307 m_allowImportRules = m_allowNamespaceDeclarations = false; | |
| 10308 | |
| 10309 RefPtr<StyleRuleViewport> rule = StyleRuleViewport::create(); | |
| 10310 | |
| 10311 rule->setProperties(createStylePropertySet()); | |
| 10312 clearProperties(); | |
| 10313 | |
| 10314 StyleRuleViewport* result = rule.get(); | |
| 10315 m_parsedRules.append(rule.release()); | |
| 10316 | |
| 10317 return result; | |
| 10318 } | |
| 10319 | |
| 10320 bool CSSParser::parseViewportProperty(CSSPropertyID propId, bool important) | |
| 10321 { | |
| 10322 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_c
ontext.mode())); | |
| 10323 | |
| 10324 CSSParserValue* value = m_valueList->current(); | |
| 10325 if (!value) | |
| 10326 return false; | |
| 10327 | |
| 10328 CSSValueID id = value->id; | |
| 10329 bool validPrimitive = false; | |
| 10330 | |
| 10331 switch (propId) { | |
| 10332 case CSSPropertyMinWidth: // auto | extend-to-zoom | <length> | <percentage> | |
| 10333 case CSSPropertyMaxWidth: | |
| 10334 case CSSPropertyMinHeight: | |
| 10335 case CSSPropertyMaxHeight: | |
| 10336 if (id == CSSValueAuto || id == CSSValueInternalExtendToZoom) | |
| 10337 validPrimitive = true; | |
| 10338 else | |
| 10339 validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonN
eg)); | |
| 10340 break; | |
| 10341 case CSSPropertyWidth: // shorthand | |
| 10342 return parseViewportShorthand(propId, CSSPropertyMinWidth, CSSPropertyMa
xWidth, important); | |
| 10343 case CSSPropertyHeight: | |
| 10344 return parseViewportShorthand(propId, CSSPropertyMinHeight, CSSPropertyM
axHeight, important); | |
| 10345 case CSSPropertyMinZoom: // auto | <number> | <percentage> | |
| 10346 case CSSPropertyMaxZoom: | |
| 10347 case CSSPropertyZoom: | |
| 10348 if (id == CSSValueAuto) | |
| 10349 validPrimitive = true; | |
| 10350 else | |
| 10351 validPrimitive = (!id && validUnit(value, FNumber | FPercent | FNonN
eg)); | |
| 10352 break; | |
| 10353 case CSSPropertyUserZoom: // zoom | fixed | |
| 10354 if (id == CSSValueZoom || id == CSSValueFixed) | |
| 10355 validPrimitive = true; | |
| 10356 break; | |
| 10357 case CSSPropertyOrientation: // auto | portrait | landscape | |
| 10358 if (id == CSSValueAuto || id == CSSValuePortrait || id == CSSValueLandsc
ape) | |
| 10359 validPrimitive = true; | |
| 10360 default: | |
| 10361 break; | |
| 10362 } | |
| 10363 | |
| 10364 RefPtr<CSSValue> parsedValue; | |
| 10365 if (validPrimitive) { | |
| 10366 parsedValue = parseValidPrimitive(id, value); | |
| 10367 m_valueList->next(); | |
| 10368 } | |
| 10369 | |
| 10370 if (parsedValue) { | |
| 10371 if (!m_valueList->current() || inShorthand()) { | |
| 10372 addProperty(propId, parsedValue.release(), important); | |
| 10373 return true; | |
| 10374 } | |
| 10375 } | |
| 10376 | |
| 10377 return false; | |
| 10378 } | |
| 10379 | |
| 10380 bool CSSParser::parseViewportShorthand(CSSPropertyID propId, CSSPropertyID first
, CSSPropertyID second, bool important) | |
| 10381 { | |
| 10382 ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_c
ontext.mode())); | |
| 10383 unsigned numValues = m_valueList->size(); | |
| 10384 | |
| 10385 if (numValues > 2) | |
| 10386 return false; | |
| 10387 | |
| 10388 ShorthandScope scope(this, propId); | |
| 10389 | |
| 10390 if (!parseViewportProperty(first, important)) | |
| 10391 return false; | |
| 10392 | |
| 10393 // If just one value is supplied, the second value | |
| 10394 // is implicitly initialized with the first value. | |
| 10395 if (numValues == 1) | |
| 10396 m_valueList->previous(); | |
| 10397 | |
| 10398 return parseViewportProperty(second, important); | |
| 10399 } | |
| 10400 | |
| 10401 template <typename CharacterType> | |
| 10402 static CSSPropertyID cssPropertyID(const CharacterType* propertyName, unsigned l
ength) | |
| 10403 { | |
| 10404 char buffer[maxCSSPropertyNameLength + 1]; // 1 for null character | |
| 10405 | |
| 10406 for (unsigned i = 0; i != length; ++i) { | |
| 10407 CharacterType c = propertyName[i]; | |
| 10408 if (c == 0 || c >= 0x7F) | |
| 10409 return CSSPropertyInvalid; // illegal character | |
| 10410 buffer[i] = toASCIILower(c); | |
| 10411 } | |
| 10412 buffer[length] = '\0'; | |
| 10413 | |
| 10414 const char* name = buffer; | |
| 10415 const Property* hashTableEntry = findProperty(name, length); | |
| 10416 return hashTableEntry ? static_cast<CSSPropertyID>(hashTableEntry->id) : CSS
PropertyInvalid; | |
| 10417 } | |
| 10418 | |
| 10419 CSSPropertyID cssPropertyID(const String& string) | |
| 10420 { | |
| 10421 unsigned length = string.length(); | |
| 10422 | |
| 10423 if (!length) | |
| 10424 return CSSPropertyInvalid; | |
| 10425 if (length > maxCSSPropertyNameLength) | |
| 10426 return CSSPropertyInvalid; | |
| 10427 | |
| 10428 return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPr
opertyID(string.characters16(), length); | |
| 10429 } | |
| 10430 | |
| 10431 CSSPropertyID cssPropertyID(const CSSParserString& string) | |
| 10432 { | |
| 10433 unsigned length = string.length(); | |
| 10434 | |
| 10435 if (!length) | |
| 10436 return CSSPropertyInvalid; | |
| 10437 if (length > maxCSSPropertyNameLength) | |
| 10438 return CSSPropertyInvalid; | |
| 10439 | |
| 10440 return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPr
opertyID(string.characters16(), length); | |
| 10441 } | |
| 10442 | |
| 10443 template <typename CharacterType> | |
| 10444 static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned
length) | |
| 10445 { | |
| 10446 char buffer[maxCSSValueKeywordLength + 1]; // 1 for null character | |
| 10447 | |
| 10448 for (unsigned i = 0; i != length; ++i) { | |
| 10449 CharacterType c = valueKeyword[i]; | |
| 10450 if (c == 0 || c >= 0x7F) | |
| 10451 return CSSValueInvalid; // illegal character | |
| 10452 buffer[i] = WTF::toASCIILower(c); | |
| 10453 } | |
| 10454 buffer[length] = '\0'; | |
| 10455 | |
| 10456 const Value* hashTableEntry = findValue(buffer, length); | |
| 10457 return hashTableEntry ? static_cast<CSSValueID>(hashTableEntry->id) : CSSVal
ueInvalid; | |
| 10458 } | |
| 10459 | |
| 10460 CSSValueID cssValueKeywordID(const CSSParserString& string) | |
| 10461 { | |
| 10462 unsigned length = string.length(); | |
| 10463 if (!length) | |
| 10464 return CSSValueInvalid; | |
| 10465 if (length > maxCSSValueKeywordLength) | |
| 10466 return CSSValueInvalid; | |
| 10467 | |
| 10468 return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : c
ssValueKeywordID(string.characters16(), length); | |
| 10469 } | |
| 10470 | |
| 10471 bool isValidNthToken(const CSSParserString& token) | |
| 10472 { | |
| 10473 // The tokenizer checks for the construct of an+b. | |
| 10474 // However, since the {ident} rule precedes the {nth} rule, some of those | |
| 10475 // tokens are identified as string literal. Furthermore we need to accept | |
| 10476 // "odd" and "even" which does not match to an+b. | |
| 10477 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") | |
| 10478 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); | |
| 10479 } | |
| 10480 | |
| 10481 } | |
| OLD | NEW |