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 next onRestored event should cause callbacks
22 * to be notified of a full-screen changed event. onRestored fires when
23 * full-screen mode is exited and also when the window is restored from
24 * being minimized; callbacks should not be notified of the latter.
27 this.notifyCallbacksOnRestore_ = this.isActive();
30 * @type {string} Internal 'full-screen changed' event name
33 this.kEventName_ = '_fullscreenchanged';
36 * @type {base.EventSource}
39 this.eventSource_ = new base.EventSource();
40 this.eventSource_.defineEvents([this.kEventName_]);
42 chrome.app.window.current().onFullscreened.addListener(
43 this.onFullscreened_.bind(this));
44 chrome.app.window.current().onRestored.addListener(
45 this.onRestored_.bind(this));
48 remoting.FullscreenAppsV2.prototype.activate = function(
49 fullscreen, opt_onDone) {
51 if (this.isActive() == fullscreen) {
54 /** @type {remoting.Fullscreen} */
56 var callbackAndRemoveListener = function() {
57 that.removeListener(callbackAndRemoveListener);
60 this.addListener(callbackAndRemoveListener);
65 chrome.app.window.current().fullscreen();
66 } else if (this.isActive()) {
67 chrome.app.window.current().restore();
71 remoting.FullscreenAppsV2.prototype.toggle = function() {
72 this.activate(!this.isActive());
75 remoting.FullscreenAppsV2.prototype.isActive = function() {
76 return chrome.app.window.current().isFullscreen();
79 remoting.FullscreenAppsV2.prototype.addListener = function(callback) {
80 this.eventSource_.addEventListener(this.kEventName_, callback);
83 remoting.FullscreenAppsV2.prototype.removeListener = function(callback) {
84 this.eventSource_.removeEventListener(this.kEventName_, callback);
87 remoting.FullscreenAppsV2.prototype.onFullscreened_ = function() {
88 this.notifyCallbacksOnRestore_ = true;
89 this.eventSource_.raiseEvent(this.kEventName_, true);
90 document.body.classList.add('fullscreen');
93 remoting.FullscreenAppsV2.prototype.onRestored_ = function() {
94 document.body.classList.remove('fullscreen');
95 if (this.notifyCallbacksOnRestore_) {
96 this.notifyCallbacksOnRestore_ = false;
97 this.eventSource_.raiseEvent(this.kEventName_, false);