| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 WmShell::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::AcceleratorPtr> 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); |
| 107 | 107 |
| 108 window_manager_->window_manager_client()->AddAccelerators( | 108 window_manager_->window_manager_client()->AddAccelerators( |
| 109 std::move(accelerator_vector), | 109 std::move(accelerator_vector), |
| 110 base::Bind(OnAcceleratorsAdded, accelerators)); | 110 base::Bind(OnAcceleratorsAdded, accelerators)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( | 113 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( |
| 114 const ui::Accelerator& accelerator) { | 114 const ui::Accelerator& accelerator) { |
| 115 auto iter = accelerator_to_ids_.find(accelerator); | 115 auto iter = accelerator_to_ids_.find(accelerator); |
| 116 DCHECK(iter != accelerator_to_ids_.end()); | 116 DCHECK(iter != accelerator_to_ids_.end()); |
| 117 Ids ids = iter->second; | 117 Ids ids = iter->second; |
| 118 accelerator_to_ids_.erase(iter); | 118 accelerator_to_ids_.erase(iter); |
| 119 ids_.erase(ids.pre_id); | 119 ids_.erase(ids.pre_id); |
| 120 ids_.erase(ids.post_id); | 120 ids_.erase(ids.post_id); |
| 121 DCHECK_EQ(accelerator_to_ids_.size() * 2, ids_.size()); | 121 DCHECK_EQ(accelerator_to_ids_.size() * 2, ids_.size()); |
| 122 window_manager_->window_manager_client()->RemoveAccelerator( | 122 window_manager_->window_manager_client()->RemoveAccelerator( |
| 123 ComputeAcceleratorId(id_namespace_, ids.pre_id)); | 123 ComputeAcceleratorId(id_namespace_, ids.pre_id)); |
| 124 window_manager_->window_manager_client()->RemoveAccelerator( | 124 window_manager_->window_manager_client()->RemoveAccelerator( |
| 125 ComputeAcceleratorId(id_namespace_, ids.post_id)); | 125 ComputeAcceleratorId(id_namespace_, ids.post_id)); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void AcceleratorControllerRegistrar::AddAcceleratorToVector( | 128 void AcceleratorControllerRegistrar::AddAcceleratorToVector( |
| 129 const ui::Accelerator& accelerator, | 129 const ui::Accelerator& accelerator, |
| 130 std::vector<ui::mojom::AcceleratorPtr>& accelerator_vector) { | 130 std::vector<ui::mojom::WmAcceleratorPtr>& accelerator_vector) { |
| 131 Ids ids; | 131 Ids ids; |
| 132 if (!GenerateIds(&ids)) { | 132 if (!GenerateIds(&ids)) { |
| 133 LOG(ERROR) << "max number of accelerators registered, dropping request"; | 133 LOG(ERROR) << "max number of accelerators registered, dropping request"; |
| 134 return; | 134 return; |
| 135 } | 135 } |
| 136 DCHECK_EQ(0u, accelerator_to_ids_.count(accelerator)); | 136 DCHECK_EQ(0u, accelerator_to_ids_.count(accelerator)); |
| 137 accelerator_to_ids_[accelerator] = ids; | 137 accelerator_to_ids_[accelerator] = ids; |
| 138 DCHECK_EQ(accelerator_to_ids_.size() * 2, ids_.size()); | 138 DCHECK_EQ(accelerator_to_ids_.size() * 2, ids_.size()); |
| 139 | 139 |
| 140 ui::mojom::EventMatcherPtr pre_event_matcher = ui::CreateKeyMatcher( | 140 ui::mojom::EventMatcherPtr pre_event_matcher = ui::CreateKeyMatcher( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // Common case is we never wrap once, so this is typically cheap. Additionally | 175 // Common case is we never wrap once, so this is typically cheap. Additionally |
| 176 // we expect there not to be too many accelerators. | 176 // we expect there not to be too many accelerators. |
| 177 while (ids_.count(next_id_) > 0) | 177 while (ids_.count(next_id_) > 0) |
| 178 ++next_id_; | 178 ++next_id_; |
| 179 ids_.insert(next_id_); | 179 ids_.insert(next_id_); |
| 180 return next_id_++; | 180 return next_id_++; |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace mus | 183 } // namespace mus |
| 184 } // namespace ash | 184 } // namespace ash |
| OLD | NEW |