| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 DCHECK(accelerator.type() == ui::ET_KEY_PRESSED || | 119 DCHECK(accelerator.type() == ui::ET_KEY_PRESSED || |
| 120 accelerator.type() == ui::ET_KEY_RELEASED); | 120 accelerator.type() == ui::ET_KEY_RELEASED); |
| 121 event_matcher->type_matcher->type = accelerator.type() == ui::ET_KEY_PRESSED | 121 event_matcher->type_matcher->type = accelerator.type() == ui::ET_KEY_PRESSED |
| 122 ? ui::mojom::EventType::KEY_PRESSED | 122 ? ui::mojom::EventType::KEY_PRESSED |
| 123 : ui::mojom::EventType::KEY_RELEASED; | 123 : ui::mojom::EventType::KEY_RELEASED; |
| 124 | 124 |
| 125 ui::mojom::EventMatcherPtr post_event_matcher = event_matcher.Clone(); | 125 ui::mojom::EventMatcherPtr post_event_matcher = event_matcher.Clone(); |
| 126 post_event_matcher->accelerator_phase = | 126 post_event_matcher->accelerator_phase = |
| 127 ui::mojom::AcceleratorPhase::POST_TARGET; | 127 ui::mojom::AcceleratorPhase::POST_TARGET; |
| 128 | 128 |
| 129 window_manager_->window_manager_client()->AddAccelerators( | 129 window_manager_->window_manager_client()->AddAccelerator( |
| 130 ui::CreateAcceleratorVector( | 130 ComputeAcceleratorId(id_namespace_, ids.pre_id), std::move(event_matcher), |
| 131 ComputeAcceleratorId(id_namespace_, ids.pre_id), | |
| 132 std::move(event_matcher)), | |
| 133 base::Bind(OnAcceleratorAdded, accelerator)); | 131 base::Bind(OnAcceleratorAdded, accelerator)); |
| 134 | 132 |
| 135 window_manager_->window_manager_client()->AddAccelerators( | 133 window_manager_->window_manager_client()->AddAccelerator( |
| 136 ui::CreateAcceleratorVector( | 134 ComputeAcceleratorId(id_namespace_, ids.post_id), |
| 137 ComputeAcceleratorId(id_namespace_, ids.post_id), | 135 std::move(post_event_matcher), |
| 138 std::move(post_event_matcher)), | |
| 139 base::Bind(OnAcceleratorAdded, accelerator)); | 136 base::Bind(OnAcceleratorAdded, accelerator)); |
| 140 } | 137 } |
| 141 | 138 |
| 142 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( | 139 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( |
| 143 const ui::Accelerator& accelerator) { | 140 const ui::Accelerator& accelerator) { |
| 144 auto iter = accelerator_to_ids_.find(accelerator); | 141 auto iter = accelerator_to_ids_.find(accelerator); |
| 145 DCHECK(iter != accelerator_to_ids_.end()); | 142 DCHECK(iter != accelerator_to_ids_.end()); |
| 146 Ids ids = iter->second; | 143 Ids ids = iter->second; |
| 147 accelerator_to_ids_.erase(iter); | 144 accelerator_to_ids_.erase(iter); |
| 148 ids_.erase(ids.pre_id); | 145 ids_.erase(ids.pre_id); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 167 // Common case is we never wrap once, so this is typically cheap. Additionally | 164 // Common case is we never wrap once, so this is typically cheap. Additionally |
| 168 // we expect there not to be too many accelerators. | 165 // we expect there not to be too many accelerators. |
| 169 while (ids_.count(next_id_) > 0) | 166 while (ids_.count(next_id_) > 0) |
| 170 ++next_id_; | 167 ++next_id_; |
| 171 ids_.insert(next_id_); | 168 ids_.insert(next_id_); |
| 172 return next_id_++; | 169 return next_id_++; |
| 173 } | 170 } |
| 174 | 171 |
| 175 } // namespace mus | 172 } // namespace mus |
| 176 } // namespace ash | 173 } // namespace ash |
| OLD | NEW |