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

Unified Diff: third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h

Issue 2173353002: Simplify ElementVisibilityObserver implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adjust visibility Created 4 years, 5 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/ElementVisibilityObserver.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index be62f5bc2218b4f15e4215628d302ade4320001d..7a01edf60e6d6df253ecac85d92d3483023c9fbc 100644
--- a/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
+++ b/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
@@ -5,44 +5,51 @@
#ifndef ElementVisibilityObserver_h
#define ElementVisibilityObserver_h
-#include "core/dom/IntersectionObserver.h"
-#include "platform/heap/Heap.h"
-#include "platform/heap/Member.h"
+#include "core/CoreExport.h"
+#include "core/dom/IntersectionObserverCallback.h"
+#include "platform/heap/Handle.h"
namespace blink {
class Element;
+class IntersectionObserver;
+class IntersectionObserverEntry;
// 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> {
+// visibility of an Element in the viewport; it is implemented on top of
+// IntersectionObserver.
+//
+// When creating an ElementVisibilityObserver instance, alongside the element
+// reference, the caller will have to supply an object reference implementing
+// the |Client| interface and its |onVisibilityChanged| method. The callback
+// method will be invoked when the element changes visibility state,
+// the boolean argument indicating which.
+class ElementVisibilityObserver final : public IntersectionObserverCallback {
WTF_MAKE_NONCOPYABLE(ElementVisibilityObserver);
public:
- using VisibilityCallback = Function<void(bool), WTF::SameThreadAffinity>;
-
- ElementVisibilityObserver(Element*, std::unique_ptr<VisibilityCallback>);
- virtual ~ElementVisibilityObserver();
+ class CORE_EXPORT Client : public GarbageCollectedMixin {
+ public:
+ virtual void onVisibilityChanged(bool isVisible) = 0;
+ virtual ExecutionContext* getElementVisibilityExecutionContext() const = 0;
+ };
+
+ static ElementVisibilityObserver* create(Element*, Client*);
+ ~ElementVisibilityObserver();
+ DECLARE_VIRTUAL_TRACE();
- void start();
void stop();
- DECLARE_VIRTUAL_TRACE();
+ // IntersectionObserverCallback implementation:
+ void handleEvent(const HeapVector<Member<IntersectionObserverEntry>>&, IntersectionObserver&) override;
+ ExecutionContext* getExecutionContext() const override;
private:
- class ElementVisibilityCallback;
+ explicit ElementVisibilityObserver(Client*);
- void onVisibilityChanged(const HeapVector<Member<IntersectionObserverEntry>>&);
+ void start(Element*);
- Member<Element> m_element;
+ Member<Client> m_client;
Member<IntersectionObserver> m_intersectionObserver;
- std::unique_ptr<VisibilityCallback> m_callback;
};
} // namespace blink
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/ElementVisibilityObserver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698