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..34c87bc69c375323cfb3a4cb0a1883466a8e1b34 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/dom/IntersectionObservation.h |
@@ -0,0 +1,91 @@ |
+// 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 RefCountedWillBeGarbageCollectedFinalized<IntersectionObservation> { |
haraken
2015/11/16 00:41:34
You don't need to use WillBe types for newly intro
szager1
2015/11/17 01:50:03
If I understand you correctly, I can use regular o
|
+public: |
+ typedef RefPtrWillBeRawPtr<IntersectionObservation> RefPtrType; |
+ typedef std::pair<IntersectionObserver*, Element*> HashKey; |
+ typedef WTF::RefPtrValuePeeker<IntersectionObservation> PeekInType; |
+ struct RefPtrHash { |
+ static unsigned hash(PeekInType keyRef) |
+ { |
+ IntersectionObservation* key = keyRef; |
+ if (!key) |
+ return DefaultHash<HashKey>::Hash::hash(HashKey(nullptr, nullptr)); |
eae
2015/11/16 23:34:44
A separate hash method that takes no type would ma
szager1
2015/11/19 19:15:38
Do you mean:
static unsigned hash(PeekInType keyR
|
+ return DefaultHash<HashKey>::Hash::hash(HashKey(key->observer(), key->target())); |
+ } |
+ static bool equal(PeekInType aRef, PeekInType bRef) |
eae
2015/11/16 23:34:44
You might want to use const here.
szager1
2015/11/19 19:15:38
Done in next patch.
|
+ { |
+ 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 RefPtrType& a, const HashKey& b) |
+ { |
+ return a->observer() == b.first && a->target() == b.second; |
+ } |
+ }; |
+ typedef WillBeHeapHashSet<RefPtrType, RefPtrHash> 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))); |
+ } |
+ |
+ static PassRefPtrWillBeRawPtr<IntersectionObservation> create(IntersectionObserver&, WeakPtrWillBeRawPtr<Element>, bool active = true); |
+ |
+ const IntersectionObserver* observer() const; |
+ IntersectionObserver* 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: |
+ IntersectionObservation(IntersectionObserver&, WeakPtrWillBeRawPtr<Element>, bool); |
+ |
+ RefPtrWillBeMember<IntersectionObserver> m_observer; |
+ WeakPtrWillBeWeakMember<Element> m_target; |
+ bool m_active; |
+ float m_lastVisibleRatio; |
+}; |
+ |
+} // namespace blink { |
+ |
+#endif // IntersectionObservation_h |