OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ozone/layout/layout_util.h" | 5 #include "ui/events/ozone/layout/layout_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ui/events/event_constants.h" | 9 #include "ui/events/event_constants.h" |
10 #include "ui/events/keycodes/dom3/dom_code.h" | 10 #include "ui/events/keycodes/dom3/dom_code.h" |
11 #include "ui/events/keycodes/dom3/dom_key.h" | 11 #include "ui/events/keycodes/dom3/dom_key.h" |
12 | 12 |
13 namespace ui { | 13 namespace ui { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
| 17 bool IsRightSideDomCode(DomCode code) { |
| 18 return (code == DomCode::SHIFT_RIGHT) || (code == DomCode::CONTROL_RIGHT) || |
| 19 (code == DomCode::ALT_RIGHT) || (code == DomCode::OS_RIGHT); |
| 20 } |
| 21 |
17 // This table, used by DomKeyToKeyboardCode(), maps DOM Level 3 .code | 22 // This table, used by DomKeyToKeyboardCode(), maps DOM Level 3 .code |
18 // values to legacy Windows-based VKEY values, where the VKEYs are | 23 // values to legacy Windows-based VKEY values, where the VKEYs are |
19 // interpreted positionally. | 24 // interpreted positionally. |
20 const struct DomCodeToKeyboardCodeEntry { | 25 const struct DomCodeToKeyboardCodeEntry { |
21 DomCode dom_code; | 26 DomCode dom_code; |
22 KeyboardCode key_code; | 27 KeyboardCode key_code; |
23 } dom_code_to_keyboard_code[] = { | 28 } dom_code_to_keyboard_code[] = { |
24 // Entries are ordered by numeric value of the DomCode enum, | 29 // Entries are ordered by numeric value of the DomCode enum, |
25 // which is the USB physical key code. | 30 // which is the USB physical key code. |
26 // DomCode::HYPER 0x000010 Hyper | 31 // DomCode::HYPER 0x000010 Hyper |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 VKEY_BROWSER_FORWARD}, // 0x0C0225 BrowserForward | 201 VKEY_BROWSER_FORWARD}, // 0x0C0225 BrowserForward |
197 {DomCode::BROWSER_STOP, VKEY_BROWSER_STOP}, // 0x0C0226 BrowserStop | 202 {DomCode::BROWSER_STOP, VKEY_BROWSER_STOP}, // 0x0C0226 BrowserStop |
198 {DomCode::BROWSER_REFRESH, | 203 {DomCode::BROWSER_REFRESH, |
199 VKEY_BROWSER_REFRESH}, // 0x0C0227 BrowserRefresh | 204 VKEY_BROWSER_REFRESH}, // 0x0C0227 BrowserRefresh |
200 {DomCode::BROWSER_FAVORITES, | 205 {DomCode::BROWSER_FAVORITES, |
201 VKEY_BROWSER_FAVORITES}, // 0x0C022A BrowserFavorites | 206 VKEY_BROWSER_FAVORITES}, // 0x0C022A BrowserFavorites |
202 }; | 207 }; |
203 | 208 |
204 } // anonymous namespace | 209 } // anonymous namespace |
205 | 210 |
206 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|. | |
207 // The returned VKEY is positional (e.g. VKEY_LSHIFT). | |
208 KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) { | |
209 const DomCodeToKeyboardCodeEntry* end = | |
210 dom_code_to_keyboard_code + arraysize(dom_code_to_keyboard_code); | |
211 const DomCodeToKeyboardCodeEntry* found = | |
212 std::lower_bound(dom_code_to_keyboard_code, end, dom_code, | |
213 [](const DomCodeToKeyboardCodeEntry& a, DomCode b) { | |
214 return static_cast<int>(a.dom_code) < static_cast<int>(b); | |
215 }); | |
216 if ((found != end) && (found->dom_code == dom_code)) | |
217 return found->key_code; | |
218 return VKEY_UNKNOWN; | |
219 } | |
220 | |
221 // Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|. | 211 // Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|. |
222 // The returned VKEY is non-positional (e.g. VKEY_SHIFT). | 212 // The returned VKEY is non-positional (e.g. VKEY_SHIFT). |
223 KeyboardCode NonPrintableDomKeyToKeyboardCode(DomKey dom_key) { | 213 KeyboardCode NonPrintableDomKeyToKeyboardCode(DomKey dom_key) { |
224 switch (dom_key) { | 214 switch (dom_key) { |
225 // No value. | 215 // No value. |
226 case DomKey::NONE: | 216 case DomKey::NONE: |
227 return VKEY_UNKNOWN; | 217 return VKEY_UNKNOWN; |
228 // Character values. | 218 // Character values. |
229 // Special Key Values | 219 // Special Key Values |
230 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special | 220 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-special |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 // Media Controller Keys | 441 // Media Controller Keys |
452 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller | 442 // http://www.w3.org/TR/DOM-Level-3-Events-key/#keys-media-controller |
453 case DomKey::ZOOM_TOGGLE: | 443 case DomKey::ZOOM_TOGGLE: |
454 return VKEY_ZOOM; | 444 return VKEY_ZOOM; |
455 // No value. | 445 // No value. |
456 default: | 446 default: |
457 return VKEY_UNKNOWN; | 447 return VKEY_UNKNOWN; |
458 } | 448 } |
459 } | 449 } |
460 | 450 |
| 451 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|. |
| 452 // The returned VKEY is located (e.g. VKEY_LSHIFT). |
| 453 KeyboardCode DomCodeToKeyboardCode(DomCode dom_code) { |
| 454 const DomCodeToKeyboardCodeEntry* end = |
| 455 dom_code_to_keyboard_code + arraysize(dom_code_to_keyboard_code); |
| 456 const DomCodeToKeyboardCodeEntry* found = |
| 457 std::lower_bound(dom_code_to_keyboard_code, end, dom_code, |
| 458 [](const DomCodeToKeyboardCodeEntry& a, DomCode b) { |
| 459 return static_cast<int>(a.dom_code) < static_cast<int>(b); |
| 460 }); |
| 461 if ((found != end) && (found->dom_code == dom_code)) |
| 462 return found->key_code; |
| 463 return VKEY_UNKNOWN; |
| 464 } |
| 465 |
| 466 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|. |
| 467 // The returned VKEY is non-located (e.g. VKEY_SHIFT). |
| 468 KeyboardCode DomCodeToNonLocatedKeyboardCode(DomCode dom_code) { |
| 469 return NonLocatedKeyboardCode(DomCodeToKeyboardCode(dom_code)); |
| 470 } |
| 471 |
461 // Determine the non-located VKEY corresponding to a located VKEY. | 472 // Determine the non-located VKEY corresponding to a located VKEY. |
462 ui::KeyboardCode DeLocateKeyboardCode(ui::KeyboardCode key_code) { | 473 KeyboardCode NonLocatedKeyboardCode(KeyboardCode key_code) { |
463 switch (key_code) { | 474 switch (key_code) { |
464 case VKEY_RWIN: | 475 case VKEY_RWIN: |
465 return VKEY_LWIN; | 476 return VKEY_LWIN; |
466 case VKEY_LSHIFT: | 477 case VKEY_LSHIFT: |
467 case VKEY_RSHIFT: | 478 case VKEY_RSHIFT: |
468 return VKEY_SHIFT; | 479 return VKEY_SHIFT; |
469 case VKEY_LCONTROL: | 480 case VKEY_LCONTROL: |
470 case VKEY_RCONTROL: | 481 case VKEY_RCONTROL: |
471 return VKEY_CONTROL; | 482 return VKEY_CONTROL; |
472 case VKEY_LMENU: | 483 case VKEY_LMENU: |
473 case VKEY_RMENU: | 484 case VKEY_RMENU: |
474 return VKEY_MENU; | 485 return VKEY_MENU; |
475 default: | 486 default: |
476 return key_code; | 487 return key_code; |
477 } | 488 } |
478 } | 489 } |
479 | 490 |
| 491 // Determine the located VKEY corresponding to a non-located VKEY. |
| 492 KeyboardCode LocatedKeyboardCode(KeyboardCode key_code, DomCode dom_code) { |
| 493 switch (key_code) { |
| 494 case VKEY_SHIFT: |
| 495 return IsRightSideDomCode(dom_code) ? VKEY_RSHIFT : VKEY_LSHIFT; |
| 496 case VKEY_CONTROL: |
| 497 return IsRightSideDomCode(dom_code) ? VKEY_RCONTROL : VKEY_LCONTROL; |
| 498 case VKEY_MENU: |
| 499 return IsRightSideDomCode(dom_code) ? VKEY_RMENU : VKEY_LMENU; |
| 500 case VKEY_LWIN: |
| 501 return IsRightSideDomCode(dom_code) ? VKEY_RWIN : VKEY_LWIN; |
| 502 case VKEY_0: |
| 503 return (dom_code == DomCode::NUMPAD0) ? VKEY_NUMPAD0 : VKEY_0; |
| 504 case VKEY_1: |
| 505 return (dom_code == DomCode::NUMPAD1) ? VKEY_NUMPAD1 : VKEY_1; |
| 506 case VKEY_2: |
| 507 return (dom_code == DomCode::NUMPAD2) ? VKEY_NUMPAD2 : VKEY_2; |
| 508 case VKEY_3: |
| 509 return (dom_code == DomCode::NUMPAD3) ? VKEY_NUMPAD3 : VKEY_3; |
| 510 case VKEY_4: |
| 511 return (dom_code == DomCode::NUMPAD4) ? VKEY_NUMPAD4 : VKEY_4; |
| 512 case VKEY_5: |
| 513 return (dom_code == DomCode::NUMPAD5) ? VKEY_NUMPAD5 : VKEY_5; |
| 514 case VKEY_6: |
| 515 return (dom_code == DomCode::NUMPAD6) ? VKEY_NUMPAD6 : VKEY_6; |
| 516 case VKEY_7: |
| 517 return (dom_code == DomCode::NUMPAD7) ? VKEY_NUMPAD7 : VKEY_7; |
| 518 case VKEY_8: |
| 519 return (dom_code == DomCode::NUMPAD8) ? VKEY_NUMPAD8 : VKEY_8; |
| 520 case VKEY_9: |
| 521 return (dom_code == DomCode::NUMPAD9) ? VKEY_NUMPAD9 : VKEY_9; |
| 522 default: |
| 523 return key_code; |
| 524 } |
| 525 } |
| 526 |
480 bool LookupControlCharacter(DomCode dom_code, | 527 bool LookupControlCharacter(DomCode dom_code, |
481 int flags, | 528 int flags, |
482 DomKey* dom_key, | 529 DomKey* dom_key, |
483 base::char16* character, | 530 base::char16* character, |
484 KeyboardCode* key_code) { | 531 KeyboardCode* key_code) { |
485 if ((flags & EF_CONTROL_DOWN) == 0) | 532 if ((flags & EF_CONTROL_DOWN) == 0) |
486 return false; | 533 return false; |
487 | 534 |
488 int code = static_cast<int>(dom_code); | 535 int code = static_cast<int>(dom_code); |
489 const int kKeyA = static_cast<int>(DomCode::KEY_A); | 536 const int kKeyA = static_cast<int>(DomCode::KEY_A); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 *character = 0x1F; | 593 *character = 0x1F; |
547 *dom_key = DomKey::CHARACTER; | 594 *dom_key = DomKey::CHARACTER; |
548 *key_code = VKEY_OEM_MINUS; | 595 *key_code = VKEY_OEM_MINUS; |
549 return true; | 596 return true; |
550 default: | 597 default: |
551 return false; | 598 return false; |
552 } | 599 } |
553 } | 600 } |
554 | 601 |
555 } // namespace ui | 602 } // namespace ui |
OLD | NEW |