Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/WebKit/Source/core/dom/IntersectionObservation.h

Issue 1449623002: IntersectionObserver: second cut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Use existing Document::m_weakFactory. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "platform/heap/Handle.h"
6 #include "wtf/HashSet.h"
7 #include "wtf/RefPtr.h"
8 #include "wtf/WeakPtr.h"
9
10 #ifndef IntersectionObservation_h
11 #define IntersectionObservation_h
12
13 namespace blink {
14
15 class Element;
16 class IntersectionObserver;
17
18 class IntersectionObservation : public GarbageCollectedFinalized<IntersectionObs ervation> {
19 public:
20 typedef std::pair<IntersectionObserver*, Element*> HashKey;
21 typedef Member<IntersectionObservation> ValueType;
22 typedef typename WTF::HashTraits<ValueType>::PeekInType PeekInType;
23 struct ValueTypeHash {
24 static unsigned hash()
25 {
26 return DefaultHash<HashKey>::Hash::hash(HashKey(nullptr, nullptr));
27 }
28 static unsigned hash(PeekInType keyRef)
29 {
30 IntersectionObservation* key = keyRef;
31 if (!key)
32 return hash();
33 return DefaultHash<HashKey>::Hash::hash(HashKey(key->observer(), key ->target()));
34 }
35 static bool equal(const PeekInType& aRef, const PeekInType& bRef)
36 {
37 IntersectionObservation* a = aRef;
38 IntersectionObservation* b = bRef;
39 if (!a)
40 return b;
41 if (!b)
42 return true;
43 return a->observer() == b->observer() && a->target() == b->target();
44 }
45 static const bool safeToCompareToEmptyOrDeleted = true;
46 };
47 struct HashKeyTranslator {
48 static unsigned hash(const HashKey& key) { return DefaultHash<HashKey>:: Hash::hash(key); }
49 static bool equal(const ValueType& a, const HashKey& b)
50 {
51 return a->observer() == b.first && a->target() == b.second;
52 }
53 };
54 typedef HeapHashSet<ValueType, ValueTypeHash> HashSet;
55
56 static HashSet::iterator find(HashSet& hashSet, IntersectionObserver* observ er, Element* target)
57 {
58 return hashSet.find<HashKeyTranslator, HashKey>(HashKey(observer, target ));
59 }
60 static bool contains(HashSet& hashSet, IntersectionObserver* observer, Eleme nt* target)
61 {
62 return hashSet.contains<HashKeyTranslator, HashKey>(HashKey(observer, ta rget));
63 }
64 static void remove(HashSet& hashSet, IntersectionObserver* observer, Element * target)
65 {
66 hashSet.remove(hashSet.find<HashKeyTranslator, HashKey>(HashKey(observer , target)));
67 }
68
69 IntersectionObservation(IntersectionObserver&, WeakPtrWillBeRawPtr<Element>, bool);
70
71 const IntersectionObserver* observer() const { return m_observer; }
72 IntersectionObserver* observer() { return m_observer; }
73 const Element* target() const { return m_target.get(); }
74 Element* target() { return m_target.get(); }
75 bool isActive() const { return m_active; }
76 void setActive(bool);
77 float lastVisibleRatio() const { return m_lastVisibleRatio; }
78 void setLastVisibleRatio(float ratio) { m_lastVisibleRatio = ratio; }
79
80 void computeIntersectionObservations(double);
81 void disconnect();
82
83 DECLARE_TRACE();
84
85 private:
86 Member<IntersectionObserver> m_observer;
87 WeakPtrWillBeWeakMember<Element> m_target;
88 bool m_active;
89 float m_lastVisibleRatio;
90 };
91
92 } // namespace blink {
93
94 #endif // IntersectionObservation_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698