Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: chromeos/ime/ime_keyboard_x11.cc

Issue 666693010: Separate ime_keyboard_x11.h from cc file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/ime/ime_keyboard_x11.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chromeos/ime/ime_keyboard.h" 5 #include "chromeos/ime/ime_keyboard_x11.h"
6
7 #include <cstdlib>
8 #include <cstring>
9 #include <queue>
10 #include <set>
11 #include <utility>
12
13 #include "base/bind.h"
14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/process/kill.h"
18 #include "base/process/launch.h"
19 #include "base/process/process_handle.h"
20 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h"
22 #include "base/sys_info.h"
23 #include "base/threading/thread_checker.h"
24 #include "ui/gfx/x/x11_types.h"
25
26 // These includes conflict with base/tracked_objects.h so must come last.
27 #include <X11/XKBlib.h>
28 #include <X11/Xlib.h>
29 6
30 namespace chromeos { 7 namespace chromeos {
31 namespace input_method { 8 namespace input_method {
32 namespace { 9 namespace {
33 10
34 // The delay in milliseconds that we'll wait between checking if 11 // The delay in milliseconds that we'll wait between checking if
35 // setxkbmap command finished. 12 // setxkbmap command finished.
36 const int kSetLayoutCommandCheckDelayMs = 100; 13 const int kSetLayoutCommandCheckDelayMs = 100;
37 14
38 // The command we use to set the current XKB layout and modifier key mapping. 15 // The command we use to set the current XKB layout and modifier key mapping.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 79
103 if (layout_name.find_first_not_of(kValidLayoutNameCharacters) != 80 if (layout_name.find_first_not_of(kValidLayoutNameCharacters) !=
104 std::string::npos) { 81 std::string::npos) {
105 DVLOG(1) << "Invalid layout_name: " << layout_name; 82 DVLOG(1) << "Invalid layout_name: " << layout_name;
106 return false; 83 return false;
107 } 84 }
108 85
109 return true; 86 return true;
110 } 87 }
111 88
112 class ImeKeyboardX11 : public ImeKeyboard {
113 public:
114 ImeKeyboardX11();
115 virtual ~ImeKeyboardX11() {}
116
117 // Adds/removes observer.
118 virtual void AddObserver(Observer* observer) override;
119 virtual void RemoveObserver(Observer* observer) override;
120
121 // ImeKeyboard:
122 virtual bool SetCurrentKeyboardLayoutByName(
123 const std::string& layout_name) override;
124 virtual bool ReapplyCurrentKeyboardLayout() override;
125 virtual void ReapplyCurrentModifierLockStatus() override;
126 virtual void DisableNumLock() override;
127 virtual void SetCapsLockEnabled(bool enable_caps_lock) override;
128 virtual bool CapsLockIsEnabled() override;
129 virtual bool IsISOLevel5ShiftAvailable() const override;
130 virtual bool IsAltGrAvailable() const override;
131 virtual bool SetAutoRepeatEnabled(bool enabled) override;
132 virtual bool SetAutoRepeatRate(const AutoRepeatRate& rate) override;
133
134 private:
135 // Returns a mask for Num Lock (e.g. 1U << 4). Returns 0 on error.
136 unsigned int GetNumLockMask();
137
138 // Sets the caps-lock status. Note that calling this function always disables
139 // the num-lock.
140 void SetLockedModifiers(bool caps_lock_enabled);
141
142 // This function is used by SetLayout() and RemapModifierKeys(). Calls
143 // setxkbmap command if needed, and updates the last_full_layout_name_ cache.
144 bool SetLayoutInternal(const std::string& layout_name, bool force);
145
146 // Executes 'setxkbmap -layout ...' command asynchronously using a layout name
147 // in the |execute_queue_|. Do nothing if the queue is empty.
148 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105)
149 void MaybeExecuteSetLayoutCommand();
150
151 // Polls to see setxkbmap process exits.
152 void PollUntilChildFinish(const base::ProcessHandle handle);
153
154 // Called when execve'd setxkbmap process exits.
155 void OnSetLayoutFinish();
156
157 const bool is_running_on_chrome_os_;
158 unsigned int num_lock_mask_;
159
160 // The current Caps Lock status. If true, enabled.
161 bool current_caps_lock_status_;
162
163 // The XKB layout name which we set last time like "us" and "us(dvorak)".
164 std::string current_layout_name_;
165
166 // A queue for executing setxkbmap one by one.
167 std::queue<std::string> execute_queue_;
168
169 base::ThreadChecker thread_checker_;
170
171 base::WeakPtrFactory<ImeKeyboardX11> weak_factory_;
172
173 ObserverList<Observer> observers_;
174
175 DISALLOW_COPY_AND_ASSIGN(ImeKeyboardX11);
176 };
177
178 ImeKeyboardX11::ImeKeyboardX11() 89 ImeKeyboardX11::ImeKeyboardX11()
179 : is_running_on_chrome_os_(base::SysInfo::IsRunningOnChromeOS()), 90 : is_running_on_chrome_os_(base::SysInfo::IsRunningOnChromeOS()),
180 weak_factory_(this) { 91 weak_factory_(this) {
181 // X must be already initialized. 92 // X must be already initialized.
182 CHECK(gfx::GetXDisplay()); 93 CHECK(gfx::GetXDisplay());
183 94
184 num_lock_mask_ = GetNumLockMask(); 95 num_lock_mask_ = GetNumLockMask();
185 96
186 if (is_running_on_chrome_os_) { 97 if (is_running_on_chrome_os_) {
187 // Some code seems to assume that Mod2Mask is always assigned to 98 // Some code seems to assume that Mod2Mask is always assigned to
188 // Num Lock. 99 // Num Lock.
189 // 100 //
190 // TODO(yusukes): Check the assumption is really okay. If not, 101 // TODO(yusukes): Check the assumption is really okay. If not,
191 // modify the Aura code, and then remove the CHECK below. 102 // modify the Aura code, and then remove the CHECK below.
192 LOG_IF(ERROR, num_lock_mask_ != Mod2Mask) 103 LOG_IF(ERROR, num_lock_mask_ != Mod2Mask)
193 << "NumLock is not assigned to Mod2Mask. : " << num_lock_mask_; 104 << "NumLock is not assigned to Mod2Mask. : " << num_lock_mask_;
194 } 105 }
195 106
196 current_caps_lock_status_ = CapsLockIsEnabled(); 107 current_caps_lock_status_ = CapsLockIsEnabled();
197 // Disable Num Lock on X start up for http://crosbug.com/29169. 108 // Disable Num Lock on X start up for http://crosbug.com/29169.
198 DisableNumLock(); 109 DisableNumLock();
199 } 110 }
200 111
112 ImeKeyboardX11::~ImeKeyboardX11() {};
113
201 void ImeKeyboardX11::AddObserver(Observer* observer) { 114 void ImeKeyboardX11::AddObserver(Observer* observer) {
202 observers_.AddObserver(observer); 115 observers_.AddObserver(observer);
203 } 116 }
204 117
205 void ImeKeyboardX11::RemoveObserver(Observer* observer) { 118 void ImeKeyboardX11::RemoveObserver(Observer* observer) {
206 observers_.RemoveObserver(observer); 119 observers_.RemoveObserver(observer);
207 } 120 }
208 121
209 unsigned int ImeKeyboardX11::GetNumLockMask() { 122 unsigned int ImeKeyboardX11::GetNumLockMask() {
210 DCHECK(thread_checker_.CalledOnValidThread()); 123 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 // static 367 // static
455 bool ImeKeyboard::CheckLayoutNameForTesting(const std::string& layout_name) { 368 bool ImeKeyboard::CheckLayoutNameForTesting(const std::string& layout_name) {
456 return CheckLayoutName(layout_name); 369 return CheckLayoutName(layout_name);
457 } 370 }
458 371
459 // static 372 // static
460 ImeKeyboard* ImeKeyboard::Create() { return new ImeKeyboardX11(); } 373 ImeKeyboard* ImeKeyboard::Create() { return new ImeKeyboardX11(); }
461 374
462 } // namespace input_method 375 } // namespace input_method
463 } // namespace chromeos 376 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/ime/ime_keyboard_x11.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698