OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/events/keycodes/keyboard_code_conversion.h" | 5 #include "ui/events/keycodes/keyboard_code_conversion.h" |
6 | 6 |
7 #include "ui/events/event_constants.h" | 7 #include "ui/events/event_constants.h" |
| 8 #include "ui/events/keycodes/dom3/dom_code.h" |
8 #include "ui/events/keycodes/dom3/dom_key.h" | 9 #include "ui/events/keycodes/dom3/dom_key.h" |
9 | 10 |
10 namespace ui { | 11 namespace ui { |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 // This table maps a subset of |KeyboardCode| (VKEYs) to DomKey and character. | 15 // This table maps a subset of |KeyboardCode| (VKEYs) to DomKey and character. |
15 // Only values not otherwise handled by GetMeaningFromKeyCode() are here. | 16 // Only values not otherwise handled by GetMeaningFromKeyCode() are here. |
16 const struct KeyboardCodeToMeaning { | 17 const struct KeyboardCodeToMeaning { |
17 KeyboardCode key_code; | 18 KeyboardCode key_code; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 #if defined(OS_POSIX) | 118 #if defined(OS_POSIX) |
118 {VKEY_POWER, DomKey::POWER, 0, 0}, | 119 {VKEY_POWER, DomKey::POWER, 0, 0}, |
119 {VKEY_BRIGHTNESS_DOWN, DomKey::BRIGHTNESS_DOWN, 0, 0}, | 120 {VKEY_BRIGHTNESS_DOWN, DomKey::BRIGHTNESS_DOWN, 0, 0}, |
120 {VKEY_BRIGHTNESS_UP, DomKey::BRIGHTNESS_UP, 0, 0}, | 121 {VKEY_BRIGHTNESS_UP, DomKey::BRIGHTNESS_UP, 0, 0}, |
121 {VKEY_COMPOSE, DomKey::COMPOSE, 0, 0}, | 122 {VKEY_COMPOSE, DomKey::COMPOSE, 0, 0}, |
122 {VKEY_OEM_103, DomKey::MEDIA_REWIND, 0, 0}, | 123 {VKEY_OEM_103, DomKey::MEDIA_REWIND, 0, 0}, |
123 {VKEY_OEM_104, DomKey::MEDIA_FAST_FORWARD, 0, 0}, | 124 {VKEY_OEM_104, DomKey::MEDIA_FAST_FORWARD, 0, 0}, |
124 #endif | 125 #endif |
125 }; | 126 }; |
126 | 127 |
| 128 bool IsRightSideDomCode(DomCode code) { |
| 129 return (code == DomCode::SHIFT_RIGHT) || (code == DomCode::CONTROL_RIGHT) || |
| 130 (code == DomCode::ALT_RIGHT) || (code == DomCode::OS_RIGHT); |
| 131 } |
| 132 |
127 } // anonymous namespace | 133 } // anonymous namespace |
128 | 134 |
129 base::char16 GetCharacterFromKeyCode(KeyboardCode key_code, int flags) { | 135 base::char16 GetCharacterFromKeyCode(KeyboardCode key_code, int flags) { |
130 ui::DomKey dom_key; | 136 ui::DomKey dom_key; |
131 base::char16 character; | 137 base::char16 character; |
132 if (GetMeaningFromKeyCode(key_code, flags, &dom_key, &character)) | 138 if (GetMeaningFromKeyCode(key_code, flags, &dom_key, &character)) |
133 return character; | 139 return character; |
134 return 0; | 140 return 0; |
135 } | 141 } |
136 | 142 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 *character = (shift && p->shift_character) ? p->shift_character | 260 *character = (shift && p->shift_character) ? p->shift_character |
255 : p->plain_character; | 261 : p->plain_character; |
256 return true; | 262 return true; |
257 } | 263 } |
258 } | 264 } |
259 *dom_key = DomKey::UNIDENTIFIED; | 265 *dom_key = DomKey::UNIDENTIFIED; |
260 *character = 0; | 266 *character = 0; |
261 return false; | 267 return false; |
262 } | 268 } |
263 | 269 |
| 270 // Determine the non-located VKEY corresponding to a located VKEY. |
| 271 KeyboardCode LocatedToNonLocatedKeyboardCode(KeyboardCode key_code) { |
| 272 switch (key_code) { |
| 273 case VKEY_RWIN: |
| 274 return VKEY_LWIN; |
| 275 case VKEY_LSHIFT: |
| 276 case VKEY_RSHIFT: |
| 277 return VKEY_SHIFT; |
| 278 case VKEY_LCONTROL: |
| 279 case VKEY_RCONTROL: |
| 280 return VKEY_CONTROL; |
| 281 case VKEY_LMENU: |
| 282 case VKEY_RMENU: |
| 283 return VKEY_MENU; |
| 284 default: |
| 285 return key_code; |
| 286 } |
| 287 } |
| 288 |
| 289 // Determine the located VKEY corresponding to a non-located VKEY. |
| 290 KeyboardCode NonLocatedToLocatedKeyboardCode(KeyboardCode key_code, |
| 291 DomCode dom_code) { |
| 292 switch (key_code) { |
| 293 case VKEY_SHIFT: |
| 294 return IsRightSideDomCode(dom_code) ? VKEY_RSHIFT : VKEY_LSHIFT; |
| 295 case VKEY_CONTROL: |
| 296 return IsRightSideDomCode(dom_code) ? VKEY_RCONTROL : VKEY_LCONTROL; |
| 297 case VKEY_MENU: |
| 298 return IsRightSideDomCode(dom_code) ? VKEY_RMENU : VKEY_LMENU; |
| 299 case VKEY_LWIN: |
| 300 return IsRightSideDomCode(dom_code) ? VKEY_RWIN : VKEY_LWIN; |
| 301 case VKEY_0: |
| 302 return (dom_code == DomCode::NUMPAD0) ? VKEY_NUMPAD0 : VKEY_0; |
| 303 case VKEY_1: |
| 304 return (dom_code == DomCode::NUMPAD1) ? VKEY_NUMPAD1 : VKEY_1; |
| 305 case VKEY_2: |
| 306 return (dom_code == DomCode::NUMPAD2) ? VKEY_NUMPAD2 : VKEY_2; |
| 307 case VKEY_3: |
| 308 return (dom_code == DomCode::NUMPAD3) ? VKEY_NUMPAD3 : VKEY_3; |
| 309 case VKEY_4: |
| 310 return (dom_code == DomCode::NUMPAD4) ? VKEY_NUMPAD4 : VKEY_4; |
| 311 case VKEY_5: |
| 312 return (dom_code == DomCode::NUMPAD5) ? VKEY_NUMPAD5 : VKEY_5; |
| 313 case VKEY_6: |
| 314 return (dom_code == DomCode::NUMPAD6) ? VKEY_NUMPAD6 : VKEY_6; |
| 315 case VKEY_7: |
| 316 return (dom_code == DomCode::NUMPAD7) ? VKEY_NUMPAD7 : VKEY_7; |
| 317 case VKEY_8: |
| 318 return (dom_code == DomCode::NUMPAD8) ? VKEY_NUMPAD8 : VKEY_8; |
| 319 case VKEY_9: |
| 320 return (dom_code == DomCode::NUMPAD9) ? VKEY_NUMPAD9 : VKEY_9; |
| 321 default: |
| 322 return key_code; |
| 323 } |
| 324 } |
| 325 |
264 } // namespace ui | 326 } // namespace ui |
OLD | NEW |