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

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

Issue 2245613002: Revert "Simplify ElementVisibilityObserver implementation." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 7a01edf60e6d6df253ecac85d92d3483023c9fbc..be62f5bc2218b4f15e4215628d302ade4320001d 100644
--- a/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
+++ b/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
@@ -5,51 +5,44 @@
#ifndef ElementVisibilityObserver_h
#define ElementVisibilityObserver_h
-#include "core/CoreExport.h"
-#include "core/dom/IntersectionObserverCallback.h"
-#include "platform/heap/Handle.h"
+#include "core/dom/IntersectionObserver.h"
+#include "platform/heap/Heap.h"
+#include "platform/heap/Member.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; 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 {
+// 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:
- 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();
+ using VisibilityCallback = Function<void(bool), WTF::SameThreadAffinity>;
+
+ ElementVisibilityObserver(Element*, std::unique_ptr<VisibilityCallback>);
+ virtual ~ElementVisibilityObserver();
+ void start();
void stop();
- // IntersectionObserverCallback implementation:
- void handleEvent(const HeapVector<Member<IntersectionObserverEntry>>&, IntersectionObserver&) override;
- ExecutionContext* getExecutionContext() const override;
+ DECLARE_VIRTUAL_TRACE();
private:
- explicit ElementVisibilityObserver(Client*);
+ class ElementVisibilityCallback;
- void start(Element*);
+ void onVisibilityChanged(const HeapVector<Member<IntersectionObserverEntry>>&);
- Member<Client> m_client;
+ Member<Element> m_element;
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