| 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 27 matching lines...) Expand all Loading... |
| 38 /** @private */ | 38 /** @private */ |
| 39 this.viewportElement_ = viewportElement; | 39 this.viewportElement_ = viewportElement; |
| 40 | 40 |
| 41 /** @private */ | 41 /** @private */ |
| 42 this.plugin_ = plugin; | 42 this.plugin_ = plugin; |
| 43 | 43 |
| 44 /** private */ | 44 /** private */ |
| 45 this.cursor_ = new remoting.ConnectedView.Cursor( | 45 this.cursor_ = new remoting.ConnectedView.Cursor( |
| 46 plugin, viewportElement, cursorElement); | 46 plugin, viewportElement, cursorElement); |
| 47 | 47 |
| 48 /** @private {Element} */ |
| 49 this.debugRegionContainer_ = |
| 50 viewportElement.querySelector('.debug-region-container'); |
| 51 |
| 48 var pluginElement = plugin.element(); | 52 var pluginElement = plugin.element(); |
| 49 | 53 |
| 50 /** private */ | 54 /** private */ |
| 51 this.disposables_ = new base.Disposables( | 55 this.disposables_ = new base.Disposables( |
| 52 this.cursor_, | 56 this.cursor_, |
| 53 new base.DomEventHook(pluginElement, 'focus', | 57 new base.DomEventHook(pluginElement, 'focus', |
| 54 this.onPluginGotFocus_.bind(this), false), | 58 this.onPluginGotFocus_.bind(this), false), |
| 55 new base.DomEventHook(pluginElement, 'blur', | 59 new base.DomEventHook(pluginElement, 'blur', |
| 56 this.onPluginLostFocus_.bind(this), false), | 60 this.onPluginLostFocus_.bind(this), false), |
| 57 new base.DomEventHook(document, 'visibilitychange', | 61 new base.DomEventHook(document, 'visibilitychange', |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 this.plugin_.releaseAllKeys(); | 120 this.plugin_.releaseAllKeys(); |
| 117 | 121 |
| 118 // Focus should stay on the element, not (for example) the toolbar. | 122 // Focus should stay on the element, not (for example) the toolbar. |
| 119 // Due to crbug.com/246335, we can't restore the focus immediately, | 123 // Due to crbug.com/246335, we can't restore the focus immediately, |
| 120 // otherwise the plugin gets confused about whether or not it has focus. | 124 // otherwise the plugin gets confused about whether or not it has focus. |
| 121 window.setTimeout( | 125 window.setTimeout( |
| 122 this.plugin_.element().focus.bind(this.plugin_.element()), 0); | 126 this.plugin_.element().focus.bind(this.plugin_.element()), 0); |
| 123 }; | 127 }; |
| 124 | 128 |
| 125 /** | 129 /** |
| 130 * Handles dirty region debug messages. |
| 131 * |
| 132 * @param {{rects:Array<Array<number>>}} region Dirty region of the latest |
| 133 * frame. |
| 134 */ |
| 135 remoting.ConnectedView.prototype.handleDebugRegion = function(region) { |
| 136 while (this.debugRegionContainer_.firstChild) { |
| 137 this.debugRegionContainer_.removeChild( |
| 138 this.debugRegionContainer_.firstChild); |
| 139 } |
| 140 if (region.rects) { |
| 141 var rects = region.rects; |
| 142 for (var i = 0; i < rects.length; ++i) { |
| 143 var rect = document.createElement('div'); |
| 144 rect.classList.add('debug-region-rect'); |
| 145 rect.style.left = rects[i][0] + 'px'; |
| 146 rect.style.top = rects[i][1] +'px'; |
| 147 rect.style.width = rects[i][2] +'px'; |
| 148 rect.style.height = rects[i][3] + 'px'; |
| 149 this.debugRegionContainer_.appendChild(rect); |
| 150 } |
| 151 } |
| 152 }; |
| 153 |
| 154 /** |
| 155 * Enables or disables rendering of dirty regions for debugging. |
| 156 * @param {boolean} enable True to enable rendering. |
| 157 */ |
| 158 remoting.ConnectedView.prototype.enableDebugRegion = function(enable) { |
| 159 if (enable) { |
| 160 this.plugin_.setDebugDirtyRegionHandler(this.handleDebugRegion.bind(this)); |
| 161 } else { |
| 162 this.plugin_.setDebugDirtyRegionHandler(null); |
| 163 } |
| 164 }; |
| 165 |
| 166 /** |
| 126 * @param {remoting.ClientPlugin} plugin | 167 * @param {remoting.ClientPlugin} plugin |
| 127 * @param {HTMLElement} viewportElement | 168 * @param {HTMLElement} viewportElement |
| 128 * @param {HTMLElement} cursorElement | 169 * @param {HTMLElement} cursorElement |
| 129 * | 170 * |
| 130 * @constructor | 171 * @constructor |
| 131 * @implements {base.Disposable} | 172 * @implements {base.Disposable} |
| 132 */ | 173 */ |
| 133 remoting.ConnectedView.Cursor = function( | 174 remoting.ConnectedView.Cursor = function( |
| 134 plugin, viewportElement, cursorElement) { | 175 plugin, viewportElement, cursorElement) { |
| 135 /** @private */ | 176 /** @private */ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 /** | 211 /** |
| 171 * @param {Event} event | 212 * @param {Event} event |
| 172 * @private | 213 * @private |
| 173 */ | 214 */ |
| 174 remoting.ConnectedView.Cursor.prototype.onMouseMoved_ = function(event) { | 215 remoting.ConnectedView.Cursor.prototype.onMouseMoved_ = function(event) { |
| 175 this.cursorElement_.style.top = event.offsetY + 'px'; | 216 this.cursorElement_.style.top = event.offsetY + 'px'; |
| 176 this.cursorElement_.style.left = event.offsetX + 'px'; | 217 this.cursorElement_.style.left = event.offsetX + 'px'; |
| 177 }; | 218 }; |
| 178 | 219 |
| 179 })(); | 220 })(); |
| OLD | NEW |