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() {
20 /** @private {string} Internal 'full-screen changed' event name */
21 this.kEventName_
= '_fullscreenchanged';
23 /** @private {base.EventSourceImpl} */
24 this.eventSource_
= new base
.EventSourceImpl();
25 this.eventSource_
.defineEvents([this.kEventName_
]);
27 document
.addEventListener(
28 'webkitfullscreenchange',
29 this.onFullscreenChanged_
.bind(this),
33 remoting
.FullscreenAppsV1
.prototype.activate = function(
34 fullscreen
, opt_onDone
) {
36 if (this.isActive() == fullscreen
) {
39 /** @type {remoting.Fullscreen} */
41 var callbackAndRemoveListener = function() {
42 that
.removeListener(callbackAndRemoveListener
);
45 this.addListener(callbackAndRemoveListener
);
50 document
.body
.webkitRequestFullScreen(Element
.ALLOW_KEYBOARD_INPUT
);
52 document
.webkitCancelFullScreen();
57 remoting
.FullscreenAppsV1
.prototype.toggle = function() {
58 this.activate(!this.isActive());
62 * @return {boolean} True if full-screen mode is active.
64 remoting
.FullscreenAppsV1
.prototype.isActive = function() {
65 return document
.webkitIsFullScreen
;
69 * @param {function(boolean=):void} callback
71 remoting
.FullscreenAppsV1
.prototype.addListener = function(callback
) {
72 this.eventSource_
.addEventListener(this.kEventName_
, callback
);
76 * @param {function(boolean=):void} callback
78 remoting
.FullscreenAppsV1
.prototype.removeListener = function(callback
) {
79 this.eventSource_
.removeEventListener(this.kEventName_
, callback
);
85 remoting
.FullscreenAppsV1
.prototype.onFullscreenChanged_ = function() {
86 /** @this {remoting.FullscreenAppsV1} */
87 var checkIsActive = function() {
88 if (this.isActive()) {
89 document
.body
.classList
.add('fullscreen');
91 document
.body
.classList
.remove('fullscreen');
93 this.eventSource_
.raiseEvent(this.kEventName_
, this.isActive());
96 // Querying full-screen immediately after the webkitfullscreenchange
97 // event fires sometimes gives the wrong answer on Mac, perhaps due to
98 // the time taken to animate presentation mode. Since I haven't been able
99 // to isolate the exact repro steps, and we're not planning on using this
100 // API for much longer, this hack will suffice for now.
101 window
.setTimeout(checkIsActive
.bind(this), 500);