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

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

Issue 2475643004: Monitor the intersection of video and viewport. (Closed)
Patch Set: Addressed miu's comments. Created 4 years, 1 month 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
index c048c2a84ef2acfe3147c12a03e784e2e8c25046..85ce0c60becd6d295f1418ddbf6ebf1b4d180543 100644
--- a/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
+++ b/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
@@ -14,6 +14,25 @@ namespace blink {
class Element;
+// Base class for ElementVisibilityObserver and ElementViewportRatioObserver.
+class VisibilityObserverBase
+ : public GarbageCollectedFinalized<VisibilityObserverBase> {
+ WTF_MAKE_NONCOPYABLE(VisibilityObserverBase);
+
+ public:
+ VisibilityObserverBase(Element*);
miu 2016/11/11 08:18:33 Add 'explicit' keyword.
xjz 2016/11/11 17:57:48 Done.
+ 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 +43,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();
+ ~ElementVisibilityObserver() override;
miu 2016/11/11 08:18:33 Since these subclasses are final, should all the '
xjz 2016/11/11 17:57:48 Done.
- void start();
- void stop();
+ void start() override;
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;
};
+// ElementViewportRatioObserver monitors the element/viewport ratio. Creating an
+// ElementViewportRatioObserver 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 float as an argument. The float is the new element/viewport ratio.
+class ElementViewportRatioObserver final : public VisibilityObserverBase {
+ WTF_MAKE_NONCOPYABLE(ElementViewportRatioObserver);
+
+ public:
+ using RatioChangeCallback = Function<void(float), WTF::SameThreadAffinity>;
+
+ ElementViewportRatioObserver(Element*, std::unique_ptr<RatioChangeCallback>);
+ ~ElementViewportRatioObserver() override;
+
+ void start() override;
+
+ private:
+ void onVisibilityChanged(
+ const HeapVector<Member<IntersectionObserverEntry>>&);
+ std::unique_ptr<RatioChangeCallback> m_callback;
+};
+
} // namespace blink
#endif // ElementVisibilityObserver_h

Powered by Google App Engine
This is Rietveld 408576698