Chromium Code Reviews| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 event_matcher->accelerator_phase = ui::mojom::AcceleratorPhase::PRE_TARGET; | 118 event_matcher->accelerator_phase = ui::mojom::AcceleratorPhase::PRE_TARGET; |
| 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 ui::mojom::AcceleratorEventPtr accelerator_pre_event( | |
|
mfomitchev
2016/11/22 22:44:16
This doesn't make much sense. You are just creatin
mfomitchev
2016/11/22 23:07:13
Nvm, I guess you have to do this b/c you removed t
thanhph
2016/11/24 16:10:12
Thanks! I created a wrapper around single pair of
| |
| 129 ui::mojom::AcceleratorEvent::New()); | |
| 130 accelerator_pre_event->id = ComputeAcceleratorId(id_namespace_, ids.pre_id); | |
| 131 accelerator_pre_event->event_matcher = std::move(event_matcher); | |
| 132 | |
| 133 mojo::Array<ui::mojom::AcceleratorEventPtr> pre_multi_accelerators; | |
| 134 pre_multi_accelerators.push_back(std::move(accelerator_pre_event)); | |
| 128 | 135 |
| 129 window_manager_->window_manager_client()->AddAccelerator( | 136 window_manager_->window_manager_client()->AddAccelerator( |
| 130 ComputeAcceleratorId(id_namespace_, ids.pre_id), std::move(event_matcher), | 137 std::move(pre_multi_accelerators), |
| 131 base::Bind(OnAcceleratorAdded, accelerator)); | 138 base::Bind(OnAcceleratorAdded, accelerator)); |
| 139 | |
| 140 ui::mojom::AcceleratorEventPtr accelerator_post_event( | |
| 141 ui::mojom::AcceleratorEvent::New()); | |
| 142 accelerator_post_event->id = ComputeAcceleratorId(id_namespace_, ids.post_id); | |
| 143 accelerator_post_event->event_matcher = std::move(post_event_matcher); | |
| 144 | |
| 145 mojo::Array<ui::mojom::AcceleratorEventPtr> post_multi_accelerators; | |
| 146 post_multi_accelerators.push_back(std::move(accelerator_post_event)); | |
| 147 | |
| 132 window_manager_->window_manager_client()->AddAccelerator( | 148 window_manager_->window_manager_client()->AddAccelerator( |
| 133 ComputeAcceleratorId(id_namespace_, ids.post_id), | 149 std::move(post_multi_accelerators), |
| 134 std::move(post_event_matcher), | |
| 135 base::Bind(OnAcceleratorAdded, accelerator)); | 150 base::Bind(OnAcceleratorAdded, accelerator)); |
| 136 } | 151 } |
| 137 | 152 |
| 138 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( | 153 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( |
| 139 const ui::Accelerator& accelerator) { | 154 const ui::Accelerator& accelerator) { |
| 140 auto iter = accelerator_to_ids_.find(accelerator); | 155 auto iter = accelerator_to_ids_.find(accelerator); |
| 141 DCHECK(iter != accelerator_to_ids_.end()); | 156 DCHECK(iter != accelerator_to_ids_.end()); |
| 142 Ids ids = iter->second; | 157 Ids ids = iter->second; |
| 143 accelerator_to_ids_.erase(iter); | 158 accelerator_to_ids_.erase(iter); |
| 144 ids_.erase(ids.pre_id); | 159 ids_.erase(ids.pre_id); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 163 // Common case is we never wrap once, so this is typically cheap. Additionally | 178 // Common case is we never wrap once, so this is typically cheap. Additionally |
| 164 // we expect there not to be too many accelerators. | 179 // we expect there not to be too many accelerators. |
| 165 while (ids_.count(next_id_) > 0) | 180 while (ids_.count(next_id_) > 0) |
| 166 ++next_id_; | 181 ++next_id_; |
| 167 ids_.insert(next_id_); | 182 ids_.insert(next_id_); |
| 168 return next_id_++; | 183 return next_id_++; |
| 169 } | 184 } |
| 170 | 185 |
| 171 } // namespace mus | 186 } // namespace mus |
| 172 } // namespace ash | 187 } // namespace ash |
| OLD | NEW |