Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / remoting / webapp / fullscreen_v2.js
blobafe2b4fb06f210ed8bf8ec45d0c4f3f59b251c4c
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.
5 /**
6  * @fileoverview
7  * Full-screen implementation for apps v2, using chrome.AppWindow.
8  */
10 'use strict';
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
15 /**
16  * @constructor
17  * @implements {remoting.Fullscreen}
18  */
19 remoting.FullscreenAppsV2 = function() {
20   /**
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.
25    * @private
26    */
27   this.notifyCallbacksOnRestore_ = this.isActive();
29   /**
30    * @type {string} Internal 'full-screen changed' event name
31    * @private
32    */
33   this.kEventName_ = '_fullscreenchanged';
35   /**
36    * @type {base.EventSource}
37    * @private
38    */
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) {
50   if (opt_onDone) {
51     if (this.isActive() == fullscreen) {
52       opt_onDone();
53     } else {
54       /** @type {remoting.Fullscreen} */
55       var that = this;
56       var callbackAndRemoveListener = function() {
57         that.removeListener(callbackAndRemoveListener);
58         opt_onDone();
59       };
60       this.addListener(callbackAndRemoveListener);
61     }
62   }
64   if (fullscreen) {
65     chrome.app.window.current().fullscreen();
66   } else if (this.isActive()) {
67     chrome.app.window.current().restore();
68   }
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);
98   }