OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/test/webdriver/keymap.h" |
| 6 |
| 7 #include "chrome/browser/automation/ui_controls.h" |
| 8 #include "views/event.h" |
| 9 |
| 10 namespace webdriver { |
| 11 |
| 12 KeyMap::KeyMap() { |
| 13 // These are keys stored in the Unicode PUA (Private Use Area) code points, |
| 14 // 0xE000-0xF8FF. |
| 15 |
| 16 // Special WebDriver NULL key; clears all modifiers. |
| 17 keys_[L'\uE000'] = base::VKEY_UNKNOWN; |
| 18 |
| 19 keys_[L'\uE001'] = base::VKEY_UNKNOWN; // TODO(jmikhail): CANCEL |
| 20 keys_[L'\uE002'] = base::VKEY_HELP; |
| 21 keys_[L'\uE003'] = base::VKEY_BACK; // BACKSPACE |
| 22 keys_[L'\uE004'] = base::VKEY_TAB; |
| 23 keys_[L'\uE005'] = base::VKEY_CLEAR; |
| 24 keys_[L'\uE006'] = base::VKEY_RETURN; |
| 25 keys_[L'\uE007'] = base::VKEY_UNKNOWN; // TODO(jmikhail): ENTER |
| 26 keys_[L'\uE008'] = base::VKEY_SHIFT; |
| 27 keys_[L'\uE009'] = base::VKEY_CONTROL; |
| 28 keys_[L'\uE00A'] = base::VKEY_MENU; // ALT |
| 29 keys_[L'\uE00B'] = base::VKEY_PAUSE; |
| 30 keys_[L'\uE00C'] = base::VKEY_ESCAPE; |
| 31 keys_[L'\uE00D'] = base::VKEY_SPACE; |
| 32 keys_[L'\uE00E'] = base::VKEY_PRIOR; // PAGEUP |
| 33 keys_[L'\uE00F'] = base::VKEY_NEXT; // PAGEDOWN |
| 34 keys_[L'\uE010'] = base::VKEY_END; |
| 35 keys_[L'\uE011'] = base::VKEY_HOME; |
| 36 keys_[L'\uE012'] = base::VKEY_LEFT; |
| 37 keys_[L'\uE013'] = base::VKEY_UP; |
| 38 keys_[L'\uE014'] = base::VKEY_RIGHT; |
| 39 keys_[L'\uE015'] = base::VKEY_DOWN; |
| 40 keys_[L'\uE016'] = base::VKEY_INSERT; |
| 41 keys_[L'\uE017'] = base::VKEY_DELETE; |
| 42 |
| 43 keys_[L'\uE01A'] = base::VKEY_NUMPAD0; |
| 44 keys_[L'\uE01B'] = base::VKEY_NUMPAD1; |
| 45 keys_[L'\uE01C'] = base::VKEY_NUMPAD2; |
| 46 keys_[L'\uE01D'] = base::VKEY_NUMPAD3; |
| 47 keys_[L'\uE01E'] = base::VKEY_NUMPAD4; |
| 48 keys_[L'\uE01F'] = base::VKEY_NUMPAD5; |
| 49 keys_[L'\uE020'] = base::VKEY_NUMPAD6; |
| 50 keys_[L'\uE021'] = base::VKEY_NUMPAD7; |
| 51 keys_[L'\uE022'] = base::VKEY_NUMPAD8; |
| 52 keys_[L'\uE023'] = base::VKEY_NUMPAD9; |
| 53 keys_[L'\uE024'] = base::VKEY_MULTIPLY; |
| 54 keys_[L'\uE025'] = base::VKEY_ADD; |
| 55 keys_[L'\uE026'] = base::VKEY_SEPARATOR; |
| 56 keys_[L'\uE027'] = base::VKEY_SUBTRACT; |
| 57 keys_[L'\uE028'] = base::VKEY_DECIMAL; |
| 58 keys_[L'\uE029'] = base::VKEY_DIVIDE; |
| 59 |
| 60 keys_[L'\uE031'] = base::VKEY_F1; |
| 61 keys_[L'\uE032'] = base::VKEY_F2; |
| 62 keys_[L'\uE033'] = base::VKEY_F3; |
| 63 keys_[L'\uE034'] = base::VKEY_F4; |
| 64 keys_[L'\uE035'] = base::VKEY_F5; |
| 65 keys_[L'\uE036'] = base::VKEY_F6; |
| 66 keys_[L'\uE037'] = base::VKEY_F7; |
| 67 keys_[L'\uE038'] = base::VKEY_F8; |
| 68 keys_[L'\uE039'] = base::VKEY_F9; |
| 69 keys_[L'\uE03A'] = base::VKEY_F10; |
| 70 keys_[L'\uE03B'] = base::VKEY_F11; |
| 71 keys_[L'\uE03C'] = base::VKEY_F12; |
| 72 |
| 73 // Common aliases. |
| 74 keys_[L'\t'] = base::VKEY_TAB; |
| 75 keys_[L'\n'] = base::VKEY_RETURN; |
| 76 keys_[L'\r'] = base::VKEY_RETURN; |
| 77 keys_[L'\b'] = base::VKEY_BACK; |
| 78 |
| 79 keys_[L' '] = base::VKEY_SPACE; |
| 80 |
| 81 // Alpha keys match their ASCII values |
| 82 for (int i = 0; i < 26; ++i) { |
| 83 keys_[static_cast<wchar_t>(L'a' + i)] = \ |
| 84 static_cast<base::KeyboardCode>(base::VKEY_A + i); |
| 85 shifted_keys_[static_cast<wchar_t>(L'A' + i)] = \ |
| 86 static_cast<base::KeyboardCode>(base::VKEY_A + i); |
| 87 } |
| 88 |
| 89 // Numeric keys match their ASCII values |
| 90 for (int i = 0; i < 10; ++i) { |
| 91 keys_[static_cast<wchar_t>(L'0' + i)] = \ |
| 92 static_cast<base::KeyboardCode>(base::VKEY_0 + i); |
| 93 } |
| 94 |
| 95 // The following all assumes the standard US keyboard. |
| 96 // TODO(jmikhail): Lookup correct keycode based on the current system keyboard |
| 97 // layout. Right now it's fixed assuming standard ANSI |
| 98 keys_[L'='] = shifted_keys_[L'+'] = base::VKEY_OEM_PLUS; |
| 99 keys_[L'-'] = shifted_keys_[L'_'] = base::VKEY_OEM_MINUS; |
| 100 keys_[L';'] = shifted_keys_[L':'] = base::VKEY_OEM_1; |
| 101 keys_[L'/'] = shifted_keys_[L'?'] = base::VKEY_OEM_2; |
| 102 keys_[L'`'] = shifted_keys_[L'~'] = base::VKEY_OEM_3; |
| 103 keys_[L'['] = shifted_keys_[L'{'] = base::VKEY_OEM_4; |
| 104 keys_[L'\\'] = shifted_keys_[L'|'] = base::VKEY_OEM_5; |
| 105 keys_[L']'] = shifted_keys_[L'}'] = base::VKEY_OEM_6; |
| 106 keys_[L'\''] = shifted_keys_[L'"'] = base::VKEY_OEM_7; |
| 107 keys_[L','] = shifted_keys_[L'<'] = base::VKEY_OEM_COMMA; |
| 108 keys_[L'.'] = shifted_keys_[L'>'] = base::VKEY_OEM_PERIOD; |
| 109 shifted_keys_[L'!'] = base::VKEY_1; |
| 110 shifted_keys_[L'@'] = base::VKEY_2; |
| 111 shifted_keys_[L'#'] = base::VKEY_3; |
| 112 shifted_keys_[L'$'] = base::VKEY_4; |
| 113 shifted_keys_[L'%'] = base::VKEY_5; |
| 114 shifted_keys_[L'^'] = base::VKEY_6; |
| 115 shifted_keys_[L'&'] = base::VKEY_7; |
| 116 shifted_keys_[L'*'] = base::VKEY_8; |
| 117 shifted_keys_[L'('] = base::VKEY_9; |
| 118 shifted_keys_[L')'] = base::VKEY_0; |
| 119 } |
| 120 |
| 121 base::KeyboardCode KeyMap::Get(const wchar_t& key) const { |
| 122 std::map<wchar_t, base::KeyboardCode>::const_iterator it; |
| 123 it = keys_.find(key); |
| 124 if (it == keys_.end()) { |
| 125 it = shifted_keys_.find(key); |
| 126 if (it == shifted_keys_.end()) { |
| 127 return base::VKEY_UNKNOWN; |
| 128 } |
| 129 } |
| 130 return it->second; |
| 131 } |
| 132 |
| 133 bool KeyMap::Press(const scoped_refptr<WindowProxy>& window, |
| 134 const base::KeyboardCode key_code, |
| 135 const wchar_t& key) { |
| 136 if (key_code == base::VKEY_SHIFT) { |
| 137 shift_ = !shift_; |
| 138 } else if (key_code == base::VKEY_CONTROL) { |
| 139 control_ = !control_; |
| 140 } else if (key_code == base::VKEY_MENU) { // ALT |
| 141 alt_ = !alt_; |
| 142 } else if (key_code == base::VKEY_COMMAND) { |
| 143 command_ = !command_; |
| 144 } |
| 145 |
| 146 int modifiers = 0; |
| 147 if (shift_ || shifted_keys_.find(key) != shifted_keys_.end()) { |
| 148 modifiers = modifiers | views::Event::EF_SHIFT_DOWN; |
| 149 } |
| 150 if (control_) { |
| 151 modifiers = modifiers | views::Event::EF_CONTROL_DOWN; |
| 152 } |
| 153 if (alt_) { |
| 154 modifiers = modifiers | views::Event::EF_ALT_DOWN; |
| 155 } |
| 156 if (command_) { |
| 157 LOG(INFO) << "Pressing command key on linux!!"; |
| 158 modifiers = modifiers | views::Event::EF_COMMAND_DOWN; |
| 159 } |
| 160 |
| 161 // TODO(jmikhail): need to be able to capture modifier key up |
| 162 window->SimulateOSKeyPress(key_code, modifiers); |
| 163 |
| 164 return true; |
| 165 } |
| 166 |
| 167 void KeyMap::ClearModifiers() { |
| 168 shift_ = false; |
| 169 alt_ = false; |
| 170 control_ = false; |
| 171 command_ = false; |
| 172 } |
| 173 } // namespace webdriver |
| 174 |
OLD | NEW |