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