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

Unified Diff: Source/core/html/shadow/MediaControls.cpp

Issue 297783004: Implement heuristic for showing media controls during playback w/o a mouse (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: IgnoreSelfHover -> IgnoreVideoHover; Tweak comment. Created 6 years, 7 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/html/shadow/MediaControls.cpp
diff --git a/Source/core/html/shadow/MediaControls.cpp b/Source/core/html/shadow/MediaControls.cpp
index 4801e1e3bc137203e361f374efae43725644572a..dac9850f4023345e50f241bf45999f5dc2adcf34 100644
--- a/Source/core/html/shadow/MediaControls.cpp
+++ b/Source/core/html/shadow/MediaControls.cpp
@@ -191,6 +191,12 @@ void MediaControls::show()
m_panel->show();
}
+void MediaControls::mediaElementFocused()
+{
+ show();
+ stopHideMediaControlsTimer();
+}
+
void MediaControls::hide()
{
m_panel->setIsDisplayed(false);
@@ -207,9 +213,22 @@ void MediaControls::makeTransparent()
m_panel->makeTransparent();
}
-bool MediaControls::shouldHideMediaControls()
+bool MediaControls::shouldHideMediaControls(unsigned behaviorFlags) const
{
- return !m_panel->hovered() && mediaElement().hasVideo();
+ // Never hide for a media element without visual representation.
+ if (!mediaElement().hasVideo())
+ return false;
+ // Don't hide if the controls are hovered or the mouse is over the video area.
+ const bool ignoreVideoHover = behaviorFlags & IgnoreVideoHover;
+ if (m_panel->hovered() || (!ignoreVideoHover && m_isMouseOverControls))
+ return false;
+ // Don't hide if focus is on the HTMLMediaElement or within the
+ // controls/shadow tree. (Perform the checks separately to avoid going
+ // through all the potential ancestor hosts for the focused element.)
+ const bool ignoreFocus = behaviorFlags & IgnoreFocus;
+ if (!ignoreFocus && (mediaElement().focused() || contains(document().focusedElement())))
+ return false;
+ return true;
}
void MediaControls::playbackStarted()
@@ -229,7 +248,7 @@ void MediaControls::playbackProgressed()
m_timeline->setPosition(mediaElement().currentTime());
updateCurrentTimeDisplay();
- if (!m_isMouseOverControls && mediaElement().hasVideo())
+ if (shouldHideMediaControls())
makeTransparent();
}
@@ -358,7 +377,7 @@ void MediaControls::defaultEventHandler(Event* event)
// When we get a mouse move, show the media controls, and start a timer
// that will hide the media controls after a 3 seconds without a mouse move.
makeOpaque();
- if (shouldHideMediaControls())
+ if (shouldHideMediaControls(IgnoreVideoHover))
startHideMediaControlsTimer();
return;
}
@@ -369,7 +388,7 @@ void MediaControls::hideMediaControlsTimerFired(Timer<MediaControls>*)
if (mediaElement().togglePlayStateWillPlay())
return;
- if (!shouldHideMediaControls())
+ if (!shouldHideMediaControls(IgnoreFocus | IgnoreVideoHover))
return;
makeTransparent();

Powered by Google App Engine
This is Rietveld 408576698