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" |
| 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/accelerator_transport_util.h" | |
| 16 #include "services/ui/common/event_matcher_util.h" | 17 #include "services/ui/common/event_matcher_util.h" |
| 17 #include "services/ui/public/cpp/window_manager_delegate.h" | 18 #include "services/ui/public/cpp/window_manager_delegate.h" |
| 18 #include "services/ui/public/cpp/window_tree_client.h" | 19 #include "services/ui/public/cpp/window_tree_client.h" |
| 19 #include "ui/base/accelerators/accelerator_history.h" | 20 #include "ui/base/accelerators/accelerator_history.h" |
| 20 | 21 |
| 21 namespace ash { | 22 namespace ash { |
| 22 namespace mus { | 23 namespace mus { |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Callback from registering the accelerator. | 26 // Callback from registering the accelerator. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 DCHECK(accelerator.type() == ui::ET_KEY_PRESSED || | 120 DCHECK(accelerator.type() == ui::ET_KEY_PRESSED || |
| 120 accelerator.type() == ui::ET_KEY_RELEASED); | 121 accelerator.type() == ui::ET_KEY_RELEASED); |
| 121 event_matcher->type_matcher->type = accelerator.type() == ui::ET_KEY_PRESSED | 122 event_matcher->type_matcher->type = accelerator.type() == ui::ET_KEY_PRESSED |
| 122 ? ui::mojom::EventType::KEY_PRESSED | 123 ? ui::mojom::EventType::KEY_PRESSED |
| 123 : ui::mojom::EventType::KEY_RELEASED; | 124 : ui::mojom::EventType::KEY_RELEASED; |
| 124 | 125 |
| 125 ui::mojom::EventMatcherPtr post_event_matcher = event_matcher.Clone(); | 126 ui::mojom::EventMatcherPtr post_event_matcher = event_matcher.Clone(); |
| 126 post_event_matcher->accelerator_phase = | 127 post_event_matcher->accelerator_phase = |
| 127 ui::mojom::AcceleratorPhase::POST_TARGET; | 128 ui::mojom::AcceleratorPhase::POST_TARGET; |
| 128 | 129 |
| 129 window_manager_->window_manager_client()->AddAccelerator( | 130 std::vector<ui::mojom::AcceleratorTransportPtr> pre_accelerators; |
| 130 ComputeAcceleratorId(id_namespace_, ids.pre_id), std::move(event_matcher), | 131 pre_accelerators = |
| 131 base::Bind(OnAcceleratorAdded, accelerator)); | 132 AddAcceleratorHelper(std::move(pre_accelerators), |
|
mfomitchev
2016/11/29 01:55:45
You are never passing a non-empty vector to AddAcc
thanhph
2016/11/29 16:50:17
Done, thanks! I use the first approach since the l
| |
| 132 window_manager_->window_manager_client()->AddAccelerator( | 133 ComputeAcceleratorId(id_namespace_, ids.pre_id), |
| 133 ComputeAcceleratorId(id_namespace_, ids.post_id), | 134 std::move(event_matcher)); |
| 134 std::move(post_event_matcher), | 135 |
| 136 window_manager_->window_manager_client()->AddAccelerators( | |
| 137 std::move(pre_accelerators), base::Bind(OnAcceleratorAdded, accelerator)); | |
| 138 | |
| 139 std::vector<ui::mojom::AcceleratorTransportPtr> post_accelerators; | |
| 140 post_accelerators = | |
| 141 AddAcceleratorHelper(std::move(post_accelerators), | |
| 142 ComputeAcceleratorId(id_namespace_, ids.post_id), | |
| 143 std::move(post_event_matcher)); | |
| 144 | |
| 145 window_manager_->window_manager_client()->AddAccelerators( | |
| 146 std::move(post_accelerators), | |
| 135 base::Bind(OnAcceleratorAdded, accelerator)); | 147 base::Bind(OnAcceleratorAdded, accelerator)); |
| 136 } | 148 } |
| 137 | 149 |
| 138 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( | 150 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( |
| 139 const ui::Accelerator& accelerator) { | 151 const ui::Accelerator& accelerator) { |
| 140 auto iter = accelerator_to_ids_.find(accelerator); | 152 auto iter = accelerator_to_ids_.find(accelerator); |
| 141 DCHECK(iter != accelerator_to_ids_.end()); | 153 DCHECK(iter != accelerator_to_ids_.end()); |
| 142 Ids ids = iter->second; | 154 Ids ids = iter->second; |
| 143 accelerator_to_ids_.erase(iter); | 155 accelerator_to_ids_.erase(iter); |
| 144 ids_.erase(ids.pre_id); | 156 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 | 175 // Common case is we never wrap once, so this is typically cheap. Additionally |
| 164 // we expect there not to be too many accelerators. | 176 // we expect there not to be too many accelerators. |
| 165 while (ids_.count(next_id_) > 0) | 177 while (ids_.count(next_id_) > 0) |
| 166 ++next_id_; | 178 ++next_id_; |
| 167 ids_.insert(next_id_); | 179 ids_.insert(next_id_); |
| 168 return next_id_++; | 180 return next_id_++; |
| 169 } | 181 } |
| 170 | 182 |
| 171 } // namespace mus | 183 } // namespace mus |
| 172 } // namespace ash | 184 } // namespace ash |
| OLD | NEW |