Bug 1682621, set input source to MOZ_SOURCE_KEYBOARD for command events on buttons, r=tnikkel

Differential Revision: https://phabricator.services.mozilla.com/D149284
This commit is contained in:
Neil Deakin 2022-06-28 16:02:37 +00:00
Родитель 1eaa8eb15b
Коммит 7aa51b41ff
2 изменённых файлов: 27 добавлений и 9 удалений

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

@ -197,10 +197,12 @@ void nsButtonBoxFrame::MouseClicked(WidgetGUIEvent* aEvent) {
nsCOMPtr<nsIContent> 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);
}

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

@ -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);
});
]]>
</script>