OLD | NEW |
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 #ifndef CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 23 matching lines...) Expand all Loading... |
34 kDeviceUnknown = 0, | 34 kDeviceUnknown = 0, |
35 kDeviceAppleKeyboard, | 35 kDeviceAppleKeyboard, |
36 }; | 36 }; |
37 | 37 |
38 KeyRewriter(); | 38 KeyRewriter(); |
39 virtual ~KeyRewriter(); | 39 virtual ~KeyRewriter(); |
40 | 40 |
41 // Calls DeviceAddedInternal. | 41 // Calls DeviceAddedInternal. |
42 DeviceType DeviceAddedForTesting(int device_id, | 42 DeviceType DeviceAddedForTesting(int device_id, |
43 const std::string& device_name); | 43 const std::string& device_name); |
44 // Calls RewriteCommandToControl. | 44 // Calls Rewrite. |
45 void RewriteCommandToControlForTesting(aura::KeyEvent* event); | 45 void RewriteForTesting(aura::KeyEvent* event); |
46 // Calls RewriteNumPadKeys. | |
47 void RewriteNumPadKeysForTesting(aura::KeyEvent* event); | |
48 | 46 |
49 const std::map<int, DeviceType>& device_id_to_type_for_testing() const { | 47 const std::map<int, DeviceType>& device_id_to_type_for_testing() const { |
50 return device_id_to_type_; | 48 return device_id_to_type_; |
51 } | 49 } |
52 void set_last_device_id_for_testing(int device_id) { | 50 void set_last_device_id_for_testing(int device_id) { |
53 last_device_id_ = device_id; | 51 last_device_id_ = device_id; |
54 } | 52 } |
55 | 53 |
56 // Gets DeviceType from the |device_name|. | 54 // Gets DeviceType from the |device_name|. |
57 static DeviceType GetDeviceType(const std::string& device_name); | 55 static DeviceType GetDeviceType(const std::string& device_name); |
(...skipping 10 matching lines...) Expand all Loading... |
68 // chromeos::DeviceHierarchyObserver overrides: | 66 // chromeos::DeviceHierarchyObserver overrides: |
69 virtual void DeviceHierarchyChanged() OVERRIDE {} | 67 virtual void DeviceHierarchyChanged() OVERRIDE {} |
70 virtual void DeviceAdded(int device_id) OVERRIDE; | 68 virtual void DeviceAdded(int device_id) OVERRIDE; |
71 virtual void DeviceRemoved(int device_id) OVERRIDE; | 69 virtual void DeviceRemoved(int device_id) OVERRIDE; |
72 virtual void DeviceKeyPressedOrReleased(int device_id) OVERRIDE; | 70 virtual void DeviceKeyPressedOrReleased(int device_id) OVERRIDE; |
73 | 71 |
74 // Updates |*_xkeycode_| in response to a keyboard map change. | 72 // Updates |*_xkeycode_| in response to a keyboard map change. |
75 void RefreshKeycodes(); | 73 void RefreshKeycodes(); |
76 #endif | 74 #endif |
77 | 75 |
| 76 // Rewrites the |event| by applying all RewriteXXX functions as needed. |
| 77 void Rewrite(aura::KeyEvent* event); |
| 78 |
78 // Rewrites Comment-L/R key presses on an Apple keyboard to Control-L/R. Only | 79 // Rewrites Comment-L/R key presses on an Apple keyboard to Control-L/R. Only |
79 // OS_CHROMEOS implementation is available at this point. Returns true when | 80 // OS_CHROMEOS implementation is available at this point. Returns true when |
80 // |event| is rewritten. | 81 // |event| is rewritten. |
81 bool RewriteCommandToControl(aura::KeyEvent* event); | 82 bool RewriteCommandToControl(aura::KeyEvent* event); |
82 | 83 |
83 // Rewrites a NumPad key press/release without Num Lock to a corresponding key | 84 // Rewrites a NumPad key press/release without Num Lock to a corresponding key |
84 // press/release with the lock. Returns true when |event| is rewritten. | 85 // press/release with the lock. Returns true when |event| is rewritten. |
85 bool RewriteNumPadKeys(aura::KeyEvent* event); | 86 bool RewriteNumPadKeys(aura::KeyEvent* event); |
86 | 87 |
87 // Overwrites |event| with the keycodes and flags. | 88 // Overwrites |event| with the keycodes and flags. |
88 void Rewrite(aura::KeyEvent* event, | 89 void OverwriteEvent(aura::KeyEvent* event, |
89 unsigned int new_native_keycode, | 90 unsigned int new_native_keycode, |
90 unsigned int new_native_state, | 91 unsigned int new_native_state, |
91 ui::KeyboardCode new_keycode, | 92 ui::KeyboardCode new_keycode, |
92 int new_flags); | 93 int new_flags); |
93 | 94 |
94 // Checks the type of the |device_name|, and inserts a new entry to | 95 // Checks the type of the |device_name|, and inserts a new entry to |
95 // |device_id_to_type_|. | 96 // |device_id_to_type_|. |
96 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name); | 97 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name); |
97 | 98 |
98 std::map<int, DeviceType> device_id_to_type_; | 99 std::map<int, DeviceType> device_id_to_type_; |
99 int last_device_id_; | 100 int last_device_id_; |
100 | 101 |
101 #if defined(OS_CHROMEOS) | 102 #if defined(OS_CHROMEOS) |
102 // X keycodes corresponding to various keysyms. | 103 // X keycodes corresponding to various keysyms. |
103 unsigned int control_l_xkeycode_; | 104 unsigned int control_l_xkeycode_; |
104 unsigned int control_r_xkeycode_; | 105 unsigned int control_r_xkeycode_; |
105 unsigned int kp_0_xkeycode_; | 106 unsigned int kp_0_xkeycode_; |
106 unsigned int kp_1_xkeycode_; | 107 unsigned int kp_1_xkeycode_; |
107 unsigned int kp_2_xkeycode_; | 108 unsigned int kp_2_xkeycode_; |
108 unsigned int kp_3_xkeycode_; | 109 unsigned int kp_3_xkeycode_; |
109 unsigned int kp_4_xkeycode_; | 110 unsigned int kp_4_xkeycode_; |
110 unsigned int kp_5_xkeycode_; | 111 unsigned int kp_5_xkeycode_; |
111 unsigned int kp_6_xkeycode_; | 112 unsigned int kp_6_xkeycode_; |
112 unsigned int kp_7_xkeycode_; | 113 unsigned int kp_7_xkeycode_; |
113 unsigned int kp_8_xkeycode_; | 114 unsigned int kp_8_xkeycode_; |
114 unsigned int kp_9_xkeycode_; | 115 unsigned int kp_9_xkeycode_; |
115 unsigned int kp_decimal_xkeycode_; | 116 unsigned int kp_decimal_xkeycode_; |
116 #endif | 117 #endif |
117 | 118 |
118 DISALLOW_COPY_AND_ASSIGN(KeyRewriter); | 119 DISALLOW_COPY_AND_ASSIGN(KeyRewriter); |
119 }; | 120 }; |
120 | 121 |
121 #endif // CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_ | 122 #endif // CHROME_BROWSER_UI_VIEWS_ASH_KEY_REWRITER_H_ |
OLD | NEW |