Chromium Code Reviews| Index: ui/aura_shell/shell_accelerator_controller.cc |
| diff --git a/ui/aura_shell/shell_accelerator_controller.cc b/ui/aura_shell/shell_accelerator_controller.cc |
| index 99f12a444d4765c3359dacb32bfdea1fc27277d9..28f6ffdf40cf1f2e53b6b098f0fb05cb797f740e 100644 |
| --- a/ui/aura_shell/shell_accelerator_controller.cc |
| +++ b/ui/aura_shell/shell_accelerator_controller.cc |
| @@ -4,6 +4,7 @@ |
| #include "ui/aura_shell/shell_accelerator_controller.h" |
| +#include "base/logging.h" |
| #include "ui/aura/desktop.h" |
| #include "ui/aura/event.h" |
| #include "ui/aura_shell/shell.h" |
| @@ -15,31 +16,55 @@ |
| namespace { |
| +enum AcceleratorAction { |
| + CYCLE_BACKWARD, |
| + CYCLE_FORWARD, |
| + TAKE_SCREENSHOT, |
| +#if !defined(NDEBUG) |
| + ROTATE_SCREEN, |
| + TOGGLE_DESKTOP_FULL_SCREEN, |
| +#endif |
| +}; |
| + |
| // Acceleraters handled by ShellAcceleratorController. |
| struct AcceleratorData { |
| ui::KeyboardCode keycode; |
| bool shift; |
| bool ctrl; |
| bool alt; |
| + AcceleratorAction action; |
| } kAcceleratorData[] = { |
| - { ui::VKEY_F11, false, false, false }, |
| - { ui::VKEY_HOME, false, true, false }, |
| + { ui::VKEY_TAB, true, false, true, CYCLE_BACKWARD }, |
| + { ui::VKEY_TAB, false, false, true, CYCLE_FORWARD }, |
| + { ui::VKEY_F5, false, true, false, TAKE_SCREENSHOT }, |
| + { ui::VKEY_PRINT, false, false, false, TAKE_SCREENSHOT }, |
| +#if !defined(NDEBUG) |
| + { ui::VKEY_HOME, false, true, false, ROTATE_SCREEN }, |
| + { ui::VKEY_F11, false, true, false, TOGGLE_DESKTOP_FULL_SCREEN }, |
| +#endif |
| }; |
| -// 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); |
| - } |
| +bool CycleBackward() { |
| + // TODO(mazda): http://crbug.com/105204 |
| + NOTIMPLEMENTED(); |
| + return false; |
| +} |
| + |
| +bool CycleForwrard() { |
|
Daniel Erat
2011/11/30 20:47:36
one more (extra 'r' after the 'w') :-)
mazda
2011/12/01 06:06:19
Done...
|
| + // TODO(mazda): http://crbug.com/105204 |
| + NOTIMPLEMENTED(); |
| + return false; |
| +} |
| + |
| +bool TakeScreenshot() { |
| + // TODO(mazda): http://crbug.com/105198 |
| + NOTIMPLEMENTED(); |
| + return false; |
| } |
| #if !defined(NDEBUG) |
| // Rotates the screen. |
| -void RotateScreen() { |
| +bool RotateScreen() { |
| static int i = 0; |
| int delta = 0; |
| switch (i) { |
| @@ -66,6 +91,12 @@ void RotateScreen() { |
| screen_rotation->AddObserver(aura::Desktop::GetInstance()); |
| aura::Desktop::GetInstance()->layer()->GetAnimator()->ScheduleAnimation( |
| screen_rotation.release()); |
| + return true; |
| +} |
| + |
| +bool ToggleDesktopFullScreen() { |
| + aura::Desktop::GetInstance()->ToggleFullScreen(); |
| + return true; |
| } |
| #endif |
| @@ -78,12 +109,24 @@ namespace aura_shell { |
| ShellAcceleratorController::ShellAcceleratorController() |
| : accelerator_manager_(new ui::AcceleratorManager) { |
| - RegisterAccelerators(this); |
| + Init(); |
| } |
| ShellAcceleratorController::~ShellAcceleratorController() { |
| } |
| +void ShellAcceleratorController::Init() { |
| + for (size_t i = 0; i < arraysize(kAcceleratorData); ++i) { |
| + ui::Accelerator accelerator(kAcceleratorData[i].keycode, |
| + kAcceleratorData[i].shift, |
| + kAcceleratorData[i].ctrl, |
| + kAcceleratorData[i].alt); |
| + Register(accelerator, this); |
| + accelerators_.insert(std::make_pair(accelerator, |
| + kAcceleratorData[i].action)); |
| + } |
| +} |
| + |
| void ShellAcceleratorController::Register( |
| const ui::Accelerator& accelerator, |
| ui::AcceleratorTarget* target) { |
| @@ -110,16 +153,25 @@ bool ShellAcceleratorController::Process(const ui::Accelerator& accelerator) { |
| bool ShellAcceleratorController::AcceleratorPressed( |
| const ui::Accelerator& accelerator) { |
| + std::map<ui::Accelerator, int>::const_iterator i = |
| + accelerators_.find(accelerator); |
| + DCHECK(i != accelerators_.end()); |
| + switch (static_cast<AcceleratorAction>(i->second)) { |
| + case CYCLE_BACKWARD: |
| + return CycleBackward(); |
| + case CYCLE_FORWARD: |
| + return CycleForwrard(); |
| + case TAKE_SCREENSHOT: |
| + return TakeScreenshot(); |
| #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; |
| - } |
| + case ROTATE_SCREEN: |
| + return RotateScreen(); |
| + case TOGGLE_DESKTOP_FULL_SCREEN: |
| + return ToggleDesktopFullScreen(); |
| #endif |
| + default: |
| + NOTREACHED(); |
| + } |
| return false; |
| } |