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 #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/IntersectionObservationRegistry.h" |
| 12 #include "core/dom/IntersectionObserverEntry.h" |
| 13 #include "platform/heap/Handle.h" |
| 14 #include "wtf/HashSet.h" |
| 15 #include "wtf/RefCounted.h" |
| 16 #include "wtf/Vector.h" |
| 17 |
| 18 namespace blink { |
| 19 |
| 20 class ExceptionState; |
| 21 class IntersectionObserverCallback; |
| 22 class IntersectionObserverInit; |
| 23 |
| 24 typedef HeapVector<Member<IntersectionObserverEntry>> IntersectionObserverEntryV
ector; |
| 25 |
| 26 class IntersectionObserver final : public GarbageCollectedFinalized<Intersection
Observer>, public ScriptWrappable { |
| 27 DEFINE_WRAPPERTYPEINFO(); |
| 28 public: |
| 29 static IntersectionObserver* create(Document* owningDocument, const Intersec
tionObserverInit&, IntersectionObserverCallback*, ExceptionState&); |
| 30 static void resumeSuspendedObservers(); |
| 31 |
| 32 void observe(Element*, ExceptionState&); |
| 33 void unobserve(Element*, ExceptionState&); |
| 34 void disconnect(IntersectionObservation&); |
| 35 void disconnect(); |
| 36 IntersectionObserverEntryVector takeRecords(); |
| 37 |
| 38 bool isDescendantOfRoot(Element*); |
| 39 void enqueueIntersectionObserverEntry(IntersectionObserverEntry*); |
| 40 |
| 41 bool hasRoot() const { return m_hasRoot; } |
| 42 Element* root() { return m_root.get(); } |
| 43 Document* owningDocument() { return m_owningDocument.get(); } |
| 44 Document* trackingDocument() { return m_trackingDocument.get(); } |
| 45 const Vector<float>& thresholds() const { return m_thresholds; } |
| 46 size_t firstThresholdGreaterThan(float ratio) const; |
| 47 bool shouldBeSuspended() const; |
| 48 void deliver(); |
| 49 |
| 50 DECLARE_TRACE(); |
| 51 |
| 52 private: |
| 53 explicit IntersectionObserver(Document* owningDocument, IntersectionObserver
Callback*, PassRefPtrWillBeRawPtr<Element>, int, const Vector<float>&); |
| 54 |
| 55 Document& getTrackingDocumentForTarget(Element*); |
| 56 IntersectionObservation* createObservation(Element*); |
| 57 |
| 58 Member<IntersectionObserverCallback> m_callback; |
| 59 WeakPtrWillBeWeakMember<Element> m_root; |
| 60 WeakPtrWillBeWeakMember<Document> m_owningDocument; |
| 61 WeakPtrWillBeWeakMember<Document> m_trackingDocument; |
| 62 Member<IntersectionObservation::HashSet> m_observations; |
| 63 Member<IntersectionObserverEntryVector> m_entries; |
| 64 Vector<float> m_thresholds; |
| 65 int m_rootMargin; |
| 66 // m_root is a weak pointer, so may become null if the root Element is deall
ocated. |
| 67 // Only m_hasRoot indicates for certain that there *should* be a root. |
| 68 bool m_hasRoot; |
| 69 }; |
| 70 |
| 71 } // namespace blink |
| 72 |
| 73 #endif // IntersectionObserver_h |
OLD | NEW |