Open in new tab with AltGr+Enter (Bug 1389739). r=adw

Before this change, AltGr+Enter wouldn't open url in new tab on non-English layouts on Windows. This happened because non-English layouts generated AltGr event on pressing right Alt key. Checking for this event in _whereToOpen function fixes the issue.

Differential Revision: https://phabricator.services.mozilla.com/D39466

--HG--
extra : moz-landing-system : lando
This commit is contained in:
bbassi 2019-07-31 20:01:15 +00:00
Родитель 6917b697b8
Коммит 1b6c07a4a6
4 изменённых файлов: 61 добавлений и 2 удалений

Просмотреть файл

@ -1317,7 +1317,11 @@ class UrlbarInput {
let isMouseEvent = event instanceof MouseEvent;
let reuseEmpty = !isMouseEvent;
let where = undefined;
if (!isMouseEvent && event && event.altKey) {
if (
!isMouseEvent &&
event &&
(event.altKey || event.getModifierState("AltGraph"))
) {
// We support using 'alt' to open in a tab, because ctrl/shift
// might be used for canonizing URLs:
where = event.shiftKey ? "tabshifted" : "tab";

Просмотреть файл

@ -124,6 +124,11 @@ add_task(async function load_in_current_tab_test() {
type: "keypress",
details: { altKey: true },
},
{
desc: "AltGr+Return keypress in a blank tab",
type: "keypress",
details: { altGraphKey: true },
},
];
for (let { desc, type, details } of tests) {
@ -166,6 +171,12 @@ add_task(async function load_in_new_tab_test() {
details: { altKey: true },
url: START_VALUE,
},
{
desc: "AltGr+Return keypress in a dirty tab",
type: "keypress",
details: { altGraphKey: true },
url: START_VALUE,
},
];
for (let { desc, type, details, url } of tests) {
@ -174,7 +185,7 @@ add_task(async function load_in_new_tab_test() {
// Add a new tab.
let tab = await promiseOpenNewTab(url);
// Trigger a load and check it occurs in the current tab.
// Trigger a load and check it occurs in a new tab.
let tabSwitchedPromise = promiseNewTabSwitched();
await triggerCommand(type, details);
await tabSwitchedPromise;

Просмотреть файл

@ -52,3 +52,30 @@ add_task(async function altReturnKeypress() {
BrowserTestUtils.removeTab(tab);
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
add_task(async function altGrReturnKeypress() {
info("AltGr+Return keypress");
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, START_VALUE);
let tabOpenPromise = BrowserTestUtils.waitForEvent(
gBrowser.tabContainer,
"TabOpen"
);
gURLBar.focus();
EventUtils.synthesizeKey("KEY_Enter", { altGraphKey: true });
// wait for the new tab to appear.
await tabOpenPromise;
// Check url bar and selected tab.
is(
gURLBar.textValue,
TEST_VALUE,
"Urlbar should preserve the value on return keypress"
);
isnot(gBrowser.selectedTab, tab, "New URL was loaded in a new tab");
// Cleanup.
BrowserTestUtils.removeTab(tab);
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});

Просмотреть файл

@ -8,6 +8,7 @@ const EMPTY_TAB = "about:blank";
const META_KEY = AppConstants.platform == "macosx" ? "metaKey" : "ctrlKey";
const ENTER = new KeyboardEvent("keydown", {});
const ALT_ENTER = new KeyboardEvent("keydown", { altKey: true });
const ALTGR_ENTER = new KeyboardEvent("keydown", { modifierAltGraph: true });
const CLICK = new MouseEvent("click", { button: 0 });
const META_CLICK = new MouseEvent("click", { button: 0, [META_KEY]: true });
const MIDDLE_CLICK = new MouseEvent("click", { button: 1 });
@ -30,6 +31,11 @@ add_task(async function openInTab() {
event: ALT_ENTER,
desc: "Alt+Enter, non-empty tab, default prefs",
},
{
pref: false,
event: ALTGR_ENTER,
desc: "AltGr+Enter, non-empty tab, default prefs",
},
{
pref: false,
event: META_CLICK,
@ -101,6 +107,11 @@ add_task(async function reuseEmptyTab() {
event: ALT_ENTER,
desc: "Alt+Enter, empty tab, default prefs",
},
{
pref: false,
event: ALTGR_ENTER,
desc: "AltGr+Enter, empty tab, default prefs",
},
{ pref: true, event: ENTER, desc: "Enter, empty tab, openInTab" },
{ pref: true, event: CLICK, desc: "Normal click, empty tab, openInTab" },
]) {
@ -146,6 +157,12 @@ add_task(async function openInCurrentTab() {
event: ALT_ENTER,
desc: "Alt+Enter, non-empty tab, openInTab",
},
{
pref: true,
url: NON_EMPTY_TAB,
event: ALTGR_ENTER,
desc: "AltGr+Enter, non-empty tab, openInTab",
},
{
pref: true,
url: NON_EMPTY_TAB,