Bug 1677334 - Part 1: Don't generate click event for mouse-left-down with ctrl key is pressed on Mac; r=masayuki

Chrome and Safari doesn't genereate click event when contorl key is pressed, either.

Differential Revision: https://phabricator.services.mozilla.com/D109903
This commit is contained in:
Edgar Chen 2021-04-07 11:23:45 +00:00
parent e073a4ee20
commit 20e4184d91
3 changed files with 19 additions and 3 deletions

View File

@ -142,9 +142,19 @@ APZEventResult APZInputBridge::ReceiveInputEvent(WidgetInputEvent& aEvent) {
mouseEvent.mRefPoint.y = input.mOrigin.y;
mouseEvent.mFlags.mHandledByAPZ = input.mHandledByAPZ;
mouseEvent.mFocusSequenceNumber = input.mFocusSequenceNumber;
#ifdef XP_MACOSX
// It's not assumed that the click event has already been prevented,
// except mousedown event with ctrl key is pressed where we prevent
// click event from widget on Mac platform.
MOZ_ASSERT_IF(!mouseEvent.IsControl() ||
mouseEvent.mMessage != eMouseDown ||
mouseEvent.mButton != MouseButton::ePrimary,
!mouseEvent.mClickEventPrevented);
#else
MOZ_ASSERT(
!mouseEvent.mClickEventPrevented,
"It's not assumed that the click event has already been prevented");
#endif
mouseEvent.mClickEventPrevented |= input.mPreventClickEvent;
MOZ_ASSERT_IF(mouseEvent.mClickEventPrevented,
mouseEvent.mMessage == eMouseDown ||

View File

@ -2970,10 +2970,12 @@ NSEvent* gLastDragMouseDownEvent = nil; // [strong]
geckoEvent.mClickCount = clickCount;
if (!StaticPrefs::dom_event_treat_ctrl_click_as_right_click_disabled() &&
([theEvent modifierFlags] & NSEventModifierFlagControl)) {
geckoEvent.IsControl()) {
geckoEvent.mButton = MouseButton::eSecondary;
} else {
geckoEvent.mButton = MouseButton::ePrimary;
// Don't send a click if ctrl key is pressed.
geckoEvent.mClickEventPrevented = geckoEvent.IsControl();
}
mGeckoChild->DispatchInputEvent(&geckoEvent);

View File

@ -63,6 +63,11 @@ function waitAndCheckMouseEvents(aTarget, aExpectedEvents) {
add_task(async function Init() {
await SimpleTest.promiseFocus();
let target = document.getElementById("target");
target.addEventListener("click", function() {
ok(false, `should not receive click event`);
});
});
add_task(async function TestMouseClickWithControl() {
@ -73,8 +78,7 @@ add_task(async function TestMouseClickWithControl() {
let target = document.getElementById("target");
let promise = waitAndCheckMouseEvents(target, [["mousedown", 0, true],
["contextmenu", 0, true],
["mouseup", 0, true],
["click", 0, true]]);
["mouseup", 0, true]]);
synthesizeNativeMouseEvent({
type: "click",
target,