OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * Class handling creation and teardown of a remoting client session. | 7 * Class handling creation and teardown of a remoting client session. |
8 * | 8 * |
9 * The ClientSession class controls lifetime of the client plugin | 9 * The ClientSession class controls lifetime of the client plugin |
10 * object and provides the plugin with the functionality it needs to | 10 * object and provides the plugin with the functionality it needs to |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 * @return {void} Nothing. | 435 * @return {void} Nothing. |
436 */ | 436 */ |
437 remoting.ClientSession.prototype.updateDimensions = function() { | 437 remoting.ClientSession.prototype.updateDimensions = function() { |
438 if (this.plugin.desktopWidth == 0 || | 438 if (this.plugin.desktopWidth == 0 || |
439 this.plugin.desktopHeight == 0) { | 439 this.plugin.desktopHeight == 0) { |
440 return; | 440 return; |
441 } | 441 } |
442 | 442 |
443 var windowWidth = window.innerWidth; | 443 var windowWidth = window.innerWidth; |
444 var windowHeight = window.innerHeight; | 444 var windowHeight = window.innerHeight; |
445 | |
446 // Estimate browser scale factor in order to be able to translate logical | |
447 // pixels on the page into physical pixels on the screen. Scale factor can | |
448 // be roughly estimated as a ratio between outerWidth and innerWidth of | |
449 // the document view. The result is not precise because outerWidth can | |
450 // include pixels allocated for toolbars, window borders and such. | |
451 var windowOuterWidth = window.outerWidth; | |
452 | |
453 // TODO(alexeypa): remove this hack once proper zooming API is available. | |
454 // See issue #30583 for details. | |
455 // Now pick the exact scale factor from the list of known zoom levels. | |
456 var zoom_levels = [ 0.25, 1.0/3, 0.5, 2.0/3, 0.75, 0.9, 1.0, 1.1, 1.25, 1.5, | |
457 1.75, 2, 2.5, 3.0, 4.0 ]; | |
458 var min_delta = Number.MAX_VALUE; | |
445 var scale = 1.0; | 459 var scale = 1.0; |
460 for (var i in zoom_levels) { | |
461 // The difference between outerWidht and scaled innerWidth should always be | |
Jamie
2012/02/17 00:10:35
Nit: Typo
| |
462 // positive. However due to rounding done by the browser the difference | |
463 // becomes negative in some cases. | |
464 var delta = Math.abs(windowOuterWidth - windowWidth * zoom_levels[i]); | |
465 if (delta < min_delta) { | |
466 min_delta = delta; | |
467 scale = 1.0 / zoom_levels[i]; | |
468 } | |
469 } | |
446 | 470 |
447 if (this.getScaleToFit()) { | 471 if (this.getScaleToFit()) { |
448 var scaleFitWidth = 1.0 * windowWidth / this.plugin.desktopWidth; | 472 var scaledWidth = 1.0 * windowWidth / (scale * this.plugin.desktopWidth); |
449 var scaleFitHeight = 1.0 * windowHeight / this.plugin.desktopHeight; | 473 var scaledHeight = 1.0 * windowHeight / (scale * this.plugin.desktopHeight); |
450 scale = Math.min(1.0, scaleFitHeight, scaleFitWidth); | 474 scale = Math.min(1.0, scaledHeight, scaledWidth) * scale; |
451 } | 475 } |
452 | 476 |
453 var width = this.plugin.desktopWidth * scale; | 477 var width = this.plugin.desktopWidth * scale; |
454 var height = this.plugin.desktopHeight * scale; | 478 var height = this.plugin.desktopHeight * scale; |
455 | 479 |
456 // Resize the plugin if necessary. | 480 // Resize the plugin if necessary. |
457 this.plugin.element().width = width; | 481 this.plugin.element().width = Math.ceil(this.plugin.desktopWidth * scale); |
458 this.plugin.element().height = height; | 482 this.plugin.element().height = Math.ceil(this.plugin.desktopHeight * scale); |
459 | 483 |
460 // Position the container. | 484 // Position the container. |
461 // TODO(wez): We should take into account scrollbars when positioning. | 485 // TODO(wez): We should take into account scrollbars when positioning. |
462 var parentNode = this.plugin.element().parentNode; | 486 var parentNode = this.plugin.element().parentNode; |
463 | 487 |
464 if (width < windowWidth) { | 488 if (width < windowWidth) { |
465 parentNode.style.left = (windowWidth - width) / 2 + 'px'; | 489 parentNode.style.left = (windowWidth - width) / 2 + 'px'; |
466 } else { | 490 } else { |
467 parentNode.style.left = '0'; | 491 parentNode.style.left = '0'; |
468 } | 492 } |
(...skipping 21 matching lines...) Expand all Loading... | |
490 }; | 514 }; |
491 | 515 |
492 /** | 516 /** |
493 * Logs statistics. | 517 * Logs statistics. |
494 * | 518 * |
495 * @param {remoting.ClientSession.PerfStats} stats | 519 * @param {remoting.ClientSession.PerfStats} stats |
496 */ | 520 */ |
497 remoting.ClientSession.prototype.logStatistics = function(stats) { | 521 remoting.ClientSession.prototype.logStatistics = function(stats) { |
498 this.logToServer.logStatistics(stats, this.mode); | 522 this.logToServer.logStatistics(stats, this.mode); |
499 }; | 523 }; |
OLD | NEW |