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

Side by Side Diff: ash/mus/accelerator_registrar_impl.cc

Issue 2029883002: Moves mash/wm into ash/mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_static_assert
Patch Set: move comment Created 4 years, 6 months 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 | « ash/mus/accelerator_registrar_impl.h ('k') | ash/mus/accelerator_registrar_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "mash/wm/accelerator_registrar_impl.h" 5 #include "ash/mus/accelerator_registrar_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/mus/root_window_controller.h"
11 #include "ash/mus/window_manager.h"
12 #include "ash/mus/window_manager_application.h"
10 #include "base/bind.h" 13 #include "base/bind.h"
11 #include "components/mus/public/cpp/window_manager_delegate.h" 14 #include "components/mus/public/cpp/window_manager_delegate.h"
12 #include "mash/wm/root_window_controller.h"
13 #include "mash/wm/window_manager.h"
14 #include "mash/wm/window_manager_application.h"
15 15
16 namespace mash { 16 namespace ash {
17 namespace wm { 17 namespace mus {
18 18
19 namespace { 19 namespace {
20 const int kAcceleratorIdMask = 0xffff; 20 const int kAcceleratorIdMask = 0xffff;
21 21
22 void OnAcceleratorAdded(bool result) {} 22 void OnAcceleratorAdded(bool result) {}
23 void CallAddAcceleratorCallback( 23 void CallAddAcceleratorCallback(
24 const mus::mojom::AcceleratorRegistrar::AddAcceleratorCallback& callback, 24 const ::mus::mojom::AcceleratorRegistrar::AddAcceleratorCallback& callback,
25 bool result) { 25 bool result) {
26 callback.Run(result); 26 callback.Run(result);
27 } 27 }
28 28
29 } // namespace 29 } // namespace
30 30
31 struct AcceleratorRegistrarImpl::Accelerator { 31 struct AcceleratorRegistrarImpl::Accelerator {
32 mus::mojom::EventMatcherPtr event_matcher; 32 ::mus::mojom::EventMatcherPtr event_matcher;
33 AddAcceleratorCallback callback; 33 AddAcceleratorCallback callback;
34 bool callback_used = false; 34 bool callback_used = false;
35 }; 35 };
36 36
37 AcceleratorRegistrarImpl::AcceleratorRegistrarImpl( 37 AcceleratorRegistrarImpl::AcceleratorRegistrarImpl(
38 WindowManagerApplication* wm_app, 38 WindowManagerApplication* wm_app,
39 uint32_t accelerator_namespace, 39 uint32_t accelerator_namespace,
40 mojo::InterfaceRequest<AcceleratorRegistrar> request, 40 mojo::InterfaceRequest<AcceleratorRegistrar> request,
41 const DestroyCallback& destroy_callback) 41 const DestroyCallback& destroy_callback)
42 : wm_app_(wm_app), 42 : wm_app_(wm_app),
43 binding_(this, std::move(request)), 43 binding_(this, std::move(request)),
44 accelerator_namespace_(accelerator_namespace & 0xffff), 44 accelerator_namespace_(accelerator_namespace & 0xffff),
45 destroy_callback_(destroy_callback) { 45 destroy_callback_(destroy_callback) {
46 wm_app_->AddRootWindowsObserver(this); 46 wm_app_->AddRootWindowsObserver(this);
47 binding_.set_connection_error_handler(base::Bind( 47 binding_.set_connection_error_handler(base::Bind(
48 &AcceleratorRegistrarImpl::OnBindingGone, base::Unretained(this))); 48 &AcceleratorRegistrarImpl::OnBindingGone, base::Unretained(this)));
49 } 49 }
50 50
51 void AcceleratorRegistrarImpl::Destroy() { 51 void AcceleratorRegistrarImpl::Destroy() {
52 delete this; 52 delete this;
53 } 53 }
54 54
55 bool AcceleratorRegistrarImpl::OwnsAccelerator(uint32_t accelerator_id) const { 55 bool AcceleratorRegistrarImpl::OwnsAccelerator(uint32_t accelerator_id) const {
56 return !!accelerators_.count(accelerator_id); 56 return !!accelerators_.count(accelerator_id);
57 } 57 }
58 58
59 void AcceleratorRegistrarImpl::ProcessAccelerator(uint32_t accelerator_id, 59 void AcceleratorRegistrarImpl::ProcessAccelerator(
60 mus::mojom::EventPtr event) { 60 uint32_t accelerator_id,
61 ::mus::mojom::EventPtr event) {
61 DCHECK(OwnsAccelerator(accelerator_id)); 62 DCHECK(OwnsAccelerator(accelerator_id));
62 accelerator_handler_->OnAccelerator(accelerator_id & kAcceleratorIdMask, 63 accelerator_handler_->OnAccelerator(accelerator_id & kAcceleratorIdMask,
63 std::move(event)); 64 std::move(event));
64 } 65 }
65 66
66 AcceleratorRegistrarImpl::~AcceleratorRegistrarImpl() { 67 AcceleratorRegistrarImpl::~AcceleratorRegistrarImpl() {
67 wm_app_->RemoveRootWindowsObserver(this); 68 wm_app_->RemoveRootWindowsObserver(this);
68 RemoveAllAccelerators(); 69 RemoveAllAccelerators();
69 destroy_callback_.Run(this); 70 destroy_callback_.Run(this);
70 } 71 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 for (const auto& pair : accelerators_) { 114 for (const auto& pair : accelerators_) {
114 for (RootWindowController* root : wm_app_->GetRootControllers()) { 115 for (RootWindowController* root : wm_app_->GetRootControllers()) {
115 root->window_manager()->window_manager_client()->RemoveAccelerator( 116 root->window_manager()->window_manager_client()->RemoveAccelerator(
116 pair.first); 117 pair.first);
117 } 118 }
118 } 119 }
119 accelerators_.clear(); 120 accelerators_.clear();
120 } 121 }
121 122
122 void AcceleratorRegistrarImpl::SetHandler( 123 void AcceleratorRegistrarImpl::SetHandler(
123 mus::mojom::AcceleratorHandlerPtr handler) { 124 ::mus::mojom::AcceleratorHandlerPtr handler) {
124 accelerator_handler_ = std::move(handler); 125 accelerator_handler_ = std::move(handler);
125 accelerator_handler_.set_connection_error_handler(base::Bind( 126 accelerator_handler_.set_connection_error_handler(base::Bind(
126 &AcceleratorRegistrarImpl::OnHandlerGone, base::Unretained(this))); 127 &AcceleratorRegistrarImpl::OnHandlerGone, base::Unretained(this)));
127 } 128 }
128 129
129 void AcceleratorRegistrarImpl::AddAccelerator( 130 void AcceleratorRegistrarImpl::AddAccelerator(
130 uint32_t accelerator_id, 131 uint32_t accelerator_id,
131 mus::mojom::EventMatcherPtr matcher, 132 ::mus::mojom::EventMatcherPtr matcher,
132 const AddAcceleratorCallback& callback) { 133 const AddAcceleratorCallback& callback) {
133 if (!accelerator_handler_ || 134 if (!accelerator_handler_ ||
134 (accelerator_id & kAcceleratorIdMask) != accelerator_id) { 135 (accelerator_id & kAcceleratorIdMask) != accelerator_id) {
135 // The |accelerator_id| is too large, and it can't be handled correctly. 136 // The |accelerator_id| is too large, and it can't be handled correctly.
136 callback.Run(false); 137 callback.Run(false);
137 return; 138 return;
138 } 139 }
139 uint32_t namespaced_accelerator_id = ComputeAcceleratorId(accelerator_id); 140 uint32_t namespaced_accelerator_id = ComputeAcceleratorId(accelerator_id);
140 accelerators_[namespaced_accelerator_id].event_matcher = matcher->Clone(); 141 accelerators_[namespaced_accelerator_id].event_matcher = matcher->Clone();
141 accelerators_[namespaced_accelerator_id].callback = callback; 142 accelerators_[namespaced_accelerator_id].callback = callback;
(...skipping 18 matching lines...) Expand all
160 if (accelerators_.empty() && !binding_.is_bound()) 161 if (accelerators_.empty() && !binding_.is_bound())
161 delete this; 162 delete this;
162 } 163 }
163 164
164 void AcceleratorRegistrarImpl::OnRootWindowControllerAdded( 165 void AcceleratorRegistrarImpl::OnRootWindowControllerAdded(
165 RootWindowController* controller) { 166 RootWindowController* controller) {
166 for (const auto& pair : accelerators_) 167 for (const auto& pair : accelerators_)
167 AddAcceleratorToRoot(controller, pair.first); 168 AddAcceleratorToRoot(controller, pair.first);
168 } 169 }
169 170
170 } // namespace wm 171 } // namespace mus
171 } // namespace mash 172 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/accelerator_registrar_impl.h ('k') | ash/mus/accelerator_registrar_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698