Home | History | Annotate | Download | only in ime
      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   kEscapeKey,
     36   // IMPORTANT: You should update kCustomizableKeys[] in .cc file, if you
     37   // add a customizable key.
     38   kNumModifierKeys,
     39 };
     40 
     41 class InputMethodUtil;
     42 
     43 class CHROMEOS_EXPORT XKeyboard {
     44  public:
     45   virtual ~XKeyboard() {}
     46 
     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;
     51 
     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;
     56 
     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;
     67 
     68   // Sets the Caps Lock and Num Lock status. Do not call the function from
     69   // non-UI threads.
     70   virtual void SetLockedModifiers(ModifierLockStatus new_caps_lock_status,
     71                                   ModifierLockStatus new_num_lock_status) = 0;
     72 
     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;
     76 
     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;
     80 
     81   // Returns true if num lock is enabled. Do not call the function from non-UI
     82   // threads.
     83   virtual bool NumLockIsEnabled() = 0;
     84 
     85   // Returns true if caps lock is enabled. Do not call the function from non-UI
     86   // threads.
     87   virtual bool CapsLockIsEnabled() = 0;
     88 
     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;
     95 
     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;
    101 
    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   // TODO(yusukes): Make this function non-static so we can mock it.
    105   static CHROMEOS_EXPORT bool SetAutoRepeatEnabled(bool enabled);
    106 
    107   // Sets the auto-repeat rate of the keyboard, initial delay in ms, and repeat
    108   // interval in ms.  Returns true on success. Do not call the function from
    109   // non-UI threads.
    110   // TODO(yusukes): Make this function non-static so we can mock it.
    111   static CHROMEOS_EXPORT bool SetAutoRepeatRate(const AutoRepeatRate& rate);
    112 
    113   // Returns true if auto repeat is enabled. This function is protected: for
    114   // testability.
    115   static CHROMEOS_EXPORT bool GetAutoRepeatEnabledForTesting();
    116 
    117   // On success, set current auto repeat rate on |out_rate| and returns true.
    118   // Returns false otherwise. This function is protected: for testability.
    119   static CHROMEOS_EXPORT bool GetAutoRepeatRateForTesting(
    120       AutoRepeatRate* out_rate);
    121 
    122   // Returns false if |layout_name| contains a bad character.
    123   static CHROMEOS_EXPORT bool CheckLayoutNameForTesting(
    124       const std::string& layout_name);
    125 
    126   // Note: At this moment, classes other than InputMethodManager should not
    127   // instantiate the XKeyboard class.
    128   static XKeyboard* Create();
    129 };
    130 
    131 }  // namespace input_method
    132 }  // namespace chromeos
    133 
    134 #endif  // CHROMEOS_IME_XKEYBOARD_H_
    135