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 maximize/restore events are being hooked. | |
22 * @private | |
23 */ | |
24 this.hookingWindowEvents_ = false; | |
25 | |
26 /** | |
27 * @type {boolean} True if the next onRestored event should cause callbacks | 21 * @type {boolean} True if the next onRestored event should cause callbacks |
28 * to be notified of a full-screen changed event. onRestored fires when | 22 * 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 | 23 * full-screen mode is exited and also when the window is restored from |
30 * being minimized; callbacks should not be notified of the latter. | 24 * being minimized; callbacks should not be notified of the latter. |
31 * @private | 25 * @private |
32 */ | 26 */ |
33 this.notifyCallbacksOnRestore_ = this.isActive(); | 27 this.notifyCallbacksOnRestore_ = this.isActive(); |
34 | 28 |
35 /** | 29 /** |
36 * @type {string} Internal 'full-screen changed' event name | 30 * @type {string} Internal 'full-screen changed' event name |
37 * @private | 31 * @private |
38 */ | 32 */ |
39 this.kEventName_ = '_fullscreenchanged'; | 33 this.kEventName_ = '_fullscreenchanged'; |
40 | 34 |
41 /** | 35 /** |
42 * @type {base.EventSource} | 36 * @type {base.EventSource} |
43 * @private | 37 * @private |
44 */ | 38 */ |
45 this.eventSource_ = new base.EventSource(); | 39 this.eventSource_ = new base.EventSource(); |
46 this.eventSource_.defineEvents([this.kEventName_]); | 40 this.eventSource_.defineEvents([this.kEventName_]); |
47 | 41 |
48 chrome.app.window.current().onFullscreened.addListener( | 42 chrome.app.window.current().onFullscreened.addListener( |
49 this.onFullscreened_.bind(this)); | 43 this.onFullscreened_.bind(this)); |
50 chrome.app.window.current().onMaximized.addListener( | |
51 this.onMaximized_.bind(this)); | |
52 chrome.app.window.current().onRestored.addListener( | 44 chrome.app.window.current().onRestored.addListener( |
53 this.onRestored_.bind(this)); | 45 this.onRestored_.bind(this)); |
54 }; | 46 }; |
55 | 47 |
56 remoting.FullscreenAppsV2.prototype.activate = function( | 48 remoting.FullscreenAppsV2.prototype.activate = function( |
57 fullscreen, opt_onDone) { | 49 fullscreen, opt_onDone) { |
58 if (opt_onDone) { | 50 if (opt_onDone) { |
59 if (this.isActive() == fullscreen) { | 51 if (this.isActive() == fullscreen) { |
60 opt_onDone(); | 52 opt_onDone(); |
61 } else { | 53 } else { |
(...skipping 23 matching lines...) Expand all Loading... |
85 }; | 77 }; |
86 | 78 |
87 remoting.FullscreenAppsV2.prototype.addListener = function(callback) { | 79 remoting.FullscreenAppsV2.prototype.addListener = function(callback) { |
88 this.eventSource_.addEventListener(this.kEventName_, callback); | 80 this.eventSource_.addEventListener(this.kEventName_, callback); |
89 }; | 81 }; |
90 | 82 |
91 remoting.FullscreenAppsV2.prototype.removeListener = function(callback) { | 83 remoting.FullscreenAppsV2.prototype.removeListener = function(callback) { |
92 this.eventSource_.removeEventListener(this.kEventName_, callback); | 84 this.eventSource_.removeEventListener(this.kEventName_, callback); |
93 }; | 85 }; |
94 | 86 |
95 remoting.FullscreenAppsV2.prototype.syncWithMaximize = function(sync) { | |
96 if (sync && chrome.app.window.current().isMaximized()) { | |
97 chrome.app.window.current().restore(); | |
98 this.activate(true); | |
99 } | |
100 this.hookingWindowEvents_ = sync; | |
101 }; | |
102 | |
103 remoting.FullscreenAppsV2.prototype.onFullscreened_ = function() { | 87 remoting.FullscreenAppsV2.prototype.onFullscreened_ = function() { |
104 this.notifyCallbacksOnRestore_ = true; | 88 this.notifyCallbacksOnRestore_ = true; |
105 this.eventSource_.raiseEvent(this.kEventName_, true); | 89 this.eventSource_.raiseEvent(this.kEventName_, true); |
106 document.body.classList.add('fullscreen'); | 90 document.body.classList.add('fullscreen'); |
107 }; | 91 }; |
108 | 92 |
109 remoting.FullscreenAppsV2.prototype.onMaximized_ = function() { | |
110 if (this.hookingWindowEvents_) { | |
111 chrome.app.window.current().restore(); | |
112 this.activate(true); | |
113 } | |
114 }; | |
115 | |
116 remoting.FullscreenAppsV2.prototype.onRestored_ = function() { | 93 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()) { | |
121 return; | |
122 } | |
123 | |
124 document.body.classList.remove('fullscreen'); | 94 document.body.classList.remove('fullscreen'); |
125 if (this.hookingWindowEvents_) { | |
126 this.activate(false); | |
127 } | |
128 if (this.notifyCallbacksOnRestore_) { | 95 if (this.notifyCallbacksOnRestore_) { |
129 this.notifyCallbacksOnRestore_ = false; | 96 this.notifyCallbacksOnRestore_ = false; |
130 this.eventSource_.raiseEvent(this.kEventName_, false); | 97 this.eventSource_.raiseEvent(this.kEventName_, false); |
131 } | 98 } |
132 }; | 99 }; |
OLD | NEW |