| 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/cssom/CSSSimpleLength.h" | 8 #include "core/css/cssom/CSSSimpleLength.h" |
| 9 #include "core/css/cssom/StyleValue.h" | 9 #include "core/css/cssom/CSSStyleValue.h" |
| 10 #include "core/css/cssom/StyleValueFactory.h" | 10 #include "core/css/cssom/StyleValueFactory.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 StyleValue* StylePropertyMap::get(const String& propertyName, ExceptionState& ex
ceptionState) | 14 CSSStyleValue* StylePropertyMap::get(const String& propertyName, ExceptionState&
exceptionState) |
| 15 { | 15 { |
| 16 CSSPropertyID propertyID = cssPropertyID(propertyName); | 16 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 17 if (propertyID == CSSPropertyInvalid) { | 17 if (propertyID == CSSPropertyInvalid) { |
| 18 // TODO(meade): Handle custom properties here. | 18 // TODO(meade): Handle custom properties here. |
| 19 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 19 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| 20 return nullptr; | 20 return nullptr; |
| 21 } | 21 } |
| 22 | 22 |
| 23 StyleValueVector styleVector = getAll(propertyID); | 23 StyleValueVector styleVector = getAll(propertyID); |
| 24 if (styleVector.isEmpty()) | 24 if (styleVector.isEmpty()) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 42 { | 42 { |
| 43 CSSPropertyID propertyID = cssPropertyID(propertyName); | 43 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 44 if (propertyID != CSSPropertyInvalid) | 44 if (propertyID != CSSPropertyInvalid) |
| 45 return has(propertyID); | 45 return has(propertyID); |
| 46 | 46 |
| 47 // TODO(meade): Handle custom properties here. | 47 // TODO(meade): Handle custom properties here. |
| 48 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 48 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| 49 return false; | 49 return false; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void StylePropertyMap::set(const String& propertyName, StyleValueOrStyleValueSeq
uenceOrString& item, ExceptionState& exceptionState) | 52 void StylePropertyMap::set(const String& propertyName, CSSStyleValueOrCSSStyleVa
lueSequenceOrString& item, ExceptionState& exceptionState) |
| 53 { | 53 { |
| 54 CSSPropertyID propertyID = cssPropertyID(propertyName); | 54 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 55 if (propertyID != CSSPropertyInvalid) { | 55 if (propertyID != CSSPropertyInvalid) { |
| 56 set(propertyID, item, exceptionState); | 56 set(propertyID, item, exceptionState); |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 // TODO(meade): Handle custom properties here. | 59 // TODO(meade): Handle custom properties here. |
| 60 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 60 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void StylePropertyMap::append(const String& propertyName, StyleValueOrStyleValue
SequenceOrString& item, ExceptionState& exceptionState) | 63 void StylePropertyMap::append(const String& propertyName, CSSStyleValueOrCSSStyl
eValueSequenceOrString& item, ExceptionState& exceptionState) |
| 64 { | 64 { |
| 65 CSSPropertyID propertyID = cssPropertyID(propertyName); | 65 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 66 if (propertyID != CSSPropertyInvalid) { | 66 if (propertyID != CSSPropertyInvalid) { |
| 67 append(propertyID, item, exceptionState); | 67 append(propertyID, item, exceptionState); |
| 68 return; | 68 return; |
| 69 } | 69 } |
| 70 // TODO(meade): Handle custom properties here. | 70 // TODO(meade): Handle custom properties here. |
| 71 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 71 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void StylePropertyMap::remove(const String& propertyName, ExceptionState& except
ionState) | 74 void StylePropertyMap::remove(const String& propertyName, ExceptionState& except
ionState) |
| 75 { | 75 { |
| 76 CSSPropertyID propertyID = cssPropertyID(propertyName); | 76 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 77 if (propertyID != CSSPropertyInvalid) { | 77 if (propertyID != CSSPropertyInvalid) { |
| 78 remove(propertyID, exceptionState); | 78 remove(propertyID, exceptionState); |
| 79 return; | 79 return; |
| 80 } | 80 } |
| 81 // TODO(meade): Handle custom properties here. | 81 // TODO(meade): Handle custom properties here. |
| 82 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 82 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| 83 } | 83 } |
| 84 | 84 |
| 85 StylePropertyMap::StyleValueVector StylePropertyMap::cssValueToStyleValueVector(
CSSPropertyID propertyID, const CSSValue& cssValue) | 85 StylePropertyMap::StyleValueVector StylePropertyMap::cssValueToStyleValueVector(
CSSPropertyID propertyID, const CSSValue& cssValue) |
| 86 { | 86 { |
| 87 StyleValueVector styleValueVector; | 87 StyleValueVector styleValueVector; |
| 88 | 88 |
| 89 if (!cssValue.isValueList()) { | 89 if (!cssValue.isValueList()) { |
| 90 StyleValue* styleValue = StyleValueFactory::create(propertyID, cssValue)
; | 90 CSSStyleValue* styleValue = StyleValueFactory::create(propertyID, cssVal
ue); |
| 91 if (styleValue) | 91 if (styleValue) |
| 92 styleValueVector.append(styleValue); | 92 styleValueVector.append(styleValue); |
| 93 return styleValueVector; | 93 return styleValueVector; |
| 94 } | 94 } |
| 95 | 95 |
| 96 for (CSSValue* value : *toCSSValueList(&cssValue)) { | 96 for (CSSValue* value : *toCSSValueList(&cssValue)) { |
| 97 StyleValue* styleValue = StyleValueFactory::create(propertyID, *value); | 97 CSSStyleValue* styleValue = StyleValueFactory::create(propertyID, *value
); |
| 98 if (!styleValue) | 98 if (!styleValue) |
| 99 return StyleValueVector(); | 99 return StyleValueVector(); |
| 100 styleValueVector.append(styleValue); | 100 styleValueVector.append(styleValue); |
| 101 } | 101 } |
| 102 return styleValueVector; | 102 return styleValueVector; |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |