| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef PropertyHandle_h | 5 #ifndef PropertyHandle_h |
| 6 #define PropertyHandle_h | 6 #define PropertyHandle_h |
| 7 | 7 |
| 8 #include "core/CSSPropertyNames.h" | 8 #include "core/CSSPropertyNames.h" |
| 9 #include "core/CoreExport.h" | 9 #include "core/CoreExport.h" |
| 10 #include "core/dom/QualifiedName.h" | 10 #include "core/dom/QualifiedName.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 bool isPresentationAttribute = false) | 21 bool isPresentationAttribute = false) |
| 22 : m_handleType(isPresentationAttribute ? HandlePresentationAttribute | 22 : m_handleType(isPresentationAttribute ? HandlePresentationAttribute |
| 23 : HandleCSSProperty), | 23 : HandleCSSProperty), |
| 24 m_cssProperty(property) { | 24 m_cssProperty(property) { |
| 25 DCHECK_NE(property, CSSPropertyInvalid); | 25 DCHECK_NE(property, CSSPropertyInvalid); |
| 26 DCHECK_NE(property, CSSPropertyVariable); | 26 DCHECK_NE(property, CSSPropertyVariable); |
| 27 } | 27 } |
| 28 | 28 |
| 29 explicit PropertyHandle(const AtomicString& propertyName) | 29 explicit PropertyHandle(const AtomicString& propertyName) |
| 30 : m_handleType(HandleCSSCustomProperty), | 30 : m_handleType(HandleCSSCustomProperty), |
| 31 m_propertyName(propertyName.impl()) {} | 31 m_svgAttribute(nullptr), |
| 32 m_propertyName(propertyName) {} |
| 32 | 33 |
| 33 explicit PropertyHandle(const QualifiedName& attributeName) | 34 explicit PropertyHandle(const QualifiedName& attributeName) |
| 34 : m_handleType(HandleSVGAttribute), m_svgAttribute(&attributeName) {} | 35 : m_handleType(HandleSVGAttribute), m_svgAttribute(&attributeName) {} |
| 35 | 36 |
| 36 bool operator==(const PropertyHandle&) const; | 37 bool operator==(const PropertyHandle&) const; |
| 37 bool operator!=(const PropertyHandle& other) const { | 38 bool operator!=(const PropertyHandle& other) const { |
| 38 return !(*this == other); | 39 return !(*this == other); |
| 39 } | 40 } |
| 40 | 41 |
| 41 unsigned hash() const; | 42 unsigned hash() const; |
| 42 | 43 |
| 43 bool isCSSProperty() const { | 44 bool isCSSProperty() const { |
| 44 return m_handleType == HandleCSSProperty || isCSSCustomProperty(); | 45 return m_handleType == HandleCSSProperty || isCSSCustomProperty(); |
| 45 } | 46 } |
| 46 CSSPropertyID cssProperty() const { | 47 CSSPropertyID cssProperty() const { |
| 47 DCHECK(isCSSProperty()); | 48 DCHECK(isCSSProperty()); |
| 48 return m_handleType == HandleCSSProperty ? m_cssProperty | 49 return m_handleType == HandleCSSProperty ? m_cssProperty |
| 49 : CSSPropertyVariable; | 50 : CSSPropertyVariable; |
| 50 } | 51 } |
| 51 | 52 |
| 52 bool isCSSCustomProperty() const { | 53 bool isCSSCustomProperty() const { |
| 53 return m_handleType == HandleCSSCustomProperty; | 54 return m_handleType == HandleCSSCustomProperty; |
| 54 } | 55 } |
| 55 AtomicString customPropertyName() const { | 56 const AtomicString& customPropertyName() const { |
| 56 DCHECK(isCSSCustomProperty()); | 57 DCHECK(isCSSCustomProperty()); |
| 57 return AtomicString(m_propertyName); | 58 return m_propertyName; |
| 58 } | 59 } |
| 59 | 60 |
| 60 bool isPresentationAttribute() const { | 61 bool isPresentationAttribute() const { |
| 61 return m_handleType == HandlePresentationAttribute; | 62 return m_handleType == HandlePresentationAttribute; |
| 62 } | 63 } |
| 63 CSSPropertyID presentationAttribute() const { | 64 CSSPropertyID presentationAttribute() const { |
| 64 DCHECK(isPresentationAttribute()); | 65 DCHECK(isPresentationAttribute()); |
| 65 return m_cssProperty; | 66 return m_cssProperty; |
| 66 } | 67 } |
| 67 | 68 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 93 } | 94 } |
| 94 | 95 |
| 95 bool isDeletedValueForHashTraits() { | 96 bool isDeletedValueForHashTraits() { |
| 96 return m_handleType == HandleDeletedValueForHashTraits; | 97 return m_handleType == HandleDeletedValueForHashTraits; |
| 97 } | 98 } |
| 98 | 99 |
| 99 HandleType m_handleType; | 100 HandleType m_handleType; |
| 100 union { | 101 union { |
| 101 CSSPropertyID m_cssProperty; | 102 CSSPropertyID m_cssProperty; |
| 102 const QualifiedName* m_svgAttribute; | 103 const QualifiedName* m_svgAttribute; |
| 103 StringImpl* m_propertyName; | |
| 104 }; | 104 }; |
| 105 AtomicString m_propertyName; |
| 105 | 106 |
| 106 friend struct ::WTF::HashTraits<blink::PropertyHandle>; | 107 friend struct ::WTF::HashTraits<blink::PropertyHandle>; |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 } // namespace blink | 110 } // namespace blink |
| 110 | 111 |
| 111 namespace WTF { | 112 namespace WTF { |
| 112 | 113 |
| 113 template <> | 114 template <> |
| 114 struct DefaultHash<blink::PropertyHandle> { | 115 struct DefaultHash<blink::PropertyHandle> { |
| 115 struct Hash { | 116 struct Hash { |
| 116 STATIC_ONLY(Hash); | 117 STATIC_ONLY(Hash); |
| 117 static unsigned hash(const blink::PropertyHandle& handle) { | 118 static unsigned hash(const blink::PropertyHandle& handle) { |
| 118 return handle.hash(); | 119 return handle.hash(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 static bool equal(const blink::PropertyHandle& a, | 122 static bool equal(const blink::PropertyHandle& a, |
| 122 const blink::PropertyHandle& b) { | 123 const blink::PropertyHandle& b) { |
| 123 return a == b; | 124 return a == b; |
| 124 } | 125 } |
| 125 | 126 |
| 126 static const bool safeToCompareToEmptyOrDeleted = true; | 127 static const bool safeToCompareToEmptyOrDeleted = true; |
| 127 }; | 128 }; |
| 128 }; | 129 }; |
| 129 | 130 |
| 130 template <> | 131 template <> |
| 131 struct HashTraits<blink::PropertyHandle> | 132 struct HashTraits<blink::PropertyHandle> |
| 132 : SimpleClassHashTraits<blink::PropertyHandle> { | 133 : SimpleClassHashTraits<blink::PropertyHandle> { |
| 133 static const bool needsDestruction = false; | 134 static const bool needsDestruction = true; |
| 134 static void constructDeletedValue(blink::PropertyHandle& slot, bool) { | 135 static void constructDeletedValue(blink::PropertyHandle& slot, bool) { |
| 135 new (NotNull, &slot) blink::PropertyHandle( | 136 new (NotNull, &slot) blink::PropertyHandle( |
| 136 blink::PropertyHandle::deletedValueForHashTraits()); | 137 blink::PropertyHandle::deletedValueForHashTraits()); |
| 137 } | 138 } |
| 138 static bool isDeletedValue(blink::PropertyHandle value) { | 139 static bool isDeletedValue(blink::PropertyHandle value) { |
| 139 return value.isDeletedValueForHashTraits(); | 140 return value.isDeletedValueForHashTraits(); |
| 140 } | 141 } |
| 141 | 142 |
| 142 static blink::PropertyHandle emptyValue() { | 143 static blink::PropertyHandle emptyValue() { |
| 143 return blink::PropertyHandle::emptyValueForHashTraits(); | 144 return blink::PropertyHandle::emptyValueForHashTraits(); |
| 144 } | 145 } |
| 145 }; | 146 }; |
| 146 | 147 |
| 147 } // namespace WTF | 148 } // namespace WTF |
| 148 | 149 |
| 149 #endif // PropertyHandle_h | 150 #endif // PropertyHandle_h |
| OLD | NEW |