summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-10-18 12:48:23 +0000
committerMoonchild <moonchild@palemoon.org>2022-10-18 12:48:23 +0000
commit7ac438f6ad7abca71e044582d7fca96cf1f84d20 (patch)
tree621efbc93af60a560b6ae5bd1f3739ba7d025057
parent3142f95469c26169a940297f1db6ed1fad5a25fe (diff)
downloaduxp-7ac438f6ad7abca71e044582d7fca96cf1f84d20.tar.gz
Issue #2019 - Follow-up: Make autocomplete and satchel listen to keypress events in the system event group
The autocomplete module listens to keypress events for both printable keys and non-printable keys a lot. However, we're stopping dispatching keypress events for non-printable keys in the default event group of web content. This means that autocomplete should listen to keypress events in the system event group. Note that it's difficult to globally change keypress event listeners to keydown event listeners because if we stop keypress events at preceding keydown event in autocomplete or satchel modules, some other modules fail to handle keydown or keypress events before autocomplete, and it's not easy to investigate which keypress event listener in which modules should be changed to a keydown event listener. Therefore, this patch doesn't do that, and uses the event group approach.
-rw-r--r--toolkit/components/satchel/nsFormFillController.cpp76
-rw-r--r--toolkit/content/widgets/autocomplete.xml2
2 files changed, 49 insertions, 29 deletions
diff --git a/toolkit/components/satchel/nsFormFillController.cpp b/toolkit/components/satchel/nsFormFillController.cpp
index a89c138fab..aac1870490 100644
--- a/toolkit/components/satchel/nsFormFillController.cpp
+++ b/toolkit/components/satchel/nsFormFillController.cpp
@@ -5,6 +5,7 @@
#include "nsFormFillController.h"
+#include "mozilla/EventListenerManager.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
#include "nsIFormAutoComplete.h"
@@ -40,6 +41,7 @@
#include "nsIScriptSecurityManager.h"
#include "nsFocusManager.h"
+using namespace mozilla;
using namespace mozilla::dom;
NS_IMPL_CYCLE_COLLECTION(nsFormFillController,
@@ -1188,23 +1190,29 @@ nsFormFillController::AddWindowListeners(nsPIDOMWindowOuter* aWindow)
if (!target)
return;
- target->AddEventListener(NS_LITERAL_STRING("focus"), this,
- true, false);
- target->AddEventListener(NS_LITERAL_STRING("blur"), this,
- true, false);
- target->AddEventListener(NS_LITERAL_STRING("pagehide"), this,
- true, false);
- target->AddEventListener(NS_LITERAL_STRING("mousedown"), this,
- true, false);
- target->AddEventListener(NS_LITERAL_STRING("input"), this,
- true, false);
- target->AddEventListener(NS_LITERAL_STRING("keypress"), this, true, false);
- target->AddEventListener(NS_LITERAL_STRING("compositionstart"), this,
- true, false);
- target->AddEventListener(NS_LITERAL_STRING("compositionend"), this,
- true, false);
- target->AddEventListener(NS_LITERAL_STRING("contextmenu"), this,
- true, false);
+ EventListenerManager* elm = target->GetOrCreateListenerManager();
+ if (NS_WARN_IF(!elm)) {
+ return;
+ }
+
+ elm->AddEventListenerByType(this, NS_LITERAL_STRING("focus"),
+ TrustedEventsAtCapture());
+ elm->AddEventListenerByType(this, NS_LITERAL_STRING("blur"),
+ TrustedEventsAtCapture());
+ elm->AddEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
+ TrustedEventsAtCapture());
+ elm->AddEventListenerByType(this, NS_LITERAL_STRING("mousedown"),
+ TrustedEventsAtCapture());
+ elm->AddEventListenerByType(this, NS_LITERAL_STRING("input"),
+ TrustedEventsAtCapture());
+ elm->AddEventListenerByType(this, NS_LITERAL_STRING("keypress"),
+ TrustedEventsAtSystemGroupCapture());
+ elm->AddEventListenerByType(this, NS_LITERAL_STRING("compositionstart"),
+ TrustedEventsAtCapture());
+ elm->AddEventListenerByType(this, NS_LITERAL_STRING("compositionend"),
+ TrustedEventsAtCapture());
+ elm->AddEventListenerByType(this, NS_LITERAL_STRING("contextmenu"),
+ TrustedEventsAtCapture());
// Note that any additional listeners added should ensure that they ignore
// untrusted events, which might be sent by content that's up to no good.
@@ -1226,17 +1234,29 @@ nsFormFillController::RemoveWindowListeners(nsPIDOMWindowOuter* aWindow)
if (!target)
return;
- target->RemoveEventListener(NS_LITERAL_STRING("focus"), this, true);
- target->RemoveEventListener(NS_LITERAL_STRING("blur"), this, true);
- target->RemoveEventListener(NS_LITERAL_STRING("pagehide"), this, true);
- target->RemoveEventListener(NS_LITERAL_STRING("mousedown"), this, true);
- target->RemoveEventListener(NS_LITERAL_STRING("input"), this, true);
- target->RemoveEventListener(NS_LITERAL_STRING("keypress"), this, true);
- target->RemoveEventListener(NS_LITERAL_STRING("compositionstart"), this,
- true);
- target->RemoveEventListener(NS_LITERAL_STRING("compositionend"), this,
- true);
- target->RemoveEventListener(NS_LITERAL_STRING("contextmenu"), this, true);
+ EventListenerManager* elm = target->GetOrCreateListenerManager();
+ if (NS_WARN_IF(!elm)) {
+ return;
+ }
+
+ elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("focus"),
+ TrustedEventsAtCapture());
+ elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("blur"),
+ TrustedEventsAtCapture());
+ elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
+ TrustedEventsAtCapture());
+ elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("mousedown"),
+ TrustedEventsAtCapture());
+ elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("input"),
+ TrustedEventsAtCapture());
+ elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("keypress"),
+ TrustedEventsAtSystemGroupCapture());
+ elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("compositionstart"),
+ TrustedEventsAtCapture());
+ elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("compositionend"),
+ TrustedEventsAtCapture());
+ elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("contextmenu"),
+ TrustedEventsAtCapture());
}
void
diff --git a/toolkit/content/widgets/autocomplete.xml b/toolkit/content/widgets/autocomplete.xml
index 885eb2eab4..d9160956c8 100644
--- a/toolkit/content/widgets/autocomplete.xml
+++ b/toolkit/content/widgets/autocomplete.xml
@@ -648,7 +648,7 @@
this.onInput(event);
]]></handler>
- <handler event="keypress" phase="capturing"
+ <handler event="keypress" phase="capturing" group="system"
action="return this.onKeyPress(event);"/>
<handler event="compositionstart" phase="capturing"