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

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

Issue 2730633004: [CSS Typed OM] Rearrange StylePropertyMap classes to match the new spec. (Closed)
Patch Set: Remove spurious : Created 3 years, 9 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/StylePropertyMap.h" 5 #include "core/css/cssom/StylePropertyMapReadonly.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "core/css/CSSValueList.h" 8 #include "core/css/CSSValueList.h"
9 #include "core/css/cssom/CSSSimpleLength.h" 9 #include "core/css/cssom/CSSSimpleLength.h"
10 #include "core/css/cssom/CSSStyleValue.h" 10 #include "core/css/cssom/CSSStyleValue.h"
11 #include "core/css/cssom/StyleValueFactory.h" 11 #include "core/css/cssom/StyleValueFactory.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 namespace { 15 namespace {
16 16
17 class StylePropertyMapIterationSource final 17 class StylePropertyMapIterationSource final
18 : public PairIterable<String, CSSStyleValueOrCSSStyleValueSequence>:: 18 : public PairIterable<String, CSSStyleValueOrCSSStyleValueSequence>::
19 IterationSource { 19 IterationSource {
20 public: 20 public:
21 explicit StylePropertyMapIterationSource( 21 explicit StylePropertyMapIterationSource(
22 HeapVector<StylePropertyMap::StylePropertyMapEntry> values) 22 HeapVector<StylePropertyMapReadonly::StylePropertyMapEntry> values)
23 : m_index(0), m_values(values) {} 23 : m_index(0), m_values(values) {}
24 24
25 bool next(ScriptState*, 25 bool next(ScriptState*,
26 String& key, 26 String& key,
27 CSSStyleValueOrCSSStyleValueSequence& value, 27 CSSStyleValueOrCSSStyleValueSequence& value,
28 ExceptionState&) override { 28 ExceptionState&) override {
29 if (m_index >= m_values.size()) 29 if (m_index >= m_values.size())
30 return false; 30 return false;
31 31
32 const StylePropertyMap::StylePropertyMapEntry& pair = 32 const StylePropertyMapReadonly::StylePropertyMapEntry& pair =
33 m_values.at(m_index++); 33 m_values.at(m_index++);
34 key = pair.first; 34 key = pair.first;
35 value = pair.second; 35 value = pair.second;
36 return true; 36 return true;
37 } 37 }
38 38
39 DEFINE_INLINE_VIRTUAL_TRACE() { 39 DEFINE_INLINE_VIRTUAL_TRACE() {
40 visitor->trace(m_values); 40 visitor->trace(m_values);
41 PairIterable<String, CSSStyleValueOrCSSStyleValueSequence>:: 41 PairIterable<String, CSSStyleValueOrCSSStyleValueSequence>::
42 IterationSource::trace(visitor); 42 IterationSource::trace(visitor);
43 } 43 }
44 44
45 private: 45 private:
46 size_t m_index; 46 size_t m_index;
47 const HeapVector<StylePropertyMap::StylePropertyMapEntry> m_values; 47 const HeapVector<StylePropertyMapReadonly::StylePropertyMapEntry> m_values;
48 }; 48 };
49 49
50 } // namespace 50 } // namespace
51 51
52 CSSStyleValue* StylePropertyMap::get(const String& propertyName, 52 CSSStyleValue* StylePropertyMapReadonly::get(const String& propertyName,
53 ExceptionState& exceptionState) { 53 ExceptionState& exceptionState) {
54 CSSPropertyID propertyID = cssPropertyID(propertyName); 54 CSSPropertyID propertyID = cssPropertyID(propertyName);
55 if (propertyID == CSSPropertyInvalid || propertyID == CSSPropertyVariable) { 55 if (propertyID == CSSPropertyInvalid || propertyID == CSSPropertyVariable) {
56 // TODO(meade): Handle custom properties here. 56 // TODO(meade): Handle custom properties here.
57 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); 57 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
58 return nullptr; 58 return nullptr;
59 } 59 }
60 60
61 CSSStyleValueVector styleVector = getAllInternal(propertyID); 61 CSSStyleValueVector styleVector = getAllInternal(propertyID);
62 if (styleVector.isEmpty()) 62 if (styleVector.isEmpty())
63 return nullptr; 63 return nullptr;
64 64
65 return styleVector[0]; 65 return styleVector[0];
66 } 66 }
67 67
68 CSSStyleValueVector StylePropertyMap::getAll(const String& propertyName, 68 CSSStyleValueVector StylePropertyMapReadonly::getAll(
69 ExceptionState& exceptionState) { 69 const String& propertyName,
70 ExceptionState& exceptionState) {
70 CSSPropertyID propertyID = cssPropertyID(propertyName); 71 CSSPropertyID propertyID = cssPropertyID(propertyName);
71 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) 72 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable)
72 return getAllInternal(propertyID); 73 return getAllInternal(propertyID);
73 74
74 // TODO(meade): Handle custom properties here. 75 // TODO(meade): Handle custom properties here.
75 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); 76 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
76 return CSSStyleValueVector(); 77 return CSSStyleValueVector();
77 } 78 }
78 79
79 bool StylePropertyMap::has(const String& propertyName, 80 bool StylePropertyMapReadonly::has(const String& propertyName,
80 ExceptionState& exceptionState) { 81 ExceptionState& exceptionState) {
81 CSSPropertyID propertyID = cssPropertyID(propertyName); 82 CSSPropertyID propertyID = cssPropertyID(propertyName);
82 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) 83 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable)
83 return !getAllInternal(propertyID).isEmpty(); 84 return !getAllInternal(propertyID).isEmpty();
84 85
85 // TODO(meade): Handle custom properties here. 86 // TODO(meade): Handle custom properties here.
86 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); 87 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
87 return false; 88 return false;
88 } 89 }
89 90
90 void StylePropertyMap::set(const String& propertyName, 91 StylePropertyMapReadonly::IterationSource*
91 CSSStyleValueOrCSSStyleValueSequenceOrString& item, 92 StylePropertyMapReadonly::startIteration(ScriptState*, ExceptionState&) {
92 ExceptionState& exceptionState) {
93 CSSPropertyID propertyID = cssPropertyID(propertyName);
94 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) {
95 set(propertyID, item, exceptionState);
96 return;
97 }
98 // TODO(meade): Handle custom properties here.
99 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
100 }
101
102 void StylePropertyMap::append(
103 const String& propertyName,
104 CSSStyleValueOrCSSStyleValueSequenceOrString& item,
105 ExceptionState& exceptionState) {
106 CSSPropertyID propertyID = cssPropertyID(propertyName);
107 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) {
108 append(propertyID, item, exceptionState);
109 return;
110 }
111 // TODO(meade): Handle custom properties here.
112 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
113 }
114
115 void StylePropertyMap::remove(const String& propertyName,
116 ExceptionState& exceptionState) {
117 CSSPropertyID propertyID = cssPropertyID(propertyName);
118 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) {
119 remove(propertyID, exceptionState);
120 return;
121 }
122 // TODO(meade): Handle custom properties here.
123 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
124 }
125
126 StylePropertyMap::IterationSource* StylePropertyMap::startIteration(
127 ScriptState*,
128 ExceptionState&) {
129 return new StylePropertyMapIterationSource(getIterationEntries()); 93 return new StylePropertyMapIterationSource(getIterationEntries());
130 } 94 }
131 95
132 } // namespace blink 96 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698