From 5d04ef1d7ac52aa181760fd5279a89e69f9691c5 Mon Sep 17 00:00:00 2001 From: Ian Bicking Date: Wed, 31 May 2017 17:17:54 -0500 Subject: [PATCH] Fix #2838, unload uicontrol event handlers properly --- addon/webextension/selector/uicontrol.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/addon/webextension/selector/uicontrol.js b/addon/webextension/selector/uicontrol.js index c3cd016296..7b3bb014f6 100644 --- a/addon/webextension/selector/uicontrol.js +++ b/addon/webextension/selector/uicontrol.js @@ -376,7 +376,7 @@ this.uicontrol = (function() { ui.Box.remove(); const handler = watchFunction(assertIsTrusted(keyupHandler)); document.addEventListener("keyup", handler); - registeredDocumentHandlers.push({name: "keyup", doc: document, handler}); + registeredDocumentHandlers.push({name: "keyup", doc: document, handler, useCapture: false}); })); }, @@ -874,15 +874,21 @@ this.uicontrol = (function() { window.addEventListener('beforeunload', beforeunloadHandler); } + let mousedownSetOnDocument = false; + function installHandlersOnDocument(docObj) { for (let [eventName, handler] of primedDocumentHandlers) { let watchHandler = watchFunction(handler); - docObj.addEventListener(eventName, watchHandler, eventName !== "keyup"); - registeredDocumentHandlers.push({name: eventName, doc: docObj, watchHandler}); + let useCapture = eventName !== "keyup"; + docObj.addEventListener(eventName, watchHandler, useCapture); + registeredDocumentHandlers.push({name: eventName, doc: docObj, handler: watchHandler, useCapture}); + } + if (!mousedownSetOnDocument) { + let mousedownHandler = primedDocumentHandlers.get("mousedown"); + document.addEventListener("mousedown", mousedownHandler, true); + registeredDocumentHandlers.push({name: "mousedown", doc: document, handler: mousedownHandler, useCapture: true}); + mousedownSetOnDocument = true; } - let mousedownHandler = primedDocumentHandlers.get("mousedown"); - document.addEventListener("mousedown", mousedownHandler, true); - registeredDocumentHandlers.push({name: "mousedown", doc: document, watchHandler: mousedownHandler, useCapture: true}); } function beforeunloadHandler() {