Skip to content

Commit fbb8c9a

Browse files
committed
Bug 1942176 - Handle context menu key for tab group labels, r=tabbrowser-reviewers,jswinarton
Differential Revision: https://phabricator.services.mozilla.com/D234668
1 parent 8372975 commit fbb8c9a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

browser/components/tabbrowser/content/tabs.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
this.addEventListener("mouseleave", this);
7373
this.addEventListener("focusin", this);
7474
this.addEventListener("focusout", this);
75+
this.addEventListener("contextmenu", this);
7576
}
7677

7778
init() {
@@ -1486,6 +1487,23 @@
14861487
?.removeAttribute("rolluponmousewheel");
14871488
}
14881489

1490+
on_contextmenu(event) {
1491+
// When pressing the context menu key (as opposed to right-clicking)
1492+
// while a tab group label has aria focus (as opposed to DOM focus),
1493+
// open the tab group context menu as if the label had DOM focus.
1494+
// The button property is used to differentiate between key and mouse.
1495+
if (
1496+
event.button == 0 &&
1497+
this.ariaFocusedItem &&
1498+
isTabGroupLabel(this.ariaFocusedItem)
1499+
) {
1500+
gBrowser.tabGroupMenu.openEditModal(
1501+
this.ariaFocusedItem.closest("tab-group")
1502+
);
1503+
event.preventDefault();
1504+
}
1505+
}
1506+
14891507
get emptyTabTitle() {
14901508
// Normal tab title is used also in the permanent private browsing mode.
14911509
const l10nId =

browser/components/tabbrowser/test/browser/tabs/browser_tab_groups_keyboard_focus.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,32 @@ add_task(async function test_TabGroupKeyboardFocus() {
133133
await EventUtils.synthesizeKey("KEY_Enter");
134134
Assert.ok(tabGroup.collapsed, "Tab group should be collapsed once again");
135135

136+
let editor = document.getElementById("tab-group-editor");
137+
let panelShown = BrowserTestUtils.waitForPopupEvent(editor.panel, "shown");
138+
//XXX Should simulate a context menu event, but this doesn't seem to work:
139+
//await EventUtils.synthesizeKey("VK_CONTEXT_MENU");
140+
gBrowser.tabContainer.on_contextmenu({ button: 0, preventDefault: () => {} });
141+
info("Waiting for the context menu key to open the group context menu");
142+
await panelShown;
143+
is(
144+
editor.panel.state,
145+
"open",
146+
"Tab group context menu should be open after hitting context menu key"
147+
);
148+
is(
149+
gBrowser.tabContainer.ariaFocusedItem,
150+
tabGroup.labelElement,
151+
"Keyboard focus should remain on tab group label while group context menu is open"
152+
);
153+
let panelHidden = BrowserTestUtils.waitForPopupEvent(editor.panel, "hidden");
154+
EventUtils.synthesizeKey("VK_ESCAPE");
155+
await panelHidden;
156+
is(
157+
gBrowser.tabContainer.ariaFocusedItem,
158+
tabGroup.labelElement,
159+
"Keyboard focus should remain on tab group label after closing the group menu context menu"
160+
);
161+
136162
info("Validate that keyboard focus skips over tabs in collapsed tab groups");
137163
await synthesizeKeyToChangeKeyboardFocus(tab4, "KEY_ArrowRight");
138164
is(

0 commit comments

Comments
 (0)