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 * This abstracts a <embed> element and controls the plugin which does the | 9 * This abstracts a <embed> element and controls the plugin which does the |
10 * actual remoting work. There should be no UI code inside this class. It | 10 * actual remoting work. There should be no UI code inside this class. It |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 * | 428 * |
429 * @return {void} Nothing. | 429 * @return {void} Nothing. |
430 */ | 430 */ |
431 remoting.ClientSession.prototype.updateDimensions = function() { | 431 remoting.ClientSession.prototype.updateDimensions = function() { |
432 if (this.plugin.desktopWidth == 0 || | 432 if (this.plugin.desktopWidth == 0 || |
433 this.plugin.desktopHeight == 0) | 433 this.plugin.desktopHeight == 0) |
434 return; | 434 return; |
435 | 435 |
436 var windowWidth = window.innerWidth; | 436 var windowWidth = window.innerWidth; |
437 var windowHeight = window.innerHeight; | 437 var windowHeight = window.innerHeight; |
438 var scale = 1.0; | 438 |
439 // Estimate browser scale factor in order to be able to translate logical | |
440 // pixels on the page into physical pixels on the screen. Scale factor can | |
441 // be roughly estimated as a ratio between outerWidht and innerWidth of | |
Jamie
2012/02/16 00:26:32
s/outerWidht/outerWidth/
alexeypa (please no reviews)
2012/02/16 01:17:56
Done.
| |
442 // the document view. The result is not precise because outerWidth can | |
443 // include pixels allocated for toolbars, window borders and such. | |
444 var viewInnerWidth = document.defaultView.innerWidth; | |
Jamie
2012/02/16 00:26:32
Why document.defaultView instead of window?
alexeypa (please no reviews)
2012/02/16 01:17:56
Done.
| |
445 var viewOuterWidth = document.defaultView.outerWidth; | |
446 var scale = Math.round(100.0 * viewOuterWidth / viewInnerWidth) / 100.0; | |
Jamie
2012/02/16 00:26:32
Why convert to int so early? You can stick with fl
alexeypa (please no reviews)
2012/02/16 01:17:56
Done.
| |
447 | |
448 // TODO(alexeypa): remove this hack once proper zooming API is available. | |
Jamie
2012/02/16 00:26:32
Can you raise a ticket for this and include the nu
| |
449 // Now pick the exact scale factor from the list of known zoom levels. | |
450 var zoom_levels = [ 0.25, 1.0/3, 0.5, 2.0/3, 0.75, 0.9, 1, 1.1, 1.25, 1.5, | |
451 1.75, 2, 2.5, 3, 4 ]; | |
452 var left = 0; | |
453 var right = zoom_levels.length; | |
454 while (left < right) { | |
Jamie
2012/02/16 00:26:32
Binary search seems overkill. In fact, you can sim
| |
455 var middle = Math.floor((left + right) / 2); | |
456 remoting.debug.log('middle=' + middle); | |
Jamie
2012/02/16 00:26:32
Remove this debug?
alexeypa (please no reviews)
2012/02/16 01:17:56
Done.
| |
457 if (zoom_levels[middle] < scale) { | |
458 left = middle + 1; | |
459 } else { | |
460 right = middle; | |
461 } | |
462 } | |
463 | |
464 if (left == 0) { | |
465 scale = zoom_levels[0]; | |
466 } else if (left < zoom_levels.length) { | |
467 if (Math.abs(zoom_levels[left - 1] - scale) < | |
468 Math.abs(zoom_levels[left] - scale)) { | |
469 scale = zoom_levels[left - 1]; | |
470 } else { | |
471 scale = zoom_levels[left]; | |
472 } | |
473 } else { | |
474 scale = zoom_levels[zoom_levels.length - 1]; | |
475 } | |
476 | |
477 scale = 1.0 / scale; | |
439 | 478 |
440 if (this.getScaleToFit()) { | 479 if (this.getScaleToFit()) { |
441 var scaleFitHeight = 1.0 * windowHeight / this.plugin.desktopHeight; | 480 var scaledHeight = 1.0 * windowHeight / (scale * this.plugin.desktopHeight); |
442 var scaleFitWidth = 1.0 * windowWidth / this.plugin.desktopWidth; | 481 var scaledWidth = 1.0 * windowWidth / (scale * this.plugin.desktopWidth); |
443 scale = Math.min(1.0, scaleFitHeight, scaleFitWidth); | 482 scale = Math.min(1.0, scaledHeight, scaledWidth, scale); |
444 } | 483 } |
445 | 484 |
446 // Resize the plugin if necessary. | 485 // Resize the plugin if necessary. |
447 this.plugin.width = this.plugin.desktopWidth * scale; | 486 this.plugin.width = Math.ceil(this.plugin.desktopWidth * scale); |
448 this.plugin.height = this.plugin.desktopHeight * scale; | 487 this.plugin.height = Math.ceil(this.plugin.desktopHeight * scale); |
449 | 488 |
450 // Position the container. | 489 // Position the container. |
451 // TODO(wez): We should take into account scrollbars when positioning. | 490 // TODO(wez): We should take into account scrollbars when positioning. |
452 var parentNode = this.plugin.parentNode; | 491 var parentNode = this.plugin.parentNode; |
453 if (this.plugin.width < windowWidth) | 492 if (this.plugin.width < windowWidth) |
454 parentNode.style.left = (windowWidth - this.plugin.width) / 2 + 'px'; | 493 parentNode.style.left = (windowWidth - this.plugin.width) / 2 + 'px'; |
455 else | 494 else |
456 parentNode.style.left = '0'; | 495 parentNode.style.left = '0'; |
457 if (this.plugin.height < windowHeight) | 496 if (this.plugin.height < windowHeight) |
458 parentNode.style.top = (windowHeight - this.plugin.height) / 2 + 'px'; | 497 parentNode.style.top = (windowHeight - this.plugin.height) / 2 + 'px'; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
491 }; | 530 }; |
492 | 531 |
493 /** | 532 /** |
494 * Logs statistics. | 533 * Logs statistics. |
495 * | 534 * |
496 * @param {Object.<string, number>} stats | 535 * @param {Object.<string, number>} stats |
497 */ | 536 */ |
498 remoting.ClientSession.prototype.logStatistics = function(stats) { | 537 remoting.ClientSession.prototype.logStatistics = function(stats) { |
499 this.logToServer.logStatistics(stats, this.mode); | 538 this.logToServer.logStatistics(stats, this.mode); |
500 }; | 539 }; |
OLD | NEW |