mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1640883 - Treat ctrl-c, ctrl-x and ctrl-v as user activation; r=smaug
ctrl-c and ctrl-x is quite common shortcut for clipboard operation, we should treat it as user activation. Differential Revision: https://phabricator.services.mozilla.com/D77046
This commit is contained in:
parent
dfcea09efd
commit
38dcba8fbb
@ -9,6 +9,7 @@ prefs =
|
||||
apz.zoom-to-focused-input.enabled=false
|
||||
|
||||
[test_useractivation_has_been_activated.html]
|
||||
[test_useractivation_key_events.html]
|
||||
[test_useractivation_transient.html]
|
||||
[test_useractivation_transient_consuming.html]
|
||||
[test_clipboard_editor.html]
|
||||
|
@ -0,0 +1,91 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>User activation test: key events</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
|
||||
function synthesizeKeyAndWait(aKey, aEvent) {
|
||||
let promise = new Promise(aResolve => {
|
||||
document.addEventListener("keydown", function(e) {
|
||||
e.preventDefault();
|
||||
aResolve();
|
||||
}, { once: true });
|
||||
});
|
||||
synthesizeKey(aKey, aEvent, window);
|
||||
return promise;
|
||||
}
|
||||
|
||||
add_task(async function TestPrintableKey() {
|
||||
let tests = [ 'a', 'b', 'c', 'A', 'B', '1', '2', '3' ];
|
||||
|
||||
for (let key of tests) {
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
await synthesizeKeyAndWait(key, {});
|
||||
ok(SpecialPowers.wrap(document).hasBeenUserGestureActivated,
|
||||
`check has-been-user-activated for ${key}`);
|
||||
ok(SpecialPowers.wrap(document).hasValidTransientUserGestureActivation,
|
||||
`check has-valid-transient-user-activation for ${key}`);
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function TestNonPrintableKey() {
|
||||
let tests = [ [ "KEY_Alt", false],
|
||||
[ "KEY_Backspace", false],
|
||||
[ "KEY_Escape" , false ],
|
||||
[ "KEY_Tab" , false ],
|
||||
// Treat as user input
|
||||
[ "KEY_Enter", true],
|
||||
[ " ", true] ];
|
||||
|
||||
for (let [key, expectedResult] of tests) {
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
await synthesizeKeyAndWait(key, {});
|
||||
is(SpecialPowers.wrap(document).hasBeenUserGestureActivated, expectedResult,
|
||||
`check has-been-user-activated for "${key}"`);
|
||||
is(SpecialPowers.wrap(document).hasValidTransientUserGestureActivation, expectedResult,
|
||||
`check has-valid-transient-user-activation for "${key}"`);
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function TestModifier() {
|
||||
let tests = [ [ 'a', { altKey: true }, false],
|
||||
[ 'a', { ctrlKey: true }, false],
|
||||
[ 'a', { metaKey: true }, false],
|
||||
[ 'a', { osKey: true }, false],
|
||||
[ 'c', { altKey: true }, false ],
|
||||
[ 'c', { osKey: true }, false ],
|
||||
[ 'v', { altKey: true }, false ],
|
||||
[ 'v', { osKey: true }, false ],
|
||||
[ 'x', { altKey: true }, false ],
|
||||
[ 'x', { osKey: true }, false ],
|
||||
// Treat as user input
|
||||
[ 'a', { altGraphKey: true }, true ],
|
||||
[ 'a', { fnKey: true }, true ],
|
||||
[ 'a', { shiftKey: true }, true ],
|
||||
[ 'c', { accelKey: true }, true ],
|
||||
[ 'v', { accelKey: true }, true ],
|
||||
[ 'x', { accelKey: true }, true ] ];
|
||||
|
||||
for (let [key, event, expectedResult] of tests) {
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
await synthesizeKeyAndWait(key, event);
|
||||
is(SpecialPowers.wrap(document).hasBeenUserGestureActivated, expectedResult,
|
||||
`check has-been-user-activated for ${key} with ${JSON.stringify(event)}`);
|
||||
is(SpecialPowers.wrap(document).hasValidTransientUserGestureActivation, expectedResult,
|
||||
`check has-valid-transient-user-activation for ${key} with ${JSON.stringify(event)}`);
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function endTests() {
|
||||
// Reset the activation flag in order not to interfere following test in the
|
||||
// verify mode which would run the test using same document couple times.
|
||||
SpecialPowers.wrap(document).clearUserGestureActivation();
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
@ -317,7 +317,16 @@ class WidgetKeyboardEvent : public WidgetInputEvent {
|
||||
const bool isEnterOrSpaceKey =
|
||||
mKeyNameIndex == KEY_NAME_INDEX_Enter || mKeyCode == NS_VK_SPACE;
|
||||
return (PseudoCharCode() || isEnterOrSpaceKey) &&
|
||||
!isCombiningWithOperationKeys;
|
||||
(!isCombiningWithOperationKeys ||
|
||||
// ctrl-c/ctrl-x/ctrl-v is quite common shortcut for clipboard
|
||||
// operation.
|
||||
// XXXedgar, we have to find a better way to handle browser keyboard
|
||||
// shortcut for user activation, instead of just ignoring all
|
||||
// combinations, see bug 1641171.
|
||||
((mKeyCode == dom::KeyboardEvent_Binding::DOM_VK_C ||
|
||||
mKeyCode == dom::KeyboardEvent_Binding::DOM_VK_V ||
|
||||
mKeyCode == dom::KeyboardEvent_Binding::DOM_VK_X) &&
|
||||
IsAccel()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user