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

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

Issue 2520093003: WindowManagerClient::AddAccelerator() should take an array (Closed)
Patch Set: Improve comments. 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/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 window_manager_->window_manager_client()->AddAccelerators(
sky 2016/12/01 22:17:04 Is this only the first change you're intending to
thanhph 2016/12/01 23:32:41 To change this I need to change the callback funct
sky 2016/12/02 00:11:16 I don't think that would help as registration adds
thanhph 2016/12/02 15:11:18 Thanks Scott, I'll keep this in mind. Should I put
130 ComputeAcceleratorId(id_namespace_, ids.pre_id), std::move(event_matcher), 130 ui::CreateAcceleratorVector(
131 ComputeAcceleratorId(id_namespace_, ids.pre_id),
132 std::move(event_matcher)),
131 base::Bind(OnAcceleratorAdded, accelerator)); 133 base::Bind(OnAcceleratorAdded, accelerator));
132 window_manager_->window_manager_client()->AddAccelerator( 134
133 ComputeAcceleratorId(id_namespace_, ids.post_id), 135 window_manager_->window_manager_client()->AddAccelerators(
134 std::move(post_event_matcher), 136 ui::CreateAcceleratorVector(
137 ComputeAcceleratorId(id_namespace_, ids.post_id),
138 std::move(post_event_matcher)),
135 base::Bind(OnAcceleratorAdded, accelerator)); 139 base::Bind(OnAcceleratorAdded, accelerator));
136 } 140 }
137 141
138 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered( 142 void AcceleratorControllerRegistrar::OnAcceleratorUnregistered(
139 const ui::Accelerator& accelerator) { 143 const ui::Accelerator& accelerator) {
140 auto iter = accelerator_to_ids_.find(accelerator); 144 auto iter = accelerator_to_ids_.find(accelerator);
141 DCHECK(iter != accelerator_to_ids_.end()); 145 DCHECK(iter != accelerator_to_ids_.end());
142 Ids ids = iter->second; 146 Ids ids = iter->second;
143 accelerator_to_ids_.erase(iter); 147 accelerator_to_ids_.erase(iter);
144 ids_.erase(ids.pre_id); 148 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 167 // Common case is we never wrap once, so this is typically cheap. Additionally
164 // we expect there not to be too many accelerators. 168 // we expect there not to be too many accelerators.
165 while (ids_.count(next_id_) > 0) 169 while (ids_.count(next_id_) > 0)
166 ++next_id_; 170 ++next_id_;
167 ids_.insert(next_id_); 171 ids_.insert(next_id_);
168 return next_id_++; 172 return next_id_++;
169 } 173 }
170 174
171 } // namespace mus 175 } // namespace mus
172 } // namespace ash 176 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/mus/window_manager.cc » ('j') | services/ui/public/interfaces/window_manager.mojom » ('J')

Powered by Google App Engine
This is Rietveld 408576698