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

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

Issue 2029883002: Moves mash/wm into ash/mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_static_assert
Patch Set: depend on test_wm 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/window_manager.h" 5 #include "ash/mus/window_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "ash/common/wm/container_finder.h" 11 #include "ash/common/wm/container_finder.h"
12 #include "ash/mus/bridge/wm_window_mus.h"
13 #include "ash/mus/non_client_frame_controller.h"
14 #include "ash/mus/property_util.h"
15 #include "ash/mus/root_window_controller.h"
12 #include "ash/public/interfaces/container.mojom.h" 16 #include "ash/public/interfaces/container.mojom.h"
13 #include "components/mus/common/types.h" 17 #include "components/mus/common/types.h"
14 #include "components/mus/public/cpp/property_type_converters.h" 18 #include "components/mus/public/cpp/property_type_converters.h"
15 #include "components/mus/public/cpp/window.h" 19 #include "components/mus/public/cpp/window.h"
16 #include "components/mus/public/cpp/window_property.h" 20 #include "components/mus/public/cpp/window_property.h"
17 #include "components/mus/public/cpp/window_tree_client.h" 21 #include "components/mus/public/cpp/window_tree_client.h"
18 #include "components/mus/public/interfaces/input_events.mojom.h" 22 #include "components/mus/public/interfaces/input_events.mojom.h"
19 #include "components/mus/public/interfaces/mus_constants.mojom.h" 23 #include "components/mus/public/interfaces/mus_constants.mojom.h"
20 #include "components/mus/public/interfaces/window_manager.mojom.h" 24 #include "components/mus/public/interfaces/window_manager.mojom.h"
21 #include "mash/wm/bridge/wm_window_mus.h"
22 #include "mash/wm/non_client_frame_controller.h"
23 #include "mash/wm/property_util.h"
24 #include "mash/wm/root_window_controller.h"
25 25
26 namespace mash { 26 namespace ash {
27 namespace wm { 27 namespace mus {
28 28
29 WindowManager::WindowManager() 29 WindowManager::WindowManager()
30 : root_controller_(nullptr), 30 : root_controller_(nullptr),
31 window_manager_client_(nullptr), 31 window_manager_client_(nullptr),
32 binding_(this) {} 32 binding_(this) {}
33 33
34 WindowManager::~WindowManager() { 34 WindowManager::~WindowManager() {}
35 }
36 35
37 void WindowManager::Initialize(RootWindowController* root_controller, 36 void WindowManager::Initialize(RootWindowController* root_controller,
38 session::mojom::Session* session) { 37 mash::session::mojom::Session* session) {
39 DCHECK(root_controller); 38 DCHECK(root_controller);
40 DCHECK(!root_controller_); 39 DCHECK(!root_controller_);
41 root_controller_ = root_controller; 40 root_controller_ = root_controller;
42 41
43 // Observe all the containers so that windows can be added to/removed from the 42 // Observe all the containers so that windows can be added to/removed from the
44 // |disconnected_app_handler_|. 43 // |disconnected_app_handler_|.
45 int count = static_cast<int>(ash::mojom::Container::COUNT); 44 int count = static_cast<int>(mojom::Container::COUNT);
46 for (int id = static_cast<int>(ash::mojom::Container::ROOT) + 1; id < count; 45 for (int id = static_cast<int>(mojom::Container::ROOT) + 1; id < count;
47 ++id) { 46 ++id) {
48 mus::Window* container = root_controller_->GetWindowForContainer( 47 ::mus::Window* container = root_controller_->GetWindowForContainer(
49 static_cast<ash::mojom::Container>(id)); 48 static_cast<mojom::Container>(id));
50 Add(container); 49 Add(container);
51 50
52 // Add any pre-existing windows in the container to 51 // Add any pre-existing windows in the container to
53 // |disconnected_app_handler_|. 52 // |disconnected_app_handler_|.
54 for (auto child : container->children()) { 53 for (auto child : container->children()) {
55 if (!root_controller_->WindowIsContainer(child)) 54 if (!root_controller_->WindowIsContainer(child))
56 disconnected_app_handler_.Add(child); 55 disconnected_app_handler_.Add(child);
57 } 56 }
58 } 57 }
59 58
60 // The insets are roughly what is needed by CustomFrameView. The expectation 59 // The insets are roughly what is needed by CustomFrameView. The expectation
61 // is at some point we'll write our own NonClientFrameView and get the insets 60 // is at some point we'll write our own NonClientFrameView and get the insets
62 // from it. 61 // from it.
63 mus::mojom::FrameDecorationValuesPtr frame_decoration_values = 62 ::mus::mojom::FrameDecorationValuesPtr frame_decoration_values =
64 mus::mojom::FrameDecorationValues::New(); 63 ::mus::mojom::FrameDecorationValues::New();
65 const gfx::Insets client_area_insets = 64 const gfx::Insets client_area_insets =
66 NonClientFrameController::GetPreferredClientAreaInsets(); 65 NonClientFrameController::GetPreferredClientAreaInsets();
67 frame_decoration_values->normal_client_area_insets = client_area_insets; 66 frame_decoration_values->normal_client_area_insets = client_area_insets;
68 frame_decoration_values->maximized_client_area_insets = client_area_insets; 67 frame_decoration_values->maximized_client_area_insets = client_area_insets;
69 frame_decoration_values->max_title_bar_button_width = 68 frame_decoration_values->max_title_bar_button_width =
70 NonClientFrameController::GetMaxTitleBarButtonWidth(); 69 NonClientFrameController::GetMaxTitleBarButtonWidth();
71 window_manager_client_->SetFrameDecorationValues( 70 window_manager_client_->SetFrameDecorationValues(
72 std::move(frame_decoration_values)); 71 std::move(frame_decoration_values));
73 72
74 if (session) 73 if (session)
75 session->AddScreenlockStateListener(binding_.CreateInterfacePtrAndBind()); 74 session->AddScreenlockStateListener(binding_.CreateInterfacePtrAndBind());
76 } 75 }
77 76
78 mus::Window* WindowManager::NewTopLevelWindow( 77 ::mus::Window* WindowManager::NewTopLevelWindow(
79 std::map<std::string, std::vector<uint8_t>>* properties) { 78 std::map<std::string, std::vector<uint8_t>>* properties) {
80 DCHECK(root_controller_); 79 DCHECK(root_controller_);
81 mus::Window* root = root_controller_->root(); 80 ::mus::Window* root = root_controller_->root();
82 DCHECK(root); 81 DCHECK(root);
83 82
84 // TODO(sky): panels need a different frame, http:://crbug.com/614362. 83 // TODO(sky): panels need a different frame, http:://crbug.com/614362.
85 const bool provide_non_client_frame = 84 const bool provide_non_client_frame =
86 GetWindowType(*properties) == mus::mojom::WindowType::WINDOW || 85 GetWindowType(*properties) == ::mus::mojom::WindowType::WINDOW ||
87 GetWindowType(*properties) == mus::mojom::WindowType::PANEL; 86 GetWindowType(*properties) == ::mus::mojom::WindowType::PANEL;
88 if (provide_non_client_frame) 87 if (provide_non_client_frame)
89 (*properties)[mus::mojom::kWaitForUnderlay_Property].clear(); 88 (*properties)[::mus::mojom::kWaitForUnderlay_Property].clear();
90 89
91 // TODO(sky): constrain and validate properties before passing to server. 90 // TODO(sky): constrain and validate properties before passing to server.
92 mus::Window* window = root->window_tree()->NewWindow(properties); 91 ::mus::Window* window = root->window_tree()->NewWindow(properties);
93 window->SetBounds(CalculateDefaultBounds(window)); 92 window->SetBounds(CalculateDefaultBounds(window));
94 93
95 mus::Window* container_window = nullptr; 94 ::mus::Window* container_window = nullptr;
96 if (window->HasSharedProperty(ash::mojom::kWindowContainer_Property)) { 95 if (window->HasSharedProperty(mojom::kWindowContainer_Property)) {
97 container_window = 96 container_window =
98 root_controller_->GetWindowForContainer(GetRequestedContainer(window)); 97 root_controller_->GetWindowForContainer(GetRequestedContainer(window));
99 } else { 98 } else {
100 // TODO(sky): window->bounds() isn't quite right. 99 // TODO(sky): window->bounds() isn't quite right.
101 container_window = WmWindowMus::GetMusWindow( 100 container_window = WmWindowMus::GetMusWindow(
102 ash::wm::GetDefaultParent(WmWindowMus::Get(root_controller_->root()), 101 wm::GetDefaultParent(WmWindowMus::Get(root_controller_->root()),
103 WmWindowMus::Get(window), window->bounds())); 102 WmWindowMus::Get(window), window->bounds()));
104 } 103 }
105 DCHECK(root_controller_->WindowIsContainer(container_window)); 104 DCHECK(root_controller_->WindowIsContainer(container_window));
106 105
107 if (provide_non_client_frame) { 106 if (provide_non_client_frame) {
108 NonClientFrameController::Create(root_controller_->GetConnector(), 107 NonClientFrameController::Create(root_controller_->GetConnector(),
109 container_window, window, 108 container_window, window,
110 root_controller_->window_manager_client()); 109 root_controller_->window_manager_client());
111 } else { 110 } else {
112 container_window->AddChild(window); 111 container_window->AddChild(window);
113 } 112 }
114 113
115 root_controller_->IncrementWindowCount(); 114 root_controller_->IncrementWindowCount();
116 115
117 return window; 116 return window;
118 } 117 }
119 118
120 gfx::Rect WindowManager::CalculateDefaultBounds(mus::Window* window) const { 119 gfx::Rect WindowManager::CalculateDefaultBounds(::mus::Window* window) const {
121 if (window->HasSharedProperty( 120 if (window->HasSharedProperty(
122 mus::mojom::WindowManager::kInitialBounds_Property)) { 121 ::mus::mojom::WindowManager::kInitialBounds_Property)) {
123 return window->GetSharedProperty<gfx::Rect>( 122 return window->GetSharedProperty<gfx::Rect>(
124 mus::mojom::WindowManager::kInitialBounds_Property); 123 ::mus::mojom::WindowManager::kInitialBounds_Property);
125 } 124 }
126 125
127 DCHECK(root_controller_); 126 DCHECK(root_controller_);
128 int width, height; 127 int width, height;
129 const gfx::Size pref = GetWindowPreferredSize(window); 128 const gfx::Size pref = GetWindowPreferredSize(window);
130 const mus::Window* root = root_controller_->root(); 129 const ::mus::Window* root = root_controller_->root();
131 if (pref.IsEmpty()) { 130 if (pref.IsEmpty()) {
132 width = root->bounds().width() - 240; 131 width = root->bounds().width() - 240;
133 height = root->bounds().height() - 240; 132 height = root->bounds().height() - 240;
134 } else { 133 } else {
135 // TODO(sky): likely want to constrain more than root size. 134 // TODO(sky): likely want to constrain more than root size.
136 const gfx::Size max_size = GetMaximizedWindowBounds().size(); 135 const gfx::Size max_size = GetMaximizedWindowBounds().size();
137 width = std::max(0, std::min(max_size.width(), pref.width())); 136 width = std::max(0, std::min(max_size.width(), pref.width()));
138 height = std::max(0, std::min(max_size.height(), pref.height())); 137 height = std::max(0, std::min(max_size.height(), pref.height()));
139 } 138 }
140 return gfx::Rect(40 + (root_controller_->window_count() % 4) * 40, 139 return gfx::Rect(40 + (root_controller_->window_count() % 4) * 40,
141 40 + (root_controller_->window_count() % 4) * 40, width, 140 40 + (root_controller_->window_count() % 4) * 40, width,
142 height); 141 height);
143 } 142 }
144 143
145 gfx::Rect WindowManager::GetMaximizedWindowBounds() const { 144 gfx::Rect WindowManager::GetMaximizedWindowBounds() const {
146 DCHECK(root_controller_); 145 DCHECK(root_controller_);
147 return gfx::Rect(root_controller_->root()->bounds().size()); 146 return gfx::Rect(root_controller_->root()->bounds().size());
148 } 147 }
149 148
150 void WindowManager::OnTreeChanging(const TreeChangeParams& params) { 149 void WindowManager::OnTreeChanging(const TreeChangeParams& params) {
151 DCHECK(root_controller_); 150 DCHECK(root_controller_);
152 if (params.old_parent == params.receiver && 151 if (params.old_parent == params.receiver &&
153 root_controller_->WindowIsContainer(params.old_parent)) 152 root_controller_->WindowIsContainer(params.old_parent))
154 disconnected_app_handler_.Remove(params.target); 153 disconnected_app_handler_.Remove(params.target);
155 154
156 if (params.new_parent == params.receiver && 155 if (params.new_parent == params.receiver &&
157 root_controller_->WindowIsContainer(params.new_parent)) 156 root_controller_->WindowIsContainer(params.new_parent))
158 disconnected_app_handler_.Add(params.target); 157 disconnected_app_handler_.Add(params.target);
159 158
160 mus::WindowTracker::OnTreeChanging(params); 159 ::mus::WindowTracker::OnTreeChanging(params);
161 } 160 }
162 161
163 void WindowManager::SetWindowManagerClient(mus::WindowManagerClient* client) { 162 void WindowManager::SetWindowManagerClient(::mus::WindowManagerClient* client) {
164 window_manager_client_ = client; 163 window_manager_client_ = client;
165 } 164 }
166 165
167 bool WindowManager::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) { 166 bool WindowManager::OnWmSetBounds(::mus::Window* window, gfx::Rect* bounds) {
168 // TODO(sky): this indirectly sets bounds, which is against what 167 // TODO(sky): this indirectly sets bounds, which is against what
169 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this. 168 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this.
170 WmWindowMus::Get(window)->SetBounds(*bounds); 169 WmWindowMus::Get(window)->SetBounds(*bounds);
171 *bounds = window->bounds(); 170 *bounds = window->bounds();
172 return true; 171 return true;
173 } 172 }
174 173
175 bool WindowManager::OnWmSetProperty( 174 bool WindowManager::OnWmSetProperty(
176 mus::Window* window, 175 ::mus::Window* window,
177 const std::string& name, 176 const std::string& name,
178 std::unique_ptr<std::vector<uint8_t>>* new_data) { 177 std::unique_ptr<std::vector<uint8_t>>* new_data) {
179 // TODO(sky): constrain this to set of keys we know about, and allowed 178 // TODO(sky): constrain this to set of keys we know about, and allowed
180 // values. 179 // values.
181 return name == mus::mojom::WindowManager::kShowState_Property || 180 return name == ::mus::mojom::WindowManager::kShowState_Property ||
182 name == mus::mojom::WindowManager::kPreferredSize_Property || 181 name == ::mus::mojom::WindowManager::kPreferredSize_Property ||
183 name == mus::mojom::WindowManager::kResizeBehavior_Property || 182 name == ::mus::mojom::WindowManager::kResizeBehavior_Property ||
184 name == mus::mojom::WindowManager::kWindowAppIcon_Property || 183 name == ::mus::mojom::WindowManager::kWindowAppIcon_Property ||
185 name == mus::mojom::WindowManager::kWindowTitle_Property; 184 name == ::mus::mojom::WindowManager::kWindowTitle_Property;
186 } 185 }
187 186
188 mus::Window* WindowManager::OnWmCreateTopLevelWindow( 187 ::mus::Window* WindowManager::OnWmCreateTopLevelWindow(
189 std::map<std::string, std::vector<uint8_t>>* properties) { 188 std::map<std::string, std::vector<uint8_t>>* properties) {
190 return NewTopLevelWindow(properties); 189 return NewTopLevelWindow(properties);
191 } 190 }
192 191
193 void WindowManager::OnWmClientJankinessChanged( 192 void WindowManager::OnWmClientJankinessChanged(
194 const std::set<mus::Window*>& client_windows, 193 const std::set<::mus::Window*>& client_windows,
195 bool janky) { 194 bool janky) {
196 for (auto window : client_windows) 195 for (auto window : client_windows)
197 SetWindowIsJanky(window, janky); 196 SetWindowIsJanky(window, janky);
198 } 197 }
199 198
200 void WindowManager::OnAccelerator(uint32_t id, const ui::Event& event) { 199 void WindowManager::OnAccelerator(uint32_t id, const ui::Event& event) {
201 root_controller_->OnAccelerator(id, std::move(event)); 200 root_controller_->OnAccelerator(id, std::move(event));
202 } 201 }
203 202
204 void WindowManager::ScreenlockStateChanged(bool locked) { 203 void WindowManager::ScreenlockStateChanged(bool locked) {
205 // Hide USER_PRIVATE_CONTAINER windows when the screen is locked. 204 // Hide USER_PRIVATE_CONTAINER windows when the screen is locked.
206 mus::Window* window = root_controller_->GetWindowForContainer( 205 ::mus::Window* window =
207 ash::mojom::Container::USER_PRIVATE); 206 root_controller_->GetWindowForContainer(mojom::Container::USER_PRIVATE);
208 window->SetVisible(!locked); 207 window->SetVisible(!locked);
209 } 208 }
210 209
211 } // namespace wm 210 } // namespace mus
212 } // namespace mash 211 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698