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.
5 #ifndef UI_BASE_IME_CHROMEOS_IME_KEYBOARD_H_
6 #define UI_BASE_IME_CHROMEOS_IME_KEYBOARD_H_
11 #include "base/basictypes.h"
12 #include "base/observer_list.h"
13 #include "ui/base/ime/ui_base_ime_export.h"
16 namespace input_method
{
18 struct AutoRepeatRate
{
19 AutoRepeatRate() : initial_delay_in_ms(0), repeat_interval_in_ms(0) {}
20 unsigned int initial_delay_in_ms
;
21 unsigned int repeat_interval_in_ms
;
25 kSearchKey
= 0, // Customizable.
26 kControlKey
, // Customizable.
27 kAltKey
, // Customizable.
31 // IMPORTANT: You should update kCustomizableKeys[] in .cc file, if you
32 // add a customizable key.
36 class InputMethodUtil
;
38 class UI_BASE_IME_EXPORT ImeKeyboard
{
42 // Called when the caps lock state has changed.
43 virtual void OnCapsLockChanged(bool enabled
) = 0;
47 virtual ~ImeKeyboard();
48 // Adds/removes observer.
49 virtual void AddObserver(Observer
* observer
);
50 virtual void RemoveObserver(Observer
* observer
);
52 // Sets the current keyboard layout to |layout_name|. This function does not
53 // change the current mapping of the modifier keys. Returns true on success.
54 virtual bool SetCurrentKeyboardLayoutByName(
55 const std::string
& layout_name
) = 0;
57 // Sets the current keyboard layout again. We have to call the function every
58 // time when "XI_HierarchyChanged" XInput2 event is sent to Chrome. See
59 // xinput_hierarchy_changed_event_listener.h for details.
60 virtual bool ReapplyCurrentKeyboardLayout() = 0;
62 // Updates keyboard LEDs on all keyboards.
63 // XKB asymmetrically propagates keyboard modifier indicator state changes to
64 // slave keyboards. If the state change is initiated from a client to the
65 // "core/master keyboard", XKB changes global state and pushes an indication
66 // change down to all keyboards. If the state change is initiated by one slave
67 // (physical) keyboard, it changes global state but only pushes an indicator
68 // state change down to that one keyboard.
69 // This function changes LEDs on all keyboards by explicitly updating the
70 // core/master keyboard.
71 virtual void ReapplyCurrentModifierLockStatus() = 0;
73 // Disables the num lock.
74 virtual void DisableNumLock() = 0;
76 // Sets the caps lock status to |enable_caps_lock|. Do not call the function
77 // from non-UI threads.
78 virtual void SetCapsLockEnabled(bool enable_caps_lock
);
80 // Returns true if caps lock is enabled. Do not call the function from non-UI
82 virtual bool CapsLockIsEnabled();
84 // Returns true if the current layout supports ISO Level 5 shift.
85 virtual bool IsISOLevel5ShiftAvailable() const;
87 // Returns true if the current layout supports alt gr.
88 virtual bool IsAltGrAvailable() const;
90 // Turns on and off the auto-repeat of the keyboard. Returns true on success.
91 // Do not call the function from non-UI threads.
92 virtual bool SetAutoRepeatEnabled(bool enabled
) = 0;
94 // Returns true if auto-repeat is enabled.
95 virtual bool GetAutoRepeatEnabled() = 0;
97 // Sets the auto-repeat rate of the keyboard, initial delay in ms, and repeat
98 // interval in ms. Returns true on success. Do not call the function from
100 virtual bool SetAutoRepeatRate(const AutoRepeatRate
& rate
) = 0;
102 // On success, set current auto repeat rate on |out_rate| and returns true.
103 // Returns false otherwise. This function is protected: for testability.
104 static UI_BASE_IME_EXPORT
bool GetAutoRepeatRateForTesting(
105 AutoRepeatRate
* out_rate
);
107 // Returns false if |layout_name| contains a bad character.
108 static UI_BASE_IME_EXPORT
bool CheckLayoutNameForTesting(
109 const std::string
& layout_name
);
111 // Note: At this moment, classes other than InputMethodManager should not
112 // instantiate the ImeKeyboard class.
113 static UI_BASE_IME_EXPORT ImeKeyboard
* Create();
115 bool caps_lock_is_enabled_
;
116 std::string last_layout_
;
119 base::ObserverList
<Observer
> observers_
;
122 } // namespace input_method
123 } // namespace chromeos
125 #endif // UI_BASE_IME_CHROMEOS_IME_KEYBOARD_H_