Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: ash/mus/accelerators/accelerator_controller_registrar.cc

Issue 2520093003: WindowManagerClient::AddAccelerator() should take an array (Closed)
Patch Set: Rename/refactor code. Add unit test for multiple accelerators. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ash/mus/window_manager.cc » ('j') | services/ui/common/accelerator_util.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/accelerator_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. 25 // Callback from registering the accelerator.
26 void OnAcceleratorAdded(const ui::Accelerator& accelerator, bool added) { 26 void OnAcceleratorAdded(const ui::Accelerator& accelerator, bool added) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()->AddAccelerator( 129 std::vector<ui::mojom::AcceleratorTransportPtr> pre_accelerators;
mfomitchev 2016/11/29 17:37:26 Don't declare the variable on a separate line and
thanhph 2016/11/29 19:06:41 Done, thanks!
130 ComputeAcceleratorId(id_namespace_, ids.pre_id), std::move(event_matcher), 130 pre_accelerators =
131 base::Bind(OnAcceleratorAdded, accelerator)); 131 AddAcceleratorHelper(ComputeAcceleratorId(id_namespace_, ids.pre_id),
132 window_manager_->window_manager_client()->AddAccelerator( 132 std::move(event_matcher));
133 ComputeAcceleratorId(id_namespace_, ids.post_id), 133
134 std::move(post_event_matcher), 134 window_manager_->window_manager_client()->AddAccelerators(
135 std::move(pre_accelerators), base::Bind(OnAcceleratorAdded, accelerator));
136
137 std::vector<ui::mojom::AcceleratorTransportPtr> post_accelerators;
138 post_accelerators =
139 AddAcceleratorHelper(ComputeAcceleratorId(id_namespace_, ids.post_id),
140 std::move(post_event_matcher));
141
142 window_manager_->window_manager_client()->AddAccelerators(
143 std::move(post_accelerators),
135 base::Bind(OnAcceleratorAdded, accelerator)); 144 base::Bind(OnAcceleratorAdded, accelerator));
136 } 145 }
137 146
138 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( 147 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered(
139 const ui::Accelerator& accelerator) { 148 const ui::Accelerator& accelerator) {
140 auto iter = accelerator_to_ids_.find(accelerator); 149 auto iter = accelerator_to_ids_.find(accelerator);
141 DCHECK(iter != accelerator_to_ids_.end()); 150 DCHECK(iter != accelerator_to_ids_.end());
142 Ids ids = iter->second; 151 Ids ids = iter->second;
143 accelerator_to_ids_.erase(iter); 152 accelerator_to_ids_.erase(iter);
144 ids_.erase(ids.pre_id); 153 ids_.erase(ids.pre_id);
(...skipping 18 matching lines...) Expand all
163 // Common case is we never wrap once, so this is typically cheap. Additionally 172 // Common case is we never wrap once, so this is typically cheap. Additionally
164 // we expect there not to be too many accelerators. 173 // we expect there not to be too many accelerators.
165 while (ids_.count(next_id_) > 0) 174 while (ids_.count(next_id_) > 0)
166 ++next_id_; 175 ++next_id_;
167 ids_.insert(next_id_); 176 ids_.insert(next_id_);
168 return next_id_++; 177 return next_id_++;
169 } 178 }
170 179
171 } // namespace mus 180 } // namespace mus
172 } // namespace ash 181 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/mus/window_manager.cc » ('j') | services/ui/common/accelerator_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698