Chromium Code Reviews| 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 * Provides view port management utilities below for a desktop remoting session. | 7 * Provides view port management utilities below for a desktop remoting session. |
| 8 * - Enabling bump scrolling | 8 * - Enabling bump scrolling |
| 9 * - Resizing the viewport to fit the host desktop | 9 * - Resizing the viewport to fit the host desktop |
| 10 * - Resizing the host desktop to fit the client viewport. | 10 * - Resizing the host desktop to fit the client viewport. |
| 11 */ | 11 */ |
| 12 | 12 |
| 13 /** @suppress {duplicate} */ | 13 /** @suppress {duplicate} */ |
| 14 var remoting = remoting || {}; | 14 var remoting = remoting || {}; |
| 15 | 15 |
| 16 (function() { | 16 (function() { |
| 17 | 17 |
| 18 'use strict'; | 18 'use strict'; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * @param {HTMLElement} rootElement The outer element with id=scroller that we | 21 * @param {HTMLElement} rootElement The outer element with id=scroller that we |
| 22 * are showing scrollbars on. | 22 * are showing scrollbars on. |
| 23 * @param {remoting.HostDesktop} hostDesktop | 23 * @param {remoting.HostDesktop} hostDesktop |
| 24 * @param {remoting.HostOptions} hostOptions | 24 * @param {remoting.HostOptions} hostOptions |
| 25 * @param {!remoting.SessionLogger} logger | |
| 25 * | 26 * |
| 26 * @constructor | 27 * @constructor |
| 27 * @implements {base.Disposable} | 28 * @implements {base.Disposable} |
| 28 */ | 29 */ |
| 29 remoting.DesktopViewport = function(rootElement, hostDesktop, hostOptions) { | 30 remoting.DesktopViewport = function(rootElement, hostDesktop, hostOptions, |
| 31 logger) { | |
| 30 /** @private */ | 32 /** @private */ |
| 31 this.rootElement_ = rootElement; | 33 this.rootElement_ = rootElement; |
| 32 /** @private */ | 34 /** @private */ |
| 33 // TODO(kelvinp): Query the container by class name instead of id. | 35 // TODO(kelvinp): Query the container by class name instead of id. |
| 34 this.pluginContainer_ = rootElement.querySelector('#client-container'); | 36 this.pluginContainer_ = rootElement.querySelector('#client-container'); |
| 35 /** @private */ | 37 /** @private */ |
| 36 this.pluginElement_ = rootElement.querySelector('embed'); | 38 this.pluginElement_ = rootElement.querySelector('embed'); |
| 37 /** @private */ | 39 /** @private */ |
| 38 this.hostDesktop_ = hostDesktop; | 40 this.hostDesktop_ = hostDesktop; |
| 39 /** @private */ | 41 /** @private */ |
| 40 this.hostOptions_ = hostOptions; | 42 this.hostOptions_ = hostOptions; |
| 41 /** @private {number?} */ | 43 /** @private {number?} */ |
| 42 this.resizeTimer_ = null; | 44 this.resizeTimer_ = null; |
| 43 /** @private {remoting.BumpScroller} */ | 45 /** @private {remoting.BumpScroller} */ |
| 44 this.bumpScroller_ = null; | 46 this.bumpScroller_ = null; |
| 45 // Bump-scroll test variables. Override to use a fake value for the width | 47 // Bump-scroll test variables. Override to use a fake value for the width |
| 46 // and height of the client plugin so that bump-scrolling can be tested | 48 // and height of the client plugin so that bump-scrolling can be tested |
| 47 // without relying on the actual size of the host desktop. | 49 // without relying on the actual size of the host desktop. |
| 48 /** @private {number} */ | 50 /** @private {number} */ |
| 49 this.pluginWidthForBumpScrollTesting_ = 0; | 51 this.pluginWidthForBumpScrollTesting_ = 0; |
| 50 /** @private {number} */ | 52 /** @private {number} */ |
| 51 this.pluginHeightForBumpScrollTesting_ = 0; | 53 this.pluginHeightForBumpScrollTesting_ = 0; |
| 54 /** @private {!remoting.SessionLogger} */ | |
| 55 this.logger_ = logger; | |
| 56 /** @private {number?} */ | |
| 57 this.loggingTimer_ = null; | |
| 52 | 58 |
| 53 this.eventHooks_ = new base.Disposables( | 59 this.eventHooks_ = new base.Disposables( |
| 54 new base.EventHook( | 60 new base.EventHook( |
| 55 this.hostDesktop_, remoting.HostDesktop.Events.sizeChanged, | 61 this.hostDesktop_, remoting.HostDesktop.Events.sizeChanged, |
| 56 this.onDesktopSizeChanged_.bind(this))); | 62 this.onDesktopSizeChanged_.bind(this))); |
| 57 | 63 |
| 58 if (this.hostOptions_.getResizeToClient()) { | 64 if (this.hostOptions_.getResizeToClient()) { |
| 59 this.resizeHostDesktop_(); | 65 this.resizeHostDesktop_(); |
| 60 } else { | 66 } else { |
| 61 this.onDesktopSizeChanged_(); | 67 this.onDesktopSizeChanged_(); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 remoting.DesktopViewport.prototype.updateDimensions_ = function() { | 330 remoting.DesktopViewport.prototype.updateDimensions_ = function() { |
| 325 var dimensions = this.hostDesktop_.getDimensions(); | 331 var dimensions = this.hostDesktop_.getDimensions(); |
| 326 if (dimensions.width === 0 || dimensions.height === 0) { | 332 if (dimensions.width === 0 || dimensions.height === 0) { |
| 327 return; | 333 return; |
| 328 } | 334 } |
| 329 | 335 |
| 330 var desktopSize = { width: dimensions.width, | 336 var desktopSize = { width: dimensions.width, |
| 331 height: dimensions.height }; | 337 height: dimensions.height }; |
| 332 var desktopDpi = { x: dimensions.xDpi, | 338 var desktopDpi = { x: dimensions.xDpi, |
| 333 y: dimensions.yDpi }; | 339 y: dimensions.yDpi }; |
| 340 var clientSize = this.getClientArea(); | |
| 334 var newSize = remoting.Viewport.choosePluginSize( | 341 var newSize = remoting.Viewport.choosePluginSize( |
| 335 this.getClientArea(), window.devicePixelRatio, | 342 clientSize, window.devicePixelRatio, |
| 336 desktopSize, desktopDpi, this.hostOptions_.getDesktopScale(), | 343 desktopSize, desktopDpi, this.hostOptions_.getDesktopScale(), |
| 337 remoting.fullscreen.isActive(), this.hostOptions_.getShrinkToFit()); | 344 remoting.fullscreen.isActive(), this.hostOptions_.getShrinkToFit()); |
| 338 | 345 |
| 346 this.logDimensions_(desktopSize, clientSize, remoting.fullscreen.isActive()); | |
|
Lambros
2016/09/28 01:30:39
Would it make more sense to log the plugin size in
Jamie
2016/09/28 21:14:36
I think there's value in both. Client area is prob
| |
| 347 | |
| 339 // Resize the plugin if necessary. | 348 // Resize the plugin if necessary. |
| 340 console.log('plugin dimensions:' + newSize.width + 'x' + newSize.height); | 349 console.log('plugin dimensions:' + newSize.width + 'x' + newSize.height); |
| 341 this.pluginElement_.style.width = newSize.width + 'px'; | 350 this.pluginElement_.style.width = newSize.width + 'px'; |
| 342 this.pluginElement_.style.height = newSize.height + 'px'; | 351 this.pluginElement_.style.height = newSize.height + 'px'; |
| 343 }; | 352 }; |
| 344 | 353 |
| 345 /** @private */ | 354 /** @private */ |
| 346 remoting.DesktopViewport.prototype.resetScroll_ = function() { | 355 remoting.DesktopViewport.prototype.resetScroll_ = function() { |
| 347 this.pluginContainer_.style.marginTop = '0px'; | 356 this.pluginContainer_.style.marginTop = '0px'; |
| 348 this.pluginContainer_.style.marginLeft = '0px'; | 357 this.pluginContainer_.style.marginLeft = '0px'; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 359 this.hostOptions_.setDesktopScale(desktopScale); | 368 this.hostOptions_.setDesktopScale(desktopScale); |
| 360 | 369 |
| 361 // onResize() will update the plugin size and scrollbars for the new | 370 // onResize() will update the plugin size and scrollbars for the new |
| 362 // scaled plugin dimensions, and send a client resolution notification. | 371 // scaled plugin dimensions, and send a client resolution notification. |
| 363 this.onResize(); | 372 this.onResize(); |
| 364 | 373 |
| 365 // Save the new desktop scale setting. | 374 // Save the new desktop scale setting. |
| 366 this.hostOptions_.save(); | 375 this.hostOptions_.save(); |
| 367 }; | 376 }; |
| 368 | 377 |
| 378 /** | |
| 379 * Log the specified client and host sizes after a short delay. Since the host | |
| 380 * size may change in response to a change in the client size, the delay allows | |
| 381 * time for the desktop size change notification to arrive from the host, and | |
| 382 * avoids logging the intermediate state. | |
| 383 */ | |
| 384 remoting.DesktopViewport.prototype.logDimensions_ = | |
| 385 function(hostSize, clientSize, isFullscreen) { | |
| 386 if (this.loggingTimer_ !== null) { | |
| 387 window.clearTimeout(this.loggingTimer_); | |
| 388 } | |
| 389 var kLoggingRateLimitMs = 2000; | |
| 390 this.loggingTimer_ = window.setTimeout( | |
| 391 () => { | |
| 392 this.logger_.logScreenResolutions(hostSize, clientSize, isFullscreen); | |
| 393 }, | |
| 394 kLoggingRateLimitMs); | |
| 395 }; | |
| 396 | |
| 369 }()); | 397 }()); |
| OLD | NEW |