diff options
author | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-22 05:08:30 +0000 |
---|---|---|
committer | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-22 05:08:30 +0000 |
commit | 745816be61e207da7cef1f839591bfb35bd15fd3 (patch) | |
tree | 60828cb9a38973d9bce185f4013437d58b5dbd82 /ui/aura_shell/shell_accelerator_controller.cc | |
parent | 0f83a23a4d149948d5d5135468fb820bcf7cd543 (diff) | |
download | chromium_src-745816be61e207da7cef1f839591bfb35bd15fd3.zip chromium_src-745816be61e207da7cef1f839591bfb35bd15fd3.tar.gz chromium_src-745816be61e207da7cef1f839591bfb35bd15fd3.tar.bz2 |
Add ShellAcceleratorController that manages global keyboard accelerators.
- Create ShellAcceleratorController that manages global keyboard accelerators and also processes several accelerators as a target.
- Create ShellAcceleratorFilter, which is used by DesktopEventFilter to handle accelerators.
- Add a function to Shell for accessing ShellAcceleratorController.
The 1st attempt (http://crrev.com/110637) broke aura_shell_unittests and this fixes it.
The differences are
- moving ShellAcceleratorFilter to Shell from DesktopEventFilter, and
- adding the ShellAcceleratorFilter in Shell initialization code to DesktopEventFilter.
BUG=97255
TEST=Manual, aura_shell_unittests succeeds.
Review URL: http://codereview.chromium.org/8561012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111100 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura_shell/shell_accelerator_controller.cc')
-rw-r--r-- | ui/aura_shell/shell_accelerator_controller.cc | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/ui/aura_shell/shell_accelerator_controller.cc b/ui/aura_shell/shell_accelerator_controller.cc new file mode 100644 index 0000000..9c67a9d --- /dev/null +++ b/ui/aura_shell/shell_accelerator_controller.cc @@ -0,0 +1,126 @@ +// Copyright (c) 2011 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 "ui/aura_shell/shell_accelerator_controller.h" + +#include "ui/aura/desktop.h" +#include "ui/aura/event.h" +#include "ui/aura_shell/shell.h" +#include "ui/base/accelerator_manager.h" +#include "ui/base/models/accelerator.h" +#include "ui/gfx/compositor/layer_animation_sequence.h" +#include "ui/gfx/compositor/layer_animator.h" +#include "ui/gfx/compositor/screen_rotation.h" + +namespace { + +// Acceleraters handled by ShellAcceleratorController. +struct AcceleratorData { + ui::KeyboardCode keycode; + bool shift; + bool ctrl; + bool alt; +} kAcceleratorData[] = { + { ui::VKEY_F11, false, false, false }, + { ui::VKEY_HOME, false, true, false }, +}; + +// Registers the accelerators with ShellAcceleratorController. +void RegisterAccelerators(aura_shell::ShellAcceleratorController* controller) { + for (size_t i = 0; i < arraysize(kAcceleratorData); ++i) { + controller->Register(ui::Accelerator(kAcceleratorData[i].keycode, + kAcceleratorData[i].shift, + kAcceleratorData[i].ctrl, + kAcceleratorData[i].alt), + controller); + } +} + +#if !defined(NDEBUG) +// Rotates the screen. +void RotateScreen() { + static int i = 0; + int delta = 0; + switch (i) { + case 0: delta = 90; break; + case 1: delta = 90; break; + case 2: delta = 90; break; + case 3: delta = 90; break; + case 4: delta = -90; break; + case 5: delta = -90; break; + case 6: delta = -90; break; + case 7: delta = -90; break; + case 8: delta = -90; break; + case 9: delta = 180; break; + case 10: delta = 180; break; + case 11: delta = 90; break; + case 12: delta = 180; break; + case 13: delta = 180; break; + } + i = (i + 1) % 14; + aura::Desktop::GetInstance()->layer()->GetAnimator()->set_preemption_strategy( + ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); + scoped_ptr<ui::LayerAnimationSequence> screen_rotation( + new ui::LayerAnimationSequence(new ui::ScreenRotation(delta))); + screen_rotation->AddObserver(aura::Desktop::GetInstance()); + aura::Desktop::GetInstance()->layer()->GetAnimator()->ScheduleAnimation( + screen_rotation.release()); +} +#endif + +} // namespace + +namespace aura_shell { + +//////////////////////////////////////////////////////////////////////////////// +// ShellAcceleratorController, public: + +ShellAcceleratorController::ShellAcceleratorController() + : accelerator_manager_(new ui::AcceleratorManager) { + RegisterAccelerators(this); +} + +ShellAcceleratorController::~ShellAcceleratorController() { +} + +void ShellAcceleratorController::Register( + const ui::Accelerator& accelerator, + ui::AcceleratorTarget* target) { + accelerator_manager_->Register(accelerator, target); +} + +void ShellAcceleratorController::Unregister( + const ui::Accelerator& accelerator, + ui::AcceleratorTarget* target) { + accelerator_manager_->Unregister(accelerator, target); +} + +void ShellAcceleratorController::UnregisterAll( + ui::AcceleratorTarget* target) { + accelerator_manager_->UnregisterAll(target); +} + +bool ShellAcceleratorController::Process(const ui::Accelerator& accelerator) { + return accelerator_manager_->Process(accelerator); +} + +//////////////////////////////////////////////////////////////////////////////// +// ShellAcceleratorController, ui::AcceleratorTarget implementation: + +bool ShellAcceleratorController::AcceleratorPressed( + const ui::Accelerator& accelerator) { +#if !defined(NDEBUG) + if (accelerator.key_code() == ui::VKEY_F11) { + aura::Desktop::GetInstance()->ToggleFullScreen(); + return true; + } else if (accelerator.key_code() == ui::VKEY_HOME && + accelerator.IsCtrlDown()) { + RotateScreen(); + return true; + } +#endif + return false; +} + +} // namespace aura_shell |