OLD | NEW |
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" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 const ui::Accelerator accelerator(*event.AsKeyEvent()); | 63 const ui::Accelerator accelerator(*event.AsKeyEvent()); |
64 auto iter = accelerator_to_ids_.find(accelerator); | 64 auto iter = accelerator_to_ids_.find(accelerator); |
65 if (iter == accelerator_to_ids_.end()) { | 65 if (iter == accelerator_to_ids_.end()) { |
66 // Because of timing we may have unregistered the accelerator already, | 66 // Because of timing we may have unregistered the accelerator already, |
67 // ignore in that case. | 67 // ignore in that case. |
68 return ui::mojom::EventResult::UNHANDLED; | 68 return ui::mojom::EventResult::UNHANDLED; |
69 } | 69 } |
70 | 70 |
71 const Ids& ids = iter->second; | 71 const Ids& ids = iter->second; |
72 AcceleratorController* accelerator_controller = | 72 AcceleratorController* accelerator_controller = |
73 WmShell::Get()->accelerator_controller(); | 73 Shell::Get()->accelerator_controller(); |
74 const bool is_pre = GetAcceleratorLocalId(id) == ids.pre_id; | 74 const bool is_pre = GetAcceleratorLocalId(id) == ids.pre_id; |
75 if (is_pre) { | 75 if (is_pre) { |
76 // TODO(sky): this does not exactly match ash code. In particular ash code | 76 // 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 | 77 // is called for *all* key events, where as this is only called for |
78 // registered accelerators. This means the previous accelerator isn't the | 78 // 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 | 79 // 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 | 80 // previous accelerator so that we can either register for the right set of |
81 // accelerators, or make WS send the previous accelerator. | 81 // accelerators, or make WS send the previous accelerator. |
82 // http://crbug.com/630683. | 82 // http://crbug.com/630683. |
83 accelerator_controller->accelerator_history()->StoreCurrentAccelerator( | 83 accelerator_controller->accelerator_history()->StoreCurrentAccelerator( |
84 accelerator); | 84 accelerator); |
85 WmWindow* target_window = WmShell::Get()->GetFocusedWindow(); | 85 WmWindow* target_window = WmShell::Get()->GetFocusedWindow(); |
86 if (!target_window) | 86 if (!target_window) |
87 target_window = Shell::GetWmRootWindowForNewWindows(); | 87 target_window = Shell::GetWmRootWindowForNewWindows(); |
88 DCHECK(target_window); | 88 DCHECK(target_window); |
89 return router_->ProcessAccelerator(target_window, *(event.AsKeyEvent()), | 89 return router_->ProcessAccelerator(target_window, *(event.AsKeyEvent()), |
90 accelerator) | 90 accelerator) |
91 ? ui::mojom::EventResult::HANDLED | 91 ? ui::mojom::EventResult::HANDLED |
92 : ui::mojom::EventResult::UNHANDLED; | 92 : ui::mojom::EventResult::UNHANDLED; |
93 } | 93 } |
94 DCHECK_EQ(GetAcceleratorLocalId(id), ids.post_id); | 94 DCHECK_EQ(GetAcceleratorLocalId(id), ids.post_id); |
95 // NOTE: for post return value doesn't really matter. | 95 // NOTE: for post return value doesn't really matter. |
96 return WmShell::Get()->accelerator_controller()->Process(accelerator) | 96 return Shell::Get()->accelerator_controller()->Process(accelerator) |
97 ? ui::mojom::EventResult::HANDLED | 97 ? ui::mojom::EventResult::HANDLED |
98 : ui::mojom::EventResult::UNHANDLED; | 98 : ui::mojom::EventResult::UNHANDLED; |
99 } | 99 } |
100 | 100 |
101 void AcceleratorControllerRegistrar::OnAcceleratorsRegistered( | 101 void AcceleratorControllerRegistrar::OnAcceleratorsRegistered( |
102 const std::vector<ui::Accelerator>& accelerators) { | 102 const std::vector<ui::Accelerator>& accelerators) { |
103 std::vector<ui::mojom::WmAcceleratorPtr> accelerator_vector; | 103 std::vector<ui::mojom::WmAcceleratorPtr> accelerator_vector; |
104 | 104 |
105 for (const ui::Accelerator& accelerator : accelerators) | 105 for (const ui::Accelerator& accelerator : accelerators) |
106 AddAcceleratorToVector(accelerator, accelerator_vector); | 106 AddAcceleratorToVector(accelerator, accelerator_vector); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // Common case is we never wrap once, so this is typically cheap. Additionally | 173 // Common case is we never wrap once, so this is typically cheap. Additionally |
174 // we expect there not to be too many accelerators. | 174 // we expect there not to be too many accelerators. |
175 while (ids_.count(next_id_) > 0) | 175 while (ids_.count(next_id_) > 0) |
176 ++next_id_; | 176 ++next_id_; |
177 ids_.insert(next_id_); | 177 ids_.insert(next_id_); |
178 return next_id_++; | 178 return next_id_++; |
179 } | 179 } |
180 | 180 |
181 } // namespace mus | 181 } // namespace mus |
182 } // namespace ash | 182 } // namespace ash |
OLD | NEW |