OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 | |
13 namespace chromeos { | |
14 namespace input_method { | |
15 | |
16 struct AutoRepeatRate { | |
17 AutoRepeatRate() : initial_delay_in_ms(0), repeat_interval_in_ms(0) {} | |
18 unsigned int initial_delay_in_ms; | |
19 unsigned int repeat_interval_in_ms; | |
20 }; | |
21 | |
22 enum ModifierLockStatus { | |
23 kDisableLock = 0, | |
24 kEnableLock, | |
25 kDontChange, | |
26 }; | |
27 | |
28 enum ModifierKey { | |
29 kSearchKey = 0, // Customizable. | |
30 kControlKey, // Customizable. | |
31 kAltKey, // Customizable. | |
32 kVoidKey, | |
33 kCapsLockKey, | |
34 // IMPORTANT: You should update kCustomizableKeys[] in .cc file, if you | |
35 // add a customizable key. | |
36 kNumModifierKeys, | |
37 }; | |
38 | |
39 class InputMethodUtil; | |
40 | |
41 class XKeyboard { | |
42 public: | |
43 virtual ~XKeyboard() {} | |
44 | |
45 // Sets the current keyboard layout to |layout_name|. This function does not | |
46 // change the current mapping of the modifier keys. Returns true on success. | |
47 virtual bool SetCurrentKeyboardLayoutByName( | |
48 const std::string& layout_name) = 0; | |
49 | |
50 // Sets the current keyboard layout again. We have to call the function every | |
51 // time when "XI_HierarchyChanged" XInput2 event is sent to Chrome. See | |
52 // xinput_hierarchy_changed_event_listener.h for details. | |
53 virtual bool ReapplyCurrentKeyboardLayout() = 0; | |
54 | |
55 // Updates keyboard LEDs on all keyboards. | |
56 // XKB asymmetrically propagates keyboard modifier indicator state changes to | |
57 // slave keyboards. If the state change is initiated from a client to the | |
58 // "core/master keyboard", XKB changes global state and pushes an indication | |
59 // change down to all keyboards. If the state change is initiated by one slave | |
60 // (physical) keyboard, it changes global state but only pushes an indicator | |
61 // state change down to that one keyboard. | |
62 // This function changes LEDs on all keyboards by explicitly updating the | |
63 // core/master keyboard. | |
64 virtual void ReapplyCurrentModifierLockStatus() = 0; | |
65 | |
66 // Sets the Caps Lock and Num Lock status. Do not call the function from | |
67 // non-UI threads. | |
68 virtual void SetLockedModifiers(ModifierLockStatus new_caps_lock_status, | |
69 ModifierLockStatus new_num_lock_status) = 0; | |
70 | |
71 // Sets the num lock status to |enable_num_lock|. Do not call the function | |
72 // from non-UI threads. | |
73 virtual void SetNumLockEnabled(bool enable_num_lock) = 0; | |
74 | |
75 // Sets the caps lock status to |enable_caps_lock|. Do not call the function | |
76 // from non-UI threads. | |
77 virtual void SetCapsLockEnabled(bool enable_caps_lock) = 0; | |
78 | |
79 // Returns true if num lock is enabled. Do not call the function from non-UI | |
80 // threads. | |
81 virtual bool NumLockIsEnabled() = 0; | |
82 | |
83 // Returns true if caps lock is enabled. Do not call the function from non-UI | |
84 // threads. | |
85 virtual bool CapsLockIsEnabled() = 0; | |
86 | |
87 // Returns a mask (e.g. 1U<<4) for Num Lock. On error, returns 0. Do not call | |
88 // the function from non-UI threads. | |
89 // TODO(yusukes): Move this and webdriver::GetXModifierMask() functions in | |
90 // chrome/test/webdriver/keycode_text_conversion_x.cc to ui/base/x/x11_util. | |
91 // The two functions are almost the same. | |
92 virtual unsigned int GetNumLockMask() = 0; | |
93 | |
94 // Set true on |out_caps_lock_enabled| if Caps Lock is enabled. Set true on | |
95 // |out_num_lock_enabled| if Num Lock is enabled. Both out parameters can be | |
96 // NULL. Do not call the function from non-UI threads. | |
97 virtual void GetLockedModifiers(bool* out_caps_lock_enabled, | |
98 bool* out_num_lock_enabled) = 0; | |
99 | |
100 // Turns on and off the auto-repeat of the keyboard. Returns true on success. | |
101 // Do not call the function from non-UI threads. | |
102 // TODO(yusukes): Make this function non-static so we can mock it. | |
103 static bool SetAutoRepeatEnabled(bool enabled); | |
104 | |
105 // Sets the auto-repeat rate of the keyboard, initial delay in ms, and repeat | |
106 // interval in ms. Returns true on success. Do not call the function from | |
107 // non-UI threads. | |
108 // TODO(yusukes): Make this function non-static so we can mock it. | |
109 static bool SetAutoRepeatRate(const AutoRepeatRate& rate); | |
110 | |
111 // Returns true if auto repeat is enabled. This function is protected: for | |
112 // testability. | |
113 static bool GetAutoRepeatEnabledForTesting(); | |
114 | |
115 // On success, set current auto repeat rate on |out_rate| and returns true. | |
116 // Returns false otherwise. This function is protected: for testability. | |
117 static bool GetAutoRepeatRateForTesting(AutoRepeatRate* out_rate); | |
118 | |
119 // Returns false if |layout_name| contains a bad character. | |
120 static bool CheckLayoutNameForTesting(const std::string& layout_name); | |
121 | |
122 // Note: At this moment, classes other than InputMethodManager should not | |
123 // instantiate the XKeyboard class. | |
124 static XKeyboard* Create(); | |
125 }; | |
126 | |
127 } // namespace input_method | |
128 } // namespace chromeos | |
129 | |
130 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_H_ | |
OLD | NEW |