summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2020-01-14 09:45:28 +0100
committerPierre Ossman <ossman@cendio.se>2020-01-14 09:45:28 +0100
commit2d53a785d521b29dbed9fbe0ec686ad2a34516bf (patch)
tree1a9426849d73f92195a9c9643b7de870ea512369
parent64fdd336a03105db8d21c896e83de97e84971a86 (diff)
parent11ae8f0ef4dc1edffb497c0ed56e66054f897b20 (diff)
downloadnovnc-2d53a785d521b29dbed9fbe0ec686ad2a34516bf.tar.gz
Merge branch 'abstraction_for_detection' of https://github.com/samhed/noVNC
-rw-r--r--app/ui.js7
-rw-r--r--core/util/browser.js38
2 files changed, 38 insertions, 7 deletions
diff --git a/app/ui.js b/app/ui.js
index 347a2af..766736a 100644
--- a/app/ui.js
+++ b/app/ui.js
@@ -8,7 +8,7 @@
import * as Log from '../core/util/logging.js';
import _, { l10n } from './localization.js';
-import { isTouchDevice, isSafari, isIOS, isAndroid, dragThreshold }
+import { isTouchDevice, isSafari, hasScrollbarGutter, dragThreshold }
from '../core/util/browser.js';
import { setCapture, getPointerEvent } from '../core/util/events.js';
import KeyTable from "../core/input/keysym.js";
@@ -1269,8 +1269,9 @@ const UI = {
// Can't be clipping if viewport is scaled to fit
UI.forceSetting('view_clip', false);
UI.rfb.clipViewport = false;
- } else if (isIOS() || isAndroid()) {
- // iOS and Android usually have shit scrollbars
+ } else if (!hasScrollbarGutter) {
+ // Some platforms have scrollbars that are difficult
+ // to use in our case, so we always use our own panning
UI.forceSetting('view_clip', true);
UI.rfb.clipViewport = true;
} else {
diff --git a/core/util/browser.js b/core/util/browser.js
index 4b371e3..1554801 100644
--- a/core/util/browser.js
+++ b/core/util/browser.js
@@ -4,6 +4,8 @@
* Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
+ *
+ * Browser feature support detection
*/
import * as Log from './logging.js';
@@ -52,6 +54,38 @@ try {
}
export const supportsImageMetadata = _supportsImageMetadata;
+let _hasScrollbarGutter = true;
+try {
+ // Create invisible container
+ const container = document.createElement('div');
+ container.style.visibility = 'hidden';
+ container.style.overflow = 'scroll'; // forcing scrollbars
+ document.body.appendChild(container);
+
+ // Create a div and place it in the container
+ const child = document.createElement('div');
+ container.appendChild(child);
+
+ // Calculate the difference between the container's full width
+ // and the child's width - the difference is the scrollbars
+ const scrollbarWidth = (container.offsetWidth - child.offsetWidth);
+
+ // Clean up
+ container.parentNode.removeChild(container);
+
+ _hasScrollbarGutter = scrollbarWidth != 0;
+} catch (exc) {
+ Log.Error("Scrollbar test exception: " + exc);
+}
+export const hasScrollbarGutter = _hasScrollbarGutter;
+
+/*
+ * The functions for detection of platforms and browsers below are exported
+ * but the use of these should be minimized as much as possible.
+ *
+ * It's better to use feature detection than platform detection.
+ */
+
export function isMac() {
return navigator && !!(/mac/i).exec(navigator.platform);
}
@@ -67,10 +101,6 @@ export function isIOS() {
!!(/ipod/i).exec(navigator.platform));
}
-export function isAndroid() {
- return navigator && !!(/android/i).exec(navigator.userAgent);
-}
-
export function isSafari() {
return navigator && (navigator.userAgent.indexOf('Safari') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1);