Commit 2abf93a3 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Allow unmodified function keys to be rewritten for ChromeVox

R=akihiroota@chromium.org, oshima@chromium.org

Fixed: 1042907
AX-Relnotes: ChromeVox detects slight differences in Chromebook keyboard (some of which have shifted brightness up keys).
Change-Id: If12a9fe12c1e12e40a32a460378057fec17b2260
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2311029Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Commit-Queue: David Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792569}
parent d89f7ba3
...@@ -62,6 +62,16 @@ ui::EventDispatchDetails SpokenFeedbackEventRewriter::RewriteEvent( ...@@ -62,6 +62,16 @@ ui::EventDispatchDetails SpokenFeedbackEventRewriter::RewriteEvent(
const ui::KeyEvent* key_event = event.AsKeyEvent(); const ui::KeyEvent* key_event = event.AsKeyEvent();
ui::EventRewriterChromeOS::MutableKeyState state(key_event); ui::EventRewriterChromeOS::MutableKeyState state(key_event);
event_rewriter_chromeos_->RewriteModifierKeys(*key_event, &state); event_rewriter_chromeos_->RewriteModifierKeys(*key_event, &state);
// Remove the Search modifier before asking for function keys to be
// rewritten, then restore the flags. This allows ChromeVox to receive keys
// mappings for raw f1-f12 as e.g. back, but also Search+f1-f12 as
// Search+back (rather than just f1-f12).
int original_flags = state.flags;
state.flags = original_flags & ~ui::EF_COMMAND_DOWN;
event_rewriter_chromeos_->RewriteFunctionKeys(*key_event, &state);
state.flags = original_flags;
std::unique_ptr<ui::Event> rewritten_event; std::unique_ptr<ui::Event> rewritten_event;
ui::EventRewriterChromeOS::BuildRewrittenKeyEvent(*key_event, state, ui::EventRewriterChromeOS::BuildRewrittenKeyEvent(*key_event, state,
&rewritten_event); &rewritten_event);
......
...@@ -228,6 +228,43 @@ IN_PROC_BROWSER_TEST_F(LoggedInSpokenFeedbackTest, NavigateNotificationCenter) { ...@@ -228,6 +228,43 @@ IN_PROC_BROWSER_TEST_F(LoggedInSpokenFeedbackTest, NavigateNotificationCenter) {
sm_.Replay(); sm_.Replay();
} }
// Test Learn Mode by pressing a few keys in Learn Mode. Only available while
// logged in.
IN_PROC_BROWSER_TEST_F(LoggedInSpokenFeedbackTest, LearnModeHardwareKeys) {
EnableChromeVox();
sm_.Call([this]() {
extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait(
browser()->profile(), extension_misc::kChromeVoxExtensionId,
"CommandHandler.onCommand('showKbExplorerPage');");
});
sm_.ExpectSpeech("ChromeVox Learn Mode");
// These are the default top row keys and their descriptions which live in
// ChromeVox.
sm_.Call([this]() { SendKeyPress(ui::VKEY_F1); });
sm_.ExpectSpeech("back");
sm_.Call([this]() { SendKeyPress(ui::VKEY_F2); });
sm_.ExpectSpeech("forward");
sm_.Call([this]() { SendKeyPress(ui::VKEY_F3); });
sm_.ExpectSpeech("refresh");
sm_.Call([this]() { SendKeyPress(ui::VKEY_F4); });
sm_.ExpectSpeech("toggle full screen");
sm_.Call([this]() { SendKeyPress(ui::VKEY_F5); });
sm_.ExpectSpeech("window overview");
sm_.Call([this]() { SendKeyPress(ui::VKEY_F6); });
sm_.ExpectSpeech("Brightness down");
sm_.Call([this]() { SendKeyPress(ui::VKEY_F7); });
sm_.ExpectSpeech("Brightness up");
sm_.Call([this]() { SendKeyPress(ui::VKEY_F8); });
sm_.ExpectSpeech("volume mute");
sm_.Call([this]() { SendKeyPress(ui::VKEY_F9); });
sm_.ExpectSpeech("volume down");
sm_.Call([this]() { SendKeyPress(ui::VKEY_F10); });
sm_.ExpectSpeech("volume up");
sm_.Replay();
}
// //
// Spoken feedback tests in both a logged in browser window and guest mode. // Spoken feedback tests in both a logged in browser window and guest mode.
// //
...@@ -792,6 +829,13 @@ IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, SmartStickyMode) { ...@@ -792,6 +829,13 @@ IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, SmartStickyMode) {
sm_.Replay(); sm_.Replay();
} }
IN_PROC_BROWSER_TEST_P(SpokenFeedbackTest, HardwareKeysGetRewritten) {
EnableChromeVox();
sm_.Call([this]() { SendKeyPressWithSearch(ui::VKEY_F7); });
sm_.ExpectSpeech("Darken screen");
sm_.Replay();
}
// //
// Spoken feedback tests of the out-of-box experience. // Spoken feedback tests of the out-of-box experience.
// //
......
...@@ -941,7 +941,7 @@ ...@@ -941,7 +941,7 @@
"sequence": { "sequence": {
"cvoxModifier": true, "cvoxModifier": true,
"keys": { "keys": {
"keyCode": [118] "keyCode": [217]
} }
} }
}, },
...@@ -950,7 +950,7 @@ ...@@ -950,7 +950,7 @@
"sequence": { "sequence": {
"cvoxModifier": true, "cvoxModifier": true,
"keys": { "keys": {
"keyCode": [119] "keyCode": [173]
} }
} }
}, },
......
...@@ -236,25 +236,25 @@ KeyUtil = class { ...@@ -236,25 +236,25 @@ KeyUtil = class {
return 'Enter'; return 'Enter';
} else if (keyCode == 27) { } else if (keyCode == 27) {
return 'Escape'; return 'Escape';
} else if (keyCode == 112) { } else if (keyCode == 166) {
return msg('back_key'); return msg('back_key');
} else if (keyCode == 113) { } else if (keyCode == 167) {
return msg('forward_key'); return msg('forward_key');
} else if (keyCode == 114) { } else if (keyCode == 168) {
return msg('refresh_key'); return msg('refresh_key');
} else if (keyCode == 115) { } else if (keyCode == 183) {
return msg('toggle_full_screen_key'); return msg('toggle_full_screen_key');
} else if (keyCode == 116) { } else if (keyCode == 182) {
return msg('window_overview_key'); return msg('window_overview_key');
} else if (keyCode == 117) { } else if (keyCode == 216) {
return msg('brightness_down_key'); return msg('brightness_down_key');
} else if (keyCode == 118) { } else if (keyCode == 217) {
return msg('brightness_up_key'); return msg('brightness_up_key');
} else if (keyCode == 119) { } else if (keyCode == 173) {
return msg('volume_mute_key'); return msg('volume_mute_key');
} else if (keyCode == 120) { } else if (keyCode == 174) {
return msg('volume_down_key'); return msg('volume_down_key');
} else if (keyCode == 121) { } else if (keyCode == 175) {
return msg('volume_up_key'); return msg('volume_up_key');
} else if (keyCode == 122) { } else if (keyCode == 122) {
return 'F11'; return 'F11';
...@@ -262,6 +262,8 @@ KeyUtil = class { ...@@ -262,6 +262,8 @@ KeyUtil = class {
return 'F12'; return 'F12';
} else if (keyCode == 153) { } else if (keyCode == 153) {
return msg('assistant_key'); return msg('assistant_key');
} else if (keyCode == 179) {
return msg('media_play_pause');
} else if (keyCode == 186) { } else if (keyCode == 186) {
return 'Semicolon'; return 'Semicolon';
} else if (keyCode == 187) { } else if (keyCode == 187) {
......
...@@ -174,3 +174,30 @@ TEST_F('ChromeVoxLearnModeTest', 'Braille', function() { ...@@ -174,3 +174,30 @@ TEST_F('ChromeVoxLearnModeTest', 'Braille', function() {
.replay(); .replay();
}); });
}); });
TEST_F('ChromeVoxLearnModeTest', 'HardwareFunctionKeys', function() {
this.runOnLearnModePage((mockFeedback, evt) => {
mockFeedback.call(doKeyDown({keyCode: 217}))
.expectSpeechWithQueueMode('Brightness up', QueueMode.FLUSH)
.call(doKeyUp({keyCode: 217}))
.call(doKeyDown({keyCode: 91, metaKey: true}))
.expectSpeechWithQueueMode('Search', QueueMode.FLUSH)
.call(doKeyDown({keyCode: 217, metaKey: true}))
.expectSpeechWithQueueMode('Brightness up', QueueMode.QUEUE)
.expectSpeechWithQueueMode('Toggle dark screen', QueueMode.QUEUE)
.call(doKeyUp({keyCode: 217, metaKey: true}))
// Search+Volume Down has no associated command.
.call(doKeyDown({keyCode: 174, metaKey: true}))
.expectSpeechWithQueueMode('volume down', QueueMode.FLUSH)
.call(doKeyUp({keyCode: 174, metaKey: true}))
// Search+Volume Mute does though.
.call(doKeyDown({keyCode: 173, metaKey: true}))
.expectSpeechWithQueueMode('volume mute', QueueMode.FLUSH)
.expectSpeechWithQueueMode('Toggle speech on or off', QueueMode.QUEUE)
.replay();
});
});
...@@ -2987,5 +2987,8 @@ ...@@ -2987,5 +2987,8 @@
<message desc="Describes a gesture to be performed on a touch screen. The gesture is to touch and drag with one finger and have items under the finger read using text-to-speech. No associated UI with this string which is spoken using text-to-speech." name="IDS_CHROMEVOX_TOUCH_EXPLORE_GESTURE" is_accessibility_with_no_ui="true"> <message desc="Describes a gesture to be performed on a touch screen. The gesture is to touch and drag with one finger and have items under the finger read using text-to-speech. No associated UI with this string which is spoken using text-to-speech." name="IDS_CHROMEVOX_TOUCH_EXPLORE_GESTURE" is_accessibility_with_no_ui="true">
Touch explore Touch explore
</message> </message>
<message desc="Describes the media play/pause key on a Chromebook. No associated UI with this string which is spoken using text-to-speech." name="IDS_CHROMEVOX_MEDIA_PLAY_PAUSE" is_accessibility_with_no_ui="true">
Media Play/Pause
</message>
</grit-part> </grit-part>
...@@ -175,10 +175,13 @@ class EventRewriterChromeOS : public EventRewriter { ...@@ -175,10 +175,13 @@ class EventRewriterChromeOS : public EventRewriter {
static bool HasAssistantKeyOnKeyboard(const InputDevice& keyboard_device, static bool HasAssistantKeyOnKeyboard(const InputDevice& keyboard_device,
bool* has_assistant_key); bool* has_assistant_key);
// Part of rewrite phases below. This method is public only so that // Part of rewrite phases below. These methods are public only so that
// SpokenFeedbackRewriter can ask for rewritten modifiers. Returns true when // SpokenFeedbackRewriter can ask for rewritten modifier and function keys.
// the input |state| has key |DomKey::ALT_GRAPH_LATCH| and is remapped.
// Returns true when the input |state| has key |DomKey::ALT_GRAPH_LATCH| and
// is remapped.
bool RewriteModifierKeys(const KeyEvent& event, MutableKeyState* state); bool RewriteModifierKeys(const KeyEvent& event, MutableKeyState* state);
void RewriteFunctionKeys(const KeyEvent& event, MutableKeyState* state);
private: private:
struct DeviceInfo { struct DeviceInfo {
...@@ -234,7 +237,6 @@ class EventRewriterChromeOS : public EventRewriter { ...@@ -234,7 +237,6 @@ class EventRewriterChromeOS : public EventRewriter {
// the current |state|, which may have been modified by previous phases. // the current |state|, which may have been modified by previous phases.
void RewriteNumPadKeys(const KeyEvent& event, MutableKeyState* state); void RewriteNumPadKeys(const KeyEvent& event, MutableKeyState* state);
void RewriteExtendedKeys(const KeyEvent& event, MutableKeyState* state); void RewriteExtendedKeys(const KeyEvent& event, MutableKeyState* state);
void RewriteFunctionKeys(const KeyEvent& event, MutableKeyState* state);
int RewriteLocatedEvent(const Event& event); int RewriteLocatedEvent(const Event& event);
int RewriteModifierClick(const MouseEvent& event, int* flags); int RewriteModifierClick(const MouseEvent& event, int* flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment