Commit 2553f800 authored by wez's avatar wez Committed by Commit bot

Add a per-host desktopScale option, available via the JS console.

This CL adds a setDesktopScale() method to ClientSession, allowing the JS console to be used to easily apply a new desktop scale factor, to be applied to the current session and all subsequent sessions to the current host from this client. If the connected host supports dynamic resize then desktopZoom changes will take effect immediately.

For example, a user with a Chromebook Pixel can set desktopScale to 2.0 to have a low-DPI host set to match the Pixel's physical resolution 1:1, rather than being set to match the logical resolution and up-scaled.

BUG=135089, 406100
TEST=Connect to Linux host w/ resize-to-client on & scale-to-fit *off*. Open Dev Console for app's main.html and run e.g. remoting.clientSession.setDesktopScale(scale) for different values of |scale|, and verify that: (1) |scale==0.5| gives a low-res desktop that is up-scaled to fill the client area. (2) on low-DPI devices, |scale==2.0| gives a normal-res desktop that is bigger than the client area. (3) on Pixel |scale==2.0| gives a desktop sized 1:1 to the device's native display resolution. (4) on Pixel |scale==3.0| gives a desktop scaled 1:1 to the device's native display resolution, and sized to be larger than the client area.

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

Cr-Commit-Position: refs/heads/master@{#308490}
parent ada7894a
...@@ -138,6 +138,8 @@ remoting.ClientSession = function(signalStrategy, container, hostDisplayName, ...@@ -138,6 +138,8 @@ remoting.ClientSession = function(signalStrategy, container, hostDisplayName,
/** @private */ /** @private */
this.resizeToClient_ = true; this.resizeToClient_ = true;
/** @private */ /** @private */
this.desktopScale_ = 1.0;
/** @private */
this.remapKeys_ = ''; this.remapKeys_ = '';
/** @private */ /** @private */
this.hasReceivedFrame_ = false; this.hasReceivedFrame_ = false;
...@@ -386,6 +388,7 @@ remoting.ClientSession.STATS_KEY_ROUNDTRIP_LATENCY = 'roundtripLatency'; ...@@ -386,6 +388,7 @@ remoting.ClientSession.STATS_KEY_ROUNDTRIP_LATENCY = 'roundtripLatency';
remoting.ClientSession.KEY_REMAP_KEYS = 'remapKeys'; remoting.ClientSession.KEY_REMAP_KEYS = 'remapKeys';
remoting.ClientSession.KEY_RESIZE_TO_CLIENT = 'resizeToClient'; remoting.ClientSession.KEY_RESIZE_TO_CLIENT = 'resizeToClient';
remoting.ClientSession.KEY_SHRINK_TO_FIT = 'shrinkToFit'; remoting.ClientSession.KEY_SHRINK_TO_FIT = 'shrinkToFit';
remoting.ClientSession.KEY_DESKTOP_SCALE = 'desktopScale';
/** /**
* Set of capabilities for which hasCapability_() can be used to test. * Set of capabilities for which hasCapability_() can be used to test.
...@@ -506,6 +509,12 @@ remoting.ClientSession.prototype.onHostSettingsLoaded_ = function(options) { ...@@ -506,6 +509,12 @@ remoting.ClientSession.prototype.onHostSettingsLoaded_ = function(options) {
this.shrinkToFit_ = /** @type {boolean} */ this.shrinkToFit_ = /** @type {boolean} */
options[remoting.ClientSession.KEY_SHRINK_TO_FIT]; options[remoting.ClientSession.KEY_SHRINK_TO_FIT];
} }
if (remoting.ClientSession.KEY_DESKTOP_SCALE in options &&
typeof(options[remoting.ClientSession.KEY_DESKTOP_SCALE]) ==
'number') {
this.desktopScale_ = /** @type {number} */
options[remoting.ClientSession.KEY_DESKTOP_SCALE];
}
/** @param {boolean} result */ /** @param {boolean} result */
this.plugin_.initialize(this.onPluginInitialized_.bind(this)); this.plugin_.initialize(this.onPluginInitialized_.bind(this));
...@@ -773,6 +782,26 @@ remoting.ClientSession.prototype.sendPrintScreen = function() { ...@@ -773,6 +782,26 @@ remoting.ClientSession.prototype.sendPrintScreen = function() {
this.sendKeyCombination_([0x070046]); this.sendKeyCombination_([0x070046]);
} }
/**
* Sets and stores the scale factor to apply to host sizing requests.
* The desktopScale applies to the dimensions reported to the host, not
* to the client DPI reported to it.
*
* @param {number} desktopScale Scale factor to apply.
*/
remoting.ClientSession.prototype.setDesktopScale = function(desktopScale) {
this.desktopScale_ = desktopScale;
// onResize() will update the plugin size and scrollbars for the new
// scaled plugin dimensions, and send a client resolution notification.
this.onResize();
// Save the new desktop scale setting.
var options = {};
options[remoting.ClientSession.KEY_DESKTOP_SCALE] = this.desktopScale_;
remoting.HostSettings.save(this.hostId_, options);
}
/** /**
* Sets and stores the key remapping setting for the current host. * Sets and stores the key remapping setting for the current host.
* *
...@@ -844,10 +873,7 @@ remoting.ClientSession.prototype.applyRemapKeys_ = function(apply) { ...@@ -844,10 +873,7 @@ remoting.ClientSession.prototype.applyRemapKeys_ = function(apply) {
remoting.ClientSession.prototype.setScreenMode = remoting.ClientSession.prototype.setScreenMode =
function(shrinkToFit, resizeToClient) { function(shrinkToFit, resizeToClient) {
if (resizeToClient && !this.resizeToClient_) { if (resizeToClient && !this.resizeToClient_) {
var clientArea = this.getClientArea_(); this.notifyClientResolution_();
this.plugin_.notifyClientResolution(clientArea.width,
clientArea.height,
window.devicePixelRatio);
} }
// If enabling shrink, reset bump-scroll offsets. // If enabling shrink, reset bump-scroll offsets.
...@@ -1010,10 +1036,7 @@ remoting.ClientSession.prototype.onConnectionStatusUpdate_ = ...@@ -1010,10 +1036,7 @@ remoting.ClientSession.prototype.onConnectionStatusUpdate_ =
this.setFocusHandlers_(); this.setFocusHandlers_();
this.onDesktopSizeChanged_(); this.onDesktopSizeChanged_();
if (this.resizeToClient_) { if (this.resizeToClient_) {
var clientArea = this.getClientArea_(); this.notifyClientResolution_();
this.plugin_.notifyClientResolution(clientArea.width,
clientArea.height,
window.devicePixelRatio);
} }
// Activate full-screen related UX. // Activate full-screen related UX.
remoting.fullscreen.addListener(this.callOnFullScreenChanged_); remoting.fullscreen.addListener(this.callOnFullScreenChanged_);
...@@ -1106,10 +1129,7 @@ remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) { ...@@ -1106,10 +1129,7 @@ remoting.ClientSession.prototype.onSetCapabilities_ = function(capabilities) {
this.capabilities_ = capabilities; this.capabilities_ = capabilities;
if (this.hasCapability_( if (this.hasCapability_(
remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION)) { remoting.ClientSession.Capability.SEND_INITIAL_RESOLUTION)) {
var clientArea = this.getClientArea_(); this.notifyClientResolution_();
this.plugin_.notifyClientResolution(clientArea.width,
clientArea.height,
window.devicePixelRatio);
} }
if (this.hasCapability_(remoting.ClientSession.Capability.GOOGLE_DRIVE)) { if (this.hasCapability_(remoting.ClientSession.Capability.GOOGLE_DRIVE)) {
this.sendGoogleDriveAccessToken_(); this.sendGoogleDriveAccessToken_();
...@@ -1178,10 +1198,7 @@ remoting.ClientSession.prototype.onResize = function() { ...@@ -1178,10 +1198,7 @@ remoting.ClientSession.prototype.onResize = function() {
} }
var clientArea = this.getClientArea_(); var clientArea = this.getClientArea_();
this.notifyClientResolutionTimer_ = window.setTimeout( this.notifyClientResolutionTimer_ = window.setTimeout(
this.plugin_.notifyClientResolution.bind(this.plugin_, this.notifyClientResolution_.bind(this),
clientArea.width,
clientArea.height,
window.devicePixelRatio),
kResizeRateLimitMs); kResizeRateLimitMs);
} }
...@@ -1289,6 +1306,10 @@ remoting.ClientSession.prototype.updateDimensions = function() { ...@@ -1289,6 +1306,10 @@ remoting.ClientSession.prototype.updateDimensions = function() {
var hostPixelRatioY = Math.ceil(this.plugin_.getDesktopYDpi() / 96); var hostPixelRatioY = Math.ceil(this.plugin_.getDesktopYDpi() / 96);
var hostPixelRatio = Math.min(hostPixelRatioX, hostPixelRatioY); var hostPixelRatio = Math.min(hostPixelRatioX, hostPixelRatioY);
// Include the desktopScale in the hostPixelRatio before comparing it with
// the client devicePixelRatio to determine the "natural" scale to use.
hostPixelRatio *= this.desktopScale_;
// Down-scale by the smaller of the client and host ratios. // Down-scale by the smaller of the client and host ratios.
var scale = 1.0 / Math.min(window.devicePixelRatio, hostPixelRatio); var scale = 1.0 / Math.min(window.devicePixelRatio, hostPixelRatio);
...@@ -1634,6 +1655,18 @@ remoting.ClientSession.prototype.getClientArea_ = function() { ...@@ -1634,6 +1655,18 @@ remoting.ClientSession.prototype.getClientArea_ = function() {
{ 'width': window.innerWidth, 'height': window.innerHeight }; { 'width': window.innerWidth, 'height': window.innerHeight };
}; };
/**
* Notifies the host of the client's current dimensions and DPI.
* Also takes into account per-host scaling factor, if configured.
* @private
*/
remoting.ClientSession.prototype.notifyClientResolution_ = function() {
var clientArea = this.getClientArea_();
this.plugin_.notifyClientResolution(clientArea.width * this.desktopScale_,
clientArea.height * this.desktopScale_,
window.devicePixelRatio);
}
/** /**
* @param {string} url * @param {string} url
* @param {number} hotspotX * @param {number} hotspotX
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment