OLD | NEW |
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/CSSValue.h" | 7 #include "core/css/CSSValue.h" |
| 8 #include "core/css/cssom/CSSNumberValue.h" |
8 #include "core/css/cssom/CSSSimpleLength.h" | 9 #include "core/css/cssom/CSSSimpleLength.h" |
9 #include "core/css/cssom/CSSStyleValue.h" | 10 #include "core/css/cssom/CSSStyleValue.h" |
10 #include "core/css/cssom/CSSTransformValue.h" | 11 #include "core/css/cssom/CSSTransformValue.h" |
11 #include "core/css/cssom/CSSUnsupportedStyleValue.h" | 12 #include "core/css/cssom/CSSUnsupportedStyleValue.h" |
12 | 13 |
13 namespace blink { | 14 namespace blink { |
14 | 15 |
| 16 namespace { |
| 17 |
| 18 CSSStyleValue* styleValueForProperty(CSSPropertyID propertyID, const CSSValue& v
alue) |
| 19 { |
| 20 switch (propertyID) { |
| 21 case CSSPropertyTransform: |
| 22 return CSSTransformValue::fromCSSValue(value); |
| 23 default: |
| 24 // TODO(meade): Implement other complex properties. |
| 25 break; |
| 26 } |
| 27 |
| 28 if (value.isPrimitiveValue()) { |
| 29 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); |
| 30 if (primitiveValue.isLength() && !primitiveValue.isCalculated()) |
| 31 return CSSSimpleLength::create(primitiveValue.getDoubleValue(), prim
itiveValue.typeWithCalcResolved()); |
| 32 if (primitiveValue.isNumber()) |
| 33 return CSSNumberValue::create(primitiveValue.getDoubleValue()); |
| 34 } |
| 35 |
| 36 return nullptr; |
| 37 } |
| 38 |
| 39 CSSStyleValueVector unsupportedCSSValue(const CSSValue& value) |
| 40 { |
| 41 CSSStyleValueVector styleValueVector; |
| 42 styleValueVector.append(CSSUnsupportedStyleValue::create(value.cssText())); |
| 43 return styleValueVector; |
| 44 } |
| 45 |
| 46 } // namespace |
| 47 |
15 CSSStyleValueVector StyleValueFactory::cssValueToStyleValueVector(CSSPropertyID
propertyID, const CSSValue& value) | 48 CSSStyleValueVector StyleValueFactory::cssValueToStyleValueVector(CSSPropertyID
propertyID, const CSSValue& value) |
16 { | 49 { |
17 CSSStyleValueVector styleValueVector; | 50 CSSStyleValueVector styleValueVector; |
18 | 51 CSSStyleValue* styleValue = styleValueForProperty(propertyID, value); |
19 if (value.isPrimitiveValue()) { | 52 if (styleValue) { |
20 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); | 53 styleValueVector.append(styleValue); |
21 if (primitiveValue.isLength() && !primitiveValue.isCalculated()) { | 54 return styleValueVector; |
22 styleValueVector.append(CSSSimpleLength::create(primitiveValue.getDo
ubleValue(), primitiveValue.typeWithCalcResolved())); | |
23 return styleValueVector; | |
24 } | |
25 } | 55 } |
26 | 56 |
27 CSSStyleValue* styleValue = nullptr; | 57 if (!value.isValueList()) { |
28 switch (propertyID) { | 58 return unsupportedCSSValue(value); |
29 case CSSPropertyTransform: | |
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 } | 59 } |
38 | 60 |
39 styleValueVector.append(CSSUnsupportedStyleValue::create(value.cssText())); | 61 // If it's a list, we can try it as a list valued property. |
| 62 const CSSValueList& cssValueList = toCSSValueList(value); |
| 63 for (const Member<const CSSValue> innerValue : cssValueList) { |
| 64 styleValue = styleValueForProperty(propertyID, *innerValue); |
| 65 if (!styleValue) { |
| 66 return unsupportedCSSValue(value); |
| 67 } |
| 68 styleValueVector.append(styleValue); |
| 69 } |
40 return styleValueVector; | 70 return styleValueVector; |
41 } | 71 } |
42 | 72 |
43 } // namespace blink | 73 } // namespace blink |
OLD | NEW |