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

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

Issue 1921353002: Moves handful of files to ash/wm/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shell_ids
Patch Set: merge to trunk Created 4 years, 8 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/common/default_state.h ('k') | ash/wm/common/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/wm/default_state.h" 5 #include "ash/wm/common/default_state.h"
6 6
7 #include "ash/shell_window_ids.h" 7 #include "ash/wm/common/dock/docked_window_layout_manager.h"
8 #include "ash/wm/common/window_animation_types.h" 8 #include "ash/wm/common/window_animation_types.h"
9 #include "ash/wm/common/window_parenting_utils.h" 9 #include "ash/wm/common/window_parenting_utils.h"
10 #include "ash/wm/common/window_positioning_utils.h" 10 #include "ash/wm/common/window_positioning_utils.h"
11 #include "ash/wm/common/window_state.h"
12 #include "ash/wm/common/window_state_delegate.h"
11 #include "ash/wm/common/window_state_util.h" 13 #include "ash/wm/common/window_state_util.h"
12 #include "ash/wm/common/wm_event.h" 14 #include "ash/wm/common/wm_event.h"
13 #include "ash/wm/common/wm_globals.h" 15 #include "ash/wm/common/wm_globals.h"
14 #include "ash/wm/common/wm_root_window_controller.h" 16 #include "ash/wm/common/wm_root_window_controller.h"
15 #include "ash/wm/common/wm_screen_util.h" 17 #include "ash/wm/common/wm_screen_util.h"
18 #include "ash/wm/common/wm_shell_window_ids.h"
16 #include "ash/wm/common/wm_window.h" 19 #include "ash/wm/common/wm_window.h"
17 #include "ash/wm/dock/docked_window_layout_manager.h"
18 #include "ash/wm/window_state.h"
19 #include "ash/wm/window_state_delegate.h"
20 #include "ui/gfx/display.h" 20 #include "ui/gfx/display.h"
21 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
22 22
23 namespace ash { 23 namespace ash {
24 namespace wm { 24 namespace wm {
25 namespace { 25 namespace {
26 26
27 // This specifies how much percent (30%) of a window rect 27 // This specifies how much percent (30%) of a window rect
28 // must be visible when the window is added to the workspace. 28 // must be visible when the window is added to the workspace.
29 const float kMinimumPercentOnScreenArea = 0.3f; 29 const float kMinimumPercentOnScreenArea = 0.3f;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 private: 102 private:
103 DockedWindowLayoutManager* docked_window_layout_manager_; 103 DockedWindowLayoutManager* docked_window_layout_manager_;
104 104
105 DISALLOW_COPY_AND_ASSIGN(ScopedDockedLayoutEventSourceResetter); 105 DISALLOW_COPY_AND_ASSIGN(ScopedDockedLayoutEventSourceResetter);
106 }; 106 };
107 107
108 void CycleSnapDock(WindowState* window_state, WMEventType event) { 108 void CycleSnapDock(WindowState* window_state, WMEventType event) {
109 DockedWindowLayoutManager* dock_layout = 109 DockedWindowLayoutManager* dock_layout =
110 GetDockedWindowLayoutManager(window_state->window()->GetGlobals()); 110 GetDockedWindowLayoutManager(window_state->window()->GetGlobals());
111 wm::WindowStateType desired_snap_state = event == 111 wm::WindowStateType desired_snap_state =
112 WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED : 112 event == WM_EVENT_CYCLE_SNAP_DOCK_LEFT
113 wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED; 113 ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
114 DockedAlignment desired_dock_alignment = event == 114 : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED;
115 WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? 115 DockedAlignment desired_dock_alignment =
116 DOCKED_ALIGNMENT_LEFT : DOCKED_ALIGNMENT_RIGHT; 116 event == WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? DOCKED_ALIGNMENT_LEFT
117 DockedAlignment current_dock_alignment = dock_layout ? 117 : DOCKED_ALIGNMENT_RIGHT;
118 dock_layout->CalculateAlignment() : DOCKED_ALIGNMENT_NONE; 118 DockedAlignment current_dock_alignment =
119 dock_layout ? dock_layout->CalculateAlignment() : DOCKED_ALIGNMENT_NONE;
119 120
120 if (!window_state->IsDocked() || 121 if (!window_state->IsDocked() ||
121 (current_dock_alignment != DOCKED_ALIGNMENT_NONE && 122 (current_dock_alignment != DOCKED_ALIGNMENT_NONE &&
122 current_dock_alignment != desired_dock_alignment)) { 123 current_dock_alignment != desired_dock_alignment)) {
123 if (window_state->CanSnap() && 124 if (window_state->CanSnap() &&
124 window_state->GetStateType() != desired_snap_state && 125 window_state->GetStateType() != desired_snap_state &&
125 window_state->window()->GetType() != ui::wm::WINDOW_TYPE_PANEL) { 126 window_state->window()->GetType() != ui::wm::WINDOW_TYPE_PANEL) {
126 const wm::WMEvent event(desired_snap_state == 127 const wm::WMEvent event(desired_snap_state ==
127 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ? 128 wm::WINDOW_STATE_TYPE_LEFT_SNAPPED
128 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); 129 ? wm::WM_EVENT_SNAP_LEFT
130 : wm::WM_EVENT_SNAP_RIGHT);
129 window_state->OnWMEvent(&event); 131 window_state->OnWMEvent(&event);
130 return; 132 return;
131 } 133 }
132 134
133 if (dock_layout && 135 if (dock_layout &&
134 dock_layout->CanDockWindow(window_state->window(), 136 dock_layout->CanDockWindow(window_state->window(),
135 desired_dock_alignment)) { 137 desired_dock_alignment)) {
136 if (window_state->IsDocked()) { 138 if (window_state->IsDocked()) {
137 dock_layout->MaybeSetDesiredDockedAlignment(desired_dock_alignment); 139 dock_layout->MaybeSetDesiredDockedAlignment(desired_dock_alignment);
138 return; 140 return;
(...skipping 15 matching lines...) Expand all
154 } 156 }
155 window_state->window()->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); 157 window_state->window()->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE);
156 } 158 }
157 159
158 } // namespace 160 } // namespace
159 161
160 DefaultState::DefaultState(WindowStateType initial_state_type) 162 DefaultState::DefaultState(WindowStateType initial_state_type)
161 : state_type_(initial_state_type), stored_window_state_(nullptr) {} 163 : state_type_(initial_state_type), stored_window_state_(nullptr) {}
162 DefaultState::~DefaultState() {} 164 DefaultState::~DefaultState() {}
163 165
164 void DefaultState::OnWMEvent(WindowState* window_state, 166 void DefaultState::OnWMEvent(WindowState* window_state, const WMEvent* event) {
165 const WMEvent* event) {
166 if (ProcessWorkspaceEvents(window_state, event)) 167 if (ProcessWorkspaceEvents(window_state, event))
167 return; 168 return;
168 169
169 if (ProcessCompoundEvents(window_state, event)) 170 if (ProcessCompoundEvents(window_state, event))
170 return; 171 return;
171 172
172 WindowStateType current_state_type = window_state->GetStateType(); 173 WindowStateType current_state_type = window_state->GetStateType();
173 WindowStateType next_state_type = WINDOW_STATE_TYPE_NORMAL; 174 WindowStateType next_state_type = WINDOW_STATE_TYPE_NORMAL;
174 switch (event->type()) { 175 switch (event->type()) {
175 case WM_EVENT_NORMAL: 176 case WM_EVENT_NORMAL:
176 next_state_type = 177 next_state_type = current_state_type == WINDOW_STATE_TYPE_DOCKED_MINIMIZED
177 current_state_type == WINDOW_STATE_TYPE_DOCKED_MINIMIZED ? 178 ? WINDOW_STATE_TYPE_DOCKED
178 WINDOW_STATE_TYPE_DOCKED : WINDOW_STATE_TYPE_NORMAL; 179 : WINDOW_STATE_TYPE_NORMAL;
179 break; 180 break;
180 case WM_EVENT_MAXIMIZE: 181 case WM_EVENT_MAXIMIZE:
181 next_state_type = WINDOW_STATE_TYPE_MAXIMIZED; 182 next_state_type = WINDOW_STATE_TYPE_MAXIMIZED;
182 break; 183 break;
183 case WM_EVENT_MINIMIZE: 184 case WM_EVENT_MINIMIZE:
184 next_state_type = 185 next_state_type = current_state_type == WINDOW_STATE_TYPE_DOCKED
185 current_state_type == WINDOW_STATE_TYPE_DOCKED ? 186 ? WINDOW_STATE_TYPE_DOCKED_MINIMIZED
186 WINDOW_STATE_TYPE_DOCKED_MINIMIZED : WINDOW_STATE_TYPE_MINIMIZED; 187 : WINDOW_STATE_TYPE_MINIMIZED;
187 break; 188 break;
188 case WM_EVENT_FULLSCREEN: 189 case WM_EVENT_FULLSCREEN:
189 next_state_type = WINDOW_STATE_TYPE_FULLSCREEN; 190 next_state_type = WINDOW_STATE_TYPE_FULLSCREEN;
190 break; 191 break;
191 case WM_EVENT_SNAP_LEFT: 192 case WM_EVENT_SNAP_LEFT:
192 next_state_type = WINDOW_STATE_TYPE_LEFT_SNAPPED; 193 next_state_type = WINDOW_STATE_TYPE_LEFT_SNAPPED;
193 break; 194 break;
194 case WM_EVENT_SNAP_RIGHT: 195 case WM_EVENT_SNAP_RIGHT:
195 next_state_type = WINDOW_STATE_TYPE_RIGHT_SNAPPED; 196 next_state_type = WINDOW_STATE_TYPE_RIGHT_SNAPPED;
196 break; 197 break;
(...skipping 17 matching lines...) Expand all
214 NOTREACHED() << "Compound event should not reach here:" << event; 215 NOTREACHED() << "Compound event should not reach here:" << event;
215 return; 216 return;
216 case WM_EVENT_ADDED_TO_WORKSPACE: 217 case WM_EVENT_ADDED_TO_WORKSPACE:
217 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: 218 case WM_EVENT_WORKAREA_BOUNDS_CHANGED:
218 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: 219 case WM_EVENT_DISPLAY_BOUNDS_CHANGED:
219 NOTREACHED() << "Workspace event should not reach here:" << event; 220 NOTREACHED() << "Workspace event should not reach here:" << event;
220 return; 221 return;
221 } 222 }
222 223
223 if (next_state_type == current_state_type && window_state->IsSnapped()) { 224 if (next_state_type == current_state_type && window_state->IsSnapped()) {
224 gfx::Rect snapped_bounds = event->type() == WM_EVENT_SNAP_LEFT ? 225 gfx::Rect snapped_bounds =
225 GetDefaultLeftSnappedWindowBoundsInParent(window_state->window()) : 226 event->type() == WM_EVENT_SNAP_LEFT
226 GetDefaultRightSnappedWindowBoundsInParent(window_state->window()); 227 ? GetDefaultLeftSnappedWindowBoundsInParent(window_state->window())
228 : GetDefaultRightSnappedWindowBoundsInParent(
229 window_state->window());
227 window_state->SetBoundsDirectAnimated(snapped_bounds); 230 window_state->SetBoundsDirectAnimated(snapped_bounds);
228 return; 231 return;
229 } 232 }
230 233
231 EnterToNextState(window_state, next_state_type); 234 EnterToNextState(window_state, next_state_type);
232 } 235 }
233 236
234 WindowStateType DefaultState::GetType() const { 237 WindowStateType DefaultState::GetType() const {
235 return state_type_; 238 return state_type_;
236 } 239 }
237 240
238 void DefaultState::AttachState( 241 void DefaultState::AttachState(WindowState* window_state,
239 WindowState* window_state, 242 WindowState::State* state_in_previous_mode) {
240 WindowState::State* state_in_previous_mode) {
241 DCHECK_EQ(stored_window_state_, window_state); 243 DCHECK_EQ(stored_window_state_, window_state);
242 244
243 ReenterToCurrentState(window_state, state_in_previous_mode); 245 ReenterToCurrentState(window_state, state_in_previous_mode);
244 246
245 // If the display has changed while in the another mode, 247 // If the display has changed while in the another mode,
246 // we need to let windows know the change. 248 // we need to let windows know the change.
247 gfx::Display current_display = 249 gfx::Display current_display =
248 window_state->window()->GetDisplayNearestWindow(); 250 window_state->window()->GetDisplayNearestWindow();
249 if (stored_display_state_.bounds() != current_display.bounds()) { 251 if (stored_display_state_.bounds() != current_display.bounds()) {
250 const WMEvent event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); 252 const WMEvent event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED);
251 window_state->OnWMEvent(&event); 253 window_state->OnWMEvent(&event);
252 } else if (stored_display_state_.work_area() != current_display.work_area()) { 254 } else if (stored_display_state_.work_area() != current_display.work_area()) {
253 const WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); 255 const WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED);
254 window_state->OnWMEvent(&event); 256 window_state->OnWMEvent(&event);
255 } 257 }
256 } 258 }
257 259
258 void DefaultState::DetachState(WindowState* window_state) { 260 void DefaultState::DetachState(WindowState* window_state) {
259 stored_window_state_ = window_state; 261 stored_window_state_ = window_state;
260 stored_bounds_ = window_state->window()->GetBounds(); 262 stored_bounds_ = window_state->window()->GetBounds();
261 stored_restore_bounds_ = window_state->HasRestoreBounds() ? 263 stored_restore_bounds_ = window_state->HasRestoreBounds()
262 window_state->GetRestoreBoundsInParent() : gfx::Rect(); 264 ? window_state->GetRestoreBoundsInParent()
265 : gfx::Rect();
263 // Remember the display state so that in case of the display change 266 // Remember the display state so that in case of the display change
264 // while in the other mode, we can perform necessary action to 267 // while in the other mode, we can perform necessary action to
265 // restore the window state to the proper state for the current 268 // restore the window state to the proper state for the current
266 // display. 269 // display.
267 stored_display_state_ = window_state->window()->GetDisplayNearestWindow(); 270 stored_display_state_ = window_state->window()->GetDisplayNearestWindow();
268 } 271 }
269 272
270 // static 273 // static
271 bool DefaultState::ProcessCompoundEvents(WindowState* window_state, 274 bool DefaultState::ProcessCompoundEvents(WindowState* window_state,
272 const WMEvent* event) { 275 const WMEvent* event) {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 WindowStateType previous_state_type = state_type_; 532 WindowStateType previous_state_type = state_type_;
530 state_type_ = next_state_type; 533 state_type_ = next_state_type;
531 534
532 window_state->UpdateWindowShowStateFromStateType(); 535 window_state->UpdateWindowShowStateFromStateType();
533 window_state->NotifyPreStateTypeChange(previous_state_type); 536 window_state->NotifyPreStateTypeChange(previous_state_type);
534 537
535 if (window_state->window()->GetParent()) { 538 if (window_state->window()->GetParent()) {
536 if (!window_state->HasRestoreBounds() && 539 if (!window_state->HasRestoreBounds() &&
537 (previous_state_type == WINDOW_STATE_TYPE_DEFAULT || 540 (previous_state_type == WINDOW_STATE_TYPE_DEFAULT ||
538 previous_state_type == WINDOW_STATE_TYPE_NORMAL) && 541 previous_state_type == WINDOW_STATE_TYPE_NORMAL) &&
539 !window_state->IsMinimized() && 542 !window_state->IsMinimized() && !window_state->IsNormalStateType()) {
540 !window_state->IsNormalStateType()) {
541 window_state->SaveCurrentBoundsForRestore(); 543 window_state->SaveCurrentBoundsForRestore();
542 } 544 }
543 545
544 // When restoring from a minimized state, we want to restore to the 546 // When restoring from a minimized state, we want to restore to the
545 // previous bounds. However, we want to maintain the restore bounds. 547 // previous bounds. However, we want to maintain the restore bounds.
546 // (The restore bounds are set if a user maximized the window in one 548 // (The restore bounds are set if a user maximized the window in one
547 // axis by double clicking the window border for example). 549 // axis by double clicking the window border for example).
548 gfx::Rect restore_bounds_in_screen; 550 gfx::Rect restore_bounds_in_screen;
549 if (previous_state_type == WINDOW_STATE_TYPE_MINIMIZED && 551 if (previous_state_type == WINDOW_STATE_TYPE_MINIMIZED &&
550 window_state->IsNormalStateType() && 552 window_state->IsNormalStateType() && window_state->HasRestoreBounds() &&
551 window_state->HasRestoreBounds() &&
552 !window_state->unminimize_to_restore_bounds()) { 553 !window_state->unminimize_to_restore_bounds()) {
553 restore_bounds_in_screen = window_state->GetRestoreBoundsInScreen(); 554 restore_bounds_in_screen = window_state->GetRestoreBoundsInScreen();
554 window_state->SaveCurrentBoundsForRestore(); 555 window_state->SaveCurrentBoundsForRestore();
555 } 556 }
556 557
557 if (window_state->IsMaximizedOrFullscreen()) 558 if (window_state->IsMaximizedOrFullscreen())
558 MoveToDisplayForRestore(window_state); 559 MoveToDisplayForRestore(window_state);
559 560
560 UpdateBoundsFromState(window_state, previous_state_type); 561 UpdateBoundsFromState(window_state, previous_state_type);
561 562
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window); 727 gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window);
727 center_in_parent.ClampToCenteredSize(window->GetBounds().size()); 728 center_in_parent.ClampToCenteredSize(window->GetBounds().size());
728 window_state->SetBoundsDirectAnimated(center_in_parent); 729 window_state->SetBoundsDirectAnimated(center_in_parent);
729 } 730 }
730 // Centering window is treated as if a user moved and resized the window. 731 // Centering window is treated as if a user moved and resized the window.
731 window_state->set_bounds_changed_by_user(true); 732 window_state->set_bounds_changed_by_user(true);
732 } 733 }
733 734
734 } // namespace wm 735 } // namespace wm
735 } // namespace ash 736 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/common/default_state.h ('k') | ash/wm/common/dock/dock_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698