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

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

Issue 2475643004: Monitor the intersection of video and viewport. (Closed)
Patch Set: Add ElementViewportRatioObserver. 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..fc612a50402ef7b44717b5a6cfc59051871b9059 100644
--- a/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
+++ b/third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h
@@ -17,13 +17,13 @@ class Element;
// 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()|.
+// has be started by calling |start()| 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 CORE_EXPORT ElementVisibilityObserver final
+class CORE_EXPORT ElementVisibilityObserver
: public GarbageCollectedFinalized<ElementVisibilityObserver> {
WTF_MAKE_NONCOPYABLE(ElementVisibilityObserver);
@@ -38,17 +38,37 @@ class CORE_EXPORT ElementVisibilityObserver final
void deliverObservationsForTesting();
+ float ratio() { return m_ratio; }
+
DECLARE_VIRTUAL_TRACE();
+ protected:
+ void startObserveElementViewportRatio();
miu 2016/11/09 22:02:07 Instead of the separate method, you should make st
xjz 2016/11/11 01:07:29 Done.
+
private:
class ElementVisibilityCallback;
void onVisibilityChanged(
const HeapVector<Member<IntersectionObserverEntry>>&);
+ void startInternal(bool isObservingElementViewportRatio);
Member<Element> m_element;
Member<IntersectionObserver> m_intersectionObserver;
std::unique_ptr<VisibilityCallback> m_callback;
+ float m_ratio = 0;
+};
+
+// ElementViewportRatioObserver monitors both the visibilty of the element and
+// the element/viewport ratio. 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. Caller can call ratio() at any time to get current
+// element/viewport ratio.
+class ElementViewportRatioObserver : public ElementVisibilityObserver {
+ WTF_MAKE_NONCOPYABLE(ElementViewportRatioObserver);
+
+ public:
+ ElementViewportRatioObserver(Element*, std::unique_ptr<VisibilityCallback>);
miu 2016/11/09 22:02:07 Reading this subclass's usage comments, it seems l
xjz 2016/11/11 01:07:29 Done.
+ void start();
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698