forked from Lainports/opnsense-ports
208 lines
8.7 KiB
Text
208 lines
8.7 KiB
Text
commit 16b8e12f668d
|
|
Author: Masayuki Nakano <masayuki@d-toybox.com>
|
|
Date: Mon Feb 5 18:01:25 2018 +0900
|
|
|
|
Bug 1435530 - part 1: Add automated tests to check Alt + D works as Ctrl + L when Alt is content access key's modifier r=enndeakin+6102 a=test-only
|
|
|
|
MozReview-Commit-ID: FG5sRJfTvue
|
|
|
|
--HG--
|
|
extra : source : 1f89e76b2f3d31cea096b0c9e52000843b8a13d7
|
|
---
|
|
dom/events/moz.build | 4 ++
|
|
dom/events/test/browser.ini | 4 ++
|
|
...er_conflicts_with_content_accesskey_modifier.js | 77 ++++++++++++++++++++++
|
|
3 files changed, 85 insertions(+)
|
|
|
|
diff --git dom/events/moz.build dom/events/moz.build
|
|
index 16f75923c120..159635d47b89 100644
|
|
--- dom/events/moz.build
|
|
+++ dom/events/moz.build
|
|
@@ -7,6 +7,10 @@
|
|
with Files("**"):
|
|
BUG_COMPONENT = ("Core", "DOM: Events")
|
|
|
|
+BROWSER_CHROME_MANIFESTS += [
|
|
+ 'test/browser.ini',
|
|
+]
|
|
+
|
|
MOCHITEST_MANIFESTS += [
|
|
'test/mochitest.ini',
|
|
'test/pointerevents/mochitest.ini',
|
|
diff --git dom/events/test/browser.ini dom/events/test/browser.ini
|
|
new file mode 100644
|
|
index 000000000000..71a61b5cdddb
|
|
--- /dev/null
|
|
+++ dom/events/test/browser.ini
|
|
@@ -0,0 +1,4 @@
|
|
+[DEFAULT]
|
|
+
|
|
+[browser_shortcutkey_modifier_conflicts_with_content_accesskey_modifier.js]
|
|
+skip-if = os != 'linux' && os != 'win' // Alt + D is defined only on Linux and Windows
|
|
diff --git dom/events/test/browser_shortcutkey_modifier_conflicts_with_content_accesskey_modifier.js dom/events/test/browser_shortcutkey_modifier_conflicts_with_content_accesskey_modifier.js
|
|
new file mode 100644
|
|
index 000000000000..d458740dad3e
|
|
--- /dev/null
|
|
+++ dom/events/test/browser_shortcutkey_modifier_conflicts_with_content_accesskey_modifier.js
|
|
@@ -0,0 +1,77 @@
|
|
+add_task(async function() {
|
|
+ // Even if modifier of a shortcut key same as modifier of content access key,
|
|
+ // the shortcut key should be executed if (remote) content doesn't handle it.
|
|
+ // This test uses existing shortcut key declaration on Linux and Windows.
|
|
+ // If you remove or change Alt + D, you need to keep check this with changing
|
|
+ // the pref or result check.
|
|
+
|
|
+ await new Promise(resolve => {
|
|
+ SpecialPowers.pushPrefEnv({"set": [["ui.key.generalAccessKey", -1],
|
|
+ ["ui.key.chromeAccess", 0 /* disabled */],
|
|
+ ["ui.key.contentAccess", 4 /* Alt */],
|
|
+ ["browser.search.widget.inNavBar", true]]},
|
|
+ resolve);
|
|
+ });
|
|
+
|
|
+ const kTestPage = "data:text/html,<body>simple web page</body>";
|
|
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, kTestPage);
|
|
+
|
|
+ let searchBar = BrowserSearch.searchBar;
|
|
+ searchBar.focus();
|
|
+
|
|
+ function promiseURLBarHasFocus() {
|
|
+ return new Promise(resolve => {
|
|
+ if (gURLBar.focused) {
|
|
+ ok(true, "The URL bar already has focus");
|
|
+ resolve();
|
|
+ return;
|
|
+ }
|
|
+ info("Waiting focus event...");
|
|
+ gURLBar.addEventListener("focus", () => {
|
|
+ ok(true, "The URL bar gets focus");
|
|
+ resolve();
|
|
+ }, {once: true});
|
|
+ });
|
|
+ }
|
|
+
|
|
+ function promiseURLBarSelectsAllText() {
|
|
+ return new Promise(resolve => {
|
|
+ function isAllTextSelected() {
|
|
+ return gURLBar.inputField.selectionStart === 0 &&
|
|
+ gURLBar.inputField.selectionEnd === gURLBar.inputField.value.length;
|
|
+ }
|
|
+ if (isAllTextSelected()) {
|
|
+ ok(true, "All text of the URL bar is already selected");
|
|
+ isnot(gURLBar.inputField.value, "", "The URL bar should have non-empty text");
|
|
+ resolve();
|
|
+ return;
|
|
+ }
|
|
+ info("Waiting selectionchange event...");
|
|
+ gURLBar.addEventListener("selectionchange", () => {
|
|
+ ok(isAllTextSelected(), "All text of the URL bar should be selected");
|
|
+ isnot(gURLBar.inputField.value, "", "The URL bar should have non-empty text");
|
|
+ resolve();
|
|
+ }, {once: true});
|
|
+ });
|
|
+ }
|
|
+
|
|
+ // Alt + D is a shortcut key to move focus to the URL bar and selects its text.
|
|
+ info("Pressing Alt + D in the search bar...");
|
|
+ EventUtils.synthesizeKey("d", {code: "KeyD", altKey: true});
|
|
+
|
|
+ await promiseURLBarHasFocus();
|
|
+ await promiseURLBarSelectsAllText();
|
|
+
|
|
+ // Alt + D in the URL bar should select all text in it.
|
|
+ await gURLBar.focus();
|
|
+ await promiseURLBarHasFocus();
|
|
+ gURLBar.inputField.selectionStart = gURLBar.inputField.selectionEnd =
|
|
+ gURLBar.inputField.value.length;
|
|
+
|
|
+ info("Pressing Alt + D in the URL bar...");
|
|
+ EventUtils.synthesizeKey("d", {code: "KeyD", altKey: true});
|
|
+ await promiseURLBarHasFocus();
|
|
+ await promiseURLBarSelectsAllText();
|
|
+
|
|
+ gBrowser.removeCurrentTab();
|
|
+});
|
|
|
|
commit d48b9f93766d
|
|
Author: Masayuki Nakano <masayuki@d-toybox.com>
|
|
Date: Mon Feb 5 18:27:30 2018 +0900
|
|
|
|
Bug 1435530 - part 2: Make nsXBLWindowKeyHandler treat eAccessKeyNotFound as eKeyPress event r=enndeakin+6102 a=lizzard
|
|
|
|
Modifiers of shortcut keys may be same as modifier of content access keys.
|
|
|
|
When focus is in the main process, such eKeyPress event is sent to remote
|
|
content first. Then, and if it's not handled in the remote content,
|
|
eAccessKeyNotFound is dispatched into the DOM tree in the main process.
|
|
However, nsXBLWindowKeyHandler doesn't handle it as eKeyPress event. So,
|
|
it causes that shortcut keys whose modifier conflicts with content access key
|
|
won't be handled.
|
|
|
|
This patch just makes nsXBLWindowKeyHandler treat eAccessKeyNotFound as
|
|
eKeyPress event even though other shortcut keys which are handled by JS
|
|
won't be executed. Perhaps, we should stop using eAccessKeyNotFound but
|
|
it's too risky change for now.
|
|
|
|
MozReview-Commit-ID: IJltg5gwBc5
|
|
|
|
--HG--
|
|
extra : source : 48bca44fe6a6e88f941a1a5ab2a41a041346fa21
|
|
---
|
|
dom/ipc/TabParent.cpp | 1 +
|
|
dom/xbl/nsXBLWindowKeyHandler.cpp | 17 ++++++++++++++++-
|
|
2 files changed, 17 insertions(+), 1 deletion(-)
|
|
|
|
diff --git dom/ipc/TabParent.cpp dom/ipc/TabParent.cpp
|
|
index d63a2ba595cd..ecb359f2a6be 100644
|
|
--- dom/ipc/TabParent.cpp
|
|
+++ dom/ipc/TabParent.cpp
|
|
@@ -2244,6 +2244,7 @@ TabParent::RecvAccessKeyNotHandled(const WidgetKeyboardEvent& aEvent)
|
|
// twice or more for a keyboard event, that must be a bug. But how to
|
|
// detect if received event has already been handled?
|
|
|
|
+ MOZ_ASSERT(aEvent.mMessage == eKeyPress);
|
|
WidgetKeyboardEvent localEvent(aEvent);
|
|
localEvent.MarkAsHandledInRemoteProcess();
|
|
localEvent.mMessage = eAccessKeyNotFound;
|
|
diff --git dom/xbl/nsXBLWindowKeyHandler.cpp dom/xbl/nsXBLWindowKeyHandler.cpp
|
|
index dffb53b9a7e9..1c035d142836 100644
|
|
--- dom/xbl/nsXBLWindowKeyHandler.cpp
|
|
+++ dom/xbl/nsXBLWindowKeyHandler.cpp
|
|
@@ -356,6 +356,12 @@ nsXBLWindowKeyHandler::InstallKeyboardEventListenersTo(
|
|
aEventListenerManager->AddEventListenerByType(
|
|
this, NS_LITERAL_STRING("keypress"),
|
|
TrustedEventsAtSystemGroupBubble());
|
|
+ // mozaccesskeynotfound event is fired when modifiers of keypress event
|
|
+ // matches with modifier of content access key but it's not consumed by
|
|
+ // remote content.
|
|
+ aEventListenerManager->AddEventListenerByType(
|
|
+ this, NS_LITERAL_STRING("mozaccesskeynotfound"),
|
|
+ TrustedEventsAtSystemGroupBubble());
|
|
aEventListenerManager->AddEventListenerByType(
|
|
this, NS_LITERAL_STRING("mozkeydownonplugin"),
|
|
TrustedEventsAtSystemGroupBubble());
|
|
@@ -409,6 +415,9 @@ nsXBLWindowKeyHandler::RemoveKeyboardEventListenersFrom(
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
this, NS_LITERAL_STRING("keypress"),
|
|
TrustedEventsAtSystemGroupBubble());
|
|
+ aEventListenerManager->RemoveEventListenerByType(
|
|
+ this, NS_LITERAL_STRING("mozaccesskeynotfound"),
|
|
+ TrustedEventsAtSystemGroupBubble());
|
|
aEventListenerManager->RemoveEventListenerByType(
|
|
this, NS_LITERAL_STRING("mozkeydownonplugin"),
|
|
TrustedEventsAtSystemGroupBubble());
|
|
@@ -465,7 +474,13 @@ nsXBLWindowKeyHandler::ConvertEventToDOMEventType(
|
|
if (aWidgetKeyboardEvent.IsKeyUpOrKeyUpOnPlugin()) {
|
|
return nsGkAtoms::keyup;
|
|
}
|
|
- if (aWidgetKeyboardEvent.mMessage == eKeyPress) {
|
|
+ // eAccessKeyNotFound event is always created from eKeyPress event and
|
|
+ // the original eKeyPress event has stopped its propagation before dispatched
|
|
+ // into the DOM tree in this process and not matched with remote content's
|
|
+ // access keys. So, we should treat it as an eKeyPress event and execute
|
|
+ // a command if it's registered as a shortcut key.
|
|
+ if (aWidgetKeyboardEvent.mMessage == eKeyPress ||
|
|
+ aWidgetKeyboardEvent.mMessage == eAccessKeyNotFound) {
|
|
return nsGkAtoms::keypress;
|
|
}
|
|
MOZ_ASSERT_UNREACHABLE(
|