| 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 c048c2a84ef2acfe3147c12a03e784e2e8c25046..3da5af86acb2575f97e21fe8d3beb87e4b979b6f 100644
|
| --- a/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
|
| +++ b/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
|
| @@ -9,11 +9,31 @@
|
| #include "core/dom/IntersectionObserver.h"
|
| #include "platform/heap/Heap.h"
|
| #include "platform/heap/Member.h"
|
| +#include "public/platform/WebRect.h"
|
|
|
| namespace blink {
|
|
|
| class Element;
|
|
|
| +// Base class for ElementVisibilityObserver and ViewportIntersectionObserver.
|
| +class VisibilityObserverBase
|
| + : public GarbageCollectedFinalized<VisibilityObserverBase> {
|
| + WTF_MAKE_NONCOPYABLE(VisibilityObserverBase);
|
| +
|
| + public:
|
| + explicit VisibilityObserverBase(Element*);
|
| + virtual ~VisibilityObserverBase();
|
| +
|
| + virtual void start() = 0;
|
| + void stop();
|
| +
|
| + DECLARE_VIRTUAL_TRACE();
|
| +
|
| + protected:
|
| + Member<Element> m_element;
|
| + Member<IntersectionObserver> m_intersectionObserver;
|
| +};
|
| +
|
| // 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
|
| @@ -24,33 +44,51 @@ class Element;
|
| // It is a layer meant to simplify the usage for C++ Blink code checking for the
|
| // visibility of an element.
|
| class CORE_EXPORT ElementVisibilityObserver final
|
| - : public GarbageCollectedFinalized<ElementVisibilityObserver> {
|
| + : public VisibilityObserverBase {
|
| WTF_MAKE_NONCOPYABLE(ElementVisibilityObserver);
|
|
|
| public:
|
| using VisibilityCallback = Function<void(bool), WTF::SameThreadAffinity>;
|
|
|
| ElementVisibilityObserver(Element*, std::unique_ptr<VisibilityCallback>);
|
| - virtual ~ElementVisibilityObserver();
|
| + ~ElementVisibilityObserver() final;
|
|
|
| - void start();
|
| - void stop();
|
| + void start() final;
|
|
|
| void deliverObservationsForTesting();
|
|
|
| - 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;
|
| };
|
|
|
| +// ViewportIntersectionObserver monitors the intersection between observed
|
| +// element and viewport. Creating an ViewportIntersectionObserver 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 the rootRect and the intersectRect as
|
| +// arguments.
|
| +class ViewportIntersectionObserver final : public VisibilityObserverBase {
|
| + WTF_MAKE_NONCOPYABLE(ViewportIntersectionObserver);
|
| +
|
| + public:
|
| + using RatioChangeCallback =
|
| + Function<void(const WebRect&, const WebRect&), WTF::SameThreadAffinity>;
|
| +
|
| + ViewportIntersectionObserver(Element*, std::unique_ptr<RatioChangeCallback>);
|
| + ~ViewportIntersectionObserver() final;
|
| +
|
| + void start() final;
|
| +
|
| + private:
|
| + void onVisibilityChanged(
|
| + const HeapVector<Member<IntersectionObserverEntry>>&);
|
| + std::unique_ptr<RatioChangeCallback> m_callback;
|
| +};
|
| +
|
| } // namespace blink
|
|
|
| #endif // ElementVisibilityObserver_h
|
|
|