| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * Implements a basic UX control for a connected remoting session. | 7 * Implements a basic UX control for a connected remoting session. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** @suppress {duplicate} */ | 10 /** @suppress {duplicate} */ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 /** @private */ | 45 /** @private */ |
| 46 this.disposables_ = new base.Disposables( | 46 this.disposables_ = new base.Disposables( |
| 47 this.cursor_, | 47 this.cursor_, |
| 48 new base.DomEventHook(pluginElement, 'blur', | 48 new base.DomEventHook(pluginElement, 'blur', |
| 49 this.onPluginLostFocus_.bind(this), false), | 49 this.onPluginLostFocus_.bind(this), false), |
| 50 new base.DomEventHook(document, 'visibilitychange', | 50 new base.DomEventHook(document, 'visibilitychange', |
| 51 this.onVisibilityChanged_.bind(this), false), | 51 this.onVisibilityChanged_.bind(this), false), |
| 52 new remoting.Clipboard(plugin) | 52 new remoting.Clipboard(plugin) |
| 53 ); | 53 ); |
| 54 | 54 |
| 55 /** @private {base.OneShotTimer} */ |
| 56 this.restoreFocusTimer_ = null; |
| 57 |
| 55 // TODO(wez): Only allow mouse lock if the app has the pointerLock permission. | 58 // TODO(wez): Only allow mouse lock if the app has the pointerLock permission. |
| 56 this.plugin_.allowMouseLock(); | 59 this.plugin_.allowMouseLock(); |
| 57 | 60 |
| 58 pluginElement.focus(); | 61 pluginElement.focus(); |
| 59 }; | 62 }; |
| 60 | 63 |
| 61 /** | 64 /** |
| 62 * @return {void} Nothing. | 65 * @return {void} Nothing. |
| 63 */ | 66 */ |
| 64 remoting.ConnectedView.prototype.dispose = function() { | 67 remoting.ConnectedView.prototype.dispose = function() { |
| 65 base.dispose(this.disposables_); | 68 base.dispose(this.disposables_); |
| 66 this.disposables_ = null; | 69 this.disposables_ = null; |
| 67 this.cursorRender_ = null; | 70 this.cursorRender_ = null; |
| 68 this.plugin_ = null; | 71 this.plugin_ = null; |
| 72 base.dispose(this.restoreFocusTimer_); |
| 73 this.restoreFocusTimer_ = null; |
| 69 }; | 74 }; |
| 70 | 75 |
| 71 /** | 76 /** |
| 72 * Called when the app window is hidden. | 77 * Called when the app window is hidden. |
| 73 * @return {void} Nothing. | 78 * @return {void} Nothing. |
| 74 * @private | 79 * @private |
| 75 */ | 80 */ |
| 76 remoting.ConnectedView.prototype.onVisibilityChanged_ = function() { | 81 remoting.ConnectedView.prototype.onVisibilityChanged_ = function() { |
| 77 var pause = document.hidden; | 82 var pause = document.hidden; |
| 78 this.plugin_.pauseVideo(pause); | 83 this.plugin_.pauseVideo(pause); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 94 * @private | 99 * @private |
| 95 */ | 100 */ |
| 96 remoting.ConnectedView.prototype.onPluginLostFocus_ = function(event) { | 101 remoting.ConnectedView.prototype.onPluginLostFocus_ = function(event) { |
| 97 // Release all keys to prevent them becoming 'stuck down' on the host. | 102 // Release all keys to prevent them becoming 'stuck down' on the host. |
| 98 this.plugin_.releaseAllKeys(); | 103 this.plugin_.releaseAllKeys(); |
| 99 | 104 |
| 100 // Focus should stay on the element, not (for example) the toolbar. | 105 // Focus should stay on the element, not (for example) the toolbar. |
| 101 // Due to crbug.com/246335, we can't restore the focus immediately, | 106 // Due to crbug.com/246335, we can't restore the focus immediately, |
| 102 // otherwise the plugin gets confused about whether or not it has focus. | 107 // otherwise the plugin gets confused about whether or not it has focus. |
| 103 var that = this; | 108 var that = this; |
| 104 var delayedCallback = function() { | 109 base.dispose(this.restoreFocusTimer_); |
| 110 this.restoreFocusTimer_ = new base.OneShotTimer(function() { |
| 105 // When the 'blur' event handler is called document.activeElement has not | 111 // When the 'blur' event handler is called document.activeElement has not |
| 106 // been set to the correct target. We need to retrieve the target in this | 112 // been set to the correct target. We need to retrieve the target in this |
| 107 // delayedCallback. | 113 // delayedCallback. |
| 108 var target = /** @type {!HTMLElement} */ (document.activeElement); | 114 var target = /** @type {!HTMLElement} */ (document.activeElement); |
| 109 if (!that.isElementFocusable_(target)) { | 115 if (!that.isElementFocusable_(target)) { |
| 110 that.plugin_.element().focus(); | 116 that.plugin_.element().focus(); |
| 111 } | 117 } |
| 112 }; | 118 }, 0); |
| 113 window.setTimeout(delayedCallback, 0); | |
| 114 }; | 119 }; |
| 115 | 120 |
| 116 /** | 121 /** |
| 117 * Return focus to the plugin. | 122 * Return focus to the plugin. |
| 118 */ | 123 */ |
| 119 remoting.ConnectedView.prototype.returnFocusToPlugin = function() { | 124 remoting.ConnectedView.prototype.returnFocusToPlugin = function() { |
| 120 this.plugin_.element().focus(); | 125 this.plugin_.element().focus(); |
| 121 }; | 126 }; |
| 122 | 127 |
| 123 /** | 128 /** |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 /** | 231 /** |
| 227 * @param {Event} event | 232 * @param {Event} event |
| 228 * @private | 233 * @private |
| 229 */ | 234 */ |
| 230 remoting.ConnectedView.Cursor.prototype.onMouseMoved_ = function(event) { | 235 remoting.ConnectedView.Cursor.prototype.onMouseMoved_ = function(event) { |
| 231 this.cursorElement_.style.top = event.offsetY + 'px'; | 236 this.cursorElement_.style.top = event.offsetY + 'px'; |
| 232 this.cursorElement_.style.left = event.offsetX + 'px'; | 237 this.cursorElement_.style.left = event.offsetX + 'px'; |
| 233 }; | 238 }; |
| 234 | 239 |
| 235 })(); | 240 })(); |
| OLD | NEW |