Chromium Code Reviews| 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. AUTO means the initial observation will always get sent. | |
| 39 enum class InitialState { | |
| 40 // TODO(skyostil): Add support for HIDDEN and VISIBLE. | |
| 41 AUTO | |
|
ojan
2016/10/31 19:37:09
The new enum naming style would be kAuto now I thi
Sami
2016/11/01 10:44:48
Done.
| |
| 42 }; | |
| 43 | |
| 36 static IntersectionObserver* create(const IntersectionObserverInit&, | 44 static IntersectionObserver* create(const IntersectionObserverInit&, |
| 37 IntersectionObserverCallback&, | 45 IntersectionObserverCallback&, |
| 38 ExceptionState&); | 46 ExceptionState&); |
| 39 static IntersectionObserver* create(const Vector<Length>& rootMargin, | 47 static IntersectionObserver* create(const Vector<Length>& rootMargin, |
| 40 const Vector<float>& thresholds, | 48 const Vector<float>& thresholds, |
| 41 Document*, | 49 Document*, |
| 42 std::unique_ptr<EventCallback>, | 50 std::unique_ptr<EventCallback>, |
| 43 ExceptionState& = ASSERT_NO_EXCEPTION); | 51 ExceptionState& = ASSERT_NO_EXCEPTION); |
| 44 static void resumeSuspendedObservers(); | 52 static void resumeSuspendedObservers(); |
| 45 | 53 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 64 void enqueueIntersectionObserverEntry(IntersectionObserverEntry&); | 72 void enqueueIntersectionObserverEntry(IntersectionObserverEntry&); |
| 65 void applyRootMargin(LayoutRect&) const; | 73 void applyRootMargin(LayoutRect&) const; |
| 66 unsigned firstThresholdGreaterThan(float ratio) const; | 74 unsigned firstThresholdGreaterThan(float ratio) const; |
| 67 void deliver(); | 75 void deliver(); |
| 68 void removeObservation(IntersectionObservation&); | 76 void removeObservation(IntersectionObservation&); |
| 69 bool hasEntries() const { return m_entries.size(); } | 77 bool hasEntries() const { return m_entries.size(); } |
| 70 const HeapLinkedHashSet<WeakMember<IntersectionObservation>>& observations() | 78 const HeapLinkedHashSet<WeakMember<IntersectionObservation>>& observations() |
| 71 const { | 79 const { |
| 72 return m_observations; | 80 return m_observations; |
| 73 } | 81 } |
| 82 // TODO(skyostil): Move this setting to IntersectionObserverInit once the API | |
| 83 // is finalized. | |
| 84 void setInitialState(InitialState); | |
| 74 | 85 |
| 75 DECLARE_TRACE(); | 86 DECLARE_TRACE(); |
| 76 | 87 |
| 77 private: | 88 private: |
| 78 explicit IntersectionObserver(IntersectionObserverCallback&, | 89 explicit IntersectionObserver(IntersectionObserverCallback&, |
| 79 Node&, | 90 Node&, |
| 80 const Vector<Length>& rootMargin, | 91 const Vector<Length>& rootMargin, |
| 81 const Vector<float>& thresholds); | 92 const Vector<float>& thresholds); |
| 82 void clearWeakMembers(Visitor*); | 93 void clearWeakMembers(Visitor*); |
| 83 | 94 |
| 84 Member<IntersectionObserverCallback> m_callback; | 95 Member<IntersectionObserverCallback> m_callback; |
| 85 WeakMember<Node> m_root; | 96 WeakMember<Node> m_root; |
| 86 HeapLinkedHashSet<WeakMember<IntersectionObservation>> m_observations; | 97 HeapLinkedHashSet<WeakMember<IntersectionObservation>> m_observations; |
| 87 HeapVector<Member<IntersectionObserverEntry>> m_entries; | 98 HeapVector<Member<IntersectionObserverEntry>> m_entries; |
| 88 Vector<float> m_thresholds; | 99 Vector<float> m_thresholds; |
| 89 Length m_topMargin; | 100 Length m_topMargin; |
| 90 Length m_rightMargin; | 101 Length m_rightMargin; |
| 91 Length m_bottomMargin; | 102 Length m_bottomMargin; |
| 92 Length m_leftMargin; | 103 Length m_leftMargin; |
| 93 }; | 104 }; |
| 94 | 105 |
| 95 } // namespace blink | 106 } // namespace blink |
| 96 | 107 |
| 97 #endif // IntersectionObserver_h | 108 #endif // IntersectionObserver_h |
| OLD | NEW |