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