Index: remoting/webapp/client_session.js |
diff --git a/remoting/webapp/client_session.js b/remoting/webapp/client_session.js |
index 1acc7b75ce45b60f881f1ffd1e7542c94dd1417a..42b456dc32980fe84230c74e542d3b006cfd6bd2 100644 |
--- a/remoting/webapp/client_session.js |
+++ b/remoting/webapp/client_session.js |
@@ -442,20 +442,44 @@ remoting.ClientSession.prototype.updateDimensions = function() { |
var windowWidth = window.innerWidth; |
var windowHeight = window.innerHeight; |
+ |
+ // 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 outerWidth and innerWidth of |
+ // the document view. The result is not precise because outerWidth can |
+ // include pixels allocated for toolbars, window borders and such. |
+ var windowOuterWidth = window.outerWidth; |
+ |
+ // TODO(alexeypa): remove this hack once proper zooming API is available. |
+ // See issue #30583 for details. |
+ // 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.0, 1.1, 1.25, 1.5, |
+ 1.75, 2, 2.5, 3.0, 4.0 ]; |
+ var min_delta = Number.MAX_VALUE; |
var scale = 1.0; |
+ for (var i in zoom_levels) { |
+ // The difference between outerWidht and scaled innerWidth should always be |
Jamie
2012/02/17 00:10:35
Nit: Typo
|
+ // positive. However due to rounding done by the browser the difference |
+ // becomes negative in some cases. |
+ var delta = Math.abs(windowOuterWidth - windowWidth * zoom_levels[i]); |
+ if (delta < min_delta) { |
+ min_delta = delta; |
+ scale = 1.0 / zoom_levels[i]; |
+ } |
+ } |
if (this.getScaleToFit()) { |
- var scaleFitWidth = 1.0 * windowWidth / this.plugin.desktopWidth; |
- var scaleFitHeight = 1.0 * windowHeight / this.plugin.desktopHeight; |
- scale = Math.min(1.0, scaleFitHeight, scaleFitWidth); |
+ var scaledWidth = 1.0 * windowWidth / (scale * this.plugin.desktopWidth); |
+ var scaledHeight = 1.0 * windowHeight / (scale * this.plugin.desktopHeight); |
+ scale = Math.min(1.0, scaledHeight, scaledWidth) * scale; |
} |
var width = this.plugin.desktopWidth * scale; |
var height = this.plugin.desktopHeight * scale; |
// Resize the plugin if necessary. |
- this.plugin.element().width = width; |
- this.plugin.element().height = height; |
+ this.plugin.element().width = Math.ceil(this.plugin.desktopWidth * scale); |
+ this.plugin.element().height = Math.ceil(this.plugin.desktopHeight * scale); |
// Position the container. |
// TODO(wez): We should take into account scrollbars when positioning. |