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

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

Issue 1179223002: Implement autoplay gesture override experiment. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: linker errors on win/mac... Created 5 years, 4 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: Source/core/layout/LayoutMedia.cpp
diff --git a/Source/core/layout/LayoutMedia.cpp b/Source/core/layout/LayoutMedia.cpp
index 374c4b1889cb25e1e8043d9c099085f857c5906d..664ab2055fdddaf6043b83c4e7a6ff226197b390 100644
--- a/Source/core/layout/LayoutMedia.cpp
+++ b/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,61 @@ 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.
+ HTMLMediaElement* element = mediaElement();
+ if (element)
ojan 2015/09/01 20:20:11 Nit: Typical blink style is to do the following, s
liberato (no reviews please) 2015/09/04 06:49:46 never thought of that, thanks!
+ element->notifyPositionMayHaveChanged();
ojan 2015/09/01 20:20:11 How about having the LayoutMedia store a bit as to
liberato (no reviews please) 2015/09/04 06:49:46 i implemented the logic as you suggest. however,
+}
+
+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

Powered by Google App Engine
This is Rietveld 408576698