From d1dce29e896dcbe5d63434bd9bc5f2cbdf67e758 Mon Sep 17 00:00:00 2001 From: Theodore Abshire Date: Mon, 16 Mar 2020 08:58:18 -0700 Subject: [PATCH] Added 'doubleClickForFullscreen' config to UI. This configuration, which is true by default, lets a user optionally disable the "go fullscreen on double-click" functionality. This allows a developer to fully disable fullscreen mode, if they so wish, or to retain the fullscreen button but disable other methods of entering fullscreen. Issue #2459 Change-Id: I196602fc9843e0fd799c78703de60f864e906841 --- test/ui/ui_unit.js | 8 ++++++++ ui/controls.js | 7 +++++-- ui/externs/ui.js | 7 ++++++- ui/ui.js | 1 + 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/test/ui/ui_unit.js b/test/ui/ui_unit.js index fa98bc7f7..6e1041988 100644 --- a/test/ui/ui_unit.js +++ b/test/ui/ui_unit.js @@ -187,6 +187,7 @@ describe('UI', () => { overflowMenuButtons: [ 'quality', ], + doubleClickForFullscreen: false, }; const ui = UiUtils.createUIThroughAPI(videoContainer, video, config); const controls = ui.getControls(); @@ -195,6 +196,13 @@ describe('UI', () => { const controlsContainer = videoContainer.querySelector('.shaka-controls-container'); + // When double-click for fullscreen is disabled, it shouldn't happen. + UiUtils.simulateEvent(controlsContainer, 'dblclick'); + await Util.shortDelay(); + expect(spy).not.toHaveBeenCalled(); + // Change the configuration and try again. + config.doubleClickForFullscreen = true; + (/** @type {!shaka.ui.Overlay} */ (ui)).configure(config); UiUtils.simulateEvent(controlsContainer, 'dblclick'); await Util.shortDelay(); expect(spy).toHaveBeenCalledTimes(1); diff --git a/ui/controls.js b/ui/controls.js index efd674ad8..82e861b7e 100644 --- a/ui/controls.js +++ b/ui/controls.js @@ -854,8 +854,11 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget { // for focused elements. this.eventManager_.listen(window, 'keydown', (e) => this.onKeyDown_(e)); - this.eventManager_.listen( - this.controlsContainer_, 'dblclick', () => this.toggleFullScreen()); + this.eventManager_.listen(this.controlsContainer_, 'dblclick', () => { + if (this.config_.doubleClickForFullscreen) { + this.toggleFullScreen(); + } + }); this.eventManager_.listen(this.video_, 'play', () => { this.onPlayStateChange_(); diff --git a/ui/externs/ui.js b/ui/externs/ui.js index cf57517b1..d5252f25b 100644 --- a/ui/externs/ui.js +++ b/ui/externs/ui.js @@ -66,7 +66,8 @@ shaka.extern.UIVolumeBarColors; * seekBarColors: shaka.extern.UISeekBarColors, * volumeBarColors: shaka.extern.UIVolumeBarColors, * trackLabelFormat: shaka.ui.TrackLabelFormat, - * fadeDelay: number + * fadeDelay: number, + * doubleClickForFullscreen: boolean * }} * * @property {!Array.} controlPanelElements @@ -119,6 +120,10 @@ shaka.extern.UIVolumeBarColors; * interacting with them. We recommend setting this to 3 on your cast * receiver UI. * Defaults to 0. + * @property {boolean} doubleClickForFullscreen + * Whether or not double-clicking on the UI should cause it to enter + * fullscreen. + * Defaults to true. */ shaka.extern.UIConfiguration; diff --git a/ui/ui.js b/ui/ui.js index e9b99572e..81940ed5b 100644 --- a/ui/ui.js +++ b/ui/ui.js @@ -195,6 +195,7 @@ shaka.ui.Overlay = class { }, trackLabelFormat: shaka.ui.TrackLabelFormat.LANGUAGE, fadeDelay: 0, + doubleClickForFullscreen: true, }; // On mobile, by default, hide the volume slide and the small play/pause