Chromium Code Reviews| 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 <map> | 9 #include <map> |
| 10 #include <sstream> | 10 #include <sstream> |
| 11 | 11 |
| 12 #include "ash/wm/common/always_on_top_controller.h" | |
| 13 #include "ash/wm/common/wm_shell_window_ids.h" | |
| 14 #include "ash/wm/common/workspace/workspace_layout_manager.h" | |
| 15 #include "ash/wm/common/workspace/workspace_layout_manager_delegate.h" | |
| 12 #include "base/bind.h" | 16 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/memory/ptr_util.h" | |
| 14 #include "components/mus/common/event_matcher_util.h" | 19 #include "components/mus/common/event_matcher_util.h" |
| 15 #include "components/mus/common/switches.h" | 20 #include "components/mus/common/switches.h" |
| 16 #include "components/mus/common/util.h" | 21 #include "components/mus/common/util.h" |
| 17 #include "components/mus/public/cpp/property_type_converters.h" | 22 #include "components/mus/public/cpp/property_type_converters.h" |
| 18 #include "components/mus/public/cpp/window.h" | 23 #include "components/mus/public/cpp/window.h" |
| 19 #include "components/mus/public/cpp/window_tree_connection.h" | 24 #include "components/mus/public/cpp/window_tree_connection.h" |
| 20 #include "components/mus/public/cpp/window_tree_host_factory.h" | 25 #include "components/mus/public/cpp/window_tree_host_factory.h" |
| 21 #include "components/mus/public/interfaces/window_manager.mojom.h" | 26 #include "components/mus/public/interfaces/window_manager.mojom.h" |
| 22 #include "mash/session/public/interfaces/session.mojom.h" | 27 #include "mash/session/public/interfaces/session.mojom.h" |
| 23 #include "mash/wm/background_layout.h" | 28 #include "mash/wm/background_layout.h" |
| 29 #include "mash/wm/bridge/wm_globals_mus.h" | |
| 30 #include "mash/wm/bridge/wm_root_window_controller_mus.h" | |
| 31 #include "mash/wm/bridge/wm_shelf_mus.h" | |
| 32 #include "mash/wm/bridge/wm_window_mus.h" | |
| 24 #include "mash/wm/container_ids.h" | 33 #include "mash/wm/container_ids.h" |
| 25 #include "mash/wm/fill_layout.h" | 34 #include "mash/wm/fill_layout.h" |
| 26 #include "mash/wm/screenlock_layout.h" | 35 #include "mash/wm/screenlock_layout.h" |
| 27 #include "mash/wm/shadow_controller.h" | 36 #include "mash/wm/shadow_controller.h" |
| 28 #include "mash/wm/shelf_layout_manager.h" | 37 #include "mash/wm/shelf_layout_manager.h" |
| 29 #include "mash/wm/status_layout_manager.h" | 38 #include "mash/wm/status_layout_manager.h" |
| 30 #include "mash/wm/window_layout.h" | |
| 31 #include "mash/wm/window_manager.h" | 39 #include "mash/wm/window_manager.h" |
| 32 #include "mash/wm/window_manager_application.h" | 40 #include "mash/wm/window_manager_application.h" |
| 41 #include "mojo/converters/geometry/geometry_type_converters.h" | |
| 33 #include "mojo/public/cpp/bindings/type_converter.h" | 42 #include "mojo/public/cpp/bindings/type_converter.h" |
| 34 #include "services/shell/public/cpp/connector.h" | 43 #include "services/shell/public/cpp/connector.h" |
| 35 #include "ui/mojo/display/display_type_converters.h" | 44 #include "ui/mojo/display/display_type_converters.h" |
| 36 | 45 |
| 37 namespace mash { | 46 namespace mash { |
| 38 namespace wm { | 47 namespace wm { |
| 39 namespace { | 48 namespace { |
| 40 | 49 |
| 41 const uint32_t kWindowSwitchAccelerator = 1; | 50 const uint32_t kWindowSwitchAccelerator = 1; |
| 42 | 51 |
| 43 void AssertTrue(bool success) { | 52 void AssertTrue(bool success) { |
| 44 DCHECK(success); | 53 DCHECK(success); |
| 45 } | 54 } |
| 46 | 55 |
| 47 int ContainerToLocalId(mojom::Container container) { | 56 int ContainerToLocalId(mojom::Container container) { |
| 48 return static_cast<int>(container); | 57 return static_cast<int>(container); |
| 49 } | 58 } |
| 50 | 59 |
| 60 class WorkspaceLayoutManagerDelegateImpl | |
| 61 : public ash::wm::WorkspaceLayoutManagerDelegate { | |
| 62 public: | |
| 63 explicit WorkspaceLayoutManagerDelegateImpl( | |
| 64 WmRootWindowControllerMus* root_window_controller) | |
| 65 : root_window_controller_(root_window_controller) {} | |
| 66 ~WorkspaceLayoutManagerDelegateImpl() override = default; | |
|
James Cook
2016/05/19 05:08:21
Just for my edification: Is there an advantage to
sky
2016/05/19 15:14:24
Good question. I'm not sure. I copied this code fr
James Cook
2016/05/19 15:27:46
Acknowledged.
| |
| 67 | |
| 68 // WorkspaceLayoutManagerDelegate: | |
| 69 void UpdateShelfVisibility() override { NOTIMPLEMENTED(); } | |
| 70 void OnFullscreenStateChanged(bool is_fullscreen) override { | |
| 71 // TODO(sky): this should only do something if there is a shelf, see | |
| 72 // implementation in ash/shell.cc. | |
| 73 NOTIMPLEMENTED(); | |
| 74 root_window_controller_->NotifyFullscreenStateChange(is_fullscreen); | |
| 75 } | |
| 76 | |
| 77 private: | |
| 78 WmRootWindowControllerMus* root_window_controller_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerDelegateImpl); | |
| 81 }; | |
| 82 | |
| 51 } // namespace | 83 } // namespace |
| 52 | 84 |
| 53 // static | 85 // static |
| 54 RootWindowController* RootWindowController::CreateFromDisplay( | 86 RootWindowController* RootWindowController::CreateFromDisplay( |
| 55 WindowManagerApplication* app, | 87 WindowManagerApplication* app, |
| 56 mus::mojom::DisplayPtr display, | 88 mus::mojom::DisplayPtr display, |
| 57 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> client_request) { | 89 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> client_request) { |
| 58 RootWindowController* controller = new RootWindowController(app); | 90 RootWindowController* controller = new RootWindowController(app); |
| 59 controller->display_ = display.To<display::Display>(); | 91 controller->display_ = display.To<display::Display>(); |
| 60 mus::WindowTreeConnection::CreateForWindowManager( | 92 mus::WindowTreeConnection::CreateForWindowManager( |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 } | 164 } |
| 133 | 165 |
| 134 void RootWindowController::OnEmbed(mus::Window* root) { | 166 void RootWindowController::OnEmbed(mus::Window* root) { |
| 135 root_ = root; | 167 root_ = root; |
| 136 root_->set_local_id(ContainerToLocalId(mojom::Container::ROOT)); | 168 root_->set_local_id(ContainerToLocalId(mojom::Container::ROOT)); |
| 137 root_->AddObserver(this); | 169 root_->AddObserver(this); |
| 138 layout_managers_[root_].reset(new FillLayout(root_)); | 170 layout_managers_[root_].reset(new FillLayout(root_)); |
| 139 | 171 |
| 140 app_->OnRootWindowControllerGotRoot(this); | 172 app_->OnRootWindowControllerGotRoot(this); |
| 141 | 173 |
| 174 wm_root_window_controller_.reset( | |
| 175 new WmRootWindowControllerMus(app_->globals(), this)); | |
| 176 | |
| 142 CreateContainers(); | 177 CreateContainers(); |
| 143 | 178 |
| 144 for (size_t i = 0; i < kNumActivationContainers; ++i) { | 179 for (size_t i = 0; i < kNumActivationContainers; ++i) { |
| 145 window_manager_client()->AddActivationParent( | 180 window_manager_client()->AddActivationParent( |
| 146 GetWindowForContainer(kActivationContainers[i])); | 181 GetWindowForContainer(kActivationContainers[i])); |
| 147 } | 182 } |
| 148 | 183 |
| 184 ash::wm::WmWindow* always_on_top_container = | |
| 185 wm::WmWindowMus::Get(root)->GetChildByShellWindowId( | |
| 186 ash::kShellWindowId_AlwaysOnTopContainer); | |
| 187 always_on_top_controller_.reset( | |
| 188 new ash::AlwaysOnTopController(always_on_top_container)); | |
| 189 | |
| 149 AddAccelerators(); | 190 AddAccelerators(); |
| 150 | 191 |
| 151 window_manager_->Initialize(this, app_->session()); | 192 window_manager_->Initialize(this, app_->session()); |
| 152 | 193 |
| 153 shadow_controller_.reset(new ShadowController(root->connection())); | 194 shadow_controller_.reset(new ShadowController(root->connection())); |
| 154 | 195 |
| 155 app_->OnRootWindowControllerDoneInit(this); | 196 app_->OnRootWindowControllerDoneInit(this); |
| 156 } | 197 } |
| 157 | 198 |
| 158 void RootWindowController::OnConnectionLost( | 199 void RootWindowController::OnConnectionLost( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 183 // which makes the window hierarchy easier to read. | 224 // which makes the window hierarchy easier to read. |
| 184 std::map<std::string, std::vector<uint8_t>> properties; | 225 std::map<std::string, std::vector<uint8_t>> properties; |
| 185 std::ostringstream container_name; | 226 std::ostringstream container_name; |
| 186 container_name << container; | 227 container_name << container; |
| 187 properties[mus::mojom::WindowManager::kName_Property] = | 228 properties[mus::mojom::WindowManager::kName_Property] = |
| 188 mojo::ConvertTo<std::vector<uint8_t>>(container_name.str()); | 229 mojo::ConvertTo<std::vector<uint8_t>>(container_name.str()); |
| 189 | 230 |
| 190 mus::Window* window = root_->connection()->NewWindow(&properties); | 231 mus::Window* window = root_->connection()->NewWindow(&properties); |
| 191 window->set_local_id(ContainerToLocalId(container)); | 232 window->set_local_id(ContainerToLocalId(container)); |
| 192 layout_managers_[window].reset(new FillLayout(window)); | 233 layout_managers_[window].reset(new FillLayout(window)); |
| 234 WmWindowMus::Get(window)->SetShellWindowId( | |
| 235 MashContainerToAshContainer(container)); | |
| 193 | 236 |
| 194 // User private windows are hidden by default until the window manager learns | 237 // User private windows are hidden by default until the window manager learns |
| 195 // the lock state, so their contents are never accidentally revealed. Tests, | 238 // the lock state, so their contents are never accidentally revealed. Tests, |
| 196 // however, usually assume the screen is unlocked. | 239 // however, usually assume the screen is unlocked. |
| 197 const bool is_test = base::CommandLine::ForCurrentProcess()->HasSwitch( | 240 const bool is_test = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 198 mus::switches::kUseTestConfig); | 241 mus::switches::kUseTestConfig); |
| 199 window->SetVisible(container != mojom::Container::USER_PRIVATE || is_test); | 242 window->SetVisible(container != mojom::Container::USER_PRIVATE || is_test); |
| 200 | 243 |
| 201 mus::Window* parent = | 244 mus::Window* parent = |
| 202 root_->GetChildByLocalId(ContainerToLocalId(parent_container)); | 245 root_->GetChildByLocalId(ContainerToLocalId(parent_container)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 mus::Window* user_background = | 284 mus::Window* user_background = |
| 242 GetWindowForContainer(mojom::Container::USER_BACKGROUND); | 285 GetWindowForContainer(mojom::Container::USER_BACKGROUND); |
| 243 layout_managers_[user_background].reset( | 286 layout_managers_[user_background].reset( |
| 244 new BackgroundLayout(user_background)); | 287 new BackgroundLayout(user_background)); |
| 245 | 288 |
| 246 mus::Window* login_app = GetWindowForContainer(mojom::Container::LOGIN_APP); | 289 mus::Window* login_app = GetWindowForContainer(mojom::Container::LOGIN_APP); |
| 247 layout_managers_[login_app].reset(new ScreenlockLayout(login_app)); | 290 layout_managers_[login_app].reset(new ScreenlockLayout(login_app)); |
| 248 | 291 |
| 249 mus::Window* user_shelf = | 292 mus::Window* user_shelf = |
| 250 GetWindowForContainer(mojom::Container::USER_PRIVATE_SHELF); | 293 GetWindowForContainer(mojom::Container::USER_PRIVATE_SHELF); |
| 251 layout_managers_[user_shelf].reset(new ShelfLayoutManager(user_shelf)); | 294 ShelfLayoutManager* shelf_layout_manager = new ShelfLayoutManager(user_shelf); |
| 295 layout_managers_[user_shelf].reset(shelf_layout_manager); | |
| 296 | |
| 297 wm_shelf_.reset(new WmShelfMus(shelf_layout_manager)); | |
| 252 | 298 |
| 253 mus::Window* status = GetWindowForContainer(mojom::Container::STATUS); | 299 mus::Window* status = GetWindowForContainer(mojom::Container::STATUS); |
| 254 layout_managers_[status].reset(new StatusLayoutManager(status)); | 300 layout_managers_[status].reset(new StatusLayoutManager(status)); |
| 255 | 301 |
| 256 mus::Window* user_private_windows = | 302 mus::Window* user_private_windows = |
| 257 GetWindowForContainer(mojom::Container::USER_PRIVATE_WINDOWS); | 303 GetWindowForContainer(mojom::Container::USER_PRIVATE_WINDOWS); |
| 258 layout_managers_[user_private_windows].reset( | 304 layout_managers_.erase(user_private_windows); |
|
James Cook
2016/05/19 05:08:21
This section reads a little oddly... maybe a comme
sky
2016/05/19 15:14:24
layout_managers_ is a different type of LayoutMana
| |
| 259 new WindowLayout(user_private_windows)); | 305 std::unique_ptr<WorkspaceLayoutManagerDelegateImpl> |
| 306 workspace_layout_manager_delegate(new WorkspaceLayoutManagerDelegateImpl( | |
| 307 wm_root_window_controller_.get())); | |
| 308 WmWindowMus::Get(user_private_windows) | |
| 309 ->SetLayoutManager(base::WrapUnique(new ash::WorkspaceLayoutManager( | |
| 310 WmWindowMus::Get(user_private_windows), | |
| 311 std::move(workspace_layout_manager_delegate)))); | |
| 260 } | 312 } |
| 261 | 313 |
| 262 } // namespace wm | 314 } // namespace wm |
| 263 } // namespace mash | 315 } // namespace mash |
| OLD | NEW |