OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/root_window_controller.h" | 5 #include "mash/wm/root_window_controller.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "components/mus/common/event_matcher_util.h" | 10 #include "components/mus/common/event_matcher_util.h" |
11 #include "components/mus/common/util.h" | 11 #include "components/mus/common/util.h" |
12 #include "components/mus/public/cpp/window.h" | 12 #include "components/mus/public/cpp/window.h" |
13 #include "components/mus/public/cpp/window_tree_connection.h" | 13 #include "components/mus/public/cpp/window_tree_connection.h" |
14 #include "components/mus/public/cpp/window_tree_host_factory.h" | 14 #include "components/mus/public/cpp/window_tree_host_factory.h" |
15 #include "mash/session/public/interfaces/session.mojom.h" | 15 #include "mash/session/public/interfaces/session.mojom.h" |
16 #include "mash/wm/background_layout.h" | 16 #include "mash/wm/background_layout.h" |
| 17 #include "mash/wm/container_ids.h" |
17 #include "mash/wm/fill_layout.h" | 18 #include "mash/wm/fill_layout.h" |
18 #include "mash/wm/screenlock_layout.h" | 19 #include "mash/wm/screenlock_layout.h" |
19 #include "mash/wm/shadow_controller.h" | 20 #include "mash/wm/shadow_controller.h" |
20 #include "mash/wm/shelf_layout_manager.h" | 21 #include "mash/wm/shelf_layout_manager.h" |
21 #include "mash/wm/status_layout_manager.h" | 22 #include "mash/wm/status_layout_manager.h" |
22 #include "mash/wm/window_layout.h" | 23 #include "mash/wm/window_layout.h" |
23 #include "mash/wm/window_manager.h" | 24 #include "mash/wm/window_manager.h" |
24 #include "mash/wm/window_manager_application.h" | 25 #include "mash/wm/window_manager_application.h" |
| 26 #include "mojo/converters/geometry/geometry_type_converters.h" |
25 #include "services/shell/public/cpp/connector.h" | 27 #include "services/shell/public/cpp/connector.h" |
26 #include "ui/mojo/display/display_type_converters.h" | 28 #include "ui/mojo/display/display_type_converters.h" |
27 | 29 |
28 namespace mash { | 30 namespace mash { |
29 namespace wm { | 31 namespace wm { |
30 namespace { | 32 namespace { |
31 | 33 |
32 const uint32_t kWindowSwitchAccelerator = 1; | 34 const uint32_t kWindowSwitchAccelerator = 1; |
33 | 35 |
34 void AssertTrue(bool success) { | 36 void AssertTrue(bool success) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 return app_->connector(); | 71 return app_->connector(); |
70 } | 72 } |
71 | 73 |
72 mus::Window* RootWindowController::GetWindowForContainer( | 74 mus::Window* RootWindowController::GetWindowForContainer( |
73 mojom::Container container) { | 75 mojom::Container container) { |
74 return root_->GetChildByLocalId(ContainerToLocalId(container)); | 76 return root_->GetChildByLocalId(ContainerToLocalId(container)); |
75 } | 77 } |
76 | 78 |
77 bool RootWindowController::WindowIsContainer(const mus::Window* window) const { | 79 bool RootWindowController::WindowIsContainer(const mus::Window* window) const { |
78 return window && | 80 return window && |
79 window->local_id() > ContainerToLocalId(mojom::Container::ROOT) && | 81 window->local_id() > |
| 82 ContainerToLocalId(mojom::Container::ROOT_CONTAINER) && |
80 window->local_id() < ContainerToLocalId(mojom::Container::COUNT); | 83 window->local_id() < ContainerToLocalId(mojom::Container::COUNT); |
81 } | 84 } |
82 | 85 |
83 mus::WindowManagerClient* RootWindowController::window_manager_client() { | 86 mus::WindowManagerClient* RootWindowController::window_manager_client() { |
84 return window_manager_->window_manager_client(); | 87 return window_manager_->window_manager_client(); |
85 } | 88 } |
86 | 89 |
87 void RootWindowController::OnAccelerator(uint32_t id, const ui::Event& event) { | 90 void RootWindowController::OnAccelerator(uint32_t id, const ui::Event& event) { |
88 switch (id) { | 91 switch (id) { |
89 case kWindowSwitchAccelerator: | 92 case kWindowSwitchAccelerator: |
90 window_manager_client()->ActivateNextWindow(); | 93 window_manager_client()->ActivateNextWindow(); |
91 break; | 94 break; |
92 default: | 95 default: |
93 app_->OnAccelerator(id, event); | 96 app_->OnAccelerator(id, event); |
94 break; | 97 break; |
95 } | 98 } |
96 } | 99 } |
97 | 100 |
98 ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() { | 101 ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() { |
99 return static_cast<ShelfLayoutManager*>( | 102 return static_cast<ShelfLayoutManager*>( |
100 layout_manager_[GetWindowForContainer(mojom::Container::USER_SHELF)] | 103 layout_managers_[GetWindowForContainer( |
| 104 mojom::Container::USER_PRIVATE_SHELF)] |
101 .get()); | 105 .get()); |
102 } | 106 } |
103 | 107 |
104 StatusLayoutManager* RootWindowController::GetStatusLayoutManager() { | 108 StatusLayoutManager* RootWindowController::GetStatusLayoutManager() { |
105 return static_cast<StatusLayoutManager*>( | 109 return static_cast<StatusLayoutManager*>( |
106 layout_manager_[GetWindowForContainer(mojom::Container::STATUS)].get()); | 110 layout_managers_[GetWindowForContainer(mojom::Container::STATUS)].get()); |
107 } | 111 } |
108 | 112 |
109 RootWindowController::RootWindowController(WindowManagerApplication* app) | 113 RootWindowController::RootWindowController(WindowManagerApplication* app) |
110 : app_(app), root_(nullptr), window_count_(0) { | 114 : app_(app), root_(nullptr), window_count_(0) { |
111 window_manager_.reset(new WindowManager); | 115 window_manager_.reset(new WindowManager); |
112 } | 116 } |
113 | 117 |
114 RootWindowController::~RootWindowController() {} | 118 RootWindowController::~RootWindowController() {} |
115 | 119 |
116 void RootWindowController::AddAccelerators() { | 120 void RootWindowController::AddAccelerators() { |
117 window_manager_client()->AddAccelerator( | 121 window_manager_client()->AddAccelerator( |
118 kWindowSwitchAccelerator, | 122 kWindowSwitchAccelerator, |
119 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::TAB, | 123 mus::CreateKeyMatcher(mus::mojom::KeyboardCode::TAB, |
120 mus::mojom::kEventFlagControlDown), | 124 mus::mojom::kEventFlagControlDown), |
121 base::Bind(&AssertTrue)); | 125 base::Bind(&AssertTrue)); |
122 } | 126 } |
123 | 127 |
124 void RootWindowController::OnEmbed(mus::Window* root) { | 128 void RootWindowController::OnEmbed(mus::Window* root) { |
125 root_ = root; | 129 root_ = root; |
126 root_->set_local_id(ContainerToLocalId(mojom::Container::ROOT)); | 130 root_->set_local_id(ContainerToLocalId(mojom::Container::ROOT_CONTAINER)); |
127 root_->AddObserver(this); | 131 root_->AddObserver(this); |
128 layout_manager_[root_].reset(new FillLayout(root_)); | 132 layout_managers_[root_].reset(new FillLayout(root_)); |
129 | 133 |
130 app_->OnRootWindowControllerGotRoot(this); | 134 app_->OnRootWindowControllerGotRoot(this); |
131 | 135 |
132 CreateContainers(); | 136 CreateContainers(); |
133 | 137 |
134 // Override the default layout managers for certain containers. | 138 for (size_t i = 0; i < kNumActivationContainers; ++i) { |
135 mus::Window* user_background = | 139 window_manager_client()->AddActivationParent( |
136 GetWindowForContainer(mojom::Container::USER_BACKGROUND); | 140 GetWindowForContainer(kActivationContainers[i])); |
137 layout_manager_[user_background].reset(new BackgroundLayout(user_background)); | 141 } |
138 mus::Window* login_app = GetWindowForContainer(mojom::Container::LOGIN_APP); | |
139 layout_manager_[login_app].reset(new ScreenlockLayout(login_app)); | |
140 mus::Window* user_shelf = GetWindowForContainer(mojom::Container::USER_SHELF); | |
141 layout_manager_[user_shelf].reset(new ShelfLayoutManager(user_shelf)); | |
142 mus::Window* status = GetWindowForContainer(mojom::Container::STATUS); | |
143 layout_manager_[status].reset(new StatusLayoutManager(status)); | |
144 | |
145 mus::Window* window = GetWindowForContainer(mojom::Container::USER_WINDOWS); | |
146 layout_manager_[window].reset(new WindowLayout(window)); | |
147 window_manager_client()->AddActivationParent(window); | |
148 | |
149 // Bubble windows must be allowed to activate because some of them rely on | |
150 // deactivation to close. | |
151 mus::Window* bubbles = GetWindowForContainer(mojom::Container::BUBBLES); | |
152 window_manager_client()->AddActivationParent(bubbles); | |
153 | 142 |
154 AddAccelerators(); | 143 AddAccelerators(); |
155 | 144 |
156 window_manager_->Initialize(this, app_->session()); | 145 window_manager_->Initialize(this, app_->session()); |
157 | 146 |
158 shadow_controller_.reset(new ShadowController(root->connection())); | 147 shadow_controller_.reset(new ShadowController(root->connection())); |
159 | 148 |
160 app_->OnRootWindowControllerDoneInit(this); | 149 app_->OnRootWindowControllerDoneInit(this); |
161 } | 150 } |
162 | 151 |
(...skipping 16 matching lines...) Expand all Loading... |
179 // worry about the possibility of |root_| being null. | 168 // worry about the possibility of |root_| being null. |
180 window_manager_.reset(); | 169 window_manager_.reset(); |
181 root_ = nullptr; | 170 root_ = nullptr; |
182 } | 171 } |
183 | 172 |
184 void RootWindowController::CreateContainer( | 173 void RootWindowController::CreateContainer( |
185 mash::wm::mojom::Container container, | 174 mash::wm::mojom::Container container, |
186 mash::wm::mojom::Container parent_container) { | 175 mash::wm::mojom::Container parent_container) { |
187 mus::Window* window = root_->connection()->NewWindow(); | 176 mus::Window* window = root_->connection()->NewWindow(); |
188 window->set_local_id(ContainerToLocalId(container)); | 177 window->set_local_id(ContainerToLocalId(container)); |
189 layout_manager_[window].reset(new FillLayout(window)); | 178 layout_managers_[window].reset(new FillLayout(window)); |
| 179 |
190 // User private windows are hidden by default until the window manager learns | 180 // User private windows are hidden by default until the window manager learns |
191 // the lock state, so their contents are never accidentally revealed. | 181 // the lock state, so their contents are never accidentally revealed. |
192 window->SetVisible(container != mojom::Container::USER_PRIVATE); | 182 window->SetVisible(container != mojom::Container::USER_PRIVATE_CONTAINER); |
193 mus::Window* parent = | 183 mus::Window* parent = |
194 root_->GetChildByLocalId(ContainerToLocalId(parent_container)); | 184 root_->GetChildByLocalId(ContainerToLocalId(parent_container)); |
195 parent->AddChild(window); | 185 parent->AddChild(window); |
196 } | 186 } |
197 | 187 |
198 void RootWindowController::CreateContainers() { | 188 void RootWindowController::CreateContainers() { |
199 CreateContainer(mojom::Container::ALL_USER_BACKGROUND, | 189 CreateContainer(mojom::Container::ALL_USER_BACKGROUND, |
200 mojom::Container::ROOT); | 190 mojom::Container::ROOT_CONTAINER); |
201 CreateContainer(mojom::Container::USER_WORKSPACE, mojom::Container::ROOT); | 191 CreateContainer(mojom::Container::USER_CONTAINER, |
| 192 mojom::Container::ROOT_CONTAINER); |
202 CreateContainer(mojom::Container::USER_BACKGROUND, | 193 CreateContainer(mojom::Container::USER_BACKGROUND, |
203 mojom::Container::USER_WORKSPACE); | 194 mojom::Container::USER_CONTAINER); |
204 CreateContainer(mojom::Container::USER_PRIVATE, | 195 CreateContainer(mojom::Container::USER_PRIVATE_CONTAINER, |
205 mojom::Container::USER_WORKSPACE); | 196 mojom::Container::USER_CONTAINER); |
206 CreateContainer(mojom::Container::USER_WINDOWS, | 197 CreateContainer(mojom::Container::USER_PRIVATE_WINDOWS, |
207 mojom::Container::USER_PRIVATE); | 198 mojom::Container::USER_PRIVATE_CONTAINER); |
208 CreateContainer(mojom::Container::USER_ALWAYS_ON_TOP_WINDOWS, | 199 CreateContainer(mojom::Container::USER_PRIVATE_ALWAYS_ON_TOP_WINDOWS, |
209 mojom::Container::USER_PRIVATE); | 200 mojom::Container::USER_PRIVATE_CONTAINER); |
210 CreateContainer(mojom::Container::USER_PRESENTATION_WINDOWS, | 201 CreateContainer(mojom::Container::USER_PRIVATE_DOCKED_WINDOWS, |
211 mojom::Container::USER_PRIVATE); | 202 mojom::Container::USER_PRIVATE_CONTAINER); |
212 CreateContainer(mojom::Container::USER_SHELF, mojom::Container::USER_PRIVATE); | 203 CreateContainer(mojom::Container::USER_PRIVATE_PRESENTATION_WINDOWS, |
213 CreateContainer(mojom::Container::LOGIN_WINDOWS, mojom::Container::ROOT); | 204 mojom::Container::USER_PRIVATE_CONTAINER); |
214 CreateContainer(mojom::Container::LOGIN_APP, mojom::Container::LOGIN_WINDOWS); | 205 CreateContainer(mojom::Container::USER_PRIVATE_SHELF, |
| 206 mojom::Container::USER_PRIVATE_CONTAINER); |
| 207 CreateContainer(mojom::Container::USER_PRIVATE_PANELS, |
| 208 mojom::Container::USER_PRIVATE_CONTAINER); |
| 209 CreateContainer(mojom::Container::USER_PRIVATE_APP_LIST, |
| 210 mojom::Container::USER_PRIVATE_CONTAINER); |
| 211 CreateContainer(mojom::Container::USER_PRIVATE_SYSTEM_MODAL, |
| 212 mojom::Container::USER_PRIVATE_CONTAINER); |
| 213 CreateContainer(mojom::Container::LOGIN_CONTAINER, |
| 214 mojom::Container::ROOT_CONTAINER); |
| 215 CreateContainer(mojom::Container::LOGIN_WINDOWS, |
| 216 mojom::Container::LOGIN_CONTAINER); |
| 217 CreateContainer(mojom::Container::LOGIN_APP, |
| 218 mojom::Container::LOGIN_CONTAINER); |
215 CreateContainer(mojom::Container::LOGIN_SHELF, | 219 CreateContainer(mojom::Container::LOGIN_SHELF, |
216 mojom::Container::LOGIN_WINDOWS); | 220 mojom::Container::LOGIN_CONTAINER); |
217 CreateContainer(mojom::Container::STATUS, mojom::Container::ROOT); | 221 CreateContainer(mojom::Container::STATUS, mojom::Container::ROOT_CONTAINER); |
218 CreateContainer(mojom::Container::BUBBLES, mojom::Container::ROOT); | 222 CreateContainer(mojom::Container::BUBBLES, mojom::Container::ROOT_CONTAINER); |
219 CreateContainer(mojom::Container::SYSTEM_MODAL_WINDOWS, | 223 CreateContainer(mojom::Container::SYSTEM_MODAL_WINDOWS, |
220 mojom::Container::ROOT); | 224 mojom::Container::ROOT_CONTAINER); |
221 CreateContainer(mojom::Container::KEYBOARD, mojom::Container::ROOT); | 225 CreateContainer(mojom::Container::KEYBOARD, mojom::Container::ROOT_CONTAINER); |
222 CreateContainer(mojom::Container::MENUS, mojom::Container::ROOT); | 226 CreateContainer(mojom::Container::MENUS, mojom::Container::ROOT_CONTAINER); |
223 CreateContainer(mojom::Container::TOOLTIPS, mojom::Container::ROOT); | 227 CreateContainer(mojom::Container::DRAG_AND_TOOLTIPS, |
| 228 mojom::Container::ROOT_CONTAINER); |
| 229 |
| 230 // Override the default layout managers for certain containers. |
| 231 mus::Window* user_background = |
| 232 GetWindowForContainer(mojom::Container::USER_BACKGROUND); |
| 233 layout_managers_[user_background].reset( |
| 234 new BackgroundLayout(user_background)); |
| 235 |
| 236 mus::Window* login_app = GetWindowForContainer(mojom::Container::LOGIN_APP); |
| 237 layout_managers_[login_app].reset(new ScreenlockLayout(login_app)); |
| 238 |
| 239 mus::Window* user_shelf = |
| 240 GetWindowForContainer(mojom::Container::USER_PRIVATE_SHELF); |
| 241 layout_managers_[user_shelf].reset(new ShelfLayoutManager(user_shelf)); |
| 242 |
| 243 mus::Window* status = GetWindowForContainer(mojom::Container::STATUS); |
| 244 layout_managers_[status].reset(new StatusLayoutManager(status)); |
| 245 |
| 246 mus::Window* user_private_windows = |
| 247 GetWindowForContainer(mojom::Container::USER_PRIVATE_WINDOWS); |
| 248 layout_managers_[user_private_windows].reset( |
| 249 new WindowLayout(user_private_windows)); |
224 } | 250 } |
225 | 251 |
226 } // namespace wm | 252 } // namespace wm |
227 } // namespace mash | 253 } // namespace mash |
OLD | NEW |