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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
diff --git a/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h b/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
new file mode 100644
index 0000000000000000000000000000000000000000..be62f5bc2218b4f15e4215628d302ade4320001d
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
@@ -0,0 +1,50 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ElementVisibilityObserver_h
+#define ElementVisibilityObserver_h
+
+#include "core/dom/IntersectionObserver.h"
+#include "platform/heap/Heap.h"
+#include "platform/heap/Member.h"
+
+namespace blink {
+
+class Element;
+
+// ElementVisibilityObserver is a helper class to be used to track the
+// visibility of an Element in the viewport. Creating an
+// ElementVisibilityObserver is a no-op with regards to CPU cycle. The observing
+// has be started by calling |start()| and can be stopped with |stop()|.
+// When creating an instance, the caller will have to pass a callback taking
+// a boolean as an argument. The boolean will be the new visibility state.
+// The ElementVisibilityObserver is implemented on top of IntersectionObserver.
+// It is a layer meant to simplify the usage for C++ Blink code checking for the
+// visibility of an element.
+class ElementVisibilityObserver final : public GarbageCollectedFinalized<ElementVisibilityObserver> {
+ WTF_MAKE_NONCOPYABLE(ElementVisibilityObserver);
+public:
+ using VisibilityCallback = Function<void(bool), WTF::SameThreadAffinity>;
+
+ ElementVisibilityObserver(Element*, std::unique_ptr<VisibilityCallback>);
+ virtual ~ElementVisibilityObserver();
+
+ void start();
+ void stop();
+
+ DECLARE_VIRTUAL_TRACE();
+
+private:
+ class ElementVisibilityCallback;
+
+ void onVisibilityChanged(const HeapVector<Member<IntersectionObserverEntry>>&);
+
+ Member<Element> m_element;
+ Member<IntersectionObserver> m_intersectionObserver;
+ std::unique_ptr<VisibilityCallback> m_callback;
+};
+
+} // namespace blink
+
+#endif // ElementVisibilityObserver_h
« 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