1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * Full-screen implementation for apps v1, using webkitRequestFullscreen.
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
17 * @implements {remoting.Fullscreen}
19 remoting.FullscreenAppsV1 = function() {
21 * @type {string} Internal 'full-screen changed' event name
24 this.kEventName_ = '_fullscreenchanged';
27 * @type {base.EventSourceImpl}
30 this.eventSource_ = new base.EventSourceImpl();
31 this.eventSource_.defineEvents([this.kEventName_]);
33 document.addEventListener(
34 'webkitfullscreenchange',
35 this.onFullscreenChanged_.bind(this),
39 remoting.FullscreenAppsV1.prototype.activate = function(
40 fullscreen, opt_onDone) {
42 if (this.isActive() == fullscreen) {
45 /** @type {remoting.Fullscreen} */
47 var callbackAndRemoveListener = function() {
48 that.removeListener(callbackAndRemoveListener);
51 this.addListener(callbackAndRemoveListener);
56 document.body.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
58 document.webkitCancelFullScreen();
63 remoting.FullscreenAppsV1.prototype.toggle = function() {
64 this.activate(!this.isActive());
68 * @return {boolean} True if full-screen mode is active.
70 remoting.FullscreenAppsV1.prototype.isActive = function() {
71 return document.webkitIsFullScreen;
75 * @param {function(boolean=):void} callback
77 remoting.FullscreenAppsV1.prototype.addListener = function(callback) {
78 this.eventSource_.addEventListener(this.kEventName_, callback);
82 * @param {function(boolean=):void} callback
84 remoting.FullscreenAppsV1.prototype.removeListener = function(callback) {
85 this.eventSource_.removeEventListener(this.kEventName_, callback);
91 remoting.FullscreenAppsV1.prototype.onFullscreenChanged_ = function() {
92 /** @this {remoting.FullscreenAppsV1} */
93 var checkIsActive = function() {
94 if (this.isActive()) {
95 document.body.classList.add('fullscreen');
97 document.body.classList.remove('fullscreen');
99 this.eventSource_.raiseEvent(this.kEventName_, this.isActive());
102 // Querying full-screen immediately after the webkitfullscreenchange
103 // event fires sometimes gives the wrong answer on Mac, perhaps due to
104 // the time taken to animate presentation mode. Since I haven't been able
105 // to isolate the exact repro steps, and we're not planning on using this
106 // API for much longer, this hack will suffice for now.
107 window.setTimeout(checkIsActive.bind(this), 500);