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;
38 * @type {string} Internal 'full-screen changed' event name.
41 this.kEventName_ = '_fullscreenchanged';
44 * @type {base.EventSourceImpl}
47 this.eventSource_ = new base.EventSourceImpl();
48 this.eventSource_.defineEvents([this.kEventName_]);
50 chrome.app.window.current().onFullscreened.addListener(
51 this.onFullscreened_.bind(this));
52 chrome.app.window.current().onRestored.addListener(
53 this.onRestored_.bind(this));
54 chrome.app.window.current().onMinimized.addListener(
55 this.onMinimized_.bind(this));
57 document.body.classList.toggle('fullscreen', this.isActive());
61 * @param {boolean} fullscreen True to enter full-screen mode; false to leave.
62 * @param {function():void=} opt_onDone Optional completion callback.
64 remoting.FullscreenAppsV2.prototype.activate = function(
65 fullscreen, opt_onDone) {
67 if (this.isActive() == fullscreen) {
70 /** @type {remoting.Fullscreen} */
72 var callbackAndRemoveListener = function() {
73 that.removeListener(callbackAndRemoveListener);
76 this.addListener(callbackAndRemoveListener);
81 chrome.app.window.current().fullscreen();
82 } else if (this.isActive()) {
83 chrome.app.window.current().restore();
87 remoting.FullscreenAppsV2.prototype.toggle = function() {
88 this.activate(!this.isActive());
94 remoting.FullscreenAppsV2.prototype.isActive = function() {
95 return chrome.app.window.current().isFullscreen();
99 * @param {function(boolean=):void} callback
101 remoting.FullscreenAppsV2.prototype.addListener = function(callback) {
102 this.eventSource_.addEventListener(this.kEventName_, callback);
106 * @param {function(boolean=):void} callback
108 remoting.FullscreenAppsV2.prototype.removeListener = function(callback) {
109 this.eventSource_.removeEventListener(this.kEventName_, callback);
115 remoting.FullscreenAppsV2.prototype.onFullscreened_ = function() {
116 this.isMinimized_ = false;
117 this.raiseEvent_(true);
118 document.body.classList.add('fullscreen');
124 remoting.FullscreenAppsV2.prototype.onRestored_ = function() {
125 if (!this.isMinimized_) {
126 document.body.classList.remove('fullscreen');
127 this.raiseEvent_(false);
129 this.isMinimized_ = false;
135 remoting.FullscreenAppsV2.prototype.onMinimized_ = function() {
136 this.isMinimized_ = true;
140 * @param {boolean} isFullscreen
143 remoting.FullscreenAppsV2.prototype.raiseEvent_ = function(isFullscreen) {
144 if (isFullscreen !== this.previousCallbackState_) {
145 this.previousCallbackState_ = isFullscreen;
146 this.eventSource_.raiseEvent(this.kEventName_, isFullscreen);