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 "components/mus/example/wm/window_manager_application.h" | 5 #include "components/mus/example/wm/window_manager_application.h" |
6 | 6 |
7 #include "components/mus/example/wm/container.h" | 7 #include "components/mus/example/wm/container.h" |
8 #include "components/mus/example/wm/window_layout.h" | 8 #include "components/mus/example/wm/window_layout.h" |
9 #include "components/mus/example/wm/window_manager_impl.h" | 9 #include "components/mus/example/wm/window_manager_impl.h" |
10 #include "components/mus/public/cpp/util.h" | 10 #include "components/mus/public/cpp/util.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 | 37 |
38 bool WindowManagerApplication::ConfigureIncomingConnection( | 38 bool WindowManagerApplication::ConfigureIncomingConnection( |
39 mojo::ApplicationConnection* connection) { | 39 mojo::ApplicationConnection* connection) { |
40 connection->AddService(this); | 40 connection->AddService(this); |
41 return true; | 41 return true; |
42 } | 42 } |
43 | 43 |
44 void WindowManagerApplication::OnEmbed(mus::Window* root) { | 44 void WindowManagerApplication::OnEmbed(mus::Window* root) { |
45 root_ = root; | 45 root_ = root; |
| 46 root_->AddObserver(this); |
46 CreateContainers(); | 47 CreateContainers(); |
47 layout_.reset( | 48 layout_.reset( |
48 new WindowLayout(GetWindowForContainer(Container::USER_WINDOWS))); | 49 new WindowLayout(GetWindowForContainer(Container::USER_WINDOWS))); |
49 | 50 |
50 host_->EnableWindowDraggingForChildren( | |
51 GetWindowForContainer(Container::USER_WINDOWS)->id()); | |
52 | |
53 window_manager_.reset(new WindowManagerImpl(this)); | 51 window_manager_.reset(new WindowManagerImpl(this)); |
54 for (auto request : requests_) | 52 for (auto request : requests_) |
55 window_manager_binding_.AddBinding(window_manager_.get(), request->Pass()); | 53 window_manager_binding_.AddBinding(window_manager_.get(), request->Pass()); |
56 requests_.clear(); | 54 requests_.clear(); |
57 } | 55 } |
58 | 56 |
59 void WindowManagerApplication::OnConnectionLost( | 57 void WindowManagerApplication::OnConnectionLost( |
60 mus::WindowTreeConnection* connection) { | 58 mus::WindowTreeConnection* connection) { |
61 // TODO(sky): shutdown. | 59 // TODO(sky): shutdown. |
62 NOTIMPLEMENTED(); | 60 NOTIMPLEMENTED(); |
63 } | 61 } |
64 | 62 |
65 void WindowManagerApplication::Create( | 63 void WindowManagerApplication::Create( |
66 mojo::ApplicationConnection* connection, | 64 mojo::ApplicationConnection* connection, |
67 mojo::InterfaceRequest<mus::mojom::WindowManager> request) { | 65 mojo::InterfaceRequest<mus::mojom::WindowManager> request) { |
68 if (root_) { | 66 if (root_) { |
69 window_manager_binding_.AddBinding(window_manager_.get(), request.Pass()); | 67 window_manager_binding_.AddBinding(window_manager_.get(), request.Pass()); |
70 } else { | 68 } else { |
71 requests_.push_back( | 69 requests_.push_back( |
72 new mojo::InterfaceRequest<mus::mojom::WindowManager>(request.Pass())); | 70 new mojo::InterfaceRequest<mus::mojom::WindowManager>(request.Pass())); |
73 } | 71 } |
74 } | 72 } |
75 | 73 |
| 74 void WindowManagerApplication::OnWindowDestroyed(mus::Window* window) { |
| 75 DCHECK_EQ(window, root_); |
| 76 root_->RemoveObserver(this); |
| 77 // Delete the |window_manager_| here so that WindowManager doesn't have to |
| 78 // worry about the possibility of |root_| being null. |
| 79 window_manager_.reset(); |
| 80 root_ = nullptr; |
| 81 } |
| 82 |
76 void WindowManagerApplication::CreateContainers() { | 83 void WindowManagerApplication::CreateContainers() { |
77 for (uint16_t container = | 84 for (uint16_t container = |
78 static_cast<uint16_t>(Container::ALL_USER_BACKGROUND); | 85 static_cast<uint16_t>(Container::ALL_USER_BACKGROUND); |
79 container < static_cast<uint16_t>(Container::COUNT); ++container) { | 86 container < static_cast<uint16_t>(Container::COUNT); ++container) { |
80 mus::Window* window = root_->connection()->NewWindow(); | 87 mus::Window* window = root_->connection()->NewWindow(); |
81 DCHECK_EQ(mus::LoWord(window->id()), container) | 88 DCHECK_EQ(mus::LoWord(window->id()), container) |
82 << "Containers must be created before other windows!"; | 89 << "Containers must be created before other windows!"; |
83 window->SetBounds(root_->bounds()); | 90 window->SetBounds(root_->bounds()); |
84 window->SetVisible(true); | 91 window->SetVisible(true); |
85 root_->AddChild(window); | 92 root_->AddChild(window); |
86 } | 93 } |
87 } | 94 } |
88 | 95 |
OLD | NEW |