@novnc/novnc 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTHORS +13 -0
- package/LICENSE.txt +2 -1
- package/README.md +69 -3
- package/core/base64.js +35 -41
- package/core/decoders/copyrect.js +22 -0
- package/core/decoders/hextile.js +137 -0
- package/core/decoders/raw.js +56 -0
- package/core/decoders/rre.js +44 -0
- package/core/decoders/tight.js +315 -0
- package/core/decoders/tightpng.js +27 -0
- package/core/deflator.js +85 -0
- package/core/des.js +90 -95
- package/core/display.js +254 -297
- package/core/encodings.js +7 -3
- package/core/inflator.js +48 -20
- package/core/input/domkeytable.js +21 -24
- package/core/input/fixedkeys.js +3 -1
- package/core/input/gesturehandler.js +567 -0
- package/core/input/keyboard.js +194 -120
- package/core/input/keysym.js +2 -0
- package/core/input/keysymdef.js +3 -3
- package/core/input/util.js +53 -12
- package/core/input/vkeys.js +2 -1
- package/core/rfb.js +1937 -1496
- package/core/util/browser.js +80 -29
- package/core/util/cursor.js +253 -0
- package/core/util/element.js +32 -0
- package/core/util/events.js +59 -55
- package/core/util/eventtarget.js +25 -30
- package/core/util/int.js +15 -0
- package/core/util/logging.js +21 -16
- package/core/util/polyfill.js +15 -8
- package/core/util/strings.js +21 -8
- package/core/websock.js +145 -167
- package/docs/API.md +31 -10
- package/lib/base64.js +115 -0
- package/lib/decoders/copyrect.js +44 -0
- package/lib/decoders/hextile.js +173 -0
- package/lib/decoders/raw.js +78 -0
- package/lib/decoders/rre.js +65 -0
- package/lib/decoders/tight.js +350 -0
- package/lib/decoders/tightpng.js +67 -0
- package/lib/deflator.js +99 -0
- package/lib/des.js +314 -0
- package/lib/display.js +733 -0
- package/lib/encodings.js +64 -0
- package/lib/inflator.js +87 -0
- package/lib/input/domkeytable.js +282 -0
- package/lib/input/fixedkeys.js +123 -0
- package/lib/input/gesturehandler.js +642 -0
- package/lib/input/keyboard.js +429 -0
- package/lib/input/keysym.js +1135 -0
- package/lib/input/keysymdef.js +1354 -0
- package/lib/input/util.js +304 -0
- package/lib/input/vkeys.js +127 -0
- package/lib/input/xtscancodes.js +505 -0
- package/lib/rfb.js +3448 -0
- package/lib/util/browser.js +131 -0
- package/lib/util/cursor.js +314 -0
- package/lib/util/element.js +43 -0
- package/lib/util/events.js +142 -0
- package/lib/util/eventtarget.js +64 -0
- package/lib/util/int.js +22 -0
- package/lib/util/logging.js +79 -0
- package/lib/util/polyfill.js +72 -0
- package/lib/util/strings.js +38 -0
- package/lib/vendor/pako/lib/utils/common.js +67 -0
- package/lib/vendor/pako/lib/zlib/adler32.js +33 -0
- package/lib/vendor/pako/lib/zlib/constants.js +51 -0
- package/lib/vendor/pako/lib/zlib/crc32.js +42 -0
- package/lib/vendor/pako/lib/zlib/deflate.js +2159 -0
- package/lib/vendor/pako/lib/zlib/gzheader.js +53 -0
- package/lib/vendor/pako/lib/zlib/inffast.js +445 -0
- package/lib/vendor/pako/lib/zlib/inflate.js +2114 -0
- package/lib/vendor/pako/lib/zlib/inftrees.js +418 -0
- package/lib/vendor/pako/lib/zlib/messages.js +36 -0
- package/lib/vendor/pako/lib/zlib/trees.js +1499 -0
- package/lib/vendor/pako/lib/zlib/zstream.js +46 -0
- package/lib/vendor/promise.js +255 -0
- package/lib/websock.js +374 -0
- package/package.json +48 -28
- package/vendor/pako/lib/zlib/deflate.js +30 -30
- package/vendor/pako/lib/zlib/inflate.js +17 -17
- package/core/input/mouse.js +0 -280
- package/docs/API-internal.md +0 -125
- package/docs/EMBEDDING.md +0 -83
- package/docs/VERSION +0 -1
package/core/util/browser.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* noVNC: HTML5 VNC client
|
|
3
|
-
* Copyright (C)
|
|
3
|
+
* Copyright (C) 2019 The noVNC Authors
|
|
4
4
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
5
5
|
*
|
|
6
6
|
* See README.md for usage and integration instructions.
|
|
7
|
+
*
|
|
8
|
+
* Browser feature support detection
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
11
|
import * as Log from './logging.js';
|
|
10
12
|
|
|
11
13
|
// Touch detection
|
|
12
|
-
export
|
|
14
|
+
export let isTouchDevice = ('ontouchstart' in document.documentElement) ||
|
|
13
15
|
// requried for Chrome debugger
|
|
14
16
|
(document.ontouchstart !== undefined) ||
|
|
15
17
|
// required for MS Surface
|
|
@@ -20,40 +22,72 @@ window.addEventListener('touchstart', function onFirstTouch() {
|
|
|
20
22
|
window.removeEventListener('touchstart', onFirstTouch, false);
|
|
21
23
|
}, false);
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Log.Error("Data URI scheme cursor test exception: " + exc);
|
|
40
|
-
_cursor_uris_supported = false;
|
|
41
|
-
}
|
|
25
|
+
|
|
26
|
+
// The goal is to find a certain physical width, the devicePixelRatio
|
|
27
|
+
// brings us a bit closer but is not optimal.
|
|
28
|
+
export let dragThreshold = 10 * (window.devicePixelRatio || 1);
|
|
29
|
+
|
|
30
|
+
let _supportsCursorURIs = false;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const target = document.createElement('canvas');
|
|
34
|
+
target.style.cursor = 'url("data:image/x-icon;base64,AAACAAEACAgAAAIAAgA4AQAAFgAAACgAAAAIAAAAEAAAAAEAIAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAD/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AAAAAAAAAAAAAAAAAAAAAA==") 2 2, default';
|
|
35
|
+
|
|
36
|
+
if (target.style.cursor.indexOf("url") === 0) {
|
|
37
|
+
Log.Info("Data URI scheme cursor supported");
|
|
38
|
+
_supportsCursorURIs = true;
|
|
39
|
+
} else {
|
|
40
|
+
Log.Warn("Data URI scheme cursor not supported");
|
|
42
41
|
}
|
|
42
|
+
} catch (exc) {
|
|
43
|
+
Log.Error("Data URI scheme cursor test exception: " + exc);
|
|
44
|
+
}
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
+
export const supportsCursorURIs = _supportsCursorURIs;
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
let _supportsImageMetadata = false;
|
|
49
|
+
try {
|
|
50
|
+
new ImageData(new Uint8ClampedArray(4), 1, 1);
|
|
51
|
+
_supportsImageMetadata = true;
|
|
52
|
+
} catch (ex) {
|
|
53
|
+
// ignore failure
|
|
49
54
|
}
|
|
55
|
+
export const supportsImageMetadata = _supportsImageMetadata;
|
|
50
56
|
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
let _hasScrollbarGutter = true;
|
|
58
|
+
try {
|
|
59
|
+
// Create invisible container
|
|
60
|
+
const container = document.createElement('div');
|
|
61
|
+
container.style.visibility = 'hidden';
|
|
62
|
+
container.style.overflow = 'scroll'; // forcing scrollbars
|
|
63
|
+
document.body.appendChild(container);
|
|
64
|
+
|
|
65
|
+
// Create a div and place it in the container
|
|
66
|
+
const child = document.createElement('div');
|
|
67
|
+
container.appendChild(child);
|
|
68
|
+
|
|
69
|
+
// Calculate the difference between the container's full width
|
|
70
|
+
// and the child's width - the difference is the scrollbars
|
|
71
|
+
const scrollbarWidth = (container.offsetWidth - child.offsetWidth);
|
|
72
|
+
|
|
73
|
+
// Clean up
|
|
74
|
+
container.parentNode.removeChild(container);
|
|
75
|
+
|
|
76
|
+
_hasScrollbarGutter = scrollbarWidth != 0;
|
|
77
|
+
} catch (exc) {
|
|
78
|
+
Log.Error("Scrollbar test exception: " + exc);
|
|
53
79
|
}
|
|
80
|
+
export const hasScrollbarGutter = _hasScrollbarGutter;
|
|
54
81
|
|
|
55
|
-
|
|
56
|
-
|
|
82
|
+
/*
|
|
83
|
+
* The functions for detection of platforms and browsers below are exported
|
|
84
|
+
* but the use of these should be minimized as much as possible.
|
|
85
|
+
*
|
|
86
|
+
* It's better to use feature detection than platform detection.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
export function isMac() {
|
|
90
|
+
return navigator && !!(/mac/i).exec(navigator.platform);
|
|
57
91
|
}
|
|
58
92
|
|
|
59
93
|
export function isWindows() {
|
|
@@ -67,3 +101,20 @@ export function isIOS() {
|
|
|
67
101
|
!!(/ipod/i).exec(navigator.platform));
|
|
68
102
|
}
|
|
69
103
|
|
|
104
|
+
export function isSafari() {
|
|
105
|
+
return navigator && (navigator.userAgent.indexOf('Safari') !== -1 &&
|
|
106
|
+
navigator.userAgent.indexOf('Chrome') === -1);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function isIE() {
|
|
110
|
+
return navigator && !!(/trident/i).exec(navigator.userAgent);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function isEdge() {
|
|
114
|
+
return navigator && !!(/edge/i).exec(navigator.userAgent);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function isFirefox() {
|
|
118
|
+
return navigator && !!(/firefox/i).exec(navigator.userAgent);
|
|
119
|
+
}
|
|
120
|
+
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* noVNC: HTML5 VNC client
|
|
3
|
+
* Copyright (C) 2019 The noVNC Authors
|
|
4
|
+
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { supportsCursorURIs, isTouchDevice } from './browser.js';
|
|
8
|
+
|
|
9
|
+
const useFallback = !supportsCursorURIs || isTouchDevice;
|
|
10
|
+
|
|
11
|
+
export default class Cursor {
|
|
12
|
+
constructor() {
|
|
13
|
+
this._target = null;
|
|
14
|
+
|
|
15
|
+
this._canvas = document.createElement('canvas');
|
|
16
|
+
|
|
17
|
+
if (useFallback) {
|
|
18
|
+
this._canvas.style.position = 'fixed';
|
|
19
|
+
this._canvas.style.zIndex = '65535';
|
|
20
|
+
this._canvas.style.pointerEvents = 'none';
|
|
21
|
+
// Can't use "display" because of Firefox bug #1445997
|
|
22
|
+
this._canvas.style.visibility = 'hidden';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this._position = { x: 0, y: 0 };
|
|
26
|
+
this._hotSpot = { x: 0, y: 0 };
|
|
27
|
+
|
|
28
|
+
this._eventHandlers = {
|
|
29
|
+
'mouseover': this._handleMouseOver.bind(this),
|
|
30
|
+
'mouseleave': this._handleMouseLeave.bind(this),
|
|
31
|
+
'mousemove': this._handleMouseMove.bind(this),
|
|
32
|
+
'mouseup': this._handleMouseUp.bind(this),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
attach(target) {
|
|
37
|
+
if (this._target) {
|
|
38
|
+
this.detach();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this._target = target;
|
|
42
|
+
|
|
43
|
+
if (useFallback) {
|
|
44
|
+
document.body.appendChild(this._canvas);
|
|
45
|
+
|
|
46
|
+
// FIXME: These don't fire properly except for mouse
|
|
47
|
+
/// movement in IE. We want to also capture element
|
|
48
|
+
// movement, size changes, visibility, etc.
|
|
49
|
+
const options = { capture: true, passive: true };
|
|
50
|
+
this._target.addEventListener('mouseover', this._eventHandlers.mouseover, options);
|
|
51
|
+
this._target.addEventListener('mouseleave', this._eventHandlers.mouseleave, options);
|
|
52
|
+
this._target.addEventListener('mousemove', this._eventHandlers.mousemove, options);
|
|
53
|
+
this._target.addEventListener('mouseup', this._eventHandlers.mouseup, options);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.clear();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
detach() {
|
|
60
|
+
if (!this._target) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (useFallback) {
|
|
65
|
+
const options = { capture: true, passive: true };
|
|
66
|
+
this._target.removeEventListener('mouseover', this._eventHandlers.mouseover, options);
|
|
67
|
+
this._target.removeEventListener('mouseleave', this._eventHandlers.mouseleave, options);
|
|
68
|
+
this._target.removeEventListener('mousemove', this._eventHandlers.mousemove, options);
|
|
69
|
+
this._target.removeEventListener('mouseup', this._eventHandlers.mouseup, options);
|
|
70
|
+
|
|
71
|
+
document.body.removeChild(this._canvas);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this._target = null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
change(rgba, hotx, hoty, w, h) {
|
|
78
|
+
if ((w === 0) || (h === 0)) {
|
|
79
|
+
this.clear();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this._position.x = this._position.x + this._hotSpot.x - hotx;
|
|
84
|
+
this._position.y = this._position.y + this._hotSpot.y - hoty;
|
|
85
|
+
this._hotSpot.x = hotx;
|
|
86
|
+
this._hotSpot.y = hoty;
|
|
87
|
+
|
|
88
|
+
let ctx = this._canvas.getContext('2d');
|
|
89
|
+
|
|
90
|
+
this._canvas.width = w;
|
|
91
|
+
this._canvas.height = h;
|
|
92
|
+
|
|
93
|
+
let img;
|
|
94
|
+
try {
|
|
95
|
+
// IE doesn't support this
|
|
96
|
+
img = new ImageData(new Uint8ClampedArray(rgba), w, h);
|
|
97
|
+
} catch (ex) {
|
|
98
|
+
img = ctx.createImageData(w, h);
|
|
99
|
+
img.data.set(new Uint8ClampedArray(rgba));
|
|
100
|
+
}
|
|
101
|
+
ctx.clearRect(0, 0, w, h);
|
|
102
|
+
ctx.putImageData(img, 0, 0);
|
|
103
|
+
|
|
104
|
+
if (useFallback) {
|
|
105
|
+
this._updatePosition();
|
|
106
|
+
} else {
|
|
107
|
+
let url = this._canvas.toDataURL();
|
|
108
|
+
this._target.style.cursor = 'url(' + url + ')' + hotx + ' ' + hoty + ', default';
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
clear() {
|
|
113
|
+
this._target.style.cursor = 'none';
|
|
114
|
+
this._canvas.width = 0;
|
|
115
|
+
this._canvas.height = 0;
|
|
116
|
+
this._position.x = this._position.x + this._hotSpot.x;
|
|
117
|
+
this._position.y = this._position.y + this._hotSpot.y;
|
|
118
|
+
this._hotSpot.x = 0;
|
|
119
|
+
this._hotSpot.y = 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Mouse events might be emulated, this allows
|
|
123
|
+
// moving the cursor in such cases
|
|
124
|
+
move(clientX, clientY) {
|
|
125
|
+
if (!useFallback) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
// clientX/clientY are relative the _visual viewport_,
|
|
129
|
+
// but our position is relative the _layout viewport_,
|
|
130
|
+
// so try to compensate when we can
|
|
131
|
+
if (window.visualViewport) {
|
|
132
|
+
this._position.x = clientX + window.visualViewport.offsetLeft;
|
|
133
|
+
this._position.y = clientY + window.visualViewport.offsetTop;
|
|
134
|
+
} else {
|
|
135
|
+
this._position.x = clientX;
|
|
136
|
+
this._position.y = clientY;
|
|
137
|
+
}
|
|
138
|
+
this._updatePosition();
|
|
139
|
+
let target = document.elementFromPoint(clientX, clientY);
|
|
140
|
+
this._updateVisibility(target);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_handleMouseOver(event) {
|
|
144
|
+
// This event could be because we're entering the target, or
|
|
145
|
+
// moving around amongst its sub elements. Let the move handler
|
|
146
|
+
// sort things out.
|
|
147
|
+
this._handleMouseMove(event);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
_handleMouseLeave(event) {
|
|
151
|
+
// Check if we should show the cursor on the element we are leaving to
|
|
152
|
+
this._updateVisibility(event.relatedTarget);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_handleMouseMove(event) {
|
|
156
|
+
this._updateVisibility(event.target);
|
|
157
|
+
|
|
158
|
+
this._position.x = event.clientX - this._hotSpot.x;
|
|
159
|
+
this._position.y = event.clientY - this._hotSpot.y;
|
|
160
|
+
|
|
161
|
+
this._updatePosition();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
_handleMouseUp(event) {
|
|
165
|
+
// We might get this event because of a drag operation that
|
|
166
|
+
// moved outside of the target. Check what's under the cursor
|
|
167
|
+
// now and adjust visibility based on that.
|
|
168
|
+
let target = document.elementFromPoint(event.clientX, event.clientY);
|
|
169
|
+
this._updateVisibility(target);
|
|
170
|
+
|
|
171
|
+
// Captures end with a mouseup but we can't know the event order of
|
|
172
|
+
// mouseup vs releaseCapture.
|
|
173
|
+
//
|
|
174
|
+
// In the cases when releaseCapture comes first, the code above is
|
|
175
|
+
// enough.
|
|
176
|
+
//
|
|
177
|
+
// In the cases when the mouseup comes first, we need wait for the
|
|
178
|
+
// browser to flush all events and then check again if the cursor
|
|
179
|
+
// should be visible.
|
|
180
|
+
if (this._captureIsActive()) {
|
|
181
|
+
window.setTimeout(() => {
|
|
182
|
+
// We might have detached at this point
|
|
183
|
+
if (!this._target) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
// Refresh the target from elementFromPoint since queued events
|
|
187
|
+
// might have altered the DOM
|
|
188
|
+
target = document.elementFromPoint(event.clientX,
|
|
189
|
+
event.clientY);
|
|
190
|
+
this._updateVisibility(target);
|
|
191
|
+
}, 0);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
_showCursor() {
|
|
196
|
+
if (this._canvas.style.visibility === 'hidden') {
|
|
197
|
+
this._canvas.style.visibility = '';
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
_hideCursor() {
|
|
202
|
+
if (this._canvas.style.visibility !== 'hidden') {
|
|
203
|
+
this._canvas.style.visibility = 'hidden';
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Should we currently display the cursor?
|
|
208
|
+
// (i.e. are we over the target, or a child of the target without a
|
|
209
|
+
// different cursor set)
|
|
210
|
+
_shouldShowCursor(target) {
|
|
211
|
+
if (!target) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
// Easy case
|
|
215
|
+
if (target === this._target) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
// Other part of the DOM?
|
|
219
|
+
if (!this._target.contains(target)) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
// Has the child its own cursor?
|
|
223
|
+
// FIXME: How can we tell that a sub element has an
|
|
224
|
+
// explicit "cursor: none;"?
|
|
225
|
+
if (window.getComputedStyle(target).cursor !== 'none') {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
_updateVisibility(target) {
|
|
232
|
+
// When the cursor target has capture we want to show the cursor.
|
|
233
|
+
// So, if a capture is active - look at the captured element instead.
|
|
234
|
+
if (this._captureIsActive()) {
|
|
235
|
+
target = document.captureElement;
|
|
236
|
+
}
|
|
237
|
+
if (this._shouldShowCursor(target)) {
|
|
238
|
+
this._showCursor();
|
|
239
|
+
} else {
|
|
240
|
+
this._hideCursor();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
_updatePosition() {
|
|
245
|
+
this._canvas.style.left = this._position.x + "px";
|
|
246
|
+
this._canvas.style.top = this._position.y + "px";
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
_captureIsActive() {
|
|
250
|
+
return document.captureElement &&
|
|
251
|
+
document.documentElement.contains(document.captureElement);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* noVNC: HTML5 VNC client
|
|
3
|
+
* Copyright (C) 2020 The noVNC Authors
|
|
4
|
+
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
5
|
+
*
|
|
6
|
+
* See README.md for usage and integration instructions.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* HTML element utility functions
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export function clientToElement(x, y, elem) {
|
|
14
|
+
const bounds = elem.getBoundingClientRect();
|
|
15
|
+
let pos = { x: 0, y: 0 };
|
|
16
|
+
// Clip to target bounds
|
|
17
|
+
if (x < bounds.left) {
|
|
18
|
+
pos.x = 0;
|
|
19
|
+
} else if (x >= bounds.right) {
|
|
20
|
+
pos.x = bounds.width - 1;
|
|
21
|
+
} else {
|
|
22
|
+
pos.x = x - bounds.left;
|
|
23
|
+
}
|
|
24
|
+
if (y < bounds.top) {
|
|
25
|
+
pos.y = 0;
|
|
26
|
+
} else if (y >= bounds.bottom) {
|
|
27
|
+
pos.y = bounds.height - 1;
|
|
28
|
+
} else {
|
|
29
|
+
pos.y = y - bounds.top;
|
|
30
|
+
}
|
|
31
|
+
return pos;
|
|
32
|
+
}
|
package/core/util/events.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* noVNC: HTML5 VNC client
|
|
3
|
-
* Copyright (C)
|
|
3
|
+
* Copyright (C) 2018 The noVNC Authors
|
|
4
4
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
5
5
|
*
|
|
6
6
|
* See README.md for usage and integration instructions.
|
|
@@ -10,27 +10,32 @@
|
|
|
10
10
|
* Cross-browser event and position routines
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
export function getPointerEvent
|
|
13
|
+
export function getPointerEvent(e) {
|
|
14
14
|
return e.changedTouches ? e.changedTouches[0] : e.touches ? e.touches[0] : e;
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
export function stopEvent
|
|
17
|
+
export function stopEvent(e) {
|
|
18
18
|
e.stopPropagation();
|
|
19
19
|
e.preventDefault();
|
|
20
|
-
}
|
|
20
|
+
}
|
|
21
21
|
|
|
22
22
|
// Emulate Element.setCapture() when not supported
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
let _captureRecursion = false;
|
|
24
|
+
let _elementForUnflushedEvents = null;
|
|
25
|
+
document.captureElement = null;
|
|
25
26
|
function _captureProxy(e) {
|
|
26
27
|
// Recursion protection as we'll see our own event
|
|
27
28
|
if (_captureRecursion) return;
|
|
28
29
|
|
|
29
30
|
// Clone the event as we cannot dispatch an already dispatched event
|
|
30
|
-
|
|
31
|
+
const newEv = new e.constructor(e.type, e);
|
|
31
32
|
|
|
32
33
|
_captureRecursion = true;
|
|
33
|
-
|
|
34
|
+
if (document.captureElement) {
|
|
35
|
+
document.captureElement.dispatchEvent(newEv);
|
|
36
|
+
} else {
|
|
37
|
+
_elementForUnflushedEvents.dispatchEvent(newEv);
|
|
38
|
+
}
|
|
34
39
|
_captureRecursion = false;
|
|
35
40
|
|
|
36
41
|
// Avoid double events
|
|
@@ -45,94 +50,93 @@ function _captureProxy(e) {
|
|
|
45
50
|
if (e.type === "mouseup") {
|
|
46
51
|
releaseCapture();
|
|
47
52
|
}
|
|
48
|
-
}
|
|
53
|
+
}
|
|
49
54
|
|
|
50
55
|
// Follow cursor style of target element
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
var _captureObserver = new MutationObserver(_captureElemChanged);
|
|
56
|
+
function _capturedElemChanged() {
|
|
57
|
+
const proxyElem = document.getElementById("noVNC_mouse_capture_elem");
|
|
58
|
+
proxyElem.style.cursor = window.getComputedStyle(document.captureElement).cursor;
|
|
59
|
+
}
|
|
56
60
|
|
|
57
|
-
|
|
61
|
+
const _captureObserver = new MutationObserver(_capturedElemChanged);
|
|
58
62
|
|
|
59
|
-
export function setCapture
|
|
60
|
-
if (
|
|
63
|
+
export function setCapture(target) {
|
|
64
|
+
if (target.setCapture) {
|
|
61
65
|
|
|
62
|
-
|
|
66
|
+
target.setCapture();
|
|
67
|
+
document.captureElement = target;
|
|
63
68
|
|
|
64
69
|
// IE releases capture on 'click' events which might not trigger
|
|
65
|
-
|
|
70
|
+
target.addEventListener('mouseup', releaseCapture);
|
|
66
71
|
|
|
67
72
|
} else {
|
|
68
73
|
// Release any existing capture in case this method is
|
|
69
74
|
// called multiple times without coordination
|
|
70
75
|
releaseCapture();
|
|
71
76
|
|
|
72
|
-
|
|
77
|
+
let proxyElem = document.getElementById("noVNC_mouse_capture_elem");
|
|
73
78
|
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
document.body.appendChild(
|
|
79
|
+
if (proxyElem === null) {
|
|
80
|
+
proxyElem = document.createElement("div");
|
|
81
|
+
proxyElem.id = "noVNC_mouse_capture_elem";
|
|
82
|
+
proxyElem.style.position = "fixed";
|
|
83
|
+
proxyElem.style.top = "0px";
|
|
84
|
+
proxyElem.style.left = "0px";
|
|
85
|
+
proxyElem.style.width = "100%";
|
|
86
|
+
proxyElem.style.height = "100%";
|
|
87
|
+
proxyElem.style.zIndex = 10000;
|
|
88
|
+
proxyElem.style.display = "none";
|
|
89
|
+
document.body.appendChild(proxyElem);
|
|
85
90
|
|
|
86
91
|
// This is to make sure callers don't get confused by having
|
|
87
92
|
// our blocking element as the target
|
|
88
|
-
|
|
93
|
+
proxyElem.addEventListener('contextmenu', _captureProxy);
|
|
89
94
|
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
proxyElem.addEventListener('mousemove', _captureProxy);
|
|
96
|
+
proxyElem.addEventListener('mouseup', _captureProxy);
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
|
|
95
|
-
_captureIndex++;
|
|
99
|
+
document.captureElement = target;
|
|
96
100
|
|
|
97
101
|
// Track cursor and get initial cursor
|
|
98
|
-
_captureObserver.observe(
|
|
99
|
-
|
|
102
|
+
_captureObserver.observe(target, {attributes: true});
|
|
103
|
+
_capturedElemChanged();
|
|
100
104
|
|
|
101
|
-
|
|
105
|
+
proxyElem.style.display = "";
|
|
102
106
|
|
|
103
107
|
// We listen to events on window in order to keep tracking if it
|
|
104
108
|
// happens to leave the viewport
|
|
105
109
|
window.addEventListener('mousemove', _captureProxy);
|
|
106
110
|
window.addEventListener('mouseup', _captureProxy);
|
|
107
111
|
}
|
|
108
|
-
}
|
|
112
|
+
}
|
|
109
113
|
|
|
110
|
-
export function releaseCapture
|
|
114
|
+
export function releaseCapture() {
|
|
111
115
|
if (document.releaseCapture) {
|
|
112
116
|
|
|
113
117
|
document.releaseCapture();
|
|
118
|
+
document.captureElement = null;
|
|
114
119
|
|
|
115
120
|
} else {
|
|
116
|
-
if (!
|
|
121
|
+
if (!document.captureElement) {
|
|
117
122
|
return;
|
|
118
123
|
}
|
|
119
124
|
|
|
120
|
-
// There might be events already queued
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}, 0, _captureIndex);
|
|
125
|
+
// There might be events already queued. The event proxy needs
|
|
126
|
+
// access to the captured element for these queued events.
|
|
127
|
+
// E.g. contextmenu (right-click) in Microsoft Edge
|
|
128
|
+
//
|
|
129
|
+
// Before removing the capturedElem pointer we save it to a
|
|
130
|
+
// temporary variable that the unflushed events can use.
|
|
131
|
+
_elementForUnflushedEvents = document.captureElement;
|
|
132
|
+
document.captureElement = null;
|
|
129
133
|
|
|
130
134
|
_captureObserver.disconnect();
|
|
131
135
|
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
const proxyElem = document.getElementById("noVNC_mouse_capture_elem");
|
|
137
|
+
proxyElem.style.display = "none";
|
|
134
138
|
|
|
135
139
|
window.removeEventListener('mousemove', _captureProxy);
|
|
136
140
|
window.removeEventListener('mouseup', _captureProxy);
|
|
137
141
|
}
|
|
138
|
-
}
|
|
142
|
+
}
|