Commit 0213eef9 authored by shuchen@chromium.org's avatar shuchen@chromium.org

Set correct DOM key code string for functional keys.

BUG=402935
TEST=Verified on Pixel.

Review URL: https://codereview.chromium.org/466223004

Cr-Commit-Position: refs/heads/master@{#289565}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289565 0039d316-1c4b-4281-b951-d872f2087c98
parent 56f58af1
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "ui/base/ime/chromeos/ime_keymap.h" #include "ui/base/ime/chromeos/ime_keymap.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/event_processor.h" #include "ui/events/event_processor.h"
#include "ui/events/keycodes/dom4/keycode_converter.h"
#include "ui/keyboard/keyboard_controller.h" #include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_util.h" #include "ui/keyboard/keyboard_util.h"
...@@ -99,7 +100,11 @@ void GetExtensionKeyboardEventFromKeyEvent( ...@@ -99,7 +100,11 @@ void GetExtensionKeyboardEventFromKeyEvent(
DCHECK(ext_event); DCHECK(ext_event);
ext_event->type = (event.type() == ui::ET_KEY_RELEASED) ? "keyup" : "keydown"; ext_event->type = (event.type() == ui::ET_KEY_RELEASED) ? "keyup" : "keydown";
ext_event->code = event.code(); std::string dom_code = event.code();
if (dom_code ==
ui::KeycodeConverter::GetInstance()->InvalidKeyboardEventCode())
dom_code = ui::KeyboardCodeToDomKeycode(event.key_code());
ext_event->code = dom_code;
ext_event->key_code = static_cast<int>(event.key_code()); ext_event->key_code = static_cast<int>(event.key_code());
ext_event->alt_key = event.IsAltDown(); ext_event->alt_key = event.IsAltDown();
ext_event->ctrl_key = event.IsControlDown(); ext_event->ctrl_key = event.IsControlDown();
......
...@@ -134,6 +134,10 @@ const struct KeyCodeTable { ...@@ -134,6 +134,10 @@ const struct KeyCodeTable {
{VKEY_VOLUME_MUTE, "VolumeMute"}, {VKEY_VOLUME_MUTE, "VolumeMute"},
{VKEY_VOLUME_DOWN, "VolumeDown"}, {VKEY_VOLUME_DOWN, "VolumeDown"},
{VKEY_VOLUME_UP, "VolumeUp"}, {VKEY_VOLUME_UP, "VolumeUp"},
{VKEY_BRIGHTNESS_DOWN, "BrightnessDown"},
{VKEY_BRIGHTNESS_UP, "BrightnessUp"},
{VKEY_MEDIA_LAUNCH_APP1, "ChromeOSSwitchWindow"},
{VKEY_MEDIA_LAUNCH_APP2, "ChromeOSFullscreen"},
{VKEY_MEDIA_NEXT_TRACK, "MediaTrackNext"}, {VKEY_MEDIA_NEXT_TRACK, "MediaTrackNext"},
{VKEY_MEDIA_PREV_TRACK, "MediaTrackPrevious"}, {VKEY_MEDIA_PREV_TRACK, "MediaTrackPrevious"},
{VKEY_MEDIA_STOP, "MediaStop"}, {VKEY_MEDIA_STOP, "MediaStop"},
...@@ -154,18 +158,27 @@ const struct KeyCodeTable { ...@@ -154,18 +158,27 @@ const struct KeyCodeTable {
class KeyCodeMap { class KeyCodeMap {
public: public:
KeyCodeMap() { KeyCodeMap() {
for (size_t i = 0; i < arraysize(kKeyCodeTable); ++i) for (size_t i = 0; i < arraysize(kKeyCodeTable); ++i) {
map_[kKeyCodeTable[i].dom_code] = kKeyCodeTable[i].keyboard_code; map_dom_key_[kKeyCodeTable[i].dom_code] = kKeyCodeTable[i].keyboard_code;
map_key_dom_[kKeyCodeTable[i].keyboard_code] = kKeyCodeTable[i].dom_code;
}
} }
KeyboardCode GetKeyboardCode(const std::string& dom_code) const { KeyboardCode GetKeyboardCode(const std::string& dom_code) const {
std::map<std::string, KeyboardCode>::const_iterator it = std::map<std::string, KeyboardCode>::const_iterator it =
map_.find(dom_code); map_dom_key_.find(dom_code);
return (it == map_.end()) ? VKEY_UNKNOWN : it->second; return (it == map_dom_key_.end()) ? VKEY_UNKNOWN : it->second;
}
std::string GetDomKeycode(KeyboardCode key_code) const {
std::map<KeyboardCode, std::string>::const_iterator it =
map_key_dom_.find(key_code);
return (it == map_key_dom_.end()) ? "" : it->second;
} }
private: private:
std::map<std::string, KeyboardCode> map_; std::map<std::string, KeyboardCode> map_dom_key_;
std::map<KeyboardCode, std::string> map_key_dom_;
}; };
base::LazyInstance<KeyCodeMap>::Leaky g_keycode_map = base::LazyInstance<KeyCodeMap>::Leaky g_keycode_map =
...@@ -177,4 +190,8 @@ KeyboardCode DomKeycodeToKeyboardCode(const std::string& code) { ...@@ -177,4 +190,8 @@ KeyboardCode DomKeycodeToKeyboardCode(const std::string& code) {
return g_keycode_map.Get().GetKeyboardCode(code); return g_keycode_map.Get().GetKeyboardCode(code);
} }
std::string KeyboardCodeToDomKeycode(KeyboardCode code) {
return g_keycode_map.Get().GetDomKeycode(code);
}
} // namespace ui } // namespace ui
...@@ -15,6 +15,9 @@ namespace ui { ...@@ -15,6 +15,9 @@ namespace ui {
// Translates the DOM4 key code string to ui::KeyboardCode. // Translates the DOM4 key code string to ui::KeyboardCode.
UI_BASE_EXPORT KeyboardCode DomKeycodeToKeyboardCode(const std::string& code); UI_BASE_EXPORT KeyboardCode DomKeycodeToKeyboardCode(const std::string& code);
// Translates the ui::KeyboardCode to DOM4 key code string.
UI_BASE_EXPORT std::string KeyboardCodeToDomKeycode(KeyboardCode code);
} // namespace ui } // namespace ui
#endif // UI_BASE_IME_CHROMEOS_IME_KEYMAP_H_ #endif // UI_BASE_IME_CHROMEOS_IME_KEYMAP_H_
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