| 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" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 bounds_in_screen.set_x(work_area.x()); | 113 bounds_in_screen.set_x(work_area.x()); |
| 114 return true; | 114 return true; |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 | 119 |
| 120 } // namespace | 120 } // namespace |
| 121 | 121 |
| 122 bool WindowSizer::GetBoundsOverrideAsh(const gfx::Rect& specified_bounds, | 122 bool WindowSizer::GetBoundsOverrideAsh(const gfx::Rect& specified_bounds, |
| 123 gfx::Rect* bounds_in_screen) const { | 123 gfx::Rect* bounds_in_screen, |
| 124 const Browser* browser) const { |
| 124 *bounds_in_screen = specified_bounds; | 125 *bounds_in_screen = specified_bounds; |
| 125 DCHECK(bounds_in_screen->IsEmpty()); | 126 DCHECK(bounds_in_screen->IsEmpty()); |
| 126 | 127 |
| 127 if (!GetSavedWindowBounds(bounds_in_screen)) | 128 if (!GetSavedWindowBounds(bounds_in_screen, browser)) |
| 128 GetDefaultWindowBounds(bounds_in_screen); | 129 GetDefaultWindowBounds(bounds_in_screen, browser); |
| 129 | 130 |
| 130 if (browser_ && browser_->is_type_tabbed()) { | 131 if (browser_ && browser_->is_type_tabbed()) { |
| 131 gfx::Rect work_area = | 132 gfx::Rect work_area = |
| 132 monitor_info_provider_->GetMonitorWorkAreaMatching(*bounds_in_screen); | 133 monitor_info_provider_->GetMonitorWorkAreaMatching(*bounds_in_screen); |
| 133 // This is a window / app. See if there is no window and try to place it. | 134 // This is a window / app. See if there is no window and try to place it. |
| 134 int count = GetNumberOfValidTopLevelBrowserWindows(work_area); | 135 int count = GetNumberOfValidTopLevelBrowserWindows(work_area); |
| 135 aura::Window* top_window = GetTopWindow(work_area); | 136 aura::Window* top_window = GetTopWindow(work_area); |
| 136 | 137 |
| 137 // If there is no valid other window we take the coordinates as is. | 138 // If there is no valid other window we take the coordinates as is. |
| 138 if (!count || !top_window || ash::wm::IsWindowMaximized(top_window)) | 139 if (!count || !top_window || ash::wm::IsWindowMaximized(top_window)) |
| 139 return true; | 140 return true; |
| 140 | 141 |
| 141 gfx::Rect other_bounds_in_screen = top_window->GetBoundsInScreen(); | 142 gfx::Rect other_bounds_in_screen = top_window->GetBoundsInScreen(); |
| 142 bool move_right = | 143 bool move_right = |
| 143 other_bounds_in_screen.CenterPoint().x() < work_area.CenterPoint().x(); | 144 other_bounds_in_screen.CenterPoint().x() < work_area.CenterPoint().x(); |
| 144 | 145 |
| 145 // In case we have only one window, we move the other window fully to the | 146 // In case we have only one window, we move the other window fully to the |
| 146 // "other side" - making room for this new window. | 147 // "other side" - making room for this new window. |
| 147 if (count == 1) { | 148 if (count == 1) { |
| 148 gfx::Display display = | 149 gfx::Display display = |
| 149 gfx::Screen::GetDisplayMatching( | 150 gfx::Screen::GetDisplayMatching( |
| 151 gfx::Screen::BadTwoWorldsContext(), |
| 150 top_window->GetRootWindow()->GetBoundsInScreen()); | 152 top_window->GetRootWindow()->GetBoundsInScreen()); |
| 151 if (MoveRect(work_area, other_bounds_in_screen, !move_right)) | 153 if (MoveRect(work_area, other_bounds_in_screen, !move_right)) |
| 152 top_window->SetBoundsInScreen(other_bounds_in_screen, display); | 154 top_window->SetBoundsInScreen(other_bounds_in_screen, display); |
| 153 } | 155 } |
| 154 // Use the size of the other window, and mirror the location to the | 156 // Use the size of the other window, and mirror the location to the |
| 155 // opposite side. Then make sure that it is inside our work area | 157 // opposite side. Then make sure that it is inside our work area |
| 156 // (if possible). | 158 // (if possible). |
| 157 *bounds_in_screen = other_bounds_in_screen; | 159 *bounds_in_screen = other_bounds_in_screen; |
| 158 MoveRect(work_area, *bounds_in_screen, move_right); | 160 MoveRect(work_area, *bounds_in_screen, move_right); |
| 159 if (bounds_in_screen->bottom() > work_area.bottom()) | 161 if (bounds_in_screen->bottom() > work_area.bottom()) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 185 if (default_width > kMaximumWindowWidth) { | 187 if (default_width > kMaximumWindowWidth) { |
| 186 // The window should get centered on the screen and not follow the grid. | 188 // The window should get centered on the screen and not follow the grid. |
| 187 offset_x = (work_area.width() - kMaximumWindowWidth) / 2; | 189 offset_x = (work_area.width() - kMaximumWindowWidth) / 2; |
| 188 default_width = kMaximumWindowWidth; | 190 default_width = kMaximumWindowWidth; |
| 189 } | 191 } |
| 190 default_bounds->SetRect(work_area.x() + offset_x, | 192 default_bounds->SetRect(work_area.x() + offset_x, |
| 191 work_area.y() + kDesktopBorderSize, | 193 work_area.y() + kDesktopBorderSize, |
| 192 default_width, | 194 default_width, |
| 193 default_height); | 195 default_height); |
| 194 } | 196 } |
| OLD | NEW |