Chromium Code Reviews| Index: ash/mus/accelerators/accelerator_controller_registrar.cc |
| diff --git a/ash/mus/accelerators/accelerator_controller_registrar.cc b/ash/mus/accelerators/accelerator_controller_registrar.cc |
| index e783e463fb2bbb6747c1978ff72857e1a8d3712d..b5710a5505a8314bdfa8a5d08e69e5ac89d34bfa 100644 |
| --- a/ash/mus/accelerators/accelerator_controller_registrar.cc |
| +++ b/ash/mus/accelerators/accelerator_controller_registrar.cc |
| @@ -8,6 +8,7 @@ |
| #include "ash/common/accelerators/accelerator_controller.h" |
| #include "ash/common/accelerators/accelerator_router.h" |
| +#include "ash/common/wm/window_cycle_controller.h" |
| #include "ash/common/wm_shell.h" |
| #include "ash/mus/accelerators/accelerator_ids.h" |
| #include "ash/mus/window_manager.h" |
| @@ -16,12 +17,18 @@ |
| #include "base/logging.h" |
| #include "services/ui/common/accelerator_util.h" |
| #include "services/ui/public/cpp/property_type_converters.h" |
| +#include "ui/base/accelerators/accelerator.h" |
| #include "ui/base/accelerators/accelerator_history.h" |
| namespace ash { |
| namespace mus { |
| namespace { |
| +const ui::Accelerator kWindowCycleCompleteAccelerator( |
|
sky
2017/03/29 22:00:57
Style guide says statics (which include this) shou
|
| + ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_MENU, 0)); |
| +const ui::Accelerator kWindowCycleCancelAccelerator(ui::VKEY_ESCAPE, |
| + ui::EF_ALT_DOWN); |
| + |
| // Callback from registering the accelerators. |
| void OnAcceleratorsAdded(const std::vector<ui::Accelerator>& accelerators, |
| bool added) { |
| @@ -39,6 +46,7 @@ AcceleratorControllerRegistrar::AcceleratorControllerRegistrar( |
| next_id_(0), |
| router_(new AcceleratorRouter) { |
| window_manager_->AddAcceleratorHandler(id_namespace, this); |
| + RegisterWindowCycleAccelerators(); |
| } |
| AcceleratorControllerRegistrar::~AcceleratorControllerRegistrar() { |
| @@ -82,6 +90,8 @@ ui::mojom::EventResult AcceleratorControllerRegistrar::OnAccelerator( |
| // http://crbug.com/630683. |
| accelerator_controller->accelerator_history()->StoreCurrentAccelerator( |
| accelerator); |
| + if (HandleWindowCycleAccelerator(accelerator)) |
| + return ui::mojom::EventResult::HANDLED; |
| WmWindow* target_window = WmShell::Get()->GetFocusedWindow(); |
| if (!target_window) |
| target_window = Shell::GetWmRootWindowForNewWindows(); |
| @@ -185,5 +195,32 @@ uint16_t AcceleratorControllerRegistrar::GetNextLocalAcceleratorId() { |
| return next_id_++; |
| } |
| +void AcceleratorControllerRegistrar::RegisterWindowCycleAccelerators() { |
| + std::vector<ui::Accelerator> accelerators; |
| + accelerators.push_back(kWindowCycleCompleteAccelerator); |
| + accelerators.push_back(kWindowCycleCancelAccelerator); |
| + OnAcceleratorsRegistered(accelerators); |
| +} |
| + |
| +bool AcceleratorControllerRegistrar::HandleWindowCycleAccelerator( |
| + const ui::Accelerator& accelerator) { |
| + ash::WindowCycleController* window_cycle_controller = |
| + Shell::Get()->window_cycle_controller(); |
| + if (!window_cycle_controller->IsCycling()) |
| + return false; |
| + |
| + if (accelerator == kWindowCycleCompleteAccelerator) { |
| + window_cycle_controller->CompleteCycling(); |
| + return true; |
| + } |
| + |
| + if (accelerator == kWindowCycleCancelAccelerator) { |
| + window_cycle_controller->CancelCycling(); |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| } // namespace mus |
| } // namespace ash |