Commit daaf59e8 authored by Tommy Steimel's avatar Tommy Steimel Committed by Commit Bot

Cancel scrubbing when the Media Controls are hidden

This CL adds logic to cancel all scrubbing state in MediaControlsImpl
and MediaControlTimelineElement when the controls are hidden. This fixes
a bug where if the controls were hidden while scrubbing, the timeline
would continue to handle touchmove events and scrub.

Bug: 810313
Change-Id: Iaa14e559e2f0b077df0d50043bb148bfb195a7a1
Reviewed-on: https://chromium-review.googlesource.com/912113Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537362}
parent 4f8aac4c
<!DOCTYPE html>
<title>Tests that scrubbing stops when the controls are hidden.</title>
<script src='../../../resources/testharness.js'></script>
<script src='../../../resources/testharnessreport.js'></script>
<script src='../../media-controls.js'></script>
<video controls width=400 src="../../content/60_sec_video.webm"></video>
<script>
async_test(t => {
let video = document.querySelector('video');
const thumb = timelineThumb(video);
const MOVEMENT_X = 50;
let thumbPosition;
video.onloadedmetadata = t.step_func(() => {
// Should not be initially scrubbing.
expectNotScrubbing();
thumbPosition = elementCoordinates(thumb);
mouseDownOnThumb();
});
function mouseDownOnThumb() {
// Should be scrubbing on mousedown on thumb.
chrome.gpuBenchmarking.pointerActionSequence([
{
source: 'mouse',
actions: [
{ name: 'pointerMove', x: thumbPosition[0], y: thumbPosition[1] },
{ name: 'pointerDown', x: thumbPosition[0], y: thumbPosition[1], button: 'left' },
]
}
], t.step_func(() => {
expectScrubbing();
mouseMoveWithControls();
}));
}
function mouseMoveWithControls() {
// Should be scrubbing on mousemove.
thumbPosition[0] += MOVEMENT_X;
chrome.gpuBenchmarking.pointerActionSequence([
{
source: 'mouse',
actions: [
{ name: 'pointerMove', x: thumbPosition[0], y: thumbPosition[1] },
]
}
], t.step_func(() => {
expectScrubbing();
removeControls();
}));
}
function removeControls() {
// Should not be scrubbing if the controls are removed.
video.controls = false;
expectNotScrubbing();
mouseMoveWithoutControls();
}
function mouseMoveWithoutControls() {
// Should still not be scrubbing if the mouse continues to move.
thumbPosition[0] += MOVEMENT_X;
chrome.gpuBenchmarking.pointerActionSequence([
{
source: 'mouse',
actions: [
{ name: 'pointerMove', x: thumbPosition[0], y: thumbPosition[1] },
]
}
], t.step_func_done(expectNotScrubbing));
}
function expectScrubbing() {
checkControlsClassName(video, 'phase-ready state-scrubbing');
}
function expectNotScrubbing() {
checkControlsClassName(video, 'phase-ready state-stopped');
}
});
</script>
......@@ -785,6 +785,8 @@ void MediaControlsImpl::MaybeShow() {
download_iph_manager_->SetControlsVisibility(true);
if (loading_panel_)
loading_panel_->OnControlsShown();
timeline_->OnControlsShown();
}
void MediaControlsImpl::Hide() {
......@@ -801,6 +803,13 @@ void MediaControlsImpl::Hide() {
download_iph_manager_->SetControlsVisibility(false);
if (loading_panel_)
loading_panel_->OnControlsHidden();
// Cancel scrubbing if necessary.
if (is_scrubbing_) {
is_paused_for_scrubbing_ = false;
EndScrubbing();
}
timeline_->OnControlsHidden();
}
bool MediaControlsImpl::IsVisible() const {
......
......@@ -129,7 +129,7 @@ const char* MediaControlTimelineElement::GetNameForHistograms() const {
}
void MediaControlTimelineElement::DefaultEventHandler(Event* event) {
if (!isConnected() || !GetDocument().IsActive())
if (!isConnected() || !GetDocument().IsActive() || controls_hidden_)
return;
RenderBarSegments();
......@@ -308,11 +308,25 @@ bool MediaControlTimelineElement::BeginScrubbingEvent(Event& event) {
return false;
}
void MediaControlTimelineElement::OnControlsHidden() {
controls_hidden_ = true;
// End scrubbing state.
is_touching_ = false;
if (current_time_display_)
current_time_display_->SetIsWanted(false);
}
void MediaControlTimelineElement::OnControlsShown() {
controls_hidden_ = false;
}
bool MediaControlTimelineElement::EndScrubbingEvent(Event& event) {
if (is_touching_) {
if (event.type() == EventTypeNames::touchend ||
event.type() == EventTypeNames::touchcancel ||
event.type() == EventTypeNames::change) {
is_touching_ = false;
return true;
}
} else if (event.type() == EventTypeNames::pointerup ||
......
......@@ -34,6 +34,10 @@ class MediaControlTimelineElement : public MediaControlSliderElement {
void RenderBarSegments();
// Inform the timeline that the Media Controls have been shown or hidden.
void OnControlsShown();
void OnControlsHidden();
virtual void Trace(blink::Visitor*);
protected:
......@@ -55,6 +59,8 @@ class MediaControlTimelineElement : public MediaControlSliderElement {
Member<MediaControlCurrentTimeDisplayElement> current_time_display_;
bool is_touching_ = false;
bool controls_hidden_ = false;
};
} // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment