| 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 m_index; | 46 size_t m_index; |
| 47 const HeapVector<StylePropertyMapReadonly::StylePropertyMapEntry> m_values; | 47 const HeapVector<StylePropertyMapReadonly::StylePropertyMapEntry> m_values; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 CSSStyleValue* StylePropertyMapReadonly::get(const String& propertyName, | 52 CSSStyleValue* StylePropertyMapReadonly::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 StylePropertyMapReadonly::getAll( | 58 CSSStyleValueVector StylePropertyMapReadonly::getAll( |
| 69 const String& propertyName, | 59 const String& propertyName, |
| 70 ExceptionState& exceptionState) { | 60 ExceptionState& exceptionState) { |
| 71 CSSPropertyID propertyID = cssPropertyID(propertyName); | 61 CSSPropertyID propertyID = cssPropertyID(propertyName); |
| 72 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) | 62 if (propertyID == CSSPropertyInvalid) { |
| 73 return getAllInternal(propertyID); | 63 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); |
| 74 | 64 return CSSStyleValueVector(); |
| 75 // TODO(meade): Handle custom properties here. | 65 } |
| 76 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | 66 if (propertyID == CSSPropertyVariable) |
| 77 return CSSStyleValueVector(); | 67 return getAllInternal(AtomicString(propertyName), exceptionState); |
| 68 return getAllInternal(propertyID); |
| 78 } | 69 } |
| 79 | 70 |
| 80 bool StylePropertyMapReadonly::has(const String& propertyName, | 71 bool StylePropertyMapReadonly::has(const String& propertyName, |
| 81 ExceptionState& exceptionState) { | 72 ExceptionState& exceptionState) { |
| 82 CSSPropertyID propertyID = cssPropertyID(propertyName); | 73 return !getAll(propertyName, exceptionState).isEmpty(); |
| 83 if (propertyID != CSSPropertyInvalid && propertyID != CSSPropertyVariable) | |
| 84 return !getAllInternal(propertyID).isEmpty(); | |
| 85 | |
| 86 // TODO(meade): Handle custom properties here. | |
| 87 exceptionState.throwTypeError("Invalid propertyName: " + propertyName); | |
| 88 return false; | |
| 89 } | 74 } |
| 90 | 75 |
| 91 StylePropertyMapReadonly::IterationSource* | 76 StylePropertyMapReadonly::IterationSource* |
| 92 StylePropertyMapReadonly::startIteration(ScriptState*, ExceptionState&) { | 77 StylePropertyMapReadonly::startIteration(ScriptState*, ExceptionState&) { |
| 93 return new StylePropertyMapIterationSource(getIterationEntries()); | 78 return new StylePropertyMapIterationSource(getIterationEntries()); |
| 94 } | 79 } |
| 95 | 80 |
| 96 } // namespace blink | 81 } // namespace blink |
| OLD | NEW |