Bug 1681217: Avoid sending keyup event to content document during cycling tabs. r=dao

Differential Revision: https://phabricator.services.mozilla.com/D98993
This commit is contained in:
Daisuke Akatsuka 2020-12-11 23:52:20 +00:00
Родитель 5d978443c6
Коммит aa31799d78
2 изменённых файлов: 42 добавлений и 6 удалений

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

@ -383,8 +383,6 @@ var ctrlTab = {
return;
}
document.addEventListener("keyup", this, true);
this.canvasWidth = Math.ceil(
(screen.availWidth * 0.85) / this.maxTabPreviews
);
@ -454,8 +452,6 @@ var ctrlTab = {
},
suspendGUI: function ctrlTab_suspendGUI() {
document.removeEventListener("keyup", this, true);
for (let preview of this.previews) {
this.updatePreview(preview, null);
}
@ -480,6 +476,8 @@ var ctrlTab = {
return;
}
Services.els.addSystemEventListener(document, "keyup", this, false);
let tabs = gBrowser.visibleTabs;
if (tabs.length > 2) {
this.open();
@ -584,8 +582,21 @@ var ctrlTab = {
this.onKeyPress(event);
break;
case "keyup":
if (event.keyCode == event.DOM_VK_CONTROL) {
this.pick();
// During cycling tabs, we avoid sending keyup event to content document.
event.preventDefault();
event.stopPropagation();
if (event.keyCode === event.DOM_VK_CONTROL) {
Services.els.removeSystemEventListener(
document,
"keyup",
this,
false
);
if (this.isOpen) {
this.pick();
}
}
break;
case "popupshowing":

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

@ -211,6 +211,17 @@ add_task(async function() {
? "back to the previously selected tab"
: normalized + " tabs back in most-recently-selected order";
// Add keyup listener to all content documents.
await Promise.all(
gBrowser.tabs.map(tab =>
SpecialPowers.spawn(tab.linkedBrowser, [], () => {
content.window.addEventListener("keyup", () => {
content.window._ctrlTabTestKeyupHappend = true;
});
})
)
);
for (let i = 0; i < tabTimes; i++) {
await pressCtrlTab();
@ -253,5 +264,19 @@ add_task(async function() {
" goes " +
where
);
const keyupEvents = await Promise.all(
gBrowser.tabs.map(tab =>
SpecialPowers.spawn(
tab.linkedBrowser,
[],
() => !!content.window._ctrlTabTestKeyupHappend
)
)
);
ok(
keyupEvents.every(isKeyupHappned => !isKeyupHappned),
"Content document doesn't capture Keyup event during cycling tabs"
);
}
});