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/InlineStylePropertyMap.h" | 5 #include "core/css/cssom/InlineStylePropertyMap.h" |
6 | 6 |
7 #include "core/CSSPropertyNames.h" | 7 #include "core/CSSPropertyNames.h" |
8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
9 #include "core/css/CSSPropertyMetadata.h" | 9 #include "core/css/CSSPropertyMetadata.h" |
10 #include "core/css/CSSValueList.h" | 10 #include "core/css/CSSValueList.h" |
11 #include "core/css/StylePropertySet.h" | 11 #include "core/css/StylePropertySet.h" |
12 #include "core/css/cssom/CSSOMTypes.h" | 12 #include "core/css/cssom/CSSOMTypes.h" |
13 #include "core/css/cssom/SimpleLength.h" | 13 #include "core/css/cssom/SimpleLength.h" |
14 #include "core/css/cssom/StyleValueFactory.h" | 14 #include "core/css/cssom/StyleValueFactory.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 StyleValue* InlineStylePropertyMap::get(CSSPropertyID propertyID) | 18 StylePropertyMap::StyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID
propertyID) |
19 { | |
20 StyleValueVector styleVector = getAll(propertyID); | |
21 if (styleVector.isEmpty()) | |
22 return nullptr; | |
23 | |
24 return styleVector.at(0); | |
25 } | |
26 | |
27 StyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID propertyID) | |
28 { | 19 { |
29 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC
SSValue(propertyID); | 20 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC
SSValue(propertyID); |
30 if (!cssValue) | 21 if (!cssValue) |
31 return StyleValueVector(); | 22 return StyleValueVector(); |
32 | 23 |
33 StyleValueVector styleValueVector; | 24 return cssValueToStyleValueVector(propertyID, *cssValue); |
34 | |
35 if (!cssValue->isValueList()) { | |
36 StyleValue* styleValue = StyleValueFactory::create(propertyID, *cssValue
); | |
37 if (styleValue) | |
38 styleValueVector.append(styleValue); | |
39 return styleValueVector; | |
40 } | |
41 | |
42 for (CSSValue* value : *toCSSValueList(cssValue)) { | |
43 StyleValue* styleValue = StyleValueFactory::create(propertyID, *value); | |
44 if (!styleValue) { | |
45 return StyleValueVector(); | |
46 } | |
47 styleValueVector.append(styleValue); | |
48 } | |
49 return styleValueVector; | |
50 } | 25 } |
51 | 26 |
52 bool InlineStylePropertyMap::has(CSSPropertyID propertyID) | 27 bool InlineStylePropertyMap::has(CSSPropertyID propertyID) |
53 { | 28 { |
54 return !getAll(propertyID).isEmpty(); | 29 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC
SSValue(propertyID); |
| 30 if (!cssValue) |
| 31 return false; |
| 32 |
| 33 return (!cssValue->isValueList() || toCSSValueList(cssValue)->length() > 0); |
55 } | 34 } |
56 | 35 |
57 Vector<String> InlineStylePropertyMap::getProperties() | 36 Vector<String> InlineStylePropertyMap::getProperties() |
58 { | 37 { |
59 Vector<String> result; | 38 Vector<String> result; |
60 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); | 39 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); |
61 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { | 40 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { |
62 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); | 41 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); |
63 result.append(getPropertyNameString(propertyID)); | 42 result.append(getPropertyNameString(propertyID)); |
64 } | 43 } |
(...skipping 25 matching lines...) Expand all Loading... |
90 } | 69 } |
91 valueList->append(value->toCSSValue()); | 70 valueList->append(value->toCSSValue()); |
92 } | 71 } |
93 | 72 |
94 m_ownerElement->setInlineStyleProperty(propertyID, valueList); | 73 m_ownerElement->setInlineStyleProperty(propertyID, valueList); |
95 } else { | 74 } else { |
96 // Parse it. | 75 // Parse it. |
97 ASSERT(item.isString()); | 76 ASSERT(item.isString()); |
98 // TODO(meade): Implement this. | 77 // TODO(meade): Implement this. |
99 exceptionState.throwTypeError("Not implemented yet"); | 78 exceptionState.throwTypeError("Not implemented yet"); |
| 79 return; |
100 } | 80 } |
101 } | 81 } |
102 | 82 |
103 void InlineStylePropertyMap::append(CSSPropertyID propertyID, StyleValueOrStyleV
alueSequenceOrString& item, ExceptionState& exceptionState) | 83 void InlineStylePropertyMap::append(CSSPropertyID propertyID, StyleValueOrStyleV
alueSequenceOrString& item, ExceptionState& exceptionState) |
104 { | 84 { |
105 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { | 85 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
106 exceptionState.throwTypeError("Property does not support multiple values
"); | 86 exceptionState.throwTypeError("Property does not support multiple values
"); |
107 return; | 87 return; |
108 } | 88 } |
109 | 89 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); | 123 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); |
144 } | 124 } |
145 | 125 |
146 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex
ceptionState) | 126 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex
ceptionState) |
147 { | 127 { |
148 m_ownerElement->removeInlineStyleProperty(propertyID); | 128 m_ownerElement->removeInlineStyleProperty(propertyID); |
149 } | 129 } |
150 | 130 |
151 } // namespace blink | 131 } // namespace blink |
152 | 132 |
OLD | NEW |