| Index: third_party/WebKit/Source/core/dom/IntersectionObservation.h
|
| diff --git a/third_party/WebKit/Source/core/dom/IntersectionObservation.h b/third_party/WebKit/Source/core/dom/IntersectionObservation.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7f92453bec72fac31b59fb2820765a8174b5b221
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/dom/IntersectionObservation.h
|
| @@ -0,0 +1,94 @@
|
| +// 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.
|
| +
|
| +#include "platform/heap/Handle.h"
|
| +#include "wtf/HashSet.h"
|
| +#include "wtf/RefPtr.h"
|
| +#include "wtf/WeakPtr.h"
|
| +
|
| +#ifndef IntersectionObservation_h
|
| +#define IntersectionObservation_h
|
| +
|
| +namespace blink {
|
| +
|
| +class Element;
|
| +class IntersectionObserver;
|
| +
|
| +class IntersectionObservation : public GarbageCollectedFinalized<IntersectionObservation> {
|
| +public:
|
| + typedef std::pair<IntersectionObserver*, Element*> HashKey;
|
| + typedef Member<IntersectionObservation> ValueType;
|
| + typedef typename WTF::HashTraits<ValueType>::PeekInType PeekInType;
|
| + struct ValueTypeHash {
|
| + static unsigned hash()
|
| + {
|
| + return DefaultHash<HashKey>::Hash::hash(HashKey(nullptr, nullptr));
|
| + }
|
| + static unsigned hash(PeekInType keyRef)
|
| + {
|
| + IntersectionObservation* key = keyRef;
|
| + if (!key)
|
| + return hash();
|
| + return DefaultHash<HashKey>::Hash::hash(HashKey(key->observer(), key->target()));
|
| + }
|
| + static bool equal(const PeekInType& aRef, const PeekInType& bRef)
|
| + {
|
| + IntersectionObservation* a = aRef;
|
| + IntersectionObservation* b = bRef;
|
| + if (!a)
|
| + return b;
|
| + if (!b)
|
| + return true;
|
| + return a->observer() == b->observer() && a->target() == b->target();
|
| + }
|
| + static const bool safeToCompareToEmptyOrDeleted = true;
|
| + };
|
| + struct HashKeyTranslator {
|
| + static unsigned hash(const HashKey& key) { return DefaultHash<HashKey>::Hash::hash(key); }
|
| + static bool equal(const ValueType& a, const HashKey& b)
|
| + {
|
| + return a->observer() == b.first && a->target() == b.second;
|
| + }
|
| + };
|
| + typedef HeapHashSet<ValueType, ValueTypeHash> HashSet;
|
| +
|
| + static HashSet::iterator find(HashSet& hashSet, IntersectionObserver* observer, Element* target)
|
| + {
|
| + return hashSet.find<HashKeyTranslator, HashKey>(HashKey(observer, target));
|
| + }
|
| + static bool contains(HashSet& hashSet, IntersectionObserver* observer, Element* target)
|
| + {
|
| + return hashSet.contains<HashKeyTranslator, HashKey>(HashKey(observer, target));
|
| + }
|
| + static void remove(HashSet& hashSet, IntersectionObserver* observer, Element* target)
|
| + {
|
| + hashSet.remove(hashSet.find<HashKeyTranslator, HashKey>(HashKey(observer, target)));
|
| + }
|
| +
|
| + IntersectionObservation(IntersectionObserver&, WeakPtrWillBeRawPtr<Element>, bool);
|
| +
|
| + const IntersectionObserver* observer() const { return m_observer; }
|
| + IntersectionObserver* observer() { return m_observer; }
|
| + const Element* target() const { return m_target.get(); }
|
| + Element* target() { return m_target.get(); }
|
| + bool isActive() const { return m_active; }
|
| + void setActive(bool);
|
| + float lastVisibleRatio() const { return m_lastVisibleRatio; }
|
| + void setLastVisibleRatio(float ratio) { m_lastVisibleRatio = ratio; }
|
| +
|
| + void computeIntersectionObservations(double);
|
| + void disconnect();
|
| +
|
| + DECLARE_TRACE();
|
| +
|
| +private:
|
| + Member<IntersectionObserver> m_observer;
|
| + WeakPtrWillBeWeakMember<Element> m_target;
|
| + bool m_active;
|
| + float m_lastVisibleRatio;
|
| +};
|
| +
|
| +} // namespace blink {
|
| +
|
| +#endif // IntersectionObservation_h
|
|
|