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

Side by Side Diff: mash/wm/window_manager.cc

Issue 1994763002: Wires up WorkspaceLayoutManager in mash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: data deps Created 4 years, 7 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 | « mash/wm/window_manager.h ('k') | mash/wm/window_manager_application.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 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 "mash/wm/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/wm/common/container_finder.h"
11 #include "components/mus/common/types.h" 12 #include "components/mus/common/types.h"
13 #include "components/mus/public/cpp/property_type_converters.h"
12 #include "components/mus/public/cpp/window.h" 14 #include "components/mus/public/cpp/window.h"
13 #include "components/mus/public/cpp/window_property.h" 15 #include "components/mus/public/cpp/window_property.h"
14 #include "components/mus/public/cpp/window_tree_connection.h" 16 #include "components/mus/public/cpp/window_tree_connection.h"
15 #include "components/mus/public/interfaces/input_events.mojom.h" 17 #include "components/mus/public/interfaces/input_events.mojom.h"
16 #include "components/mus/public/interfaces/mus_constants.mojom.h" 18 #include "components/mus/public/interfaces/mus_constants.mojom.h"
17 #include "components/mus/public/interfaces/window_manager.mojom.h" 19 #include "components/mus/public/interfaces/window_manager.mojom.h"
20 #include "mash/wm/bridge/wm_window_mus.h"
18 #include "mash/wm/non_client_frame_controller.h" 21 #include "mash/wm/non_client_frame_controller.h"
19 #include "mash/wm/property_util.h" 22 #include "mash/wm/property_util.h"
20 #include "mash/wm/public/interfaces/container.mojom.h" 23 #include "mash/wm/public/interfaces/container.mojom.h"
21 #include "mash/wm/root_window_controller.h" 24 #include "mash/wm/root_window_controller.h"
22 #include "mojo/converters/geometry/geometry_type_converters.h" 25 #include "mojo/converters/geometry/geometry_type_converters.h"
23 26
24 namespace mash { 27 namespace mash {
25 namespace wm { 28 namespace wm {
26 29
27 WindowManager::WindowManager() 30 WindowManager::WindowManager()
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 mojo::Insets::From(client_area_insets); 71 mojo::Insets::From(client_area_insets);
69 frame_decoration_values->max_title_bar_button_width = 72 frame_decoration_values->max_title_bar_button_width =
70 NonClientFrameController::GetMaxTitleBarButtonWidth(); 73 NonClientFrameController::GetMaxTitleBarButtonWidth();
71 window_manager_client_->SetFrameDecorationValues( 74 window_manager_client_->SetFrameDecorationValues(
72 std::move(frame_decoration_values)); 75 std::move(frame_decoration_values));
73 76
74 if (session) 77 if (session)
75 session->AddScreenlockStateListener(binding_.CreateInterfacePtrAndBind()); 78 session->AddScreenlockStateListener(binding_.CreateInterfacePtrAndBind());
76 } 79 }
77 80
78 gfx::Rect WindowManager::CalculateDefaultBounds(mus::Window* window) const {
79 DCHECK(root_controller_);
80 int width, height;
81 const gfx::Size pref = GetWindowPreferredSize(window);
82 const mus::Window* root = root_controller_->root();
83 if (pref.IsEmpty()) {
84 width = root->bounds().width() - 240;
85 height = root->bounds().height() - 240;
86 } else {
87 // TODO(sky): likely want to constrain more than root size.
88 const gfx::Size max_size = GetMaximizedWindowBounds().size();
89 width = std::max(0, std::min(max_size.width(), pref.width()));
90 height = std::max(0, std::min(max_size.height(), pref.height()));
91 }
92 return gfx::Rect(40 + (root_controller_->window_count() % 4) * 40,
93 40 + (root_controller_->window_count() % 4) * 40, width,
94 height);
95 }
96
97 gfx::Rect WindowManager::GetMaximizedWindowBounds() const {
98 DCHECK(root_controller_);
99 return gfx::Rect(root_controller_->root()->bounds().size());
100 }
101
102 mus::Window* WindowManager::NewTopLevelWindow( 81 mus::Window* WindowManager::NewTopLevelWindow(
103 std::map<std::string, std::vector<uint8_t>>* properties) { 82 std::map<std::string, std::vector<uint8_t>>* properties) {
104 DCHECK(root_controller_); 83 DCHECK(root_controller_);
105 mus::Window* root = root_controller_->root(); 84 mus::Window* root = root_controller_->root();
106 DCHECK(root); 85 DCHECK(root);
107 86
108 const bool provide_non_client_frame = 87 const bool provide_non_client_frame =
109 GetWindowType(*properties) == mus::mojom::WindowType::WINDOW; 88 GetWindowType(*properties) == mus::mojom::WindowType::WINDOW;
110 if (provide_non_client_frame) 89 if (provide_non_client_frame)
111 (*properties)[mus::mojom::kWaitForUnderlay_Property].clear(); 90 (*properties)[mus::mojom::kWaitForUnderlay_Property].clear();
112 91
113 // TODO(sky): constrain and validate properties before passing to server. 92 // TODO(sky): constrain and validate properties before passing to server.
114 mus::Window* window = root->connection()->NewWindow(properties); 93 mus::Window* window = root->connection()->NewWindow(properties);
115 window->SetBounds(CalculateDefaultBounds(window)); 94 window->SetBounds(CalculateDefaultBounds(window));
116 95
117 mojom::Container container = GetRequestedContainer(window); 96 mus::Window* container_window = nullptr;
118 mus::Window* container_window = 97 if (window->HasSharedProperty(mojom::kWindowContainer_Property)) {
119 root_controller_->GetWindowForContainer(container); 98 container_window =
99 root_controller_->GetWindowForContainer(GetRequestedContainer(window));
100 } else {
101 // TODO(sky): window->bounds() isn't quite right.
102 container_window = WmWindowMus::GetMusWindow(
103 ash::wm::GetDefaultParent(WmWindowMus::Get(root_controller_->root()),
104 WmWindowMus::Get(window), window->bounds()));
105 }
120 DCHECK(root_controller_->WindowIsContainer(container_window)); 106 DCHECK(root_controller_->WindowIsContainer(container_window));
121 container_window->AddChild(window);
122 107
123 if (provide_non_client_frame) { 108 if (provide_non_client_frame) {
124 NonClientFrameController::Create(root_controller_->GetConnector(), window, 109 NonClientFrameController::Create(root_controller_->GetConnector(),
110 container_window, window,
125 root_controller_->window_manager_client()); 111 root_controller_->window_manager_client());
112 } else {
113 container_window->AddChild(window);
126 } 114 }
127 115
128 root_controller_->IncrementWindowCount(); 116 root_controller_->IncrementWindowCount();
129 117
130 return window; 118 return window;
131 } 119 }
132 120
121 gfx::Rect WindowManager::CalculateDefaultBounds(mus::Window* window) const {
122 if (window->HasSharedProperty(
123 mus::mojom::WindowManager::kInitialBounds_Property)) {
124 return window->GetSharedProperty<gfx::Rect>(
125 mus::mojom::WindowManager::kInitialBounds_Property);
126 }
127
128 DCHECK(root_controller_);
129 int width, height;
130 const gfx::Size pref = GetWindowPreferredSize(window);
131 const mus::Window* root = root_controller_->root();
132 if (pref.IsEmpty()) {
133 width = root->bounds().width() - 240;
134 height = root->bounds().height() - 240;
135 } else {
136 // TODO(sky): likely want to constrain more than root size.
137 const gfx::Size max_size = GetMaximizedWindowBounds().size();
138 width = std::max(0, std::min(max_size.width(), pref.width()));
139 height = std::max(0, std::min(max_size.height(), pref.height()));
140 }
141 return gfx::Rect(40 + (root_controller_->window_count() % 4) * 40,
142 40 + (root_controller_->window_count() % 4) * 40, width,
143 height);
144 }
145
146 gfx::Rect WindowManager::GetMaximizedWindowBounds() const {
147 DCHECK(root_controller_);
148 return gfx::Rect(root_controller_->root()->bounds().size());
149 }
150
133 void WindowManager::OnTreeChanging(const TreeChangeParams& params) { 151 void WindowManager::OnTreeChanging(const TreeChangeParams& params) {
134 DCHECK(root_controller_); 152 DCHECK(root_controller_);
135 if (params.old_parent == params.receiver && 153 if (params.old_parent == params.receiver &&
136 root_controller_->WindowIsContainer(params.old_parent)) 154 root_controller_->WindowIsContainer(params.old_parent))
137 disconnected_app_handler_.Remove(params.target); 155 disconnected_app_handler_.Remove(params.target);
138 156
139 if (params.new_parent == params.receiver && 157 if (params.new_parent == params.receiver &&
140 root_controller_->WindowIsContainer(params.new_parent)) 158 root_controller_->WindowIsContainer(params.new_parent))
141 disconnected_app_handler_.Add(params.target); 159 disconnected_app_handler_.Add(params.target);
142 160
143 mus::WindowTracker::OnTreeChanging(params); 161 mus::WindowTracker::OnTreeChanging(params);
144 } 162 }
145 163
146 void WindowManager::SetWindowManagerClient(mus::WindowManagerClient* client) { 164 void WindowManager::SetWindowManagerClient(mus::WindowManagerClient* client) {
147 window_manager_client_ = client; 165 window_manager_client_ = client;
148 } 166 }
149 167
150 bool WindowManager::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) { 168 bool WindowManager::OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) {
151 // By returning true the bounds of |window| is updated. 169 // TODO(sky): this indirectly sets bounds, which is against what
170 // OnWmSetBounds() recommends doing. Remove that restriction, or fix this.
171 WmWindowMus::Get(window)->SetBounds(*bounds);
172 *bounds = window->bounds();
152 return true; 173 return true;
153 } 174 }
154 175
155 bool WindowManager::OnWmSetProperty( 176 bool WindowManager::OnWmSetProperty(
156 mus::Window* window, 177 mus::Window* window,
157 const std::string& name, 178 const std::string& name,
158 std::unique_ptr<std::vector<uint8_t>>* new_data) { 179 std::unique_ptr<std::vector<uint8_t>>* new_data) {
159 // TODO(sky): constrain this to set of keys we know about, and allowed 180 // TODO(sky): constrain this to set of keys we know about, and allowed
160 // values. 181 // values.
161 return name == mus::mojom::WindowManager::kShowState_Property || 182 return name == mus::mojom::WindowManager::kShowState_Property ||
(...skipping 14 matching lines...) Expand all
176 197
177 void WindowManager::ScreenlockStateChanged(bool locked) { 198 void WindowManager::ScreenlockStateChanged(bool locked) {
178 // Hide USER_PRIVATE_CONTAINER windows when the screen is locked. 199 // Hide USER_PRIVATE_CONTAINER windows when the screen is locked.
179 mus::Window* window = root_controller_->GetWindowForContainer( 200 mus::Window* window = root_controller_->GetWindowForContainer(
180 mash::wm::mojom::Container::USER_PRIVATE); 201 mash::wm::mojom::Container::USER_PRIVATE);
181 window->SetVisible(!locked); 202 window->SetVisible(!locked);
182 } 203 }
183 204
184 } // namespace wm 205 } // namespace wm
185 } // namespace mash 206 } // namespace mash
OLDNEW
« no previous file with comments | « mash/wm/window_manager.h ('k') | mash/wm/window_manager_application.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698