OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef IntersectionObserver_h | 5 #ifndef IntersectionObserver_h |
6 #define IntersectionObserver_h | 6 #define IntersectionObserver_h |
7 | 7 |
8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 8 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
9 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
10 #include "core/dom/IntersectionObservation.h" | 10 #include "core/dom/IntersectionObservation.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 class CORE_EXPORT IntersectionObserver final | 26 class CORE_EXPORT IntersectionObserver final |
27 : public GarbageCollectedFinalized<IntersectionObserver>, | 27 : public GarbageCollectedFinalized<IntersectionObserver>, |
28 public ScriptWrappable { | 28 public ScriptWrappable { |
29 DEFINE_WRAPPERTYPEINFO(); | 29 DEFINE_WRAPPERTYPEINFO(); |
30 | 30 |
31 public: | 31 public: |
32 using EventCallback = | 32 using EventCallback = |
33 Function<void(const HeapVector<Member<IntersectionObserverEntry>>&), | 33 Function<void(const HeapVector<Member<IntersectionObserverEntry>>&), |
34 WTF::SameThreadAffinity>; | 34 WTF::SameThreadAffinity>; |
35 | 35 |
36 // Defines the assumed initial state of the observed element. If the actual | |
37 // state is the same as the initial state, then no observation will be | |
38 // delivered. kAuto means the initial observation will always get sent. | |
39 enum class InitialState { | |
40 // TODO(skyostil): Add support for kVisible. | |
41 kAuto, | |
42 kHidden, | |
43 }; | |
44 | |
45 static IntersectionObserver* create(const IntersectionObserverInit&, | 36 static IntersectionObserver* create(const IntersectionObserverInit&, |
46 IntersectionObserverCallback&, | 37 IntersectionObserverCallback&, |
47 ExceptionState&); | 38 ExceptionState&); |
48 static IntersectionObserver* create(const Vector<Length>& rootMargin, | 39 static IntersectionObserver* create(const Vector<Length>& rootMargin, |
49 const Vector<float>& thresholds, | 40 const Vector<float>& thresholds, |
50 Document*, | 41 Document*, |
51 std::unique_ptr<EventCallback>, | 42 std::unique_ptr<EventCallback>, |
52 ExceptionState& = ASSERT_NO_EXCEPTION); | 43 ExceptionState& = ASSERT_NO_EXCEPTION); |
53 static void resumeSuspendedObservers(); | 44 static void resumeSuspendedObservers(); |
54 | 45 |
(...skipping 19 matching lines...) Expand all Loading... |
74 void applyRootMargin(LayoutRect&) const; | 65 void applyRootMargin(LayoutRect&) const; |
75 unsigned firstThresholdGreaterThan(float ratio) const; | 66 unsigned firstThresholdGreaterThan(float ratio) const; |
76 void deliver(); | 67 void deliver(); |
77 void removeObservation(IntersectionObservation&); | 68 void removeObservation(IntersectionObservation&); |
78 bool hasEntries() const { return m_entries.size(); } | 69 bool hasEntries() const { return m_entries.size(); } |
79 const HeapLinkedHashSet<WeakMember<IntersectionObservation>>& observations() | 70 const HeapLinkedHashSet<WeakMember<IntersectionObservation>>& observations() |
80 const { | 71 const { |
81 return m_observations; | 72 return m_observations; |
82 } | 73 } |
83 | 74 |
84 // Set the assumed initial state of the observed element. Note that this can | |
85 // only be set before calling observe(). | |
86 // TODO(skyostil): Move this setting to IntersectionObserverInit once the API | |
87 // is finalized. | |
88 void setInitialState(InitialState); | |
89 | |
90 DECLARE_TRACE(); | 75 DECLARE_TRACE(); |
91 | 76 |
92 private: | 77 private: |
93 explicit IntersectionObserver(IntersectionObserverCallback&, | 78 explicit IntersectionObserver(IntersectionObserverCallback&, |
94 Node&, | 79 Node&, |
95 const Vector<Length>& rootMargin, | 80 const Vector<Length>& rootMargin, |
96 const Vector<float>& thresholds); | 81 const Vector<float>& thresholds); |
97 void clearWeakMembers(Visitor*); | 82 void clearWeakMembers(Visitor*); |
98 | 83 |
99 Member<IntersectionObserverCallback> m_callback; | 84 Member<IntersectionObserverCallback> m_callback; |
100 WeakMember<Node> m_root; | 85 WeakMember<Node> m_root; |
101 HeapLinkedHashSet<WeakMember<IntersectionObservation>> m_observations; | 86 HeapLinkedHashSet<WeakMember<IntersectionObservation>> m_observations; |
102 HeapVector<Member<IntersectionObserverEntry>> m_entries; | 87 HeapVector<Member<IntersectionObserverEntry>> m_entries; |
103 Vector<float> m_thresholds; | 88 Vector<float> m_thresholds; |
104 Length m_topMargin; | 89 Length m_topMargin; |
105 Length m_rightMargin; | 90 Length m_rightMargin; |
106 Length m_bottomMargin; | 91 Length m_bottomMargin; |
107 Length m_leftMargin; | 92 Length m_leftMargin; |
108 InitialState m_initialState; | |
109 }; | 93 }; |
110 | 94 |
111 } // namespace blink | 95 } // namespace blink |
112 | 96 |
113 #endif // IntersectionObserver_h | 97 #endif // IntersectionObserver_h |
OLD | NEW |