| 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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 const int kForceMaximizeWidthLimitDisabled = 640; | 43 const int kForceMaximizeWidthLimitDisabled = 640; |
| 44 | 44 |
| 45 // The time in milliseconds which should be used to visually move a window | 45 // The time in milliseconds which should be used to visually move a window |
| 46 // through an automatic "intelligent" window management option. | 46 // through an automatic "intelligent" window management option. |
| 47 const int kWindowAutoMoveDurationMS = 125; | 47 const int kWindowAutoMoveDurationMS = 125; |
| 48 | 48 |
| 49 // If set to true all window repositioning actions will be ignored. Set through | 49 // If set to true all window repositioning actions will be ignored. Set through |
| 50 // WindowPositioner::SetIgnoreActivations(). | 50 // WindowPositioner::SetIgnoreActivations(). |
| 51 static bool disable_auto_positioning = false; | 51 static bool disable_auto_positioning = false; |
| 52 | 52 |
| 53 // If set to true, by default the first window in ASH will be maxmized. |
| 54 static bool maximize_first_window = false; |
| 55 |
| 53 // Check if any management should be performed (with a given |window|). | 56 // Check if any management should be performed (with a given |window|). |
| 54 bool UseAutoWindowManager(const aura::Window* window) { | 57 bool UseAutoWindowManager(const aura::Window* window) { |
| 55 if (disable_auto_positioning) | 58 if (disable_auto_positioning) |
| 56 return false; | 59 return false; |
| 57 const wm::WindowState* window_state = wm::GetWindowState(window); | 60 const wm::WindowState* window_state = wm::GetWindowState(window); |
| 58 return window_state->tracked_by_workspace() && | 61 return window_state->tracked_by_workspace() && |
| 59 window_state->window_position_managed(); | 62 window_state->window_position_managed(); |
| 60 } | 63 } |
| 61 | 64 |
| 62 // Check if a given |window| can be managed. This includes that it's state is | 65 // Check if a given |window| can be managed. This includes that it's state is |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // If there is no valid other window we take and adjust the passed coordinates | 233 // If there is no valid other window we take and adjust the passed coordinates |
| 231 // and show state. | 234 // and show state. |
| 232 if (!top_window) { | 235 if (!top_window) { |
| 233 gfx::Rect work_area = screen->GetDisplayNearestWindow(target).work_area(); | 236 gfx::Rect work_area = screen->GetDisplayNearestWindow(target).work_area(); |
| 234 | 237 |
| 235 bounds_in_out->AdjustToFit(work_area); | 238 bounds_in_out->AdjustToFit(work_area); |
| 236 // Use adjusted saved bounds, if there is one. | 239 // Use adjusted saved bounds, if there is one. |
| 237 if (is_saved_bounds) | 240 if (is_saved_bounds) |
| 238 return; | 241 return; |
| 239 // When using "small screens" we want to always open in full screen mode. | 242 // When using "small screens" we want to always open in full screen mode. |
| 240 if (show_state_in == ui::SHOW_STATE_DEFAULT && | 243 if (show_state_in == ui::SHOW_STATE_DEFAULT && (maximize_first_window || |
| 241 work_area.width() <= GetForceMaximizedWidthLimit() && | 244 (work_area.width() <= GetForceMaximizedWidthLimit() && |
| 242 (!new_window || !wm::GetWindowState(new_window)->IsFullscreen())) { | 245 (!new_window || !wm::GetWindowState(new_window)->IsFullscreen())))) { |
| 243 *show_state_out = ui::SHOW_STATE_MAXIMIZED; | 246 *show_state_out = ui::SHOW_STATE_MAXIMIZED; |
| 244 } | 247 } |
| 245 return; | 248 return; |
| 246 } | 249 } |
| 247 bool maximized = wm::GetWindowState(top_window)->IsMaximized(); | 250 bool maximized = wm::GetWindowState(top_window)->IsMaximized(); |
| 248 // We ignore the saved show state, but look instead for the top level | 251 // We ignore the saved show state, but look instead for the top level |
| 249 // window's show state. | 252 // window's show state. |
| 250 if (show_state_in == ui::SHOW_STATE_DEFAULT) { | 253 if (show_state_in == ui::SHOW_STATE_DEFAULT) { |
| 251 *show_state_out = maximized ? ui::SHOW_STATE_MAXIMIZED : | 254 *show_state_out = maximized ? ui::SHOW_STATE_MAXIMIZED : |
| 252 ui::SHOW_STATE_DEFAULT; | 255 ui::SHOW_STATE_DEFAULT; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 work_area.width()) || | 411 work_area.width()) || |
| 409 (old_pos.height() + popup_position_offset_from_screen_corner_y >= | 412 (old_pos.height() + popup_position_offset_from_screen_corner_y >= |
| 410 work_area.height())) | 413 work_area.height())) |
| 411 return AlignPopupPosition(old_pos, work_area, grid); | 414 return AlignPopupPosition(old_pos, work_area, grid); |
| 412 const gfx::Rect result = SmartPopupPosition(old_pos, work_area, grid); | 415 const gfx::Rect result = SmartPopupPosition(old_pos, work_area, grid); |
| 413 if (!result.IsEmpty()) | 416 if (!result.IsEmpty()) |
| 414 return AlignPopupPosition(result, work_area, grid); | 417 return AlignPopupPosition(result, work_area, grid); |
| 415 return NormalPopupPosition(old_pos, work_area); | 418 return NormalPopupPosition(old_pos, work_area); |
| 416 } | 419 } |
| 417 | 420 |
| 421 // static |
| 422 void WindowPositioner::SetMaximizeFirstWindow(bool maximize) { |
| 423 maximize_first_window = maximize; |
| 424 } |
| 425 |
| 418 gfx::Rect WindowPositioner::NormalPopupPosition( | 426 gfx::Rect WindowPositioner::NormalPopupPosition( |
| 419 const gfx::Rect& old_pos, | 427 const gfx::Rect& old_pos, |
| 420 const gfx::Rect& work_area) { | 428 const gfx::Rect& work_area) { |
| 421 int w = old_pos.width(); | 429 int w = old_pos.width(); |
| 422 int h = old_pos.height(); | 430 int h = old_pos.height(); |
| 423 // Note: The 'last_popup_position' is checked and kept relative to the | 431 // Note: The 'last_popup_position' is checked and kept relative to the |
| 424 // screen size. The offsetting will be done in the last step when the | 432 // screen size. The offsetting will be done in the last step when the |
| 425 // target rectangle gets returned. | 433 // target rectangle gets returned. |
| 426 bool reset = false; | 434 bool reset = false; |
| 427 if (last_popup_position_y_ + h > work_area.height() || | 435 if (last_popup_position_y_ + h > work_area.height() || |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 // If the alignment was pushing the window out of the screen, we ignore the | 539 // If the alignment was pushing the window out of the screen, we ignore the |
| 532 // alignment for that call. | 540 // alignment for that call. |
| 533 if (abs(pos.right() - work_area.right()) < grid) | 541 if (abs(pos.right() - work_area.right()) < grid) |
| 534 x = work_area.right() - w; | 542 x = work_area.right() - w; |
| 535 if (abs(pos.bottom() - work_area.bottom()) < grid) | 543 if (abs(pos.bottom() - work_area.bottom()) < grid) |
| 536 y = work_area.bottom() - h; | 544 y = work_area.bottom() - h; |
| 537 return gfx::Rect(x, y, w, h); | 545 return gfx::Rect(x, y, w, h); |
| 538 } | 546 } |
| 539 | 547 |
| 540 } // namespace ash | 548 } // namespace ash |
| OLD | NEW |