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

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_window_state.cc

Issue 1921883002: Removes WindowState::aura_window() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix windows build 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 | « ash/wm/lock_window_state.cc ('k') | ash/wm/panels/panel_layout_manager_unittest.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/maximize_mode/maximize_mode_window_state.h" 5 #include "ash/wm/maximize_mode/maximize_mode_window_state.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/screen_util.h" 9 #include "ash/screen_util.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h" 11 #include "ash/shell_window_ids.h"
12 #include "ash/wm/aura/wm_window_aura.h"
12 #include "ash/wm/common/window_animation_types.h" 13 #include "ash/wm/common/window_animation_types.h"
13 #include "ash/wm/common/window_state_util.h" 14 #include "ash/wm/common/window_state_util.h"
14 #include "ash/wm/common/wm_event.h" 15 #include "ash/wm/common/wm_event.h"
16 #include "ash/wm/common/wm_screen_util.h"
15 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" 17 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
16 #include "ash/wm/window_animations.h" 18 #include "ash/wm/window_animations.h"
17 #include "ash/wm/window_properties.h" 19 #include "ash/wm/window_properties.h"
18 #include "ash/wm/window_state_aura.h" 20 #include "ash/wm/window_state_aura.h"
19 #include "ash/wm/window_state_delegate.h" 21 #include "ash/wm/window_state_delegate.h"
20 #include "ash/wm/window_util.h" 22 #include "ash/wm/window_util.h"
21 #include "ash/wm/workspace/workspace_window_resizer.h" 23 #include "ash/wm/workspace/workspace_window_resizer.h"
22 #include "ui/aura/client/aura_constants.h" 24 #include "ui/aura/client/aura_constants.h"
23 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
24 #include "ui/aura/window_delegate.h" 26 #include "ui/aura/window_delegate.h"
25 #include "ui/compositor/layer.h" 27 #include "ui/compositor/layer.h"
26 #include "ui/gfx/display.h" 28 #include "ui/gfx/display.h"
27 #include "ui/gfx/geometry/rect.h" 29 #include "ui/gfx/geometry/rect.h"
28 #include "ui/views/view_constants_aura.h" 30 #include "ui/views/view_constants_aura.h"
29 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
30 32
31 namespace ash { 33 namespace ash {
32 namespace { 34 namespace {
33 35
34 // Returns the biggest possible size for a window which is about to be 36 // Returns the biggest possible size for a window which is about to be
35 // maximized. 37 // maximized.
36 gfx::Size GetMaximumSizeOfWindow(wm::WindowState* window_state) { 38 gfx::Size GetMaximumSizeOfWindow(wm::WindowState* window_state) {
37 DCHECK(window_state->CanMaximize() || window_state->CanResize()); 39 DCHECK(window_state->CanMaximize() || window_state->CanResize());
38 40
39 gfx::Size workspace_size = 41 gfx::Size workspace_size =
40 ScreenUtil::GetMaximizedWindowBoundsInParent(window_state->aura_window()) 42 wm::GetMaximizedWindowBoundsInParent(window_state->window()).size();
41 .size();
42 43
43 aura::WindowDelegate* delegate = window_state->aura_window()->delegate(); 44 gfx::Size size = window_state->window()->GetMaximumSize();
44 if (!delegate)
45 return workspace_size;
46
47 gfx::Size size = delegate->GetMaximumSize();
48 if (size.IsEmpty()) 45 if (size.IsEmpty())
49 return workspace_size; 46 return workspace_size;
50 47
51 size.SetToMin(workspace_size); 48 size.SetToMin(workspace_size);
52 return size; 49 return size;
53 } 50 }
54 51
55 // Returns the centered bounds of the given bounds in the work area. 52 // Returns the centered bounds of the given bounds in the work area.
56 gfx::Rect GetCenteredBounds(const gfx::Rect& bounds_in_parent, 53 gfx::Rect GetCenteredBounds(const gfx::Rect& bounds_in_parent,
57 wm::WindowState* state_object) { 54 wm::WindowState* state_object) {
58 gfx::Rect work_area_in_parent = 55 gfx::Rect work_area_in_parent =
59 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->aura_window()); 56 wm::GetDisplayWorkAreaBoundsInParent(state_object->window());
60 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size()); 57 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size());
61 return work_area_in_parent; 58 return work_area_in_parent;
62 } 59 }
63 60
64 // Returns the maximized/full screen and/or centered bounds of a window. 61 // Returns the maximized/full screen and/or centered bounds of a window.
65 gfx::Rect GetBoundsInMaximizedMode(wm::WindowState* state_object) { 62 gfx::Rect GetBoundsInMaximizedMode(wm::WindowState* state_object) {
66 if (state_object->IsFullscreen()) 63 if (state_object->IsFullscreen())
67 return ScreenUtil::GetDisplayBoundsInParent(state_object->aura_window()); 64 return wm::GetDisplayBoundsInParent(state_object->window());
68 65
69 gfx::Rect bounds_in_parent; 66 gfx::Rect bounds_in_parent;
70 // Make the window as big as possible. 67 // Make the window as big as possible.
71 if (state_object->CanMaximize() || state_object->CanResize()) { 68 if (state_object->CanMaximize() || state_object->CanResize()) {
72 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object)); 69 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object));
73 } else { 70 } else {
74 // We prefer the user given window dimensions over the current windows 71 // We prefer the user given window dimensions over the current windows
75 // dimensions since they are likely to be the result from some other state 72 // dimensions since they are likely to be the result from some other state
76 // object logic. 73 // object logic.
77 if (state_object->HasRestoreBounds()) 74 if (state_object->HasRestoreBounds())
78 bounds_in_parent = state_object->GetRestoreBoundsInParent(); 75 bounds_in_parent = state_object->GetRestoreBoundsInParent();
79 else 76 else
80 bounds_in_parent = state_object->aura_window()->bounds(); 77 bounds_in_parent = state_object->window()->GetBounds();
81 } 78 }
82 return GetCenteredBounds(bounds_in_parent, state_object); 79 return GetCenteredBounds(bounds_in_parent, state_object);
83 } 80 }
84 81
85 } // namespace 82 } // namespace
86 83
87 // static 84 // static
88 void MaximizeModeWindowState::UpdateWindowPosition( 85 void MaximizeModeWindowState::UpdateWindowPosition(
89 wm::WindowState* window_state) { 86 wm::WindowState* window_state) {
90 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); 87 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state);
91 if (bounds_in_parent == window_state->aura_window()->bounds()) 88 if (bounds_in_parent == window_state->window()->GetBounds())
92 return; 89 return;
93 window_state->SetBoundsDirect(bounds_in_parent); 90 window_state->SetBoundsDirect(bounds_in_parent);
94 } 91 }
95 92
96 MaximizeModeWindowState::MaximizeModeWindowState( 93 MaximizeModeWindowState::MaximizeModeWindowState(
97 aura::Window* window, MaximizeModeWindowManager* creator) 94 aura::Window* window, MaximizeModeWindowManager* creator)
98 : window_(window), 95 : window_(window),
99 creator_(creator), 96 creator_(creator),
100 current_state_type_(wm::GetWindowState(window)->GetStateType()), 97 current_state_type_(wm::GetWindowState(window)->GetStateType()),
101 defer_bounds_updates_(false) { 98 defer_bounds_updates_(false) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 if (!bounds_in_parent.IsEmpty()) 160 if (!bounds_in_parent.IsEmpty())
164 window_state->SetRestoreBoundsInParent(bounds_in_parent); 161 window_state->SetRestoreBoundsInParent(bounds_in_parent);
165 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && 162 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
166 current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && 163 current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
167 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) { 164 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) {
168 // In all other cases (except for minimized windows) we respect the 165 // In all other cases (except for minimized windows) we respect the
169 // requested bounds and center it to a fully visible area on the screen. 166 // requested bounds and center it to a fully visible area on the screen.
170 gfx::Rect bounds_in_parent = 167 gfx::Rect bounds_in_parent =
171 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); 168 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds();
172 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state); 169 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state);
173 if (bounds_in_parent != window_state->aura_window()->bounds()) { 170 if (bounds_in_parent != window_state->window()->GetBounds()) {
174 if (window_state->window()->IsVisible()) 171 if (window_state->window()->IsVisible())
175 window_state->SetBoundsDirectAnimated(bounds_in_parent); 172 window_state->SetBoundsDirectAnimated(bounds_in_parent);
176 else 173 else
177 window_state->SetBoundsDirect(bounds_in_parent); 174 window_state->SetBoundsDirect(bounds_in_parent);
178 } 175 }
179 } 176 }
180 break; 177 break;
181 case wm::WM_EVENT_ADDED_TO_WORKSPACE: 178 case wm::WM_EVENT_ADDED_TO_WORKSPACE:
182 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && 179 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
183 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && 180 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN &&
(...skipping 17 matching lines...) Expand all
201 198
202 wm::WindowStateType MaximizeModeWindowState::GetType() const { 199 wm::WindowStateType MaximizeModeWindowState::GetType() const {
203 return current_state_type_; 200 return current_state_type_;
204 } 201 }
205 202
206 void MaximizeModeWindowState::AttachState( 203 void MaximizeModeWindowState::AttachState(
207 wm::WindowState* window_state, 204 wm::WindowState* window_state,
208 wm::WindowState::State* previous_state) { 205 wm::WindowState::State* previous_state) {
209 current_state_type_ = previous_state->GetType(); 206 current_state_type_ = previous_state->GetType();
210 207
211 views::Widget* widget = 208 aura::Window* window =
212 views::Widget::GetWidgetForNativeWindow(window_state->aura_window()); 209 ash::wm::WmWindowAura::GetAuraWindow(window_state->window());
210 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
213 if (widget) { 211 if (widget) {
214 gfx::Rect bounds = widget->GetRestoredBounds(); 212 gfx::Rect bounds = widget->GetRestoredBounds();
215 if (!bounds.IsEmpty()) { 213 if (!bounds.IsEmpty()) {
216 // We do not want to do a session restore to our window states. Therefore 214 // We do not want to do a session restore to our window states. Therefore
217 // we tell the window to use the current default states instead. 215 // we tell the window to use the current default states instead.
218 window_state->aura_window()->SetProperty( 216 window->SetProperty(ash::kRestoreShowStateOverrideKey,
219 ash::kRestoreShowStateOverrideKey, window_state->GetShowState()); 217 window_state->GetShowState());
220 window_state->aura_window()->SetProperty( 218 window->SetProperty(ash::kRestoreBoundsOverrideKey,
221 ash::kRestoreBoundsOverrideKey, 219 new gfx::Rect(widget->GetRestoredBounds()));
222 new gfx::Rect(widget->GetRestoredBounds()));
223 } 220 }
224 } 221 }
225 222
226 // Initialize the state to a good preset. 223 // Initialize the state to a good preset.
227 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && 224 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED &&
228 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && 225 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
229 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) { 226 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN) {
230 UpdateWindow(window_state, 227 UpdateWindow(window_state,
231 GetMaximizedOrCenteredWindowType(window_state), 228 GetMaximizedOrCenteredWindowType(window_state),
232 true); 229 true);
233 } 230 }
234 231
235 window_state->set_can_be_dragged(false); 232 window_state->set_can_be_dragged(false);
236 } 233 }
237 234
238 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { 235 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) {
239 // From now on, we can use the default session restore mechanism again. 236 // From now on, we can use the default session restore mechanism again.
240 window_state->aura_window()->ClearProperty(ash::kRestoreBoundsOverrideKey); 237 ash::wm::WmWindowAura::GetAuraWindow(window_state->window())
238 ->ClearProperty(ash::kRestoreBoundsOverrideKey);
241 window_state->set_can_be_dragged(true); 239 window_state->set_can_be_dragged(true);
242 } 240 }
243 241
244 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, 242 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state,
245 wm::WindowStateType target_state, 243 wm::WindowStateType target_state,
246 bool animated) { 244 bool animated) {
247 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || 245 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED ||
248 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || 246 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED ||
249 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && 247 (target_state == wm::WINDOW_STATE_TYPE_NORMAL &&
250 !window_state->CanMaximize()) || 248 !window_state->CanMaximize()) ||
251 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); 249 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN);
252 250
253 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { 251 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) {
254 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED) 252 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED)
255 return; 253 return;
256 254
257 current_state_type_ = target_state; 255 current_state_type_ = target_state;
258 ::wm::SetWindowVisibilityAnimationType( 256 window_state->window()->SetVisibilityAnimationType(
259 window_state->aura_window(),
260 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); 257 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
261 window_state->window()->Hide(); 258 window_state->window()->Hide();
262 if (window_state->IsActive()) 259 if (window_state->IsActive())
263 window_state->Deactivate(); 260 window_state->Deactivate();
264 return; 261 return;
265 } 262 }
266 263
267 if (current_state_type_ == target_state) { 264 if (current_state_type_ == target_state) {
268 // If the state type did not change, update it accordingly. 265 // If the state type did not change, update it accordingly.
269 UpdateBounds(window_state, animated); 266 UpdateBounds(window_state, animated);
270 return; 267 return;
271 } 268 }
272 269
273 const wm::WindowStateType old_state_type = current_state_type_; 270 const wm::WindowStateType old_state_type = current_state_type_;
274 current_state_type_ = target_state; 271 current_state_type_ = target_state;
275 window_state->UpdateWindowShowStateFromStateType(); 272 window_state->UpdateWindowShowStateFromStateType();
276 window_state->NotifyPreStateTypeChange(old_state_type); 273 window_state->NotifyPreStateTypeChange(old_state_type);
277 UpdateBounds(window_state, animated); 274 UpdateBounds(window_state, animated);
278 window_state->NotifyPostStateTypeChange(old_state_type); 275 window_state->NotifyPostStateTypeChange(old_state_type);
279 276
280 if ((window_state->aura_window()->TargetVisibility() || 277 if ((window_state->window()->GetTargetVisibility() ||
281 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && 278 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) &&
282 !window_state->aura_window()->layer()->visible()) { 279 !window_state->window()->GetLayer()->visible()) {
283 // The layer may be hidden if the window was previously minimized. Make 280 // The layer may be hidden if the window was previously minimized. Make
284 // sure it's visible. 281 // sure it's visible.
285 window_state->window()->Show(); 282 window_state->window()->Show();
286 } 283 }
287 } 284 }
288 285
289 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType( 286 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType(
290 wm::WindowState* window_state) { 287 wm::WindowState* window_state) {
291 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED : 288 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED :
292 wm::WINDOW_STATE_TYPE_NORMAL; 289 wm::WINDOW_STATE_TYPE_NORMAL;
293 } 290 }
294 291
295 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state, 292 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state,
296 bool animated) { 293 bool animated) {
297 if (defer_bounds_updates_) 294 if (defer_bounds_updates_)
298 return; 295 return;
299 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); 296 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state);
300 // If we have a target bounds rectangle, we center it and set it 297 // If we have a target bounds rectangle, we center it and set it
301 // accordingly. 298 // accordingly.
302 if (!bounds_in_parent.IsEmpty() && 299 if (!bounds_in_parent.IsEmpty() &&
303 bounds_in_parent != window_state->aura_window()->bounds()) { 300 bounds_in_parent != window_state->window()->GetBounds()) {
304 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || 301 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED ||
305 !window_state->window()->IsVisible() || 302 !window_state->window()->IsVisible() ||
306 !animated) { 303 !animated) {
307 window_state->SetBoundsDirect(bounds_in_parent); 304 window_state->SetBoundsDirect(bounds_in_parent);
308 } else { 305 } else {
309 // If we animate (to) maximized mode, we want to use the cross fade to 306 // If we animate (to) maximized mode, we want to use the cross fade to
310 // avoid flashing. 307 // avoid flashing.
311 if (window_state->IsMaximized()) 308 if (window_state->IsMaximized())
312 window_state->SetBoundsDirectCrossFade(bounds_in_parent); 309 window_state->SetBoundsDirectCrossFade(bounds_in_parent);
313 else 310 else
314 window_state->SetBoundsDirectAnimated(bounds_in_parent); 311 window_state->SetBoundsDirectAnimated(bounds_in_parent);
315 } 312 }
316 } 313 }
317 } 314 }
318 315
319 } // namespace ash 316 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/lock_window_state.cc ('k') | ash/wm/panels/panel_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698