Chromium Code Reviews| Index: remoting/webapp/crd/js/fullscreen_v2.js |
| diff --git a/remoting/webapp/crd/js/fullscreen_v2.js b/remoting/webapp/crd/js/fullscreen_v2.js |
| index ea20f9000f7185ce7554154ac9890fc1bbec28dc..ea932446a3d6bf5235ff8a850c47f0f67268969f 100644 |
| --- a/remoting/webapp/crd/js/fullscreen_v2.js |
| +++ b/remoting/webapp/crd/js/fullscreen_v2.js |
| @@ -18,16 +18,24 @@ var remoting = remoting || {}; |
| */ |
| remoting.FullscreenAppsV2 = function() { |
| /** |
| - * @type {boolean} True if the next onRestored event should cause callbacks |
| - * to be notified of a full-screen changed event. onRestored fires when |
| - * full-screen mode is exited and also when the window is restored from |
| - * being minimized; callbacks should not be notified of the latter. |
| + * @type {boolean} True if the window is minimized. onRestored fires when the |
| + * the window transitions from minimized to any other state, but since we |
| + * only want transitions from full-screen to windowed to cause a callback, |
| + * we must keep track of the minimized state of the window. |
| * @private |
| */ |
| - this.notifyCallbacksOnRestore_ = this.isActive(); |
| + this.isMinimized_ = chrome.app.window.current().isMinimized(); |
| /** |
| - * @type {string} Internal 'full-screen changed' event name |
| + * @type {?boolean} The most recent full-screen state passed to the callback. |
| + * This guards against redundant invocations, as as would otherwise occur |
| + * in response to a full-screen -> maximized -> unmaximized transition, |
| + * because this results in two onRestored callbacks. |
| + */ |
| + this.previousCallbackState_ = null; |
|
kelvinp
2015/01/23 18:26:07
Nit: I think isFullScreen_ would be a better name.
Jamie
2015/01/23 18:51:34
I think there are a couple of options:
* Leave it
|
| + |
| + /** |
| + * @type {string} Internal 'full-screen changed' event name. |
| * @private |
| */ |
| this.kEventName_ = '_fullscreenchanged'; |
| @@ -43,8 +51,14 @@ remoting.FullscreenAppsV2 = function() { |
| this.onFullscreened_.bind(this)); |
| chrome.app.window.current().onRestored.addListener( |
| this.onRestored_.bind(this)); |
| + chrome.app.window.current().onMinimized.addListener( |
| + this.onMinimized_.bind(this)); |
| }; |
| +/** |
| + * @param {boolean} fullscreen True to enter full-screen mode; false to leave. |
| + * @param {function():void=} opt_onDone Optional completion callback. |
| + */ |
| remoting.FullscreenAppsV2.prototype.activate = function( |
| fullscreen, opt_onDone) { |
| if (opt_onDone) { |
| @@ -72,6 +86,9 @@ remoting.FullscreenAppsV2.prototype.toggle = function() { |
| this.activate(!this.isActive()); |
| }; |
| +/** |
| + * @return {boolean} |
| + */ |
| remoting.FullscreenAppsV2.prototype.isActive = function() { |
| return chrome.app.window.current().isFullscreen(); |
| }; |
| @@ -90,16 +107,41 @@ remoting.FullscreenAppsV2.prototype.removeListener = function(callback) { |
| this.eventSource_.removeEventListener(this.kEventName_, callback); |
| }; |
| +/** |
| + * @private |
| + */ |
| remoting.FullscreenAppsV2.prototype.onFullscreened_ = function() { |
| - this.notifyCallbacksOnRestore_ = true; |
| - this.eventSource_.raiseEvent(this.kEventName_, true); |
| + this.isMinimized_ = false; |
| + this.raiseEvent_(true); |
| document.body.classList.add('fullscreen'); |
| }; |
| +/** |
| + * @private |
| + */ |
| remoting.FullscreenAppsV2.prototype.onRestored_ = function() { |
| - document.body.classList.remove('fullscreen'); |
| - if (this.notifyCallbacksOnRestore_) { |
| + if (!this.isMinimized_) { |
| + document.body.classList.remove('fullscreen'); |
| this.notifyCallbacksOnRestore_ = false; |
|
kelvinp
2015/01/23 18:26:07
Now this.notifyCallbacksOnRestore_ can be removed
Jamie
2015/01/23 18:51:34
Done.
|
| - this.eventSource_.raiseEvent(this.kEventName_, false); |
| + this.raiseEvent_(false); |
| + } |
| + this.isMinimized_ = false; |
| +}; |
| + |
| +/** |
| + * @private |
| + */ |
| +remoting.FullscreenAppsV2.prototype.onMinimized_ = function() { |
| + this.isMinimized_ = true; |
| +}; |
| + |
| +/** |
| + * @param {boolean} isFullscreen |
| + * @private |
| + */ |
| +remoting.FullscreenAppsV2.prototype.raiseEvent_ = function(isFullscreen) { |
| + if (isFullscreen !== this.previousCallbackState_) { |
| + this.previousCallbackState_ = isFullscreen; |
| + this.eventSource_.raiseEvent(this.kEventName_, isFullscreen); |
| } |
| }; |