From f8ef310be3f196ae5df2ed39e8b1057c5dddf782 Mon Sep 17 00:00:00 2001 From: "skuhne@chromium.org" Date: Thu, 10 Apr 2014 17:55:53 +0000 Subject: Fixing caps lock problems under ChromeOS where the tray does not properly follow the real caps lock change BUG=356393 TEST=visual with chromebooks internal keyboard, external keyboard and with linux Review URL: https://codereview.chromium.org/231753002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263025 0039d316-1c4b-4281-b951-d872f2087c98 --- chromeos/ime/fake_xkeyboard.cc | 6 ++++++ chromeos/ime/fake_xkeyboard.h | 2 ++ chromeos/ime/xkeyboard.cc | 19 +++++++++++++++++++ chromeos/ime/xkeyboard.h | 10 ++++++++++ 4 files changed, 37 insertions(+) (limited to 'chromeos') diff --git a/chromeos/ime/fake_xkeyboard.cc b/chromeos/ime/fake_xkeyboard.cc index 6a7d7a4..fdc227a 100644 --- a/chromeos/ime/fake_xkeyboard.cc +++ b/chromeos/ime/fake_xkeyboard.cc @@ -13,6 +13,12 @@ FakeXKeyboard::FakeXKeyboard() auto_repeat_is_enabled_(false) { } +void FakeXKeyboard::AddObserver(XKeyboard::Observer* observer) { +} + +void FakeXKeyboard::RemoveObserver(XKeyboard::Observer* observer) { +} + bool FakeXKeyboard::SetCurrentKeyboardLayoutByName( const std::string& layout_name) { ++set_current_keyboard_layout_by_name_count_; diff --git a/chromeos/ime/fake_xkeyboard.h b/chromeos/ime/fake_xkeyboard.h index df531ae..3422bfa 100644 --- a/chromeos/ime/fake_xkeyboard.h +++ b/chromeos/ime/fake_xkeyboard.h @@ -20,6 +20,8 @@ class CHROMEOS_EXPORT FakeXKeyboard : public XKeyboard { FakeXKeyboard(); virtual ~FakeXKeyboard() {} + virtual void AddObserver(Observer* observer) OVERRIDE; + virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual bool SetCurrentKeyboardLayoutByName(const std::string& layout_name) OVERRIDE; virtual bool ReapplyCurrentKeyboardLayout() OVERRIDE; diff --git a/chromeos/ime/xkeyboard.cc b/chromeos/ime/xkeyboard.cc index b2f55f1..8f2adc8 100644 --- a/chromeos/ime/xkeyboard.cc +++ b/chromeos/ime/xkeyboard.cc @@ -117,6 +117,10 @@ class XKeyboardImpl : public XKeyboard { XKeyboardImpl(); virtual ~XKeyboardImpl() {} + // Adds/removes observer. + virtual void AddObserver(Observer* observer) OVERRIDE; + virtual void RemoveObserver(Observer* observer) OVERRIDE; + // Overridden from XKeyboard: virtual bool SetCurrentKeyboardLayoutByName( const std::string& layout_name) OVERRIDE; @@ -169,6 +173,8 @@ class XKeyboardImpl : public XKeyboard { base::WeakPtrFactory weak_factory_; + ObserverList observers_; + DISALLOW_COPY_AND_ASSIGN(XKeyboardImpl); }; @@ -193,6 +199,14 @@ XKeyboardImpl::XKeyboardImpl() current_caps_lock_status_ = CapsLockIsEnabled(); } +void XKeyboardImpl::AddObserver(XKeyboard::Observer* observer) { + observers_.AddObserver(observer); +} + +void XKeyboardImpl::RemoveObserver(XKeyboard::Observer* observer) { + observers_.RemoveObserver(observer); +} + unsigned int XKeyboardImpl::GetNumLockMask() { DCHECK(thread_checker_.CalledOnValidThread()); static const unsigned int kBadMask = 0; @@ -378,7 +392,12 @@ bool XKeyboardImpl::SetAutoRepeatRate(const AutoRepeatRate& rate) { } void XKeyboardImpl::SetCapsLockEnabled(bool enable_caps_lock) { + bool old_state = current_caps_lock_status_; SetLockedModifiers(enable_caps_lock); + if (old_state != enable_caps_lock) { + FOR_EACH_OBSERVER(XKeyboard::Observer, observers_, + OnCapsLockChanged(enable_caps_lock)); + } } bool XKeyboardImpl::SetCurrentKeyboardLayoutByName( diff --git a/chromeos/ime/xkeyboard.h b/chromeos/ime/xkeyboard.h index b07e4f4..ad2cbc7 100644 --- a/chromeos/ime/xkeyboard.h +++ b/chromeos/ime/xkeyboard.h @@ -36,8 +36,18 @@ class InputMethodUtil; class CHROMEOS_EXPORT XKeyboard { public: + class Observer { + public: + // Called when the caps lock state has changed. + virtual void OnCapsLockChanged(bool enabled) = 0; + }; + virtual ~XKeyboard() {} + // Adds/removes observer. + virtual void AddObserver(Observer* observer) = 0; + virtual void RemoveObserver(Observer* observer) = 0; + // Sets the current keyboard layout to |layout_name|. This function does not // change the current mapping of the modifier keys. Returns true on success. virtual bool SetCurrentKeyboardLayoutByName( -- cgit v1.1