Skip to content

Commit

Permalink
fix(ui): Ignore seek touch events on hidden controls
Browse files Browse the repository at this point in the history
When the controls are hidden, the seek bar should not respond to touch
events.  But since the seek bar is a child element of the controls
panel, it receives the touchstart event before the controls do.  So
there is no good opportunity to stop the propagation of the event.

I tried using the capturing phase of the event, but that didn't work.
So instead, we let the seek bar know if the controls are shown, and if
not, ignore touch and click events.

Further, I changed the mouseup, touchmove, and touchend event handlers
to ignore the events if the corresponding start event (mousedown or
touchstart) was ignored.  That way, you can't accidentally start a
drag operation while the controls are hidden.

Closes shaka-project#2888

Change-Id: I6ee393e3d631ad3d2a8f7314af692004240fb2bd
  • Loading branch information
joeyparrish committed Oct 1, 2020
1 parent 5ebbaef commit 5e559c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
12 changes: 6 additions & 6 deletions ui/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
*/
this.timeAndSeekRangeTimer_ = new shaka.util.Timer(() => {
// Suppress timer-based updates if the controls are hidden.
if (this.isOpaque_()) {
if (this.isOpaque()) {
this.updateTimeAndSeekRange_();
}
});
Expand Down Expand Up @@ -1040,7 +1040,7 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
// open.
this.hideSettingsMenusTimer_.stop();

if (!this.isOpaque_()) {
if (!this.isOpaque()) {
// Only update the time and seek range on mouse movement if it's the very
// first movement and we're about to show the controls. Otherwise, the
// seek bar will be updated much more rapidly during mouse movement. Do
Expand Down Expand Up @@ -1137,7 +1137,7 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
return;
}

if (this.isOpaque_()) {
if (this.isOpaque()) {
this.lastTouchEventTime_ = Date.now();
// The controls are showing.
// Let this event continue and become a click.
Expand Down Expand Up @@ -1268,9 +1268,9 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {

/**
* @return {boolean}
* @private
* @export
*/
isOpaque_() {
isOpaque() {
if (!this.enabled_) {
return false;
}
Expand All @@ -1287,7 +1287,7 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
*/
seek_(currentTime, event) {
this.video_.currentTime = currentTime;
if (this.isOpaque_()) {
if (this.isOpaque()) {
// Only update the time and seek range if it's visible.
this.updateTimeAndSeekRange_();
}
Expand Down
34 changes: 22 additions & 12 deletions ui/range_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,34 +64,44 @@ shaka.ui.RangeElement = class extends shaka.ui.Element {
this.parent.appendChild(this.container);

this.eventManager.listen(this.bar, 'mousedown', () => {
this.isChanging_ = true;
this.onChangeStart();
if (this.controls.isOpaque()) {
this.isChanging_ = true;
this.onChangeStart();
}
});

this.eventManager.listen(this.bar, 'touchstart', (e) => {
this.isChanging_ = true;
this.setBarValueForTouch_(e);
this.onChangeStart();
if (this.controls.isOpaque()) {
this.isChanging_ = true;
this.setBarValueForTouch_(e);
this.onChangeStart();
}
});

this.eventManager.listen(this.bar, 'input', () => {
this.onChange();
});

this.eventManager.listen(this.bar, 'touchmove', (e) => {
this.setBarValueForTouch_(e);
this.onChange();
if (this.isChanging_) {
this.setBarValueForTouch_(e);
this.onChange();
}
});

this.eventManager.listen(this.bar, 'touchend', (e) => {
this.isChanging_ = false;
this.setBarValueForTouch_(e);
this.onChangeEnd();
if (this.isChanging_) {
this.isChanging_ = false;
this.setBarValueForTouch_(e);
this.onChangeEnd();
}
});

this.eventManager.listen(this.bar, 'mouseup', () => {
this.isChanging_ = false;
this.onChangeEnd();
if (this.isChanging_) {
this.isChanging_ = false;
this.onChangeEnd();
}
});
}

Expand Down

0 comments on commit 5e559c3

Please sign in to comment.