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 maximize/restore events are being hooked.
24 this.hookingWindowEvents_ = false;
27 * @type {boolean} True if the next onRestored event should cause callbacks
28 * to be notified of a full-screen changed event. onRestored fires when
29 * full-screen mode is exited and also when the window is restored from
30 * being minimized; callbacks should not be notified of the latter.
33 this.notifyCallbacksOnRestore_ = this.isActive();
36 * @type {string} Internal 'full-screen changed' event name
39 this.kEventName_ = '_fullscreenchanged';
42 * @type {base.EventSource}
45 this.eventSource_ = new base.EventSource();
46 this.eventSource_.defineEvents([this.kEventName_]);
48 chrome.app.window.current().onFullscreened.addListener(
49 this.onFullscreened_.bind(this));
50 chrome.app.window.current().onMaximized.addListener(
51 this.onMaximized_.bind(this));
52 chrome.app.window.current().onRestored.addListener(
53 this.onRestored_.bind(this));
56 remoting.FullscreenAppsV2.prototype.activate = function(
57 fullscreen, opt_onDone) {
59 if (this.isActive() == fullscreen) {
62 /** @type {remoting.Fullscreen} */
64 var callbackAndRemoveListener = function() {
65 that.removeListener(callbackAndRemoveListener);
68 this.addListener(callbackAndRemoveListener);
73 chrome.app.window.current().fullscreen();
74 } else if (this.isActive()) {
75 chrome.app.window.current().restore();
79 remoting.FullscreenAppsV2.prototype.toggle = function() {
80 this.activate(!this.isActive());
83 remoting.FullscreenAppsV2.prototype.isActive = function() {
84 return chrome.app.window.current().isFullscreen();
87 remoting.FullscreenAppsV2.prototype.addListener = function(callback) {
88 this.eventSource_.addEventListener(this.kEventName_, callback);
91 remoting.FullscreenAppsV2.prototype.removeListener = function(callback) {
92 this.eventSource_.removeEventListener(this.kEventName_, callback);
95 remoting.FullscreenAppsV2.prototype.syncWithMaximize = function(sync) {
96 if (sync && chrome.app.window.current().isMaximized()) {
97 chrome.app.window.current().restore();
100 this.hookingWindowEvents_ = sync;
103 remoting.FullscreenAppsV2.prototype.onFullscreened_ = function() {
104 this.notifyCallbacksOnRestore_ = true;
105 this.eventSource_.raiseEvent(this.kEventName_, true);
106 document.body.classList.add('fullscreen');
109 remoting.FullscreenAppsV2.prototype.onMaximized_ = function() {
110 if (this.hookingWindowEvents_) {
111 chrome.app.window.current().restore();
116 remoting.FullscreenAppsV2.prototype.onRestored_ = function() {
117 // TODO(jamiewalch): ChromeOS generates a spurious onRestore event if
118 // fullscreen() is called from an onMaximized handler (crbug.com/394819),
119 // so ignore the callback if the window is still full-screen.
120 if (this.isActive()) {
124 document.body.classList.remove('fullscreen');
125 if (this.hookingWindowEvents_) {
126 this.activate(false);
128 if (this.notifyCallbacksOnRestore_) {
129 this.notifyCallbacksOnRestore_ = false;
130 this.eventSource_.raiseEvent(this.kEventName_, false);