controlbarMouseDownOffsetY: 0,
keyboardVisible: false,
- isTouchDevice: false,
isSafari: false,
rememberedClipSetting: null,
lastKeyboardinput: null,
start: function(callback) {
// Setup global variables first
- UI.isTouchDevice = 'ontouchstart' in document.documentElement;
UI.isSafari = (navigator.userAgent.indexOf('Safari') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1);
UI.initSettings();
// Adapt the interface for touch screen devices
- if (UI.isTouchDevice) {
+ if (Util.isTouchDevice) {
document.documentElement.classList.add("noVNC_touch");
// Remove the address bar
setTimeout(function() { window.scrollTo(0, 1); }, 100);
UI.initSetting('password', '');
UI.initSetting('encrypt', (window.location.protocol === "https:"));
UI.initSetting('true_color', true);
- UI.initSetting('cursor', !UI.isTouchDevice);
+ UI.initSetting('cursor', !Util.isTouchDevice);
UI.initSetting('resize', 'off');
UI.initSetting('shared', true);
UI.initSetting('view_only', false);
if (Util.browserSupportsCursorURIs()) {
document.getElementById('noVNC_setting_cursor').disabled = UI.connected;
} else {
- UI.updateSetting('cursor', !UI.isTouchDevice);
+ UI.updateSetting('cursor', !Util.isTouchDevice);
document.getElementById('noVNC_setting_cursor').disabled = true;
}
},
// Move the handle but don't allow any position outside the bounds
- moveControlbarHandle: function (posY) {
+ moveControlbarHandle: function (viewportRelativeY) {
var handle = document.getElementById("noVNC_control_bar_handle");
- var handleHeight = Util.getPosition(handle).height;
- var controlbar = document.getElementById("noVNC_control_bar");
- var controlbarBounds = Util.getPosition(controlbar);
- var controlbarTop = controlbarBounds.y;
- var controlbarBottom = controlbarBounds.y + controlbarBounds.height;
+ var handleHeight = handle.getBoundingClientRect().height;
+ var controlbarBounds = document.getElementById("noVNC_control_bar")
+ .getBoundingClientRect();
var margin = 10;
- var viewportY = posY;
+ // These heights need to be non-zero for the below logic to work
+ if (handleHeight === 0 || controlbarBounds.height === 0) {
+ return;
+ }
+
+ var newY = viewportRelativeY;
+
+ // Check if the coordinates are outside the control bar
+ if (newY < controlbarBounds.top + margin) {
+ // Force coordinates to be below the top of the control bar
+ newY = controlbarBounds.top + margin;
- // Refuse coordinates outside the control bar
- if (viewportY < controlbarTop + margin) {
- viewportY = controlbarTop + margin;
- } else if (viewportY > controlbarBottom - handleHeight - margin) {
- viewportY = controlbarBottom - handleHeight - margin;
+ } else if (newY > controlbarBounds.top +
+ controlbarBounds.height - handleHeight - margin) {
+ // Force coordinates to be above the bottom of the control bar
+ newY = controlbarBounds.top +
+ controlbarBounds.height - handleHeight - margin;
}
// Corner case: control bar too small for stable position
if (controlbarBounds.height < (handleHeight + margin * 2)) {
- viewportY = controlbarTop + (controlbarBounds.height - handleHeight) / 2;
+ newY = controlbarBounds.top +
+ (controlbarBounds.height - handleHeight) / 2;
}
- var relativeY = viewportY - controlbarTop;
- handle.style.transform = "translateY(" + relativeY + "px)";
+ // The transform needs coordinates that are relative to the parent
+ var parentRelativeY = newY - controlbarBounds.top;
+ handle.style.transform = "translateY(" + parentRelativeY + "px)";
},
updateControlbarHandle: function () {
+ // Since the control bar is fixed on the viewport and not the page,
+ // the move function expects coordinates relative the the viewport.
var handle = document.getElementById("noVNC_control_bar_handle");
- var pos = Util.getPosition(handle);
- UI.moveControlbarHandle(pos.y);
+ var handleBounds = handle.getBoundingClientRect();
+ UI.moveControlbarHandle(handleBounds.top);
},
controlbarHandleMouseUp: function(e) {
if (Util.browserSupportsCursorURIs()) {
UI.updateSetting('cursor');
} else {
- UI.updateSetting('cursor', !UI.isTouchDevice);
+ UI.updateSetting('cursor', !Util.isTouchDevice);
document.getElementById('noVNC_setting_cursor').disabled = true;
}
UI.updateSetting('clip');
UI.rememberedClipSetting = UI.getSetting('clip');
UI.setViewClip(true);
document.getElementById('noVNC_setting_clip').disabled = true;
- } else if (document.body.msRequestFullscreen && UI.rememberedClip !== null) {
+ } else if (document.body.msRequestFullscreen &&
+ UI.rememberedClipSetting !== null) {
// Restore view clip to what it was before fullscreen on IE
UI.setViewClip(UI.rememberedClipSetting);
document.getElementById('noVNC_setting_clip').disabled =
- UI.connected || UI.isTouchDevice;
+ UI.connected || Util.isTouchDevice;
} else {
document.getElementById('noVNC_setting_clip').disabled =
- UI.connected || UI.isTouchDevice;
- if (UI.isTouchDevice) {
+ UI.connected || Util.isTouchDevice;
+ if (Util.isTouchDevice) {
UI.setViewClip(true);
}
}
// Different behaviour for touch vs non-touch
// The button is disabled instead of hidden on touch devices
- if (UI.isTouchDevice) {
+ if (Util.isTouchDevice) {
viewDragButton.classList.remove("noVNC_hidden");
if (clipping) {
* ------v------*/
showVirtualKeyboard: function() {
- if (!UI.isTouchDevice) return;
+ if (!Util.isTouchDevice) return;
var input = document.getElementById('noVNC_keyboardinput');
},
hideVirtualKeyboard: function() {
- if (!UI.isTouchDevice) return;
+ if (!Util.isTouchDevice) return;
var input = document.getElementById('noVNC_keyboardinput');
grab: function () {
var c = this._target;
- if ('ontouchstart' in document.documentElement) {
+ if (Util.isTouchDevice) {
c.addEventListener('touchstart', this._eventHandlers.mousedown);
window.addEventListener('touchend', this._eventHandlers.mouseup);
c.addEventListener('touchend', this._eventHandlers.mouseup);
c.addEventListener('touchmove', this._eventHandlers.mousemove);
- } else {
- c.addEventListener('mousedown', this._eventHandlers.mousedown);
- window.addEventListener('mouseup', this._eventHandlers.mouseup);
- c.addEventListener('mouseup', this._eventHandlers.mouseup);
- c.addEventListener('mousemove', this._eventHandlers.mousemove);
- c.addEventListener((Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
- this._eventHandlers.mousewheel);
}
+ c.addEventListener('mousedown', this._eventHandlers.mousedown);
+ window.addEventListener('mouseup', this._eventHandlers.mouseup);
+ c.addEventListener('mouseup', this._eventHandlers.mouseup);
+ c.addEventListener('mousemove', this._eventHandlers.mousemove);
+ c.addEventListener((Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
+ this._eventHandlers.mousewheel);
/* Work around right and middle click browser behaviors */
document.addEventListener('click', this._eventHandlers.mousedisable);
ungrab: function () {
var c = this._target;
- if ('ontouchstart' in document.documentElement) {
+ if (Util.isTouchDevice) {
c.removeEventListener('touchstart', this._eventHandlers.mousedown);
window.removeEventListener('touchend', this._eventHandlers.mouseup);
c.removeEventListener('touchend', this._eventHandlers.mouseup);
c.removeEventListener('touchmove', this._eventHandlers.mousemove);
- } else {
- c.removeEventListener('mousedown', this._eventHandlers.mousedown);
- window.removeEventListener('mouseup', this._eventHandlers.mouseup);
- c.removeEventListener('mouseup', this._eventHandlers.mouseup);
- c.removeEventListener('mousemove', this._eventHandlers.mousemove);
- c.removeEventListener((Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
- this._eventHandlers.mousewheel);
}
+ c.removeEventListener('mousedown', this._eventHandlers.mousedown);
+ window.removeEventListener('mouseup', this._eventHandlers.mouseup);
+ c.removeEventListener('mouseup', this._eventHandlers.mouseup);
+ c.removeEventListener('mousemove', this._eventHandlers.mousemove);
+ c.removeEventListener((Util.Engine.gecko) ? 'DOMMouseScroll' : 'mousewheel',
+ this._eventHandlers.mousewheel);
/* Work around right and middle click browser behaviors */
document.removeEventListener('click', this._eventHandlers.mousedisable);