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

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

Issue 2051253002: Start autoplay muted videos with autoplay attribute when they are visible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reduce Created 4 years, 6 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef ElementVisibilityObserver_h
6 #define ElementVisibilityObserver_h
7
8 #include "core/dom/IntersectionObserver.h"
9 #include "platform/heap/Heap.h"
10 #include "platform/heap/Member.h"
11
12 namespace blink {
13
14 class Element;
15
16 // ElementVisibilityObserver is a helper class to be used to track the
17 // visibility of an Element in the viewport. Creating an
18 // ElementVisibilityObserver is a no-op with regards to CPU cycle. The observing
19 // has be started by calling |start()| and can be stopped with |stop()|.
20 // When creating an instance, the caller will have to pass a callback taking
21 // a boolean as an argument. The boolean will be the new visibility state.
22 // The ElementVisibilityObserver is implemented on top of IntersectionObserver.
23 // It is a layer meant to simplify the usage for C++ Blink code checking for the
24 // visibility of an element.
25 class ElementVisibilityObserver final : public GarbageCollectedFinalized<Element VisibilityObserver> {
26 WTF_MAKE_NONCOPYABLE(ElementVisibilityObserver);
27 public:
28 using VisibilityCallback = Function<void(bool), WTF::SameThreadAffinity>;
29
30 ElementVisibilityObserver(Element*, std::unique_ptr<VisibilityCallback>);
31 virtual ~ElementVisibilityObserver();
32
33 void start();
34 void stop();
35
36 DECLARE_VIRTUAL_TRACE();
37
38 private:
39 class ElementVisibilityCallback;
40
41 void onVisibilityChanged(const HeapVector<Member<IntersectionObserverEntry>> &);
42
43 Member<Element> m_element;
44 Member<IntersectionObserver> m_intersectionObserver;
45 std::unique_ptr<VisibilityCallback> m_callback;
46 };
47
48 } // namespace blink
49
50 #endif // ElementVisibilityObserver_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/core.gypi ('k') | third_party/WebKit/Source/core/dom/ElementVisibilityObserver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698