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

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

Issue 2520093003: WindowManagerClient::AddAccelerator() should take an array (Closed)
Patch Set: Create anonymous namespace helper for AcceleratorTransport mojom struct. Cleanup/format codes. 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
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/event_matcher_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 {
mfomitchev 2016/11/24 19:56:13 Just use the existing anonymous namespace in ash::
thanhph 2016/11/29 00:08:29 I put this helper in different file accelerator_tr
22
23 struct AcceleratorTransportWrapper {
24 ui::mojom::AcceleratorTransportPtr accelerator_transport_ptr;
25 AcceleratorTransportWrapper(uint32_t id,
26 ui::mojom::EventMatcherPtr event_matcher) {
27 accelerator_transport_ptr = ui::mojom::AcceleratorTransport::New();
28 accelerator_transport_ptr->id = id;
29 accelerator_transport_ptr->event_matcher = event_matcher.Clone();
30 }
31 };
32 }
33
21 namespace ash { 34 namespace ash {
22 namespace mus { 35 namespace mus {
23 namespace { 36 namespace {
24 37
25 // Callback from registering the accelerator. 38 // Callback from registering the accelerator.
26 void OnAcceleratorAdded(const ui::Accelerator& accelerator, bool added) { 39 void OnAcceleratorAdded(const ui::Accelerator& accelerator, bool added) {
27 // All our accelerators should be registered, so we expect |added| to be true. 40 // All our accelerators should be registered, so we expect |added| to be true.
28 DCHECK(added) << "duplicate accelerator key_code=" << accelerator.key_code() 41 DCHECK(added) << "duplicate accelerator key_code=" << accelerator.key_code()
29 << " type=" << accelerator.type() 42 << " type=" << accelerator.type()
30 << " modifiers=" << accelerator.modifiers(); 43 << " modifiers=" << accelerator.modifiers();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 DCHECK(accelerator.type() == ui::ET_KEY_PRESSED || 132 DCHECK(accelerator.type() == ui::ET_KEY_PRESSED ||
120 accelerator.type() == ui::ET_KEY_RELEASED); 133 accelerator.type() == ui::ET_KEY_RELEASED);
121 event_matcher->type_matcher->type = accelerator.type() == ui::ET_KEY_PRESSED 134 event_matcher->type_matcher->type = accelerator.type() == ui::ET_KEY_PRESSED
122 ? ui::mojom::EventType::KEY_PRESSED 135 ? ui::mojom::EventType::KEY_PRESSED
123 : ui::mojom::EventType::KEY_RELEASED; 136 : ui::mojom::EventType::KEY_RELEASED;
124 137
125 ui::mojom::EventMatcherPtr post_event_matcher = event_matcher.Clone(); 138 ui::mojom::EventMatcherPtr post_event_matcher = event_matcher.Clone();
126 post_event_matcher->accelerator_phase = 139 post_event_matcher->accelerator_phase =
127 ui::mojom::AcceleratorPhase::POST_TARGET; 140 ui::mojom::AcceleratorPhase::POST_TARGET;
128 141
129 window_manager_->window_manager_client()->AddAccelerator( 142 AcceleratorTransportWrapper pre_accelerator_transport_wrapper(
mfomitchev 2016/11/24 19:56:13 I don't think this struct helps us much. Why not j
thanhph 2016/11/29 00:08:29 Done. Please review the accelerator_transport_util
130 ComputeAcceleratorId(id_namespace_, ids.pre_id), std::move(event_matcher), 143 ComputeAcceleratorId(id_namespace_, ids.pre_id),
144 std::move(event_matcher));
145
146 std::vector<ui::mojom::AcceleratorTransportPtr> pre_multi_accelerators;
147 pre_multi_accelerators.push_back(
148 std::move(pre_accelerator_transport_wrapper.accelerator_transport_ptr));
149
150 window_manager_->window_manager_client()->AddAccelerators(
151 std::move(pre_multi_accelerators),
131 base::Bind(OnAcceleratorAdded, accelerator)); 152 base::Bind(OnAcceleratorAdded, accelerator));
132 window_manager_->window_manager_client()->AddAccelerator( 153
154 AcceleratorTransportWrapper post_accelerator_transport_wrapper(
133 ComputeAcceleratorId(id_namespace_, ids.post_id), 155 ComputeAcceleratorId(id_namespace_, ids.post_id),
134 std::move(post_event_matcher), 156 std::move(post_event_matcher));
157
158 std::vector<ui::mojom::AcceleratorTransportPtr> post_multi_accelerators;
159 post_multi_accelerators.push_back(
160 std::move(post_accelerator_transport_wrapper.accelerator_transport_ptr));
161
162 window_manager_->window_manager_client()->AddAccelerators(
163 std::move(post_multi_accelerators),
135 base::Bind(OnAcceleratorAdded, accelerator)); 164 base::Bind(OnAcceleratorAdded, accelerator));
136 } 165 }
137 166
138 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( 167 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered(
139 const ui::Accelerator& accelerator) { 168 const ui::Accelerator& accelerator) {
140 auto iter = accelerator_to_ids_.find(accelerator); 169 auto iter = accelerator_to_ids_.find(accelerator);
141 DCHECK(iter != accelerator_to_ids_.end()); 170 DCHECK(iter != accelerator_to_ids_.end());
142 Ids ids = iter->second; 171 Ids ids = iter->second;
143 accelerator_to_ids_.erase(iter); 172 accelerator_to_ids_.erase(iter);
144 ids_.erase(ids.pre_id); 173 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 192 // Common case is we never wrap once, so this is typically cheap. Additionally
164 // we expect there not to be too many accelerators. 193 // we expect there not to be too many accelerators.
165 while (ids_.count(next_id_) > 0) 194 while (ids_.count(next_id_) > 0)
166 ++next_id_; 195 ++next_id_;
167 ids_.insert(next_id_); 196 ids_.insert(next_id_);
168 return next_id_++; 197 return next_id_++;
169 } 198 }
170 199
171 } // namespace mus 200 } // namespace mus
172 } // namespace ash 201 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | services/ui/public/cpp/window_manager_delegate.h » ('j') | services/ui/public/cpp/window_manager_delegate.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698