| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 #include "chromeos/ime/ime_keyboard.h" | 6 #include "chromeos/ime/ime_keyboard.h" |
| 7 | 7 |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 #include <cstring> | 9 #include <cstring> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 namespace chromeos { | 32 namespace chromeos { |
| 33 namespace input_method { | 33 namespace input_method { |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 class ImeKeyboardX11 : public ImeKeyboard { | 36 class ImeKeyboardX11 : public ImeKeyboard { |
| 37 public: | 37 public: |
| 38 ImeKeyboardX11(); | 38 ImeKeyboardX11(); |
| 39 virtual ~ImeKeyboardX11(); | 39 virtual ~ImeKeyboardX11(); |
| 40 | 40 |
| 41 // Adds/removes observer. |
| 42 virtual void AddObserver(Observer* observer) override; |
| 43 virtual void RemoveObserver(Observer* observer) override; |
| 44 |
| 41 // ImeKeyboard: | 45 // ImeKeyboard: |
| 42 virtual bool SetCurrentKeyboardLayoutByName( | 46 virtual bool SetCurrentKeyboardLayoutByName( |
| 43 const std::string& layout_name) override; | 47 const std::string& layout_name) override; |
| 44 virtual bool ReapplyCurrentKeyboardLayout() override; | 48 virtual bool ReapplyCurrentKeyboardLayout() override; |
| 45 virtual void ReapplyCurrentModifierLockStatus() override; | 49 virtual void ReapplyCurrentModifierLockStatus() override; |
| 46 virtual void DisableNumLock() override; | 50 virtual void DisableNumLock() override; |
| 47 virtual void SetCapsLockEnabled(bool enable_caps_lock) override; | 51 virtual void SetCapsLockEnabled(bool enable_caps_lock) override; |
| 48 virtual bool CapsLockIsEnabled() override; | 52 virtual bool CapsLockIsEnabled() override; |
| 53 virtual bool IsISOLevel5ShiftAvailable() const override; |
| 54 virtual bool IsAltGrAvailable() const override; |
| 49 virtual bool SetAutoRepeatEnabled(bool enabled) override; | 55 virtual bool SetAutoRepeatEnabled(bool enabled) override; |
| 50 virtual bool SetAutoRepeatRate(const AutoRepeatRate& rate) override; | 56 virtual bool SetAutoRepeatRate(const AutoRepeatRate& rate) override; |
| 51 | 57 |
| 52 private: | 58 private: |
| 53 // Returns a mask for Num Lock (e.g. 1U << 4). Returns 0 on error. | 59 // Returns a mask for Num Lock (e.g. 1U << 4). Returns 0 on error. |
| 54 unsigned int GetNumLockMask(); | 60 unsigned int GetNumLockMask(); |
| 55 | 61 |
| 56 // Sets the caps-lock status. Note that calling this function always disables | 62 // Sets the caps-lock status. Note that calling this function always disables |
| 57 // the num-lock. | 63 // the num-lock. |
| 58 void SetLockedModifiers(bool caps_lock_enabled); | 64 void SetLockedModifiers(bool caps_lock_enabled); |
| 59 | 65 |
| 60 // This function is used by SetLayout() and RemapModifierKeys(). Calls | 66 // This function is used by SetLayout() and RemapModifierKeys(). Calls |
| 61 // setxkbmap command if needed, and updates the last_full_layout_name_ cache. | 67 // setxkbmap command if needed, and updates the last_full_layout_name_ cache. |
| 62 bool SetLayoutInternal(const std::string& layout_name, bool force); | 68 bool SetLayoutInternal(const std::string& layout_name, bool force); |
| 63 | 69 |
| 64 // Executes 'setxkbmap -layout ...' command asynchronously using a layout name | 70 // Executes 'setxkbmap -layout ...' command asynchronously using a layout name |
| 65 // in the |execute_queue_|. Do nothing if the queue is empty. | 71 // in the |execute_queue_|. Do nothing if the queue is empty. |
| 66 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105) | 72 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105) |
| 67 void MaybeExecuteSetLayoutCommand(); | 73 void MaybeExecuteSetLayoutCommand(); |
| 68 | 74 |
| 69 // Polls to see setxkbmap process exits. | 75 // Polls to see setxkbmap process exits. |
| 70 void PollUntilChildFinish(const base::ProcessHandle handle); | 76 void PollUntilChildFinish(const base::ProcessHandle handle); |
| 71 | 77 |
| 72 // Called when execve'd setxkbmap process exits. | 78 // Called when execve'd setxkbmap process exits. |
| 73 void OnSetLayoutFinish(); | 79 void OnSetLayoutFinish(); |
| 74 | 80 |
| 75 const bool is_running_on_chrome_os_; | 81 const bool is_running_on_chrome_os_; |
| 76 unsigned int num_lock_mask_; | 82 unsigned int num_lock_mask_; |
| 77 | 83 |
| 84 // The current Caps Lock status. If true, enabled. |
| 85 bool current_caps_lock_status_; |
| 86 |
| 87 // The XKB layout name which we set last time like "us" and "us(dvorak)". |
| 88 std::string current_layout_name_; |
| 89 |
| 78 // A queue for executing setxkbmap one by one. | 90 // A queue for executing setxkbmap one by one. |
| 79 std::queue<std::string> execute_queue_; | 91 std::queue<std::string> execute_queue_; |
| 80 | 92 |
| 81 base::ThreadChecker thread_checker_; | 93 base::ThreadChecker thread_checker_; |
| 82 | 94 |
| 83 base::WeakPtrFactory<ImeKeyboardX11> weak_factory_; | 95 base::WeakPtrFactory<ImeKeyboardX11> weak_factory_; |
| 84 | 96 |
| 97 ObserverList<Observer> observers_; |
| 98 |
| 85 DISALLOW_COPY_AND_ASSIGN(ImeKeyboardX11); | 99 DISALLOW_COPY_AND_ASSIGN(ImeKeyboardX11); |
| 86 }; | 100 }; |
| 87 | 101 |
| 88 | 102 |
| 89 } // namespace | 103 } // namespace |
| 90 | 104 |
| 91 } // namespace input_method | 105 } // namespace input_method |
| 92 } // namespace chromeos | 106 } // namespace chromeos |
| 93 | 107 |
| OLD | NEW |