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 v2, using chrome.AppWindow.
12 /** @suppress {duplicate} */
13 var remoting
= remoting
|| {};
17 * @implements {remoting.Fullscreen}
19 remoting
.FullscreenAppsV2 = function() {
21 * @type {boolean} True if the window is minimized. onRestored fires when the
22 * the window transitions from minimized to any other state, but since we
23 * only want transitions from full-screen to windowed to cause a callback,
24 * we must keep track of the minimized state of the window.
27 this.isMinimized_
= chrome
.app
.window
.current().isMinimized();
30 * @type {?boolean} The most recent full-screen state passed to the callback.
31 * This guards against redundant invocations, as as would otherwise occur
32 * in response to a full-screen -> maximized -> unmaximized transition,
33 * because this results in two onRestored callbacks.
35 this.previousCallbackState_
= null;
37 /** @private {string} Internal 'full-screen changed' event name. */
38 this.kEventName_
= '_fullscreenchanged';
40 /** @private {base.EventSourceImpl} */
41 this.eventSource_
= new base
.EventSourceImpl();
42 this.eventSource_
.defineEvents([this.kEventName_
]);
44 chrome
.app
.window
.current().onFullscreened
.addListener(
45 this.onFullscreened_
.bind(this));
46 chrome
.app
.window
.current().onRestored
.addListener(
47 this.onRestored_
.bind(this));
48 chrome
.app
.window
.current().onMinimized
.addListener(
49 this.onMinimized_
.bind(this));
51 document
.body
.classList
.toggle('fullscreen', this.isActive());
55 * @param {boolean} fullscreen True to enter full-screen mode; false to leave.
56 * @param {function():void=} opt_onDone Optional completion callback.
58 remoting
.FullscreenAppsV2
.prototype.activate = function(
59 fullscreen
, opt_onDone
) {
61 if (this.isActive() == fullscreen
) {
64 /** @type {remoting.Fullscreen} */
66 var callbackAndRemoveListener = function() {
67 that
.removeListener(callbackAndRemoveListener
);
70 this.addListener(callbackAndRemoveListener
);
75 chrome
.app
.window
.current().fullscreen();
76 } else if (this.isActive()) {
77 chrome
.app
.window
.current().restore();
81 remoting
.FullscreenAppsV2
.prototype.toggle = function() {
82 this.activate(!this.isActive());
88 remoting
.FullscreenAppsV2
.prototype.isActive = function() {
89 return chrome
.app
.window
.current().isFullscreen();
93 * @param {function(boolean=):void} callback
95 remoting
.FullscreenAppsV2
.prototype.addListener = function(callback
) {
96 this.eventSource_
.addEventListener(this.kEventName_
, callback
);
100 * @param {function(boolean=):void} callback
102 remoting
.FullscreenAppsV2
.prototype.removeListener = function(callback
) {
103 this.eventSource_
.removeEventListener(this.kEventName_
, callback
);
109 remoting
.FullscreenAppsV2
.prototype.onFullscreened_ = function() {
110 this.isMinimized_
= false;
111 this.raiseEvent_(true);
112 document
.body
.classList
.add('fullscreen');
118 remoting
.FullscreenAppsV2
.prototype.onRestored_ = function() {
119 if (!this.isMinimized_
) {
120 // ChromeOS fires a spurious onRestored event going maximized->fullscreen.
121 // TODO(jamiewalch): Remove this work-around when crbug.com/394819 is fixed.
122 if (remoting
.platformIsChromeOS() && this.isActive()) {
125 document
.body
.classList
.remove('fullscreen');
126 this.raiseEvent_(false);
128 this.isMinimized_
= false;
134 remoting
.FullscreenAppsV2
.prototype.onMinimized_ = function() {
135 this.isMinimized_
= true;
139 * @param {boolean} isFullscreen
142 remoting
.FullscreenAppsV2
.prototype.raiseEvent_ = function(isFullscreen
) {
143 if (isFullscreen
!== this.previousCallbackState_
) {
144 this.previousCallbackState_
= isFullscreen
;
145 this.eventSource_
.raiseEvent(this.kEventName_
, isFullscreen
);