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

Side by Side Diff: third_party/WebKit/Source/core/css/cssom/StyleValueFactory.cpp

Issue 2222863002: [Typed-OM] Enable getting CSSURLImageValue from stylemap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@CSSProperties_Image
Patch Set: Remove backgroundImage test from unsupported-properties, simplify test to get from StyleMap Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/css/cssom/StyleValueFactory.h" 5 #include "core/css/cssom/StyleValueFactory.h"
6 6
7 #include "core/css/CSSImageValue.h"
7 #include "core/css/CSSValue.h" 8 #include "core/css/CSSValue.h"
9 #include "core/css/cssom/CSSNumberValue.h"
8 #include "core/css/cssom/CSSSimpleLength.h" 10 #include "core/css/cssom/CSSSimpleLength.h"
9 #include "core/css/cssom/CSSStyleValue.h" 11 #include "core/css/cssom/CSSStyleValue.h"
10 #include "core/css/cssom/CSSTransformValue.h" 12 #include "core/css/cssom/CSSTransformValue.h"
13 #include "core/css/cssom/CSSURLImageValue.h"
11 #include "core/css/cssom/CSSUnsupportedStyleValue.h" 14 #include "core/css/cssom/CSSUnsupportedStyleValue.h"
12 15
13 namespace blink { 16 namespace blink {
14 17
15 CSSStyleValueVector StyleValueFactory::cssValueToStyleValueVector(CSSPropertyID propertyID, const CSSValue& value) 18 namespace {
19
20 CSSStyleValue* styleValueForProperty(CSSPropertyID propertyID, const CSSValue& v alue)
16 { 21 {
17 CSSStyleValueVector styleValueVector; 22 switch (propertyID) {
23 case CSSPropertyTransform:
24 return CSSTransformValue::fromCSSValue(value);
25 default:
26 // TODO(meade): Implement other complex properties.
27 break;
28 }
18 29
19 if (value.isPrimitiveValue()) { 30 if (value.isPrimitiveValue()) {
20 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); 31 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
21 if (primitiveValue.isLength() && !primitiveValue.isCalculated()) { 32 if (primitiveValue.isLength() && !primitiveValue.isCalculated())
22 styleValueVector.append(CSSSimpleLength::create(primitiveValue.getDo ubleValue(), primitiveValue.typeWithCalcResolved())); 33 return CSSSimpleLength::create(primitiveValue.getDoubleValue(), prim itiveValue.typeWithCalcResolved());
23 return styleValueVector; 34 if (primitiveValue.isNumber())
24 } 35 return CSSNumberValue::create(primitiveValue.getDoubleValue());
25 } 36 }
26 37
27 CSSStyleValue* styleValue = nullptr; 38 if (value.isImageValue()) {
28 switch (propertyID) { 39 const CSSImageValue& imageValue = toCSSImageValue(value);
29 case CSSPropertyTransform: 40 return CSSURLImageValue::create(imageValue.valueWithURLMadeAbsolute());
30 styleValue = CSSTransformValue::fromCSSValue(value);
31 if (styleValue)
32 styleValueVector.append(styleValue);
33 return styleValueVector;
34 default:
35 // TODO(meade): Implement the rest.
36 break;
37 } 41 }
38 42
43 return nullptr;
44 }
45
46 CSSStyleValueVector unsupportedCSSValue(const CSSValue& value)
47 {
48 CSSStyleValueVector styleValueVector;
39 styleValueVector.append(CSSUnsupportedStyleValue::create(value.cssText())); 49 styleValueVector.append(CSSUnsupportedStyleValue::create(value.cssText()));
40 return styleValueVector; 50 return styleValueVector;
41 } 51 }
42 52
53 } // namespace
54
55 CSSStyleValueVector StyleValueFactory::cssValueToStyleValueVector(CSSPropertyID propertyID, const CSSValue& value)
56 {
57 CSSStyleValueVector styleValueVector;
58 CSSStyleValue* styleValue = styleValueForProperty(propertyID, value);
59 if (styleValue) {
60 styleValueVector.append(styleValue);
61 return styleValueVector;
62 }
63
64 if (!value.isValueList()) {
65 return unsupportedCSSValue(value);
66 }
67
68 // If it's a list, we can try it as a list valued property.
69 const CSSValueList& cssValueList = toCSSValueList(value);
70 for (const CSSValue* innerValue : cssValueList) {
71 styleValue = styleValueForProperty(propertyID, *innerValue);
72 if (!styleValue) {
73 return unsupportedCSSValue(value);
74 }
75 styleValueVector.append(styleValue);
76 }
77 return styleValueVector;
78 }
79
43 } // namespace blink 80 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698