| 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/StylePropertyMapReadonly.h" | 5 #include "core/css/cssom/StylePropertyMapReadonly.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 Loading... |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 size_t index_; | 46 size_t index_; |
| 47 const HeapVector<StylePropertyMapReadonly::StylePropertyMapEntry> values_; | 47 const HeapVector<StylePropertyMapReadonly::StylePropertyMapEntry> values_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 CSSStyleValue* StylePropertyMapReadonly::get(const String& property_name, | 52 CSSStyleValue* StylePropertyMapReadonly::get(const String& property_name, |
| 53 ExceptionState& exception_state) { | 53 ExceptionState& exception_state) { |
| 54 CSSPropertyID property_id = cssPropertyID(property_name); | 54 CSSStyleValueVector style_vector = getAll(property_name, exception_state); |
| 55 if (property_id == CSSPropertyInvalid || property_id == CSSPropertyVariable) { | 55 return style_vector.IsEmpty() ? nullptr : style_vector[0]; |
| 56 // TODO(meade): Handle custom properties here. | |
| 57 exception_state.ThrowTypeError("Invalid propertyName: " + property_name); | |
| 58 return nullptr; | |
| 59 } | |
| 60 | |
| 61 CSSStyleValueVector style_vector = GetAllInternal(property_id); | |
| 62 if (style_vector.IsEmpty()) | |
| 63 return nullptr; | |
| 64 | |
| 65 return style_vector[0]; | |
| 66 } | 56 } |
| 67 | 57 |
| 68 CSSStyleValueVector StylePropertyMapReadonly::getAll( | 58 CSSStyleValueVector StylePropertyMapReadonly::getAll( |
| 69 const String& property_name, | 59 const String& property_name, |
| 70 ExceptionState& exception_state) { | 60 ExceptionState& exception_state) { |
| 71 CSSPropertyID property_id = cssPropertyID(property_name); | 61 CSSPropertyID property_id = cssPropertyID(property_name); |
| 72 if (property_id != CSSPropertyInvalid && property_id != CSSPropertyVariable) | 62 if (property_id == CSSPropertyInvalid) |
| 73 return GetAllInternal(property_id); | 63 exception_state.ThrowTypeError("Invalid propertyName: " + property_name); |
| 74 | 64 if (property_id == CSSPropertyVariable) |
| 75 // TODO(meade): Handle custom properties here. | 65 return GetAllInternal(AtomicString(property_name)); |
| 76 exception_state.ThrowTypeError("Invalid propertyName: " + property_name); | 66 return GetAllInternal(property_id); |
| 77 return CSSStyleValueVector(); | |
| 78 } | 67 } |
| 79 | 68 |
| 80 bool StylePropertyMapReadonly::has(const String& property_name, | 69 bool StylePropertyMapReadonly::has(const String& property_name, |
| 81 ExceptionState& exception_state) { | 70 ExceptionState& exception_state) { |
| 82 CSSPropertyID property_id = cssPropertyID(property_name); | 71 return !getAll(property_name, exception_state).IsEmpty(); |
| 83 if (property_id != CSSPropertyInvalid && property_id != CSSPropertyVariable) | |
| 84 return !GetAllInternal(property_id).IsEmpty(); | |
| 85 | |
| 86 // TODO(meade): Handle custom properties here. | |
| 87 exception_state.ThrowTypeError("Invalid propertyName: " + property_name); | |
| 88 return false; | |
| 89 } | 72 } |
| 90 | 73 |
| 91 StylePropertyMapReadonly::IterationSource* | 74 StylePropertyMapReadonly::IterationSource* |
| 92 StylePropertyMapReadonly::StartIteration(ScriptState*, ExceptionState&) { | 75 StylePropertyMapReadonly::StartIteration(ScriptState*, ExceptionState&) { |
| 93 return new StylePropertyMapIterationSource(GetIterationEntries()); | 76 return new StylePropertyMapIterationSource(GetIterationEntries()); |
| 94 } | 77 } |
| 95 | 78 |
| 96 } // namespace blink | 79 } // namespace blink |
| OLD | NEW |