Skip to content

Commit

Permalink
[Chromoting] Fix initial resolution for AppRemoting.
Browse files Browse the repository at this point in the history
crrev.com/1015523005 introduced a bug where the initial resolution on a
new VM was the wrong resolution. This was caused by two problems:

* shrinkToFit was set to false, so the dimensions were set incorrectly
  for AppRemoting

* Only the first desktop resize event was being handled, so the client
  didn't get the latest dimensions.

BUG=

Review URL: https://codereview.chromium.org/1077263002

Cr-Commit-Position: refs/heads/master@{#324733}
  • Loading branch information
garykac authored and Commit bot committed Apr 11, 2015
1 parent 8155760 commit 4d6dd27
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions remoting/webapp/app_remoting/js/app_connected_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ remoting.AppConnectedView = function(containerElement, connectionInfo) {
this.plugin_, containerElement,
containerElement.querySelector('.mouse-cursor-overlay'));

var eventHook = new base.EventHook(
var windowShapeHook = new base.EventHook(
this.plugin_.hostDesktop(),
remoting.HostDesktop.Events.shapeChanged,
remoting.windowShape.setDesktopRects.bind(remoting.windowShape));

var desktopSizeHook = new base.EventHook(
this.plugin_.hostDesktop(),
remoting.HostDesktop.Events.sizeChanged,
this.onDesktopSizeChanged_.bind(this));

/** @private */
this.disposables_ = new base.Disposables(baseView, eventHook);
this.disposables_ = new base.Disposables(
baseView, windowShapeHook, desktopSizeHook);

this.resizeHostToClientArea_().then(
this.setPluginSize_.bind(this)
);
this.resizeHostToClientArea_();
};

/**
Expand All @@ -55,40 +59,35 @@ remoting.AppConnectedView.prototype.dispose = function() {

/**
* Resize the host to the dimensions of the current window.
*
* @return {Promise} A promise that resolves when the host finishes responding
* to the resize request.
* @private
*/
remoting.AppConnectedView.prototype.resizeHostToClientArea_ = function() {
var hostDesktop = this.plugin_.hostDesktop();
var desktopScale = this.host_.options.desktopScale;

return new Promise(function(/** Function */ resolve) {
var eventHook = new base.EventHook(
hostDesktop, remoting.HostDesktop.Events.sizeChanged, resolve);
hostDesktop.resize(window.innerWidth * desktopScale,
window.innerHeight * desktopScale,
window.devicePixelRatio);
});
hostDesktop.resize(window.innerWidth * desktopScale,
window.innerHeight * desktopScale,
window.devicePixelRatio);
};


/**
* Adjust the size of the plugin according to the dimensions of the hostDesktop.
*
* @param {{width:number, height:number, xDpi:number, yDpi:number}} hostDesktop
* @private
*/
remoting.AppConnectedView.prototype.setPluginSize_ = function(hostDesktop) {
remoting.AppConnectedView.prototype.onDesktopSizeChanged_ =
function(hostDesktop) {
// The first desktop size change indicates that we can close the loading
// window.
remoting.LoadingWindow.close();

var hostSize = { width: hostDesktop.width, height: hostDesktop.height };
var hostDpi = { x: hostDesktop.xDpi, y: hostDesktop.yDpi };
var clientArea = { width: window.innerWidth, height: window.innerHeight };
var newSize = remoting.DesktopViewport.choosePluginSize(
clientArea, window.devicePixelRatio,
hostSize, hostDpi, this.host_.options.desktopScale,
true /* fullscreen */ , false /* shrinkToFit */ );
true /* fullscreen */ , true /* shrinkToFit */ );

this.plugin_.element().style.width = newSize.width + 'px';
this.plugin_.element().style.height = newSize.height + 'px';
Expand Down

0 comments on commit 4d6dd27

Please sign in to comment.