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

Side by Side Diff: chrome/browser/extensions/api/braille_display_private/brlapi_keycode_map.cc

Issue 297833015: Support standard keyboard keys emulated by the braille drivers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 6 years, 7 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/braille_display_private/brlapi_keycode_m ap.h"
6
7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversion_utils.h"
9
10 namespace extensions {
11 namespace api {
12 namespace braille_display_private {
13
14 namespace {
15 // Bitmask for all braille dots in a key command argument, which coincides
16 // with the representation in the braille_dots member of the KeyEvent
17 // class.
18 const int kAllDots = BRLAPI_DOT1 | BRLAPI_DOT2 | BRLAPI_DOT3 | BRLAPI_DOT4 |
19 BRLAPI_DOT5 | BRLAPI_DOT6 | BRLAPI_DOT7 | BRLAPI_DOT8;
20
21 // Maximum Laitn 1 character keyboard symbol.
David Tseng 2014/05/27 21:29:31 Latin
22 const brlapi_keyCode_t kMaxLatin1KeySym = 0xff;
23
24 // Range of function keys that we support.
25 // See ui/events/keycodes/dom4/keycode_converter_data.h for the list of all
26 // key codes.
27 const brlapi_keyCode_t kMinFunctionKey = BRLAPI_KEY_SYM_FUNCTION;
28 const brlapi_keyCode_t kMaxFunctionKey = BRLAPI_KEY_SYM_FUNCTION + 23;
29
30 // Maps the keyboard modifier flags to their corresponding flags in a
31 // |KeyEvent|.
32 void MapModifierFlags(brlapi_keyCode_t code, KeyEvent* event) {
33 if (code & BRLAPI_KEY_FLG_CONTROL)
34 event->ctrl_key.reset(new bool(true));
35 if (code & BRLAPI_KEY_FLG_META)
36 event->alt_key.reset(new bool(true));
37 if (code & BRLAPI_KEY_FLG_SHIFT)
38 event->shift_key.reset(new bool(true));
David Tseng 2014/05/27 21:29:31 Do we get any other modifiers?
39 }
40
41 // Maps a brlapi keysym, which is similar to an X keysym into the
42 // provided event.
43 void MapKeySym(brlapi_keyCode_t code, KeyEvent* event) {
44 brlapi_keyCode_t key_sym = code & BRLAPI_KEY_CODE_MASK;
45 if (key_sym < kMaxLatin1KeySym ||
46 (key_sym & BRLAPI_KEY_SYM_UNICODE) != 0) {
47 uint32 code_point = key_sym & ~BRLAPI_KEY_SYM_UNICODE;
48 if (!base::IsValidCharacter(code_point))
49 return;
50 event->standard_key_char.reset(new std::string);
51 base::WriteUnicodeCharacter(code_point, event->standard_key_char.get());
52 } else if (key_sym >= kMinFunctionKey && key_sym <= kMaxFunctionKey) {
53 // Function keys are 0-based here, so we need to add one to get e.g.
54 // 'F1' for the first key.
55 int function_key_number = key_sym - kMinFunctionKey + 1;
56 event->standard_key_code.reset(
57 new std::string(base::StringPrintf("F%d", function_key_number)));
58 } else {
59 // Explicitly map the keys that brlapi provides.
60 const char* code_string;
61 switch (key_sym) {
62 case BRLAPI_KEY_SYM_BACKSPACE:
63 code_string = "Backspace";
David Tseng 2014/05/27 21:29:31 Where do these strings come from?
64 break;
65 case BRLAPI_KEY_SYM_TAB:
66 code_string = "Tab";
67 break;
68 case BRLAPI_KEY_SYM_LINEFEED:
69 code_string = "Enter";
70 break;
71 case BRLAPI_KEY_SYM_ESCAPE:
72 code_string = "Escape";
73 break;
74 case BRLAPI_KEY_SYM_HOME:
75 code_string = "Home";
76 break;
77 case BRLAPI_KEY_SYM_LEFT:
78 code_string = "ArrowLeft";
79 break;
80 case BRLAPI_KEY_SYM_UP:
81 code_string = "ArrowUp";
82 break;
83 case BRLAPI_KEY_SYM_RIGHT:
84 code_string = "ArrowRight";
85 break;
86 case BRLAPI_KEY_SYM_DOWN:
87 code_string = "ArrowDown";
88 break;
89 case BRLAPI_KEY_SYM_PAGE_UP:
90 code_string = "PageUp";
91 break;
92 case BRLAPI_KEY_SYM_PAGE_DOWN:
93 code_string = "PageDown";
94 break;
95 case BRLAPI_KEY_SYM_END:
96 code_string = "End";
97 break;
98 case BRLAPI_KEY_SYM_INSERT:
99 code_string = "Insert";
100 break;
101 case BRLAPI_KEY_SYM_DELETE:
102 code_string = "Delete";
103 break;
104 default:
105 return;
David Tseng 2014/05/27 21:29:31 DCHECK?
106 }
107 event->standard_key_code.reset(new std::string(code_string));
108 }
109 MapModifierFlags(code, event);
110 event->command = KEY_COMMAND_STANDARD_KEY;
111 }
112
113 void MapCommand(brlapi_keyCode_t code, KeyEvent* event) {
114 brlapi_keyCode_t argument = code & BRLAPI_KEY_CMD_ARG_MASK;
115 switch (code & BRLAPI_KEY_CODE_MASK) {
116 case BRLAPI_KEY_CMD_LNUP:
117 event->command = KEY_COMMAND_LINE_UP;
118 break;
119 case BRLAPI_KEY_CMD_LNDN:
120 event->command = KEY_COMMAND_LINE_DOWN;
121 break;
122 case BRLAPI_KEY_CMD_FWINLT:
123 event->command = KEY_COMMAND_PAN_LEFT;
124 break;
125 case BRLAPI_KEY_CMD_FWINRT:
126 event->command = KEY_COMMAND_PAN_RIGHT;
127 break;
128 case BRLAPI_KEY_CMD_TOP:
129 event->command = KEY_COMMAND_TOP;
130 break;
131 case BRLAPI_KEY_CMD_BOT:
132 event->command = KEY_COMMAND_BOTTOM;
133 break;
134 default:
135 switch (code & BRLAPI_KEY_CMD_BLK_MASK) {
136 case BRLAPI_KEY_CMD_ROUTE:
137 event->command = KEY_COMMAND_ROUTING;
138 event->display_position.reset(new int(argument));
139 break;
140 case BRLAPI_KEY_CMD_PASSDOTS:
141 event->command = KEY_COMMAND_DOTS;
142 event->braille_dots.reset(new int(argument & kAllDots));
David Tseng 2014/05/27 21:29:31 When would |argument| have bits not in kAllDots se
143 MapModifierFlags(code, event);
144 break;
145 }
146 }
147 }
148
149 } // namespace
150
151 scoped_ptr<KeyEvent> BrlapiKeyCodeToEvent(brlapi_keyCode_t code) {
152 scoped_ptr<KeyEvent> result(new KeyEvent);
153 result->command = KEY_COMMAND_NONE;
154 switch (code & BRLAPI_KEY_TYPE_MASK) {
155 case BRLAPI_KEY_TYPE_SYM:
156 MapKeySym(code, result.get());
157 break;
158 case BRLAPI_KEY_TYPE_CMD:
159 MapCommand(code, result.get());
160 break;
161 }
162 if (result->command == KEY_COMMAND_NONE)
163 result.reset();
164 return result.Pass();
165 }
166
167 } // namespace braille_display_private
168 } // namespace api
169 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698