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

Unified Diff: third_party/WebKit/Source/core/layout/LayoutMedia.cpp

Issue 1329853004: Include viewport visibility checks for autoplay experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@autoplay_step1
Patch Set: Rebased onto merged blink repo. Created 5 years, 3 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
Index: third_party/WebKit/Source/core/layout/LayoutMedia.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutMedia.cpp b/third_party/WebKit/Source/core/layout/LayoutMedia.cpp
index 374c4b1889cb25e1e8043d9c099085f857c5906d..4d7740e9711694e47f555bef52e71af1825defba 100644
--- a/third_party/WebKit/Source/core/layout/LayoutMedia.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutMedia.cpp
@@ -35,6 +35,8 @@ namespace blink {
LayoutMedia::LayoutMedia(HTMLMediaElement* video)
: LayoutImage(video)
+ , m_registeredForPositionChangeNotifications(false)
+ , m_wantPositionChangeNotifications(false)
{
setImageResource(LayoutImageResource::create());
}
@@ -119,4 +121,60 @@ void LayoutMedia::paintReplaced(const PaintInfo&, const LayoutPoint&)
{
}
+void LayoutMedia::willBeDestroyed()
+{
+ updatePositionChangeRegistration(false);
+ LayoutImage::willBeDestroyed();
+}
+
+void LayoutMedia::insertedIntoTree()
+{
+ LayoutImage::insertedIntoTree();
+
+ // Note that if we don't want them and aren't registered, then this
+ // will do nothing.
+ updatePositionChangeRegistration(m_wantPositionChangeNotifications);
+}
+
+void LayoutMedia::willBeRemovedFromTree()
+{
+ // Note that if we don't want them and/or aren't registered, then this
+ // will do nothing.
+ updatePositionChangeRegistration(false);
+
+ LayoutImage::willBeRemovedFromTree();
+}
+
+void LayoutMedia::notifyPositionMayHaveChanged()
+{
+ // Tell our element about it.
+ if (HTMLMediaElement* element = mediaElement())
+ element->notifyPositionMayHaveChanged();
+}
+
+void LayoutMedia::updatePositionChangeRegistration(bool doRegister)
+{
+ // If we don't have a view, then take no action.
+ if (!view())
+ return;
+
+ // If our registration state matches the incoming state, then no work
+ // is needed.
+ if (doRegister == m_registeredForPositionChangeNotifications)
+ return;
+
+ if (doRegister)
+ view()->registerMediaForPositionChangeNotification(this);
+ else
+ view()->unregisterMediaForPositionChangeNotification(this);
+
+ m_registeredForPositionChangeNotifications = doRegister;
+}
+
+void LayoutMedia::setRequestPositionUpdates(bool want)
+{
+ m_wantPositionChangeNotifications = want;
+ updatePositionChangeRegistration(m_wantPositionChangeNotifications);
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutMedia.h ('k') | third_party/WebKit/Source/core/layout/LayoutVideo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698