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

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

Issue 231753002: Fixing caps lock problems under ChromeOS where the tray does not properly follow the real caps lock… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed & fixed linux desktop Created 6 years, 8 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/xkeyboard.h" 5 #include "chromeos/ime/xkeyboard.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 #include <cstring> 8 #include <cstring>
9 #include <queue> 9 #include <queue>
10 #include <set> 10 #include <set>
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 110 }
111 111
112 return true; 112 return true;
113 } 113 }
114 114
115 class XKeyboardImpl : public XKeyboard { 115 class XKeyboardImpl : public XKeyboard {
116 public: 116 public:
117 XKeyboardImpl(); 117 XKeyboardImpl();
118 virtual ~XKeyboardImpl() {} 118 virtual ~XKeyboardImpl() {}
119 119
120 // Adds/removes observer.
121 virtual void AddObserver(Observer* observer) OVERRIDE;
122 virtual void RemoveObserver(Observer* observer) OVERRIDE;
123
120 // Overridden from XKeyboard: 124 // Overridden from XKeyboard:
121 virtual bool SetCurrentKeyboardLayoutByName( 125 virtual bool SetCurrentKeyboardLayoutByName(
122 const std::string& layout_name) OVERRIDE; 126 const std::string& layout_name) OVERRIDE;
123 virtual bool ReapplyCurrentKeyboardLayout() OVERRIDE; 127 virtual bool ReapplyCurrentKeyboardLayout() OVERRIDE;
124 virtual void ReapplyCurrentModifierLockStatus() OVERRIDE; 128 virtual void ReapplyCurrentModifierLockStatus() OVERRIDE;
125 virtual void DisableNumLock() OVERRIDE; 129 virtual void DisableNumLock() OVERRIDE;
126 virtual void SetCapsLockEnabled(bool enable_caps_lock) OVERRIDE; 130 virtual void SetCapsLockEnabled(bool enable_caps_lock) OVERRIDE;
127 virtual bool CapsLockIsEnabled() OVERRIDE; 131 virtual bool CapsLockIsEnabled() OVERRIDE;
128 virtual bool IsISOLevel5ShiftAvailable() const OVERRIDE; 132 virtual bool IsISOLevel5ShiftAvailable() const OVERRIDE;
129 virtual bool IsAltGrAvailable() const OVERRIDE; 133 virtual bool IsAltGrAvailable() const OVERRIDE;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // The XKB layout name which we set last time like "us" and "us(dvorak)". 166 // The XKB layout name which we set last time like "us" and "us(dvorak)".
163 std::string current_layout_name_; 167 std::string current_layout_name_;
164 168
165 // A queue for executing setxkbmap one by one. 169 // A queue for executing setxkbmap one by one.
166 std::queue<std::string> execute_queue_; 170 std::queue<std::string> execute_queue_;
167 171
168 base::ThreadChecker thread_checker_; 172 base::ThreadChecker thread_checker_;
169 173
170 base::WeakPtrFactory<XKeyboardImpl> weak_factory_; 174 base::WeakPtrFactory<XKeyboardImpl> weak_factory_;
171 175
176 ObserverList<Observer> observers_;
177
172 DISALLOW_COPY_AND_ASSIGN(XKeyboardImpl); 178 DISALLOW_COPY_AND_ASSIGN(XKeyboardImpl);
173 }; 179 };
174 180
175 XKeyboardImpl::XKeyboardImpl() 181 XKeyboardImpl::XKeyboardImpl()
176 : is_running_on_chrome_os_(base::SysInfo::IsRunningOnChromeOS()), 182 : is_running_on_chrome_os_(base::SysInfo::IsRunningOnChromeOS()),
177 weak_factory_(this) { 183 weak_factory_(this) {
178 // X must be already initialized. 184 // X must be already initialized.
179 CHECK(GetXDisplay()); 185 CHECK(GetXDisplay());
180 186
181 num_lock_mask_ = GetNumLockMask(); 187 num_lock_mask_ = GetNumLockMask();
182 188
183 if (is_running_on_chrome_os_) { 189 if (is_running_on_chrome_os_) {
184 // Some code seems to assume that Mod2Mask is always assigned to 190 // Some code seems to assume that Mod2Mask is always assigned to
185 // Num Lock. 191 // Num Lock.
186 // 192 //
187 // TODO(yusukes): Check the assumption is really okay. If not, 193 // TODO(yusukes): Check the assumption is really okay. If not,
188 // modify the Aura code, and then remove the CHECK below. 194 // modify the Aura code, and then remove the CHECK below.
189 LOG_IF(ERROR, num_lock_mask_ != Mod2Mask) 195 LOG_IF(ERROR, num_lock_mask_ != Mod2Mask)
190 << "NumLock is not assigned to Mod2Mask. : " << num_lock_mask_; 196 << "NumLock is not assigned to Mod2Mask. : " << num_lock_mask_;
191 } 197 }
192 198
193 current_caps_lock_status_ = CapsLockIsEnabled(); 199 current_caps_lock_status_ = CapsLockIsEnabled();
194 } 200 }
195 201
202 void XKeyboardImpl::AddObserver(XKeyboard::Observer* observer) {
203 observers_.AddObserver(observer);
204 }
205
206 void XKeyboardImpl::RemoveObserver(XKeyboard::Observer* observer) {
207 observers_.RemoveObserver(observer);
208 }
209
196 unsigned int XKeyboardImpl::GetNumLockMask() { 210 unsigned int XKeyboardImpl::GetNumLockMask() {
197 DCHECK(thread_checker_.CalledOnValidThread()); 211 DCHECK(thread_checker_.CalledOnValidThread());
198 static const unsigned int kBadMask = 0; 212 static const unsigned int kBadMask = 0;
199 213
200 unsigned int real_mask = kBadMask; 214 unsigned int real_mask = kBadMask;
201 XkbDescPtr xkb_desc = 215 XkbDescPtr xkb_desc =
202 XkbGetKeyboard(GetXDisplay(), XkbAllComponentsMask, XkbUseCoreKbd); 216 XkbGetKeyboard(GetXDisplay(), XkbAllComponentsMask, XkbUseCoreKbd);
203 if (!xkb_desc) 217 if (!xkb_desc)
204 return kBadMask; 218 return kBadMask;
205 219
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 if (XkbSetAutoRepeatRate(GetXDisplay(), XkbUseCoreKbd, 385 if (XkbSetAutoRepeatRate(GetXDisplay(), XkbUseCoreKbd,
372 rate.initial_delay_in_ms, 386 rate.initial_delay_in_ms,
373 rate.repeat_interval_in_ms) != True) { 387 rate.repeat_interval_in_ms) != True) {
374 DVLOG(1) << "Failed to set auto-repeat rate"; 388 DVLOG(1) << "Failed to set auto-repeat rate";
375 return false; 389 return false;
376 } 390 }
377 return true; 391 return true;
378 } 392 }
379 393
380 void XKeyboardImpl::SetCapsLockEnabled(bool enable_caps_lock) { 394 void XKeyboardImpl::SetCapsLockEnabled(bool enable_caps_lock) {
395 if (current_caps_lock_status_ != enable_caps_lock)
Daniel Erat 2014/04/09 23:39:40 add curly brackets since the statement is more tha
Mr4D (OOO till 08-26) 2014/04/09 23:44:47 Done.
396 FOR_EACH_OBSERVER(XKeyboard::Observer, observers_,
397 OnCapsLockChanged(enable_caps_lock));
381 SetLockedModifiers(enable_caps_lock); 398 SetLockedModifiers(enable_caps_lock);
Daniel Erat 2014/04/09 23:39:40 you should probably update the state before you no
Mr4D (OOO till 08-26) 2014/04/09 23:44:47 Done.
382 } 399 }
383 400
384 bool XKeyboardImpl::SetCurrentKeyboardLayoutByName( 401 bool XKeyboardImpl::SetCurrentKeyboardLayoutByName(
385 const std::string& layout_name) { 402 const std::string& layout_name) {
386 if (SetLayoutInternal(layout_name, false)) { 403 if (SetLayoutInternal(layout_name, false)) {
387 current_layout_name_ = layout_name; 404 current_layout_name_ = layout_name;
388 return true; 405 return true;
389 } 406 }
390 return false; 407 return false;
391 } 408 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 return CheckLayoutName(layout_name); 454 return CheckLayoutName(layout_name);
438 } 455 }
439 456
440 // static 457 // static
441 XKeyboard* XKeyboard::Create() { 458 XKeyboard* XKeyboard::Create() {
442 return new XKeyboardImpl(); 459 return new XKeyboardImpl();
443 } 460 }
444 461
445 } // namespace input_method 462 } // namespace input_method
446 } // namespace chromeos 463 } // namespace chromeos
OLDNEW
« ash/system/chromeos/tray_caps_lock.cc ('K') | « chromeos/ime/xkeyboard.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698