Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: ash/mus/accelerators/accelerator_controller_registrar.cc

Issue 2783613003: Add window cycle completion and cancellation accelerators in mus+ash. (Closed)
Patch Set: cleanup. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/mus/accelerators/accelerator_controller_registrar.h" 5 #include "ash/mus/accelerators/accelerator_controller_registrar.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "ash/common/accelerators/accelerator_controller.h" 9 #include "ash/common/accelerators/accelerator_controller.h"
10 #include "ash/common/accelerators/accelerator_router.h" 10 #include "ash/common/accelerators/accelerator_router.h"
11 #include "ash/common/wm/window_cycle_controller.h"
11 #include "ash/common/wm_shell.h" 12 #include "ash/common/wm_shell.h"
12 #include "ash/mus/accelerators/accelerator_ids.h" 13 #include "ash/mus/accelerators/accelerator_ids.h"
13 #include "ash/mus/window_manager.h" 14 #include "ash/mus/window_manager.h"
14 #include "ash/public/interfaces/event_properties.mojom.h" 15 #include "ash/public/interfaces/event_properties.mojom.h"
15 #include "ash/shell.h" 16 #include "ash/shell.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "services/ui/common/accelerator_util.h" 18 #include "services/ui/common/accelerator_util.h"
18 #include "services/ui/public/cpp/property_type_converters.h" 19 #include "services/ui/public/cpp/property_type_converters.h"
20 #include "ui/base/accelerators/accelerator.h"
19 #include "ui/base/accelerators/accelerator_history.h" 21 #include "ui/base/accelerators/accelerator_history.h"
20 22
21 namespace ash { 23 namespace ash {
22 namespace mus { 24 namespace mus {
23 namespace { 25 namespace {
24 26
27 const ui::Accelerator kWindowCycleCompleteAccelerator(
sky 2017/03/29 22:00:57 Style guide says statics (which include this) shou
28 ui::KeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_MENU, 0));
29 const ui::Accelerator kWindowCycleCancelAccelerator(ui::VKEY_ESCAPE,
30 ui::EF_ALT_DOWN);
31
25 // Callback from registering the accelerators. 32 // Callback from registering the accelerators.
26 void OnAcceleratorsAdded(const std::vector<ui::Accelerator>& accelerators, 33 void OnAcceleratorsAdded(const std::vector<ui::Accelerator>& accelerators,
27 bool added) { 34 bool added) {
28 // All our accelerators should be registered, so we expect |added| to be true. 35 // All our accelerators should be registered, so we expect |added| to be true.
29 DCHECK(added) << "Unexpected accelerator vector registration failure."; 36 DCHECK(added) << "Unexpected accelerator vector registration failure.";
30 } 37 }
31 38
32 } // namespace 39 } // namespace
33 40
34 AcceleratorControllerRegistrar::AcceleratorControllerRegistrar( 41 AcceleratorControllerRegistrar::AcceleratorControllerRegistrar(
35 WindowManager* window_manager, 42 WindowManager* window_manager,
36 uint16_t id_namespace) 43 uint16_t id_namespace)
37 : window_manager_(window_manager), 44 : window_manager_(window_manager),
38 id_namespace_(id_namespace), 45 id_namespace_(id_namespace),
39 next_id_(0), 46 next_id_(0),
40 router_(new AcceleratorRouter) { 47 router_(new AcceleratorRouter) {
41 window_manager_->AddAcceleratorHandler(id_namespace, this); 48 window_manager_->AddAcceleratorHandler(id_namespace, this);
49 RegisterWindowCycleAccelerators();
42 } 50 }
43 51
44 AcceleratorControllerRegistrar::~AcceleratorControllerRegistrar() { 52 AcceleratorControllerRegistrar::~AcceleratorControllerRegistrar() {
45 window_manager_->RemoveAcceleratorHandler(id_namespace_); 53 window_manager_->RemoveAcceleratorHandler(id_namespace_);
46 54
47 if (!window_manager_->window_manager_client()) 55 if (!window_manager_->window_manager_client())
48 return; 56 return;
49 57
50 // TODO(sky): consider not doing this. If we assume the destructor is called 58 // TODO(sky): consider not doing this. If we assume the destructor is called
51 // during shutdown, then this is unnecessary and results in a bunch of 59 // during shutdown, then this is unnecessary and results in a bunch of
(...skipping 23 matching lines...) Expand all
75 if (is_pre) { 83 if (is_pre) {
76 // TODO(sky): this does not exactly match ash code. In particular ash code 84 // TODO(sky): this does not exactly match ash code. In particular ash code
77 // is called for *all* key events, where as this is only called for 85 // is called for *all* key events, where as this is only called for
78 // registered accelerators. This means the previous accelerator isn't the 86 // registered accelerators. This means the previous accelerator isn't the
79 // same as it was in ash. We need to figure out exactly what is needed of 87 // same as it was in ash. We need to figure out exactly what is needed of
80 // previous accelerator so that we can either register for the right set of 88 // previous accelerator so that we can either register for the right set of
81 // accelerators, or make WS send the previous accelerator. 89 // accelerators, or make WS send the previous accelerator.
82 // http://crbug.com/630683. 90 // http://crbug.com/630683.
83 accelerator_controller->accelerator_history()->StoreCurrentAccelerator( 91 accelerator_controller->accelerator_history()->StoreCurrentAccelerator(
84 accelerator); 92 accelerator);
93 if (HandleWindowCycleAccelerator(accelerator))
94 return ui::mojom::EventResult::HANDLED;
85 WmWindow* target_window = WmShell::Get()->GetFocusedWindow(); 95 WmWindow* target_window = WmShell::Get()->GetFocusedWindow();
86 if (!target_window) 96 if (!target_window)
87 target_window = Shell::GetWmRootWindowForNewWindows(); 97 target_window = Shell::GetWmRootWindowForNewWindows();
88 DCHECK(target_window); 98 DCHECK(target_window);
89 if (router_->ProcessAccelerator(target_window, *(event.AsKeyEvent()), 99 if (router_->ProcessAccelerator(target_window, *(event.AsKeyEvent()),
90 accelerator)) { 100 accelerator)) {
91 return ui::mojom::EventResult::HANDLED; 101 return ui::mojom::EventResult::HANDLED;
92 } 102 }
93 if (accelerator_controller->IsActionForAcceleratorEnabled(accelerator)) { 103 if (accelerator_controller->IsActionForAcceleratorEnabled(accelerator)) {
94 // We do have an accelerator for the key. Set a property so that the real 104 // We do have an accelerator for the key. Set a property so that the real
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 uint16_t AcceleratorControllerRegistrar::GetNextLocalAcceleratorId() { 188 uint16_t AcceleratorControllerRegistrar::GetNextLocalAcceleratorId() {
179 DCHECK_LT(ids_.size(), std::numeric_limits<uint16_t>::max()); 189 DCHECK_LT(ids_.size(), std::numeric_limits<uint16_t>::max());
180 // Common case is we never wrap once, so this is typically cheap. Additionally 190 // Common case is we never wrap once, so this is typically cheap. Additionally
181 // we expect there not to be too many accelerators. 191 // we expect there not to be too many accelerators.
182 while (ids_.count(next_id_) > 0) 192 while (ids_.count(next_id_) > 0)
183 ++next_id_; 193 ++next_id_;
184 ids_.insert(next_id_); 194 ids_.insert(next_id_);
185 return next_id_++; 195 return next_id_++;
186 } 196 }
187 197
198 void AcceleratorControllerRegistrar::RegisterWindowCycleAccelerators() {
199 std::vector<ui::Accelerator> accelerators;
200 accelerators.push_back(kWindowCycleCompleteAccelerator);
201 accelerators.push_back(kWindowCycleCancelAccelerator);
202 OnAcceleratorsRegistered(accelerators);
203 }
204
205 bool AcceleratorControllerRegistrar::HandleWindowCycleAccelerator(
206 const ui::Accelerator& accelerator) {
207 ash::WindowCycleController* window_cycle_controller =
208 Shell::Get()->window_cycle_controller();
209 if (!window_cycle_controller->IsCycling())
210 return false;
211
212 if (accelerator == kWindowCycleCompleteAccelerator) {
213 window_cycle_controller->CompleteCycling();
214 return true;
215 }
216
217 if (accelerator == kWindowCycleCancelAccelerator) {
218 window_cycle_controller->CancelCycling();
219 return true;
220 }
221
222 return false;
223 }
224
188 } // namespace mus 225 } // namespace mus
189 } // namespace ash 226 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/accelerators/accelerator_controller_registrar.h ('k') | services/ui/ws/event_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698