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 "bindings/core/v8/Iterable.h" | |
7 #include "core/CSSPropertyNames.h" | 8 #include "core/CSSPropertyNames.h" |
8 #include "core/css/CSSPrimitiveValue.h" | 9 #include "core/css/CSSPrimitiveValue.h" |
9 #include "core/css/CSSPropertyMetadata.h" | 10 #include "core/css/CSSPropertyMetadata.h" |
10 #include "core/css/CSSValueList.h" | 11 #include "core/css/CSSValueList.h" |
11 #include "core/css/StylePropertySet.h" | 12 #include "core/css/StylePropertySet.h" |
12 #include "core/css/cssom/CSSOMTypes.h" | 13 #include "core/css/cssom/CSSOMTypes.h" |
13 #include "core/css/cssom/SimpleLength.h" | 14 #include "core/css/cssom/SimpleLength.h" |
14 #include "core/css/cssom/StyleValueFactory.h" | 15 #include "core/css/cssom/StyleValueFactory.h" |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
18 StyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID propertyID) | 19 namespace { |
20 | |
21 class InlineStylePropertyMapIterationSource final : public PairIterable<String, StyleValueOrStyleValueSequence>::IterationSource { | |
22 public: | |
23 explicit InlineStylePropertyMapIterationSource(HeapVector<std::pair<String, StyleValueOrStyleValueSequence>> values) | |
Timothy Loh
2016/04/15 05:27:53
let's just make a using declaration for the pair s
meade_UTC10
2016/04/27 05:39:01
Done.
| |
24 : m_index(0) | |
25 , m_values(values) | |
26 { | |
27 } | |
28 | |
29 bool next(ScriptState*, String& key, StyleValueOrStyleValueSequence& value, ExceptionState&) override | |
30 { | |
31 if (m_index >= m_values.size()) | |
32 return false; | |
33 | |
34 std::pair<String, StyleValueOrStyleValueSequence> pair = m_values.at(m_i ndex++); | |
35 key = pair.first; | |
36 value = pair.second; | |
37 return true; | |
38 } | |
39 | |
40 DEFINE_INLINE_VIRTUAL_TRACE() | |
41 { | |
42 visitor->trace(m_values); | |
43 PairIterable<String, StyleValueOrStyleValueSequence>::IterationSource::t race(visitor); | |
44 } | |
45 | |
46 private: | |
47 size_t m_index; | |
48 const HeapVector<std::pair<String, StyleValueOrStyleValueSequence>> m_values ; | |
49 }; | |
50 | |
51 } // namespace | |
52 | |
53 StylePropertyMap::StyleValueVector InlineStylePropertyMap::getAll(CSSPropertyID propertyID) | |
19 { | 54 { |
20 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID); | 55 CSSValue* cssValue = m_ownerElement->ensureMutableInlineStyle().getPropertyC SSValue(propertyID); |
21 if (!cssValue) | 56 if (!cssValue) |
22 return StyleValueVector(); | 57 return StyleValueVector(); |
23 | 58 |
24 return cssValueToStyleValueVector(propertyID, *cssValue); | 59 return cssValueToStyleValueVector(propertyID, *cssValue); |
25 } | 60 } |
26 | 61 |
27 bool InlineStylePropertyMap::has(CSSPropertyID propertyID) | 62 bool InlineStylePropertyMap::has(CSSPropertyID propertyID) |
28 { | 63 { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 } | 156 } |
122 | 157 |
123 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); | 158 m_ownerElement->setInlineStyleProperty(propertyID, cssValueList); |
124 } | 159 } |
125 | 160 |
126 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex ceptionState) | 161 void InlineStylePropertyMap::remove(CSSPropertyID propertyID, ExceptionState& ex ceptionState) |
127 { | 162 { |
128 m_ownerElement->removeInlineStyleProperty(propertyID); | 163 m_ownerElement->removeInlineStyleProperty(propertyID); |
129 } | 164 } |
130 | 165 |
166 InlineStylePropertyMap::IterationSource* InlineStylePropertyMap::startIteration( ScriptState* scriptState, ExceptionState& exceptionState) | |
Timothy Loh
2016/04/15 05:27:53
can we make something that works for all the maps?
meade_UTC10
2016/04/27 05:39:01
Done.
| |
167 { | |
168 HeapVector<std::pair<String, StyleValueOrStyleValueSequence>> result; | |
169 StylePropertySet& inlineStyleSet = m_ownerElement->ensureMutableInlineStyle( ); | |
170 for (unsigned i = 0; i < inlineStyleSet.propertyCount(); i++) { | |
171 StylePropertySet::PropertyReference propertyReference = inlineStyleSet.p ropertyAt(i); | |
172 CSSPropertyID propertyID = propertyReference.id(); | |
173 StyleValueVector styleValueVector = cssValueToStyleValueVector(propertyI D, *propertyReference.value()); | |
174 StyleValueOrStyleValueSequence value; | |
175 if (styleValueVector.size() == 1) | |
176 value.setStyleValue(styleValueVector[0]); | |
177 else | |
178 value.setStyleValueSequence(styleValueVector); | |
179 result.append(std::make_pair(getPropertyNameString(propertyID), value)); | |
180 } | |
181 return new InlineStylePropertyMapIterationSource(result); | |
182 } | |
183 | |
131 } // namespace blink | 184 } // namespace blink |
132 | 185 |
OLD | NEW |