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

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

Issue 2695093007: [Typed CSSOM] Get computed values for custom properties
Patch Set: Fix unregistered props and registered but unset props 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
« no previous file with comments | « third_party/WebKit/Source/core/css/cssom/StylePropertyMap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<StylePropertyMap::StylePropertyMapEntry> m_values;
48 }; 48 };
49 49
50 } // namespace 50 } // namespace
51 51
52 CSSStyleValue* StylePropertyMap::get(const String& propertyName, 52 CSSStyleValue* StylePropertyMap::get(const String& propertyName,
53 ExceptionState& exceptionState) { 53 ExceptionState& exceptionState) {
54 CSSPropertyID propertyID = cssPropertyID(propertyName); 54 CSSStyleValueVector styleVector = getAll(propertyName, exceptionState);
55 if (propertyID == CSSPropertyInvalid || propertyID == CSSPropertyVariable) { 55 return styleVector.isEmpty() ? nullptr : styleVector[0];
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 } 56 }
67 57
68 CSSStyleValueVector StylePropertyMap::getAll(const String& propertyName, 58 CSSStyleValueVector StylePropertyMap::getAll(const String& propertyName,
69 ExceptionState& exceptionState) { 59 ExceptionState& exceptionState) {
70 CSSPropertyID propertyID = cssPropertyID(propertyName); 60 CSSPropertyID propertyID = cssPropertyID(propertyName);
71 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) 61 if (propertyID == CSSPropertyInvalid) {
72 return getAllInternal(propertyID); 62 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
73 63 return CSSStyleValueVector();
74 // TODO(meade): Handle custom properties here. 64 }
75 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); 65 if (propertyID == CSSPropertyVariable) {
76 return CSSStyleValueVector(); 66 return getAllInternal(AtomicString(propertyName), exceptionState);
67 }
68 return getAllInternal(propertyID);
77 } 69 }
78 70
79 bool StylePropertyMap::has(const String& propertyName, 71 bool StylePropertyMap::has(const String& propertyName,
80 ExceptionState& exceptionState) { 72 ExceptionState& exceptionState) {
81 CSSPropertyID propertyID = cssPropertyID(propertyName); 73 return !getAll(propertyName, exceptionState).isEmpty();
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 } 74 }
89 75
90 void StylePropertyMap::set(const String& propertyName, 76 void StylePropertyMap::set(const String& propertyName,
91 CSSStyleValueOrCSSStyleValueSequenceOrString& item, 77 CSSStyleValueOrCSSStyleValueSequenceOrString& item,
92 ExceptionState& exceptionState) { 78 ExceptionState& exceptionState) {
93 CSSPropertyID propertyID = cssPropertyID(propertyName); 79 CSSPropertyID propertyID = cssPropertyID(propertyName);
94 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) { 80 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) {
95 set(propertyID, item, exceptionState); 81 set(propertyID, item, exceptionState);
96 return; 82 return;
97 } 83 }
(...skipping 25 matching lines...) Expand all
123 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); 109 exceptionState.throwTypeError("Invalid propertyName: " + propertyName);
124 } 110 }
125 111
126 StylePropertyMap::IterationSource* StylePropertyMap::startIteration( 112 StylePropertyMap::IterationSource* StylePropertyMap::startIteration(
127 ScriptState*, 113 ScriptState*,
128 ExceptionState&) { 114 ExceptionState&) {
129 return new StylePropertyMapIterationSource(getIterationEntries()); 115 return new StylePropertyMapIterationSource(getIterationEntries());
130 } 116 }
131 117
132 } // namespace blink 118 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/cssom/StylePropertyMap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698