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 var delta = Math.abs(windowOuterWidth - windowWidth * zoom_levels[i]); | |
Jamie
2012/02/16 18:45:22
I'm don't think that taking an absolute value is r
alexeypa (please no reviews)
2012/02/16 23:58:17
I added a comment explaining why it is needed. I w
| |
462 if (delta < min_delta) { | |
463 min_delta = delta; | |
464 scale = 1.0 / zoom_levels[i]; | |
465 } | |
466 } | |
446 | 467 |
447 if (this.getScaleToFit()) { | 468 if (this.getScaleToFit()) { |
448 var scaleFitWidth = 1.0 * windowWidth / this.plugin.desktopWidth; | 469 var scaledWidth = 1.0 * windowWidth / (scale * this.plugin.desktopWidth); |
449 var scaleFitHeight = 1.0 * windowHeight / this.plugin.desktopHeight; | 470 var scaledHeight = 1.0 * windowHeight / (scale * this.plugin.desktopHeight); |
450 scale = Math.min(1.0, scaleFitHeight, scaleFitWidth); | 471 scale = Math.min(1.0, scaledHeight, scaledWidth) * scale; |
451 } | 472 } |
452 | 473 |
453 var width = this.plugin.desktopWidth * scale; | 474 var width = this.plugin.desktopWidth * scale; |
454 var height = this.plugin.desktopHeight * scale; | 475 var height = this.plugin.desktopHeight * scale; |
455 | 476 |
456 // Resize the plugin if necessary. | 477 // Resize the plugin if necessary. |
457 this.plugin.element().width = width; | 478 this.plugin.element().width = Math.ceil(this.plugin.desktopWidth * scale); |
458 this.plugin.element().height = height; | 479 this.plugin.element().height = Math.ceil(this.plugin.desktopHeight * scale); |
459 | 480 |
460 // Position the container. | 481 // Position the container. |
461 // TODO(wez): We should take into account scrollbars when positioning. | 482 // TODO(wez): We should take into account scrollbars when positioning. |
462 var parentNode = this.plugin.element().parentNode; | 483 var parentNode = this.plugin.element().parentNode; |
463 | 484 |
464 if (width < windowWidth) { | 485 if (width < windowWidth) { |
465 parentNode.style.left = (windowWidth - width) / 2 + 'px'; | 486 parentNode.style.left = (windowWidth - width) / 2 + 'px'; |
466 } else { | 487 } else { |
467 parentNode.style.left = '0'; | 488 parentNode.style.left = '0'; |
468 } | 489 } |
(...skipping 21 matching lines...) Expand all Loading... | |
490 }; | 511 }; |
491 | 512 |
492 /** | 513 /** |
493 * Logs statistics. | 514 * Logs statistics. |
494 * | 515 * |
495 * @param {remoting.ClientSession.PerfStats} stats | 516 * @param {remoting.ClientSession.PerfStats} stats |
496 */ | 517 */ |
497 remoting.ClientSession.prototype.logStatistics = function(stats) { | 518 remoting.ClientSession.prototype.logStatistics = function(stats) { |
498 this.logToServer.logStatistics(stats, this.mode); | 519 this.logToServer.logStatistics(stats, this.mode); |
499 }; | 520 }; |
OLD | NEW |