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 "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 <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
11 #include <sstream> | 11 #include <sstream> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "ash/common/shelf/shelf_layout_manager.h" | 16 #include "ash/common/shelf/shelf_layout_manager.h" |
17 #include "ash/common/shelf/wm_shelf.h" | 17 #include "ash/common/shelf/wm_shelf.h" |
18 #include "ash/common/wm/container_finder.h" | 18 #include "ash/common/wm/container_finder.h" |
19 #include "ash/common/wm/dock/docked_window_layout_manager.h" | 19 #include "ash/common/wm/dock/docked_window_layout_manager.h" |
20 #include "ash/common/wm/panels/panel_layout_manager.h" | 20 #include "ash/common/wm/panels/panel_layout_manager.h" |
21 #include "ash/common/wm/root_window_layout_manager.h" | 21 #include "ash/common/wm/root_window_layout_manager.h" |
22 #include "ash/mus/bridge/wm_root_window_controller_mus.h" | |
23 #include "ash/mus/bridge/wm_shell_mus.h" | 22 #include "ash/mus/bridge/wm_shell_mus.h" |
24 #include "ash/mus/bridge/wm_window_mus.h" | 23 #include "ash/mus/bridge/wm_window_mus.h" |
25 #include "ash/mus/non_client_frame_controller.h" | 24 #include "ash/mus/non_client_frame_controller.h" |
26 #include "ash/mus/property_util.h" | 25 #include "ash/mus/property_util.h" |
27 #include "ash/mus/screen_mus.h" | 26 #include "ash/mus/screen_mus.h" |
28 #include "ash/mus/window_manager.h" | 27 #include "ash/mus/window_manager.h" |
29 #include "ash/public/cpp/shell_window_ids.h" | 28 #include "ash/public/cpp/shell_window_ids.h" |
30 #include "ash/wm/stacking_controller.h" | 29 #include "ash/root_window_settings.h" |
31 #include "base/bind.h" | 30 #include "base/bind.h" |
32 #include "base/command_line.h" | 31 #include "base/command_line.h" |
33 #include "base/memory/ptr_util.h" | 32 #include "base/memory/ptr_util.h" |
34 #include "mojo/public/cpp/bindings/type_converter.h" | 33 #include "mojo/public/cpp/bindings/type_converter.h" |
35 #include "services/service_manager/public/cpp/connector.h" | 34 #include "services/service_manager/public/cpp/connector.h" |
36 #include "services/ui/common/switches.h" | 35 #include "services/ui/common/switches.h" |
37 #include "services/ui/common/util.h" | 36 #include "services/ui/common/util.h" |
38 #include "ui/aura/client/aura_constants.h" | 37 #include "ui/aura/client/aura_constants.h" |
39 #include "ui/aura/mus/property_converter.h" | 38 #include "ui/aura/mus/property_converter.h" |
40 #include "ui/aura/mus/property_utils.h" | 39 #include "ui/aura/mus/property_utils.h" |
41 #include "ui/aura/mus/window_tree_client.h" | 40 #include "ui/aura/mus/window_tree_client.h" |
42 #include "ui/aura/mus/window_tree_host_mus.h" | 41 #include "ui/aura/mus/window_tree_host_mus.h" |
43 #include "ui/aura/window.h" | 42 #include "ui/aura/window.h" |
| 43 #include "ui/aura/window_property.h" |
44 #include "ui/base/ui_base_types.h" | 44 #include "ui/base/ui_base_types.h" |
45 #include "ui/display/display_list.h" | 45 #include "ui/display/display_list.h" |
46 | 46 |
| 47 DECLARE_WINDOW_PROPERTY_TYPE(ash::mus::RootWindowController*); |
| 48 |
47 namespace ash { | 49 namespace ash { |
48 namespace mus { | 50 namespace mus { |
49 namespace { | 51 namespace { |
50 | 52 |
| 53 DEFINE_LOCAL_WINDOW_PROPERTY_KEY(ash::mus::RootWindowController*, |
| 54 kRootWindowControllerKey, |
| 55 nullptr); |
| 56 |
51 bool IsFullscreen(aura::PropertyConverter* property_converter, | 57 bool IsFullscreen(aura::PropertyConverter* property_converter, |
52 const std::vector<uint8_t>& transport_data) { | 58 const std::vector<uint8_t>& transport_data) { |
53 using ui::mojom::WindowManager; | 59 using ui::mojom::WindowManager; |
54 aura::PropertyConverter::PrimitiveType show_state = 0; | 60 aura::PropertyConverter::PrimitiveType show_state = 0; |
55 return property_converter->GetPropertyValueFromTransportValue( | 61 return property_converter->GetPropertyValueFromTransportValue( |
56 WindowManager::kShowState_Property, transport_data, &show_state) && | 62 WindowManager::kShowState_Property, transport_data, &show_state) && |
57 (static_cast<ui::WindowShowState>(show_state) == | 63 (static_cast<ui::WindowShowState>(show_state) == |
58 ui::SHOW_STATE_FULLSCREEN); | 64 ui::SHOW_STATE_FULLSCREEN); |
59 } | 65 } |
60 | 66 |
61 } // namespace | 67 } // namespace |
62 | 68 |
63 RootWindowController::RootWindowController( | 69 RootWindowController::RootWindowController( |
64 WindowManager* window_manager, | 70 WindowManager* window_manager, |
65 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, | 71 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
66 const display::Display& display) | 72 const display::Display& display, |
| 73 ash::RootWindowController::RootWindowType root_window_type) |
67 : window_manager_(window_manager), | 74 : window_manager_(window_manager), |
68 window_tree_host_(std::move(window_tree_host)), | 75 window_tree_host_(window_tree_host.get()), |
69 window_count_(0), | 76 window_count_(0), |
70 display_(display), | 77 display_(display) { |
71 wm_shelf_(base::MakeUnique<WmShelf>()) { | 78 ash::InitRootWindowSettings(window_tree_host->window()); |
72 wm_root_window_controller_ = base::MakeUnique<WmRootWindowControllerMus>( | 79 window_tree_host->window()->SetProperty(kRootWindowControllerKey, this); |
73 window_manager_->shell(), this); | 80 WmShellMus::Get()->AddRootWindowController(this); |
74 wm_root_window_controller_->CreateContainers(); | 81 ash_root_window_controller_ = base::WrapUnique( |
75 wm_root_window_controller_->CreateLayoutManagers(); | 82 new ash::RootWindowController(nullptr, window_tree_host.release())); |
76 | 83 ash_root_window_controller_->Init(root_window_type); |
77 parenting_client_ = base::MakeUnique<StackingController>(); | |
78 aura::client::SetWindowParentingClient(root(), parenting_client_.get()); | |
79 | 84 |
80 disconnected_app_handler_.reset(new DisconnectedAppHandler(root())); | 85 disconnected_app_handler_.reset(new DisconnectedAppHandler(root())); |
81 | 86 |
82 // Force a layout of the root, and its children, RootWindowLayout handles | |
83 // both. | |
84 wm_root_window_controller_->root_window_layout_manager()->OnWindowResized(); | |
85 | |
86 for (size_t i = 0; i < kNumActivatableShellWindowIds; ++i) { | 87 for (size_t i = 0; i < kNumActivatableShellWindowIds; ++i) { |
87 window_manager_->window_manager_client()->AddActivationParent( | 88 window_manager_->window_manager_client()->AddActivationParent( |
88 GetWindowByShellWindowId(kActivatableShellWindowIds[i])->aura_window()); | 89 GetWindowByShellWindowId(kActivatableShellWindowIds[i])->aura_window()); |
89 } | 90 } |
90 } | 91 } |
91 | 92 |
92 RootWindowController::~RootWindowController() { | 93 RootWindowController::~RootWindowController() { |
93 Shutdown(); | 94 Shutdown(); |
94 // Destroy WindowTreeHost last as it owns the root Window. | 95 ash_root_window_controller_.reset(); |
95 wm_shelf_.reset(); | 96 WmShellMus::Get()->RemoveRootWindowController(this); |
96 wm_root_window_controller_.reset(); | 97 } |
97 window_tree_host_.reset(); | 98 |
| 99 // static |
| 100 RootWindowController* RootWindowController::ForWindow(aura::Window* window) { |
| 101 return window->GetRootWindow()->GetProperty(kRootWindowControllerKey); |
98 } | 102 } |
99 | 103 |
100 void RootWindowController::Shutdown() { | 104 void RootWindowController::Shutdown() { |
101 // NOTE: Shutdown() may be called multiple times. | 105 // NOTE: Shutdown() may be called multiple times. |
102 wm_root_window_controller_->ResetRootForNewWindowsIfNecessary(); | 106 ash_root_window_controller_->Shutdown(); |
103 wm_root_window_controller_->CloseChildWindows(); | |
104 } | 107 } |
105 | 108 |
106 service_manager::Connector* RootWindowController::GetConnector() { | 109 service_manager::Connector* RootWindowController::GetConnector() { |
107 return window_manager_->connector(); | 110 return window_manager_->connector(); |
108 } | 111 } |
109 | 112 |
110 aura::Window* RootWindowController::root() { | 113 aura::Window* RootWindowController::root() { |
111 return window_tree_host_->window(); | 114 return window_tree_host_->window(); |
112 } | 115 } |
113 | 116 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 window, property_pair.first, &property_pair.second); | 156 window, property_pair.first, &property_pair.second); |
154 } | 157 } |
155 window->Init(ui::LAYER_TEXTURED); | 158 window->Init(ui::LAYER_TEXTURED); |
156 window->SetBounds(bounds); | 159 window->SetBounds(bounds); |
157 | 160 |
158 if (container_window) { | 161 if (container_window) { |
159 container_window->AddChild(window); | 162 container_window->AddChild(window); |
160 } else { | 163 } else { |
161 WmWindowMus* root = WmWindowMus::Get(this->root()); | 164 WmWindowMus* root = WmWindowMus::Get(this->root()); |
162 gfx::Point origin = | 165 gfx::Point origin = |
163 wm_root_window_controller_->ConvertPointToScreen(root, gfx::Point()); | 166 root->ConvertPointToTarget(root->GetRootWindow(), gfx::Point()); |
| 167 origin += display_.bounds().OffsetFromOrigin(); |
164 gfx::Rect bounds_in_screen(origin, bounds.size()); | 168 gfx::Rect bounds_in_screen(origin, bounds.size()); |
165 static_cast<WmWindowMus*>( | 169 static_cast<WmWindowMus*>( |
166 ash::wm::GetDefaultParent(WmWindowMus::Get(context), | 170 ash::wm::GetDefaultParent(WmWindowMus::Get(context), |
167 WmWindowMus::Get(window), bounds_in_screen)) | 171 WmWindowMus::Get(window), bounds_in_screen)) |
168 ->aura_window() | 172 ->aura_window() |
169 ->AddChild(window); | 173 ->AddChild(window); |
170 } | 174 } |
171 return window; | 175 return window; |
172 } | 176 } |
173 | 177 |
174 WmWindowMus* RootWindowController::GetWindowByShellWindowId(int id) { | 178 WmWindowMus* RootWindowController::GetWindowByShellWindowId(int id) { |
175 return WmWindowMus::AsWmWindowMus( | 179 return WmWindowMus::AsWmWindowMus( |
176 WmWindowMus::Get(root())->GetChildByShellWindowId(id)); | 180 WmWindowMus::Get(root())->GetChildByShellWindowId(id)); |
177 } | 181 } |
178 | 182 |
179 void RootWindowController::SetWorkAreaInests(const gfx::Insets& insets) { | 183 void RootWindowController::SetWorkAreaInests(const gfx::Insets& insets) { |
180 gfx::Rect old_work_area = display_.work_area(); | 184 gfx::Rect old_work_area = display_.work_area(); |
181 display_.UpdateWorkAreaFromInsets(insets); | 185 display_.UpdateWorkAreaFromInsets(insets); |
182 | 186 |
183 if (old_work_area == display_.work_area()) | 187 if (old_work_area == display_.work_area()) |
184 return; | 188 return; |
185 | 189 |
186 window_manager_->screen()->display_list().UpdateDisplay(display_); | 190 window_manager_->screen()->display_list().UpdateDisplay(display_); |
187 | 191 |
188 // Push new display insets to service:ui if we have a connection. | 192 // Push new display insets to service:ui if we have a connection. |
189 auto* display_controller = window_manager_->GetDisplayController(); | 193 auto* display_controller = window_manager_->GetDisplayController(); |
190 if (display_controller) | 194 if (display_controller) { |
191 display_controller->SetDisplayWorkArea(display_.id(), | 195 display_controller->SetDisplayWorkArea(display_.id(), |
192 display_.bounds().size(), insets); | 196 display_.bounds().size(), insets); |
| 197 } |
193 } | 198 } |
194 | 199 |
195 void RootWindowController::SetDisplay(const display::Display& display) { | 200 void RootWindowController::SetDisplay(const display::Display& display) { |
196 DCHECK_EQ(display.id(), display_.id()); | 201 DCHECK_EQ(display.id(), display_.id()); |
197 display_ = display; | 202 display_ = display; |
198 window_manager_->screen()->display_list().UpdateDisplay(display_); | 203 window_manager_->screen()->display_list().UpdateDisplay(display_); |
199 } | 204 } |
200 | 205 |
201 gfx::Rect RootWindowController::CalculateDefaultBounds( | 206 gfx::Rect RootWindowController::CalculateDefaultBounds( |
202 aura::Window* container_window, | 207 aura::Window* container_window, |
(...skipping 27 matching lines...) Expand all Loading... |
230 } else { | 235 } else { |
231 width = root()->bounds().width() - 240; | 236 width = root()->bounds().width() - 240; |
232 height = root()->bounds().height() - 240; | 237 height = root()->bounds().height() - 240; |
233 } | 238 } |
234 return gfx::Rect(40 + (window_count_ % 4) * 40, 40 + (window_count_ % 4) * 40, | 239 return gfx::Rect(40 + (window_count_ % 4) * 40, 40 + (window_count_ % 4) * 40, |
235 width, height); | 240 width, height); |
236 } | 241 } |
237 | 242 |
238 } // namespace mus | 243 } // namespace mus |
239 } // namespace ash | 244 } // namespace ash |
OLD | NEW |