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

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

Issue 2700523004: Remove docked windows entirely in M59. (Closed)
Patch Set: Rebase Created 3 years, 9 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/common/shelf/shelf_window_watcher_unittest.cc ('k') | ash/common/wm/dock/dock_types.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/common/wm/default_state.h" 5 #include "ash/common/wm/default_state.h"
6 6
7 #include "ash/common/ash_switches.h"
8 #include "ash/common/wm/dock/docked_window_layout_manager.h"
9 #include "ash/common/wm/window_animation_types.h" 7 #include "ash/common/wm/window_animation_types.h"
10 #include "ash/common/wm/window_parenting_utils.h" 8 #include "ash/common/wm/window_parenting_utils.h"
11 #include "ash/common/wm/window_positioning_utils.h" 9 #include "ash/common/wm/window_positioning_utils.h"
12 #include "ash/common/wm/window_state.h" 10 #include "ash/common/wm/window_state.h"
13 #include "ash/common/wm/window_state_delegate.h" 11 #include "ash/common/wm/window_state_delegate.h"
14 #include "ash/common/wm/window_state_util.h" 12 #include "ash/common/wm/window_state_util.h"
15 #include "ash/common/wm/wm_event.h" 13 #include "ash/common/wm/wm_event.h"
16 #include "ash/common/wm/wm_screen_util.h" 14 #include "ash/common/wm/wm_screen_util.h"
17 #include "ash/common/wm_shell.h" 15 #include "ash/common/wm_shell.h"
18 #include "ash/common/wm_window.h" 16 #include "ash/common/wm_window.h"
19 #include "ash/public/cpp/shell_window_ids.h" 17 #include "ash/public/cpp/shell_window_ids.h"
20 #include "ash/root_window_controller.h" 18 #include "ash/root_window_controller.h"
21 #include "ui/display/display.h" 19 #include "ui/display/display.h"
22 #include "ui/display/screen.h" 20 #include "ui/display/screen.h"
23 21
24 namespace ash { 22 namespace ash {
25 namespace wm { 23 namespace wm {
26 namespace { 24 namespace {
27 25
28 // This specifies how much percent (30%) of a window rect 26 // This specifies how much percent (30%) of a window rect
29 // must be visible when the window is added to the workspace. 27 // must be visible when the window is added to the workspace.
30 const float kMinimumPercentOnScreenArea = 0.3f; 28 const float kMinimumPercentOnScreenArea = 0.3f;
31 29
32 // When a window that has restore bounds at least as large as a work area is 30 // When a window that has restore bounds at least as large as a work area is
33 // unmaximized, inset the bounds slightly so that they are not exactly the same. 31 // unmaximized, inset the bounds slightly so that they are not exactly the same.
34 // This makes it easier to resize the window. 32 // This makes it easier to resize the window.
35 const int kMaximizedWindowInset = 10; // DIPs. 33 const int kMaximizedWindowInset = 10; // DIPs.
36 34
37 bool IsMinimizedWindowState(const WindowStateType state_type) { 35 bool IsMinimizedWindowState(const WindowStateType state_type) {
38 return state_type == WINDOW_STATE_TYPE_MINIMIZED || 36 return state_type == WINDOW_STATE_TYPE_MINIMIZED;
39 state_type == WINDOW_STATE_TYPE_DOCKED_MINIMIZED;
40 } 37 }
41 38
42 void MoveToDisplayForRestore(WindowState* window_state) { 39 void MoveToDisplayForRestore(WindowState* window_state) {
43 if (!window_state->HasRestoreBounds()) 40 if (!window_state->HasRestoreBounds())
44 return; 41 return;
45 const gfx::Rect restore_bounds = window_state->GetRestoreBoundsInScreen(); 42 const gfx::Rect restore_bounds = window_state->GetRestoreBoundsInScreen();
46 43
47 // Move only if the restore bounds is outside of 44 // Move only if the restore bounds is outside of
48 // the display. There is no information about in which 45 // the display. There is no information about in which
49 // display it should be restored, so this is best guess. 46 // display it should be restored, so this is best guess.
50 // TODO(oshima): Restore information should contain the 47 // TODO(oshima): Restore information should contain the
51 // work area information like WindowResizer does for the 48 // work area information like WindowResizer does for the
52 // last window location. 49 // last window location.
53 gfx::Rect display_area = 50 gfx::Rect display_area =
54 window_state->window()->GetDisplayNearestWindow().bounds(); 51 window_state->window()->GetDisplayNearestWindow().bounds();
55 52
56 if (!display_area.Intersects(restore_bounds)) { 53 if (!display_area.Intersects(restore_bounds)) {
57 const display::Display& display = 54 const display::Display& display =
58 display::Screen::GetScreen()->GetDisplayMatching(restore_bounds); 55 display::Screen::GetScreen()->GetDisplayMatching(restore_bounds);
59 WmShell* shell = window_state->window()->GetShell(); 56 WmShell* shell = window_state->window()->GetShell();
60 WmWindow* new_root = shell->GetRootWindowForDisplayId(display.id()); 57 WmWindow* new_root = shell->GetRootWindowForDisplayId(display.id());
61 if (new_root != window_state->window()->GetRootWindow()) { 58 if (new_root != window_state->window()->GetRootWindow()) {
62 WmWindow* new_container = new_root->GetChildByShellWindowId( 59 WmWindow* new_container = new_root->GetChildByShellWindowId(
63 window_state->window()->GetParent()->GetShellWindowId()); 60 window_state->window()->GetParent()->GetShellWindowId());
64 new_container->AddChild(window_state->window()); 61 new_container->AddChild(window_state->window());
65 } 62 }
66 } 63 }
67 } 64 }
68 65
69 DockedWindowLayoutManager* GetDockedWindowLayoutManager(WmShell* shell) {
70 return DockedWindowLayoutManager::Get(shell->GetActiveWindow());
71 }
72
73 class ScopedPreferredAlignmentResetter {
74 public:
75 ScopedPreferredAlignmentResetter(DockedAlignment dock_alignment,
76 DockedWindowLayoutManager* dock_layout)
77 : docked_window_layout_manager_(dock_layout) {
78 docked_window_layout_manager_->set_preferred_alignment(dock_alignment);
79 }
80 ~ScopedPreferredAlignmentResetter() {
81 docked_window_layout_manager_->set_preferred_alignment(
82 DOCKED_ALIGNMENT_NONE);
83 }
84
85 private:
86 DockedWindowLayoutManager* docked_window_layout_manager_;
87
88 DISALLOW_COPY_AND_ASSIGN(ScopedPreferredAlignmentResetter);
89 };
90
91 class ScopedDockedLayoutEventSourceResetter {
92 public:
93 ScopedDockedLayoutEventSourceResetter(DockedWindowLayoutManager* dock_layout)
94 : docked_window_layout_manager_(dock_layout) {
95 docked_window_layout_manager_->set_event_source(
96 DOCKED_ACTION_SOURCE_KEYBOARD);
97 }
98 ~ScopedDockedLayoutEventSourceResetter() {
99 docked_window_layout_manager_->set_event_source(
100 DOCKED_ACTION_SOURCE_UNKNOWN);
101 }
102
103 private:
104 DockedWindowLayoutManager* docked_window_layout_manager_;
105
106 DISALLOW_COPY_AND_ASSIGN(ScopedDockedLayoutEventSourceResetter);
107 };
108
109 void CycleSnap(WindowState* window_state, WMEventType event) { 66 void CycleSnap(WindowState* window_state, WMEventType event) {
110 DCHECK(!ash::switches::DockedWindowsEnabled());
111
112 wm::WindowStateType desired_snap_state = 67 wm::WindowStateType desired_snap_state =
113 event == WM_EVENT_CYCLE_SNAP_DOCK_LEFT 68 event == WM_EVENT_CYCLE_SNAP_LEFT ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
114 ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED 69 : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED;
115 : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED;
116 70
117 if (window_state->CanSnap() && 71 if (window_state->CanSnap() &&
118 window_state->GetStateType() != desired_snap_state && 72 window_state->GetStateType() != desired_snap_state &&
119 window_state->window()->GetType() != ui::wm::WINDOW_TYPE_PANEL) { 73 window_state->window()->GetType() != ui::wm::WINDOW_TYPE_PANEL) {
120 const wm::WMEvent event(desired_snap_state == 74 const wm::WMEvent event(desired_snap_state ==
121 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED 75 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
122 ? wm::WM_EVENT_SNAP_LEFT 76 ? wm::WM_EVENT_SNAP_LEFT
123 : wm::WM_EVENT_SNAP_RIGHT); 77 : wm::WM_EVENT_SNAP_RIGHT);
124 window_state->OnWMEvent(&event); 78 window_state->OnWMEvent(&event);
125 return; 79 return;
126 } 80 }
127 81
128 if (window_state->IsSnapped()) { 82 if (window_state->IsSnapped()) {
129 window_state->Restore(); 83 window_state->Restore();
130 return; 84 return;
131 } 85 }
132 window_state->window()->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); 86 window_state->window()->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
133 } 87 }
134 88
135 void CycleSnapDock(WindowState* window_state, WMEventType event) {
136 DCHECK(ash::switches::DockedWindowsEnabled());
137
138 DockedWindowLayoutManager* dock_layout =
139 GetDockedWindowLayoutManager(window_state->window()->GetShell());
140 wm::WindowStateType desired_snap_state =
141 event == WM_EVENT_CYCLE_SNAP_DOCK_LEFT
142 ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
143 : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED;
144 DockedAlignment desired_dock_alignment =
145 event == WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? DOCKED_ALIGNMENT_LEFT
146 : DOCKED_ALIGNMENT_RIGHT;
147 DockedAlignment current_dock_alignment =
148 dock_layout ? dock_layout->CalculateAlignment() : DOCKED_ALIGNMENT_NONE;
149
150 if (!window_state->IsDocked() ||
151 (current_dock_alignment != DOCKED_ALIGNMENT_NONE &&
152 current_dock_alignment != desired_dock_alignment)) {
153 if (window_state->CanSnap() &&
154 window_state->GetStateType() != desired_snap_state &&
155 window_state->window()->GetType() != ui::wm::WINDOW_TYPE_PANEL) {
156 const wm::WMEvent event(desired_snap_state ==
157 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
158 ? wm::WM_EVENT_SNAP_LEFT
159 : wm::WM_EVENT_SNAP_RIGHT);
160 window_state->OnWMEvent(&event);
161 return;
162 }
163
164 if (dock_layout &&
165 dock_layout->CanDockWindow(window_state->window(),
166 desired_dock_alignment)) {
167 if (window_state->IsDocked()) {
168 dock_layout->MaybeSetDesiredDockedAlignment(desired_dock_alignment);
169 return;
170 }
171
172 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout);
173 ScopedPreferredAlignmentResetter alignmentResetter(desired_dock_alignment,
174 dock_layout);
175 const wm::WMEvent event(wm::WM_EVENT_DOCK);
176 window_state->OnWMEvent(&event);
177 return;
178 }
179 }
180
181 if (window_state->IsDocked() || window_state->IsSnapped()) {
182 ScopedDockedLayoutEventSourceResetter event_source_resetter(dock_layout);
183 window_state->Restore();
184 return;
185 }
186 window_state->window()->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
187 }
188
189 } // namespace 89 } // namespace
190 90
191 DefaultState::DefaultState(WindowStateType initial_state_type) 91 DefaultState::DefaultState(WindowStateType initial_state_type)
192 : state_type_(initial_state_type), stored_window_state_(nullptr) {} 92 : state_type_(initial_state_type), stored_window_state_(nullptr) {}
193 DefaultState::~DefaultState() {} 93 DefaultState::~DefaultState() {}
194 94
195 void DefaultState::OnWMEvent(WindowState* window_state, const WMEvent* event) { 95 void DefaultState::OnWMEvent(WindowState* window_state, const WMEvent* event) {
196 if (ProcessWorkspaceEvents(window_state, event)) 96 if (ProcessWorkspaceEvents(window_state, event))
197 return; 97 return;
198 98
199 // Do not change the PINNED window state if this is not unpin event. 99 // Do not change the PINNED window state if this is not unpin event.
200 if (window_state->IsTrustedPinned() && event->type() != WM_EVENT_NORMAL) 100 if (window_state->IsTrustedPinned() && event->type() != WM_EVENT_NORMAL)
201 return; 101 return;
202 102
203 if (ProcessCompoundEvents(window_state, event)) 103 if (ProcessCompoundEvents(window_state, event))
204 return; 104 return;
205 105
206 WindowStateType current_state_type = window_state->GetStateType(); 106 WindowStateType current_state_type = window_state->GetStateType();
207 WindowStateType next_state_type = WINDOW_STATE_TYPE_NORMAL; 107 WindowStateType next_state_type = WINDOW_STATE_TYPE_NORMAL;
208 switch (event->type()) { 108 switch (event->type()) {
209 case WM_EVENT_NORMAL: 109 case WM_EVENT_NORMAL:
210 next_state_type = current_state_type == WINDOW_STATE_TYPE_DOCKED_MINIMIZED 110 next_state_type = WINDOW_STATE_TYPE_NORMAL;
211 ? WINDOW_STATE_TYPE_DOCKED
212 : WINDOW_STATE_TYPE_NORMAL;
213 break; 111 break;
214 case WM_EVENT_MAXIMIZE: 112 case WM_EVENT_MAXIMIZE:
215 next_state_type = WINDOW_STATE_TYPE_MAXIMIZED; 113 next_state_type = WINDOW_STATE_TYPE_MAXIMIZED;
216 break; 114 break;
217 case WM_EVENT_MINIMIZE: 115 case WM_EVENT_MINIMIZE:
218 next_state_type = current_state_type == WINDOW_STATE_TYPE_DOCKED 116 next_state_type = WINDOW_STATE_TYPE_MINIMIZED;
219 ? WINDOW_STATE_TYPE_DOCKED_MINIMIZED
220 : WINDOW_STATE_TYPE_MINIMIZED;
221 break; 117 break;
222 case WM_EVENT_FULLSCREEN: 118 case WM_EVENT_FULLSCREEN:
223 next_state_type = WINDOW_STATE_TYPE_FULLSCREEN; 119 next_state_type = WINDOW_STATE_TYPE_FULLSCREEN;
224 break; 120 break;
225 case WM_EVENT_SNAP_LEFT: 121 case WM_EVENT_SNAP_LEFT:
226 next_state_type = WINDOW_STATE_TYPE_LEFT_SNAPPED; 122 next_state_type = WINDOW_STATE_TYPE_LEFT_SNAPPED;
227 break; 123 break;
228 case WM_EVENT_SNAP_RIGHT: 124 case WM_EVENT_SNAP_RIGHT:
229 next_state_type = WINDOW_STATE_TYPE_RIGHT_SNAPPED; 125 next_state_type = WINDOW_STATE_TYPE_RIGHT_SNAPPED;
230 break; 126 break;
231 case WM_EVENT_DOCK:
232 next_state_type = WINDOW_STATE_TYPE_DOCKED;
233 break;
234 case WM_EVENT_SET_BOUNDS: 127 case WM_EVENT_SET_BOUNDS:
235 SetBounds(window_state, static_cast<const SetBoundsEvent*>(event)); 128 SetBounds(window_state, static_cast<const SetBoundsEvent*>(event));
236 return; 129 return;
237 case WM_EVENT_SHOW_INACTIVE: 130 case WM_EVENT_SHOW_INACTIVE:
238 next_state_type = WINDOW_STATE_TYPE_INACTIVE; 131 next_state_type = WINDOW_STATE_TYPE_INACTIVE;
239 break; 132 break;
240 case WM_EVENT_PIN: 133 case WM_EVENT_PIN:
241 case WM_EVENT_TRUSTED_PIN: 134 case WM_EVENT_TRUSTED_PIN:
242 // If there already is a pinned window, it is not allowed to set it 135 // If there already is a pinned window, it is not allowed to set it
243 // to this window. 136 // to this window.
244 // TODO(hidehiko): If a system modal window is openening, the pinning 137 // TODO(hidehiko): If a system modal window is openening, the pinning
245 // probably should fail. 138 // probably should fail.
246 if (WmShell::Get()->IsPinned()) { 139 if (WmShell::Get()->IsPinned()) {
247 LOG(ERROR) << "An PIN event will be failed since another window is " 140 LOG(ERROR) << "An PIN event will be failed since another window is "
248 << "already in pinned mode."; 141 << "already in pinned mode.";
249 next_state_type = current_state_type; 142 next_state_type = current_state_type;
250 } else { 143 } else {
251 next_state_type = event->type() == WM_EVENT_PIN 144 next_state_type = event->type() == WM_EVENT_PIN
252 ? WINDOW_STATE_TYPE_PINNED 145 ? WINDOW_STATE_TYPE_PINNED
253 : WINDOW_STATE_TYPE_TRUSTED_PINNED; 146 : WINDOW_STATE_TYPE_TRUSTED_PINNED;
254 } 147 }
255 break; 148 break;
256 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: 149 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
257 case WM_EVENT_TOGGLE_MAXIMIZE: 150 case WM_EVENT_TOGGLE_MAXIMIZE:
258 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: 151 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
259 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: 152 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
260 case WM_EVENT_TOGGLE_FULLSCREEN: 153 case WM_EVENT_TOGGLE_FULLSCREEN:
261 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT: 154 case WM_EVENT_CYCLE_SNAP_LEFT:
262 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: 155 case WM_EVENT_CYCLE_SNAP_RIGHT:
263 case WM_EVENT_CENTER: 156 case WM_EVENT_CENTER:
264 NOTREACHED() << "Compound event should not reach here:" << event; 157 NOTREACHED() << "Compound event should not reach here:" << event;
265 return; 158 return;
266 case WM_EVENT_ADDED_TO_WORKSPACE: 159 case WM_EVENT_ADDED_TO_WORKSPACE:
267 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: 160 case WM_EVENT_WORKAREA_BOUNDS_CHANGED:
268 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: 161 case WM_EVENT_DISPLAY_BOUNDS_CHANGED:
269 NOTREACHED() << "Workspace event should not reach here:" << event; 162 NOTREACHED() << "Workspace event should not reach here:" << event;
270 return; 163 return;
271 } 164 }
272 165
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 297 }
405 298
406 window_state->SetRestoreBoundsInParent(restore_bounds); 299 window_state->SetRestoreBoundsInParent(restore_bounds);
407 window->SetBounds(new_bounds); 300 window->SetBounds(new_bounds);
408 } 301 }
409 return true; 302 return true;
410 } 303 }
411 case WM_EVENT_TOGGLE_FULLSCREEN: 304 case WM_EVENT_TOGGLE_FULLSCREEN:
412 ToggleFullScreen(window_state, window_state->delegate()); 305 ToggleFullScreen(window_state, window_state->delegate());
413 return true; 306 return true;
414 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT: 307 case WM_EVENT_CYCLE_SNAP_LEFT:
415 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: 308 case WM_EVENT_CYCLE_SNAP_RIGHT:
416 if (ash::switches::DockedWindowsEnabled()) 309 CycleSnap(window_state, event->type());
417 CycleSnapDock(window_state, event->type());
418 else
419 CycleSnap(window_state, event->type());
420 return true; 310 return true;
421 case WM_EVENT_CENTER: 311 case WM_EVENT_CENTER:
422 CenterWindow(window_state); 312 CenterWindow(window_state);
423 return true; 313 return true;
424 case WM_EVENT_NORMAL: 314 case WM_EVENT_NORMAL:
425 case WM_EVENT_MAXIMIZE: 315 case WM_EVENT_MAXIMIZE:
426 case WM_EVENT_MINIMIZE: 316 case WM_EVENT_MINIMIZE:
427 case WM_EVENT_FULLSCREEN: 317 case WM_EVENT_FULLSCREEN:
428 case WM_EVENT_PIN: 318 case WM_EVENT_PIN:
429 case WM_EVENT_TRUSTED_PIN: 319 case WM_EVENT_TRUSTED_PIN:
430 case WM_EVENT_SNAP_LEFT: 320 case WM_EVENT_SNAP_LEFT:
431 case WM_EVENT_SNAP_RIGHT: 321 case WM_EVENT_SNAP_RIGHT:
432 case WM_EVENT_SET_BOUNDS: 322 case WM_EVENT_SET_BOUNDS:
433 case WM_EVENT_SHOW_INACTIVE: 323 case WM_EVENT_SHOW_INACTIVE:
434 case WM_EVENT_DOCK:
435 break; 324 break;
436 case WM_EVENT_ADDED_TO_WORKSPACE: 325 case WM_EVENT_ADDED_TO_WORKSPACE:
437 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: 326 case WM_EVENT_WORKAREA_BOUNDS_CHANGED:
438 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: 327 case WM_EVENT_DISPLAY_BOUNDS_CHANGED:
439 NOTREACHED() << "Workspace event should not reach here:" << event; 328 NOTREACHED() << "Workspace event should not reach here:" << event;
440 break; 329 break;
441 } 330 }
442 return false; 331 return false;
443 } 332 }
444 333
(...skipping 19 matching lines...) Expand all
464 if (bounds.IsEmpty()) 353 if (bounds.IsEmpty())
465 return true; 354 return true;
466 355
467 // Only windows of type WINDOW_TYPE_NORMAL or WINDOW_TYPE_PANEL need to be 356 // Only windows of type WINDOW_TYPE_NORMAL or WINDOW_TYPE_PANEL need to be
468 // adjusted to have minimum visibility, because they are positioned by the 357 // adjusted to have minimum visibility, because they are positioned by the
469 // user and user should always be able to interact with them. Other 358 // user and user should always be able to interact with them. Other
470 // windows are positioned programmatically. 359 // windows are positioned programmatically.
471 if (!window_state->IsUserPositionable()) 360 if (!window_state->IsUserPositionable())
472 return true; 361 return true;
473 362
474 // Use entire display instead of workarea because the workarea can 363 // Use entire display instead of workarea. The logic ensures 30%
475 // be further shrunk by the docked area. The logic ensures 30%
476 // visibility which should be enough to see where the window gets 364 // visibility which should be enough to see where the window gets
477 // moved. 365 // moved.
478 gfx::Rect display_area = GetDisplayBoundsInParent(window); 366 gfx::Rect display_area = GetDisplayBoundsInParent(window);
479 int min_width = bounds.width() * wm::kMinimumPercentOnScreenArea; 367 int min_width = bounds.width() * wm::kMinimumPercentOnScreenArea;
480 int min_height = bounds.height() * wm::kMinimumPercentOnScreenArea; 368 int min_height = bounds.height() * wm::kMinimumPercentOnScreenArea;
481 wm::AdjustBoundsToEnsureWindowVisibility(display_area, min_width, 369 wm::AdjustBoundsToEnsureWindowVisibility(display_area, min_width,
482 min_height, &bounds); 370 min_height, &bounds);
483 window_state->AdjustSnappedBounds(&bounds); 371 window_state->AdjustSnappedBounds(&bounds);
484 if (window->GetBounds() != bounds) 372 if (window->GetBounds() != bounds)
485 window_state->SetBoundsConstrained(bounds); 373 window_state->SetBoundsConstrained(bounds);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 window_state->AdjustSnappedBounds(&bounds); 413 window_state->AdjustSnappedBounds(&bounds);
526 if (window_state->window()->GetTargetBounds() != bounds) 414 if (window_state->window()->GetTargetBounds() != bounds)
527 window_state->SetBoundsDirectAnimated(bounds); 415 window_state->SetBoundsDirectAnimated(bounds);
528 return true; 416 return true;
529 } 417 }
530 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: 418 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION:
531 case WM_EVENT_TOGGLE_MAXIMIZE: 419 case WM_EVENT_TOGGLE_MAXIMIZE:
532 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: 420 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE:
533 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: 421 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE:
534 case WM_EVENT_TOGGLE_FULLSCREEN: 422 case WM_EVENT_TOGGLE_FULLSCREEN:
535 case WM_EVENT_CYCLE_SNAP_DOCK_LEFT: 423 case WM_EVENT_CYCLE_SNAP_LEFT:
536 case WM_EVENT_CYCLE_SNAP_DOCK_RIGHT: 424 case WM_EVENT_CYCLE_SNAP_RIGHT:
537 case WM_EVENT_CENTER: 425 case WM_EVENT_CENTER:
538 case WM_EVENT_NORMAL: 426 case WM_EVENT_NORMAL:
539 case WM_EVENT_MAXIMIZE: 427 case WM_EVENT_MAXIMIZE:
540 case WM_EVENT_MINIMIZE: 428 case WM_EVENT_MINIMIZE:
541 case WM_EVENT_FULLSCREEN: 429 case WM_EVENT_FULLSCREEN:
542 case WM_EVENT_PIN: 430 case WM_EVENT_PIN:
543 case WM_EVENT_TRUSTED_PIN: 431 case WM_EVENT_TRUSTED_PIN:
544 case WM_EVENT_SNAP_LEFT: 432 case WM_EVENT_SNAP_LEFT:
545 case WM_EVENT_SNAP_RIGHT: 433 case WM_EVENT_SNAP_RIGHT:
546 case WM_EVENT_SET_BOUNDS: 434 case WM_EVENT_SET_BOUNDS:
547 case WM_EVENT_SHOW_INACTIVE: 435 case WM_EVENT_SHOW_INACTIVE:
548 case WM_EVENT_DOCK:
549 break; 436 break;
550 } 437 }
551 return false; 438 return false;
552 } 439 }
553 440
554 // static 441 // static
555 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) { 442 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) {
556 DCHECK(!window_state->is_dragged()); 443 DCHECK(!window_state->is_dragged());
557 if (window_state->IsMaximized()) { 444 if (window_state->IsMaximized()) {
558 window_state->SetBoundsDirect( 445 window_state->SetBoundsDirect(
559 GetMaximizedWindowBoundsInParent(window_state->window())); 446 GetMaximizedWindowBoundsInParent(window_state->window()));
560 return true; 447 return true;
561 } 448 }
562 if (window_state->IsFullscreen()) { 449 if (window_state->IsFullscreen()) {
563 window_state->SetBoundsDirect( 450 window_state->SetBoundsDirect(
564 GetDisplayBoundsInParent(window_state->window())); 451 GetDisplayBoundsInParent(window_state->window()));
565 return true; 452 return true;
566 } 453 }
567 return false; 454 return false;
568 } 455 }
569 456
570 // static 457 // static
571 void DefaultState::SetBounds(WindowState* window_state, 458 void DefaultState::SetBounds(WindowState* window_state,
572 const SetBoundsEvent* event) { 459 const SetBoundsEvent* event) {
573 if (window_state->is_dragged()) { 460 if (window_state->is_dragged()) {
574 // TODO(oshima|varkha): This may be no longer needed, as the dragging 461 // TODO(oshima|varkha): Is this still needed? crbug.com/485612.
575 // happens in docked window container. crbug.com/485612.
576 window_state->SetBoundsDirect(event->requested_bounds()); 462 window_state->SetBoundsDirect(event->requested_bounds());
577 } else if (window_state->IsSnapped()) { 463 } else if (window_state->IsSnapped()) {
578 gfx::Rect work_area_in_parent = 464 gfx::Rect work_area_in_parent =
579 GetDisplayWorkAreaBoundsInParent(window_state->window()); 465 GetDisplayWorkAreaBoundsInParent(window_state->window());
580 gfx::Rect child_bounds(event->requested_bounds()); 466 gfx::Rect child_bounds(event->requested_bounds());
581 wm::AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); 467 wm::AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds);
582 window_state->AdjustSnappedBounds(&child_bounds); 468 window_state->AdjustSnappedBounds(&child_bounds);
583 window_state->SetBoundsDirect(child_bounds); 469 window_state->SetBoundsDirect(child_bounds);
584 } else if (!SetMaximizedOrFullscreenBounds(window_state) || 470 } else if (!SetMaximizedOrFullscreenBounds(window_state) ||
585 window_state->allow_set_bounds_in_maximized()) { 471 window_state->allow_set_bounds_in_maximized()) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 WmWindow* window = window_state->window(); 572 WmWindow* window = window_state->window();
687 gfx::Rect bounds_in_parent; 573 gfx::Rect bounds_in_parent;
688 switch (state_type_) { 574 switch (state_type_) {
689 case WINDOW_STATE_TYPE_LEFT_SNAPPED: 575 case WINDOW_STATE_TYPE_LEFT_SNAPPED:
690 case WINDOW_STATE_TYPE_RIGHT_SNAPPED: 576 case WINDOW_STATE_TYPE_RIGHT_SNAPPED:
691 bounds_in_parent = 577 bounds_in_parent =
692 state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED 578 state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED
693 ? GetDefaultLeftSnappedWindowBoundsInParent(window) 579 ? GetDefaultLeftSnappedWindowBoundsInParent(window)
694 : GetDefaultRightSnappedWindowBoundsInParent(window); 580 : GetDefaultRightSnappedWindowBoundsInParent(window);
695 break; 581 break;
696 case WINDOW_STATE_TYPE_DOCKED: { 582
697 // TODO(afakhry): Remove in M58.
698 DCHECK(ash::switches::DockedWindowsEnabled());
699 if (window->GetParent()->GetShellWindowId() !=
700 kShellWindowId_DockedContainer) {
701 WmWindow* docked_container =
702 window->GetRootWindow()->GetChildByShellWindowId(
703 kShellWindowId_DockedContainer);
704 ReparentChildWithTransientChildren(window->aura_window(),
705 window->aura_window()->parent(),
706 docked_container->aura_window());
707 }
708 // Return early because we don't want to update the bounds of the
709 // window below; as the bounds are managed by the dock layout.
710 return;
711 }
712 case WINDOW_STATE_TYPE_DEFAULT: 583 case WINDOW_STATE_TYPE_DEFAULT:
713 case WINDOW_STATE_TYPE_NORMAL: { 584 case WINDOW_STATE_TYPE_NORMAL: {
714 gfx::Rect work_area_in_parent = GetDisplayWorkAreaBoundsInParent(window); 585 gfx::Rect work_area_in_parent = GetDisplayWorkAreaBoundsInParent(window);
715 if (window_state->HasRestoreBounds()) { 586 if (window_state->HasRestoreBounds()) {
716 bounds_in_parent = window_state->GetRestoreBoundsInParent(); 587 bounds_in_parent = window_state->GetRestoreBoundsInParent();
717 // Check if the |window|'s restored size is bigger than the working area 588 // Check if the |window|'s restored size is bigger than the working area
718 // This may happen if a window was resized to maximized bounds or if the 589 // This may happen if a window was resized to maximized bounds or if the
719 // display resolution changed while the window was maximized. 590 // display resolution changed while the window was maximized.
720 if (previous_state_type == WINDOW_STATE_TYPE_MAXIMIZED && 591 if (previous_state_type == WINDOW_STATE_TYPE_MAXIMIZED &&
721 bounds_in_parent.width() >= work_area_in_parent.width() && 592 bounds_in_parent.width() >= work_area_in_parent.width() &&
(...skipping 18 matching lines...) Expand all
740 case WINDOW_STATE_TYPE_MAXIMIZED: 611 case WINDOW_STATE_TYPE_MAXIMIZED:
741 bounds_in_parent = GetMaximizedWindowBoundsInParent(window); 612 bounds_in_parent = GetMaximizedWindowBoundsInParent(window);
742 break; 613 break;
743 614
744 case WINDOW_STATE_TYPE_FULLSCREEN: 615 case WINDOW_STATE_TYPE_FULLSCREEN:
745 case WINDOW_STATE_TYPE_PINNED: 616 case WINDOW_STATE_TYPE_PINNED:
746 case WINDOW_STATE_TYPE_TRUSTED_PINNED: 617 case WINDOW_STATE_TYPE_TRUSTED_PINNED:
747 bounds_in_parent = GetDisplayBoundsInParent(window); 618 bounds_in_parent = GetDisplayBoundsInParent(window);
748 break; 619 break;
749 620
750 case WINDOW_STATE_TYPE_DOCKED_MINIMIZED:
751 case WINDOW_STATE_TYPE_MINIMIZED: 621 case WINDOW_STATE_TYPE_MINIMIZED:
752 break; 622 break;
753 case WINDOW_STATE_TYPE_INACTIVE: 623 case WINDOW_STATE_TYPE_INACTIVE:
754 case WINDOW_STATE_TYPE_END: 624 case WINDOW_STATE_TYPE_END:
755 case WINDOW_STATE_TYPE_AUTO_POSITIONED: 625 case WINDOW_STATE_TYPE_AUTO_POSITIONED:
756 return; 626 return;
757 } 627 }
758 628
759 if (!window_state->IsMinimized()) { 629 if (!window_state->IsMinimized()) {
760 if (IsMinimizedWindowState(previous_state_type) || 630 if (IsMinimizedWindowState(previous_state_type) ||
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window); 685 gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window);
816 center_in_parent.ClampToCenteredSize(window->GetBounds().size()); 686 center_in_parent.ClampToCenteredSize(window->GetBounds().size());
817 window_state->SetBoundsDirectAnimated(center_in_parent); 687 window_state->SetBoundsDirectAnimated(center_in_parent);
818 } 688 }
819 // Centering window is treated as if a user moved and resized the window. 689 // Centering window is treated as if a user moved and resized the window.
820 window_state->set_bounds_changed_by_user(true); 690 window_state->set_bounds_changed_by_user(true);
821 } 691 }
822 692
823 } // namespace wm 693 } // namespace wm
824 } // namespace ash 694 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_window_watcher_unittest.cc ('k') | ash/common/wm/dock/dock_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698