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" |
(...skipping 21 matching lines...) Expand all Loading... |
32 { | 32 { |
33 Vector<String> result; | 33 Vector<String> result; |
34 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); | 34 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle(
); |
35 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { | 35 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { |
36 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); | 36 CSSPropertyID propertyID = inlineStyleSet.propertyAt(i).id(); |
37 result.append(getPropertyNameString(propertyID)); | 37 result.append(getPropertyNameString(propertyID)); |
38 } | 38 } |
39 return result; | 39 return result; |
40 } | 40 } |
41 | 41 |
42 void InlineStylePropertyMap::set(CSSPropertyID propertyID, StyleValueOrStyleValu
eSequenceOrString& item, ExceptionState& exceptionState) | 42 void InlineStylePropertyMap::set(CSSPropertyID propertyID, CSSStyleValueOrCSSSty
leValueSequenceOrString& item, ExceptionState& exceptionState) |
43 { | 43 { |
44 if (item.isStyleValue()) { | 44 if (item.isCSSStyleValue()) { |
45 StyleValue* styleValue = item.getAsStyleValue(); | 45 CSSStyleValue* styleValue = item.getAsCSSStyleValue(); |
46 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { | 46 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { |
47 exceptionState.throwTypeError("Invalid type for property"); | 47 exceptionState.throwTypeError("Invalid type for property"); |
48 return; | 48 return; |
49 } | 49 } |
50 m_ownerElement->setInlineStyleProperty(propertyID, styleValue->toCSSValu
e()); | 50 m_ownerElement->setInlineStyleProperty(propertyID, styleValue->toCSSValu
e()); |
51 } else if (item.isStyleValueSequence()) { | 51 } else if (item.isCSSStyleValueSequence()) { |
52 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { | 52 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
53 exceptionState.throwTypeError("Property does not support multiple va
lues"); | 53 exceptionState.throwTypeError("Property does not support multiple va
lues"); |
54 return; | 54 return; |
55 } | 55 } |
56 | 56 |
57 // TODO(meade): This won't always work. Figure out what kind of CSSValue
List to create properly. | 57 // TODO(meade): This won't always work. Figure out what kind of CSSValue
List to create properly. |
58 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); | 58 CSSValueList* valueList = CSSValueList::createSpaceSeparated(); |
59 StyleValueVector styleValueVector = item.getAsStyleValueSequence(); | 59 StyleValueVector styleValueVector = item.getAsCSSStyleValueSequence(); |
60 for (const Member<StyleValue> value : styleValueVector) { | 60 for (const Member<CSSStyleValue> value : styleValueVector) { |
61 if (!CSSOMTypes::propertyCanTake(propertyID, *value)) { | 61 if (!CSSOMTypes::propertyCanTake(propertyID, *value)) { |
62 exceptionState.throwTypeError("Invalid type for property"); | 62 exceptionState.throwTypeError("Invalid type for property"); |
63 return; | 63 return; |
64 } | 64 } |
65 valueList->append(value->toCSSValue()); | 65 valueList->append(value->toCSSValue()); |
66 } | 66 } |
67 | 67 |
68 m_ownerElement->setInlineStyleProperty(propertyID, valueList); | 68 m_ownerElement->setInlineStyleProperty(propertyID, valueList); |
69 } else { | 69 } else { |
70 // Parse it. | 70 // Parse it. |
71 ASSERT(item.isString()); | 71 ASSERT(item.isString()); |
72 // TODO(meade): Implement this. | 72 // TODO(meade): Implement this. |
73 exceptionState.throwTypeError("Not implemented yet"); | 73 exceptionState.throwTypeError("Not implemented yet"); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 void InlineStylePropertyMap::append(CSSPropertyID propertyID, StyleValueOrStyleV
alueSequenceOrString& item, ExceptionState& exceptionState) | 77 void InlineStylePropertyMap::append(CSSPropertyID propertyID, CSSStyleValueOrCSS
StyleValueSequenceOrString& item, ExceptionState& exceptionState) |
78 { | 78 { |
79 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { | 79 if (!CSSPropertyMetadata::propertySupportsMultiple(propertyID)) { |
80 exceptionState.throwTypeError("Property does not support multiple values
"); | 80 exceptionState.throwTypeError("Property does not support multiple values
"); |
81 return; | 81 return; |
82 } | 82 } |
83 | 83 |
84 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC
SSValue(propertyID); | 84 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC
SSValue(propertyID); |
85 CSSValueList* cssValueList = nullptr; | 85 CSSValueList* cssValueList = nullptr; |
86 if (cssValue->isValueList()) { | 86 if (cssValue->isValueList()) { |
87 cssValueList = toCSSValueList(cssValue); | 87 cssValueList = toCSSValueList(cssValue); |
88 } else { | 88 } else { |
89 // TODO(meade): Figure out what the correct behaviour here is. | 89 // TODO(meade): Figure out what the correct behaviour here is. |
90 exceptionState.throwTypeError("Property is not already list valued"); | 90 exceptionState.throwTypeError("Property is not already list valued"); |
91 return; | 91 return; |
92 } | 92 } |
93 | 93 |
94 if (item.isStyleValue()) { | 94 if (item.isCSSStyleValue()) { |
95 StyleValue* styleValue = item.getAsStyleValue(); | 95 CSSStyleValue* styleValue = item.getAsCSSStyleValue(); |
96 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { | 96 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { |
97 exceptionState.throwTypeError("Invalid type for property"); | 97 exceptionState.throwTypeError("Invalid type for property"); |
98 return; | 98 return; |
99 } | 99 } |
100 cssValueList->append(item.getAsStyleValue()->toCSSValue()); | 100 cssValueList->append(item.getAsCSSStyleValue()->toCSSValue()); |
101 } else if (item.isStyleValueSequence()) { | 101 } else if (item.isCSSStyleValueSequence()) { |
102 for (StyleValue* styleValue : item.getAsStyleValueSequence()) { | 102 for (CSSStyleValue* styleValue : item.getAsCSSStyleValueSequence()) { |
103 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { | 103 if (!CSSOMTypes::propertyCanTake(propertyID, *styleValue)) { |
104 exceptionState.throwTypeError("Invalid type for property"); | 104 exceptionState.throwTypeError("Invalid type for property"); |
105 return; | 105 return; |
106 } | 106 } |
107 cssValueList->append(styleValue->toCSSValue()); | 107 cssValueList->append(styleValue->toCSSValue()); |
108 } | 108 } |
109 } else { | 109 } else { |
110 // Parse it. | 110 // Parse it. |
111 ASSERT(item.isString()); | 111 ASSERT(item.isString()); |
112 // TODO(meade): Implement this. | 112 // TODO(meade): Implement this. |
113 exceptionState.throwTypeError("Not implemented yet"); | 113 exceptionState.throwTypeError("Not implemented yet"); |
114 return; | 114 return; |
115 } | 115 } |
116 | 116 |
117 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); | 117 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); |
118 } | 118 } |
119 | 119 |
120 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex
ceptionState) | 120 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex
ceptionState) |
121 { | 121 { |
122 m_ownerElement->removeInlineStyleProperty(propertyID); | 122 m_ownerElement->removeInlineStyleProperty(propertyID); |
123 } | 123 } |
124 | 124 |
125 } // namespace blink | 125 } // namespace blink |
126 | 126 |
OLD | NEW |