| 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" |
| 11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 12 #include "ash/mus/accelerators/accelerator_ids.h" | 12 #include "ash/mus/accelerators/accelerator_ids.h" |
| 13 #include "ash/mus/bridge/wm_window_mus.h" | 13 #include "ash/mus/bridge/wm_window_mus.h" |
| 14 #include "ash/mus/window_manager.h" | 14 #include "ash/mus/window_manager.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "services/ui/common/event_matcher_util.h" | 16 #include "services/ui/common/event_matcher_util.h" |
| 17 #include "services/ui/public/cpp/window_manager_delegate.h" | 17 #include "services/ui/public/cpp/window_manager_delegate.h" |
| 18 #include "services/ui/public/cpp/window_tree_client.h" | 18 #include "services/ui/public/cpp/window_tree_client.h" |
| 19 #include "ui/base/accelerators/accelerator_history.h" | 19 #include "ui/base/accelerators/accelerator_history.h" |
| 20 | 20 |
| 21 namespace ash { | 21 namespace ash { |
| 22 namespace mus { | 22 namespace mus { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Callback from registering the accelerator. All our accelerators should be | 25 // Callback from registering the accelerator. |
| 26 // registered, so we expect |added| to be true. | 26 void OnAcceleratorAdded(const ui::Accelerator& accelerator, bool added) { |
| 27 void OnAcceleratorAdded(bool added) { | 27 // All our accelerators should be registered, so we expect |added| to be true. |
| 28 DCHECK(added); | 28 DCHECK(added) << "duplicate accelerator key_code=" << accelerator.key_code() |
| 29 << " type=" << accelerator.type() |
| 30 << " modifiers=" << accelerator.modifiers(); |
| 29 } | 31 } |
| 30 | 32 |
| 31 } // namespace | 33 } // namespace |
| 32 | 34 |
| 33 AcceleratorControllerRegistrar::AcceleratorControllerRegistrar( | 35 AcceleratorControllerRegistrar::AcceleratorControllerRegistrar( |
| 34 WindowManager* window_manager, | 36 WindowManager* window_manager, |
| 35 uint16_t id_namespace) | 37 uint16_t id_namespace) |
| 36 : window_manager_(window_manager), | 38 : window_manager_(window_manager), |
| 37 id_namespace_(id_namespace), | 39 id_namespace_(id_namespace), |
| 38 next_id_(0), | 40 next_id_(0), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 event_matcher->type_matcher->type = accelerator.type() == ui::ET_KEY_PRESSED | 121 event_matcher->type_matcher->type = accelerator.type() == ui::ET_KEY_PRESSED |
| 120 ? ui::mojom::EventType::KEY_PRESSED | 122 ? ui::mojom::EventType::KEY_PRESSED |
| 121 : ui::mojom::EventType::KEY_RELEASED; | 123 : ui::mojom::EventType::KEY_RELEASED; |
| 122 | 124 |
| 123 ui::mojom::EventMatcherPtr post_event_matcher = event_matcher.Clone(); | 125 ui::mojom::EventMatcherPtr post_event_matcher = event_matcher.Clone(); |
| 124 post_event_matcher->accelerator_phase = | 126 post_event_matcher->accelerator_phase = |
| 125 ui::mojom::AcceleratorPhase::POST_TARGET; | 127 ui::mojom::AcceleratorPhase::POST_TARGET; |
| 126 | 128 |
| 127 window_manager_->window_manager_client()->AddAccelerator( | 129 window_manager_->window_manager_client()->AddAccelerator( |
| 128 ComputeAcceleratorId(id_namespace_, ids.pre_id), std::move(event_matcher), | 130 ComputeAcceleratorId(id_namespace_, ids.pre_id), std::move(event_matcher), |
| 129 base::Bind(OnAcceleratorAdded)); | 131 base::Bind(OnAcceleratorAdded, accelerator)); |
| 130 window_manager_->window_manager_client()->AddAccelerator( | 132 window_manager_->window_manager_client()->AddAccelerator( |
| 131 ComputeAcceleratorId(id_namespace_, ids.post_id), | 133 ComputeAcceleratorId(id_namespace_, ids.post_id), |
| 132 std::move(post_event_matcher), base::Bind(OnAcceleratorAdded)); | 134 std::move(post_event_matcher), |
| 135 base::Bind(OnAcceleratorAdded, accelerator)); |
| 133 } | 136 } |
| 134 | 137 |
| 135 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( | 138 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( |
| 136 const ui::Accelerator& accelerator) { | 139 const ui::Accelerator& accelerator) { |
| 137 auto iter = accelerator_to_ids_.find(accelerator); | 140 auto iter = accelerator_to_ids_.find(accelerator); |
| 138 DCHECK(iter != accelerator_to_ids_.end()); | 141 DCHECK(iter != accelerator_to_ids_.end()); |
| 139 Ids ids = iter->second; | 142 Ids ids = iter->second; |
| 140 accelerator_to_ids_.erase(iter); | 143 accelerator_to_ids_.erase(iter); |
| 141 ids_.erase(ids.pre_id); | 144 ids_.erase(ids.pre_id); |
| 142 ids_.erase(ids.post_id); | 145 ids_.erase(ids.post_id); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 160 // Common case is we never wrap once, so this is typically cheap. Additionally | 163 // Common case is we never wrap once, so this is typically cheap. Additionally |
| 161 // we expect there not to be too many accelerators. | 164 // we expect there not to be too many accelerators. |
| 162 while (ids_.count(next_id_) > 0) | 165 while (ids_.count(next_id_) > 0) |
| 163 ++next_id_; | 166 ++next_id_; |
| 164 ids_.insert(next_id_); | 167 ids_.insert(next_id_); |
| 165 return next_id_++; | 168 return next_id_++; |
| 166 } | 169 } |
| 167 | 170 |
| 168 } // namespace mus | 171 } // namespace mus |
| 169 } // namespace ash | 172 } // namespace ash |
| OLD | NEW |