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/ash_switches.h" |
7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
8 #include "ash/wm/window_cycle_controller.h" | 9 #include "ash/wm/window_cycle_controller.h" |
9 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| 11 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
14 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
15 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 17 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
16 #include "chrome/browser/ui/host_desktop.h" | 18 #include "chrome/browser/ui/host_desktop.h" |
17 #include "ui/aura/root_window.h" | 19 #include "ui/aura/root_window.h" |
18 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
19 #include "ui/aura/window_delegate.h" | 21 #include "ui/aura/window_delegate.h" |
20 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
21 | 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 // When a window gets opened in default mode and the screen is less then this | 26 // When a window gets opened in default mode and the screen is less then this |
25 // width, the window will get opened in maximized mode. | 27 // width, the window will get opened in maximized mode. This value can be |
| 28 // reduced to a "tame" number if the feature is disabled. |
26 const int kForceMaximizeWidthLimit = 1366; | 29 const int kForceMaximizeWidthLimit = 1366; |
| 30 const int kForceMaximizeWidthLimitDisabled = 640; |
27 | 31 |
28 // Check if the given browser is 'valid': It is a tabbed, non minimized | 32 // Check if the given browser is 'valid': It is a tabbed, non minimized |
29 // window, which intersects with the |bounds_in_screen| area of a given screen. | 33 // window, which intersects with the |bounds_in_screen| area of a given screen. |
30 bool IsValidBrowser(Browser* browser, const gfx::Rect& bounds_in_screen) { | 34 bool IsValidBrowser(Browser* browser, const gfx::Rect& bounds_in_screen) { |
31 return (browser && browser->window() && | 35 return (browser && browser->window() && |
32 !browser->is_type_popup() && | 36 !browser->is_type_popup() && |
33 !browser->window()->IsMinimized() && | 37 !browser->window()->IsMinimized() && |
34 browser->window()->GetNativeWindow() && | 38 browser->window()->GetNativeWindow() && |
35 bounds_in_screen.Intersects( | 39 bounds_in_screen.Intersects( |
36 browser->window()->GetNativeWindow()->GetBoundsInScreen())); | 40 browser->window()->GetNativeWindow()->GetBoundsInScreen())); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 return true; | 132 return true; |
129 } | 133 } |
130 } | 134 } |
131 return false; | 135 return false; |
132 } | 136 } |
133 | 137 |
134 } // namespace | 138 } // namespace |
135 | 139 |
136 // static | 140 // static |
137 int WindowSizer::GetForceMaximizedWidthLimit() { | 141 int WindowSizer::GetForceMaximizedWidthLimit() { |
138 return kForceMaximizeWidthLimit; | 142 static int maximum_limit = 0; |
| 143 if (!maximum_limit) { |
| 144 maximum_limit = CommandLine::ForCurrentProcess()->HasSwitch( |
| 145 ash::switches::kAshDisableAutoMaximizing) ? |
| 146 kForceMaximizeWidthLimitDisabled : kForceMaximizeWidthLimit; |
| 147 } |
| 148 return maximum_limit; |
139 } | 149 } |
140 | 150 |
141 bool WindowSizer::GetBoundsOverrideAsh(gfx::Rect* bounds_in_screen, | 151 bool WindowSizer::GetBoundsOverrideAsh(gfx::Rect* bounds_in_screen, |
142 ui::WindowShowState* show_state) const { | 152 ui::WindowShowState* show_state) const { |
143 DCHECK(show_state); | 153 DCHECK(show_state); |
144 DCHECK(bounds_in_screen); | 154 DCHECK(bounds_in_screen); |
145 | 155 |
146 if (browser_ && | 156 if (browser_ && |
147 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) { | 157 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) { |
148 return false; | 158 return false; |
(...skipping 16 matching lines...) Expand all Loading... |
165 aura::Window* top_window = GetTopWindow(work_area); | 175 aura::Window* top_window = GetTopWindow(work_area); |
166 // Our window should not have any impact if we are already on top. | 176 // Our window should not have any impact if we are already on top. |
167 if (browser_->window() && | 177 if (browser_->window() && |
168 top_window == browser_->window()->GetNativeWindow()) | 178 top_window == browser_->window()->GetNativeWindow()) |
169 top_window = NULL; | 179 top_window = NULL; |
170 // If there is no valid other window we take the coordinates as is. | 180 // If there is no valid other window we take the coordinates as is. |
171 if (!count || !top_window) { | 181 if (!count || !top_window) { |
172 // When using "small screens" we want to always open in full screen mode. | 182 // When using "small screens" we want to always open in full screen mode. |
173 if (passed_show_state == ui::SHOW_STATE_DEFAULT && | 183 if (passed_show_state == ui::SHOW_STATE_DEFAULT && |
174 !browser_->is_session_restore() && | 184 !browser_->is_session_restore() && |
175 work_area.width() < kForceMaximizeWidthLimit && | 185 work_area.width() < GetForceMaximizedWidthLimit() && |
176 (!browser_->window() || !browser_->window()->IsFullscreen()) && | 186 (!browser_->window() || !browser_->window()->IsFullscreen()) && |
177 (!browser_->fullscreen_controller() || | 187 (!browser_->fullscreen_controller() || |
178 !browser_->fullscreen_controller()->IsFullscreenForBrowser())) | 188 !browser_->fullscreen_controller()->IsFullscreenForBrowser())) |
179 *show_state = ui::SHOW_STATE_MAXIMIZED; | 189 *show_state = ui::SHOW_STATE_MAXIMIZED; |
180 return true; | 190 return true; |
181 } | 191 } |
182 bool maximized = ash::wm::IsWindowMaximized(top_window); | 192 bool maximized = ash::wm::IsWindowMaximized(top_window); |
183 // We ignore the saved show state, but look instead for the top level | 193 // We ignore the saved show state, but look instead for the top level |
184 // window's show state. | 194 // window's show state. |
185 if (passed_show_state == ui::SHOW_STATE_DEFAULT) { | 195 if (passed_show_state == ui::SHOW_STATE_DEFAULT) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 if (default_width > kMaximumWindowWidth) { | 238 if (default_width > kMaximumWindowWidth) { |
229 // The window should get centered on the screen and not follow the grid. | 239 // The window should get centered on the screen and not follow the grid. |
230 offset_x = (work_area.width() - kMaximumWindowWidth) / 2; | 240 offset_x = (work_area.width() - kMaximumWindowWidth) / 2; |
231 default_width = kMaximumWindowWidth; | 241 default_width = kMaximumWindowWidth; |
232 } | 242 } |
233 default_bounds->SetRect(work_area.x() + offset_x, | 243 default_bounds->SetRect(work_area.x() + offset_x, |
234 work_area.y() + kDesktopBorderSize, | 244 work_area.y() + kDesktopBorderSize, |
235 default_width, | 245 default_width, |
236 default_height); | 246 default_height); |
237 } | 247 } |
OLD | NEW |