Commit f8ef310b authored by skuhne@chromium.org's avatar skuhne@chromium.org

Fixing caps lock problems under ChromeOS where the tray does not properly...

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
parent c754b8be
......@@ -10,6 +10,7 @@
#include "ash/system/tray/fixed_sized_image_view.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
#include "base/sys_info.h"
#include "chromeos/ime/input_method_manager.h"
#include "chromeos/ime/xkeyboard.h"
#include "grit/ash_resources.h"
......@@ -129,24 +130,39 @@ TrayCapsLock::TrayCapsLock(SystemTray* system_tray)
detailed_(NULL),
caps_lock_enabled_(CapsLockIsEnabled()),
message_shown_(false) {
// Make sure the event is processed by this before the IME.
Shell::GetInstance()->PrependPreTargetHandler(this);
// Since keyboard handling differs between ChromeOS and Linux we need to
// use different observers depending on the two platforms.
if (base::SysInfo::IsRunningOnChromeOS()) {
chromeos::input_method::XKeyboard* xkeyboard =
chromeos::input_method::InputMethodManager::Get()->GetXKeyboard();
xkeyboard->AddObserver(this);
} else {
Shell::GetInstance()->PrependPreTargetHandler(this);
}
}
TrayCapsLock::~TrayCapsLock() {
Shell::GetInstance()->RemovePreTargetHandler(this);
// Since keyboard handling differs between ChromeOS and Linux we need to
// use different observers depending on the two platforms.
if (base::SysInfo::IsRunningOnChromeOS()) {
chromeos::input_method::XKeyboard* xkeyboard =
chromeos::input_method::InputMethodManager::Get()->GetXKeyboard();
xkeyboard->RemoveObserver(this);
} else {
Shell::GetInstance()->RemovePreTargetHandler(this);
}
}
void TrayCapsLock::OnCapsLockChanged(bool enabled) {
if (tray_view())
tray_view()->SetVisible(enabled);
caps_lock_enabled_ = enabled;
if (tray_view())
tray_view()->SetVisible(caps_lock_enabled_);
if (default_) {
default_->Update(enabled);
default_->Update(caps_lock_enabled_);
} else {
if (enabled) {
if (caps_lock_enabled_) {
if (!message_shown_) {
Shell::GetInstance()->metrics()->RecordUserMetricsAction(
ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP);
......
......@@ -6,6 +6,7 @@
#define ASH_SYSTEM_CHROMEOS_TRAY_CAPS_LOCK_H_
#include "ash/system/tray/tray_image_item.h"
#include "chromeos/ime/xkeyboard.h"
#include "ui/events/event_handler.h"
namespace views {
......@@ -17,13 +18,15 @@ namespace ash {
class CapsLockDefaultView;
class TrayCapsLock : public TrayImageItem,
public ui::EventHandler {
public ui::EventHandler,
public chromeos::input_method::XKeyboard::Observer {
public:
explicit TrayCapsLock(SystemTray* system_tray);
virtual ~TrayCapsLock();
private:
void OnCapsLockChanged(bool enabled);
// Overriden from chromeos::input_method::XKeyboard::Observer:
virtual void OnCapsLockChanged(bool enabled) OVERRIDE;
// ui::EventHandler:
virtual void OnKeyEvent(ui::KeyEvent* key) OVERRIDE;
......
......@@ -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_;
......
......@@ -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;
......
......@@ -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<XKeyboardImpl> weak_factory_;
ObserverList<Observer> 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(
......
......@@ -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(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment