| 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/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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 CSSStyleValue* StylePropertyMap::get(const String& propertyName, ExceptionState&
exceptionState) | 49 CSSStyleValue* StylePropertyMap::get(const String& propertyName, ExceptionState&
exceptionState) |
| 50 { | 50 { |
| 51 CSSPropertyID propertyID = cssPropertyID(propertyName); | 51 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 52 if (propertyID == CSSPropertyInvalid) { | 52 if (propertyID == CSSPropertyInvalid) { |
| 53 // TODO(meade): Handle custom properties here. | 53 // TODO(meade): Handle custom properties here. |
| 54 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 54 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| 55 return nullptr; | 55 return nullptr; |
| 56 } | 56 } |
| 57 | 57 |
| 58 StyleValueVector styleVector = getAll(propertyID); | 58 CSSStyleValueVector styleVector = getAll(propertyID); |
| 59 if (styleVector.isEmpty()) | 59 if (styleVector.isEmpty()) |
| 60 return nullptr; | 60 return nullptr; |
| 61 | 61 |
| 62 return styleVector[0]; | 62 return styleVector[0]; |
| 63 } | 63 } |
| 64 | 64 |
| 65 StylePropertyMap::StyleValueVector StylePropertyMap::getAll(const String& proper
tyName, ExceptionState& exceptionState) | 65 CSSStyleValueVector StylePropertyMap::getAll(const String& propertyName, Excepti
onState& exceptionState) |
| 66 { | 66 { |
| 67 CSSPropertyID propertyID = cssPropertyID(propertyName); | 67 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 68 if (propertyID != CSSPropertyInvalid) | 68 if (propertyID != CSSPropertyInvalid) |
| 69 return getAll(propertyID); | 69 return getAll(propertyID); |
| 70 | 70 |
| 71 // TODO(meade): Handle custom properties here. | 71 // TODO(meade): Handle custom properties here. |
| 72 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 72 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| 73 return StyleValueVector(); | 73 return CSSStyleValueVector(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool StylePropertyMap::has(const String& propertyName, ExceptionState& exception
State) | 76 bool StylePropertyMap::has(const String& propertyName, ExceptionState& exception
State) |
| 77 { | 77 { |
| 78 CSSPropertyID propertyID = cssPropertyID(propertyName); | 78 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 79 if (propertyID != CSSPropertyInvalid) | 79 if (propertyID != CSSPropertyInvalid) |
| 80 return !getAll(propertyID).isEmpty(); | 80 return !getAll(propertyID).isEmpty(); |
| 81 | 81 |
| 82 // TODO(meade): Handle custom properties here. | 82 // TODO(meade): Handle custom properties here. |
| 83 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 83 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 110 { | 110 { |
| 111 CSSPropertyID propertyID = cssPropertyID(propertyName); | 111 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 112 if (propertyID != CSSPropertyInvalid) { | 112 if (propertyID != CSSPropertyInvalid) { |
| 113 remove(propertyID, exceptionState); | 113 remove(propertyID, exceptionState); |
| 114 return; | 114 return; |
| 115 } | 115 } |
| 116 // TODO(meade): Handle custom properties here. | 116 // TODO(meade): Handle custom properties here. |
| 117 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 117 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| 118 } | 118 } |
| 119 | 119 |
| 120 StylePropertyMap::StyleValueVector StylePropertyMap::cssValueToStyleValueVector(
CSSPropertyID propertyID, const CSSValue& cssValue) | |
| 121 { | |
| 122 StyleValueVector styleValueVector; | |
| 123 | |
| 124 if (!cssValue.isValueList()) { | |
| 125 CSSStyleValue* styleValue = StyleValueFactory::create(propertyID, cssVal
ue); | |
| 126 if (styleValue) | |
| 127 styleValueVector.append(styleValue); | |
| 128 return styleValueVector; | |
| 129 } | |
| 130 | |
| 131 for (const CSSValue* value : toCSSValueList(cssValue)) { | |
| 132 CSSStyleValue* styleValue = StyleValueFactory::create(propertyID, *value
); | |
| 133 if (!styleValue) | |
| 134 return StyleValueVector(); | |
| 135 styleValueVector.append(styleValue); | |
| 136 } | |
| 137 return styleValueVector; | |
| 138 } | |
| 139 | |
| 140 StylePropertyMap::IterationSource* StylePropertyMap::startIteration(ScriptState*
, ExceptionState&) | 120 StylePropertyMap::IterationSource* StylePropertyMap::startIteration(ScriptState*
, ExceptionState&) |
| 141 { | 121 { |
| 142 return new StylePropertyMapIterationSource(getIterationEntries()); | 122 return new StylePropertyMapIterationSource(getIterationEntries()); |
| 143 } | 123 } |
| 144 | 124 |
| 145 } // namespace blink | 125 } // namespace blink |
| OLD | NEW |