| 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/ash_switches.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/wm/mru_window_tracker.h" | 9 #include "ash/wm/mru_window_tracker.h" |
| 10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| 11 #include "ash/wm/workspace/auto_window_management.h" | 11 #include "ash/wm/workspace/auto_window_management.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "chrome/browser/browser_process.h" | |
| 15 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | |
| 19 #include "chrome/browser/ui/host_desktop.h" | |
| 20 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
| 21 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 22 #include "ui/aura/window_delegate.h" | 19 #include "ui/aura/window_delegate.h" |
| 23 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
| 24 | 21 |
| 25 namespace { | 22 namespace { |
| 26 | 23 |
| 27 // When a window gets opened in default mode and the screen is less than or | 24 // When a window gets opened in default mode and the screen is less than or |
| 28 // equal to this width, the window will get opened in maximized mode. This value | 25 // equal to this width, the window will get opened in maximized mode. This value |
| 29 // can be reduced to a "tame" number if the feature is disabled. | 26 // can be reduced to a "tame" number if the feature is disabled. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 int WindowSizer::GetForceMaximizedWidthLimit() { | 79 int WindowSizer::GetForceMaximizedWidthLimit() { |
| 83 static int maximum_limit = 0; | 80 static int maximum_limit = 0; |
| 84 if (!maximum_limit) { | 81 if (!maximum_limit) { |
| 85 maximum_limit = CommandLine::ForCurrentProcess()->HasSwitch( | 82 maximum_limit = CommandLine::ForCurrentProcess()->HasSwitch( |
| 86 ash::switches::kAshDisableAutoMaximizing) ? | 83 ash::switches::kAshDisableAutoMaximizing) ? |
| 87 kForceMaximizeWidthLimitDisabled : kForceMaximizeWidthLimit; | 84 kForceMaximizeWidthLimitDisabled : kForceMaximizeWidthLimit; |
| 88 } | 85 } |
| 89 return maximum_limit; | 86 return maximum_limit; |
| 90 } | 87 } |
| 91 | 88 |
| 92 bool WindowSizer::GetBoundsOverrideAsh(gfx::Rect* bounds_in_screen, | 89 void WindowSizer::GetTabbedBrowserBoundsAsh( |
| 93 ui::WindowShowState* show_state) const { | 90 gfx::Rect* bounds_in_screen, |
| 91 ui::WindowShowState* show_state) const { |
| 94 DCHECK(show_state); | 92 DCHECK(show_state); |
| 95 DCHECK(bounds_in_screen); | 93 DCHECK(bounds_in_screen); |
| 94 DCHECK(!browser_ || browser_->is_type_tabbed()); |
| 96 | 95 |
| 97 if (browser_ && | |
| 98 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) { | |
| 99 return false; | |
| 100 } | |
| 101 bounds_in_screen->SetRect(0, 0, 0, 0); | 96 bounds_in_screen->SetRect(0, 0, 0, 0); |
| 102 | 97 |
| 103 // Experiment: Force the maximize mode for all windows. | 98 // Experiment: Force the maximize mode for all tabbed windows |
| 104 if (ash::Shell::IsForcedMaximizeMode()) { | 99 if (ash::Shell::IsForcedMaximizeMode()) |
| 105 // Exceptions: Do not maximize popups and do not maximize windowed V1 apps | 100 *show_state = ui::SHOW_STATE_MAXIMIZED; |
| 106 // which explicitly specify a |show_state| (they might be tuned for a | |
| 107 // particular resolution / type). | |
| 108 bool is_tabbed = browser_ && browser_->is_type_tabbed(); | |
| 109 bool is_popup = browser_ && browser_->is_type_popup(); | |
| 110 if (!is_popup && (is_tabbed || *show_state == ui::SHOW_STATE_DEFAULT)) | |
| 111 *show_state = ui::SHOW_STATE_MAXIMIZED; | |
| 112 } | |
| 113 | 101 |
| 114 ui::WindowShowState passed_show_state = *show_state; | 102 ui::WindowShowState passed_show_state = *show_state; |
| 115 bool has_saved_bounds = true; | 103 bool has_saved_bounds = true; |
| 116 if (!GetSavedWindowBounds(bounds_in_screen, show_state)) { | 104 if (!GetSavedWindowBounds(bounds_in_screen, show_state)) { |
| 117 has_saved_bounds = false; | 105 has_saved_bounds = false; |
| 118 GetDefaultWindowBounds(bounds_in_screen); | 106 GetDefaultWindowBoundsAsh(bounds_in_screen); |
| 119 } | 107 } |
| 120 | 108 |
| 121 if (browser_ && browser_->is_type_tabbed()) { | 109 aura::RootWindow* active = ash::Shell::GetActiveRootWindow(); |
| 122 aura::RootWindow* active = ash::Shell::GetActiveRootWindow(); | 110 // Always open new window in the active display. |
| 123 // Always open new window in the active display. | 111 gfx::Rect work_area = |
| 124 gfx::Rect work_area = | 112 screen_->GetDisplayMatching(active->GetBoundsInScreen()).work_area(); |
| 125 screen_->GetDisplayMatching(active->GetBoundsInScreen()).work_area(); | |
| 126 | 113 |
| 127 // This is a window / app. See if there is no window and try to place it. | 114 // This is a window / app. See if there is no window and try to place it. |
| 128 int count = GetNumberOfValidTopLevelBrowserWindows(work_area); | 115 int count = GetNumberOfValidTopLevelBrowserWindows(work_area); |
| 129 aura::Window* top_window = ash::GetTopWindowForNewWindow(active); | 116 aura::Window* top_window = ash::GetTopWindowForNewWindow(active); |
| 130 // Our window should not have any impact if we are already on top. | 117 // Our window should not have any impact if we are already on top. |
| 131 if (browser_->window() && | 118 if (browser_->window() && |
| 132 top_window == browser_->window()->GetNativeWindow()) | 119 top_window == browser_->window()->GetNativeWindow()) |
| 133 top_window = NULL; | 120 top_window = NULL; |
| 134 | 121 |
| 135 // If there is no valid other window we take the coordinates as is. | 122 // If there is no valid other window we take the coordinates as is. |
| 136 if ((!count || !top_window)) { | 123 if ((!count || !top_window)) { |
| 137 if (has_saved_bounds) { | 124 if (has_saved_bounds) { |
| 138 // Restore to previous state - if there is one. | 125 // Restore to previous state - if there is one. |
| 139 bounds_in_screen->AdjustToFit(work_area); | 126 bounds_in_screen->AdjustToFit(work_area); |
| 140 return true; | 127 return; |
| 141 } | |
| 142 // When using "small screens" we want to always open in full screen mode. | |
| 143 if (passed_show_state == ui::SHOW_STATE_DEFAULT && | |
| 144 !browser_->is_session_restore() && | |
| 145 work_area.width() <= GetForceMaximizedWidthLimit() && | |
| 146 (!browser_->window() || !browser_->window()->IsFullscreen()) && | |
| 147 (!browser_->fullscreen_controller() || | |
| 148 !browser_->fullscreen_controller()->IsFullscreenForBrowser())) | |
| 149 *show_state = ui::SHOW_STATE_MAXIMIZED; | |
| 150 return true; | |
| 151 } | |
| 152 bool maximized = ash::wm::IsWindowMaximized(top_window); | |
| 153 // We ignore the saved show state, but look instead for the top level | |
| 154 // window's show state. | |
| 155 if (passed_show_state == ui::SHOW_STATE_DEFAULT) { | |
| 156 *show_state = maximized ? ui::SHOW_STATE_MAXIMIZED : | |
| 157 ui::SHOW_STATE_DEFAULT; | |
| 158 } | 128 } |
| 159 | 129 |
| 160 if (maximized) | 130 // When using "small screens" we want to always open in full screen mode. |
| 161 return true; | 131 if (passed_show_state == ui::SHOW_STATE_DEFAULT && |
| 162 | 132 !browser_->is_session_restore() && |
| 163 // Use the size of the other window. The window's bound will be rearranged | 133 work_area.width() <= GetForceMaximizedWidthLimit() && |
| 164 // in ash::WorkspaceLayoutManager using this location. | 134 (!browser_->window() || !browser_->window()->IsFullscreen())) |
| 165 *bounds_in_screen = top_window->GetBoundsInScreen(); | 135 *show_state = ui::SHOW_STATE_MAXIMIZED; |
| 166 | 136 return; |
| 167 return true; | 137 } |
| 138 bool maximized = ash::wm::IsWindowMaximized(top_window); |
| 139 // We ignore the saved show state, but look instead for the top level |
| 140 // window's show state. |
| 141 if (passed_show_state == ui::SHOW_STATE_DEFAULT) { |
| 142 *show_state = maximized ? ui::SHOW_STATE_MAXIMIZED : |
| 143 ui::SHOW_STATE_DEFAULT; |
| 168 } | 144 } |
| 169 | 145 |
| 170 return false; | 146 // Use the size of the other window. The window's bound will be rearranged |
| 147 // in ash::WorkspaceLayoutManager using this location. |
| 148 *bounds_in_screen = top_window->GetBoundsInScreen(); |
| 171 } | 149 } |
| 172 | 150 |
| 173 void WindowSizer::GetDefaultWindowBoundsAsh(gfx::Rect* default_bounds) const { | 151 void WindowSizer::GetDefaultWindowBoundsAsh(gfx::Rect* default_bounds) const { |
| 174 DCHECK(default_bounds); | 152 DCHECK(default_bounds); |
| 175 | 153 |
| 176 gfx::Rect work_area = screen_->GetPrimaryDisplay().work_area(); | 154 gfx::Rect work_area = screen_->GetPrimaryDisplay().work_area(); |
| 177 | 155 |
| 178 // There should be a 'desktop' border around the window at the left and right | 156 // There should be a 'desktop' border around the window at the left and right |
| 179 // side. | 157 // side. |
| 180 int default_width = work_area.width() - 2 * kDesktopBorderSize; | 158 int default_width = work_area.width() - 2 * kDesktopBorderSize; |
| 181 // There should also be a 'desktop' border around the window at the top. | 159 // There should also be a 'desktop' border around the window at the top. |
| 182 // Since the workspace excludes the tray area we only need one border size. | 160 // Since the workspace excludes the tray area we only need one border size. |
| 183 int default_height = work_area.height() - kDesktopBorderSize; | 161 int default_height = work_area.height() - kDesktopBorderSize; |
| 184 // We align the size to the grid size to avoid any surprise when the | 162 // We align the size to the grid size to avoid any surprise when the |
| 185 // monitor height isn't divide-able by our alignment factor. | 163 // monitor height isn't divide-able by our alignment factor. |
| 186 default_width -= default_width % kDesktopBorderSize; | 164 default_width -= default_width % kDesktopBorderSize; |
| 187 default_height -= default_height % kDesktopBorderSize; | 165 default_height -= default_height % kDesktopBorderSize; |
| 188 int offset_x = kDesktopBorderSize; | 166 int offset_x = kDesktopBorderSize; |
| 189 if (default_width > kMaximumWindowWidth) { | 167 if (default_width > kMaximumWindowWidth) { |
| 190 // The window should get centered on the screen and not follow the grid. | 168 // The window should get centered on the screen and not follow the grid. |
| 191 offset_x = (work_area.width() - kMaximumWindowWidth) / 2; | 169 offset_x = (work_area.width() - kMaximumWindowWidth) / 2; |
| 192 default_width = kMaximumWindowWidth; | 170 default_width = kMaximumWindowWidth; |
| 193 } | 171 } |
| 194 default_bounds->SetRect(work_area.x() + offset_x, | 172 default_bounds->SetRect(work_area.x() + offset_x, |
| 195 work_area.y() + kDesktopBorderSize, | 173 work_area.y() + kDesktopBorderSize, |
| 196 default_width, | 174 default_width, |
| 197 default_height); | 175 default_height); |
| 198 } | 176 } |
| OLD | NEW |