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

Side by Side Diff: third_party/WebKit/Source/core/css/cssom/StylePropertyMap.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/StylePropertyMap.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 {
16
17 class StylePropertyMapIterationSource final
18 : public PairIterable<String, CSSStyleValueOrCSSStyleValueSequence>::
19 IterationSource {
20 public:
21 explicit StylePropertyMapIterationSource(
22 HeapVector<StylePropertyMap::StylePropertyMapEntry> values)
23 : m_index(0), m_values(values) {}
24
25 bool next(ScriptState*,
26 String& key,
27 CSSStyleValueOrCSSStyleValueSequence& value,
28 ExceptionState&) override {
29 if (m_index >= m_values.size())
30 return false;
31
32 const StylePropertyMap::StylePropertyMapEntry& pair =
33 m_values.at(m_index++);
34 key = pair.first;
35 value = pair.second;
36 return true;
37 }
38
39 DEFINE_INLINE_VIRTUAL_TRACE() {
40 visitor->trace(m_values);
41 PairIterable<String, CSSStyleValueOrCSSStyleValueSequence>::
42 IterationSource::trace(visitor);
43 }
44
45 private:
46 size_t m_index;
47 const HeapVector<StylePropertyMap::StylePropertyMapEntry> m_values;
48 };
49
50 } // namespace
51
52 CSSStyleValue* StylePropertyMap::get(const String& propertyName,
53 ExceptionState& exceptionState) {
54 CSSPropertyID propertyID = cssPropertyID(propertyName);
55 if (propertyID == CSSPropertyInvalid || propertyID == CSSPropertyVariable) {
56 // TODO(meade): Handle custom properties here.
57 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
58 return nullptr;
59 }
60
61 CSSStyleValueVector styleVector = getAllInternal(propertyID);
62 if (styleVector.isEmpty())
63 return nullptr;
64
65 return styleVector[0];
66 }
67
68 CSSStyleValueVector StylePropertyMap::getAll(const String& propertyName,
69 ExceptionState& exceptionState) {
70 CSSPropertyID propertyID = cssPropertyID(propertyName);
71 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable)
72 return getAllInternal(propertyID);
73
74 // TODO(meade): Handle custom properties here.
75 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
76 return CSSStyleValueVector();
77 }
78
79 bool StylePropertyMap::has(const String& propertyName,
80 ExceptionState& exceptionState) {
81 CSSPropertyID propertyID = cssPropertyID(propertyName);
82 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable)
83 return !getAllInternal(propertyID).isEmpty();
84
85 // TODO(meade): Handle custom properties here.
86 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
87 return false;
88 }
89
90 void StylePropertyMap::set(const String& propertyName, 15 void StylePropertyMap::set(const String& propertyName,
91 CSSStyleValueOrCSSStyleValueSequenceOrString& item, 16 CSSStyleValueOrCSSStyleValueSequenceOrString& item,
92 ExceptionState& exceptionState) { 17 ExceptionState& exceptionState) {
93 CSSPropertyID propertyID = cssPropertyID(propertyName); 18 CSSPropertyID propertyID = cssPropertyID(propertyName);
94 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) { 19 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) {
95 set(propertyID, item, exceptionState); 20 set(propertyID, item, exceptionState);
96 return; 21 return;
97 } 22 }
98 // TODO(meade): Handle custom properties here. 23 // TODO(meade): Handle custom properties here.
99 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); 24 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
(...skipping 16 matching lines...) Expand all
116 ExceptionState& exceptionState) { 41 ExceptionState& exceptionState) {
117 CSSPropertyID propertyID = cssPropertyID(propertyName); 42 CSSPropertyID propertyID = cssPropertyID(propertyName);
118 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) { 43 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) {
119 remove(propertyID, exceptionState); 44 remove(propertyID, exceptionState);
120 return; 45 return;
121 } 46 }
122 // TODO(meade): Handle custom properties here. 47 // TODO(meade): Handle custom properties here.
123 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); 48 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
124 } 49 }
125 50
126 StylePropertyMap::IterationSource* StylePropertyMap::startIteration(
127 ScriptState*,
128 ExceptionState&) {
129 return new StylePropertyMapIterationSource(getIterationEntries());
130 }
131
132 } // namespace blink 51 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698