Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: third_party/WebKit/Source/core/dom/IntersectionObserver.h

Issue 2272773002: Use intersection observer to control frame throttling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update LeakExpectations Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
36 static IntersectionObserver* create(const IntersectionObserverInit&, 45 static IntersectionObserver* create(const IntersectionObserverInit&,
37 IntersectionObserverCallback&, 46 IntersectionObserverCallback&,
38 ExceptionState&); 47 ExceptionState&);
39 static IntersectionObserver* create(const Vector<Length>& rootMargin, 48 static IntersectionObserver* create(const Vector<Length>& rootMargin,
40 const Vector<float>& thresholds, 49 const Vector<float>& thresholds,
41 Document*, 50 Document*,
42 std::unique_ptr<EventCallback>, 51 std::unique_ptr<EventCallback>,
43 ExceptionState& = ASSERT_NO_EXCEPTION); 52 ExceptionState& = ASSERT_NO_EXCEPTION);
44 static void resumeSuspendedObservers(); 53 static void resumeSuspendedObservers();
45 54
(...skipping 19 matching lines...) Expand all
65 void applyRootMargin(LayoutRect&) const; 74 void applyRootMargin(LayoutRect&) const;
66 unsigned firstThresholdGreaterThan(float ratio) const; 75 unsigned firstThresholdGreaterThan(float ratio) const;
67 void deliver(); 76 void deliver();
68 void removeObservation(IntersectionObservation&); 77 void removeObservation(IntersectionObservation&);
69 bool hasEntries() const { return m_entries.size(); } 78 bool hasEntries() const { return m_entries.size(); }
70 const HeapLinkedHashSet<WeakMember<IntersectionObservation>>& observations() 79 const HeapLinkedHashSet<WeakMember<IntersectionObservation>>& observations()
71 const { 80 const {
72 return m_observations; 81 return m_observations;
73 } 82 }
74 83
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
75 DECLARE_TRACE(); 90 DECLARE_TRACE();
76 91
77 private: 92 private:
78 explicit IntersectionObserver(IntersectionObserverCallback&, 93 explicit IntersectionObserver(IntersectionObserverCallback&,
79 Node&, 94 Node&,
80 const Vector<Length>& rootMargin, 95 const Vector<Length>& rootMargin,
81 const Vector<float>& thresholds); 96 const Vector<float>& thresholds);
82 void clearWeakMembers(Visitor*); 97 void clearWeakMembers(Visitor*);
83 98
84 Member<IntersectionObserverCallback> m_callback; 99 Member<IntersectionObserverCallback> m_callback;
85 WeakMember<Node> m_root; 100 WeakMember<Node> m_root;
86 HeapLinkedHashSet<WeakMember<IntersectionObservation>> m_observations; 101 HeapLinkedHashSet<WeakMember<IntersectionObservation>> m_observations;
87 HeapVector<Member<IntersectionObserverEntry>> m_entries; 102 HeapVector<Member<IntersectionObserverEntry>> m_entries;
88 Vector<float> m_thresholds; 103 Vector<float> m_thresholds;
89 Length m_topMargin; 104 Length m_topMargin;
90 Length m_rightMargin; 105 Length m_rightMargin;
91 Length m_bottomMargin; 106 Length m_bottomMargin;
92 Length m_leftMargin; 107 Length m_leftMargin;
108 InitialState m_initialState;
93 }; 109 };
94 110
95 } // namespace blink 111 } // namespace blink
96 112
97 #endif // IntersectionObserver_h 113 #endif // IntersectionObserver_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698