| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/window_sizer/window_sizer.h" | 5 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/wm/window_cycle_controller.h" | 8 #include "ash/wm/window_cycle_controller.h" |
| 9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_delegate.h" | 17 #include "ui/aura/window_delegate.h" |
| 18 #include "ui/compositor/layer_animator.h" |
| 19 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 18 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 24 // The time which should be used to visually move a window through an automatic |
| 25 // "intelligent" window management option. |
| 26 const base::TimeDelta kWindowAutoMoveDuration = |
| 27 base::TimeDelta::FromMilliseconds(125); |
| 28 |
| 22 // Check if the given browser is 'valid': It is a tabbed, non minimized | 29 // Check if the given browser is 'valid': It is a tabbed, non minimized |
| 23 // window, which intersects with the |bounds_in_screen| area of a given screen. | 30 // window, which intersects with the |bounds_in_screen| area of a given screen. |
| 24 bool IsValidBrowser(Browser* browser, const gfx::Rect& bounds_in_screen) { | 31 bool IsValidBrowser(Browser* browser, const gfx::Rect& bounds_in_screen) { |
| 25 return (browser && browser->window() && | 32 return (browser && browser->window() && |
| 26 !(browser->is_type_popup() || browser->is_type_panel()) && | 33 !(browser->is_type_popup() || browser->is_type_panel()) && |
| 27 !browser->window()->IsMinimized() && | 34 !browser->window()->IsMinimized() && |
| 28 browser->window()->GetNativeWindow() && | 35 browser->window()->GetNativeWindow() && |
| 29 bounds_in_screen.Intersects( | 36 bounds_in_screen.Intersects( |
| 30 browser->window()->GetNativeWindow()->GetBoundsInScreen())); | 37 browser->window()->GetNativeWindow()->GetBoundsInScreen())); |
| 31 } | 38 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // We ignore the saved show state, but look instead for the top level | 156 // We ignore the saved show state, but look instead for the top level |
| 150 // window's show state. | 157 // window's show state. |
| 151 if (passed_show_state == ui::SHOW_STATE_DEFAULT) { | 158 if (passed_show_state == ui::SHOW_STATE_DEFAULT) { |
| 152 *show_state = maximized ? ui::SHOW_STATE_MAXIMIZED : | 159 *show_state = maximized ? ui::SHOW_STATE_MAXIMIZED : |
| 153 ui::SHOW_STATE_DEFAULT; | 160 ui::SHOW_STATE_DEFAULT; |
| 154 } | 161 } |
| 155 | 162 |
| 156 if (maximized) | 163 if (maximized) |
| 157 return true; | 164 return true; |
| 158 | 165 |
| 159 gfx::Rect other_bounds_in_screen = top_window->GetBoundsInScreen(); | |
| 160 bool move_right = | |
| 161 other_bounds_in_screen.CenterPoint().x() < work_area.CenterPoint().x(); | |
| 162 | |
| 163 // In case we have only one window, we move the other window fully to the | |
| 164 // "other side" - making room for this new window. | |
| 165 if (count == 1) { | |
| 166 gfx::Display display = ash::Shell::GetScreen()->GetDisplayMatching( | |
| 167 top_window->GetRootWindow()->GetBoundsInScreen()); | |
| 168 if (MoveRect(work_area, other_bounds_in_screen, !move_right)) | |
| 169 top_window->SetBoundsInScreen(other_bounds_in_screen, display); | |
| 170 } | |
| 171 // Use the size of the other window, and mirror the location to the | 166 // Use the size of the other window, and mirror the location to the |
| 172 // opposite side. Then make sure that it is inside our work area | 167 // opposite side. Then make sure that it is inside our work area |
| 173 // (if possible). | 168 // (if possible). |
| 174 *bounds_in_screen = other_bounds_in_screen; | 169 *bounds_in_screen = top_window->GetBoundsInScreen(); |
| 170 |
| 171 bool move_right = |
| 172 bounds_in_screen->CenterPoint().x() < work_area.CenterPoint().x(); |
| 173 |
| 175 MoveRect(work_area, *bounds_in_screen, move_right); | 174 MoveRect(work_area, *bounds_in_screen, move_right); |
| 176 if (bounds_in_screen->bottom() > work_area.bottom()) | 175 if (bounds_in_screen->bottom() > work_area.bottom()) |
| 177 bounds_in_screen->set_y(std::max(work_area.y(), | 176 bounds_in_screen->set_y(std::max(work_area.y(), |
| 178 work_area.bottom() - bounds_in_screen->height())); | 177 work_area.bottom() - bounds_in_screen->height())); |
| 179 return true; | 178 return true; |
| 180 } | 179 } |
| 181 | 180 |
| 182 return false; | 181 return false; |
| 183 } | 182 } |
| 184 | 183 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 202 if (default_width > kMaximumWindowWidth) { | 201 if (default_width > kMaximumWindowWidth) { |
| 203 // The window should get centered on the screen and not follow the grid. | 202 // The window should get centered on the screen and not follow the grid. |
| 204 offset_x = (work_area.width() - kMaximumWindowWidth) / 2; | 203 offset_x = (work_area.width() - kMaximumWindowWidth) / 2; |
| 205 default_width = kMaximumWindowWidth; | 204 default_width = kMaximumWindowWidth; |
| 206 } | 205 } |
| 207 default_bounds->SetRect(work_area.x() + offset_x, | 206 default_bounds->SetRect(work_area.x() + offset_x, |
| 208 work_area.y() + kDesktopBorderSize, | 207 work_area.y() + kDesktopBorderSize, |
| 209 default_width, | 208 default_width, |
| 210 default_height); | 209 default_height); |
| 211 } | 210 } |
| OLD | NEW |