| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/chromedriver/keycode_text_conversion.h" | 5 #include "chrome/test/chromedriver/keycode_text_conversion.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <X11/keysym.h> | 8 #include <X11/keysym.h> |
| 9 #include <X11/XKBlib.h> | 9 #include <X11/XKBlib.h> |
| 10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 173 } |
| 174 XFreeModifiermap(mod_map); | 174 XFreeModifiermap(mod_map); |
| 175 return found; | 175 return found; |
| 176 } | 176 } |
| 177 | 177 |
| 178 } // namespace | 178 } // namespace |
| 179 | 179 |
| 180 std::string ConvertKeyCodeToText(ui::KeyboardCode key_code, int modifiers) { | 180 std::string ConvertKeyCodeToText(ui::KeyboardCode key_code, int modifiers) { |
| 181 int x_key_code = KeyboardCodeToXKeyCode(key_code); | 181 int x_key_code = KeyboardCodeToXKeyCode(key_code); |
| 182 if (x_key_code == -1) | 182 if (x_key_code == -1) |
| 183 return ""; | 183 return std::string(); |
| 184 | 184 |
| 185 XEvent event; | 185 XEvent event; |
| 186 memset(&event, 0, sizeof(XEvent)); | 186 memset(&event, 0, sizeof(XEvent)); |
| 187 XKeyEvent* key_event = &event.xkey; | 187 XKeyEvent* key_event = &event.xkey; |
| 188 Display* display = ui::GetXDisplay(); | 188 Display* display = ui::GetXDisplay(); |
| 189 key_event->display = display; | 189 key_event->display = display; |
| 190 key_event->keycode = x_key_code; | 190 key_event->keycode = x_key_code; |
| 191 if (modifiers & kShiftKeyModifierMask) | 191 if (modifiers & kShiftKeyModifierMask) |
| 192 key_event->state |= ShiftMask; | 192 key_event->state |= ShiftMask; |
| 193 if (modifiers & kControlKeyModifierMask) | 193 if (modifiers & kControlKeyModifierMask) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 204 key_event->state |= x_modifier; | 204 key_event->state |= x_modifier; |
| 205 } | 205 } |
| 206 if (modifiers & kNumLockKeyModifierMask && | 206 if (modifiers & kNumLockKeyModifierMask && |
| 207 GetXModifierMask(display, kNumLockKeyModifierMask, &x_modifier)) { | 207 GetXModifierMask(display, kNumLockKeyModifierMask, &x_modifier)) { |
| 208 key_event->state |= x_modifier; | 208 key_event->state |= x_modifier; |
| 209 } | 209 } |
| 210 key_event->type = KeyPress; | 210 key_event->type = KeyPress; |
| 211 uint16 character = ui::GetCharacterFromXEvent(&event); | 211 uint16 character = ui::GetCharacterFromXEvent(&event); |
| 212 | 212 |
| 213 if (!character) | 213 if (!character) |
| 214 return ""; | 214 return std::string(); |
| 215 return UTF16ToUTF8(string16(1, character)); | 215 return UTF16ToUTF8(string16(1, character)); |
| 216 } | 216 } |
| 217 | 217 |
| 218 bool ConvertCharToKeyCode( | 218 bool ConvertCharToKeyCode( |
| 219 char16 key, | 219 char16 key, |
| 220 ui::KeyboardCode* key_code, | 220 ui::KeyboardCode* key_code, |
| 221 int* necessary_modifiers) { | 221 int* necessary_modifiers) { |
| 222 std::string key_string(UTF16ToUTF8(string16(1, key))); | 222 std::string key_string(UTF16ToUTF8(string16(1, key))); |
| 223 bool found = false; | 223 bool found = false; |
| 224 ui::KeyboardCode test_code; | 224 ui::KeyboardCode test_code; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 238 found = true; | 238 found = true; |
| 239 break; | 239 break; |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 if (found) { | 242 if (found) { |
| 243 *key_code = test_code; | 243 *key_code = test_code; |
| 244 *necessary_modifiers = test_modifiers; | 244 *necessary_modifiers = test_modifiers; |
| 245 } | 245 } |
| 246 return found; | 246 return found; |
| 247 } | 247 } |
| OLD | NEW |