1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_PROPERTY_HANDLE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_PROPERTY_HANDLE_H_
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/css_property_name.h"
#include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/core/css/properties/css_property.h"
#include "third_party/blink/renderer/core/dom/qualified_name.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
namespace blink {
// Represents the property of a PropertySpecificKeyframe.
class CORE_EXPORT PropertyHandle {
DISALLOW_NEW();
public:
explicit PropertyHandle(const CSSProperty& property,
bool is_presentation_attribute = false)
: handle_type_(is_presentation_attribute ? kHandlePresentationAttribute
: kHandleCSSProperty),
css_property_(&property) {
DCHECK_NE(CSSPropertyVariable, property.PropertyID());
}
explicit PropertyHandle(const AtomicString& property_name)
: handle_type_(kHandleCSSCustomProperty),
css_property_(&GetCSSPropertyVariable()),
property_name_(property_name) {}
explicit PropertyHandle(const QualifiedName& attribute_name)
: handle_type_(kHandleSVGAttribute), svg_attribute_(&attribute_name) {}
bool operator==(const PropertyHandle&) const;
bool operator!=(const PropertyHandle& other) const {
return !(*this == other);
}
unsigned GetHash() const;
bool IsCSSProperty() const {
return handle_type_ == kHandleCSSProperty || IsCSSCustomProperty();
}
const CSSProperty& GetCSSProperty() const {
DCHECK(IsCSSProperty());
return *css_property_;
}
bool IsCSSCustomProperty() const {
return handle_type_ == kHandleCSSCustomProperty;
}
const AtomicString& CustomPropertyName() const {
DCHECK(IsCSSCustomProperty());
return property_name_;
}
bool IsPresentationAttribute() const {
return handle_type_ == kHandlePresentationAttribute;
}
const CSSProperty& PresentationAttribute() const {
DCHECK(IsPresentationAttribute());
return *css_property_;
}
bool IsSVGAttribute() const { return handle_type_ == kHandleSVGAttribute; }
const QualifiedName& SvgAttribute() const {
DCHECK(IsSVGAttribute());
return *svg_attribute_;
}
CSSPropertyName GetCSSPropertyName() const {
if (handle_type_ == kHandleCSSCustomProperty)
return CSSPropertyName(property_name_);
DCHECK(IsCSSProperty() || IsPresentationAttribute());
return CSSPropertyName(css_property_->PropertyID());
}
private:
enum HandleType {
kHandleEmptyValueForHashTraits,
kHandleDeletedValueForHashTraits,
kHandleCSSProperty,
kHandleCSSCustomProperty,
kHandlePresentationAttribute,
kHandleSVGAttribute,
};
explicit PropertyHandle(HandleType handle_type)
: handle_type_(handle_type), svg_attribute_(nullptr) {}
static PropertyHandle EmptyValueForHashTraits() {
return PropertyHandle(kHandleEmptyValueForHashTraits);
}
static PropertyHandle DeletedValueForHashTraits() {
return PropertyHandle(kHandleDeletedValueForHashTraits);
}
bool IsDeletedValueForHashTraits() {
return handle_type_ == kHandleDeletedValueForHashTraits;
}
HandleType handle_type_;
union {
const CSSProperty* css_property_;
const QualifiedName* svg_attribute_;
};
AtomicString property_name_;
friend struct ::WTF::HashTraits<blink::PropertyHandle>;
};
} // namespace blink
namespace WTF {
template <>
struct DefaultHash<blink::PropertyHandle> {
struct Hash {
STATIC_ONLY(Hash);
static unsigned GetHash(const blink::PropertyHandle& handle) {
return handle.GetHash();
}
static bool Equal(const blink::PropertyHandle& a,
const blink::PropertyHandle& b) {
return a == b;
}
static const bool safe_to_compare_to_empty_or_deleted = true;
};
};
template <>
struct HashTraits<blink::PropertyHandle>
: SimpleClassHashTraits<blink::PropertyHandle> {
static const bool kNeedsDestruction = true;
static void ConstructDeletedValue(blink::PropertyHandle& slot, bool) {
new (NotNull, &slot) blink::PropertyHandle(
blink::PropertyHandle::DeletedValueForHashTraits());
}
static bool IsDeletedValue(blink::PropertyHandle value) {
return value.IsDeletedValueForHashTraits();
}
static blink::PropertyHandle EmptyValue() {
return blink::PropertyHandle::EmptyValueForHashTraits();
}
};
} // namespace WTF
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_PROPERTY_HANDLE_H_
|