Chromium Code Reviews| 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" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 int WindowSizer::GetForceMaximizedWidthLimit() { | 82 int WindowSizer::GetForceMaximizedWidthLimit() { |
| 83 static int maximum_limit = 0; | 83 static int maximum_limit = 0; |
| 84 if (!maximum_limit) { | 84 if (!maximum_limit) { |
| 85 maximum_limit = CommandLine::ForCurrentProcess()->HasSwitch( | 85 maximum_limit = CommandLine::ForCurrentProcess()->HasSwitch( |
| 86 ash::switches::kAshDisableAutoMaximizing) ? | 86 ash::switches::kAshDisableAutoMaximizing) ? |
| 87 kForceMaximizeWidthLimitDisabled : kForceMaximizeWidthLimit; | 87 kForceMaximizeWidthLimitDisabled : kForceMaximizeWidthLimit; |
| 88 } | 88 } |
| 89 return maximum_limit; | 89 return maximum_limit; |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool WindowSizer::GetBoundsOverrideAsh(gfx::Rect* bounds_in_screen, | 92 void WindowSizer::GetBoundsOverrideAsh(gfx::Rect* bounds_in_screen, |
| 93 ui::WindowShowState* show_state) const { | 93 ui::WindowShowState* show_state) const { |
| 94 DCHECK(show_state); | 94 DCHECK(show_state); |
| 95 DCHECK(bounds_in_screen); | 95 DCHECK(bounds_in_screen); |
| 96 | 96 |
| 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); | 97 bounds_in_screen->SetRect(0, 0, 0, 0); |
| 102 | 98 |
| 103 // Experiment: Force the maximize mode for all windows. | 99 // Experiment: Force the maximize mode for all tabbed windows |
| 104 if (ash::Shell::IsForcedMaximizeMode()) { | 100 if (ash::Shell::IsForcedMaximizeMode()) |
| 105 // Exceptions: Do not maximize popups and do not maximize windowed V1 apps | 101 *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(); | |
|
oshima
2013/08/30 23:49:46
apps v1 is TYPE_POPUP, so these checks aren't nece
| |
| 110 if (!is_popup && (is_tabbed || *show_state == ui::SHOW_STATE_DEFAULT)) | |
| 111 *show_state = ui::SHOW_STATE_MAXIMIZED; | |
| 112 } | |
| 113 | 102 |
| 114 ui::WindowShowState passed_show_state = *show_state; | 103 ui::WindowShowState passed_show_state = *show_state; |
| 115 bool has_saved_bounds = true; | 104 bool has_saved_bounds = true; |
| 116 if (!GetSavedWindowBounds(bounds_in_screen, show_state)) { | 105 if (!GetSavedWindowBounds(bounds_in_screen, show_state)) { |
| 117 has_saved_bounds = false; | 106 has_saved_bounds = false; |
| 118 GetDefaultWindowBounds(bounds_in_screen); | 107 GetDefaultWindowBounds(bounds_in_screen); |
| 119 } | 108 } |
| 120 | 109 |
| 121 if (browser_ && browser_->is_type_tabbed()) { | 110 aura::RootWindow* active = ash::Shell::GetActiveRootWindow(); |
| 122 aura::RootWindow* active = ash::Shell::GetActiveRootWindow(); | 111 // Always open new window in the active display. |
| 123 // Always open new window in the active display. | 112 gfx::Rect work_area = |
| 124 gfx::Rect work_area = | 113 screen_->GetDisplayMatching(active->GetBoundsInScreen()).work_area(); |
| 125 screen_->GetDisplayMatching(active->GetBoundsInScreen()).work_area(); | |
| 126 | 114 |
| 127 // This is a window / app. See if there is no window and try to place it. | 115 // This is a window / app. See if there is no window and try to place it. |
| 128 int count = GetNumberOfValidTopLevelBrowserWindows(work_area); | 116 int count = GetNumberOfValidTopLevelBrowserWindows(work_area); |
| 129 aura::Window* top_window = ash::GetTopWindowForNewWindow(active); | 117 aura::Window* top_window = ash::GetTopWindowForNewWindow(active); |
| 130 // Our window should not have any impact if we are already on top. | 118 // Our window should not have any impact if we are already on top. |
| 131 if (browser_->window() && | 119 if (browser_->window() && |
| 132 top_window == browser_->window()->GetNativeWindow()) | 120 top_window == browser_->window()->GetNativeWindow()) |
| 133 top_window = NULL; | 121 top_window = NULL; |
| 134 | 122 |
| 135 // If there is no valid other window we take the coordinates as is. | 123 // If there is no valid other window we take the coordinates as is. |
| 136 if ((!count || !top_window)) { | 124 if ((!count || !top_window)) { |
| 137 if (has_saved_bounds) { | 125 if (has_saved_bounds) { |
| 138 // Restore to previous state - if there is one. | 126 // Restore to previous state - if there is one. |
| 139 bounds_in_screen->AdjustToFit(work_area); | 127 bounds_in_screen->AdjustToFit(work_area); |
| 140 return true; | 128 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 } | 129 } |
| 159 | 130 |
| 160 if (maximized) | 131 // When using "small screens" we want to always open in full screen mode. |
| 161 return true; | 132 if (passed_show_state == ui::SHOW_STATE_DEFAULT && |
| 162 | 133 !browser_->is_session_restore() && |
| 163 // Use the size of the other window. The window's bound will be rearranged | 134 work_area.width() <= GetForceMaximizedWidthLimit() && |
| 164 // in ash::WorkspaceLayoutManager using this location. | 135 (!browser_->window() || !browser_->window()->IsFullscreen())) { |
| 165 *bounds_in_screen = top_window->GetBoundsInScreen(); | 136 *show_state = ui::SHOW_STATE_MAXIMIZED; |
| 166 | 137 return; |
| 167 return true; | 138 } |
| 139 } | |
| 140 bool maximized = ash::wm::IsWindowMaximized(top_window); | |
| 141 // We ignore the saved show state, but look instead for the top level | |
| 142 // window's show state. | |
| 143 if (passed_show_state == ui::SHOW_STATE_DEFAULT) { | |
| 144 *show_state = maximized ? ui::SHOW_STATE_MAXIMIZED : | |
| 145 ui::SHOW_STATE_DEFAULT; | |
| 168 } | 146 } |
| 169 | 147 |
| 170 return false; | 148 // Use the size of the other window. The window's bound will be rearranged |
| 149 // in ash::WorkspaceLayoutManager using this location. | |
| 150 *bounds_in_screen = top_window->GetBoundsInScreen(); | |
| 171 } | 151 } |
| 172 | 152 |
| 173 void WindowSizer::GetDefaultWindowBoundsAsh(gfx::Rect* default_bounds) const { | 153 void WindowSizer::GetDefaultWindowBoundsAsh(gfx::Rect* default_bounds) const { |
| 174 DCHECK(default_bounds); | 154 DCHECK(default_bounds); |
| 175 | 155 |
| 176 gfx::Rect work_area = screen_->GetPrimaryDisplay().work_area(); | 156 gfx::Rect work_area = screen_->GetPrimaryDisplay().work_area(); |
| 177 | 157 |
| 178 // There should be a 'desktop' border around the window at the left and right | 158 // There should be a 'desktop' border around the window at the left and right |
| 179 // side. | 159 // side. |
| 180 int default_width = work_area.width() - 2 * kDesktopBorderSize; | 160 int default_width = work_area.width() - 2 * kDesktopBorderSize; |
| 181 // There should also be a 'desktop' border around the window at the top. | 161 // 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. | 162 // Since the workspace excludes the tray area we only need one border size. |
| 183 int default_height = work_area.height() - kDesktopBorderSize; | 163 int default_height = work_area.height() - kDesktopBorderSize; |
| 184 // We align the size to the grid size to avoid any surprise when the | 164 // 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. | 165 // monitor height isn't divide-able by our alignment factor. |
| 186 default_width -= default_width % kDesktopBorderSize; | 166 default_width -= default_width % kDesktopBorderSize; |
| 187 default_height -= default_height % kDesktopBorderSize; | 167 default_height -= default_height % kDesktopBorderSize; |
| 188 int offset_x = kDesktopBorderSize; | 168 int offset_x = kDesktopBorderSize; |
| 189 if (default_width > kMaximumWindowWidth) { | 169 if (default_width > kMaximumWindowWidth) { |
| 190 // The window should get centered on the screen and not follow the grid. | 170 // The window should get centered on the screen and not follow the grid. |
| 191 offset_x = (work_area.width() - kMaximumWindowWidth) / 2; | 171 offset_x = (work_area.width() - kMaximumWindowWidth) / 2; |
| 192 default_width = kMaximumWindowWidth; | 172 default_width = kMaximumWindowWidth; |
| 193 } | 173 } |
| 194 default_bounds->SetRect(work_area.x() + offset_x, | 174 default_bounds->SetRect(work_area.x() + offset_x, |
| 195 work_area.y() + kDesktopBorderSize, | 175 work_area.y() + kDesktopBorderSize, |
| 196 default_width, | 176 default_width, |
| 197 default_height); | 177 default_height); |
| 198 } | 178 } |
| OLD | NEW |