OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) | 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. | 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> | 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> |
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 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. | 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. |
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. | 9 * Copyright (C) 2012 Intel Corporation. All rights reserved. |
10 * | 10 * |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 case CSSPropertyWebkitBorderEndColor: | 556 case CSSPropertyWebkitBorderEndColor: |
557 case CSSPropertyWebkitBorderBeforeColor: | 557 case CSSPropertyWebkitBorderBeforeColor: |
558 case CSSPropertyWebkitBorderAfterColor: | 558 case CSSPropertyWebkitBorderAfterColor: |
559 case CSSPropertyColor: // <color> | inherit | 559 case CSSPropertyColor: // <color> | inherit |
560 case CSSPropertyTextDecorationColor: // CSS3 text decoration colors | 560 case CSSPropertyTextDecorationColor: // CSS3 text decoration colors |
561 case CSSPropertyWebkitColumnRuleColor: | 561 case CSSPropertyWebkitColumnRuleColor: |
562 case CSSPropertyWebkitTextEmphasisColor: | 562 case CSSPropertyWebkitTextEmphasisColor: |
563 case CSSPropertyWebkitTextFillColor: | 563 case CSSPropertyWebkitTextFillColor: |
564 case CSSPropertyWebkitTextStrokeColor: | 564 case CSSPropertyWebkitTextStrokeColor: |
565 ASSERT(propId != CSSPropertyTextDecorationColor || RuntimeEnabledFeature
s::css3TextDecorationsEnabled()); | 565 ASSERT(propId != CSSPropertyTextDecorationColor || RuntimeEnabledFeature
s::css3TextDecorationsEnabled()); |
566 | 566 parsedValue = parseColor(m_valueList->current(), acceptQuirkyColors(prop
Id)); |
567 if ((id >= CSSValueAqua && id <= CSSValueWebkitText) || id == CSSValueMe
nu) { | 567 if (parsedValue) |
568 validPrimitive = isValueAllowedInMode(id, m_context.mode()); | 568 m_valueList->next(); |
569 } else { | |
570 if (!inQuirksMode()) { | |
571 parsedValue = parseColor(); | |
572 if (parsedValue) | |
573 m_valueList->next(); | |
574 break; | |
575 } | |
576 | |
577 bool acceptQuirkyColors = false; | |
578 switch (propId) { | |
579 case CSSPropertyBackgroundColor: | |
580 case CSSPropertyBorderBottomColor: | |
581 case CSSPropertyBorderLeftColor: | |
582 case CSSPropertyBorderRightColor: | |
583 case CSSPropertyBorderTopColor: | |
584 if (!inShorthand() || m_currentShorthand == CSSPropertyBorderCol
or) | |
585 acceptQuirkyColors = true; | |
586 break; | |
587 case CSSPropertyColor: | |
588 acceptQuirkyColors = true; | |
589 break; | |
590 default: | |
591 break; | |
592 } | |
593 parsedValue = parseColor(0, acceptQuirkyColors); | |
594 if (parsedValue) | |
595 m_valueList->next(); | |
596 } | |
597 break; | 569 break; |
598 | 570 |
599 case CSSPropertyCursor: { | 571 case CSSPropertyCursor: { |
600 // Grammar defined by CSS3 UI and modified by CSS4 images: | 572 // Grammar defined by CSS3 UI and modified by CSS4 images: |
601 // [ [<image> [<x> <y>]?,]* | 573 // [ [<image> [<x> <y>]?,]* |
602 // [ auto | crosshair | default | pointer | progress | move | e-resize |
ne-resize | | 574 // [ auto | crosshair | default | pointer | progress | move | e-resize |
ne-resize | |
603 // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize |
ew-resize | | 575 // nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize |
ew-resize | |
604 // ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | tex
t | wait | help | | 576 // ns-resize | nesw-resize | nwse-resize | col-resize | row-resize | tex
t | wait | help | |
605 // vertical-text | cell | context-menu | alias | copy | no-drop | not-al
lowed | all-scroll | | 577 // vertical-text | cell | context-menu | alias | copy | no-drop | not-al
lowed | all-scroll | |
606 // zoom-in | zoom-out | -webkit-grab | -webkit-grabbing | -webkit-zoom-i
n | -webkit-zoom-out ] ] | inherit | 578 // zoom-in | zoom-out | -webkit-grab | -webkit-grabbing | -webkit-zoom-i
n | -webkit-zoom-out ] ] | inherit |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 break; | 1339 break; |
1368 | 1340 |
1369 // End Apple-specific properties | 1341 // End Apple-specific properties |
1370 | 1342 |
1371 case CSSPropertyWebkitAppRegion: | 1343 case CSSPropertyWebkitAppRegion: |
1372 if (id >= CSSValueDrag && id <= CSSValueNoDrag) | 1344 if (id >= CSSValueDrag && id <= CSSValueNoDrag) |
1373 validPrimitive = true; | 1345 validPrimitive = true; |
1374 break; | 1346 break; |
1375 | 1347 |
1376 case CSSPropertyWebkitTapHighlightColor: | 1348 case CSSPropertyWebkitTapHighlightColor: |
1377 if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMe
nu | 1349 parsedValue = parseTapHighlightColor(m_valueList->current()); |
1378 || (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText &&
inQuirksMode())) { | 1350 if (parsedValue) |
1379 validPrimitive = true; | 1351 m_valueList->next(); |
1380 } else { | |
1381 parsedValue = parseColor(); | |
1382 if (parsedValue) | |
1383 m_valueList->next(); | |
1384 } | |
1385 break; | 1352 break; |
1386 | 1353 |
1387 /* shorthand properties */ | 1354 /* shorthand properties */ |
1388 case CSSPropertyBackground: { | 1355 case CSSPropertyBackground: { |
1389 // Position must come before color in this array because a plain old "0"
is a legal color | 1356 // Position must come before color in this array because a plain old "0"
is a legal color |
1390 // in quirks mode but it's usually the X coordinate of a position. | 1357 // in quirks mode but it's usually the X coordinate of a position. |
1391 const CSSPropertyID properties[] = { CSSPropertyBackgroundImage, CSSProp
ertyBackgroundRepeat, | 1358 const CSSPropertyID properties[] = { CSSPropertyBackgroundImage, CSSProp
ertyBackgroundRepeat, |
1392 CSSPropertyBackgroundAttachment, CSSPropertyB
ackgroundPosition, CSSPropertyBackgroundOrigin, | 1359 CSSPropertyBackgroundAttachment, CSSPropertyB
ackgroundPosition, CSSPropertyBackgroundOrigin, |
1393 CSSPropertyBackgroundClip, CSSPropertyBackgro
undColor, CSSPropertyBackgroundSize }; | 1360 CSSPropertyBackgroundClip, CSSPropertyBackgro
undColor, CSSPropertyBackgroundSize }; |
1394 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(propertie
s), important); | 1361 return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(propertie
s), important); |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2291 // even parse them inside attr(). | 2258 // even parse them inside attr(). |
2292 if (attrName[0] == '-') | 2259 if (attrName[0] == '-') |
2293 return nullptr; | 2260 return nullptr; |
2294 | 2261 |
2295 if (m_context.isHTMLDocument()) | 2262 if (m_context.isHTMLDocument()) |
2296 attrName = attrName.lower(); | 2263 attrName = attrName.lower(); |
2297 | 2264 |
2298 return cssValuePool().createValue(attrName, CSSPrimitiveValue::CSS_ATTR); | 2265 return cssValuePool().createValue(attrName, CSSPrimitiveValue::CSS_ATTR); |
2299 } | 2266 } |
2300 | 2267 |
2301 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseBackgroundColor() | 2268 bool CSSPropertyParser::acceptQuirkyColors(CSSPropertyID propertyId) const |
2302 { | 2269 { |
2303 CSSValueID id = m_valueList->current()->id; | 2270 if (!inQuirksMode()) |
2304 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowt
ext) || id == CSSValueMenu || id == CSSValueCurrentcolor || | 2271 return false; |
2305 (id >= CSSValueGrey && id < CSSValueWebkitText && inQuirksMode())) | 2272 switch (propertyId) { |
| 2273 case CSSPropertyBackgroundColor: |
| 2274 case CSSPropertyBorderBottomColor: |
| 2275 case CSSPropertyBorderLeftColor: |
| 2276 case CSSPropertyBorderRightColor: |
| 2277 case CSSPropertyBorderTopColor: |
| 2278 return !inShorthand() || m_currentShorthand == CSSPropertyBorderColor; |
| 2279 case CSSPropertyColor: |
| 2280 return true; |
| 2281 default: |
| 2282 break; |
| 2283 } |
| 2284 return false; |
| 2285 } |
| 2286 |
| 2287 bool CSSPropertyParser::isColorKeyword(CSSValueID id) |
| 2288 { |
| 2289 // Named colors and color keywords: |
| 2290 // |
| 2291 // <named-color> |
| 2292 // 'aqua', 'black', 'blue', ..., 'yellow' (CSS3: "basic color keywords") |
| 2293 // 'aliceblue', ..., 'yellowgreen' (CSS3: "extended color keywords"
) |
| 2294 // 'transparent' |
| 2295 // |
| 2296 // 'currentcolor' |
| 2297 // |
| 2298 // <deprecated-system-color> |
| 2299 // 'ActiveBorder', ..., 'WindowText' |
| 2300 // |
| 2301 // WebKit proprietary/internal: |
| 2302 // '-webkit-link' |
| 2303 // '-webkit-activelink' |
| 2304 // '-internal-active-list-box-selection' |
| 2305 // '-internal-active-list-box-selection-text' |
| 2306 // '-internal-inactive-list-box-selection' |
| 2307 // '-internal-inactive-list-box-selection-text' |
| 2308 // '-webkit-focus-ring-color' |
| 2309 // |
| 2310 // TODO(fs): The "extended color keywords" are not included. |
| 2311 return (id >= CSSValueAqua && id <= CSSValueWebkitText) || id == CSSValueMen
u; |
| 2312 } |
| 2313 |
| 2314 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseColor(const CS
SParserValue* value, bool acceptQuirkyColors) |
| 2315 { |
| 2316 CSSValueID id = value->id; |
| 2317 if (isColorKeyword(id)) { |
| 2318 if (!isValueAllowedInMode(id, m_context.mode())) |
| 2319 return nullptr; |
2306 return cssValuePool().createIdentifierValue(id); | 2320 return cssValuePool().createIdentifierValue(id); |
2307 return parseColor(); | 2321 } |
| 2322 RGBA32 c = Color::transparent; |
| 2323 if (!parseColorFromValue(value, c, acceptQuirkyColors)) |
| 2324 return nullptr; |
| 2325 return cssValuePool().createColorValue(c); |
| 2326 } |
| 2327 |
| 2328 // Used to parse background-color when part of a shorthand. |
| 2329 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseBackgroundColo
r(const CSSParserValue* value) |
| 2330 { |
| 2331 CSSValueID id = value->id; |
| 2332 // Allow -webkit-text regardless of quirks. |
| 2333 if (id == CSSValueWebkitText) |
| 2334 return cssValuePool().createIdentifierValue(id); |
| 2335 return parseColor(value); |
| 2336 } |
| 2337 |
| 2338 // Used to parse the '-webkit-tap-highlight-color' property. |
| 2339 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseTapHighlightCo
lor(const CSSParserValue* value) |
| 2340 { |
| 2341 CSSValueID id = value->id; |
| 2342 // Disallow -webkit-text regardless of quirks. |
| 2343 if (id == CSSValueWebkitText) |
| 2344 return nullptr; |
| 2345 // Allow currentcolor in quirks-mode only. |
| 2346 if (id == CSSValueCurrentcolor) { |
| 2347 if (!inQuirksMode()) |
| 2348 return nullptr; |
| 2349 return cssValuePool().createIdentifierValue(id); |
| 2350 } |
| 2351 return parseColor(value); |
| 2352 } |
| 2353 |
| 2354 // Used to parse <color> for CSS gradients. |
| 2355 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseGradientStopCo
lor(const CSSParserValue* value) |
| 2356 { |
| 2357 CSSValueID id = value->id; |
| 2358 // Allow -webkit-text regardless of quirks. |
| 2359 if (id == CSSValueWebkitText) |
| 2360 return cssValuePool().createIdentifierValue(id); |
| 2361 return parseColor(value); |
| 2362 } |
| 2363 |
| 2364 // Used to parse colors for -webkit-gradient(...). |
| 2365 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseDeprecatedGrad
ientStopColor(const CSSParserValue* value) |
| 2366 { |
| 2367 // Disallow currentcolor. |
| 2368 if (value->id == CSSValueCurrentcolor) |
| 2369 return nullptr; |
| 2370 return parseGradientStopColor(value); |
| 2371 } |
| 2372 |
| 2373 // Used to parse <color> for SVG properties. |
| 2374 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseSVGColor(const
CSSParserValue* value) |
| 2375 { |
| 2376 CSSValueID id = value->id; |
| 2377 if (id == CSSValueCurrentcolor) |
| 2378 return cssValuePool().createIdentifierValue(id); |
| 2379 if ((id >= CSSValueActiveborder && id <= CSSValueWindowtext) || id == CSSVal
ueMenu) |
| 2380 return cssValuePool().createColorValue(LayoutTheme::theme().systemColor(
id).rgb()); |
| 2381 RGBA32 c = Color::transparent; |
| 2382 if (!parseColorFromValue(value, c)) |
| 2383 return nullptr; |
| 2384 return cssValuePool().createColorValue(c); |
2308 } | 2385 } |
2309 | 2386 |
2310 bool CSSPropertyParser::parseFillImage(CSSParserValueList* valueList, RefPtrWill
BeRawPtr<CSSValue>& value) | 2387 bool CSSPropertyParser::parseFillImage(CSSParserValueList* valueList, RefPtrWill
BeRawPtr<CSSValue>& value) |
2311 { | 2388 { |
2312 if (valueList->current()->id == CSSValueNone) { | 2389 if (valueList->current()->id == CSSValueNone) { |
2313 value = cssValuePool().createIdentifierValue(CSSValueNone); | 2390 value = cssValuePool().createIdentifierValue(CSSValueNone); |
2314 return true; | 2391 return true; |
2315 } | 2392 } |
2316 if (valueList->current()->unit == CSSPrimitiveValue::CSS_URI) { | 2393 if (valueList->current()->unit == CSSPrimitiveValue::CSS_URI) { |
2317 value = createCSSImageValueWithReferrer(valueList->current()->string, co
mpleteURL(valueList->current()->string)); | 2394 value = createCSSImageValueWithReferrer(valueList->current()->string, co
mpleteURL(valueList->current()->string)); |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2788 while (true) { | 2865 while (true) { |
2789 RefPtrWillBeRawPtr<CSSValue> currValue = nullptr; | 2866 RefPtrWillBeRawPtr<CSSValue> currValue = nullptr; |
2790 RefPtrWillBeRawPtr<CSSValue> currValue2 = nullptr; | 2867 RefPtrWillBeRawPtr<CSSValue> currValue2 = nullptr; |
2791 | 2868 |
2792 Units unitless = FUnknown; | 2869 Units unitless = FUnknown; |
2793 CSSParserValue* val = m_valueList->current(); | 2870 CSSParserValue* val = m_valueList->current(); |
2794 ASSERT(val); | 2871 ASSERT(val); |
2795 | 2872 |
2796 switch (propId) { | 2873 switch (propId) { |
2797 case CSSPropertyBackgroundColor: | 2874 case CSSPropertyBackgroundColor: |
2798 currValue = parseBackgroundColor(); | 2875 currValue = parseBackgroundColor(val); |
2799 if (currValue) | 2876 if (currValue) |
2800 m_valueList->next(); | 2877 m_valueList->next(); |
2801 break; | 2878 break; |
2802 case CSSPropertyBackgroundAttachment: | 2879 case CSSPropertyBackgroundAttachment: |
2803 if (val->id == CSSValueScroll || val->id == CSSValueFixed || val->id
== CSSValueLocal) { | 2880 if (val->id == CSSValueScroll || val->id == CSSValueFixed || val->id
== CSSValueLocal) { |
2804 currValue = cssValuePool().createIdentifierValue(val->id); | 2881 currValue = cssValuePool().createIdentifierValue(val->id); |
2805 m_valueList->next(); | 2882 m_valueList->next(); |
2806 } | 2883 } |
2807 break; | 2884 break; |
2808 case CSSPropertyBackgroundImage: | 2885 case CSSPropertyBackgroundImage: |
(...skipping 2156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4965 return 255; | 5042 return 255; |
4966 return static_cast<int>(value * 256.0 / 100.0); | 5043 return static_cast<int>(value * 256.0 / 100.0); |
4967 } | 5044 } |
4968 | 5045 |
4969 if (value >= 255.0) | 5046 if (value >= 255.0) |
4970 return 255; | 5047 return 255; |
4971 | 5048 |
4972 return static_cast<int>(value); | 5049 return static_cast<int>(value); |
4973 } | 5050 } |
4974 | 5051 |
4975 bool CSSPropertyParser::parseColorParameters(CSSParserValue* value, int* colorAr
ray, bool parseAlpha) | 5052 bool CSSPropertyParser::parseColorParameters(const CSSParserValue* value, int* c
olorArray, bool parseAlpha) |
4976 { | 5053 { |
4977 CSSParserValueList* args = value->function->args.get(); | 5054 CSSParserValueList* args = value->function->args.get(); |
4978 CSSParserValue* v = args->current(); | 5055 CSSParserValue* v = args->current(); |
4979 Units unitType = FUnknown; | 5056 Units unitType = FUnknown; |
4980 // Get the first value and its type | 5057 // Get the first value and its type |
4981 if (validUnit(v, FInteger)) | 5058 if (validUnit(v, FInteger)) |
4982 unitType = FInteger; | 5059 unitType = FInteger; |
4983 else if (validUnit(v, FPercent)) | 5060 else if (validUnit(v, FPercent)) |
4984 unitType = FPercent; | 5061 unitType = FPercent; |
4985 else | 5062 else |
(...skipping 21 matching lines...) Expand all Loading... |
5007 colorArray[3] = static_cast<int>(std::max(0.0, std::min(1.0, v->fValue))
* nextafter(256.0, 0.0)); | 5084 colorArray[3] = static_cast<int>(std::max(0.0, std::min(1.0, v->fValue))
* nextafter(256.0, 0.0)); |
5008 } | 5085 } |
5009 return true; | 5086 return true; |
5010 } | 5087 } |
5011 | 5088 |
5012 // The CSS3 specification defines the format of a HSL color as | 5089 // The CSS3 specification defines the format of a HSL color as |
5013 // hsl(<number>, <percent>, <percent>) | 5090 // hsl(<number>, <percent>, <percent>) |
5014 // and with alpha, the format is | 5091 // and with alpha, the format is |
5015 // hsla(<number>, <percent>, <percent>, <number>) | 5092 // hsla(<number>, <percent>, <percent>, <number>) |
5016 // The first value, HUE, is in an angle with a value between 0 and 360 | 5093 // The first value, HUE, is in an angle with a value between 0 and 360 |
5017 bool CSSPropertyParser::parseHSLParameters(CSSParserValue* value, double* colorA
rray, bool parseAlpha) | 5094 bool CSSPropertyParser::parseHSLParameters(const CSSParserValue* value, double*
colorArray, bool parseAlpha) |
5018 { | 5095 { |
5019 CSSParserValueList* args = value->function->args.get(); | 5096 CSSParserValueList* args = value->function->args.get(); |
5020 CSSParserValue* v = args->current(); | 5097 CSSParserValue* v = args->current(); |
5021 // Get the first value | 5098 // Get the first value |
5022 if (!validUnit(v, FNumber)) | 5099 if (!validUnit(v, FNumber)) |
5023 return false; | 5100 return false; |
5024 // normalize the Hue value and change it to be between 0 and 1.0 | 5101 // normalize the Hue value and change it to be between 0 and 1.0 |
5025 colorArray[0] = (((static_cast<int>(v->fValue) % 360) + 360) % 360) / 360.0; | 5102 colorArray[0] = (((static_cast<int>(v->fValue) % 360) + 360) % 360) / 360.0; |
5026 for (int i = 1; i < 3; i++) { | 5103 for (int i = 1; i < 3; i++) { |
5027 args->next(); | 5104 args->next(); |
(...skipping 10 matching lines...) Expand all Loading... |
5038 if (!consumeComma(args)) | 5115 if (!consumeComma(args)) |
5039 return false; | 5116 return false; |
5040 v = args->current(); | 5117 v = args->current(); |
5041 if (!validUnit(v, FNumber)) | 5118 if (!validUnit(v, FNumber)) |
5042 return false; | 5119 return false; |
5043 colorArray[3] = std::max(0.0, std::min(1.0, v->fValue)); | 5120 colorArray[3] = std::max(0.0, std::min(1.0, v->fValue)); |
5044 } | 5121 } |
5045 return true; | 5122 return true; |
5046 } | 5123 } |
5047 | 5124 |
5048 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseColor(CSSParse
rValue* value, bool acceptQuirkyColors) | 5125 bool CSSPropertyParser::parseColorFromValue(const CSSParserValue* value, RGBA32&
result, bool acceptQuirkyColors) |
5049 { | |
5050 RGBA32 c = Color::transparent; | |
5051 if (!parseColorFromValue(value ? value : m_valueList->current(), c, acceptQu
irkyColors)) | |
5052 return nullptr; | |
5053 return cssValuePool().createColorValue(c); | |
5054 } | |
5055 | |
5056 bool CSSPropertyParser::parseColorFromValue(CSSParserValue* value, RGBA32& resul
t, bool acceptQuirkyColors) | |
5057 { | 5126 { |
5058 if (acceptQuirkyColors && value->unit == CSSPrimitiveValue::CSS_NUMBER | 5127 if (acceptQuirkyColors && value->unit == CSSPrimitiveValue::CSS_NUMBER |
5059 && value->fValue >= 0. && value->fValue < 1000000. && value->isInt) { | 5128 && value->fValue >= 0. && value->fValue < 1000000. && value->isInt) { |
5060 String str = String::format("%06d", static_cast<int>(value->fValue)); | 5129 String str = String::format("%06d", static_cast<int>(value->fValue)); |
5061 return Color::parseHexColor(str, result); | 5130 return Color::parseHexColor(str, result); |
5062 } else if (acceptQuirkyColors && value->unit == CSSParserValue::DimensionLis
t) { | 5131 } else if (acceptQuirkyColors && value->unit == CSSParserValue::DimensionLis
t) { |
5063 CSSParserValue* numberToken = value->valueList->valueAt(0); | 5132 CSSParserValue* numberToken = value->valueList->valueAt(0); |
5064 CSSParserValue* unitToken = value->valueList->valueAt(1); | 5133 CSSParserValue* unitToken = value->valueList->valueAt(1); |
5065 ASSERT(numberToken->unit == CSSPrimitiveValue::CSS_NUMBER); | 5134 ASSERT(numberToken->unit == CSSPrimitiveValue::CSS_NUMBER); |
5066 ASSERT(unitToken->unit == CSSPrimitiveValue::CSS_IDENT); | 5135 ASSERT(unitToken->unit == CSSPrimitiveValue::CSS_IDENT); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5265 | 5334 |
5266 // A length is allowed here. Construct the value and add it. | 5335 // A length is allowed here. Construct the value and add it. |
5267 RefPtrWillBeRawPtr<CSSPrimitiveValue> length = createPrimitiveNumeri
cValue(val); | 5336 RefPtrWillBeRawPtr<CSSPrimitiveValue> length = createPrimitiveNumeri
cValue(val); |
5268 context.commitLength(length.release()); | 5337 context.commitLength(length.release()); |
5269 } else if (val->id == CSSValueInset) { | 5338 } else if (val->id == CSSValueInset) { |
5270 if (!context.allowStyle) | 5339 if (!context.allowStyle) |
5271 return nullptr; | 5340 return nullptr; |
5272 | 5341 |
5273 context.commitStyle(val); | 5342 context.commitStyle(val); |
5274 } else { | 5343 } else { |
| 5344 if (!context.allowColor) |
| 5345 return nullptr; |
| 5346 |
5275 // The only other type of value that's ok is a color value. | 5347 // The only other type of value that's ok is a color value. |
5276 RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedColor = nullptr; | 5348 RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedColor = parseColor(val); |
5277 bool isColor = ((val->id >= CSSValueAqua && val->id <= CSSValueWindo
wtext) || val->id == CSSValueMenu | |
5278 || (val->id >= CSSValueWebkitFocusRingColor && val->
id <= CSSValueWebkitText && inQuirksMode()) | |
5279 || val->id == CSSValueCurrentcolor); | |
5280 if (isColor) { | |
5281 if (!context.allowColor) | |
5282 return nullptr; | |
5283 parsedColor = cssValuePool().createIdentifierValue(val->id); | |
5284 } | |
5285 | |
5286 if (!parsedColor) | 5349 if (!parsedColor) |
5287 // It's not built-in. Try to parse it as a color. | 5350 return nullptr; |
5288 parsedColor = parseColor(val); | |
5289 | |
5290 if (!parsedColor || !context.allowColor) | |
5291 return nullptr; // This value is not a color or length and is in
valid or | |
5292 // it is a color, but a color isn't allowed at this po
int. | |
5293 | 5351 |
5294 context.commitColor(parsedColor.release()); | 5352 context.commitColor(parsedColor.release()); |
5295 } | 5353 } |
5296 } | 5354 } |
5297 | 5355 |
5298 if (context.allowBreak) { | 5356 if (context.allowBreak) { |
5299 context.commitValue(); | 5357 context.commitValue(); |
5300 if (context.values && context.values->length()) | 5358 if (context.values && context.values->length()) |
5301 return context.values.release(); | 5359 return context.values.release(); |
5302 } | 5360 } |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6035 if (a->function->id == CSSValueFrom || a->function->id == CSSValueTo) { | 6093 if (a->function->id == CSSValueFrom || a->function->id == CSSValueTo) { |
6036 // The "from" and "to" stops expect 1 argument. | 6094 // The "from" and "to" stops expect 1 argument. |
6037 if (args->size() != 1) | 6095 if (args->size() != 1) |
6038 return false; | 6096 return false; |
6039 | 6097 |
6040 if (a->function->id == CSSValueFrom) | 6098 if (a->function->id == CSSValueFrom) |
6041 stop.m_position = cssValuePool().createValue(0, CSSPrimitiveValue::C
SS_NUMBER); | 6099 stop.m_position = cssValuePool().createValue(0, CSSPrimitiveValue::C
SS_NUMBER); |
6042 else | 6100 else |
6043 stop.m_position = cssValuePool().createValue(1, CSSPrimitiveValue::C
SS_NUMBER); | 6101 stop.m_position = cssValuePool().createValue(1, CSSPrimitiveValue::C
SS_NUMBER); |
6044 | 6102 |
6045 CSSValueID id = args->current()->id; | 6103 stop.m_color = parseDeprecatedGradientStopColor(args->current()); |
6046 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWin
dowtext) || id == CSSValueMenu) | |
6047 stop.m_color = cssValuePool().createIdentifierValue(id); | |
6048 else | |
6049 stop.m_color = parseColor(args->current()); | |
6050 if (!stop.m_color) | 6104 if (!stop.m_color) |
6051 return false; | 6105 return false; |
6052 } | 6106 } |
6053 | 6107 |
6054 // The "color-stop" function expects 3 arguments. | 6108 // The "color-stop" function expects 3 arguments. |
6055 if (a->function->id == CSSValueColorStop) { | 6109 if (a->function->id == CSSValueColorStop) { |
6056 if (args->size() != 3) | 6110 if (args->size() != 3) |
6057 return false; | 6111 return false; |
6058 | 6112 |
6059 CSSParserValue* stopArg = args->current(); | 6113 CSSParserValue* stopArg = args->current(); |
6060 if (stopArg->unit == CSSPrimitiveValue::CSS_PERCENTAGE) | 6114 if (stopArg->unit == CSSPrimitiveValue::CSS_PERCENTAGE) |
6061 stop.m_position = cssValuePool().createValue(stopArg->fValue / 100,
CSSPrimitiveValue::CSS_NUMBER); | 6115 stop.m_position = cssValuePool().createValue(stopArg->fValue / 100,
CSSPrimitiveValue::CSS_NUMBER); |
6062 else if (stopArg->unit == CSSPrimitiveValue::CSS_NUMBER) | 6116 else if (stopArg->unit == CSSPrimitiveValue::CSS_NUMBER) |
6063 stop.m_position = cssValuePool().createValue(stopArg->fValue, CSSPri
mitiveValue::CSS_NUMBER); | 6117 stop.m_position = cssValuePool().createValue(stopArg->fValue, CSSPri
mitiveValue::CSS_NUMBER); |
6064 else | 6118 else |
6065 return false; | 6119 return false; |
6066 | 6120 |
6067 args->next(); | 6121 args->next(); |
6068 if (!consumeComma(args)) | 6122 if (!consumeComma(args)) |
6069 return false; | 6123 return false; |
6070 | 6124 |
6071 stopArg = args->current(); | 6125 stop.m_color = parseDeprecatedGradientStopColor(args->current()); |
6072 CSSValueID id = stopArg->id; | |
6073 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWin
dowtext) || id == CSSValueMenu) | |
6074 stop.m_color = cssValuePool().createIdentifierValue(id); | |
6075 else | |
6076 stop.m_color = parseColor(stopArg); | |
6077 if (!stop.m_color) | 6126 if (!stop.m_color) |
6078 return false; | 6127 return false; |
6079 } | 6128 } |
6080 | 6129 |
6081 return true; | 6130 return true; |
6082 } | 6131 } |
6083 | 6132 |
6084 bool CSSPropertyParser::parseDeprecatedGradient(CSSParserValueList* valueList, R
efPtrWillBeRawPtr<CSSValue>& gradient) | 6133 bool CSSPropertyParser::parseDeprecatedGradient(CSSParserValueList* valueList, R
efPtrWillBeRawPtr<CSSValue>& gradient) |
6085 { | 6134 { |
6086 // Walk the arguments. | 6135 // Walk the arguments. |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6631 return false; | 6680 return false; |
6632 | 6681 |
6633 a = valueList->next(); | 6682 a = valueList->next(); |
6634 if (!a) | 6683 if (!a) |
6635 return false; | 6684 return false; |
6636 } | 6685 } |
6637 | 6686 |
6638 // <color-stop> = <color> [ <percentage> | <length> ]? | 6687 // <color-stop> = <color> [ <percentage> | <length> ]? |
6639 // <color-hint> = <length> | <percentage> | 6688 // <color-hint> = <length> | <percentage> |
6640 CSSGradientColorStop stop; | 6689 CSSGradientColorStop stop; |
6641 CSSValueID id = a->id; | 6690 stop.m_color = parseGradientStopColor(a); |
6642 if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWin
dowtext) || id == CSSValueMenu || id == CSSValueCurrentcolor) | |
6643 stop.m_color = cssValuePool().createIdentifierValue(id); | |
6644 else | |
6645 stop.m_color = parseColor(a); | |
6646 | |
6647 | 6691 |
6648 // Two hints in a row are not allowed. | 6692 // Two hints in a row are not allowed. |
6649 if (!stop.m_color && (!supportsColorHints || previousStopWasColorHint)) | 6693 if (!stop.m_color && (!supportsColorHints || previousStopWasColorHint)) |
6650 return false; | 6694 return false; |
6651 previousStopWasColorHint = !stop.m_color; | 6695 previousStopWasColorHint = !stop.m_color; |
6652 | 6696 |
6653 if (stop.m_color) | 6697 if (stop.m_color) |
6654 a = valueList->next(); | 6698 a = valueList->next(); |
6655 | 6699 |
6656 if (a) { | 6700 if (a) { |
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7646 { | 7690 { |
7647 unsigned length = string.length(); | 7691 unsigned length = string.length(); |
7648 if (!length) | 7692 if (!length) |
7649 return CSSValueInvalid; | 7693 return CSSValueInvalid; |
7650 if (length > maxCSSValueKeywordLength) | 7694 if (length > maxCSSValueKeywordLength) |
7651 return CSSValueInvalid; | 7695 return CSSValueInvalid; |
7652 | 7696 |
7653 return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : c
ssValueKeywordID(string.characters16(), length); | 7697 return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : c
ssValueKeywordID(string.characters16(), length); |
7654 } | 7698 } |
7655 | 7699 |
7656 bool CSSPropertyParser::isSystemColor(int id) | 7700 bool CSSPropertyParser::isSystemColor(CSSValueID id) |
7657 { | 7701 { |
7658 return (id >= CSSValueActiveborder && id <= CSSValueWindowtext) || id == CSS
ValueMenu; | 7702 return (id >= CSSValueActiveborder && id <= CSSValueWindowtext) || id == CSS
ValueMenu; |
7659 } | 7703 } |
7660 | 7704 |
7661 bool CSSPropertyParser::parseSVGValue(CSSPropertyID propId, bool important) | 7705 bool CSSPropertyParser::parseSVGValue(CSSPropertyID propId, bool important) |
7662 { | 7706 { |
7663 CSSParserValue* value = m_valueList->current(); | 7707 CSSParserValue* value = m_valueList->current(); |
7664 ASSERT(value); | 7708 ASSERT(value); |
7665 | 7709 |
7666 CSSValueID id = value->id; | 7710 CSSValueID id = value->id; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7790 parsedValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitiveV
alue::CSS_DEG); | 7834 parsedValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitiveV
alue::CSS_DEG); |
7791 | 7835 |
7792 if (parsedValue) | 7836 if (parsedValue) |
7793 m_valueList->next(); | 7837 m_valueList->next(); |
7794 } | 7838 } |
7795 break; | 7839 break; |
7796 | 7840 |
7797 case CSSPropertyFill: // <paint> | inherit | 7841 case CSSPropertyFill: // <paint> | inherit |
7798 case CSSPropertyStroke: // <paint> | inherit | 7842 case CSSPropertyStroke: // <paint> | inherit |
7799 { | 7843 { |
7800 if (id == CSSValueNone || id == CSSValueCurrentcolor) { | 7844 if (id == CSSValueNone) { |
7801 parsedValue = cssValuePool().createIdentifierValue(id); | 7845 parsedValue = cssValuePool().createIdentifierValue(id); |
7802 } else if (isSystemColor(id)) { | |
7803 parsedValue = cssValuePool().createColorValue(LayoutTheme::theme
().systemColor(id).rgb()); | |
7804 } else if (value->unit == CSSPrimitiveValue::CSS_URI) { | 7846 } else if (value->unit == CSSPrimitiveValue::CSS_URI) { |
7805 RGBA32 c = Color::transparent; | |
7806 if (m_valueList->next()) { | 7847 if (m_valueList->next()) { |
7807 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::crea
teSpaceSeparated(); | 7848 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::crea
teSpaceSeparated(); |
7808 values->append(CSSPrimitiveValue::create(value->string, CSSP
rimitiveValue::CSS_URI)); | 7849 values->append(CSSPrimitiveValue::create(value->string, CSSP
rimitiveValue::CSS_URI)); |
7809 if (parseColorFromValue(m_valueList->current(), c)) | 7850 if (m_valueList->current()->id == CSSValueNone) |
7810 parsedValue = cssValuePool().createColorValue(c); | |
7811 else if (m_valueList->current()->id == CSSValueNone || m_val
ueList->current()->id == CSSValueCurrentcolor) | |
7812 parsedValue = cssValuePool().createIdentifierValue(m_val
ueList->current()->id); | 7851 parsedValue = cssValuePool().createIdentifierValue(m_val
ueList->current()->id); |
| 7852 else |
| 7853 parsedValue = parseSVGColor(m_valueList->current()); |
7813 if (parsedValue) { | 7854 if (parsedValue) { |
7814 values->append(parsedValue); | 7855 values->append(parsedValue); |
7815 parsedValue = values; | 7856 parsedValue = values; |
7816 } | 7857 } |
7817 } | 7858 } |
7818 if (!parsedValue) | 7859 if (!parsedValue) |
7819 parsedValue = CSSPrimitiveValue::create(value->string, CSSPr
imitiveValue::CSS_URI); | 7860 parsedValue = CSSPrimitiveValue::create(value->string, CSSPr
imitiveValue::CSS_URI); |
7820 } else { | 7861 } else { |
7821 parsedValue = parseColor(); | 7862 parsedValue = parseSVGColor(m_valueList->current()); |
7822 } | 7863 } |
7823 | 7864 |
7824 if (parsedValue) | 7865 if (parsedValue) |
7825 m_valueList->next(); | 7866 m_valueList->next(); |
7826 } | 7867 } |
7827 break; | 7868 break; |
7828 | 7869 |
7829 case CSSPropertyStopColor: // TODO : icccolor | 7870 case CSSPropertyStopColor: // TODO : icccolor |
7830 case CSSPropertyFloodColor: | 7871 case CSSPropertyFloodColor: |
7831 case CSSPropertyLightingColor: | 7872 case CSSPropertyLightingColor: |
7832 if (isSystemColor(id)) | 7873 parsedValue = parseSVGColor(m_valueList->current()); |
7833 parsedValue = cssValuePool().createColorValue(LayoutTheme::theme().s
ystemColor(id).rgb()); | |
7834 else if (id == CSSValueCurrentcolor) | |
7835 parsedValue = cssValuePool().createIdentifierValue(id); | |
7836 else // TODO : svgcolor (iccColor) | |
7837 parsedValue = parseColor(); | |
7838 | |
7839 if (parsedValue) | 7874 if (parsedValue) |
7840 m_valueList->next(); | 7875 m_valueList->next(); |
7841 | 7876 |
7842 break; | 7877 break; |
7843 | 7878 |
7844 case CSSPropertyPaintOrder: | 7879 case CSSPropertyPaintOrder: |
7845 if (m_valueList->size() == 1 && id == CSSValueNormal) | 7880 if (m_valueList->size() == 1 && id == CSSValueNormal) |
7846 validPrimitive = true; | 7881 validPrimitive = true; |
7847 else if ((parsedValue = parsePaintOrder())) | 7882 else if ((parsedValue = parsePaintOrder())) |
7848 m_valueList->next(); | 7883 m_valueList->next(); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8246 } | 8281 } |
8247 } | 8282 } |
8248 | 8283 |
8249 if (!list->length()) | 8284 if (!list->length()) |
8250 return nullptr; | 8285 return nullptr; |
8251 | 8286 |
8252 return list.release(); | 8287 return list.release(); |
8253 } | 8288 } |
8254 | 8289 |
8255 } // namespace blink | 8290 } // namespace blink |
OLD | NEW |