Cleanup for the resize related functions
Renamed functions, added clarifying comments and moved the resize related functions closer to the other viewport functions.
This commit is contained in:
parent
553864e858
commit
777cb7a0c5
|
@ -311,6 +311,8 @@ var RFB;
|
||||||
this._sock.flush();
|
this._sock.flush();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Requests a change of remote desktop size. This message is an extension
|
||||||
|
// and may only be sent if we have received an ExtendedDesktopSize message
|
||||||
setDesktopSize: function (width, height) {
|
setDesktopSize: function (width, height) {
|
||||||
if (this._rfb_state !== "normal") { return; }
|
if (this._rfb_state !== "normal") { return; }
|
||||||
|
|
||||||
|
|
147
include/ui.js
147
include/ui.js
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* noVNC: HTML5 VNC client
|
* noVNC: HTML5 VNC client
|
||||||
* Copyright (C) 2012 Joel Martin
|
* Copyright (C) 2012 Joel Martin
|
||||||
* Copyright (C) 2015 Samuel Mannehed for Cendio AB
|
* Copyright (C) 2016 Samuel Mannehed for Cendio AB
|
||||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||||
*
|
*
|
||||||
* See README.md for usage and integration instructions.
|
* See README.md for usage and integration instructions.
|
||||||
|
@ -132,7 +132,7 @@ var UI;
|
||||||
UI.setBarPosition();
|
UI.setBarPosition();
|
||||||
|
|
||||||
Util.addEvent(window, 'resize', function () {
|
Util.addEvent(window, 'resize', function () {
|
||||||
UI.onresize();
|
UI.applyResizeMode();
|
||||||
UI.setViewClip();
|
UI.setViewClip();
|
||||||
UI.updateViewDrag();
|
UI.updateViewDrag();
|
||||||
UI.setBarPosition();
|
UI.setBarPosition();
|
||||||
|
@ -188,7 +188,7 @@ var UI;
|
||||||
'onUpdateState': UI.updateState,
|
'onUpdateState': UI.updateState,
|
||||||
'onXvpInit': UI.updateXvpVisualState,
|
'onXvpInit': UI.updateXvpVisualState,
|
||||||
'onClipboard': UI.clipReceive,
|
'onClipboard': UI.clipReceive,
|
||||||
'onFBUComplete': UI.FBUComplete,
|
'onFBUComplete': UI.initialResize,
|
||||||
'onFBResize': UI.updateViewDrag,
|
'onFBResize': UI.updateViewDrag,
|
||||||
'onDesktopName': UI.updateDocumentTitle});
|
'onDesktopName': UI.updateDocumentTitle});
|
||||||
return true;
|
return true;
|
||||||
|
@ -245,60 +245,6 @@ var UI;
|
||||||
$D("noVNC_resize").onchange = UI.enableDisableViewClip;
|
$D("noVNC_resize").onchange = UI.enableDisableViewClip;
|
||||||
},
|
},
|
||||||
|
|
||||||
onresize: function (callback) {
|
|
||||||
if (!UI.rfb) return;
|
|
||||||
|
|
||||||
var size = UI.screenSize();
|
|
||||||
|
|
||||||
if (size && UI.rfb_state === 'normal' && UI.rfb.get_display()) {
|
|
||||||
var display = UI.rfb.get_display();
|
|
||||||
var scaleType = UI.getSetting('resize');
|
|
||||||
if (scaleType === 'remote') {
|
|
||||||
// use remote resizing
|
|
||||||
|
|
||||||
// When the local window has been resized, wait until the size remains
|
|
||||||
// the same for 0.5 seconds before sending the request for changing
|
|
||||||
// the resolution of the session
|
|
||||||
clearTimeout(UI.resizeTimeout);
|
|
||||||
UI.resizeTimeout = setTimeout(function(){
|
|
||||||
display.set_maxWidth(size.w);
|
|
||||||
display.set_maxHeight(size.h);
|
|
||||||
Util.Debug('Attempting setDesktopSize(' +
|
|
||||||
size.w + ', ' + size.h + ')');
|
|
||||||
UI.rfb.setDesktopSize(size.w, size.h);
|
|
||||||
}, 500);
|
|
||||||
} else if (scaleType === 'scale' || scaleType === 'downscale') {
|
|
||||||
// use local scaling
|
|
||||||
|
|
||||||
var downscaleOnly = scaleType === 'downscale';
|
|
||||||
var scaleRatio = display.autoscale(size.w, size.h, downscaleOnly);
|
|
||||||
UI.rfb.get_mouse().set_scale(scaleRatio);
|
|
||||||
Util.Debug('Scaling by ' + UI.rfb.get_mouse().get_scale());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// The screen is always the same size as the available
|
|
||||||
// viewport minus the height of the control bar
|
|
||||||
screenSize: function () {
|
|
||||||
var screen = $D('noVNC_screen');
|
|
||||||
|
|
||||||
// Hide the scrollbars until the size is calculated
|
|
||||||
screen.style.overflow = "hidden";
|
|
||||||
|
|
||||||
var pos = Util.getPosition(screen);
|
|
||||||
var w = pos.width;
|
|
||||||
var h = pos.height;
|
|
||||||
|
|
||||||
screen.style.overflow = "visible";
|
|
||||||
|
|
||||||
if (isNaN(w) || isNaN(h)) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return {w: w, h: h};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Read form control compatible setting from cookie
|
// Read form control compatible setting from cookie
|
||||||
getSetting: function(name) {
|
getSetting: function(name) {
|
||||||
var ctrl = $D('noVNC_' + name);
|
var ctrl = $D('noVNC_' + name);
|
||||||
|
@ -792,16 +738,6 @@ var UI;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// This resize can not be done until we know from the first Frame Buffer Update
|
|
||||||
// if it is supported or not.
|
|
||||||
// The resize is needed to make sure the server desktop size is updated to the
|
|
||||||
// corresponding size of the current local window when reconnecting to an
|
|
||||||
// existing session.
|
|
||||||
FBUComplete: function(rfb, fbu) {
|
|
||||||
UI.onresize();
|
|
||||||
UI.rfb.set_onFBUComplete(function() { });
|
|
||||||
},
|
|
||||||
|
|
||||||
// Display the desktop name in the document title
|
// Display the desktop name in the document title
|
||||||
updateDocumentTitle: function(rfb, name) {
|
updateDocumentTitle: function(rfb, name) {
|
||||||
document.title = name + " - noVNC";
|
document.title = name + " - noVNC";
|
||||||
|
@ -854,7 +790,7 @@ var UI;
|
||||||
UI.rfb.disconnect();
|
UI.rfb.disconnect();
|
||||||
|
|
||||||
// Restore the callback used for initial resize
|
// Restore the callback used for initial resize
|
||||||
UI.rfb.set_onFBUComplete(UI.FBUComplete);
|
UI.rfb.set_onFBUComplete(UI.initialResize);
|
||||||
|
|
||||||
$D('noVNC_logo').style.display = "block";
|
$D('noVNC_logo').style.display = "block";
|
||||||
$D('noVNC_screen').style.display = "none";
|
$D('noVNC_screen').style.display = "none";
|
||||||
|
@ -888,6 +824,81 @@ var UI;
|
||||||
Util.Debug("<< UI.clipSend");
|
Util.Debug("<< UI.clipSend");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Apply remote resizing or local scaling
|
||||||
|
applyResizeMode: function () {
|
||||||
|
if (!UI.rfb) return;
|
||||||
|
|
||||||
|
var screen = UI.screenSize();
|
||||||
|
|
||||||
|
if (screen && UI.rfb_state === 'normal' && UI.rfb.get_display()) {
|
||||||
|
|
||||||
|
var display = UI.rfb.get_display();
|
||||||
|
var resizeMode = UI.getSetting('resize');
|
||||||
|
|
||||||
|
if (resizeMode === 'remote') {
|
||||||
|
|
||||||
|
// Request changing the resolution of the remote display to
|
||||||
|
// the size of the local browser viewport.
|
||||||
|
|
||||||
|
// In order to not send multiple requests before the browser-resize
|
||||||
|
// is finished we wait 0.5 seconds before sending the request.
|
||||||
|
clearTimeout(UI.resizeTimeout);
|
||||||
|
UI.resizeTimeout = setTimeout(function(){
|
||||||
|
|
||||||
|
// Limit the viewport to the size of the browser window
|
||||||
|
display.set_maxWidth(screen.w);
|
||||||
|
display.set_maxHeight(screen.h);
|
||||||
|
|
||||||
|
Util.Debug('Attempting setDesktopSize(' +
|
||||||
|
screen.w + ', ' + screen.h + ')');
|
||||||
|
|
||||||
|
// Request a remote size covering the viewport
|
||||||
|
UI.rfb.setDesktopSize(screen.w, screen.h);
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
} else if (resizeMode === 'scale' || resizeMode === 'downscale') {
|
||||||
|
var downscaleOnly = resizeMode === 'downscale';
|
||||||
|
var scaleRatio = display.autoscale(screen.w, screen.h, downscaleOnly);
|
||||||
|
UI.rfb.get_mouse().set_scale(scaleRatio);
|
||||||
|
Util.Debug('Scaling by ' + UI.rfb.get_mouse().get_scale());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// The screen is always the same size as the available viewport
|
||||||
|
// in the browser window minus the height of the control bar
|
||||||
|
screenSize: function () {
|
||||||
|
var screen = $D('noVNC_screen');
|
||||||
|
|
||||||
|
// Hide the scrollbars until the size is calculated
|
||||||
|
screen.style.overflow = "hidden";
|
||||||
|
|
||||||
|
var pos = Util.getPosition(screen);
|
||||||
|
var w = pos.width;
|
||||||
|
var h = pos.height;
|
||||||
|
|
||||||
|
screen.style.overflow = "visible";
|
||||||
|
|
||||||
|
if (isNaN(w) || isNaN(h)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return {w: w, h: h};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Normally we only apply the current resize mode after a window resize
|
||||||
|
// event. This means that when a new connection is opened, there is no
|
||||||
|
// resize mode active.
|
||||||
|
// We have to wait until the first FBU because this is where the client
|
||||||
|
// will find the supported encodings of the server. Some calls later in
|
||||||
|
// the chain is dependant on knowing the server-capabilities.
|
||||||
|
initialResize: function(rfb, fbu) {
|
||||||
|
UI.applyResizeMode();
|
||||||
|
// After doing this once, we remove the callback.
|
||||||
|
UI.rfb.set_onFBUComplete(function() { });
|
||||||
|
},
|
||||||
|
|
||||||
// Set and configure viewport clipping
|
// Set and configure viewport clipping
|
||||||
setViewClip: function(clip) {
|
setViewClip: function(clip) {
|
||||||
var display;
|
var display;
|
||||||
|
|
Loading…
Reference in New Issue