OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/window_positioner.h" | 5 #include "ash/wm/window_positioner.h" |
6 | 6 |
7 #include "ash/screen_util.h" | 7 #include "ash/screen_util.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_delegate.h" |
9 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
10 #include "ash/wm/mru_window_tracker.h" | 11 #include "ash/wm/mru_window_tracker.h" |
11 #include "ash/wm/window_resizer.h" | 12 #include "ash/wm/window_resizer.h" |
12 #include "ash/wm/window_state.h" | 13 #include "ash/wm/window_state.h" |
13 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
15 #include "ui/aura/window_delegate.h" | 16 #include "ui/aura/window_delegate.h" |
16 #include "ui/aura/window_event_dispatcher.h" | 17 #include "ui/aura/window_event_dispatcher.h" |
17 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
18 #include "ui/compositor/scoped_layer_animation_settings.h" | 19 #include "ui/compositor/scoped_layer_animation_settings.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 } | 240 } |
240 | 241 |
241 // static | 242 // static |
242 void WindowPositioner::GetBoundsAndShowStateForNewWindow( | 243 void WindowPositioner::GetBoundsAndShowStateForNewWindow( |
243 const gfx::Screen* screen, | 244 const gfx::Screen* screen, |
244 const aura::Window* new_window, | 245 const aura::Window* new_window, |
245 bool is_saved_bounds, | 246 bool is_saved_bounds, |
246 ui::WindowShowState show_state_in, | 247 ui::WindowShowState show_state_in, |
247 gfx::Rect* bounds_in_out, | 248 gfx::Rect* bounds_in_out, |
248 ui::WindowShowState* show_state_out) { | 249 ui::WindowShowState* show_state_out) { |
249 | |
250 // Always open new window in the target display. | 250 // Always open new window in the target display. |
251 aura::Window* target = Shell::GetTargetRootWindow(); | 251 aura::Window* target = Shell::GetTargetRootWindow(); |
252 | 252 |
253 aura::Window* top_window = GetReferenceWindow(target, NULL, NULL); | 253 aura::Window* top_window = GetReferenceWindow(target, NULL, NULL); |
254 // Our window should not have any impact if we are already on top. | 254 // Our window should not have any impact if we are already on top. |
255 if (top_window == new_window) | 255 if (top_window == new_window) |
256 top_window = NULL; | 256 top_window = NULL; |
257 | 257 |
258 // If there is no valid other window we take and adjust the passed coordinates | 258 // If there is no valid other window we take and adjust the passed coordinates |
259 // and show state. | 259 // and show state. |
260 if (!top_window) { | 260 if (!top_window) { |
261 gfx::Rect work_area = screen->GetDisplayNearestWindow(target).work_area(); | 261 gfx::Rect work_area = screen->GetDisplayNearestWindow(target).work_area(); |
262 | 262 |
263 bounds_in_out->AdjustToFit(work_area); | 263 bounds_in_out->AdjustToFit(work_area); |
264 // Use adjusted saved bounds, if there is one. | 264 // Use adjusted saved bounds, if there is one. |
265 if (is_saved_bounds) | 265 if (is_saved_bounds) |
266 return; | 266 return; |
267 // When using "small screens" we want to always open in full screen mode. | 267 |
268 if (show_state_in == ui::SHOW_STATE_DEFAULT && (maximize_first_window || | 268 if (show_state_in == ui::SHOW_STATE_DEFAULT) { |
269 (work_area.width() <= GetForceMaximizedWidthLimit() && | 269 const bool maximize_first_window_on_first_run = |
270 (!new_window || !wm::GetWindowState(new_window)->IsFullscreen())))) { | 270 Shell::GetInstance()->delegate()->ForceMaximizeOnFirstRun(); |
271 *show_state_out = ui::SHOW_STATE_MAXIMIZED; | 271 // We want to always open maximized on "small screens" or when policy |
| 272 // tells us to. |
| 273 const bool set_maximized = |
| 274 maximize_first_window || |
| 275 ((work_area.width() <= GetForceMaximizedWidthLimit() || |
| 276 maximize_first_window_on_first_run) && |
| 277 (!new_window || !wm::GetWindowState(new_window)->IsFullscreen())); |
| 278 |
| 279 if (set_maximized) |
| 280 *show_state_out = ui::SHOW_STATE_MAXIMIZED; |
272 } | 281 } |
273 return; | 282 return; |
274 } | 283 } |
| 284 |
275 wm::WindowState* top_window_state = wm::GetWindowState(top_window); | 285 wm::WindowState* top_window_state = wm::GetWindowState(top_window); |
276 bool maximized = top_window_state->IsMaximized(); | 286 bool maximized = top_window_state->IsMaximized(); |
277 // We ignore the saved show state, but look instead for the top level | 287 // We ignore the saved show state, but look instead for the top level |
278 // window's show state. | 288 // window's show state. |
279 if (show_state_in == ui::SHOW_STATE_DEFAULT) { | 289 if (show_state_in == ui::SHOW_STATE_DEFAULT) { |
280 *show_state_out = maximized ? ui::SHOW_STATE_MAXIMIZED : | 290 *show_state_out = maximized ? ui::SHOW_STATE_MAXIMIZED : |
281 ui::SHOW_STATE_DEFAULT; | 291 ui::SHOW_STATE_DEFAULT; |
282 } | 292 } |
283 | 293 |
284 if (maximized) { | 294 if (maximized) { |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 // If the alignment was pushing the window out of the screen, we ignore the | 592 // If the alignment was pushing the window out of the screen, we ignore the |
583 // alignment for that call. | 593 // alignment for that call. |
584 if (abs(pos.right() - work_area.right()) < grid) | 594 if (abs(pos.right() - work_area.right()) < grid) |
585 x = work_area.right() - w; | 595 x = work_area.right() - w; |
586 if (abs(pos.bottom() - work_area.bottom()) < grid) | 596 if (abs(pos.bottom() - work_area.bottom()) < grid) |
587 y = work_area.bottom() - h; | 597 y = work_area.bottom() - h; |
588 return gfx::Rect(x, y, w, h); | 598 return gfx::Rect(x, y, w, h); |
589 } | 599 } |
590 | 600 |
591 } // namespace ash | 601 } // namespace ash |
OLD | NEW |