From ece69eea9a76b80c2e3631890b8e55b0c8a332f8 Mon Sep 17 00:00:00 2001 From: Christopher Speck Date: Thu, 11 Jul 2024 13:16:56 -0400 Subject: [PATCH] GUAC-1967: Remove duplicate wheel handler registrations. Modern-day browsers abide the standardized wheel event (typed WheelEvent), however to support older browsers the legacy DOMMouseScroll (FireFox) and mousewheel (all others) events are also being registered. However modern browsers support both the wheel event as well as the legacy, which results in the wheel handler being registered multiple times. This results in the wheel handler firing twice instead of once, causing excessive scrolling. This change separates the event registration such that either the modern or the legacy events are registered, and not both. --- .../src/main/webapp/modules/Mouse.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/webapp/modules/Mouse.js b/guacamole-common-js/src/main/webapp/modules/Mouse.js index 2f8bc28b50..083616e3c6 100644 --- a/guacamole-common-js/src/main/webapp/modules/Mouse.js +++ b/guacamole-common-js/src/main/webapp/modules/Mouse.js @@ -258,9 +258,16 @@ Guacamole.Mouse = function Mouse(element) { } - element.addEventListener('DOMMouseScroll', mousewheel_handler, false); - element.addEventListener('mousewheel', mousewheel_handler, false); - element.addEventListener('wheel', mousewheel_handler, false); + if (window.WheelEvent) { + // All modern browsers support wheel events. + element.addEventListener('wheel', mousewheel_handler, false); + } + else { + // Legacy FireFox wheel events. + element.addEventListener('DOMMouseScroll', mousewheel_handler, false); + // Legacy Chrome/IE/other wheel events. + element.addEventListener('mousewheel', mousewheel_handler, false); + } /** * Whether the browser supports CSS3 cursor styling, including hotspot