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

Side by Side Diff: ash/wm/window_state.cc

Issue 2901663003: chromeos: converts WindowState to aura::Window (Closed)
Patch Set: moar Created 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/wm/window_state.h" 5 #include "ash/wm/window_state.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/public/cpp/window_properties.h" 9 #include "ash/public/cpp/window_properties.h"
10 #include "ash/public/interfaces/window_pin_type.mojom.h" 10 #include "ash/public/interfaces/window_pin_type.mojom.h"
11 #include "ash/screen_util.h" 11 #include "ash/screen_util.h"
12 #include "ash/wm/default_state.h" 12 #include "ash/wm/default_state.h"
13 #include "ash/wm/window_animations.h"
13 #include "ash/wm/window_positioning_utils.h" 14 #include "ash/wm/window_positioning_utils.h"
14 #include "ash/wm/window_properties.h" 15 #include "ash/wm/window_properties.h"
15 #include "ash/wm/window_state_delegate.h" 16 #include "ash/wm/window_state_delegate.h"
16 #include "ash/wm/window_state_observer.h" 17 #include "ash/wm/window_state_observer.h"
17 #include "ash/wm/window_util.h" 18 #include "ash/wm/window_util.h"
18 #include "ash/wm/wm_event.h" 19 #include "ash/wm/wm_event.h"
19 #include "ash/wm_window.h"
20 #include "base/auto_reset.h" 20 #include "base/auto_reset.h"
21 #include "base/memory/ptr_util.h"
22 #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
23 #include "ui/aura/client/aura_constants.h"
24 #include "ui/aura/layout_manager.h"
21 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
26 #include "ui/aura/window_delegate.h"
27 #include "ui/compositor/layer_tree_owner.h"
28 #include "ui/compositor/scoped_layer_animation_settings.h"
29 #include "ui/display/display.h"
30 #include "ui/display/screen.h"
31 #include "ui/wm/core/coordinate_conversion.h"
32 #include "ui/wm/core/ime_util_chromeos.h"
33 #include "ui/wm/core/window_util.h"
22 34
23 namespace ash { 35 namespace ash {
24 namespace wm { 36 namespace wm {
37 namespace {
25 38
26 namespace { 39 // A tentative class to set the bounds on the window.
40 // TODO(oshima): Once all logic is cleaned up, move this to the real layout
41 // manager with proper friendship.
42 class BoundsSetter : public aura::LayoutManager {
43 public:
44 BoundsSetter() {}
45 ~BoundsSetter() override {}
46
47 // aura::LayoutManager overrides:
48 void OnWindowResized() override {}
49 void OnWindowAddedToLayout(aura::Window* child) override {}
50 void OnWillRemoveWindowFromLayout(aura::Window* child) override {}
51 void OnWindowRemovedFromLayout(aura::Window* child) override {}
52 void OnChildWindowVisibilityChanged(aura::Window* child,
53 bool visible) override {}
54 void SetChildBounds(aura::Window* child,
55 const gfx::Rect& requested_bounds) override {}
56
57 void SetBounds(aura::Window* window, const gfx::Rect& bounds) {
58 SetChildBoundsDirect(window, bounds);
59 }
60
61 private:
62 DISALLOW_COPY_AND_ASSIGN(BoundsSetter);
63 };
27 64
28 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) { 65 WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) {
29 switch (requested_show_state) { 66 switch (requested_show_state) {
30 case ui::SHOW_STATE_DEFAULT: 67 case ui::SHOW_STATE_DEFAULT:
31 case ui::SHOW_STATE_NORMAL: 68 case ui::SHOW_STATE_NORMAL:
32 return WM_EVENT_NORMAL; 69 return WM_EVENT_NORMAL;
33 case ui::SHOW_STATE_MINIMIZED: 70 case ui::SHOW_STATE_MINIMIZED:
34 return WM_EVENT_MINIMIZE; 71 return WM_EVENT_MINIMIZE;
35 case ui::SHOW_STATE_MAXIMIZED: 72 case ui::SHOW_STATE_MAXIMIZED:
36 return WM_EVENT_MAXIMIZE; 73 return WM_EVENT_MAXIMIZE;
(...skipping 17 matching lines...) Expand all
54 return WM_EVENT_PIN; 91 return WM_EVENT_PIN;
55 case ash::mojom::WindowPinType::TRUSTED_PINNED: 92 case ash::mojom::WindowPinType::TRUSTED_PINNED:
56 return WM_EVENT_TRUSTED_PIN; 93 return WM_EVENT_TRUSTED_PIN;
57 } 94 }
58 NOTREACHED() << "No WMEvent defined for the window pin type:" << type; 95 NOTREACHED() << "No WMEvent defined for the window pin type:" << type;
59 return WM_EVENT_NORMAL; 96 return WM_EVENT_NORMAL;
60 } 97 }
61 98
62 } // namespace 99 } // namespace
63 100
64 WindowState::~WindowState() {} 101 WindowState::~WindowState() {
102 // WindowState is registered as an owned property of |window_|, and window
sky 2017/05/23 00:13:27 This comment comes from before I created WmWindow.
msw 2017/05/23 05:46:55 Acknowledged.
103 // unregisters all of its observers in its d'tor before destroying its
104 // properties. As a result, window_->RemoveObserver() doesn't need to (and
105 // shouldn't) be called here.
106 }
65 107
66 bool WindowState::HasDelegate() const { 108 bool WindowState::HasDelegate() const {
67 return !!delegate_; 109 return !!delegate_;
68 } 110 }
69 111
70 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) { 112 void WindowState::SetDelegate(std::unique_ptr<WindowStateDelegate> delegate) {
71 DCHECK(!delegate_.get()); 113 DCHECK(!delegate_.get());
72 delegate_ = std::move(delegate); 114 delegate_ = std::move(delegate);
73 } 115 }
74 116
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 bool WindowState::IsNormalStateType() const { 152 bool WindowState::IsNormalStateType() const {
111 return GetStateType() == WINDOW_STATE_TYPE_NORMAL || 153 return GetStateType() == WINDOW_STATE_TYPE_NORMAL ||
112 GetStateType() == WINDOW_STATE_TYPE_DEFAULT; 154 GetStateType() == WINDOW_STATE_TYPE_DEFAULT;
113 } 155 }
114 156
115 bool WindowState::IsNormalOrSnapped() const { 157 bool WindowState::IsNormalOrSnapped() const {
116 return IsNormalStateType() || IsSnapped(); 158 return IsNormalStateType() || IsSnapped();
117 } 159 }
118 160
119 bool WindowState::IsActive() const { 161 bool WindowState::IsActive() const {
120 return window_->IsActive(); 162 return ::wm::IsActiveWindow(window_);
121 } 163 }
122 164
123 bool WindowState::IsUserPositionable() const { 165 bool WindowState::IsUserPositionable() const {
124 return (window_->GetType() == ui::wm::WINDOW_TYPE_NORMAL || 166 return (window_->type() == ui::wm::WINDOW_TYPE_NORMAL ||
125 window_->GetType() == ui::wm::WINDOW_TYPE_PANEL); 167 window_->type() == ui::wm::WINDOW_TYPE_PANEL);
126 } 168 }
127 169
128 bool WindowState::CanMaximize() const { 170 bool WindowState::CanMaximize() const {
129 // Window must allow maximization and have no maximum width or height. 171 // Window must allow maximization and have no maximum width or height.
130 if (!window_->CanMaximize()) 172 if ((window_->GetProperty(aura::client::kResizeBehaviorKey) &
173 ui::mojom::kResizeBehaviorCanMaximize) == 0) {
131 return false; 174 return false;
175 }
132 176
133 if (!window_->HasNonClientArea()) 177 if (!window_->delegate())
134 return true; 178 return true;
135 179
136 gfx::Size max_size = window_->GetMaximumSize(); 180 const gfx::Size max_size = window_->delegate()->GetMaximumSize();
137 return !max_size.width() && !max_size.height(); 181 return !max_size.width() && !max_size.height();
138 } 182 }
139 183
140 bool WindowState::CanMinimize() const { 184 bool WindowState::CanMinimize() const {
141 return window_->CanMinimize(); 185 return (window_->GetProperty(aura::client::kResizeBehaviorKey) &
186 ui::mojom::kResizeBehaviorCanMinimize) != 0;
142 } 187 }
143 188
144 bool WindowState::CanResize() const { 189 bool WindowState::CanResize() const {
145 return window_->CanResize(); 190 return (window_->GetProperty(aura::client::kResizeBehaviorKey) &
191 ui::mojom::kResizeBehaviorCanResize) != 0;
146 } 192 }
147 193
148 bool WindowState::CanActivate() const { 194 bool WindowState::CanActivate() const {
149 return window_->CanActivate(); 195 return ::wm::CanActivateWindow(window_);
150 } 196 }
151 197
152 bool WindowState::CanSnap() const { 198 bool WindowState::CanSnap() const {
153 if (!CanResize() || window_->GetType() == ui::wm::WINDOW_TYPE_PANEL || 199 if (!CanResize() || window_->type() == ui::wm::WINDOW_TYPE_PANEL ||
154 window_->GetTransientParent()) { 200 ::wm::GetTransientParent(window_)) {
155 return false; 201 return false;
156 } 202 }
157 // If a window cannot be maximized, assume it cannot snap either. 203 // If a window cannot be maximized, assume it cannot snap either.
158 // TODO(oshima): We should probably snap if the maximum size is greater than 204 // TODO(oshima): We should probably snap if the maximum size is greater than
159 // the snapped size. 205 // the snapped size.
160 return CanMaximize(); 206 return CanMaximize();
161 } 207 }
162 208
163 bool WindowState::HasRestoreBounds() const { 209 bool WindowState::HasRestoreBounds() const {
164 return window_->HasRestoreBounds(); 210 return window_->GetProperty(aura::client::kRestoreBoundsKey) != nullptr;
165 } 211 }
166 212
167 void WindowState::Maximize() { 213 void WindowState::Maximize() {
168 window_->Maximize(); 214 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
169 } 215 }
170 216
171 void WindowState::Minimize() { 217 void WindowState::Minimize() {
172 window_->Minimize(); 218 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
173 } 219 }
174 220
175 void WindowState::Unminimize() { 221 void WindowState::Unminimize() {
176 window_->Unminimize(); 222 window_->SetProperty(
223 aura::client::kShowStateKey,
224 window_->GetProperty(aura::client::kPreMinimizedShowStateKey));
225 window_->ClearProperty(aura::client::kPreMinimizedShowStateKey);
177 } 226 }
178 227
179 void WindowState::Activate() { 228 void WindowState::Activate() {
180 window_->Activate(); 229 wm::ActivateWindow(window_);
181 } 230 }
182 231
183 void WindowState::Deactivate() { 232 void WindowState::Deactivate() {
184 window_->Deactivate(); 233 wm::DeactivateWindow(window_);
185 } 234 }
186 235
187 void WindowState::Restore() { 236 void WindowState::Restore() {
188 if (!IsNormalStateType()) { 237 if (!IsNormalStateType()) {
189 const WMEvent event(WM_EVENT_NORMAL); 238 const WMEvent event(WM_EVENT_NORMAL);
190 OnWMEvent(&event); 239 OnWMEvent(&event);
191 } 240 }
192 } 241 }
193 242
194 void WindowState::DisableAlwaysOnTop(WmWindow* window_on_top) { 243 void WindowState::DisableAlwaysOnTop(aura::Window* window_on_top) {
195 if (GetAlwaysOnTop()) { 244 if (GetAlwaysOnTop()) {
196 // |window_| is hidden first to avoid canceling fullscreen mode when it is 245 // |window_| is hidden first to avoid canceling fullscreen mode when it is
197 // no longer always on top and gets added to default container. This avoids 246 // no longer always on top and gets added to default container. This avoids
198 // sending redundant OnFullscreenStateChanged to the layout manager. The 247 // sending redundant OnFullscreenStateChanged to the layout manager. The
199 // |window_| visibility is restored after it no longer obscures the 248 // |window_| visibility is restored after it no longer obscures the
200 // |window_on_top|. 249 // |window_on_top|.
201 bool visible = window_->IsVisible(); 250 bool visible = window_->IsVisible();
202 if (visible) 251 if (visible)
203 window_->Hide(); 252 window_->Hide();
204 window_->SetAlwaysOnTop(false); 253 window_->SetProperty(aura::client::kAlwaysOnTopKey, false);
205 // Technically it is possible that a |window_| could make itself 254 // Technically it is possible that a |window_| could make itself
206 // always_on_top really quickly. This is probably not a realistic case but 255 // always_on_top really quickly. This is probably not a realistic case but
207 // check if the two windows are in the same container just in case. 256 // check if the two windows are in the same container just in case.
208 if (window_on_top && window_on_top->GetParent() == window_->GetParent()) 257 if (window_on_top && window_on_top->parent() == window_->parent())
209 window_->GetParent()->StackChildAbove(window_on_top, window_); 258 window_->parent()->StackChildAbove(window_on_top, window_);
210 if (visible) 259 if (visible)
211 window_->Show(); 260 window_->Show();
212 cached_always_on_top_ = true; 261 cached_always_on_top_ = true;
213 } 262 }
214 } 263 }
215 264
216 void WindowState::RestoreAlwaysOnTop() { 265 void WindowState::RestoreAlwaysOnTop() {
217 if (delegate() && delegate()->RestoreAlwaysOnTop(this)) 266 if (delegate() && delegate()->RestoreAlwaysOnTop(this))
218 return; 267 return;
219 if (cached_always_on_top_) { 268 if (cached_always_on_top_) {
220 cached_always_on_top_ = false; 269 cached_always_on_top_ = false;
221 window_->SetAlwaysOnTop(true); 270 window_->SetProperty(aura::client::kAlwaysOnTopKey, true);
222 } 271 }
223 } 272 }
224 273
225 void WindowState::OnWMEvent(const WMEvent* event) { 274 void WindowState::OnWMEvent(const WMEvent* event) {
226 current_state_->OnWMEvent(this, event); 275 current_state_->OnWMEvent(this, event);
227 } 276 }
228 277
229 void WindowState::SaveCurrentBoundsForRestore() { 278 void WindowState::SaveCurrentBoundsForRestore() {
230 gfx::Rect bounds_in_screen = 279 gfx::Rect bounds_in_screen = window_->bounds();
231 window_->GetParent()->ConvertRectToScreen(window_->GetBounds()); 280 ::wm::ConvertRectToScreen(window_->parent(), &bounds_in_screen);
232 SetRestoreBoundsInScreen(bounds_in_screen); 281 SetRestoreBoundsInScreen(bounds_in_screen);
233 } 282 }
234 283
235 gfx::Rect WindowState::GetRestoreBoundsInScreen() const { 284 gfx::Rect WindowState::GetRestoreBoundsInScreen() const {
236 return window_->GetRestoreBoundsInScreen(); 285 gfx::Rect* restore_bounds =
286 window_->GetProperty(aura::client::kRestoreBoundsKey);
287 return restore_bounds ? *restore_bounds : gfx::Rect();
237 } 288 }
238 289
239 gfx::Rect WindowState::GetRestoreBoundsInParent() const { 290 gfx::Rect WindowState::GetRestoreBoundsInParent() const {
240 return window_->GetParent()->ConvertRectFromScreen( 291 gfx::Rect result = GetRestoreBoundsInScreen();
241 GetRestoreBoundsInScreen()); 292 ::wm::ConvertRectFromScreen(window_->parent(), &result);
293 return result;
242 } 294 }
243 295
244 void WindowState::SetRestoreBoundsInScreen(const gfx::Rect& bounds) { 296 void WindowState::SetRestoreBoundsInScreen(const gfx::Rect& bounds) {
245 window_->SetRestoreBoundsInScreen(bounds); 297 window_->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds));
246 } 298 }
247 299
248 void WindowState::SetRestoreBoundsInParent(const gfx::Rect& bounds) { 300 void WindowState::SetRestoreBoundsInParent(const gfx::Rect& bounds) {
249 SetRestoreBoundsInScreen(window_->GetParent()->ConvertRectToScreen(bounds)); 301 gfx::Rect bounds_in_screen = bounds;
302 ::wm::ConvertRectToScreen(window_->parent(), &bounds_in_screen);
303 SetRestoreBoundsInScreen(bounds_in_screen);
250 } 304 }
251 305
252 void WindowState::ClearRestoreBounds() { 306 void WindowState::ClearRestoreBounds() {
253 window_->ClearRestoreBounds(); 307 window_->ClearProperty(aura::client::kRestoreBoundsKey);
308 window_->ClearProperty(::wm::kVirtualKeyboardRestoreBoundsKey);
254 } 309 }
255 310
256 std::unique_ptr<WindowState::State> WindowState::SetStateObject( 311 std::unique_ptr<WindowState::State> WindowState::SetStateObject(
257 std::unique_ptr<WindowState::State> new_state) { 312 std::unique_ptr<WindowState::State> new_state) {
258 current_state_->DetachState(this); 313 current_state_->DetachState(this);
259 std::unique_ptr<WindowState::State> old_object = std::move(current_state_); 314 std::unique_ptr<WindowState::State> old_object = std::move(current_state_);
260 current_state_ = std::move(new_state); 315 current_state_ = std::move(new_state);
261 current_state_->AttachState(this, old_object.get()); 316 current_state_->AttachState(this, old_object.get());
262 return old_object; 317 return old_object;
263 } 318 }
(...skipping 12 matching lines...) Expand all
276 331
277 void WindowState::set_bounds_changed_by_user(bool bounds_changed_by_user) { 332 void WindowState::set_bounds_changed_by_user(bool bounds_changed_by_user) {
278 bounds_changed_by_user_ = bounds_changed_by_user; 333 bounds_changed_by_user_ = bounds_changed_by_user;
279 if (bounds_changed_by_user) 334 if (bounds_changed_by_user)
280 pre_auto_manage_window_bounds_.reset(); 335 pre_auto_manage_window_bounds_.reset();
281 } 336 }
282 337
283 void WindowState::CreateDragDetails(const gfx::Point& point_in_parent, 338 void WindowState::CreateDragDetails(const gfx::Point& point_in_parent,
284 int window_component, 339 int window_component,
285 aura::client::WindowMoveSource source) { 340 aura::client::WindowMoveSource source) {
286 drag_details_.reset( 341 drag_details_ = base::MakeUnique<DragDetails>(window_, point_in_parent,
287 new DragDetails(window_, point_in_parent, window_component, source)); 342 window_component, source);
288 } 343 }
289 344
290 void WindowState::DeleteDragDetails() { 345 void WindowState::DeleteDragDetails() {
291 drag_details_.reset(); 346 drag_details_.reset();
292 } 347 }
293 348
294 void WindowState::SetAndClearRestoreBounds() { 349 void WindowState::SetAndClearRestoreBounds() {
295 DCHECK(HasRestoreBounds()); 350 DCHECK(HasRestoreBounds());
296 SetBoundsInScreen(GetRestoreBoundsInScreen()); 351 SetBoundsInScreen(GetRestoreBoundsInScreen());
297 ClearRestoreBounds(); 352 ClearRestoreBounds();
298 } 353 }
299 354
300 void WindowState::OnWindowShowStateChanged() { 355 WindowState::WindowState(aura::Window* window)
301 if (!ignore_property_change_) {
302 WMEvent event(WMEventTypeFromShowState(GetShowState()));
303 OnWMEvent(&event);
304 }
305 }
306
307 void WindowState::OnWindowPinTypeChanged() {
308 if (!ignore_property_change_) {
309 WMEvent event(WMEventTypeFromWindowPinType(GetPinType()));
310 OnWMEvent(&event);
311 }
312 }
313
314 WindowState::WindowState(WmWindow* window)
315 : window_(window), 356 : window_(window),
316 window_position_managed_(false), 357 window_position_managed_(false),
317 bounds_changed_by_user_(false), 358 bounds_changed_by_user_(false),
318 ignored_by_shelf_(false), 359 ignored_by_shelf_(false),
319 can_consume_system_keys_(false), 360 can_consume_system_keys_(false),
320 unminimize_to_restore_bounds_(false), 361 unminimize_to_restore_bounds_(false),
321 in_immersive_fullscreen_(false), 362 in_immersive_fullscreen_(false),
322 hide_shelf_when_fullscreen_(true), 363 hide_shelf_when_fullscreen_(true),
323 autohide_shelf_when_maximized_or_fullscreen_(false), 364 autohide_shelf_when_maximized_or_fullscreen_(false),
324 minimum_visibility_(false), 365 minimum_visibility_(false),
325 can_be_dragged_(true), 366 can_be_dragged_(true),
326 cached_always_on_top_(false), 367 cached_always_on_top_(false),
327 ignore_property_change_(false), 368 ignore_property_change_(false),
328 current_state_(new DefaultState(ToWindowStateType(GetShowState()))) {} 369 current_state_(new DefaultState(ToWindowStateType(GetShowState()))) {
370 window_->AddObserver(this);
371 }
329 372
330 bool WindowState::GetAlwaysOnTop() const { 373 bool WindowState::GetAlwaysOnTop() const {
331 return window_->IsAlwaysOnTop(); 374 return window_->GetProperty(aura::client::kAlwaysOnTopKey);
332 } 375 }
333 376
334 ui::WindowShowState WindowState::GetShowState() const { 377 ui::WindowShowState WindowState::GetShowState() const {
335 return window_->GetShowState(); 378 return window_->GetProperty(aura::client::kShowStateKey);
336 } 379 }
337 380
338 ash::mojom::WindowPinType WindowState::GetPinType() const { 381 ash::mojom::WindowPinType WindowState::GetPinType() const {
339 return window_->aura_window()->GetProperty(kWindowPinTypeKey); 382 return window_->GetProperty(kWindowPinTypeKey);
340 } 383 }
341 384
342 void WindowState::SetBoundsInScreen(const gfx::Rect& bounds_in_screen) { 385 void WindowState::SetBoundsInScreen(const gfx::Rect& bounds_in_screen) {
343 gfx::Rect bounds_in_parent = 386 gfx::Rect bounds_in_parent = bounds_in_screen;
344 window_->GetParent()->ConvertRectFromScreen(bounds_in_screen); 387 ::wm::ConvertRectFromScreen(window_->parent(), &bounds_in_parent);
345 window_->SetBounds(bounds_in_parent); 388 window_->SetBounds(bounds_in_parent);
346 } 389 }
347 390
348 void WindowState::AdjustSnappedBounds(gfx::Rect* bounds) { 391 void WindowState::AdjustSnappedBounds(gfx::Rect* bounds) {
349 if (is_dragged() || !IsSnapped()) 392 if (is_dragged() || !IsSnapped())
350 return; 393 return;
351 gfx::Rect maximized_bounds = 394 gfx::Rect maximized_bounds =
352 ScreenUtil::GetMaximizedWindowBoundsInParent(window_->aura_window()); 395 ScreenUtil::GetMaximizedWindowBoundsInParent(window_);
353 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED) 396 if (GetStateType() == WINDOW_STATE_TYPE_LEFT_SNAPPED)
354 bounds->set_x(maximized_bounds.x()); 397 bounds->set_x(maximized_bounds.x());
355 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED) 398 else if (GetStateType() == WINDOW_STATE_TYPE_RIGHT_SNAPPED)
356 bounds->set_x(maximized_bounds.right() - bounds->width()); 399 bounds->set_x(maximized_bounds.right() - bounds->width());
357 bounds->set_y(maximized_bounds.y()); 400 bounds->set_y(maximized_bounds.y());
358 bounds->set_height(maximized_bounds.height()); 401 bounds->set_height(maximized_bounds.height());
359 } 402 }
360 403
361 void WindowState::UpdateWindowPropertiesFromStateType() { 404 void WindowState::UpdateWindowPropertiesFromStateType() {
362 ui::WindowShowState new_window_state = 405 ui::WindowShowState new_window_state =
363 ToWindowShowState(current_state_->GetType()); 406 ToWindowShowState(current_state_->GetType());
364 if (new_window_state != GetShowState()) { 407 if (new_window_state != GetShowState()) {
365 base::AutoReset<bool> resetter(&ignore_property_change_, true); 408 base::AutoReset<bool> resetter(&ignore_property_change_, true);
366 window_->SetShowState(new_window_state); 409 window_->SetProperty(aura::client::kShowStateKey, new_window_state);
367 } 410 }
368 411
369 // sync up current window show state with PinType property. 412 // sync up current window show state with PinType property.
370 ash::mojom::WindowPinType pin_type = ash::mojom::WindowPinType::NONE; 413 ash::mojom::WindowPinType pin_type = ash::mojom::WindowPinType::NONE;
371 if (GetStateType() == WINDOW_STATE_TYPE_PINNED) 414 if (GetStateType() == WINDOW_STATE_TYPE_PINNED)
372 pin_type = ash::mojom::WindowPinType::PINNED; 415 pin_type = ash::mojom::WindowPinType::PINNED;
373 else if (GetStateType() == WINDOW_STATE_TYPE_TRUSTED_PINNED) 416 else if (GetStateType() == WINDOW_STATE_TYPE_TRUSTED_PINNED)
374 pin_type = ash::mojom::WindowPinType::TRUSTED_PINNED; 417 pin_type = ash::mojom::WindowPinType::TRUSTED_PINNED;
375 if (pin_type != GetPinType()) { 418 if (pin_type != GetPinType()) {
376 base::AutoReset<bool> resetter(&ignore_property_change_, true); 419 base::AutoReset<bool> resetter(&ignore_property_change_, true);
377 window_->aura_window()->SetProperty(kWindowPinTypeKey, pin_type); 420 window_->SetProperty(kWindowPinTypeKey, pin_type);
378 } 421 }
379 } 422 }
380 423
381 void WindowState::NotifyPreStateTypeChange( 424 void WindowState::NotifyPreStateTypeChange(
382 WindowStateType old_window_state_type) { 425 WindowStateType old_window_state_type) {
383 for (auto& observer : observer_list_) 426 for (auto& observer : observer_list_)
384 observer.OnPreWindowStateTypeChange(this, old_window_state_type); 427 observer.OnPreWindowStateTypeChange(this, old_window_state_type);
385 } 428 }
386 429
387 void WindowState::NotifyPostStateTypeChange( 430 void WindowState::NotifyPostStateTypeChange(
388 WindowStateType old_window_state_type) { 431 WindowStateType old_window_state_type) {
389 for (auto& observer : observer_list_) 432 for (auto& observer : observer_list_)
390 observer.OnPostWindowStateTypeChange(this, old_window_state_type); 433 observer.OnPostWindowStateTypeChange(this, old_window_state_type);
391 } 434 }
392 435
393 void WindowState::SetBoundsDirect(const gfx::Rect& bounds) { 436 void WindowState::SetBoundsDirect(const gfx::Rect& bounds) {
394 gfx::Rect actual_new_bounds(bounds); 437 gfx::Rect actual_new_bounds(bounds);
395 // Ensure we don't go smaller than our minimum bounds in "normal" window 438 // Ensure we don't go smaller than our minimum bounds in "normal" window
396 // modes 439 // modes
397 if (window_->HasNonClientArea() && !IsMaximized() && !IsFullscreen()) { 440 if (window_->delegate() && !IsMaximized() && !IsFullscreen()) {
398 // Get the minimum usable size of the minimum size and the screen size. 441 // Get the minimum usable size of the minimum size and the screen size.
399 gfx::Size min_size = window_->GetMinimumSize(); 442 gfx::Size min_size = window_->delegate()
400 min_size.SetToMin(window_->GetDisplayNearestWindow().work_area().size()); 443 ? window_->delegate()->GetMinimumSize()
444 : gfx::Size();
445 const display::Display display =
446 display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
447 min_size.SetToMin(display.work_area().size());
401 448
402 actual_new_bounds.set_width( 449 actual_new_bounds.set_width(
403 std::max(min_size.width(), actual_new_bounds.width())); 450 std::max(min_size.width(), actual_new_bounds.width()));
404 actual_new_bounds.set_height( 451 actual_new_bounds.set_height(
405 std::max(min_size.height(), actual_new_bounds.height())); 452 std::max(min_size.height(), actual_new_bounds.height()));
406 } 453 }
407 window_->SetBoundsDirect(actual_new_bounds); 454 BoundsSetter().SetBounds(window_, actual_new_bounds);
455 wm::SnapWindowToPixelBoundary(window_);
408 } 456 }
409 457
410 void WindowState::SetBoundsConstrained(const gfx::Rect& bounds) { 458 void WindowState::SetBoundsConstrained(const gfx::Rect& bounds) {
411 gfx::Rect work_area_in_parent = 459 gfx::Rect work_area_in_parent =
412 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_->aura_window()); 460 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_);
413 gfx::Rect child_bounds(bounds); 461 gfx::Rect child_bounds(bounds);
414 AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); 462 AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds);
415 SetBoundsDirect(child_bounds); 463 SetBoundsDirect(child_bounds);
416 } 464 }
417 465
418 void WindowState::SetBoundsDirectAnimated(const gfx::Rect& bounds) { 466 void WindowState::SetBoundsDirectAnimated(const gfx::Rect& bounds) {
419 window_->SetBoundsDirectAnimated(bounds); 467 const int kBoundsChangeSlideDurationMs = 120;
468
469 ui::Layer* layer = window_->layer();
470 ui::ScopedLayerAnimationSettings slide_settings(layer->GetAnimator());
471 slide_settings.SetPreemptionStrategy(
472 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
473 slide_settings.SetTransitionDuration(
474 base::TimeDelta::FromMilliseconds(kBoundsChangeSlideDurationMs));
475 SetBoundsDirect(bounds);
420 } 476 }
421 477
422 void WindowState::SetBoundsDirectCrossFade(const gfx::Rect& new_bounds) { 478 void WindowState::SetBoundsDirectCrossFade(const gfx::Rect& new_bounds) {
423 // Some test results in invoking CrossFadeToBounds when window is not visible. 479 // Some test results in invoking CrossFadeToBounds when window is not visible.
424 // No animation is necessary in that case, thus just change the bounds and 480 // No animation is necessary in that case, thus just change the bounds and
425 // quit. 481 // quit.
426 if (!window_->GetTargetVisibility()) { 482 if (!window_->TargetVisibility()) {
427 SetBoundsConstrained(new_bounds); 483 SetBoundsConstrained(new_bounds);
428 return; 484 return;
429 } 485 }
430 486
431 window_->SetBoundsDirectCrossFade(new_bounds); 487 const gfx::Rect old_bounds = window_->bounds();
488
489 // Create fresh layers for the window and all its children to paint into.
490 // Takes ownership of the old layer and all its children, which will be
491 // cleaned up after the animation completes.
492 // Specify |set_bounds| to true here to keep the old bounds in the child
493 // windows of |window|.
494 std::unique_ptr<ui::LayerTreeOwner> old_layer_owner =
495 ::wm::RecreateLayers(window_);
496 ui::Layer* old_layer = old_layer_owner->root();
497 DCHECK(old_layer);
498 ui::Layer* new_layer = window_->layer();
499
500 // Resize the window to the new size, which will force a layout and paint.
501 SetBoundsDirect(new_bounds);
502
503 // Ensure the higher-resolution layer is on top.
504 bool old_on_top = (old_bounds.width() > new_bounds.width());
505 if (old_on_top)
506 old_layer->parent()->StackBelow(new_layer, old_layer);
507 else
508 old_layer->parent()->StackAbove(new_layer, old_layer);
509
510 CrossFadeAnimation(window_, std::move(old_layer_owner), gfx::Tween::EASE_OUT);
432 } 511 }
433 512
434 WindowState* GetActiveWindowState() { 513 WindowState* GetActiveWindowState() {
435 aura::Window* active = GetActiveWindow(); 514 aura::Window* active = GetActiveWindow();
436 return active ? GetWindowState(active) : nullptr; 515 return active ? GetWindowState(active) : nullptr;
437 } 516 }
438 517
439 WindowState* GetWindowState(aura::Window* window) { 518 WindowState* GetWindowState(aura::Window* window) {
440 if (!window) 519 if (!window)
441 return nullptr; 520 return nullptr;
442 WindowState* settings = window->GetProperty(kWindowStateKey); 521 WindowState* settings = window->GetProperty(kWindowStateKey);
443 if (!settings) { 522 if (!settings) {
444 settings = new WindowState(WmWindow::Get(window)); 523 settings = new WindowState(window);
445 window->SetProperty(kWindowStateKey, settings); 524 window->SetProperty(kWindowStateKey, settings);
446 } 525 }
447 return settings; 526 return settings;
448 } 527 }
449 528
450 const WindowState* GetWindowState(const aura::Window* window) { 529 const WindowState* GetWindowState(const aura::Window* window) {
451 return GetWindowState(const_cast<aura::Window*>(window)); 530 return GetWindowState(const_cast<aura::Window*>(window));
452 } 531 }
453 532
533 void WindowState::OnWindowPropertyChanged(aura::Window* window,
534 const void* key,
535 intptr_t old) {
536 if (key == aura::client::kShowStateKey) {
537 if (!ignore_property_change_) {
538 WMEvent event(WMEventTypeFromShowState(GetShowState()));
539 OnWMEvent(&event);
540 }
541 return;
542 }
543 if (key == aura::client::kImmersiveFullscreenKey) {
544 in_immersive_fullscreen_ =
545 window_->GetProperty(aura::client::kImmersiveFullscreenKey);
546 return;
547 }
548 if (key == kWindowPinTypeKey) {
549 if (!ignore_property_change_) {
550 WMEvent event(WMEventTypeFromWindowPinType(GetPinType()));
551 OnWMEvent(&event);
552 }
553 return;
554 }
555 }
556
454 } // namespace wm 557 } // namespace wm
455 } // namespace ash 558 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698