Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/geometry/LayoutRect.h" | |
| 6 #include "platform/heap/Handle.h" | |
| 7 #include "wtf/HashSet.h" | |
| 8 #include "wtf/RefPtr.h" | |
| 9 #include "wtf/WeakPtr.h" | |
| 10 | |
| 11 #ifndef IntersectionObservation_h | |
| 12 #define IntersectionObservation_h | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 class Element; | |
| 17 class IntersectionObserver; | |
| 18 | |
| 19 class IntersectionObservation : public GarbageCollectedFinalized<IntersectionObs ervation> { | |
| 20 public: | |
| 21 typedef std::pair<IntersectionObserver*, Element*> HashKey; | |
| 22 typedef Member<IntersectionObservation> ValueType; | |
| 23 typedef WeakMember<IntersectionObservation> WeakValueType; | |
| 24 typedef typename WTF::HashTraits<ValueType>::PeekInType PeekInType; | |
| 25 struct ValueTypeHash { | |
|
esprehn
2015/12/12 00:14:14
hmm, we've never had to do this before for a norma
szager1
2015/12/16 19:15:35
Removed the custom hash_traits.
| |
| 26 static unsigned hash() | |
| 27 { | |
| 28 return DefaultHash<HashKey>::Hash::hash(HashKey(nullptr, nullptr)); | |
| 29 } | |
| 30 static unsigned hash(PeekInType keyRef) | |
| 31 { | |
| 32 IntersectionObservation* key = keyRef; | |
| 33 if (!key) | |
| 34 return hash(); | |
| 35 return DefaultHash<HashKey>::Hash::hash(HashKey(key->observer(), key ->target())); | |
| 36 } | |
| 37 static bool equal(const PeekInType& aRef, const PeekInType& bRef) | |
| 38 { | |
| 39 IntersectionObservation* a = aRef; | |
| 40 IntersectionObservation* b = bRef; | |
| 41 if (!a) | |
| 42 return b; | |
| 43 if (!b) | |
| 44 return true; | |
| 45 return a->observer() == b->observer() && a->target() == b->target(); | |
| 46 } | |
| 47 static const bool safeToCompareToEmptyOrDeleted = true; | |
| 48 }; | |
| 49 struct HashKeyTranslator { | |
| 50 static unsigned hash(const HashKey& key) { return DefaultHash<HashKey>:: Hash::hash(key); } | |
| 51 static bool equal(const ValueType& a, const HashKey& b) | |
| 52 { | |
|
esprehn
2015/12/12 00:14:14
yeah I'd really rather we didn't do this
szager1
2015/12/16 19:15:35
Done.
| |
| 53 return a && a->observer() == b.first && a->target() == b.second; | |
| 54 } | |
| 55 static bool equal(const WeakValueType& a, const HashKey& b) | |
| 56 { | |
| 57 return a && a->observer() == b.first && a->target() == b.second; | |
| 58 } | |
| 59 }; | |
| 60 typedef HeapHashSet<ValueType, ValueTypeHash> HashSet; | |
| 61 typedef HeapHashSet<WeakValueType, ValueTypeHash> WeakHashSet; | |
| 62 | |
| 63 template<typename HashSetType> | |
| 64 static typename HashSetType::iterator find(HashSetType& hashSet, Intersectio nObserver* observer, Element* target) | |
|
esprehn
2015/12/12 00:14:14
remove this, no templates or statics like this, ad
szager1
2015/12/16 19:15:35
Done.
| |
| 65 { | |
| 66 return hashSet.template find<HashKeyTranslator, HashKey>(HashKey(observe r, target)); | |
| 67 } | |
| 68 | |
| 69 template<typename HashSetType> | |
| 70 static bool contains(HashSetType& hashSet, IntersectionObserver* observer, E lement* target) | |
| 71 { | |
| 72 return hashSet.template contains<HashKeyTranslator, HashKey>(HashKey(obs erver, target)); | |
| 73 } | |
| 74 | |
| 75 template<typename HashSetType> | |
| 76 static void remove(HashSetType& hashSet, IntersectionObserver* observer, Ele ment* target) | |
|
esprehn
2015/12/12 00:14:14
ditto for all of these
szager1
2015/12/16 19:15:35
Done.
| |
| 77 { | |
| 78 hashSet.remove(hashSet.template find<HashKeyTranslator, HashKey>(HashKey (observer, target))); | |
| 79 } | |
| 80 | |
| 81 IntersectionObservation(IntersectionObserver&, Element*, bool); | |
|
esprehn
2015/12/12 00:14:14
bool needs an argument name, why not an enum? We d
szager1
2015/12/16 19:15:35
The bool is canReportRootBounds, is there some oth
| |
| 82 | |
| 83 const IntersectionObserver* observer() const { return m_observer; } | |
| 84 IntersectionObserver* observer() { return m_observer; } | |
| 85 const Element* target() const { return m_target.get(); } | |
| 86 Element* target() { return m_target.get(); } | |
| 87 bool isActive() const { return m_active; } | |
| 88 void setActive(bool active) { m_active = active; } | |
| 89 float lastVisibleRatio() const { return m_lastVisibleRatio; } | |
| 90 void setLastVisibleRatio(float ratio) { m_lastVisibleRatio = ratio; } | |
| 91 bool canReportRootBounds() const { return m_canReportRootBounds; } | |
| 92 | |
| 93 void computeIntersectionObservations(int); | |
|
esprehn
2015/12/12 00:14:14
int needs an argument name, primitive arguments al
szager1
2015/12/16 19:15:35
Done.
| |
| 94 void disconnect(); | |
| 95 | |
| 96 DECLARE_TRACE(); | |
| 97 | |
| 98 private: | |
| 99 bool computeGeometry(LayoutRect& targetRect, LayoutRect& rootRect, LayoutRec t& intersectionRect); | |
| 100 | |
| 101 Member<IntersectionObserver> m_observer; | |
| 102 WeakPtrWillBeWeakMember<Element> m_target; | |
| 103 bool m_active; | |
| 104 bool m_canReportRootBounds; | |
|
esprehn
2015/12/12 00:14:14
I'd swap these with the float, and make them both
ojan
2015/12/12 01:06:28
Bikeshed nit: We typically call this m_shouldRepor
szager1
2015/12/16 19:15:35
Done.
szager1
2015/12/16 19:15:35
Done.
| |
| 105 float m_lastVisibleRatio; | |
| 106 }; | |
| 107 | |
| 108 } // namespace blink { | |
| 109 | |
| 110 #endif // IntersectionObservation_h | |
| OLD | NEW |