Chromium Code Reviews| Index: remoting/webapp/client_session.js |
| diff --git a/remoting/webapp/client_session.js b/remoting/webapp/client_session.js |
| index 9977d58b2e98f34cc2bd7901f3e38a2d71b6482f..594ecf9e147e648c5faaa9821282d4fff3fea2a4 100644 |
| --- a/remoting/webapp/client_session.js |
| +++ b/remoting/webapp/client_session.js |
| @@ -435,17 +435,56 @@ remoting.ClientSession.prototype.updateDimensions = function() { |
| var windowWidth = window.innerWidth; |
| var windowHeight = window.innerHeight; |
| - var scale = 1.0; |
| + |
| + // Estimate browser scale factor in order to be able to translate logical |
| + // pixels on the page into physical pixels on the screen. Scale factor can |
| + // 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.
|
| + // the document view. The result is not precise because outerWidth can |
| + // include pixels allocated for toolbars, window borders and such. |
| + 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.
|
| + var viewOuterWidth = document.defaultView.outerWidth; |
| + 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.
|
| + |
| + // 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
|
| + // Now pick the exact scale factor from the list of known zoom levels. |
| + var zoom_levels = [ 0.25, 1.0/3, 0.5, 2.0/3, 0.75, 0.9, 1, 1.1, 1.25, 1.5, |
| + 1.75, 2, 2.5, 3, 4 ]; |
| + var left = 0; |
| + var right = zoom_levels.length; |
| + while (left < right) { |
|
Jamie
2012/02/16 00:26:32
Binary search seems overkill. In fact, you can sim
|
| + var middle = Math.floor((left + right) / 2); |
| + 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.
|
| + if (zoom_levels[middle] < scale) { |
| + left = middle + 1; |
| + } else { |
| + right = middle; |
| + } |
| + } |
| + |
| + if (left == 0) { |
| + scale = zoom_levels[0]; |
| + } else if (left < zoom_levels.length) { |
| + if (Math.abs(zoom_levels[left - 1] - scale) < |
| + Math.abs(zoom_levels[left] - scale)) { |
| + scale = zoom_levels[left - 1]; |
| + } else { |
| + scale = zoom_levels[left]; |
| + } |
| + } else { |
| + scale = zoom_levels[zoom_levels.length - 1]; |
| + } |
| + |
| + scale = 1.0 / scale; |
| if (this.getScaleToFit()) { |
| - var scaleFitHeight = 1.0 * windowHeight / this.plugin.desktopHeight; |
| - var scaleFitWidth = 1.0 * windowWidth / this.plugin.desktopWidth; |
| - scale = Math.min(1.0, scaleFitHeight, scaleFitWidth); |
| + var scaledHeight = 1.0 * windowHeight / (scale * this.plugin.desktopHeight); |
| + var scaledWidth = 1.0 * windowWidth / (scale * this.plugin.desktopWidth); |
| + scale = Math.min(1.0, scaledHeight, scaledWidth, scale); |
| } |
| // Resize the plugin if necessary. |
| - this.plugin.width = this.plugin.desktopWidth * scale; |
| - this.plugin.height = this.plugin.desktopHeight * scale; |
| + this.plugin.width = Math.ceil(this.plugin.desktopWidth * scale); |
| + this.plugin.height = Math.ceil(this.plugin.desktopHeight * scale); |
| // Position the container. |
| // TODO(wez): We should take into account scrollbars when positioning. |