OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #ifndef IntersectionObserver_h |
| 6 #define IntersectionObserver_h |
| 7 |
| 8 #include "bindings/core/v8/ScriptWrappable.h" |
| 9 #include "core/dom/Element.h" |
| 10 #include "core/dom/IntersectionObservation.h" |
| 11 #include "core/dom/IntersectionObserverEntry.h" |
| 12 #include "platform/heap/Handle.h" |
| 13 #include "wtf/HashSet.h" |
| 14 #include "wtf/RefCounted.h" |
| 15 #include "wtf/Vector.h" |
| 16 |
| 17 namespace blink { |
| 18 |
| 19 class ExceptionState; |
| 20 class IntersectionObserverCallback; |
| 21 class IntersectionObserverInit; |
| 22 |
| 23 class IntersectionObserver final : public GarbageCollectedFinalized<Intersection
Observer>, public ScriptWrappable { |
| 24 DEFINE_WRAPPERTYPEINFO(); |
| 25 |
| 26 public: |
| 27 static IntersectionObserver* create(const IntersectionObserverInit&, Interse
ctionObserverCallback&, ExceptionState&); |
| 28 static void resumeSuspendedObservers(); |
| 29 |
| 30 // API methods |
| 31 void observe(Element*, ExceptionState&); |
| 32 void unobserve(Element*, ExceptionState&); |
| 33 HeapVector<Member<IntersectionObserverEntry>> takeRecords(); |
| 34 |
| 35 Element* root() { return m_root.get(); } |
| 36 LayoutObject* rootLayoutObject(); |
| 37 bool isDescendantOfRoot(const Element*) const; |
| 38 void computeIntersectionObservations(double timestamp); |
| 39 void enqueueIntersectionObserverEntry(IntersectionObserverEntry&); |
| 40 unsigned firstThresholdGreaterThan(float ratio) const; |
| 41 void deliver(); |
| 42 void setActive(bool); |
| 43 void disconnect(); |
| 44 void removeObservation(IntersectionObservation&); |
| 45 |
| 46 DECLARE_TRACE(); |
| 47 |
| 48 private: |
| 49 explicit IntersectionObserver(IntersectionObserverCallback&, Element&, const
Vector<float>& thresholds); |
| 50 |
| 51 void checkRootAndDetachIfNeeded(); |
| 52 |
| 53 Member<IntersectionObserverCallback> m_callback; |
| 54 WeakPtrWillBeWeakMember<Element> m_root; |
| 55 HeapHashSet<WeakMember<IntersectionObservation>> m_observations; |
| 56 HeapVector<Member<IntersectionObserverEntry>> m_entries; |
| 57 Vector<float> m_thresholds; |
| 58 }; |
| 59 |
| 60 } // namespace blink |
| 61 |
| 62 #endif // IntersectionObserver_h |
OLD | NEW |