Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: ash/mus/root_window_controller.cc

Issue 2072343002: Changes how window manager obtains WindowTree from mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/mus/root_window_controller.h ('k') | ash/mus/root_windows_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/mus/root_window_controller.h" 5 #include "ash/mus/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/common/root_window_controller_common.h" 12 #include "ash/common/root_window_controller_common.h"
13 #include "ash/common/shell_window_ids.h" 13 #include "ash/common/shell_window_ids.h"
14 #include "ash/common/wm/always_on_top_controller.h" 14 #include "ash/common/wm/always_on_top_controller.h"
15 #include "ash/common/wm/container_finder.h"
15 #include "ash/common/wm/dock/docked_window_layout_manager.h" 16 #include "ash/common/wm/dock/docked_window_layout_manager.h"
16 #include "ash/common/wm/panels/panel_layout_manager.h" 17 #include "ash/common/wm/panels/panel_layout_manager.h"
17 #include "ash/common/wm/root_window_layout_manager.h" 18 #include "ash/common/wm/root_window_layout_manager.h"
18 #include "ash/common/wm/workspace/workspace_layout_manager.h" 19 #include "ash/common/wm/workspace/workspace_layout_manager.h"
19 #include "ash/common/wm/workspace/workspace_layout_manager_delegate.h" 20 #include "ash/common/wm/workspace/workspace_layout_manager_delegate.h"
20 #include "ash/mus/bridge/wm_root_window_controller_mus.h" 21 #include "ash/mus/bridge/wm_root_window_controller_mus.h"
21 #include "ash/mus/bridge/wm_shelf_mus.h" 22 #include "ash/mus/bridge/wm_shelf_mus.h"
22 #include "ash/mus/bridge/wm_shell_mus.h" 23 #include "ash/mus/bridge/wm_shell_mus.h"
23 #include "ash/mus/bridge/wm_window_mus.h" 24 #include "ash/mus/bridge/wm_window_mus.h"
24 #include "ash/mus/container_ids.h" 25 #include "ash/mus/container_ids.h"
26 #include "ash/mus/non_client_frame_controller.h"
27 #include "ash/mus/property_util.h"
25 #include "ash/mus/screenlock_layout.h" 28 #include "ash/mus/screenlock_layout.h"
26 #include "ash/mus/shadow_controller.h"
27 #include "ash/mus/shelf_layout_manager.h" 29 #include "ash/mus/shelf_layout_manager.h"
28 #include "ash/mus/status_layout_manager.h" 30 #include "ash/mus/status_layout_manager.h"
29 #include "ash/mus/window_manager.h" 31 #include "ash/mus/window_manager.h"
30 #include "ash/mus/window_manager_application.h"
31 #include "base/bind.h" 32 #include "base/bind.h"
32 #include "base/command_line.h" 33 #include "base/command_line.h"
33 #include "base/memory/ptr_util.h" 34 #include "base/memory/ptr_util.h"
34 #include "components/mus/common/event_matcher_util.h"
35 #include "components/mus/common/switches.h" 35 #include "components/mus/common/switches.h"
36 #include "components/mus/common/util.h" 36 #include "components/mus/common/util.h"
37 #include "components/mus/public/cpp/property_type_converters.h" 37 #include "components/mus/public/cpp/property_type_converters.h"
38 #include "components/mus/public/cpp/window.h" 38 #include "components/mus/public/cpp/window.h"
39 #include "components/mus/public/cpp/window_property.h"
39 #include "components/mus/public/cpp/window_tree_client.h" 40 #include "components/mus/public/cpp/window_tree_client.h"
40 #include "components/mus/public/cpp/window_tree_host_factory.h" 41 #include "components/mus/public/cpp/window_tree_host_factory.h"
41 #include "components/mus/public/interfaces/window_manager.mojom.h"
42 #include "mash/session/public/interfaces/session.mojom.h"
43 #include "mojo/public/cpp/bindings/type_converter.h" 42 #include "mojo/public/cpp/bindings/type_converter.h"
44 #include "services/shell/public/cpp/connector.h" 43 #include "services/shell/public/cpp/connector.h"
45 #include "ui/display/mojo/display_type_converters.h" 44 #include "ui/display/mojo/display_type_converters.h"
46 45
47 using ash::mojom::Container; 46 using ash::mojom::Container;
48 47
49 namespace ash { 48 namespace ash {
50 namespace mus { 49 namespace mus {
51 namespace { 50 namespace {
52 51
53 const uint32_t kWindowSwitchAccelerator = 1;
54
55 void AssertTrue(bool success) {
56 DCHECK(success);
57 }
58
59 class WorkspaceLayoutManagerDelegateImpl 52 class WorkspaceLayoutManagerDelegateImpl
60 : public wm::WorkspaceLayoutManagerDelegate { 53 : public wm::WorkspaceLayoutManagerDelegate {
61 public: 54 public:
62 explicit WorkspaceLayoutManagerDelegateImpl( 55 explicit WorkspaceLayoutManagerDelegateImpl(
63 WmRootWindowControllerMus* root_window_controller) 56 WmRootWindowControllerMus* root_window_controller)
64 : root_window_controller_(root_window_controller) {} 57 : root_window_controller_(root_window_controller) {}
65 ~WorkspaceLayoutManagerDelegateImpl() override = default; 58 ~WorkspaceLayoutManagerDelegateImpl() override = default;
66 59
67 // WorkspaceLayoutManagerDelegate: 60 // WorkspaceLayoutManagerDelegate:
68 void UpdateShelfVisibility() override { NOTIMPLEMENTED(); } 61 void UpdateShelfVisibility() override { NOTIMPLEMENTED(); }
69 void OnFullscreenStateChanged(bool is_fullscreen) override { 62 void OnFullscreenStateChanged(bool is_fullscreen) override {
70 // TODO(sky): this should only do something if there is a shelf, see 63 // TODO(sky): this should only do something if there is a shelf, see
71 // implementation in ash/shell.cc. 64 // implementation in ash/shell.cc.
72 NOTIMPLEMENTED(); 65 NOTIMPLEMENTED();
73 root_window_controller_->NotifyFullscreenStateChange(is_fullscreen); 66 root_window_controller_->NotifyFullscreenStateChange(is_fullscreen);
74 } 67 }
75 68
76 private: 69 private:
77 WmRootWindowControllerMus* root_window_controller_; 70 WmRootWindowControllerMus* root_window_controller_;
78 71
79 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerDelegateImpl); 72 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerDelegateImpl);
80 }; 73 };
81 74
82 } // namespace 75 } // namespace
83 76
84 // static 77 RootWindowController::RootWindowController(WindowManager* window_manager,
85 RootWindowController* RootWindowController::CreateFromDisplay( 78 ::mus::Window* root,
86 WindowManagerApplication* app, 79 const display::Display& display)
87 ::mus::mojom::DisplayPtr display, 80 : window_manager_(window_manager),
88 ::mus::mojom::WindowTreeClientRequest client_request) { 81 root_(root),
89 RootWindowController* controller = new RootWindowController(app); 82 window_count_(0),
90 controller->display_ = display.To<display::Display>(); 83 display_(display) {
91 new ::mus::WindowTreeClient(controller, controller->window_manager_.get(), 84 wm_root_window_controller_.reset(
92 std::move(client_request)); 85 new WmRootWindowControllerMus(window_manager_->shell(), this));
93 return controller; 86
87 root_window_controller_common_.reset(
88 new RootWindowControllerCommon(WmWindowMus::Get(root_)));
89 root_window_controller_common_->CreateContainers();
90 root_window_controller_common_->CreateLayoutManagers();
91 CreateLayoutManagers();
92
93 disconnected_app_handler_.reset(new DisconnectedAppHandler(root));
94
95 // Force a layout of the root, and its children, RootWindowLayout handles
96 // both.
97 root_window_controller_common_->root_window_layout()->OnWindowResized();
98
99 for (size_t i = 0; i < kNumActivatableShellWindowIds; ++i) {
100 window_manager_->window_manager_client()->AddActivationParent(
101 GetWindowByShellWindowId(kActivatableShellWindowIds[i])->mus_window());
102 }
103
104 WmWindowMus* always_on_top_container =
105 GetWindowByShellWindowId(kShellWindowId_AlwaysOnTopContainer);
106 always_on_top_controller_.reset(
107 new AlwaysOnTopController(always_on_top_container));
94 } 108 }
95 109
96 void RootWindowController::Destroy() { 110 RootWindowController::~RootWindowController() {}
97 // See class description for details on lifetime. 111
98 if (root_) { 112 shell::Connector* RootWindowController::GetConnector() {
99 delete root_->window_tree(); 113 return window_manager_->connector();
100 } else {
101 // This case only happens if we're destroyed before OnEmbed().
102 delete this;
103 }
104 } 114 }
105 115
106 shell::Connector* RootWindowController::GetConnector() { 116 ::mus::Window* RootWindowController::NewTopLevelWindow(
107 return app_->connector(); 117 std::map<std::string, std::vector<uint8_t>>* properties) {
118 // TODO(sky): panels need a different frame, http:://crbug.com/614362.
119 const bool provide_non_client_frame =
120 GetWindowType(*properties) == ::mus::mojom::WindowType::WINDOW ||
121 GetWindowType(*properties) == ::mus::mojom::WindowType::PANEL;
122 if (provide_non_client_frame)
123 (*properties)[::mus::mojom::kWaitForUnderlay_Property].clear();
124
125 // TODO(sky): constrain and validate properties before passing to server.
126 ::mus::Window* window = root_->window_tree()->NewWindow(properties);
127 window->SetBounds(CalculateDefaultBounds(window));
128
129 ::mus::Window* container_window = nullptr;
130 mojom::Container container;
131 if (GetRequestedContainer(window, &container)) {
132 container_window = GetWindowForContainer(container);
133 } else {
134 // TODO(sky): window->bounds() isn't quite right.
135 container_window = WmWindowMus::GetMusWindow(wm::GetDefaultParent(
136 WmWindowMus::Get(root_), WmWindowMus::Get(window), window->bounds()));
137 }
138 DCHECK(WmWindowMus::Get(container_window)->IsContainer());
139
140 if (provide_non_client_frame) {
141 NonClientFrameController::Create(GetConnector(), container_window, window,
142 window_manager_->window_manager_client());
143 } else {
144 container_window->AddChild(window);
145 }
146
147 window_count_++;
148
149 return window;
108 } 150 }
109 151
110 ::mus::Window* RootWindowController::GetWindowForContainer( 152 ::mus::Window* RootWindowController::GetWindowForContainer(
111 Container container) { 153 Container container) {
112 WmWindowMus* wm_window = 154 WmWindowMus* wm_window =
113 GetWindowByShellWindowId(MashContainerToAshShellWindowId(container)); 155 GetWindowByShellWindowId(MashContainerToAshShellWindowId(container));
114 DCHECK(wm_window); 156 DCHECK(wm_window);
115 return wm_window->mus_window(); 157 return wm_window->mus_window();
116 } 158 }
117 159
118 bool RootWindowController::WindowIsContainer(::mus::Window* window) {
119 return window &&
120 WmWindowMus::Get(window)->GetShellWindowId() != kShellWindowId_Invalid;
121 }
122
123 WmWindowMus* RootWindowController::GetWindowByShellWindowId(int id) { 160 WmWindowMus* RootWindowController::GetWindowByShellWindowId(int id) {
124 return WmWindowMus::AsWmWindowMus( 161 return WmWindowMus::AsWmWindowMus(
125 WmWindowMus::Get(root_)->GetChildByShellWindowId(id)); 162 WmWindowMus::Get(root_)->GetChildByShellWindowId(id));
126 } 163 }
127 164
128 ::mus::WindowManagerClient* RootWindowController::window_manager_client() {
129 return window_manager_->window_manager_client();
130 }
131
132 void RootWindowController::OnAccelerator(uint32_t id, const ui::Event& event) {
133 switch (id) {
134 case kWindowSwitchAccelerator:
135 window_manager_client()->ActivateNextWindow();
136 break;
137 default:
138 app_->OnAccelerator(id, event);
139 break;
140 }
141 }
142
143 ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() { 165 ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
144 return static_cast<ShelfLayoutManager*>( 166 return static_cast<ShelfLayoutManager*>(
145 layout_managers_[GetWindowForContainer(Container::USER_PRIVATE_SHELF)] 167 layout_managers_[GetWindowForContainer(Container::USER_PRIVATE_SHELF)]
146 .get()); 168 .get());
147 } 169 }
148 170
149 StatusLayoutManager* RootWindowController::GetStatusLayoutManager() { 171 StatusLayoutManager* RootWindowController::GetStatusLayoutManager() {
150 return static_cast<StatusLayoutManager*>( 172 return static_cast<StatusLayoutManager*>(
151 layout_managers_[GetWindowForContainer(Container::STATUS)].get()); 173 layout_managers_[GetWindowForContainer(Container::STATUS)].get());
152 } 174 }
153 175
154 RootWindowController::RootWindowController(WindowManagerApplication* app) 176 gfx::Rect RootWindowController::CalculateDefaultBounds(
155 : app_(app), root_(nullptr), window_count_(0) { 177 ::mus::Window* window) const {
156 window_manager_.reset(new WindowManager); 178 if (window->HasSharedProperty(
157 } 179 ::mus::mojom::WindowManager::kInitialBounds_Property)) {
158 180 return window->GetSharedProperty<gfx::Rect>(
159 RootWindowController::~RootWindowController() {} 181 ::mus::mojom::WindowManager::kInitialBounds_Property);
160
161 void RootWindowController::AddAccelerators() {
162 window_manager_client()->AddAccelerator(
163 kWindowSwitchAccelerator,
164 ::mus::CreateKeyMatcher(ui::mojom::KeyboardCode::TAB,
165 ui::mojom::kEventFlagControlDown),
166 base::Bind(&AssertTrue));
167 }
168
169 void RootWindowController::OnEmbed(::mus::Window* root) {
170 root_ = root;
171 root_->AddObserver(this);
172
173 app_->OnRootWindowControllerGotRoot(this);
174
175 wm_root_window_controller_.reset(
176 new WmRootWindowControllerMus(app_->shell(), this));
177
178 root_window_controller_common_.reset(
179 new RootWindowControllerCommon(WmWindowMus::Get(root_)));
180 root_window_controller_common_->CreateContainers();
181 root_window_controller_common_->CreateLayoutManagers();
182 CreateLayoutManagers();
183
184 // Force a layout of the root, and its children, RootWindowLayout handles
185 // both.
186 root_window_controller_common_->root_window_layout()->OnWindowResized();
187
188 for (size_t i = 0; i < kNumActivatableShellWindowIds; ++i) {
189 window_manager_client()->AddActivationParent(
190 GetWindowByShellWindowId(kActivatableShellWindowIds[i])->mus_window());
191 } 182 }
192 183
193 WmWindowMus* always_on_top_container = 184 int width, height;
194 GetWindowByShellWindowId(kShellWindowId_AlwaysOnTopContainer); 185 const gfx::Size pref = GetWindowPreferredSize(window);
195 always_on_top_controller_.reset( 186 if (pref.IsEmpty()) {
196 new AlwaysOnTopController(always_on_top_container)); 187 width = root_->bounds().width() - 240;
197 188 height = root_->bounds().height() - 240;
198 AddAccelerators(); 189 } else {
199 190 // TODO(sky): likely want to constrain more than root size.
200 window_manager_->Initialize(this, app_->session()); 191 const gfx::Size max_size = root_->bounds().size();
201 192 width = std::max(0, std::min(max_size.width(), pref.width()));
202 shadow_controller_.reset(new ShadowController(root->window_tree())); 193 height = std::max(0, std::min(max_size.height(), pref.height()));
203 194 }
204 app_->OnRootWindowControllerDoneInit(this); 195 return gfx::Rect(40 + (window_count_ % 4) * 40, 40 + (window_count_ % 4) * 40,
205 } 196 width, height);
206
207 void RootWindowController::OnWindowTreeClientDestroyed(
208 ::mus::WindowTreeClient* client) {
209 shadow_controller_.reset();
210 delete this;
211 }
212
213 void RootWindowController::OnEventObserved(const ui::Event& event,
214 ::mus::Window* target) {
215 // Does not use EventObservers.
216 }
217
218 void RootWindowController::OnWindowDestroyed(::mus::Window* window) {
219 DCHECK_EQ(window, root_);
220 app_->OnRootWindowDestroyed(this);
221 root_->RemoveObserver(this);
222 // Delete the |window_manager_| here so that WindowManager doesn't have to
223 // worry about the possibility of |root_| being null.
224 window_manager_.reset();
225 root_ = nullptr;
226 } 197 }
227 198
228 void RootWindowController::OnShelfWindowAvailable() { 199 void RootWindowController::OnShelfWindowAvailable() {
229 DockedWindowLayoutManager::Get(WmWindowMus::Get(root_)) 200 DockedWindowLayoutManager::Get(WmWindowMus::Get(root_))
230 ->SetShelf(wm_shelf_.get()); 201 ->SetShelf(wm_shelf_.get());
231 202
232 PanelLayoutManager::Get(WmWindowMus::Get(root_))->SetShelf(wm_shelf_.get()); 203 PanelLayoutManager::Get(WmWindowMus::Get(root_))->SetShelf(wm_shelf_.get());
233 204
234 // TODO: http://crbug.com/614182 Ash's ShelfLayoutManager implements 205 // TODO: http://crbug.com/614182 Ash's ShelfLayoutManager implements
235 // DockedWindowLayoutManagerObserver so that it can inset by the docked 206 // DockedWindowLayoutManagerObserver so that it can inset by the docked
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 base::WrapUnique(new DockedWindowLayoutManager(docked_container))); 245 base::WrapUnique(new DockedWindowLayoutManager(docked_container)));
275 246
276 WmWindowMus* panel_container = 247 WmWindowMus* panel_container =
277 GetWindowByShellWindowId(kShellWindowId_PanelContainer); 248 GetWindowByShellWindowId(kShellWindowId_PanelContainer);
278 panel_container->SetLayoutManager( 249 panel_container->SetLayoutManager(
279 base::WrapUnique(new PanelLayoutManager(panel_container))); 250 base::WrapUnique(new PanelLayoutManager(panel_container)));
280 } 251 }
281 252
282 } // namespace mus 253 } // namespace mus
283 } // namespace ash 254 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/root_window_controller.h ('k') | ash/mus/root_windows_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698