OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Full-screen implementation for apps v2, using chrome.AppWindow. | 7 * Full-screen implementation for apps v2, using chrome.AppWindow. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
11 | 11 |
12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
14 | 14 |
15 /** | 15 /** |
16 * @constructor | 16 * @constructor |
17 * @implements {remoting.Fullscreen} | 17 * @implements {remoting.Fullscreen} |
18 */ | 18 */ |
19 remoting.FullscreenAppsV2 = function() { | 19 remoting.FullscreenAppsV2 = function() { |
20 /** | 20 /** |
21 * @type {boolean} True if the next onRestored event should cause callbacks | 21 * @type {boolean} True if the window is minimized. onRestored fires when the |
22 * to be notified of a full-screen changed event. onRestored fires when | 22 * the window transitions from minimized to any other state, but since we |
23 * full-screen mode is exited and also when the window is restored from | 23 * only want transitions from full-screen to windowed to cause a callback, |
kelvinp
2015/01/22 17:42:08
s/cause/call
Jamie
2015/01/22 23:27:31
Cause is acceptable here. Apart from anything else
kelvinp
2015/01/23 00:14:59
Acknowledged.
| |
24 * being minimized; callbacks should not be notified of the latter. | 24 * we must keep track of the minimized state of the window. |
25 * @private | 25 * @private |
26 */ | 26 */ |
27 this.notifyCallbacksOnRestore_ = this.isActive(); | 27 this.isMinimized_ = chrome.app.window.current().isMinimized(); |
28 | 28 |
29 /** | 29 /** |
30 * @type {string} Internal 'full-screen changed' event name | 30 * @type {string} Internal 'full-screen changed' event name |
31 * @private | 31 * @private |
32 */ | 32 */ |
33 this.kEventName_ = '_fullscreenchanged'; | 33 this.kEventName_ = '_fullscreenchanged'; |
34 | 34 |
35 /** | 35 /** |
36 * @type {base.EventSource} | 36 * @type {base.EventSource} |
37 * @private | 37 * @private |
38 */ | 38 */ |
39 this.eventSource_ = new base.EventSource(); | 39 this.eventSource_ = new base.EventSource(); |
40 this.eventSource_.defineEvents([this.kEventName_]); | 40 this.eventSource_.defineEvents([this.kEventName_]); |
41 | 41 |
42 chrome.app.window.current().onFullscreened.addListener( | 42 chrome.app.window.current().onFullscreened.addListener( |
43 this.onFullscreened_.bind(this)); | 43 this.onFullscreened_.bind(this)); |
44 chrome.app.window.current().onRestored.addListener( | 44 chrome.app.window.current().onRestored.addListener( |
45 this.onRestored_.bind(this)); | 45 this.onRestored_.bind(this)); |
46 chrome.app.window.current().onMinimized.addListener( | |
47 this.onMinimized_.bind(this)); | |
46 }; | 48 }; |
47 | 49 |
48 remoting.FullscreenAppsV2.prototype.activate = function( | 50 remoting.FullscreenAppsV2.prototype.activate = function( |
49 fullscreen, opt_onDone) { | 51 fullscreen, opt_onDone) { |
50 if (opt_onDone) { | 52 if (opt_onDone) { |
51 if (this.isActive() == fullscreen) { | 53 if (this.isActive() == fullscreen) { |
52 opt_onDone(); | 54 opt_onDone(); |
53 } else { | 55 } else { |
54 /** @type {remoting.Fullscreen} */ | 56 /** @type {remoting.Fullscreen} */ |
55 var that = this; | 57 var that = this; |
(...skipping 28 matching lines...) Expand all Loading... | |
84 }; | 86 }; |
85 | 87 |
86 /** | 88 /** |
87 * @param {function(boolean=):void} callback | 89 * @param {function(boolean=):void} callback |
88 */ | 90 */ |
89 remoting.FullscreenAppsV2.prototype.removeListener = function(callback) { | 91 remoting.FullscreenAppsV2.prototype.removeListener = function(callback) { |
90 this.eventSource_.removeEventListener(this.kEventName_, callback); | 92 this.eventSource_.removeEventListener(this.kEventName_, callback); |
91 }; | 93 }; |
92 | 94 |
93 remoting.FullscreenAppsV2.prototype.onFullscreened_ = function() { | 95 remoting.FullscreenAppsV2.prototype.onFullscreened_ = function() { |
94 this.notifyCallbacksOnRestore_ = true; | 96 this.isMinimized_ = false; |
95 this.eventSource_.raiseEvent(this.kEventName_, true); | 97 this.eventSource_.raiseEvent(this.kEventName_, true); |
96 document.body.classList.add('fullscreen'); | 98 document.body.classList.add('fullscreen'); |
97 }; | 99 }; |
98 | 100 |
99 remoting.FullscreenAppsV2.prototype.onRestored_ = function() { | 101 remoting.FullscreenAppsV2.prototype.onRestored_ = function() { |
100 document.body.classList.remove('fullscreen'); | 102 if (!this.isMinimized_) { |
kelvinp
2015/01/22 17:42:08
According to
OnRestored is called whenever the wi
Jamie
2015/01/22 23:27:31
That's a valid observation. I had a go at adding a
kelvinp
2015/01/23 00:14:59
Maybe we can add a member variable isFullScreened
Jamie
2015/01/23 00:44:16
Done.
| |
101 if (this.notifyCallbacksOnRestore_) { | 103 document.body.classList.remove('fullscreen'); |
102 this.notifyCallbacksOnRestore_ = false; | 104 this.notifyCallbacksOnRestore_ = false; |
103 this.eventSource_.raiseEvent(this.kEventName_, false); | 105 this.eventSource_.raiseEvent(this.kEventName_, false); |
104 } | 106 } |
107 this.isMinimized_ = false; | |
105 }; | 108 }; |
109 | |
110 remoting.FullscreenAppsV2.prototype.onMinimized_ = function() { | |
111 this.isMinimized_ = true; | |
112 }; | |
OLD | NEW |