OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/services/window_manager/window_manager_app.h" | 5 #include "mojo/services/window_manager/window_manager_app.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "mojo/aura/aura_init.h" | 9 #include "mojo/aura/aura_init.h" |
| 10 #include "mojo/converters/geometry/geometry_type_converters.h" |
10 #include "mojo/converters/input_events/input_events_type_converters.h" | 11 #include "mojo/converters/input_events/input_events_type_converters.h" |
11 #include "mojo/public/cpp/application/application_connection.h" | 12 #include "mojo/public/cpp/application/application_connection.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/public/interfaces/application/shell.mojom.h" | 14 #include "mojo/public/interfaces/application/shell.mojom.h" |
14 #include "mojo/services/public/cpp/view_manager/view.h" | 15 #include "mojo/services/public/cpp/view_manager/view.h" |
15 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 16 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" |
18 #include "ui/aura/window_property.h" | 19 #include "ui/aura/window_property.h" |
19 #include "ui/base/hit_test.h" | 20 #include "ui/base/hit_test.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 173 |
173 void WindowManagerApp::OnEmbed(ViewManager* view_manager, | 174 void WindowManagerApp::OnEmbed(ViewManager* view_manager, |
174 View* root, | 175 View* root, |
175 ServiceProviderImpl* exported_services, | 176 ServiceProviderImpl* exported_services, |
176 scoped_ptr<ServiceProvider> imported_services) { | 177 scoped_ptr<ServiceProvider> imported_services) { |
177 DCHECK(!view_manager_ && !root_); | 178 DCHECK(!view_manager_ && !root_); |
178 view_manager_ = view_manager; | 179 view_manager_ = view_manager; |
179 root_ = root; | 180 root_ = root; |
180 | 181 |
181 window_tree_host_.reset(new WindowTreeHostMojo(shell_, root_)); | 182 window_tree_host_.reset(new WindowTreeHostMojo(shell_, root_)); |
182 window_tree_host_->window()->SetBounds(root->bounds()); | 183 window_tree_host_->window()->SetBounds( |
| 184 root->bounds().Clone().To<gfx::Rect>()); |
183 window_tree_host_->window()->Show(); | 185 window_tree_host_->window()->Show(); |
184 | 186 |
185 RegisterSubtree(root_, window_tree_host_->window()); | 187 RegisterSubtree(root_, window_tree_host_->window()); |
186 | 188 |
187 capture_client_.reset( | 189 capture_client_.reset( |
188 new wm::ScopedCaptureClient(window_tree_host_->window())); | 190 new wm::ScopedCaptureClient(window_tree_host_->window())); |
189 | 191 |
190 if (wrapped_view_manager_delegate_) { | 192 if (wrapped_view_manager_delegate_) { |
191 wrapped_view_manager_delegate_->OnEmbed( | 193 wrapped_view_manager_delegate_->OnEmbed( |
192 view_manager, root, exported_services, imported_services.Pass()); | 194 view_manager, root, exported_services, imported_services.Pass()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 root_ = NULL; | 243 root_ = NULL; |
242 STLDeleteValues(&view_id_to_window_map_); | 244 STLDeleteValues(&view_id_to_window_map_); |
243 if (focus_client_.get()) | 245 if (focus_client_.get()) |
244 focus_client_->RemoveObserver(this); | 246 focus_client_->RemoveObserver(this); |
245 if (activation_client_) | 247 if (activation_client_) |
246 activation_client_->RemoveObserver(this); | 248 activation_client_->RemoveObserver(this); |
247 window_tree_host_.reset(); | 249 window_tree_host_.reset(); |
248 } | 250 } |
249 | 251 |
250 void WindowManagerApp::OnViewBoundsChanged(View* view, | 252 void WindowManagerApp::OnViewBoundsChanged(View* view, |
251 const gfx::Rect& old_bounds, | 253 const Rect& old_bounds, |
252 const gfx::Rect& new_bounds) { | 254 const Rect& new_bounds) { |
253 aura::Window* window = GetWindowForViewId(view->id()); | 255 aura::Window* window = GetWindowForViewId(view->id()); |
254 window->SetBounds(new_bounds); | 256 window->SetBounds(new_bounds.Clone().To<gfx::Rect>()); |
255 } | 257 } |
256 | 258 |
257 //////////////////////////////////////////////////////////////////////////////// | 259 //////////////////////////////////////////////////////////////////////////////// |
258 // WindowManagerApp, ui::EventHandler implementation: | 260 // WindowManagerApp, ui::EventHandler implementation: |
259 | 261 |
260 void WindowManagerApp::OnEvent(ui::Event* event) { | 262 void WindowManagerApp::OnEvent(ui::Event* event) { |
261 if (!window_manager_client_) | 263 if (!window_manager_client_) |
262 return; | 264 return; |
263 | 265 |
264 View* view = GetViewForWindow(static_cast<aura::Window*>(event->target())); | 266 View* view = GetViewForWindow(static_cast<aura::Window*>(event->target())); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 DCHECK(view_id_to_window_map_.find(view->id()) == | 307 DCHECK(view_id_to_window_map_.find(view->id()) == |
306 view_id_to_window_map_.end()); | 308 view_id_to_window_map_.end()); |
307 aura::Window* window = new aura::Window(dummy_delegate_.get()); | 309 aura::Window* window = new aura::Window(dummy_delegate_.get()); |
308 window->set_id(view->id()); | 310 window->set_id(view->id()); |
309 window->SetProperty(kViewKey, view); | 311 window->SetProperty(kViewKey, view); |
310 // All events pass through the root during dispatch, so we only need a handler | 312 // All events pass through the root during dispatch, so we only need a handler |
311 // installed there. | 313 // installed there. |
312 if (view == root_) | 314 if (view == root_) |
313 window->AddPreTargetHandler(this); | 315 window->AddPreTargetHandler(this); |
314 parent->AddChild(window); | 316 parent->AddChild(window); |
315 window->SetBounds(view->bounds()); | 317 window->SetBounds(view->bounds().Clone().To<gfx::Rect>()); |
316 window->Show(); | 318 window->Show(); |
317 view_id_to_window_map_[view->id()] = window; | 319 view_id_to_window_map_[view->id()] = window; |
318 View::Children::const_iterator it = view->children().begin(); | 320 View::Children::const_iterator it = view->children().begin(); |
319 for (; it != view->children().end(); ++it) | 321 for (; it != view->children().end(); ++it) |
320 RegisterSubtree(*it, window); | 322 RegisterSubtree(*it, window); |
321 } | 323 } |
322 | 324 |
323 void WindowManagerApp::UnregisterSubtree(View* view) { | 325 void WindowManagerApp::UnregisterSubtree(View* view) { |
324 for (View* child : view->children()) | 326 for (View* child : view->children()) |
325 UnregisterSubtree(child); | 327 UnregisterSubtree(child); |
326 Unregister(view); | 328 Unregister(view); |
327 } | 329 } |
328 | 330 |
329 void WindowManagerApp::Unregister(View* view) { | 331 void WindowManagerApp::Unregister(View* view) { |
330 ViewIdToWindowMap::iterator it = view_id_to_window_map_.find(view->id()); | 332 ViewIdToWindowMap::iterator it = view_id_to_window_map_.find(view->id()); |
331 if (it == view_id_to_window_map_.end()) { | 333 if (it == view_id_to_window_map_.end()) { |
332 // Because we unregister in OnViewDestroying() we can still get a subsequent | 334 // Because we unregister in OnViewDestroying() we can still get a subsequent |
333 // OnTreeChanged for the same view. Ignore this one. | 335 // OnTreeChanged for the same view. Ignore this one. |
334 return; | 336 return; |
335 } | 337 } |
336 view->RemoveObserver(this); | 338 view->RemoveObserver(this); |
337 DCHECK(it != view_id_to_window_map_.end()); | 339 DCHECK(it != view_id_to_window_map_.end()); |
338 // Delete before we remove from map as destruction may want to look up view | 340 // Delete before we remove from map as destruction may want to look up view |
339 // for window. | 341 // for window. |
340 delete it->second; | 342 delete it->second; |
341 view_id_to_window_map_.erase(it); | 343 view_id_to_window_map_.erase(it); |
342 } | 344 } |
343 | 345 |
344 } // namespace mojo | 346 } // namespace mojo |
OLD | NEW |