From 7aa51b41ff7fedb1d303d006c8289f0f2bdf19dd Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Tue, 28 Jun 2022 16:02:37 +0000 Subject: [PATCH] Bug 1682621, set input source to MOZ_SOURCE_KEYBOARD for command events on buttons, r=tnikkel Differential Revision: https://phabricator.services.mozilla.com/D149284 --- layout/xul/nsButtonBoxFrame.cpp | 4 ++- .../content/tests/chrome/test_button.xhtml | 32 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/layout/xul/nsButtonBoxFrame.cpp b/layout/xul/nsButtonBoxFrame.cpp index 966b6f10d4b8..ef88d1653378 100644 --- a/layout/xul/nsButtonBoxFrame.cpp +++ b/layout/xul/nsButtonBoxFrame.cpp @@ -197,10 +197,12 @@ void nsButtonBoxFrame::MouseClicked(WidgetGUIEvent* aEvent) { nsCOMPtr content = mContent; WidgetInputEvent* inputEvent = aEvent->AsInputEvent(); WidgetMouseEventBase* mouseEvent = aEvent->AsMouseEventBase(); + WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent(); nsContentUtils::DispatchXULCommand( content, aEvent->IsTrusted(), nullptr, presShell, inputEvent->IsControl(), inputEvent->IsAlt(), inputEvent->IsShift(), inputEvent->IsMeta(), mouseEvent ? mouseEvent->mInputSource - : MouseEvent_Binding::MOZ_SOURCE_UNKNOWN, + : (keyEvent ? MouseEvent_Binding::MOZ_SOURCE_KEYBOARD + : MouseEvent_Binding::MOZ_SOURCE_UNKNOWN), mouseEvent ? mouseEvent->mButton : 0); } diff --git a/toolkit/content/tests/chrome/test_button.xhtml b/toolkit/content/tests/chrome/test_button.xhtml index 58a0a503250b..3b6654b74993 100644 --- a/toolkit/content/tests/chrome/test_button.xhtml +++ b/toolkit/content/tests/chrome/test_button.xhtml @@ -27,11 +27,31 @@ SimpleTest.waitForExplicitFinish(); -function test_button() +add_task(async function test_button() { - synthesizeMouseExpectEvent($("one"), 2, 2, {}, $("one"), "command", "button press"); + await SimpleTest.promiseFocus(); + + // Click on the button. + let commandPromise = new Promise(resolve => { + addEventListener("command", event => resolve(event), { once: true }); + }); + + synthesizeMouseAtCenter($("one"), {}); + let event = await commandPromise; + is(event.button, 0, "button for mouse"); + is(event.inputSource, MouseEvent.MOZ_SOURCE_MOUSE, "input source for mouse"); + + // Press space while to button is focused. + commandPromise = new Promise(resolve => { + addEventListener("command", event => resolve(event), { once: true }); + }); + $("one").focus(); - synthesizeKeyExpectEvent("VK_SPACE", { }, $("one"), "command", "key press"); + synthesizeKey("VK_SPACE", { }); + event = await commandPromise; + is(event.button, 0, "button for keyboard"); + is(event.inputSource, MouseEvent.MOZ_SOURCE_KEYBOARD, "input source for keyboard"); + $("two").disabled = true; synthesizeMouseExpectEvent($("two"), 2, 2, {}, $("two"), "!command", "button press command when disabled"); synthesizeMouseExpectEvent($("two"), 2, 2, {}, $("two"), "click", "button press click when disabled"); @@ -53,11 +73,7 @@ function test_button() $("two").focus(); ok(document.activeElement != $("two"), "focus disabled button"); - - SimpleTest.finish(); -} - -SimpleTest.waitForFocus(test_button); +}); ]]>