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

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

Issue 683773002: Adds ozone support for ime keyboard. (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
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_x11.h" 5 #include "chromeos/ime/ime_keyboard_x11.h"
6 6
7 namespace chromeos { 7 namespace chromeos {
8 namespace input_method { 8 namespace input_method {
9 namespace { 9 namespace {
10 10
11 // The delay in milliseconds that we'll wait between checking if 11 // The delay in milliseconds that we'll wait between checking if
12 // setxkbmap command finished. 12 // setxkbmap command finished.
13 const int kSetLayoutCommandCheckDelayMs = 100; 13 const int kSetLayoutCommandCheckDelayMs = 100;
14 14
15 // 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.
16 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105) 16 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105)
17 const char kSetxkbmapCommand[] = "/usr/bin/setxkbmap"; 17 const char kSetxkbmapCommand[] = "/usr/bin/setxkbmap";
18 18
19 // A string for obtaining a mask value for Num Lock. 19 // A string for obtaining a mask value for Num Lock.
20 const char kNumLockVirtualModifierString[] = "NumLock"; 20 const char kNumLockVirtualModifierString[] = "NumLock";
21 21
22 const char *kISOLevel5ShiftLayoutIds[] = {
23 "ca(multix)",
24 "de(neo)",
25 };
26
27 const char *kAltGrLayoutIds[] = {
28 "be",
29 "be",
30 "be",
31 "bg",
32 "bg(phonetic)",
33 "br",
34 "ca",
35 "ca(eng)",
36 "ca(multix)",
37 "ch",
38 "ch(fr)",
39 "cz",
40 "de",
41 "de(neo)",
42 "dk",
43 "ee",
44 "es",
45 "es(cat)",
46 "fi",
47 "fr",
48 "gb(dvorak)",
49 "gb(extd)",
50 "gr",
51 "hr",
52 "il",
53 "it",
54 "latam",
55 "lt",
56 "no",
57 "pl",
58 "pt",
59 "ro",
60 "se",
61 "si",
62 "sk",
63 "tr",
64 "ua",
65 "us(altgr-intl)",
66 "us(intl)",
67 };
68
69
70 // Returns false if |layout_name| contains a bad character. 22 // Returns false if |layout_name| contains a bad character.
71 bool CheckLayoutName(const std::string& layout_name) { 23 bool CheckLayoutName(const std::string& layout_name) {
72 static const char kValidLayoutNameCharacters[] = 24 static const char kValidLayoutNameCharacters[] =
73 "abcdefghijklmnopqrstuvwxyz0123456789()-_"; 25 "abcdefghijklmnopqrstuvwxyz0123456789()-_";
74 26
75 if (layout_name.empty()) { 27 if (layout_name.empty()) {
76 DVLOG(1) << "Invalid layout_name: " << layout_name; 28 DVLOG(1) << "Invalid layout_name: " << layout_name;
77 return false; 29 return false;
78 } 30 }
79 31
(...skipping 17 matching lines...) Expand all
97 if (is_running_on_chrome_os_) { 49 if (is_running_on_chrome_os_) {
98 // Some code seems to assume that Mod2Mask is always assigned to 50 // Some code seems to assume that Mod2Mask is always assigned to
99 // Num Lock. 51 // Num Lock.
100 // 52 //
101 // TODO(yusukes): Check the assumption is really okay. If not, 53 // TODO(yusukes): Check the assumption is really okay. If not,
102 // modify the Aura code, and then remove the CHECK below. 54 // modify the Aura code, and then remove the CHECK below.
103 LOG_IF(ERROR, num_lock_mask_ != Mod2Mask) 55 LOG_IF(ERROR, num_lock_mask_ != Mod2Mask)
104 << "NumLock is not assigned to Mod2Mask. : " << num_lock_mask_; 56 << "NumLock is not assigned to Mod2Mask. : " << num_lock_mask_;
105 } 57 }
106 58
107 current_caps_lock_status_ = CapsLockIsEnabled(); 59 caps_lock_is_enabled_ = CapsLockIsEnabled();
108 // Disable Num Lock on X start up for http://crosbug.com/29169. 60 // Disable Num Lock on X start up for http://crosbug.com/29169.
109 DisableNumLock(); 61 DisableNumLock();
110 } 62 }
111 63
112 ImeKeyboardX11::~ImeKeyboardX11() {}; 64 ImeKeyboardX11::~ImeKeyboardX11() {};
113 65
114 void ImeKeyboardX11::AddObserver(Observer* observer) {
115 observers_.AddObserver(observer);
116 }
117
118 void ImeKeyboardX11::RemoveObserver(Observer* observer) {
119 observers_.RemoveObserver(observer);
120 }
121
122 unsigned int ImeKeyboardX11::GetNumLockMask() { 66 unsigned int ImeKeyboardX11::GetNumLockMask() {
123 DCHECK(thread_checker_.CalledOnValidThread()); 67 DCHECK(thread_checker_.CalledOnValidThread());
124 static const unsigned int kBadMask = 0; 68 static const unsigned int kBadMask = 0;
125 69
126 unsigned int real_mask = kBadMask; 70 unsigned int real_mask = kBadMask;
127 XkbDescPtr xkb_desc = 71 XkbDescPtr xkb_desc =
128 XkbGetKeyboard(gfx::GetXDisplay(), XkbAllComponentsMask, XkbUseCoreKbd); 72 XkbGetKeyboard(gfx::GetXDisplay(), XkbAllComponentsMask, XkbUseCoreKbd);
129 if (!xkb_desc) 73 if (!xkb_desc)
130 return kBadMask; 74 return kBadMask;
131 75
(...skipping 23 matching lines...) Expand all
155 99
156 void ImeKeyboardX11::SetLockedModifiers(bool caps_lock_enabled) { 100 void ImeKeyboardX11::SetLockedModifiers(bool caps_lock_enabled) {
157 DCHECK(thread_checker_.CalledOnValidThread()); 101 DCHECK(thread_checker_.CalledOnValidThread());
158 102
159 // Always turn off num lock. 103 // Always turn off num lock.
160 unsigned int affect_mask = num_lock_mask_; 104 unsigned int affect_mask = num_lock_mask_;
161 unsigned int value_mask = 0; 105 unsigned int value_mask = 0;
162 106
163 affect_mask |= LockMask; 107 affect_mask |= LockMask;
164 value_mask |= (caps_lock_enabled ? LockMask : 0); 108 value_mask |= (caps_lock_enabled ? LockMask : 0);
165 current_caps_lock_status_ = caps_lock_enabled; 109 caps_lock_is_enabled_ = caps_lock_enabled;
166 110
167 XkbLockModifiers(gfx::GetXDisplay(), XkbUseCoreKbd, affect_mask, value_mask); 111 XkbLockModifiers(gfx::GetXDisplay(), XkbUseCoreKbd, affect_mask, value_mask);
168 } 112 }
169 113
170 bool ImeKeyboardX11::SetLayoutInternal(const std::string& layout_name, 114 bool ImeKeyboardX11::SetLayoutInternal(const std::string& layout_name,
171 bool force) { 115 bool force) {
172 if (!is_running_on_chrome_os_) { 116 if (!is_running_on_chrome_os_) {
173 // We should not try to change a layout on Linux or inside ui_tests. Just 117 // We should not try to change a layout on Linux or inside ui_tests. Just
174 // return true. 118 // return true.
175 return true; 119 return true;
176 } 120 }
177 121
178 if (!CheckLayoutName(layout_name)) 122 if (!CheckLayoutName(layout_name))
179 return false; 123 return false;
180 124
181 if (!force && (current_layout_name_ == layout_name)) { 125 if (!force && (last_layout_ == layout_name)) {
182 DVLOG(1) << "The requested layout is already set: " << layout_name; 126 DVLOG(1) << "The requested layout is already set: " << layout_name;
183 return true; 127 return true;
184 } 128 }
185 129
186 DVLOG(1) << (force ? "Reapply" : "Set") << " layout: " << layout_name; 130 DVLOG(1) << (force ? "Reapply" : "Set") << " layout: " << layout_name;
187 131
188 const bool start_execution = execute_queue_.empty(); 132 const bool start_execution = execute_queue_.empty();
189 // If no setxkbmap command is in flight (i.e. start_execution is true), 133 // If no setxkbmap command is in flight (i.e. start_execution is true),
190 // start the first one by explicitly calling MaybeExecuteSetLayoutCommand(). 134 // start the first one by explicitly calling MaybeExecuteSetLayoutCommand().
191 // If one or more setxkbmap commands are already in flight, just push the 135 // If one or more setxkbmap commands are already in flight, just push the
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 202 }
259 } 203 }
260 204
261 bool ImeKeyboardX11::CapsLockIsEnabled() { 205 bool ImeKeyboardX11::CapsLockIsEnabled() {
262 DCHECK(thread_checker_.CalledOnValidThread()); 206 DCHECK(thread_checker_.CalledOnValidThread());
263 XkbStateRec status; 207 XkbStateRec status;
264 XkbGetState(gfx::GetXDisplay(), XkbUseCoreKbd, &status); 208 XkbGetState(gfx::GetXDisplay(), XkbUseCoreKbd, &status);
265 return (status.locked_mods & LockMask); 209 return (status.locked_mods & LockMask);
266 } 210 }
267 211
268 bool ImeKeyboardX11::IsISOLevel5ShiftAvailable() const {
269 for (size_t i = 0; i < arraysize(kISOLevel5ShiftLayoutIds); ++i) {
270 if (current_layout_name_ == kISOLevel5ShiftLayoutIds[i])
271 return true;
272 }
273 return false;
274 }
275
276 bool ImeKeyboardX11::IsAltGrAvailable() const {
277 for (size_t i = 0; i < arraysize(kAltGrLayoutIds); ++i) {
278 if (current_layout_name_ == kAltGrLayoutIds[i])
279 return true;
280 }
281 return false;
282 }
283
284 bool ImeKeyboardX11::SetAutoRepeatEnabled(bool enabled) { 212 bool ImeKeyboardX11::SetAutoRepeatEnabled(bool enabled) {
285 if (enabled) 213 if (enabled)
286 XAutoRepeatOn(gfx::GetXDisplay()); 214 XAutoRepeatOn(gfx::GetXDisplay());
287 else 215 else
288 XAutoRepeatOff(gfx::GetXDisplay()); 216 XAutoRepeatOff(gfx::GetXDisplay());
289 DVLOG(1) << "Set auto-repeat mode to: " << (enabled ? "on" : "off"); 217 DVLOG(1) << "Set auto-repeat mode to: " << (enabled ? "on" : "off");
290 return true; 218 return true;
291 } 219 }
292 220
293 bool ImeKeyboardX11::SetAutoRepeatRate(const AutoRepeatRate& rate) { 221 bool ImeKeyboardX11::SetAutoRepeatRate(const AutoRepeatRate& rate) {
294 DVLOG(1) << "Set auto-repeat rate to: " 222 DVLOG(1) << "Set auto-repeat rate to: "
295 << rate.initial_delay_in_ms << " ms delay, " 223 << rate.initial_delay_in_ms << " ms delay, "
296 << rate.repeat_interval_in_ms << " ms interval"; 224 << rate.repeat_interval_in_ms << " ms interval";
297 if (XkbSetAutoRepeatRate(gfx::GetXDisplay(), XkbUseCoreKbd, 225 if (XkbSetAutoRepeatRate(gfx::GetXDisplay(), XkbUseCoreKbd,
298 rate.initial_delay_in_ms, 226 rate.initial_delay_in_ms,
299 rate.repeat_interval_in_ms) != True) { 227 rate.repeat_interval_in_ms) != True) {
300 DVLOG(1) << "Failed to set auto-repeat rate"; 228 DVLOG(1) << "Failed to set auto-repeat rate";
301 return false; 229 return false;
302 } 230 }
303 return true; 231 return true;
304 } 232 }
305 233
306 void ImeKeyboardX11::SetCapsLockEnabled(bool enable_caps_lock) { 234 void ImeKeyboardX11::SetCapsLockEnabled(bool enable_caps_lock) {
307 bool old_state = current_caps_lock_status_;
308 SetLockedModifiers(enable_caps_lock); 235 SetLockedModifiers(enable_caps_lock);
309 if (old_state != enable_caps_lock) { 236 ImeKeyboard::SetCapsLockEnabled(enable_caps_lock);
310 FOR_EACH_OBSERVER(ImeKeyboard::Observer, observers_,
311 OnCapsLockChanged(enable_caps_lock));
312 }
313 } 237 }
314 238
315 bool ImeKeyboardX11::SetCurrentKeyboardLayoutByName( 239 bool ImeKeyboardX11::SetCurrentKeyboardLayoutByName(
316 const std::string& layout_name) { 240 const std::string& layout_name) {
317 if (SetLayoutInternal(layout_name, false)) { 241 if (SetLayoutInternal(layout_name, false)) {
318 current_layout_name_ = layout_name; 242 last_layout_ = layout_name;
319 return true; 243 return true;
320 } 244 }
321 return false; 245 return false;
322 } 246 }
323 247
324 bool ImeKeyboardX11::ReapplyCurrentKeyboardLayout() { 248 bool ImeKeyboardX11::ReapplyCurrentKeyboardLayout() {
325 if (current_layout_name_.empty()) { 249 if (last_layout_.empty()) {
326 DVLOG(1) << "Can't reapply XKB layout: layout unknown"; 250 DVLOG(1) << "Can't reapply XKB layout: layout unknown";
327 return false; 251 return false;
328 } 252 }
329 return SetLayoutInternal(current_layout_name_, true /* force */); 253 return SetLayoutInternal(last_layout_, true /* force */);
330 } 254 }
331 255
332 void ImeKeyboardX11::ReapplyCurrentModifierLockStatus() { 256 void ImeKeyboardX11::ReapplyCurrentModifierLockStatus() {
333 SetLockedModifiers(current_caps_lock_status_); 257 SetLockedModifiers(caps_lock_is_enabled_);
334 } 258 }
335 259
336 void ImeKeyboardX11::DisableNumLock() { 260 void ImeKeyboardX11::DisableNumLock() {
337 SetCapsLockEnabled(current_caps_lock_status_); 261 SetCapsLockEnabled(caps_lock_is_enabled_);
338 } 262 }
339 263
340 void ImeKeyboardX11::OnSetLayoutFinish() { 264 void ImeKeyboardX11::OnSetLayoutFinish() {
341 if (execute_queue_.empty()) { 265 if (execute_queue_.empty()) {
342 DVLOG(1) << "OnSetLayoutFinish: execute_queue_ is empty. " 266 DVLOG(1) << "OnSetLayoutFinish: execute_queue_ is empty. "
343 << "base::LaunchProcess failed?"; 267 << "base::LaunchProcess failed?";
344 return; 268 return;
345 } 269 }
346 execute_queue_.pop(); 270 execute_queue_.pop();
347 MaybeExecuteSetLayoutCommand(); 271 MaybeExecuteSetLayoutCommand();
(...skipping 19 matching lines...) Expand all
367 // static 291 // static
368 bool ImeKeyboard::CheckLayoutNameForTesting(const std::string& layout_name) { 292 bool ImeKeyboard::CheckLayoutNameForTesting(const std::string& layout_name) {
369 return CheckLayoutName(layout_name); 293 return CheckLayoutName(layout_name);
370 } 294 }
371 295
372 // static 296 // static
373 ImeKeyboard* ImeKeyboard::Create() { return new ImeKeyboardX11(); } 297 ImeKeyboard* ImeKeyboard::Create() { return new ImeKeyboardX11(); }
374 298
375 } // namespace input_method 299 } // namespace input_method
376 } // namespace chromeos 300 } // namespace chromeos
OLDNEW
« chromeos/ime/fake_ime_keyboard.cc ('K') | « chromeos/ime/ime_keyboard_x11.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698