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

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

Issue 249723002: Fixing problem where applications are not getting centered when created after maximize mode starts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_window_manager_unittest.cc ('k') | no next file » | 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 "ash/display/display_controller.h" 7 #include "ash/display/display_controller.h"
8 #include "ash/screen_util.h" 8 #include "ash/screen_util.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
(...skipping 27 matching lines...) Expand all
38 return workspace_size; 38 return workspace_size;
39 39
40 gfx::Size size = delegate->GetMaximumSize(); 40 gfx::Size size = delegate->GetMaximumSize();
41 if (size.IsEmpty()) 41 if (size.IsEmpty())
42 return workspace_size; 42 return workspace_size;
43 43
44 size.SetToMin(workspace_size); 44 size.SetToMin(workspace_size);
45 return size; 45 return size;
46 } 46 }
47 47
48 // Returns the centered bounds of the given bounds in the work area.
49 gfx::Rect GetCenteredBounds(const gfx::Rect& bounds_in_parent,
50 wm::WindowState* state_object) {
51 gfx::Rect bounds = bounds_in_parent;
52 gfx::Rect work_area_in_parent =
53 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->window());
54 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, &bounds);
55
56 // Center the window over the work area.
57 int x = (work_area_in_parent.width() - bounds.width()) / 2 +
58 work_area_in_parent.x();
59 int y = (work_area_in_parent.height() - bounds.height()) / 2 +
60 work_area_in_parent.y();
oshima 2014/04/24 21:01:25 I think work_area_in_parent.ClampToCenteredSize(b
Mr4D (OOO till 08-26) 2014/04/24 21:42:20 I tried this yesterday. And it did not work. Appar
61
62 bounds.set_origin(gfx::Point(x, y));
63
64 return bounds;
65 }
66
48 // Returns the maximized and centered bounds of a window. 67 // Returns the maximized and centered bounds of a window.
49 gfx::Rect GetMaximizedAndCenteredBounds(wm::WindowState* state_object) { 68 gfx::Rect GetMaximizedAndCenteredBounds(wm::WindowState* state_object) {
50 gfx::Rect bounds_in_parent; 69 gfx::Rect bounds_in_parent;
51 // Make the window as big as possible. 70 // Make the window as big as possible.
52 if (state_object->CanMaximize() || state_object->CanResize()) { 71 if (state_object->CanMaximize() || state_object->CanResize()) {
53 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object)); 72 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object));
54 } else { 73 } else {
55 // We prefer the user given window dimensions over the current windows 74 // We prefer the user given window dimensions over the current windows
56 // dimensions since they are likely to be the result from some other state 75 // dimensions since they are likely to be the result from some other state
57 // object logic. 76 // object logic.
58 if (state_object->HasRestoreBounds()) 77 if (state_object->HasRestoreBounds())
59 bounds_in_parent = state_object->GetRestoreBoundsInParent(); 78 bounds_in_parent = state_object->GetRestoreBoundsInParent();
60 else 79 else
61 bounds_in_parent = state_object->window()->bounds(); 80 bounds_in_parent = state_object->window()->bounds();
62 } 81 }
63 gfx::Rect work_area_in_parent = 82 return GetCenteredBounds(bounds_in_parent, state_object);
64 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->window());
65
66 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent,
67 &bounds_in_parent);
68
69 // Center the window over the work area.
70 int x = (work_area_in_parent.width() - bounds_in_parent.width()) / 2 +
71 work_area_in_parent.x();
72 int y = (work_area_in_parent.height() - bounds_in_parent.height()) / 2 +
73 work_area_in_parent.y();
74
75 bounds_in_parent.set_origin(gfx::Point(x, y));
76
77 return bounds_in_parent;
78 } 83 }
79 84
80 } // namespace 85 } // namespace
81 86
82 // static 87 // static
83 void MaximizeModeWindowState::UpdateWindowPosition( 88 void MaximizeModeWindowState::UpdateWindowPosition(
84 wm::WindowState* window_state, bool animated) { 89 wm::WindowState* window_state, bool animated) {
85 gfx::Rect bounds_in_parent = GetMaximizedAndCenteredBounds(window_state); 90 gfx::Rect bounds_in_parent = GetMaximizedAndCenteredBounds(window_state);
86 91
87 if (bounds_in_parent == window_state->window()->bounds()) 92 if (bounds_in_parent == window_state->window()->bounds())
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED || 146 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED ||
142 window_state->CanResize()) { 147 window_state->CanResize()) {
143 // In case the window is resizable and / or maximized we ignore the 148 // In case the window is resizable and / or maximized we ignore the
144 // requested bounds change and resize to the biggest possible size. 149 // requested bounds change and resize to the biggest possible size.
145 MaximizeOrCenterWindow(window_state, true); 150 MaximizeOrCenterWindow(window_state, true);
146 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED) { 151 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED) {
147 // In all other cases (except for minimized windows) we respect the 152 // In all other cases (except for minimized windows) we respect the
148 // requested bounds and center it to a fully visible area on the screen. 153 // requested bounds and center it to a fully visible area on the screen.
149 gfx::Rect bounds_in_parent = 154 gfx::Rect bounds_in_parent =
150 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); 155 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds();
151 bounds_in_parent.ClampToCenteredSize( 156 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state);
152 ScreenUtil::GetDisplayWorkAreaBoundsInParent( 157 if (bounds_in_parent != window_state->window()->bounds()) {
153 window_state->window()).size()); 158 if (window_state->window()->IsVisible())
oshima 2014/04/24 21:01:25 how this can be not visible (in non minimized mode
Mr4D (OOO till 08-26) 2014/04/24 21:42:20 Multi user mode for example. Before the window get
oshima 2014/04/24 21:57:52 I see. I don't think we do this in normal mode, bu
154 if (bounds_in_parent != window_state->window()->bounds()) 159 window_state->SetBoundsDirectAnimated(bounds_in_parent);
155 window_state->SetBoundsDirectAnimated(bounds_in_parent); 160 else
161 window_state->SetBoundsDirect(bounds_in_parent);
162 }
156 } 163 }
157 break; 164 break;
158 case wm::WM_EVENT_ADDED_TO_WORKSPACE: 165 case wm::WM_EVENT_ADDED_TO_WORKSPACE:
159 MaximizeOrCenterWindow(window_state, true); 166 MaximizeOrCenterWindow(window_state, true);
160 break; 167 break;
161 case wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED: 168 case wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED:
162 case wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED: 169 case wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED:
163 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED) 170 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED)
164 MaximizeOrCenterWindow(window_state, false); 171 MaximizeOrCenterWindow(window_state, false);
165 break; 172 break;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); 241 window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
235 242
236 // Hide the window. 243 // Hide the window.
237 window_state->window()->Hide(); 244 window_state->window()->Hide();
238 // Activate another window. 245 // Activate another window.
239 if (window_state->IsActive()) 246 if (window_state->IsActive())
240 window_state->Deactivate(); 247 window_state->Deactivate();
241 } 248 }
242 249
243 } // namespace ash 250 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/maximize_mode/maximize_mode_window_manager_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698