Chromium Code Reviews| 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/SimpleLength.h" | 8 #include "core/css/cssom/SimpleLength.h" |
| 9 #include "core/css/cssom/StyleValue.h" | 9 #include "core/css/cssom/StyleValue.h" |
| 10 #include "core/css/cssom/StyleValueFactory.h" | |
| 10 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 StyleValue* StylePropertyMap::get(const String& propertyName, ExceptionState& ex ceptionState) | 14 StyleValue* StylePropertyMap::get(const String& propertyName, ExceptionState& ex ceptionState) |
| 14 { | 15 { |
| 15 CSSPropertyID propertyID = cssPropertyID(propertyName); | 16 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 16 if (propertyID != CSSPropertyInvalid) | 17 if (propertyID == CSSPropertyInvalid) { |
| 17 return get(propertyID); | 18 // TODO(meade): Handle custom properties here. |
| 19 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | |
| 20 return nullptr; | |
| 21 } | |
| 18 | 22 |
| 19 // TODO(meade): Handle custom properties here. | 23 StyleValueVector styleVector = getAll(propertyID); |
| 20 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 24 if (styleVector.isEmpty()) |
| 21 return nullptr; | 25 return nullptr; |
| 26 | |
| 27 return styleVector.at(0); | |
| 22 } | 28 } |
| 23 | 29 |
| 24 HeapVector<Member<StyleValue>> StylePropertyMap::getAll(const String& propertyNa me, ExceptionState& exceptionState) | 30 StylePropertyMap::StyleValueVector StylePropertyMap::getAll(const String& proper tyName, ExceptionState& exceptionState) |
| 25 { | 31 { |
| 26 CSSPropertyID propertyID = cssPropertyID(propertyName); | 32 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 27 if (propertyID != CSSPropertyInvalid) | 33 if (propertyID != CSSPropertyInvalid) |
| 28 return getAll(propertyID); | 34 return getAll(propertyID); |
| 29 | 35 |
| 30 // TODO(meade): Handle custom properties here. | 36 // TODO(meade): Handle custom properties here. |
| 31 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 37 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| 32 return HeapVector<Member<StyleValue>>(); | 38 return HeapVector<Member<StyleValue>>(); |
| 33 } | 39 } |
| 34 | 40 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 { | 75 { |
| 70 CSSPropertyID propertyID = cssPropertyID(propertyName); | 76 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 71 if (propertyID != CSSPropertyInvalid) { | 77 if (propertyID != CSSPropertyInvalid) { |
| 72 remove(propertyID, exceptionState); | 78 remove(propertyID, exceptionState); |
| 73 return; | 79 return; |
| 74 } | 80 } |
| 75 // TODO(meade): Handle custom properties here. | 81 // TODO(meade): Handle custom properties here. |
| 76 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 82 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| 77 } | 83 } |
| 78 | 84 |
| 85 StylePropertyMap::StyleValueVector StylePropertyMap::cssValueToStyleValueVector( CSSPropertyID propertyID, const CSSValue& cssValue) | |
|
Timothy Loh
2016/04/15 04:16:08
The part of the CL which just moves code around sh
| |
| 86 { | |
| 87 StyleValueVector styleValueVector; | |
| 88 | |
| 89 if (!cssValue.isValueList()) { | |
| 90 StyleValue* styleValue = StyleValueFactory::create(propertyID, cssValue) ; | |
| 91 if (styleValue) | |
| 92 styleValueVector.append(styleValue); | |
| 93 return styleValueVector; | |
| 94 } | |
| 95 | |
| 96 for (const Member<CSSValue> value : *toCSSValueList(&cssValue)) { | |
|
Timothy Loh
2016/04/15 04:16:08
Wasn't this CSSValue* previously?
| |
| 97 StyleValue* styleValue = StyleValueFactory::create(propertyID, *value); | |
| 98 if (!styleValue) | |
| 99 return StyleValueVector(); | |
| 100 styleValueVector.append(styleValue); | |
| 101 } | |
| 102 | |
| 103 return styleValueVector; | |
| 104 } | |
| 105 | |
| 79 } // namespace blink | 106 } // namespace blink |
| OLD | NEW |