Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: ui/events/ozone/layout/layout_util.cc

Issue 796003005: Located vs non-located ui::KeyboardCode functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comment (wez) Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/events/ozone/layout/layout_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ui/events/keycodes/keyboard_code_conversion.h"
12 13
13 namespace ui { 14 namespace ui {
14 15
15 namespace { 16 namespace {
16 17
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
22 // This table, used by DomKeyToKeyboardCode(), maps DOM Level 3 .code 18 // This table, used by DomKeyToKeyboardCode(), maps DOM Level 3 .code
23 // values to legacy Windows-based VKEY values, where the VKEYs are 19 // values to legacy Windows-based VKEY values, where the VKEYs are
24 // interpreted positionally. 20 // interpreted positionally.
25 const struct DomCodeToKeyboardCodeEntry { 21 const struct DomCodeToKeyboardCodeEntry {
26 DomCode dom_code; 22 DomCode dom_code;
27 KeyboardCode key_code; 23 KeyboardCode key_code;
28 } dom_code_to_keyboard_code[] = { 24 } dom_code_to_keyboard_code[] = {
29 // Entries are ordered by numeric value of the DomCode enum, 25 // Entries are ordered by numeric value of the DomCode enum,
30 // which is the USB physical key code. 26 // which is the USB physical key code.
31 // DomCode::HYPER 0x000010 Hyper 27 // DomCode::HYPER 0x000010 Hyper
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 return static_cast<int>(a.dom_code) < static_cast<int>(b); 455 return static_cast<int>(a.dom_code) < static_cast<int>(b);
460 }); 456 });
461 if ((found != end) && (found->dom_code == dom_code)) 457 if ((found != end) && (found->dom_code == dom_code))
462 return found->key_code; 458 return found->key_code;
463 return VKEY_UNKNOWN; 459 return VKEY_UNKNOWN;
464 } 460 }
465 461
466 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|. 462 // Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|.
467 // The returned VKEY is non-located (e.g. VKEY_SHIFT). 463 // The returned VKEY is non-located (e.g. VKEY_SHIFT).
468 KeyboardCode DomCodeToNonLocatedKeyboardCode(DomCode dom_code) { 464 KeyboardCode DomCodeToNonLocatedKeyboardCode(DomCode dom_code) {
469 return NonLocatedKeyboardCode(DomCodeToKeyboardCode(dom_code)); 465 return LocatedToNonLocatedKeyboardCode(DomCodeToKeyboardCode(dom_code));
470 }
471
472 // Determine the non-located VKEY corresponding to a located VKEY.
473 KeyboardCode NonLocatedKeyboardCode(KeyboardCode key_code) {
474 switch (key_code) {
475 case VKEY_RWIN:
476 return VKEY_LWIN;
477 case VKEY_LSHIFT:
478 case VKEY_RSHIFT:
479 return VKEY_SHIFT;
480 case VKEY_LCONTROL:
481 case VKEY_RCONTROL:
482 return VKEY_CONTROL;
483 case VKEY_LMENU:
484 case VKEY_RMENU:
485 return VKEY_MENU;
486 default:
487 return key_code;
488 }
489 }
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 } 466 }
526 467
527 bool LookupControlCharacter(DomCode dom_code, 468 bool LookupControlCharacter(DomCode dom_code,
528 int flags, 469 int flags,
529 DomKey* dom_key, 470 DomKey* dom_key,
530 base::char16* character, 471 base::char16* character,
531 KeyboardCode* key_code) { 472 KeyboardCode* key_code) {
532 if ((flags & EF_CONTROL_DOWN) == 0) 473 if ((flags & EF_CONTROL_DOWN) == 0)
533 return false; 474 return false;
534 475
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 // DomKey::ACCEL 567 // DomKey::ACCEL
627 // DomKey::FN 568 // DomKey::FN
628 // DomKey::FN_LOCK 569 // DomKey::FN_LOCK
629 // DomKey::NUM_LOCK 570 // DomKey::NUM_LOCK
630 // DomKey::SCROLL_LOCK 571 // DomKey::SCROLL_LOCK
631 // DomKey::SYMBOL 572 // DomKey::SYMBOL
632 // DomKey::SYMBOL_LOCK 573 // DomKey::SYMBOL_LOCK
633 } 574 }
634 575
635 } // namespace ui 576 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/layout/layout_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698