diff options
author | yusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 04:12:14 +0000 |
---|---|---|
committer | yusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 04:12:14 +0000 |
commit | fb9a35593b87e79a08cbcfa8105189b54c9f2adf (patch) | |
tree | b38a21db7f41c1570e90297f5198908ebab37db8 /ash | |
parent | 80b64ea5a60284fcdc509a99c83bc889e27db28b (diff) | |
download | chromium_src-fb9a35593b87e79a08cbcfa8105189b54c9f2adf.zip chromium_src-fb9a35593b87e79a08cbcfa8105189b54c9f2adf.tar.gz chromium_src-fb9a35593b87e79a08cbcfa8105189b54c9f2adf.tar.bz2 |
Handle Caps Lock short cut (Shift+Search) in ash [part 1 of 2].
Currently it's handled in chrome/browser/chromeos/system_key_event_listener.cc by checking the X event loop directly, but for Aura, it'd be better to remove the X dependency by moving the code to ash/accelerators/ since any class except aura::RootWindowHost should not handle an X event directly.
Part 2 of 2: https://chromiumcodereview.appspot.com/9225004/
BUG=110129
TEST=ran aura_shell_unittests
Review URL: http://codereview.chromium.org/9242003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118035 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/accelerators/accelerator_controller.cc | 13 | ||||
-rw-r--r-- | ash/accelerators/accelerator_controller.h | 5 | ||||
-rw-r--r-- | ash/accelerators/accelerator_controller_unittest.cc | 74 | ||||
-rw-r--r-- | ash/ash.gyp | 1 | ||||
-rw-r--r-- | ash/caps_lock_delegate.h | 22 |
5 files changed, 101 insertions, 14 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index 71f8507..2a48859 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -4,6 +4,7 @@ #include "ash/accelerators/accelerator_controller.h" +#include "ash/caps_lock_delegate.h" #include "ash/launcher/launcher.h" #include "ash/launcher/launcher_model.h" #include "ash/screenshot_delegate.h" @@ -25,6 +26,7 @@ enum AcceleratorAction { CYCLE_BACKWARD, CYCLE_FORWARD, TAKE_SCREENSHOT, + TOGGLE_CAPS_LOCK, #if !defined(NDEBUG) ROTATE_SCREEN, PRINT_LAYER_HIERARCHY, @@ -46,6 +48,8 @@ struct AcceleratorData { { ui::VKEY_F5, true, false, false, CYCLE_BACKWARD }, { ui::VKEY_F5, false, true, false, TAKE_SCREENSHOT }, { ui::VKEY_PRINT, false, false, false, TAKE_SCREENSHOT }, + // On Chrome OS, Search key is mapped to LWIN. + { ui::VKEY_LWIN, true, false, false, TOGGLE_CAPS_LOCK }, #if !defined(NDEBUG) { ui::VKEY_HOME, false, true, false, ROTATE_SCREEN }, { ui::VKEY_F11, false, true, false, TOGGLE_ROOT_WINDOW_FULL_SCREEN }, @@ -162,6 +166,11 @@ void AcceleratorController::SetScreenshotDelegate( screenshot_delegate_.reset(screenshot_delegate); } +void AcceleratorController::SetCapsLockDelegate( + scoped_ptr<CapsLockDelegate> caps_lock_delegate) { + caps_lock_delegate_.swap(caps_lock_delegate); +} + //////////////////////////////////////////////////////////////////////////////// // AcceleratorController, ui::AcceleratorTarget implementation: @@ -182,6 +191,10 @@ bool AcceleratorController::AcceleratorPressed( screenshot_delegate_->HandleTakeScreenshot(); // Return true to prevent propagation of the key event. return true; + case TOGGLE_CAPS_LOCK: + if (caps_lock_delegate_.get()) + return caps_lock_delegate_->HandleToggleCapsLock(); + break; #if !defined(NDEBUG) case ROTATE_SCREEN: return HandleRotateScreen(); diff --git a/ash/accelerators/accelerator_controller.h b/ash/accelerators/accelerator_controller.h index 55c3ed5..8d2d61f 100644 --- a/ash/accelerators/accelerator_controller.h +++ b/ash/accelerators/accelerator_controller.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -21,6 +21,7 @@ class AcceleratorManager; namespace ash { class ScreenshotDelegate; +class CapsLockDelegate; // AcceleratorController provides functions for registering or unregistering // global keyboard accelerators, which are handled earlier than any windows. It @@ -56,6 +57,7 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { virtual bool CanHandleAccelerators() const OVERRIDE; void SetScreenshotDelegate(ScreenshotDelegate* screenshot_delegate); + void SetCapsLockDelegate(scoped_ptr<CapsLockDelegate> caps_lock_delegate); private: // Initialize the accelerators this class handles as a target. @@ -64,6 +66,7 @@ class ASH_EXPORT AcceleratorController : public ui::AcceleratorTarget { scoped_ptr<ui::AcceleratorManager> accelerator_manager_; scoped_ptr<ScreenshotDelegate> screenshot_delegate_; + scoped_ptr<CapsLockDelegate> caps_lock_delegate_; // A map from accelerators to the AcceleratorAction values, which are used in // the implementation. diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc index e5dd5d9..9f86b45 100644 --- a/ash/accelerators/accelerator_controller_unittest.cc +++ b/ash/accelerators/accelerator_controller_unittest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "ash/accelerators/accelerator_controller.h" +#include "ash/caps_lock_delegate.h" #include "ash/ime/event.h" #include "ash/screenshot_delegate.h" #include "ash/shell.h" @@ -69,6 +70,30 @@ 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); +}; + bool TestTarget::AcceleratorPressed(const ui::Accelerator& accelerator) { ++accelerator_pressed_count_; return true; @@ -248,19 +273,42 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) { ui::Accelerator(ui::VKEY_TAB, false, false, true))); // TakeScreenshot // True should always be returned regardless of the existence of the delegate. - EXPECT_TRUE(GetController()->Process( - ui::Accelerator(ui::VKEY_F5, false, true, false))); - EXPECT_TRUE(GetController()->Process( - ui::Accelerator(ui::VKEY_PRINT, false, false, false))); - DummyScreenshotDelegate* delegate = new DummyScreenshotDelegate; - GetController()->SetScreenshotDelegate(delegate); - EXPECT_EQ(0, delegate->handle_take_screenshot_count()); - EXPECT_TRUE(GetController()->Process( - ui::Accelerator(ui::VKEY_F5, false, true, false))); - EXPECT_EQ(1, delegate->handle_take_screenshot_count()); - EXPECT_TRUE(GetController()->Process( - ui::Accelerator(ui::VKEY_PRINT, false, false, false))); - EXPECT_EQ(2, delegate->handle_take_screenshot_count()); + { + EXPECT_TRUE(GetController()->Process( + ui::Accelerator(ui::VKEY_F5, false, true, false))); + EXPECT_TRUE(GetController()->Process( + ui::Accelerator(ui::VKEY_PRINT, false, false, false))); + DummyScreenshotDelegate* delegate = new DummyScreenshotDelegate; + GetController()->SetScreenshotDelegate(delegate); + EXPECT_EQ(0, delegate->handle_take_screenshot_count()); + EXPECT_TRUE(GetController()->Process( + ui::Accelerator(ui::VKEY_F5, false, true, false))); + EXPECT_EQ(1, delegate->handle_take_screenshot_count()); + EXPECT_TRUE(GetController()->Process( + ui::Accelerator(ui::VKEY_PRINT, false, false, false))); + EXPECT_EQ(2, delegate->handle_take_screenshot_count()); + } + // ToggleCapsLock + { + EXPECT_FALSE(GetController()->Process( + ui::Accelerator(ui::VKEY_LWIN, true, false, false))); + 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, true, false, false))); + 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()); + EXPECT_TRUE(GetController()->Process( + ui::Accelerator(ui::VKEY_LWIN, true, false, false))); + EXPECT_EQ(1, delegate->handle_caps_lock_count()); + } #if !defined(NDEBUG) // RotateScreen EXPECT_TRUE(GetController()->Process( diff --git a/ash/ash.gyp b/ash/ash.gyp index d506cf1..a911108 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -60,6 +60,7 @@ 'app_list/drop_shadow_label.h', 'ash_switches.cc', 'ash_switches.h', + 'caps_lock_delegate.h', 'desktop_background/desktop_background_view.cc', 'desktop_background/desktop_background_view.h', 'drag_drop/drag_drop_controller.cc', diff --git a/ash/caps_lock_delegate.h b/ash/caps_lock_delegate.h new file mode 100644 index 0000000..dd843e7 --- /dev/null +++ b/ash/caps_lock_delegate.h @@ -0,0 +1,22 @@ +// 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_H_ +#define ASH_CAPS_LOCK_DELEGATE_H_ +#pragma once + +namespace ash { + +// Delegate for toggling Caps Lock. +class 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; +}; +} // namespace ash + +#endif // ASH_CAPS_LOCK_DELEGATE_H_ |