Bug 1615732 - Don't show menu on Mac when ctrl key is pressed; r=NeilDeakin

On Mac, ctrl-click will send a context menu event from the widget, so we don't
want to bring up the panel when ctrl key is pressed.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edgar Chen 2020-03-30 11:20:45 +00:00
Родитель 7e26f04dd1
Коммит 002ef4c5f0
3 изменённых файлов: 49 добавлений и 0 удалений

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

@ -17,6 +17,7 @@ skip-if = (verify && debug)
[browser_bookmark_backup_export_import.js]
[browser_bookmark_change_location.js]
[browser_bookmark_folder_moveability.js]
[browser_bookmark_menu_ctrl_click.js]
[browser_bookmark_popup.js]
skip-if = (os == "linux" && debug) || (verify && (os == 'win')) # mouseover not reliable on linux debug builds
[browser_bookmark_private_window.js]

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

@ -0,0 +1,43 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
function onPopupEvent(popup, evt) {
let fullEvent = "popup" + evt;
return BrowserTestUtils.waitForEvent(popup, fullEvent, false, e => {
return e.target == popup;
});
}
add_task(async function test_bookmarks_menu() {
// On macOS, ctrl-click shouldn't open the panel because this normally opens
// the context menu. This happens via the `contextmenu` event which is created
// by widget code, so our simulated clicks do not do so, so we can't test
// anything on macOS.
if (AppConstants.platform == "macosx") {
ok(true, "The test is ignored on Mac");
return;
}
CustomizableUI.addWidgetToArea(
"bookmarks-menu-button",
CustomizableUI.AREA_NAVBAR,
4
);
const button = document.getElementById("bookmarks-menu-button");
const popup = document.getElementById("BMB_bookmarksPopup");
let shownPromise = onPopupEvent(popup, "shown");
EventUtils.synthesizeMouseAtCenter(button, { ctrlKey: true });
await shownPromise;
ok(true, "Bookmarks menu shown after button pressed");
// Close bookmarks popup.
let hiddenPromise = onPopupEvent(popup, "hidden");
popup.hidePopup();
await hiddenPromise;
CustomizableUI.reset();
});

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

@ -383,6 +383,11 @@ nsresult nsMenuFrame::HandleEvent(nsPresContext* aPresContext,
#endif
} else if (aEvent->mMessage == eMouseDown &&
aEvent->AsMouseEvent()->mButton == MouseButton::eLeft &&
#ifdef XP_MACOSX
// On mac, ctrl-click will send a context menu event from the
// widget, so we don't want to bring up the menu.
!aEvent->AsMouseEvent()->IsControl() &&
#endif
!IsDisabled() && IsMenu()) {
// The menu item was selected. Bring up the menu.
// We have children.