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

Side by Side Diff: mash/wm/window_manager_application.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 | « mash/wm/window_manager_application.h ('k') | mash/wm/window_manager_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mash/wm/window_manager_application.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h"
11 #include "components/mus/common/event_matcher_util.h"
12 #include "components/mus/public/cpp/window.h"
13 #include "components/mus/public/interfaces/window_manager_factory.mojom.h"
14 #include "mash/wm/accelerator_registrar_impl.h"
15 #include "mash/wm/bridge/wm_globals_mus.h"
16 #include "mash/wm/bridge/wm_lookup_mus.h"
17 #include "mash/wm/root_window_controller.h"
18 #include "mash/wm/root_windows_observer.h"
19 #include "mash/wm/shelf_layout_impl.h"
20 #include "mash/wm/user_window_controller_impl.h"
21 #include "services/shell/public/cpp/connection.h"
22 #include "services/shell/public/cpp/connector.h"
23 #include "services/tracing/public/cpp/tracing_impl.h"
24 #include "ui/events/event.h"
25 #include "ui/events/mojo/input_events_type_converters.h"
26 #include "ui/views/mus/aura_init.h"
27 #include "ui/views/mus/screen_mus.h"
28
29 namespace mash {
30 namespace wm {
31
32 WindowManagerApplication::WindowManagerApplication()
33 : connector_(nullptr), window_manager_factory_binding_(this) {}
34
35 WindowManagerApplication::~WindowManagerApplication() {
36 // AcceleratorRegistrarImpl removes an observer in its destructor. Destroy
37 // it early on.
38 std::set<AcceleratorRegistrarImpl*> accelerator_registrars(
39 accelerator_registrars_);
40 for (AcceleratorRegistrarImpl* registrar : accelerator_registrars)
41 registrar->Destroy();
42
43 std::set<RootWindowController*> controllers(root_controllers_);
44 for (RootWindowController* controller : controllers)
45 controller->Destroy();
46 }
47
48 std::set<RootWindowController*> WindowManagerApplication::GetRootControllers() {
49 std::set<RootWindowController*> root_controllers;
50 for (RootWindowController* controller : root_controllers_) {
51 if (controller->root())
52 root_controllers.insert(controller);
53 }
54 return root_controllers;
55 }
56
57 void WindowManagerApplication::OnRootWindowControllerGotRoot(
58 RootWindowController* root_controller) {
59 if (globals_)
60 return; // |root_controller| is the > 1 root, nothing to do.
61
62 if (connector_)
63 aura_init_.reset(new views::AuraInit(connector_, "mash_wm_resources.pak"));
64
65 globals_.reset(new WmGlobalsMus(root_controller->root()->window_tree()));
66 lookup_.reset(new WmLookupMus);
67 }
68
69 void WindowManagerApplication::OnRootWindowControllerDoneInit(
70 RootWindowController* root_controller) {
71 if (!screen_) {
72 std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr));
73 screen->Init(connector_);
74 screen_ = std::move(screen);
75 }
76
77 // TODO(msw): figure out if this should be per display, or global.
78 user_window_controller_->Initialize(root_controller);
79 for (auto& request : user_window_controller_requests_)
80 user_window_controller_bindings_.AddBinding(user_window_controller_.get(),
81 std::move(*request));
82 user_window_controller_requests_.clear();
83
84 // TODO(msw): figure out if this should be per display, or global.
85 shelf_layout_->Initialize(root_controller);
86 for (auto& request : shelf_layout_requests_)
87 shelf_layout_bindings_.AddBinding(shelf_layout_.get(), std::move(*request));
88 shelf_layout_requests_.clear();
89
90 FOR_EACH_OBSERVER(RootWindowsObserver, root_windows_observers_,
91 OnRootWindowControllerAdded(root_controller));
92 }
93
94 void WindowManagerApplication::OnRootWindowDestroyed(
95 RootWindowController* root_controller) {
96 root_controllers_.erase(root_controller);
97 user_window_controller_.reset(nullptr);
98 }
99
100 void WindowManagerApplication::OnAccelerator(uint32_t id,
101 const ui::Event& event) {
102 for (auto* registrar : accelerator_registrars_) {
103 if (registrar->OwnsAccelerator(id)) {
104 registrar->ProcessAccelerator(id, mus::mojom::Event::From(event));
105 break;
106 }
107 }
108 }
109
110 void WindowManagerApplication::AddRootWindowsObserver(
111 RootWindowsObserver* observer) {
112 root_windows_observers_.AddObserver(observer);
113 }
114
115 void WindowManagerApplication::RemoveRootWindowsObserver(
116 RootWindowsObserver* observer) {
117 root_windows_observers_.RemoveObserver(observer);
118 }
119
120 void WindowManagerApplication::OnAcceleratorRegistrarDestroyed(
121 AcceleratorRegistrarImpl* registrar) {
122 accelerator_registrars_.erase(registrar);
123 }
124
125 void WindowManagerApplication::AddRootWindowController(
126 RootWindowController* root_window_controller) {
127 root_controllers_.insert(root_window_controller);
128 }
129
130 void WindowManagerApplication::Initialize(shell::Connector* connector,
131 const shell::Identity& identity,
132 uint32_t id) {
133 connector_ = connector;
134 if (connector) {
135 tracing_.Initialize(connector, identity.name());
136
137 mus::mojom::WindowManagerFactoryServicePtr wm_factory_service;
138 connector_->ConnectToInterface("mojo:mus", &wm_factory_service);
139 wm_factory_service->SetWindowManagerFactory(
140 window_manager_factory_binding_.CreateInterfacePtrAndBind());
141 }
142
143 shelf_layout_.reset(new ShelfLayoutImpl);
144 user_window_controller_.reset(new UserWindowControllerImpl());
145 }
146
147 bool WindowManagerApplication::AcceptConnection(shell::Connection* connection) {
148 connection->AddInterface<ash::mojom::ShelfLayout>(this);
149 connection->AddInterface<ash::mojom::UserWindowController>(this);
150 connection->AddInterface<mus::mojom::AcceleratorRegistrar>(this);
151 if (connection->GetRemoteIdentity().name() == "mojo:mash_session")
152 connection->GetInterface(&session_);
153 return true;
154 }
155
156 void WindowManagerApplication::Create(
157 shell::Connection* connection,
158 mojo::InterfaceRequest<ash::mojom::ShelfLayout> request) {
159 // TODO(msw): Handle multiple shelves (one per display).
160 if (!root_controllers_.empty() && (*root_controllers_.begin())->root()) {
161 shelf_layout_bindings_.AddBinding(shelf_layout_.get(), std::move(request));
162 } else {
163 shelf_layout_requests_.push_back(
164 base::WrapUnique(new mojo::InterfaceRequest<ash::mojom::ShelfLayout>(
165 std::move(request))));
166 }
167 }
168
169 void WindowManagerApplication::Create(
170 shell::Connection* connection,
171 mojo::InterfaceRequest<ash::mojom::UserWindowController> request) {
172 if (!root_controllers_.empty() && (*root_controllers_.begin())->root()) {
173 user_window_controller_bindings_.AddBinding(user_window_controller_.get(),
174 std::move(request));
175 } else {
176 user_window_controller_requests_.push_back(base::WrapUnique(
177 new mojo::InterfaceRequest<ash::mojom::UserWindowController>(
178 std::move(request))));
179 }
180 }
181
182 void WindowManagerApplication::Create(
183 shell::Connection* connection,
184 mojo::InterfaceRequest<mus::mojom::AcceleratorRegistrar> request) {
185 static int accelerator_registrar_count = 0;
186 if (accelerator_registrar_count == std::numeric_limits<int>::max()) {
187 // Restart from zero if we have reached the limit. It is technically
188 // possible to end up with multiple active registrars with the same
189 // namespace, but it is highly unlikely. In the event that multiple
190 // registrars have the same namespace, this new registrar will be unable to
191 // install accelerators.
192 accelerator_registrar_count = 0;
193 }
194 accelerator_registrars_.insert(new AcceleratorRegistrarImpl(
195 this, ++accelerator_registrar_count, std::move(request),
196 base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed,
197 base::Unretained(this))));
198 }
199
200 void WindowManagerApplication::CreateWindowManager(
201 mus::mojom::DisplayPtr display,
202 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> client_request) {
203 AddRootWindowController(RootWindowController::CreateFromDisplay(
204 this, std::move(display), std::move(client_request)));
205 }
206
207 } // namespace wm
208 } // namespace mash
OLDNEW
« no previous file with comments | « mash/wm/window_manager_application.h ('k') | mash/wm/window_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698