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/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 void disconnect(); |
| 34 HeapVector<Member<IntersectionObserverEntry>> takeRecords(); |
| 35 |
| 36 Element* root() { return m_root.get(); } |
| 37 LayoutObject* rootLayoutObject(); |
| 38 bool isDescendantOfRoot(const Element*) const; |
| 39 void computeIntersectionObservations(double timestamp); |
| 40 void disconnect(IntersectionObservation&); |
| 41 void enqueueIntersectionObserverEntry(IntersectionObserverEntry&); |
| 42 void applyRootMargin(LayoutRect&) const; |
| 43 unsigned firstThresholdGreaterThan(float ratio) const; |
| 44 bool shouldBeSuspended() const; |
| 45 void deliver(); |
| 46 void setActive(bool); |
| 47 bool hasPercentMargin() const; |
| 48 const Length& topMargin() const { return m_topMargin; } |
| 49 const Length& rightMargin() const { return m_rightMargin; } |
| 50 const Length& bottomMargin() const { return m_bottomMargin; } |
| 51 const Length& leftMargin() const { return m_leftMargin; } |
| 52 |
| 53 #if !ENABLE(OILPAN) |
| 54 void dispose(); |
| 55 #endif |
| 56 |
| 57 DECLARE_TRACE(); |
| 58 |
| 59 private: |
| 60 explicit IntersectionObserver(IntersectionObserverCallback&, Element&, const
Vector<Length>& rootMargin, const Vector<float>& thresholds); |
| 61 |
| 62 void checkRootAndDetachIfNeeded(); |
| 63 |
| 64 Member<IntersectionObserverCallback> m_callback; |
| 65 WeakPtrWillBeWeakMember<Element> m_root; |
| 66 HeapHashSet<WeakMember<IntersectionObservation>> m_observations; |
| 67 HeapVector<Member<IntersectionObserverEntry>> m_entries; |
| 68 Vector<float> m_thresholds; |
| 69 Length m_topMargin; |
| 70 Length m_rightMargin; |
| 71 Length m_bottomMargin; |
| 72 Length m_leftMargin; |
| 73 }; |
| 74 |
| 75 } // namespace blink |
| 76 |
| 77 #endif // IntersectionObserver_h |
OLD | NEW |