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

Side by Side Diff: ui/base/events/key_identifier_conversion.cc

Issue 13957005: Move KeyIdentifier->KeyEvent conversion to src/ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/extensions/key_identifier_conversion_views.h" 5 #include "ui/base/events/key_identifier_conversion.h"
6 6
7 #include <string.h> 7 #include <string.h>
8
9 #include <utility> 8 #include <utility>
10 9
11 #include "base/basictypes.h" 10 #include "base/basictypes.h"
12 #include "base/hash_tables.h" 11 #include "base/hash_tables.h"
13 #include "base/logging.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "ui/base/events/event.h" 12 #include "ui/base/events/event.h"
16 #include "ui/base/keycodes/keyboard_codes.h" 13 #include "ui/base/keycodes/keyboard_codes.h"
17 14
18 using content::BrowserThread;
19
20 namespace { 15 namespace {
21 16
22 static const int kNumIdentifierTypes = 3; 17 static const int kNumIdentifierTypes = 3;
sadrul 2013/04/15 02:05:12 We typically don't mark things 'static' in anonymo
bryeung 2013/04/15 15:34:13 Fixed (throughout).
23 18
24 typedef struct KeyIdentifier { 19 typedef struct KeyIdentifier {
25 // In order: key identifier, character and unicode codepoint. They are 20 // In order: key identifier, character and unicode codepoint. They are
26 // searched in that order as well. 21 // searched in that order as well.
27 // These are all placed into a single array as they are treated uniformly and 22 // These are all placed into a single array as they are treated uniformly and
28 // we never refer to a specific type of identifier. This reduces code 23 // we never refer to a specific type of identifier. This reduces code
29 // duplication below. 24 // duplication below.
30 const char* identifiers[kNumIdentifierTypes]; 25 const char* identifiers[kNumIdentifierTypes];
31 const ui::KeyboardCode key_code; 26 const ui::KeyboardCode key_code;
32 const int event_flags; 27 const int event_flags;
33 } KeyIdentifier; 28 } KeyIdentifier;
34 29
35 // Taken from Section 6.3.3 here: 30 // Taken from Section 6.3.3 here:
36 // http://www.w3.org/TR/DOM-Level-3-Events/#keyset-keyidentifiers 31 // http://www.w3.org/TR/DOM-Level-3-Events/#keyset-keyidentifiers
37 // TODO(bryeung): keycodes could be wrong: I took the keydown code only 32 // WARNING: keycodes could be wrong, as they are based soley on keydown
38 static const KeyIdentifier kKeyIdentifiers[] = { 33 static const KeyIdentifier kKeyIdentifiers[] = {
39 { {"Accept", "", ""}, ui::VKEY_ACCEPT, 0 }, 34 { {"Accept", "", ""}, ui::VKEY_ACCEPT, 0 },
40 { {"Add", "", ""}, ui::VKEY_ADD, 0 }, 35 { {"Add", "", ""}, ui::VKEY_ADD, 0 },
41 { {"Again", "", ""}, ui::VKEY_UNKNOWN, 0 }, 36 { {"Again", "", ""}, ui::VKEY_UNKNOWN, 0 },
42 { {"AllCandidates", "", ""}, ui::VKEY_UNKNOWN, 0 }, 37 { {"AllCandidates", "", ""}, ui::VKEY_UNKNOWN, 0 },
43 { {"Alphanumeric", "", ""}, ui::VKEY_UNKNOWN, 0 }, 38 { {"Alphanumeric", "", ""}, ui::VKEY_UNKNOWN, 0 },
44 { {"Alt", "", ""}, ui::VKEY_MENU, 0 }, 39 { {"Alt", "", ""}, ui::VKEY_MENU, 0 },
45 { {"AltGraph", "", ""}, ui::VKEY_UNKNOWN, 0 }, 40 { {"AltGraph", "", ""}, ui::VKEY_UNKNOWN, 0 },
46 { {"Apps", "", ""}, ui::VKEY_APPS, 0 }, 41 { {"Apps", "", ""}, ui::VKEY_APPS, 0 },
47 { {"Attn", "", ""}, ui::VKEY_ATTN, 0 }, 42 { {"Attn", "", ""}, ui::VKEY_ATTN, 0 },
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 identifierMaps[j]->insert( 314 identifierMaps[j]->insert(
320 IdentifierPair(key.identifiers[j], event)); 315 IdentifierPair(key.identifiers[j], event));
321 DCHECK(result.second); 316 DCHECK(result.second);
322 } 317 }
323 } 318 }
324 } 319 }
325 } 320 }
326 321
327 } // namespace 322 } // namespace
328 323
324 namespace ui {
329 325
330 const ui::KeyEvent& KeyEventFromKeyIdentifier( 326 const ui::KeyEvent& KeyEventFromKeyIdentifier(
331 const std::string& key_identifier) { 327 const std::string& key_identifier) {
332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 328 // FIXME: what about races?
bryeung 2013/04/14 15:40:16 Sadrul: do you know what the Right Way (TM) is to
sadrul 2013/04/15 02:05:12 You can keep a static base::PlatformThreadId in In
bryeung 2013/04/15 15:34:13 Works for me: I'll add a comment about that to the
333 InitializeMaps(); 329 InitializeMaps();
334 330
335 for (int i = 0; i < kNumIdentifierTypes; ++i) { 331 for (int i = 0; i < kNumIdentifierTypes; ++i) {
336 const IdentifierMap& map = *identifierMaps[i]; 332 const IdentifierMap& map = *identifierMaps[i];
337 333
338 IdentifierMap::const_iterator iter = map.find(key_identifier); 334 IdentifierMap::const_iterator iter = map.find(key_identifier);
339 if (iter != map.end()) 335 if (iter != map.end())
340 return *iter->second; 336 return *iter->second;
341 } 337 }
342 338
343 return *kUnknownKeyEvent; 339 return *kUnknownKeyEvent;
344 } 340 }
341
342 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698