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

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

Issue 2901663003: chromeos: converts WindowState to aura::Window (Closed)
Patch Set: feedback 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
« no previous file with comments | « ash/test/wm_window_test_api.cc ('k') | ash/wm/drag_details.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 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/default_state.h" 5 #include "ash/wm/default_state.h"
6 6
7 #include "ash/public/cpp/shell_window_ids.h" 7 #include "ash/public/cpp/shell_window_ids.h"
8 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
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_port.h" 11 #include "ash/shell_port.h"
12 #include "ash/wm/screen_pinning_controller.h" 12 #include "ash/wm/screen_pinning_controller.h"
13 #include "ash/wm/window_animation_types.h" 13 #include "ash/wm/window_animation_types.h"
14 #include "ash/wm/window_parenting_utils.h" 14 #include "ash/wm/window_parenting_utils.h"
15 #include "ash/wm/window_positioning_utils.h" 15 #include "ash/wm/window_positioning_utils.h"
16 #include "ash/wm/window_state.h" 16 #include "ash/wm/window_state.h"
17 #include "ash/wm/window_state_delegate.h" 17 #include "ash/wm/window_state_delegate.h"
18 #include "ash/wm/window_state_util.h" 18 #include "ash/wm/window_state_util.h"
19 #include "ash/wm/wm_event.h" 19 #include "ash/wm/wm_event.h"
20 #include "ash/wm_window.h" 20 #include "ash/wm_window.h"
21 #include "ui/aura/client/aura_constants.h" 21 #include "ui/aura/client/aura_constants.h"
22 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
23 #include "ui/aura/window_delegate.h"
23 #include "ui/display/display.h" 24 #include "ui/display/display.h"
24 #include "ui/display/screen.h" 25 #include "ui/display/screen.h"
26 #include "ui/wm/core/window_util.h"
25 27
26 namespace ash { 28 namespace ash {
27 namespace wm { 29 namespace wm {
28 namespace { 30 namespace {
29 31
30 // This specifies how much percent (30%) of a window rect 32 // This specifies how much percent (30%) of a window rect
31 // must be visible when the window is added to the workspace. 33 // must be visible when the window is added to the workspace.
32 const float kMinimumPercentOnScreenArea = 0.3f; 34 const float kMinimumPercentOnScreenArea = 0.3f;
33 35
34 // When a window that has restore bounds at least as large as a work area is 36 // When a window that has restore bounds at least as large as a work area is
35 // unmaximized, inset the bounds slightly so that they are not exactly the same. 37 // unmaximized, inset the bounds slightly so that they are not exactly the same.
36 // This makes it easier to resize the window. 38 // This makes it easier to resize the window.
37 const int kMaximizedWindowInset = 10; // DIPs. 39 const int kMaximizedWindowInset = 10; // DIPs.
38 40
41 gfx::Size GetWindowMaximumSize(aura::Window* window) {
42 return window->delegate() ? window->delegate()->GetMaximumSize()
43 : gfx::Size();
44 }
45
39 bool IsMinimizedWindowState(const WindowStateType state_type) { 46 bool IsMinimizedWindowState(const WindowStateType state_type) {
40 return state_type == WINDOW_STATE_TYPE_MINIMIZED; 47 return state_type == WINDOW_STATE_TYPE_MINIMIZED;
41 } 48 }
42 49
43 void MoveToDisplayForRestore(WindowState* window_state) { 50 void MoveToDisplayForRestore(WindowState* window_state) {
44 if (!window_state->HasRestoreBounds()) 51 if (!window_state->HasRestoreBounds())
45 return; 52 return;
46 const gfx::Rect restore_bounds = window_state->GetRestoreBoundsInScreen(); 53 const gfx::Rect restore_bounds = window_state->GetRestoreBoundsInScreen();
47 54
48 // Move only if the restore bounds is outside of 55 // Move only if the restore bounds is outside of
49 // the display. There is no information about in which 56 // the display. There is no information about in which
50 // display it should be restored, so this is best guess. 57 // display it should be restored, so this is best guess.
51 // TODO(oshima): Restore information should contain the 58 // TODO(oshima): Restore information should contain the
52 // work area information like WindowResizer does for the 59 // work area information like WindowResizer does for the
53 // last window location. 60 // last window location.
54 gfx::Rect display_area = 61 gfx::Rect display_area = display::Screen::GetScreen()
55 window_state->window()->GetDisplayNearestWindow().bounds(); 62 ->GetDisplayNearestWindow(window_state->window())
63 .bounds();
56 64
57 if (!display_area.Intersects(restore_bounds)) { 65 if (!display_area.Intersects(restore_bounds)) {
58 const display::Display& display = 66 const display::Display& display =
59 display::Screen::GetScreen()->GetDisplayMatching(restore_bounds); 67 display::Screen::GetScreen()->GetDisplayMatching(restore_bounds);
60 RootWindowController* new_root_controller = 68 RootWindowController* new_root_controller =
61 Shell::Get()->GetRootWindowControllerWithDisplayId(display.id()); 69 Shell::Get()->GetRootWindowControllerWithDisplayId(display.id());
62 if (new_root_controller->GetRootWindow() != 70 if (new_root_controller->GetRootWindow() !=
63 window_state->window()->GetRootWindow()->aura_window()) { 71 window_state->window()->GetRootWindow()) {
64 aura::Window* new_container = 72 aura::Window* new_container =
65 new_root_controller->GetRootWindow()->GetChildById( 73 new_root_controller->GetRootWindow()->GetChildById(
66 window_state->window()->GetParent()->aura_window()->id()); 74 window_state->window()->parent()->id());
67 new_container->AddChild(window_state->window()->aura_window()); 75 new_container->AddChild(window_state->window());
68 } 76 }
69 } 77 }
70 } 78 }
71 79
72 void CycleSnap(WindowState* window_state, WMEventType event) { 80 void CycleSnap(WindowState* window_state, WMEventType event) {
73 wm::WindowStateType desired_snap_state = 81 wm::WindowStateType desired_snap_state =
74 event == WM_EVENT_CYCLE_SNAP_LEFT ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED 82 event == WM_EVENT_CYCLE_SNAP_LEFT ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
75 : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED; 83 : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED;
76 84
77 if (window_state->CanSnap() && 85 if (window_state->CanSnap() &&
78 window_state->GetStateType() != desired_snap_state && 86 window_state->GetStateType() != desired_snap_state &&
79 window_state->window()->GetType() != ui::wm::WINDOW_TYPE_PANEL) { 87 window_state->window()->type() != ui::wm::WINDOW_TYPE_PANEL) {
80 const wm::WMEvent event(desired_snap_state == 88 const wm::WMEvent event(desired_snap_state ==
81 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED 89 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
82 ? wm::WM_EVENT_SNAP_LEFT 90 ? wm::WM_EVENT_SNAP_LEFT
83 : wm::WM_EVENT_SNAP_RIGHT); 91 : wm::WM_EVENT_SNAP_RIGHT);
84 window_state->OnWMEvent(&event); 92 window_state->OnWMEvent(&event);
85 return; 93 return;
86 } 94 }
87 95
88 if (window_state->IsSnapped()) { 96 if (window_state->IsSnapped()) {
89 window_state->Restore(); 97 window_state->Restore();
90 return; 98 return;
91 } 99 }
92 window_state->window()->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); 100 ::wm::AnimateWindow(window_state->window(),
101 ::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
93 } 102 }
94 103
95 } // namespace 104 } // namespace
96 105
97 DefaultState::DefaultState(WindowStateType initial_state_type) 106 DefaultState::DefaultState(WindowStateType initial_state_type)
98 : state_type_(initial_state_type), stored_window_state_(nullptr) {} 107 : state_type_(initial_state_type), stored_window_state_(nullptr) {}
99 DefaultState::~DefaultState() {} 108 DefaultState::~DefaultState() {}
100 109
101 void DefaultState::OnWMEvent(WindowState* window_state, const WMEvent* event) { 110 void DefaultState::OnWMEvent(WindowState* window_state, const WMEvent* event) {
102 if (ProcessWorkspaceEvents(window_state, event)) 111 if (ProcessWorkspaceEvents(window_state, event))
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 NOTREACHED() << "Compound event should not reach here:" << event; 172 NOTREACHED() << "Compound event should not reach here:" << event;
164 return; 173 return;
165 case WM_EVENT_ADDED_TO_WORKSPACE: 174 case WM_EVENT_ADDED_TO_WORKSPACE:
166 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: 175 case WM_EVENT_WORKAREA_BOUNDS_CHANGED:
167 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: 176 case WM_EVENT_DISPLAY_BOUNDS_CHANGED:
168 NOTREACHED() << "Workspace event should not reach here:" << event; 177 NOTREACHED() << "Workspace event should not reach here:" << event;
169 return; 178 return;
170 } 179 }
171 180
172 if (next_state_type == current_state_type && window_state->IsSnapped()) { 181 if (next_state_type == current_state_type && window_state->IsSnapped()) {
173 aura::Window* window = window_state->window()->aura_window(); 182 aura::Window* window = window_state->window();
174 gfx::Rect snapped_bounds = 183 gfx::Rect snapped_bounds =
175 event->type() == WM_EVENT_SNAP_LEFT 184 event->type() == WM_EVENT_SNAP_LEFT
176 ? GetDefaultLeftSnappedWindowBoundsInParent(window) 185 ? GetDefaultLeftSnappedWindowBoundsInParent(window)
177 : GetDefaultRightSnappedWindowBoundsInParent(window); 186 : GetDefaultRightSnappedWindowBoundsInParent(window);
178 window_state->SetBoundsDirectAnimated(snapped_bounds); 187 window_state->SetBoundsDirectAnimated(snapped_bounds);
179 return; 188 return;
180 } 189 }
181 190
182 if (event->type() == WM_EVENT_SNAP_LEFT || 191 if (event->type() == WM_EVENT_SNAP_LEFT ||
183 event->type() == WM_EVENT_SNAP_RIGHT) { 192 event->type() == WM_EVENT_SNAP_RIGHT) {
184 window_state->set_bounds_changed_by_user(true); 193 window_state->set_bounds_changed_by_user(true);
185 } 194 }
186 195
187 EnterToNextState(window_state, next_state_type); 196 EnterToNextState(window_state, next_state_type);
188 } 197 }
189 198
190 WindowStateType DefaultState::GetType() const { 199 WindowStateType DefaultState::GetType() const {
191 return state_type_; 200 return state_type_;
192 } 201 }
193 202
194 void DefaultState::AttachState(WindowState* window_state, 203 void DefaultState::AttachState(WindowState* window_state,
195 WindowState::State* state_in_previous_mode) { 204 WindowState::State* state_in_previous_mode) {
196 DCHECK_EQ(stored_window_state_, window_state); 205 DCHECK_EQ(stored_window_state_, window_state);
197 206
198 ReenterToCurrentState(window_state, state_in_previous_mode); 207 ReenterToCurrentState(window_state, state_in_previous_mode);
199 208
200 // If the display has changed while in the another mode, 209 // If the display has changed while in the another mode,
201 // we need to let windows know the change. 210 // we need to let windows know the change.
202 display::Display current_display = 211 display::Display current_display =
203 window_state->window()->GetDisplayNearestWindow(); 212 display::Screen::GetScreen()->GetDisplayNearestWindow(
213 window_state->window());
204 if (stored_display_state_.bounds() != current_display.bounds()) { 214 if (stored_display_state_.bounds() != current_display.bounds()) {
205 const WMEvent event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); 215 const WMEvent event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED);
206 window_state->OnWMEvent(&event); 216 window_state->OnWMEvent(&event);
207 } else if (stored_display_state_.work_area() != current_display.work_area()) { 217 } else if (stored_display_state_.work_area() != current_display.work_area()) {
208 const WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); 218 const WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
209 window_state->OnWMEvent(&event); 219 window_state->OnWMEvent(&event);
210 } 220 }
211 } 221 }
212 222
213 void DefaultState::DetachState(WindowState* window_state) { 223 void DefaultState::DetachState(WindowState* window_state) {
214 stored_window_state_ = window_state; 224 stored_window_state_ = window_state;
215 stored_bounds_ = window_state->window()->GetBounds(); 225 stored_bounds_ = window_state->window()->bounds();
216 stored_restore_bounds_ = window_state->HasRestoreBounds() 226 stored_restore_bounds_ = window_state->HasRestoreBounds()
217 ? window_state->GetRestoreBoundsInParent() 227 ? window_state->GetRestoreBoundsInParent()
218 : gfx::Rect(); 228 : gfx::Rect();
219 // Remember the display state so that in case of the display change 229 // Remember the display state so that in case of the display change
220 // while in the other mode, we can perform necessary action to 230 // while in the other mode, we can perform necessary action to
221 // restore the window state to the proper state for the current 231 // restore the window state to the proper state for the current
222 // display. 232 // display.
223 stored_display_state_ = window_state->window()->GetDisplayNearestWindow(); 233 stored_display_state_ = display::Screen::GetScreen()->GetDisplayNearestWindow(
234 window_state->window());
224 } 235 }
225 236
226 // static 237 // static
227 bool DefaultState::ProcessCompoundEvents(WindowState* window_state, 238 bool DefaultState::ProcessCompoundEvents(WindowState* window_state,
228 const WMEvent* event) { 239 const WMEvent* event) {
229 WmWindow* window = window_state->window(); 240 aura::Window* window = window_state->window();
230 241
231 switch (event->type()) { 242 switch (event->type()) {
232 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: 243 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
233 if (window_state->IsFullscreen()) { 244 if (window_state->IsFullscreen()) {
234 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); 245 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
235 window_state->OnWMEvent(&event); 246 window_state->OnWMEvent(&event);
236 } else if (window_state->IsMaximized()) { 247 } else if (window_state->IsMaximized()) {
237 window_state->Restore(); 248 window_state->Restore();
238 } else if (window_state->IsNormalOrSnapped()) { 249 } else if (window_state->IsNormalOrSnapped()) {
239 if (window_state->CanMaximize()) 250 if (window_state->CanMaximize())
240 window_state->Maximize(); 251 window_state->Maximize();
241 } 252 }
242 return true; 253 return true;
243 case WM_EVENT_TOGGLE_MAXIMIZE: 254 case WM_EVENT_TOGGLE_MAXIMIZE:
244 if (window_state->IsFullscreen()) { 255 if (window_state->IsFullscreen()) {
245 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); 256 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
246 window_state->OnWMEvent(&event); 257 window_state->OnWMEvent(&event);
247 } else if (window_state->IsMaximized()) { 258 } else if (window_state->IsMaximized()) {
248 window_state->Restore(); 259 window_state->Restore();
249 } else if (window_state->CanMaximize()) { 260 } else if (window_state->CanMaximize()) {
250 window_state->Maximize(); 261 window_state->Maximize();
251 } 262 }
252 return true; 263 return true;
253 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: { 264 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: {
254 gfx::Rect work_area = 265 gfx::Rect work_area =
255 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()); 266 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window);
256 267
257 // Maximize vertically if: 268 // Maximize vertically if:
258 // - The window does not have a max height defined. 269 // - The window does not have a max height defined.
259 // - The window has the normal state type. Snapped windows are excluded 270 // - The window has the normal state type. Snapped windows are excluded
260 // because they are already maximized vertically and reverting to the 271 // because they are already maximized vertically and reverting to the
261 // restored bounds looks weird. 272 // restored bounds looks weird.
262 if (window->GetMaximumSize().height() != 0 || 273 if (GetWindowMaximumSize(window).height() != 0 ||
263 !window_state->IsNormalStateType()) { 274 !window_state->IsNormalStateType()) {
264 return true; 275 return true;
265 } 276 }
266 if (window_state->HasRestoreBounds() && 277 if (window_state->HasRestoreBounds() &&
267 (window->GetBounds().height() == work_area.height() && 278 (window->bounds().height() == work_area.height() &&
268 window->GetBounds().y() == work_area.y())) { 279 window->bounds().y() == work_area.y())) {
269 window_state->SetAndClearRestoreBounds(); 280 window_state->SetAndClearRestoreBounds();
270 } else { 281 } else {
271 window_state->SaveCurrentBoundsForRestore(); 282 window_state->SaveCurrentBoundsForRestore();
272 window->SetBounds(gfx::Rect(window->GetBounds().x(), work_area.y(), 283 window->SetBounds(gfx::Rect(window->bounds().x(), work_area.y(),
273 window->GetBounds().width(), 284 window->bounds().width(),
274 work_area.height())); 285 work_area.height()));
275 } 286 }
276 return true; 287 return true;
277 } 288 }
278 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: { 289 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: {
279 // Maximize horizontally if: 290 // Maximize horizontally if:
280 // - The window does not have a max width defined. 291 // - The window does not have a max width defined.
281 // - The window is snapped or has the normal state type. 292 // - The window is snapped or has the normal state type.
282 if (window->GetMaximumSize().width() != 0) 293 if (GetWindowMaximumSize(window).width() != 0)
283 return true; 294 return true;
284 if (!window_state->IsNormalOrSnapped()) 295 if (!window_state->IsNormalOrSnapped())
285 return true; 296 return true;
286 gfx::Rect work_area = 297 gfx::Rect work_area =
287 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()); 298 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window);
288 if (window_state->IsNormalStateType() && 299 if (window_state->IsNormalStateType() &&
289 window_state->HasRestoreBounds() && 300 window_state->HasRestoreBounds() &&
290 (window->GetBounds().width() == work_area.width() && 301 (window->bounds().width() == work_area.width() &&
291 window->GetBounds().x() == work_area.x())) { 302 window->bounds().x() == work_area.x())) {
292 window_state->SetAndClearRestoreBounds(); 303 window_state->SetAndClearRestoreBounds();
293 } else { 304 } else {
294 gfx::Rect new_bounds(work_area.x(), window->GetBounds().y(), 305 gfx::Rect new_bounds(work_area.x(), window->bounds().y(),
295 work_area.width(), window->GetBounds().height()); 306 work_area.width(), window->bounds().height());
296 307
297 gfx::Rect restore_bounds = window->GetBounds(); 308 gfx::Rect restore_bounds = window->bounds();
298 if (window_state->IsSnapped()) { 309 if (window_state->IsSnapped()) {
299 window_state->SetRestoreBoundsInParent(new_bounds); 310 window_state->SetRestoreBoundsInParent(new_bounds);
300 window_state->Restore(); 311 window_state->Restore();
301 312
302 // The restore logic prevents a window from being restored to bounds 313 // The restore logic prevents a window from being restored to bounds
303 // which match the workspace bounds exactly so it is necessary to set 314 // which match the workspace bounds exactly so it is necessary to set
304 // the bounds again below. 315 // the bounds again below.
305 } 316 }
306 317
307 window_state->SetRestoreBoundsInParent(restore_bounds); 318 window_state->SetRestoreBoundsInParent(restore_bounds);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // root window, the bounds will be updated after they are added 358 // root window, the bounds will be updated after they are added
348 // to the root window. 359 // to the root window.
349 // If a window is opened as maximized or fullscreen, its bounds may be 360 // If a window is opened as maximized or fullscreen, its bounds may be
350 // empty, so update the bounds now before checking empty. 361 // empty, so update the bounds now before checking empty.
351 if (window_state->is_dragged() || 362 if (window_state->is_dragged() ||
352 window_state->allow_set_bounds_direct() || 363 window_state->allow_set_bounds_direct() ||
353 SetMaximizedOrFullscreenBounds(window_state)) { 364 SetMaximizedOrFullscreenBounds(window_state)) {
354 return true; 365 return true;
355 } 366 }
356 367
357 WmWindow* window = window_state->window(); 368 aura::Window* window = window_state->window();
358 gfx::Rect bounds = window->GetBounds(); 369 gfx::Rect bounds = window->bounds();
359 370
360 // Don't adjust window bounds if the bounds are empty as this 371 // Don't adjust window bounds if the bounds are empty as this
361 // happens when a new views::Widget is created. 372 // happens when a new views::Widget is created.
362 if (bounds.IsEmpty()) 373 if (bounds.IsEmpty())
363 return true; 374 return true;
364 375
365 // Only windows of type WINDOW_TYPE_NORMAL or WINDOW_TYPE_PANEL need to be 376 // Only windows of type WINDOW_TYPE_NORMAL or WINDOW_TYPE_PANEL need to be
366 // adjusted to have minimum visibility, because they are positioned by the 377 // adjusted to have minimum visibility, because they are positioned by the
367 // user and user should always be able to interact with them. Other 378 // user and user should always be able to interact with them. Other
368 // windows are positioned programmatically. 379 // windows are positioned programmatically.
369 if (!window_state->IsUserPositionable()) 380 if (!window_state->IsUserPositionable())
370 return true; 381 return true;
371 382
372 // Use entire display instead of workarea. The logic ensures 30% 383 // Use entire display instead of workarea. The logic ensures 30%
373 // visibility which should be enough to see where the window gets 384 // visibility which should be enough to see where the window gets
374 // moved. 385 // moved.
375 gfx::Rect display_area = 386 gfx::Rect display_area = ScreenUtil::GetDisplayBoundsInParent(window);
376 ScreenUtil::GetDisplayBoundsInParent(window->aura_window());
377 int min_width = bounds.width() * wm::kMinimumPercentOnScreenArea; 387 int min_width = bounds.width() * wm::kMinimumPercentOnScreenArea;
378 int min_height = bounds.height() * wm::kMinimumPercentOnScreenArea; 388 int min_height = bounds.height() * wm::kMinimumPercentOnScreenArea;
379 wm::AdjustBoundsToEnsureWindowVisibility(display_area, min_width, 389 wm::AdjustBoundsToEnsureWindowVisibility(display_area, min_width,
380 min_height, &bounds); 390 min_height, &bounds);
381 window_state->AdjustSnappedBounds(&bounds); 391 window_state->AdjustSnappedBounds(&bounds);
382 if (window->GetBounds() != bounds) 392 if (window->bounds() != bounds)
383 window_state->SetBoundsConstrained(bounds); 393 window_state->SetBoundsConstrained(bounds);
384 return true; 394 return true;
385 } 395 }
386 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: { 396 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: {
387 if (window_state->is_dragged() || 397 if (window_state->is_dragged() ||
388 window_state->allow_set_bounds_direct() || 398 window_state->allow_set_bounds_direct() ||
389 SetMaximizedOrFullscreenBounds(window_state)) { 399 SetMaximizedOrFullscreenBounds(window_state)) {
390 return true; 400 return true;
391 } 401 }
392 gfx::Rect work_area_in_parent = 402 gfx::Rect work_area_in_parent =
393 ScreenUtil::GetDisplayWorkAreaBoundsInParent( 403 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window());
394 window_state->window()->aura_window());
395 gfx::Rect bounds = window_state->window()->GetTargetBounds(); 404 gfx::Rect bounds = window_state->window()->GetTargetBounds();
396 // When display bounds has changed, make sure the entire window is fully 405 // When display bounds has changed, make sure the entire window is fully
397 // visible. 406 // visible.
398 bounds.AdjustToFit(work_area_in_parent); 407 bounds.AdjustToFit(work_area_in_parent);
399 window_state->AdjustSnappedBounds(&bounds); 408 window_state->AdjustSnappedBounds(&bounds);
400 if (window_state->window()->GetTargetBounds() != bounds) 409 if (window_state->window()->GetTargetBounds() != bounds)
401 window_state->SetBoundsDirectAnimated(bounds); 410 window_state->SetBoundsDirectAnimated(bounds);
402 return true; 411 return true;
403 } 412 }
404 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: { 413 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: {
405 // Don't resize the maximized window when the desktop is covered 414 // Don't resize the maximized window when the desktop is covered
406 // by fullscreen window. crbug.com/504299. 415 // by fullscreen window. crbug.com/504299.
407 bool in_fullscreen = 416 bool in_fullscreen =
408 window_state->window() 417 RootWindowController::ForWindow(window_state->window())
409 ->GetRootWindowController()
410 ->GetWorkspaceWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN; 418 ->GetWorkspaceWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN;
411 if (in_fullscreen && window_state->IsMaximized()) 419 if (in_fullscreen && window_state->IsMaximized())
412 return true; 420 return true;
413 421
414 if (window_state->is_dragged() || 422 if (window_state->is_dragged() ||
415 window_state->allow_set_bounds_direct() || 423 window_state->allow_set_bounds_direct() ||
416 SetMaximizedOrFullscreenBounds(window_state)) { 424 SetMaximizedOrFullscreenBounds(window_state)) {
417 return true; 425 return true;
418 } 426 }
419 gfx::Rect work_area_in_parent = 427 gfx::Rect work_area_in_parent =
420 ScreenUtil::GetDisplayWorkAreaBoundsInParent( 428 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window());
421 window_state->window()->aura_window());
422 gfx::Rect bounds = window_state->window()->GetTargetBounds(); 429 gfx::Rect bounds = window_state->window()->GetTargetBounds();
423 if (!window_state->window()->GetTransientParent()) { 430 if (!::wm::GetTransientParent(window_state->window())) {
424 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, 431 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent,
425 &bounds); 432 &bounds);
426 } 433 }
427 window_state->AdjustSnappedBounds(&bounds); 434 window_state->AdjustSnappedBounds(&bounds);
428 if (window_state->window()->GetTargetBounds() != bounds) 435 if (window_state->window()->GetTargetBounds() != bounds)
429 window_state->SetBoundsDirectAnimated(bounds); 436 window_state->SetBoundsDirectAnimated(bounds);
430 return true; 437 return true;
431 } 438 }
432 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: 439 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
433 case WM_EVENT_TOGGLE_MAXIMIZE: 440 case WM_EVENT_TOGGLE_MAXIMIZE:
(...skipping 16 matching lines...) Expand all
450 break; 457 break;
451 } 458 }
452 return false; 459 return false;
453 } 460 }
454 461
455 // static 462 // static
456 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) { 463 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) {
457 DCHECK(!window_state->is_dragged()); 464 DCHECK(!window_state->is_dragged());
458 DCHECK(!window_state->allow_set_bounds_direct()); 465 DCHECK(!window_state->allow_set_bounds_direct());
459 if (window_state->IsMaximized()) { 466 if (window_state->IsMaximized()) {
460 window_state->SetBoundsDirect(ScreenUtil::GetMaximizedWindowBoundsInParent( 467 window_state->SetBoundsDirect(
461 window_state->window()->aura_window())); 468 ScreenUtil::GetMaximizedWindowBoundsInParent(window_state->window()));
462 return true; 469 return true;
463 } 470 }
464 if (window_state->IsFullscreen()) { 471 if (window_state->IsFullscreen()) {
465 window_state->SetBoundsDirect(ScreenUtil::GetDisplayBoundsInParent( 472 window_state->SetBoundsDirect(
466 window_state->window()->aura_window())); 473 ScreenUtil::GetDisplayBoundsInParent(window_state->window()));
467 return true; 474 return true;
468 } 475 }
469 return false; 476 return false;
470 } 477 }
471 478
472 // static 479 // static
473 void DefaultState::SetBounds(WindowState* window_state, 480 void DefaultState::SetBounds(WindowState* window_state,
474 const SetBoundsEvent* event) { 481 const SetBoundsEvent* event) {
475 if (window_state->is_dragged() || window_state->allow_set_bounds_direct()) { 482 if (window_state->is_dragged() || window_state->allow_set_bounds_direct()) {
476 // TODO(oshima|varkha): Is this still needed? crbug.com/485612. 483 // TODO(oshima|varkha): Is this still needed? crbug.com/485612.
477 window_state->SetBoundsDirect(event->requested_bounds()); 484 window_state->SetBoundsDirect(event->requested_bounds());
478 } else if (window_state->IsSnapped()) { 485 } else if (window_state->IsSnapped()) {
479 gfx::Rect work_area_in_parent = 486 gfx::Rect work_area_in_parent =
480 ScreenUtil::GetDisplayWorkAreaBoundsInParent( 487 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_state->window());
481 window_state->window()->aura_window());
482 gfx::Rect child_bounds(event->requested_bounds()); 488 gfx::Rect child_bounds(event->requested_bounds());
483 wm::AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); 489 wm::AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds);
484 window_state->AdjustSnappedBounds(&child_bounds); 490 window_state->AdjustSnappedBounds(&child_bounds);
485 window_state->SetBoundsDirect(child_bounds); 491 window_state->SetBoundsDirect(child_bounds);
486 } else if (!SetMaximizedOrFullscreenBounds(window_state)) { 492 } else if (!SetMaximizedOrFullscreenBounds(window_state)) {
487 window_state->SetBoundsConstrained(event->requested_bounds()); 493 window_state->SetBoundsConstrained(event->requested_bounds());
488 } 494 }
489 } 495 }
490 496
491 void DefaultState::EnterToNextState(WindowState* window_state, 497 void DefaultState::EnterToNextState(WindowState* window_state,
492 WindowStateType next_state_type) { 498 WindowStateType next_state_type) {
493 // Do nothing if we're already in the same state. 499 // Do nothing if we're already in the same state.
494 if (state_type_ == next_state_type) 500 if (state_type_ == next_state_type)
495 return; 501 return;
496 502
497 WindowStateType previous_state_type = state_type_; 503 WindowStateType previous_state_type = state_type_;
498 state_type_ = next_state_type; 504 state_type_ = next_state_type;
499 505
500 window_state->UpdateWindowPropertiesFromStateType(); 506 window_state->UpdateWindowPropertiesFromStateType();
501 window_state->NotifyPreStateTypeChange(previous_state_type); 507 window_state->NotifyPreStateTypeChange(previous_state_type);
502 508
503 if (window_state->window()->GetParent()) { 509 if (window_state->window()->parent()) {
504 if (!window_state->HasRestoreBounds() && 510 if (!window_state->HasRestoreBounds() &&
505 (previous_state_type == WINDOW_STATE_TYPE_DEFAULT || 511 (previous_state_type == WINDOW_STATE_TYPE_DEFAULT ||
506 previous_state_type == WINDOW_STATE_TYPE_NORMAL) && 512 previous_state_type == WINDOW_STATE_TYPE_NORMAL) &&
507 !window_state->IsMinimized() && !window_state->IsNormalStateType()) { 513 !window_state->IsMinimized() && !window_state->IsNormalStateType()) {
508 window_state->SaveCurrentBoundsForRestore(); 514 window_state->SaveCurrentBoundsForRestore();
509 } 515 }
510 516
511 // When restoring from a minimized state, we want to restore to the 517 // When restoring from a minimized state, we want to restore to the
512 // previous bounds. However, we want to maintain the restore bounds. 518 // previous bounds. However, we want to maintain the restore bounds.
513 // (The restore bounds are set if a user maximized the window in one 519 // (The restore bounds are set if a user maximized the window in one
(...skipping 18 matching lines...) Expand all
532 else if (window_state->IsNormalStateType()) 538 else if (window_state->IsNormalStateType())
533 window_state->ClearRestoreBounds(); 539 window_state->ClearRestoreBounds();
534 } 540 }
535 window_state->NotifyPostStateTypeChange(previous_state_type); 541 window_state->NotifyPostStateTypeChange(previous_state_type);
536 542
537 if (next_state_type == WINDOW_STATE_TYPE_PINNED || 543 if (next_state_type == WINDOW_STATE_TYPE_PINNED ||
538 previous_state_type == WINDOW_STATE_TYPE_PINNED || 544 previous_state_type == WINDOW_STATE_TYPE_PINNED ||
539 next_state_type == WINDOW_STATE_TYPE_TRUSTED_PINNED || 545 next_state_type == WINDOW_STATE_TYPE_TRUSTED_PINNED ||
540 previous_state_type == WINDOW_STATE_TYPE_TRUSTED_PINNED) { 546 previous_state_type == WINDOW_STATE_TYPE_TRUSTED_PINNED) {
541 Shell::Get()->screen_pinning_controller()->SetPinnedWindow( 547 Shell::Get()->screen_pinning_controller()->SetPinnedWindow(
542 window_state->window()); 548 WmWindow::Get(window_state->window()));
543 } 549 }
544 } 550 }
545 551
546 void DefaultState::ReenterToCurrentState( 552 void DefaultState::ReenterToCurrentState(
547 WindowState* window_state, 553 WindowState* window_state,
548 WindowState::State* state_in_previous_mode) { 554 WindowState::State* state_in_previous_mode) {
549 WindowStateType previous_state_type = state_in_previous_mode->GetType(); 555 WindowStateType previous_state_type = state_in_previous_mode->GetType();
550 556
551 // A state change should not move a window into or out of full screen or 557 // A state change should not move a window into or out of full screen or
552 // pinned since these are "special mode" the user wanted to be in and 558 // pinned since these are "special mode" the user wanted to be in and
(...skipping 25 matching lines...) Expand all
578 if (!stored_restore_bounds_.IsEmpty()) 584 if (!stored_restore_bounds_.IsEmpty())
579 window_state->SetRestoreBoundsInParent(stored_restore_bounds_); 585 window_state->SetRestoreBoundsInParent(stored_restore_bounds_);
580 else 586 else
581 window_state->ClearRestoreBounds(); 587 window_state->ClearRestoreBounds();
582 588
583 window_state->NotifyPostStateTypeChange(previous_state_type); 589 window_state->NotifyPostStateTypeChange(previous_state_type);
584 } 590 }
585 591
586 void DefaultState::UpdateBoundsFromState(WindowState* window_state, 592 void DefaultState::UpdateBoundsFromState(WindowState* window_state,
587 WindowStateType previous_state_type) { 593 WindowStateType previous_state_type) {
588 aura::Window* window = window_state->window()->aura_window(); 594 aura::Window* window = window_state->window();
589 gfx::Rect bounds_in_parent; 595 gfx::Rect bounds_in_parent;
590 switch (state_type_) { 596 switch (state_type_) {
591 case WINDOW_STATE_TYPE_LEFT_SNAPPED: 597 case WINDOW_STATE_TYPE_LEFT_SNAPPED:
592 case WINDOW_STATE_TYPE_RIGHT_SNAPPED: 598 case WINDOW_STATE_TYPE_RIGHT_SNAPPED:
593 bounds_in_parent = 599 bounds_in_parent =
594 state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED 600 state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED
595 ? GetDefaultLeftSnappedWindowBoundsInParent(window) 601 ? GetDefaultLeftSnappedWindowBoundsInParent(window)
596 : GetDefaultRightSnappedWindowBoundsInParent(window); 602 : GetDefaultRightSnappedWindowBoundsInParent(window);
597 break; 603 break;
598 604
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 !window_state->IsMaximizedOrFullscreenOrPinned()) { 687 !window_state->IsMaximizedOrFullscreenOrPinned()) {
682 window_state->set_unminimize_to_restore_bounds(false); 688 window_state->set_unminimize_to_restore_bounds(false);
683 } 689 }
684 } 690 }
685 } 691 }
686 692
687 // static 693 // static
688 void DefaultState::CenterWindow(WindowState* window_state) { 694 void DefaultState::CenterWindow(WindowState* window_state) {
689 if (!window_state->IsNormalOrSnapped()) 695 if (!window_state->IsNormalOrSnapped())
690 return; 696 return;
691 WmWindow* window = window_state->window(); 697 aura::Window* window = window_state->window();
692 if (window_state->IsSnapped()) { 698 if (window_state->IsSnapped()) {
693 gfx::Rect center_in_screen = window->GetDisplayNearestWindow().work_area(); 699 gfx::Rect center_in_screen = display::Screen::GetScreen()
700 ->GetDisplayNearestWindow(window)
701 .work_area();
694 gfx::Size size = window_state->HasRestoreBounds() 702 gfx::Size size = window_state->HasRestoreBounds()
695 ? window_state->GetRestoreBoundsInScreen().size() 703 ? window_state->GetRestoreBoundsInScreen().size()
696 : window->GetBounds().size(); 704 : window->bounds().size();
697 center_in_screen.ClampToCenteredSize(size); 705 center_in_screen.ClampToCenteredSize(size);
698 window_state->SetRestoreBoundsInScreen(center_in_screen); 706 window_state->SetRestoreBoundsInScreen(center_in_screen);
699 window_state->Restore(); 707 window_state->Restore();
700 } else { 708 } else {
701 gfx::Rect center_in_parent = 709 gfx::Rect center_in_parent =
702 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()); 710 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window);
703 center_in_parent.ClampToCenteredSize(window->GetBounds().size()); 711 center_in_parent.ClampToCenteredSize(window->bounds().size());
704 window_state->SetBoundsDirectAnimated(center_in_parent); 712 window_state->SetBoundsDirectAnimated(center_in_parent);
705 } 713 }
706 // Centering window is treated as if a user moved and resized the window. 714 // Centering window is treated as if a user moved and resized the window.
707 window_state->set_bounds_changed_by_user(true); 715 window_state->set_bounds_changed_by_user(true);
708 } 716 }
709 717
710 } // namespace wm 718 } // namespace wm
711 } // namespace ash 719 } // namespace ash
OLDNEW
« no previous file with comments | « ash/test/wm_window_test_api.cc ('k') | ash/wm/drag_details.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698