0

Move functions for controlling Caps Lock to CapsLockDelegate from SystemTrayDelegate.

- Add functions for controlling Caps Lock to CapsLockDelegate
- Move the ownership of CapsLockDelegate to Shell from AcceleratorController
- Add ShellDelegate::CreateCapsLockDelegate

BUG=144474


Review URL: https://chromiumcodereview.appspot.com/10878058

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153597 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
mazda@chromium.org
2012-08-28 00:59:59 +00:00
parent 76ab62b152
commit f4c92b381a
24 changed files with 200 additions and 112 deletions

@ -492,14 +492,12 @@ bool AcceleratorController::PerformAction(int action,
ash::Shell::GetInstance()->ToggleAppList();
return true;
case DISABLE_CAPS_LOCK:
// TODO(mazda): Handle this using |caps_lock_delegate_|.
if (shell->tray_delegate()->IsCapsLockOn())
shell->tray_delegate()->SetCapsLockEnabled(false);
if (shell->caps_lock_delegate()->IsCapsLockEnabled())
shell->caps_lock_delegate()->SetCapsLockEnabled(false);
return true;
case TOGGLE_CAPS_LOCK:
if (caps_lock_delegate_.get())
return caps_lock_delegate_->HandleToggleCapsLock();
break;
shell->caps_lock_delegate()->ToggleCapsLock();
return true;
case BRIGHTNESS_DOWN:
if (brightness_control_delegate_.get())
return brightness_control_delegate_->HandleBrightnessDown(accelerator);
@ -703,11 +701,6 @@ void AcceleratorController::SetBrightnessControlDelegate(
brightness_control_delegate_.swap(brightness_control_delegate);
}
void AcceleratorController::SetCapsLockDelegate(
scoped_ptr<CapsLockDelegate> caps_lock_delegate) {
caps_lock_delegate_.swap(caps_lock_delegate);
}
void AcceleratorController::SetImeControlDelegate(
scoped_ptr<ImeControlDelegate> ime_control_delegate) {
ime_control_delegate_.swap(ime_control_delegate);

@ -22,7 +22,6 @@ namespace ash {
struct AcceleratorData;
class BrightnessControlDelegate;
class CapsLockDelegate;
class ImeControlDelegate;
class KeyboardBrightnessControlDelegate;
class ScreenshotDelegate;
@ -75,7 +74,6 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
void SetBrightnessControlDelegate(
scoped_ptr<BrightnessControlDelegate> brightness_control_delegate);
void SetCapsLockDelegate(scoped_ptr<CapsLockDelegate> caps_lock_delegate);
void SetImeControlDelegate(
scoped_ptr<ImeControlDelegate> ime_control_delegate);
void SetKeyboardBrightnessControlDelegate(
@ -104,7 +102,6 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget {
// TODO(derat): BrightnessControlDelegate is also used by the system tray;
// move it outside of this class.
scoped_ptr<BrightnessControlDelegate> brightness_control_delegate_;
scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
scoped_ptr<ImeControlDelegate> ime_control_delegate_;
scoped_ptr<KeyboardBrightnessControlDelegate>
keyboard_brightness_control_delegate_;

@ -93,30 +93,6 @@ class DummyScreenshotDelegate : public ScreenshotDelegate {
DISALLOW_COPY_AND_ASSIGN(DummyScreenshotDelegate);
};
class DummyCapsLockDelegate : public CapsLockDelegate {
public:
explicit DummyCapsLockDelegate(bool consume)
: consume_(consume),
handle_caps_lock_count_(0) {
}
virtual ~DummyCapsLockDelegate() {}
virtual bool HandleToggleCapsLock() OVERRIDE {
++handle_caps_lock_count_;
return consume_;
}
int handle_caps_lock_count() const {
return handle_caps_lock_count_;
}
private:
const bool consume_;
int handle_caps_lock_count_;
DISALLOW_COPY_AND_ASSIGN(DummyCapsLockDelegate);
};
class DummyVolumeControlDelegate : public VolumeControlDelegate {
public:
explicit DummyVolumeControlDelegate(bool consume)
@ -602,44 +578,51 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) {
}
// DisableCapsLock
{
CapsLockDelegate* delegate = Shell::GetInstance()->caps_lock_delegate();
delegate->SetCapsLockEnabled(true);
EXPECT_TRUE(delegate->IsCapsLockEnabled());
// Handled only on key release.
EXPECT_FALSE(GetController()->Process(
ui::Accelerator(ui::VKEY_LSHIFT, ui::EF_NONE)));
EXPECT_TRUE(delegate->IsCapsLockEnabled());
EXPECT_TRUE(GetController()->Process(
ReleaseAccelerator(ui::VKEY_SHIFT, ui::EF_NONE)));
EXPECT_FALSE(delegate->IsCapsLockEnabled());
delegate->SetCapsLockEnabled(true);
EXPECT_FALSE(GetController()->Process(
ui::Accelerator(ui::VKEY_RSHIFT, ui::EF_NONE)));
EXPECT_TRUE(delegate->IsCapsLockEnabled());
EXPECT_TRUE(GetController()->Process(
ReleaseAccelerator(ui::VKEY_LSHIFT, ui::EF_NONE)));
EXPECT_FALSE(delegate->IsCapsLockEnabled());
delegate->SetCapsLockEnabled(true);
EXPECT_FALSE(GetController()->Process(
ui::Accelerator(ui::VKEY_SHIFT, ui::EF_NONE)));
EXPECT_TRUE(delegate->IsCapsLockEnabled());
EXPECT_TRUE(GetController()->Process(
ReleaseAccelerator(ui::VKEY_RSHIFT, ui::EF_NONE)));
EXPECT_FALSE(delegate->IsCapsLockEnabled());
// Do not handle when a shift pressed with other keys.
delegate->SetCapsLockEnabled(true);
EXPECT_FALSE(GetController()->Process(
ui::Accelerator(ui::VKEY_A, ui::EF_SHIFT_DOWN)));
EXPECT_TRUE(delegate->IsCapsLockEnabled());
EXPECT_FALSE(GetController()->Process(
ReleaseAccelerator(ui::VKEY_A, ui::EF_SHIFT_DOWN)));
EXPECT_TRUE(delegate->IsCapsLockEnabled());
}
// ToggleCapsLock
{
EXPECT_FALSE(GetController()->Process(
ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN)));
DummyCapsLockDelegate* delegate = new DummyCapsLockDelegate(false);
GetController()->SetCapsLockDelegate(
scoped_ptr<CapsLockDelegate>(delegate).Pass());
EXPECT_EQ(0, delegate->handle_caps_lock_count());
EXPECT_FALSE(GetController()->Process(
ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN)));
EXPECT_EQ(1, delegate->handle_caps_lock_count());
}
{
DummyCapsLockDelegate* delegate = new DummyCapsLockDelegate(true);
GetController()->SetCapsLockDelegate(
scoped_ptr<CapsLockDelegate>(delegate).Pass());
EXPECT_EQ(0, delegate->handle_caps_lock_count());
CapsLockDelegate* delegate = Shell::GetInstance()->caps_lock_delegate();
delegate->SetCapsLockEnabled(true);
EXPECT_TRUE(delegate->IsCapsLockEnabled());
EXPECT_TRUE(GetController()->Process(
ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN)));
EXPECT_EQ(1, delegate->handle_caps_lock_count());
EXPECT_FALSE(delegate->IsCapsLockEnabled());
EXPECT_TRUE(GetController()->Process(
ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN)));
EXPECT_TRUE(delegate->IsCapsLockEnabled());
}
// Volume
const ui::Accelerator f8(ui::VKEY_F8, ui::EF_NONE);

@ -58,6 +58,8 @@
'ash_switches.cc',
'ash_switches.h',
'caps_lock_delegate.h',
'caps_lock_delegate_stub.cc',
'caps_lock_delegate_stub.h',
'desktop_background/desktop_background_controller.cc',
'desktop_background/desktop_background_controller.h',
'desktop_background/desktop_background_resources.cc',

@ -5,17 +5,29 @@
#ifndef ASH_CAPS_LOCK_DELEGATE_H_
#define ASH_CAPS_LOCK_DELEGATE_H_
#include "ash/ash_export.h"
namespace ash {
// Delegate for toggling Caps Lock.
class CapsLockDelegate {
// Delegate for controlling Caps Lock.
class ASH_EXPORT CapsLockDelegate {
public:
virtual ~CapsLockDelegate() {}
// A derived class should do either of the following: 1) toggle Caps Lock and
// return true, or 2) do nothing and return false (see crosbug.com/110127).
virtual bool HandleToggleCapsLock() = 0;
// Returns true if caps lock is enabled.
virtual bool IsCapsLockEnabled() const = 0;
// Sets the caps lock state to |enabled|.
// The state change can occur asynchronously and calling IsCapsLockEnabled
// just after this may return the old state.
virtual void SetCapsLockEnabled(bool enabled) = 0;
// Toggles the caps lock state.
// The state change can occur asynchronously and calling IsCapsLockEnabled
// just after this may return the old state.
virtual void ToggleCapsLock() = 0;
};
} // namespace ash
#endif // ASH_CAPS_LOCK_DELEGATE_H_

@ -0,0 +1,26 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/caps_lock_delegate_stub.h"
namespace ash {
CapsLockDelegateStub::CapsLockDelegateStub()
: enabled_(false) {}
CapsLockDelegateStub::~CapsLockDelegateStub() {}
bool CapsLockDelegateStub::IsCapsLockEnabled() const {
return enabled_;
}
void CapsLockDelegateStub::SetCapsLockEnabled(bool enabled) {
enabled_ = enabled;
}
void CapsLockDelegateStub::ToggleCapsLock() {
enabled_ = !enabled_;
}
} // namespace ash

@ -0,0 +1,34 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_CAPS_LOCK_DELEGATE_STUB_H_
#define ASH_CAPS_LOCK_DELEGATE_STUB_H_
#include "ash/ash_export.h"
#include "ash/caps_lock_delegate.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
namespace ash {
// Stub implementation of CapsLockDelegate mainly for testing.
class ASH_EXPORT CapsLockDelegateStub : public CapsLockDelegate {
public:
CapsLockDelegateStub();
virtual ~CapsLockDelegateStub();
// Overridden from CapsLockDelegate:
virtual bool IsCapsLockEnabled() const OVERRIDE;
virtual void SetCapsLockEnabled(bool enabled) OVERRIDE;
virtual void ToggleCapsLock() OVERRIDE;
private:
bool enabled_;
DISALLOW_COPY_AND_ASSIGN(CapsLockDelegateStub);
};
} // namespace ash
#endif // ASH_CAPS_LOCK_DELEGATE_STUB

@ -9,19 +9,20 @@
#include "ash/accelerators/focus_manager_factory.h"
#include "ash/ash_switches.h"
#include "ash/caps_lock_delegate_stub.h"
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/desktop_background/desktop_background_resources.h"
#include "ash/desktop_background/desktop_background_view.h"
#include "ash/drag_drop/drag_drop_controller.h"
#include "ash/focus_cycler.h"
#include "ash/high_contrast/high_contrast_controller.h"
#include "ash/launcher/launcher.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/display/display_controller.h"
#include "ash/display/mouse_cursor_event_filter.h"
#include "ash/display/multi_display_manager.h"
#include "ash/display/screen_position_controller.h"
#include "ash/display/secondary_display_view.h"
#include "ash/drag_drop/drag_drop_controller.h"
#include "ash/focus_cycler.h"
#include "ash/high_contrast/high_contrast_controller.h"
#include "ash/launcher/launcher.h"
#include "ash/magnifier/magnification_controller.h"
#include "ash/root_window_controller.h"
#include "ash/screen_ash.h"
#include "ash/shell_context_menu.h"
@ -61,8 +62,8 @@
#include "ash/wm/visibility_controller.h"
#include "ash/wm/window_cycle_controller.h"
#include "ash/wm/window_modality_controller.h"
#include "ash/wm/window_util.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace/workspace_event_filter.h"
#include "ash/wm/workspace/workspace_layout_manager.h"
#include "ash/wm/workspace_controller.h"
@ -71,10 +72,10 @@
#include "grit/ui_resources.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/user_action_client.h"
#include "ui/aura/display_manager.h"
#include "ui/aura/env.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/display_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/shared/compound_event_filter.h"
#include "ui/aura/shared/input_method_event_filter.h"
@ -452,6 +453,12 @@ void Shell::Init() {
InitRootWindowController(root_window_controller);
// StatusAreaWidget uses Shell's CapsLockDelegate.
if (delegate_.get())
caps_lock_delegate_.reset(delegate_->CreateCapsLockDelegate());
else
caps_lock_delegate_.reset(new CapsLockDelegateStub);
// Initialize Primary RootWindow specific items.
status_area_widget_ = new internal::StatusAreaWidget();
status_area_widget_->CreateTrayViews(delegate_.get());

@ -59,6 +59,7 @@ class Widget;
namespace ash {
class AcceleratorController;
class CapsLockDelegate;
class DesktopBackgroundController;
class HighContrastController;
class Launcher;
@ -286,6 +287,10 @@ class ASH_EXPORT Shell : ash::CursorDelegate {
return user_wallpaper_delegate_.get();
}
CapsLockDelegate* caps_lock_delegate() {
return caps_lock_delegate_.get();
}
HighContrastController* high_contrast_controller() {
return high_contrast_controller_.get();
}
@ -408,6 +413,7 @@ class ASH_EXPORT Shell : ash::CursorDelegate {
scoped_ptr<ShellDelegate> delegate_;
scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
scoped_ptr<Launcher> launcher_;

@ -4,6 +4,7 @@
#include "ash/shell/shell_delegate_impl.h"
#include "ash/caps_lock_delegate_stub.h"
#include "ash/shell/example_factory.h"
#include "ash/shell/launcher_delegate_impl.h"
#include "ash/shell/toplevel_window.h"
@ -123,6 +124,10 @@ ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() {
return NULL;
}
ash::CapsLockDelegate* ShellDelegateImpl::CreateCapsLockDelegate() {
return new CapsLockDelegateStub;
}
aura::client::UserActionClient* ShellDelegateImpl::CreateUserActionClient() {
return NULL;
}

@ -46,6 +46,7 @@ class ShellDelegateImpl : public ash::ShellDelegate {
virtual ash::SystemTrayDelegate* CreateSystemTrayDelegate(
ash::SystemTray* tray) OVERRIDE;
virtual ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE;
virtual ash::CapsLockDelegate* CreateCapsLockDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void OpenFeedbackPage() OVERRIDE;
virtual void RecordUserMetricsAction(UserMetricsAction action) OVERRIDE;

@ -29,6 +29,7 @@ class Widget;
namespace ash {
class CapsLockDelegate;
class LauncherDelegate;
class LauncherModel;
struct LauncherItem;
@ -129,6 +130,9 @@ class ASH_EXPORT ShellDelegate {
// Creates a user wallpaper delegate. Shell takes ownership of the delegate.
virtual UserWallpaperDelegate* CreateUserWallpaperDelegate() = 0;
// Creates a caps lock delegate. Shell takes ownership of the delegate.
virtual CapsLockDelegate* CreateCapsLockDelegate() = 0;
// Creates a user action client. Shell takes ownership of the object.
virtual aura::client::UserActionClient* CreateUserActionClient() = 0;

@ -125,14 +125,6 @@ class DummySystemTrayDelegate : public SystemTrayDelegate {
virtual void ShowHelp() OVERRIDE {
}
virtual bool IsCapsLockOn() const OVERRIDE {
return caps_lock_enabled_;
}
virtual void SetCapsLockEnabled(bool enabled) OVERRIDE {
caps_lock_enabled_ = enabled;
}
virtual void ShutDown() OVERRIDE {
MessageLoop::current()->Quit();
}

@ -145,12 +145,6 @@ class SystemTrayDelegate {
// Shows help.
virtual void ShowHelp() = 0;
// Gets whether the caps lock is on.
virtual bool IsCapsLockOn() const = 0;
// Sets the caps lock status to |enabled|.
virtual void SetCapsLockEnabled(bool enabled) = 0;
// Attempts to shut down the system.
virtual void ShutDown() = 0;

@ -4,8 +4,8 @@
#include "ash/system/tray_caps_lock.h"
#include "ash/caps_lock_delegate.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_views.h"
#include "grit/ash_strings.h"
@ -92,8 +92,7 @@ class CapsLockDefaultView : public ActionableView {
// Overridden from ActionableView:
virtual bool PerformAction(const ui::Event& event) OVERRIDE {
Shell::GetInstance()->tray_delegate()->SetCapsLockEnabled(
!Shell::GetInstance()->tray_delegate()->IsCapsLockOn());
Shell::GetInstance()->caps_lock_delegate()->ToggleCapsLock();
return true;
}
@ -109,14 +108,14 @@ TrayCapsLock::TrayCapsLock()
detailed_(NULL),
search_mapped_to_caps_lock_(false),
caps_lock_enabled_(
Shell::GetInstance()->tray_delegate()->IsCapsLockOn()),
Shell::GetInstance()->caps_lock_delegate()->IsCapsLockEnabled()),
message_shown_(false) {
}
TrayCapsLock::~TrayCapsLock() {}
bool TrayCapsLock::GetInitialVisibility() {
return Shell::GetInstance()->tray_delegate()->IsCapsLockOn();
return Shell::GetInstance()->caps_lock_delegate()->IsCapsLockEnabled();
}
views::View* TrayCapsLock::CreateDefaultView(user::LoginStatus status) {

@ -6,6 +6,7 @@
#include <algorithm>
#include "ash/caps_lock_delegate_stub.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/test_launcher_delegate.h"
@ -108,6 +109,10 @@ UserWallpaperDelegate* TestShellDelegate::CreateUserWallpaperDelegate() {
return NULL;
}
CapsLockDelegate* TestShellDelegate::CreateCapsLockDelegate() {
return new CapsLockDelegateStub;
}
aura::client::UserActionClient* TestShellDelegate::CreateUserActionClient() {
return NULL;
}

@ -41,6 +41,7 @@ class TestShellDelegate : public ShellDelegate {
ash::LauncherModel* model) OVERRIDE;
virtual SystemTrayDelegate* CreateSystemTrayDelegate(SystemTray* t) OVERRIDE;
virtual UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE;
virtual CapsLockDelegate* CreateCapsLockDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void OpenFeedbackPage() OVERRIDE;
virtual void RecordUserMetricsAction(UserMetricsAction action) OVERRIDE;

@ -341,18 +341,6 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
chrome::ShowHelp(GetAppropriateBrowser(), chrome::HELP_SOURCE_MENU);
}
virtual bool IsCapsLockOn() const OVERRIDE {
input_method::InputMethodManager* ime_manager =
input_method::InputMethodManager::GetInstance();
return ime_manager->GetXKeyboard()->CapsLockIsEnabled();
}
virtual void SetCapsLockEnabled(bool enabled) OVERRIDE {
input_method::InputMethodManager* ime_manager =
input_method::InputMethodManager::GetInstance();
return ime_manager->GetXKeyboard()->SetCapsLockEnabled(enabled);
}
virtual void ShutDown() OVERRIDE {
DBusThreadManager::Get()->GetPowerManagerClient()->RequestShutdown();
if (!base::chromeos::IsRunningOnChromeOS())

@ -14,7 +14,6 @@
#include "base/command_line.h"
#include "chrome/browser/chromeos/accessibility/accessibility_util.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/ui/ash/caps_lock_handler.h"
#include "chrome/browser/ui/ash/chrome_shell_delegate.h"
#include "chrome/browser/ui/ash/event_rewriter.h"
#include "chrome/browser/ui/ash/screenshot_taker.h"
@ -27,7 +26,6 @@
#if defined(OS_CHROMEOS)
#include "base/chromeos/chromeos_version.h"
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/ui/ash/brightness_controller_chromeos.h"
#include "chrome/browser/ui/ash/ime_controller_chromeos.h"
@ -78,10 +76,6 @@ void OpenAsh() {
shell->accelerator_controller()->SetBrightnessControlDelegate(
scoped_ptr<ash::BrightnessControlDelegate>(
new BrightnessController).Pass());
chromeos::input_method::XKeyboard* xkeyboard =
chromeos::input_method::InputMethodManager::GetInstance()->GetXKeyboard();
shell->accelerator_controller()->SetCapsLockDelegate(
scoped_ptr<ash::CapsLockDelegate>(new CapsLockHandler(xkeyboard)).Pass());
shell->accelerator_controller()->SetImeControlDelegate(
scoped_ptr<ash::ImeControlDelegate>(new ImeController).Pass());
shell->accelerator_controller()->SetKeyboardBrightnessControlDelegate(

@ -37,17 +37,37 @@ CapsLockHandler::~CapsLockHandler() {
#endif
}
bool CapsLockHandler::HandleToggleCapsLock() {
bool CapsLockHandler::IsCapsLockEnabled() const {
#if defined(OS_CHROMEOS)
return caps_lock_is_on_;
#else
NOTIMPLEMENTED();
return false;
#endif
}
void CapsLockHandler::SetCapsLockEnabled(bool enabled) {
#if defined(OS_CHROMEOS)
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
if (is_running_on_chromeos_) {
xkeyboard_->SetCapsLockEnabled(!caps_lock_is_on_);
return true; // consume the shortcut key.
xkeyboard_->SetCapsLockEnabled(enabled);
return;
}
#else
NOTIMPLEMENTED();
#endif
}
void CapsLockHandler::ToggleCapsLock() {
#if defined(OS_CHROMEOS)
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
if (is_running_on_chromeos_) {
xkeyboard_->SetCapsLockEnabled(!caps_lock_is_on_);
return;
}
#else
NOTIMPLEMENTED();
#endif
return false;
}
#if defined(OS_CHROMEOS)

@ -34,7 +34,9 @@ class CapsLockHandler : public ash::CapsLockDelegate
virtual ~CapsLockHandler();
// Overridden from ash::CapsLockHandler:
virtual bool HandleToggleCapsLock() OVERRIDE;
virtual bool IsCapsLockEnabled() const OVERRIDE;
virtual void SetCapsLockEnabled(bool enabled) OVERRIDE;
virtual void ToggleCapsLock() OVERRIDE;
#if defined(OS_CHROMEOS)
// Overridden from chromeos::SystemKeyEventListener::CapsLockObserver:

@ -22,7 +22,7 @@ class CapsLockHandlerTest : public InProcessBrowserTest {
}
virtual void SetUp() OVERRIDE {
handler_.reset(new CapsLockHandler(&xkeyboard_));
// Force CapsLockHandler::HandleToggleCapsLock() to toggle the lock state.
// Force CapsLockHandler::ToggleCapsLock() to toggle the lock state.
handler_->set_is_running_on_chromeos_for_test(true);
}
virtual void TearDown() OVERRIDE {
@ -41,16 +41,26 @@ class CapsLockHandlerTest : public InProcessBrowserTest {
} // namespace
#if defined(OS_CHROMEOS)
// Check if HandleToggleCapsLock() really changes the lock state.
// Check if ToggleCapsLock() really changes the lock state.
IN_PROC_BROWSER_TEST_F(CapsLockHandlerTest, TestCapsLock) {
EXPECT_EQ(initial_caps_lock_state_, handler_->caps_lock_is_on_for_test());
EXPECT_TRUE(handler_->HandleToggleCapsLock());
handler_->ToggleCapsLock();
EXPECT_EQ(!initial_caps_lock_state_, xkeyboard_.CapsLockIsEnabled());
handler_->OnCapsLockChange(!initial_caps_lock_state_);
EXPECT_EQ(!initial_caps_lock_state_, handler_->caps_lock_is_on_for_test());
EXPECT_TRUE(handler_->HandleToggleCapsLock());
handler_->ToggleCapsLock();
handler_->OnCapsLockChange(initial_caps_lock_state_);
EXPECT_EQ(initial_caps_lock_state_, xkeyboard_.CapsLockIsEnabled());
EXPECT_EQ(initial_caps_lock_state_, handler_->caps_lock_is_on_for_test());
// Check if SetCapsLockEnabled really changes the lock state.
handler_->SetCapsLockEnabled(!initial_caps_lock_state_);
EXPECT_EQ(!initial_caps_lock_state_, handler_->caps_lock_is_on_for_test());
EXPECT_EQ(!initial_caps_lock_state_, xkeyboard_.CapsLockIsEnabled());
EXPECT_EQ(!initial_caps_lock_state_, handler_->IsCapsLockEnabled());
handler_->SetCapsLockEnabled(initial_caps_lock_state_);
EXPECT_EQ(initial_caps_lock_state_, handler_->caps_lock_is_on_for_test());
EXPECT_EQ(initial_caps_lock_state_, xkeyboard_.CapsLockIsEnabled());
EXPECT_EQ(initial_caps_lock_state_, handler_->IsCapsLockEnabled());
}
#endif

@ -16,6 +16,7 @@
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/ui/app_list/app_list_view_delegate.h"
#include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h"
#include "chrome/browser/ui/ash/caps_lock_handler.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/user_action_handler.h"
#include "chrome/browser/ui/ash/window_positioner.h"
@ -41,6 +42,7 @@
#include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h"
#include "chrome/browser/chromeos/extensions/file_manager_util.h"
#include "chrome/browser/chromeos/extensions/media_player_event_router.h"
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/webui_login_display_host.h"
@ -322,6 +324,16 @@ ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
#endif
}
ash::CapsLockDelegate* ChromeShellDelegate::CreateCapsLockDelegate() {
#if defined(OS_CHROMEOS)
chromeos::input_method::XKeyboard* xkeyboard =
chromeos::input_method::InputMethodManager::GetInstance()->GetXKeyboard();
return new CapsLockHandler(xkeyboard);
#else
return new CapsLockHandler;
#endif
}
aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() {
return new UserActionHandler;
}

@ -59,6 +59,7 @@ class ChromeShellDelegate : public ash::ShellDelegate,
virtual ash::SystemTrayDelegate* CreateSystemTrayDelegate(
ash::SystemTray* tray) OVERRIDE;
virtual ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE;
virtual ash::CapsLockDelegate* CreateCapsLockDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void OpenFeedbackPage() OVERRIDE;
virtual void RecordUserMetricsAction(ash::UserMetricsAction action) OVERRIDE;