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