| 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..64ba35df717927d3520bd82d94d1c903c3793738 100644
|
| --- a/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
|
| +++ b/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
|
| @@ -9,11 +9,35 @@
|
| #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
|
| +// ElementViewportIntersectionObserver.
|
| +class CORE_EXPORT VisibilityObserverBase
|
| + : public GarbageCollectedFinalized<VisibilityObserverBase> {
|
| + WTF_MAKE_NONCOPYABLE(VisibilityObserverBase);
|
| +
|
| + public:
|
| + VisibilityObserverBase(Element*, const Vector<float>&);
|
| + virtual ~VisibilityObserverBase();
|
| +
|
| + virtual void onVisibilityChanged(
|
| + const HeapVector<Member<IntersectionObserverEntry>>& entries) = 0;
|
| + void start();
|
| + void stop();
|
| +
|
| + DECLARE_VIRTUAL_TRACE();
|
| +
|
| + protected:
|
| + Member<Element> m_element;
|
| + Vector<float> m_thresholds;
|
| + 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 +48,49 @@ 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();
|
| -
|
| - void start();
|
| - void stop();
|
| + ~ElementVisibilityObserver() final;
|
|
|
| void deliverObservationsForTesting();
|
|
|
| - DECLARE_VIRTUAL_TRACE();
|
| -
|
| private:
|
| class ElementVisibilityCallback;
|
|
|
| void onVisibilityChanged(
|
| - const HeapVector<Member<IntersectionObserverEntry>>&);
|
| -
|
| - Member<Element> m_element;
|
| - Member<IntersectionObserver> m_intersectionObserver;
|
| + const HeapVector<Member<IntersectionObserverEntry>>&) final;
|
| std::unique_ptr<VisibilityCallback> m_callback;
|
| };
|
|
|
| +// ElementViewportIntersectionObserver monitors the intersection between
|
| +// observed element and viewport.
|
| +// Creating an ElementViewportIntersectionObserver 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 ElementViewportIntersectionObserver final
|
| + : public VisibilityObserverBase {
|
| + WTF_MAKE_NONCOPYABLE(ElementViewportIntersectionObserver);
|
| +
|
| + public:
|
| + using RatioChangeCallback =
|
| + Function<void(const WebRect&, const WebRect&), WTF::SameThreadAffinity>;
|
| +
|
| + ElementViewportIntersectionObserver(Element*,
|
| + std::unique_ptr<RatioChangeCallback>);
|
| + ~ElementViewportIntersectionObserver() final;
|
| +
|
| + private:
|
| + void onVisibilityChanged(
|
| + const HeapVector<Member<IntersectionObserverEntry>>&) final;
|
| + std::unique_ptr<RatioChangeCallback> m_callback;
|
| +};
|
| +
|
| } // namespace blink
|
|
|
| #endif // ElementVisibilityObserver_h
|
|
|