OLD | NEW |
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/window_manager_application.h" | 5 #include "mash/wm/window_manager_application.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "components/mus/common/util.h" | 11 #include "components/mus/common/util.h" |
12 #include "components/mus/public/cpp/event_matcher.h" | 12 #include "components/mus/public/cpp/event_matcher.h" |
13 #include "components/mus/public/cpp/window.h" | 13 #include "components/mus/public/cpp/window.h" |
14 #include "components/mus/public/cpp/window_tree_connection.h" | 14 #include "components/mus/public/cpp/window_tree_connection.h" |
15 #include "components/mus/public/cpp/window_tree_host_factory.h" | 15 #include "components/mus/public/cpp/window_tree_host_factory.h" |
16 #include "mash/wm/accelerator_registrar_impl.h" | 16 #include "mash/wm/accelerator_registrar_impl.h" |
17 #include "mash/wm/background_layout.h" | 17 #include "mash/wm/background_layout.h" |
18 #include "mash/wm/shadow_controller.h" | 18 #include "mash/wm/shadow_controller.h" |
19 #include "mash/wm/shelf_layout.h" | 19 #include "mash/wm/shelf_layout.h" |
| 20 #include "mash/wm/user_window_controller_impl.h" |
20 #include "mash/wm/window_layout.h" | 21 #include "mash/wm/window_layout.h" |
21 #include "mash/wm/window_manager_impl.h" | 22 #include "mash/wm/window_manager_impl.h" |
22 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | 23 #include "mojo/services/tracing/public/cpp/tracing_impl.h" |
23 #include "mojo/shell/public/cpp/application_connection.h" | 24 #include "mojo/shell/public/cpp/application_connection.h" |
24 #include "ui/mojo/init/ui_init.h" | 25 #include "ui/mojo/init/ui_init.h" |
25 #include "ui/views/mus/aura_init.h" | 26 #include "ui/views/mus/aura_init.h" |
26 #include "ui/views/mus/display_converter.h" | 27 #include "ui/views/mus/display_converter.h" |
27 | 28 |
28 namespace mash { | 29 namespace mash { |
29 namespace wm { | 30 namespace wm { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 AcceleratorRegistrarImpl* registrar) { | 73 AcceleratorRegistrarImpl* registrar) { |
73 accelerator_registrars_.erase(registrar); | 74 accelerator_registrars_.erase(registrar); |
74 } | 75 } |
75 | 76 |
76 void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) { | 77 void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) { |
77 app_ = app; | 78 app_ = app; |
78 tracing_.Initialize(app); | 79 tracing_.Initialize(app); |
79 window_manager_.reset(new WindowManagerImpl()); | 80 window_manager_.reset(new WindowManagerImpl()); |
80 // Don't bind to the WindowManager immediately. Wait for OnEmbed() first. | 81 // Don't bind to the WindowManager immediately. Wait for OnEmbed() first. |
81 mus::mojom::WindowManagerPtr window_manager; | 82 mus::mojom::WindowManagerPtr window_manager; |
82 requests_.push_back(new mojo::InterfaceRequest<mus::mojom::WindowManager>( | 83 requests_.push_back( |
83 mojo::GetProxy(&window_manager))); | 84 make_scoped_ptr(new mojo::InterfaceRequest<mus::mojom::WindowManager>( |
| 85 mojo::GetProxy(&window_manager)))); |
| 86 user_window_controller_.reset(new UserWindowControllerImpl()); |
84 mus::mojom::WindowTreeHostClientPtr host_client; | 87 mus::mojom::WindowTreeHostClientPtr host_client; |
85 host_client_binding_.Bind(GetProxy(&host_client)); | 88 host_client_binding_.Bind(GetProxy(&host_client)); |
86 mus::CreateSingleWindowTreeHost(app, std::move(host_client), this, | 89 mus::CreateSingleWindowTreeHost(app, std::move(host_client), this, |
87 &window_tree_host_, std::move(window_manager), | 90 &window_tree_host_, std::move(window_manager), |
88 window_manager_.get()); | 91 window_manager_.get()); |
89 } | 92 } |
90 | 93 |
91 bool WindowManagerApplication::ConfigureIncomingConnection( | 94 bool WindowManagerApplication::ConfigureIncomingConnection( |
92 mojo::ApplicationConnection* connection) { | 95 mojo::ApplicationConnection* connection) { |
| 96 connection->AddService<mash::wm::mojom::UserWindowController>(this); |
93 connection->AddService<mus::mojom::AcceleratorRegistrar>(this); | 97 connection->AddService<mus::mojom::AcceleratorRegistrar>(this); |
94 connection->AddService<mus::mojom::WindowManager>(this); | 98 connection->AddService<mus::mojom::WindowManager>(this); |
95 return true; | 99 return true; |
96 } | 100 } |
97 | 101 |
98 void WindowManagerApplication::OnAccelerator(uint32_t id, | 102 void WindowManagerApplication::OnAccelerator(uint32_t id, |
99 mus::mojom::EventPtr event) { | 103 mus::mojom::EventPtr event) { |
100 switch (id) { | 104 switch (id) { |
101 case kWindowSwitchCmd: | 105 case kWindowSwitchCmd: |
102 window_tree_host_->ActivateNextWindow(); | 106 window_tree_host_->ActivateNextWindow(); |
(...skipping 22 matching lines...) Expand all Loading... |
125 new WindowLayout(GetWindowForContainer(mojom::CONTAINER_USER_WINDOWS))); | 129 new WindowLayout(GetWindowForContainer(mojom::CONTAINER_USER_WINDOWS))); |
126 window_tree_host_->AddActivationParent(window->id()); | 130 window_tree_host_->AddActivationParent(window->id()); |
127 window_tree_host_->SetTitle("Mash"); | 131 window_tree_host_->SetTitle("Mash"); |
128 | 132 |
129 AddAccelerators(); | 133 AddAccelerators(); |
130 | 134 |
131 ui_init_.reset(new ui::mojo::UIInit(views::GetDisplaysFromWindow(root))); | 135 ui_init_.reset(new ui::mojo::UIInit(views::GetDisplaysFromWindow(root))); |
132 aura_init_.reset(new views::AuraInit(app_, "mash_wm_resources.pak")); | 136 aura_init_.reset(new views::AuraInit(app_, "mash_wm_resources.pak")); |
133 window_manager_->Initialize(this); | 137 window_manager_->Initialize(this); |
134 | 138 |
135 for (auto request : requests_) | 139 for (auto& request : requests_) |
136 window_manager_binding_.AddBinding(window_manager_.get(), | 140 window_manager_binding_.AddBinding(window_manager_.get(), |
137 std::move(*request)); | 141 std::move(*request)); |
138 requests_.clear(); | 142 requests_.clear(); |
139 | 143 |
| 144 user_window_controller_->Initialize(this); |
| 145 for (auto& request : user_window_controller_requests_) |
| 146 user_window_controller_binding_.AddBinding(user_window_controller_.get(), |
| 147 std::move(*request)); |
| 148 user_window_controller_requests_.clear(); |
| 149 |
140 shadow_controller_.reset(new ShadowController(root->connection())); | 150 shadow_controller_.reset(new ShadowController(root->connection())); |
141 } | 151 } |
142 | 152 |
143 void WindowManagerApplication::OnConnectionLost( | 153 void WindowManagerApplication::OnConnectionLost( |
144 mus::WindowTreeConnection* connection) { | 154 mus::WindowTreeConnection* connection) { |
145 // TODO(sky): shutdown. | 155 // TODO(sky): shutdown. |
146 NOTIMPLEMENTED(); | 156 NOTIMPLEMENTED(); |
147 shadow_controller_.reset(); | 157 shadow_controller_.reset(); |
148 } | 158 } |
149 | 159 |
150 void WindowManagerApplication::Create( | 160 void WindowManagerApplication::Create( |
151 mojo::ApplicationConnection* connection, | 161 mojo::ApplicationConnection* connection, |
| 162 mojo::InterfaceRequest<mash::wm::mojom::UserWindowController> request) { |
| 163 if (root_) { |
| 164 user_window_controller_binding_.AddBinding(user_window_controller_.get(), |
| 165 std::move(request)); |
| 166 } else { |
| 167 user_window_controller_requests_.push_back(make_scoped_ptr( |
| 168 new mojo::InterfaceRequest<mash::wm::mojom::UserWindowController>( |
| 169 std::move(request)))); |
| 170 } |
| 171 } |
| 172 |
| 173 void WindowManagerApplication::Create( |
| 174 mojo::ApplicationConnection* connection, |
152 mojo::InterfaceRequest<mus::mojom::AcceleratorRegistrar> request) { | 175 mojo::InterfaceRequest<mus::mojom::AcceleratorRegistrar> request) { |
153 static int accelerator_registrar_count = 0; | 176 static int accelerator_registrar_count = 0; |
154 if (accelerator_registrar_count == std::numeric_limits<int>::max()) { | 177 if (accelerator_registrar_count == std::numeric_limits<int>::max()) { |
155 // Restart from zero if we have reached the limit. It is technically | 178 // Restart from zero if we have reached the limit. It is technically |
156 // possible to end up with multiple active registrars with the same | 179 // possible to end up with multiple active registrars with the same |
157 // namespace, but it is highly unlikely. In the event that multiple | 180 // namespace, but it is highly unlikely. In the event that multiple |
158 // registrars have the same namespace, this new registrar will be unable to | 181 // registrars have the same namespace, this new registrar will be unable to |
159 // install accelerators. | 182 // install accelerators. |
160 accelerator_registrar_count = 0; | 183 accelerator_registrar_count = 0; |
161 } | 184 } |
162 accelerator_registrars_.insert(new AcceleratorRegistrarImpl( | 185 accelerator_registrars_.insert(new AcceleratorRegistrarImpl( |
163 window_tree_host_.get(), ++accelerator_registrar_count, | 186 window_tree_host_.get(), ++accelerator_registrar_count, |
164 std::move(request), | 187 std::move(request), |
165 base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed, | 188 base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed, |
166 base::Unretained(this)))); | 189 base::Unretained(this)))); |
167 } | 190 } |
168 | 191 |
169 void WindowManagerApplication::Create( | 192 void WindowManagerApplication::Create( |
170 mojo::ApplicationConnection* connection, | 193 mojo::ApplicationConnection* connection, |
171 mojo::InterfaceRequest<mus::mojom::WindowManager> request) { | 194 mojo::InterfaceRequest<mus::mojom::WindowManager> request) { |
172 if (root_) { | 195 if (root_) { |
173 window_manager_binding_.AddBinding(window_manager_.get(), | 196 window_manager_binding_.AddBinding(window_manager_.get(), |
174 std::move(request)); | 197 std::move(request)); |
175 } else { | 198 } else { |
176 requests_.push_back(new mojo::InterfaceRequest<mus::mojom::WindowManager>( | 199 requests_.push_back( |
177 std::move(request))); | 200 make_scoped_ptr(new mojo::InterfaceRequest<mus::mojom::WindowManager>( |
| 201 std::move(request)))); |
178 } | 202 } |
179 } | 203 } |
180 | 204 |
181 void WindowManagerApplication::OnWindowDestroyed(mus::Window* window) { | 205 void WindowManagerApplication::OnWindowDestroyed(mus::Window* window) { |
182 DCHECK_EQ(window, root_); | 206 DCHECK_EQ(window, root_); |
183 root_->RemoveObserver(this); | 207 root_->RemoveObserver(this); |
184 // Delete the |window_manager_| here so that WindowManager doesn't have to | 208 // Delete the |window_manager_| here so that WindowManager doesn't have to |
185 // worry about the possibility of |root_| being null. | 209 // worry about the possibility of |root_| being null. |
186 window_manager_.reset(); | 210 window_manager_.reset(); |
187 root_ = nullptr; | 211 root_ = nullptr; |
188 } | 212 } |
189 | 213 |
190 void WindowManagerApplication::CreateContainers() { | 214 void WindowManagerApplication::CreateContainers() { |
191 for (uint16_t container = | 215 for (uint16_t container = |
192 static_cast<uint16_t>(mojom::CONTAINER_ALL_USER_BACKGROUND); | 216 static_cast<uint16_t>(mojom::CONTAINER_ALL_USER_BACKGROUND); |
193 container < static_cast<uint16_t>(mojom::CONTAINER_COUNT); ++container) { | 217 container < static_cast<uint16_t>(mojom::CONTAINER_COUNT); ++container) { |
194 mus::Window* window = root_->connection()->NewWindow(); | 218 mus::Window* window = root_->connection()->NewWindow(); |
195 DCHECK_EQ(mus::LoWord(window->id()), container) | 219 DCHECK_EQ(mus::LoWord(window->id()), container) |
196 << "Containers must be created before other windows!"; | 220 << "Containers must be created before other windows!"; |
197 window->SetBounds(root_->bounds()); | 221 window->SetBounds(root_->bounds()); |
198 window->SetVisible(true); | 222 window->SetVisible(true); |
199 root_->AddChild(window); | 223 root_->AddChild(window); |
200 } | 224 } |
201 } | 225 } |
202 | 226 |
203 } // namespace wm | 227 } // namespace wm |
204 } // namespace mash | 228 } // namespace mash |
OLD | NEW |