Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: chrome/browser/ui/window_sizer/window_sizer_ash.cc

Issue 23567007: More cleanup in window_sizer/window_sizer_ash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 {
Mr4D (OOO till 08-26) 2013/09/03 15:55:03 Since you have changed the meaning of the function
oshima 2013/09/03 18:15:27 Changed to GetTabbedBrowserBoundsAsh
94 DCHECK(show_state); 94 DCHECK(show_state);
95 DCHECK(bounds_in_screen); 95 DCHECK(bounds_in_screen);
96 DCHECK(!browser_ || browser_->is_type_tabbed());
96 97
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); 98 bounds_in_screen->SetRect(0, 0, 0, 0);
102 99
103 // Experiment: Force the maximize mode for all windows. 100 // Experiment: Force the maximize mode for all tabbed windows
104 if (ash::Shell::IsForcedMaximizeMode()) { 101 if (ash::Shell::IsForcedMaximizeMode())
105 // Exceptions: Do not maximize popups and do not maximize windowed V1 apps 102 *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 103
114 ui::WindowShowState passed_show_state = *show_state; 104 ui::WindowShowState passed_show_state = *show_state;
115 bool has_saved_bounds = true; 105 bool has_saved_bounds = true;
116 if (!GetSavedWindowBounds(bounds_in_screen, show_state)) { 106 if (!GetSavedWindowBounds(bounds_in_screen, show_state)) {
117 has_saved_bounds = false; 107 has_saved_bounds = false;
118 GetDefaultWindowBounds(bounds_in_screen); 108 GetDefaultWindowBounds(bounds_in_screen);
119 } 109 }
120 110
121 if (browser_ && browser_->is_type_tabbed()) { 111 aura::RootWindow* active = ash::Shell::GetActiveRootWindow();
122 aura::RootWindow* active = ash::Shell::GetActiveRootWindow(); 112 // Always open new window in the active display.
123 // Always open new window in the active display. 113 gfx::Rect work_area =
124 gfx::Rect work_area = 114 screen_->GetDisplayMatching(active->GetBoundsInScreen()).work_area();
125 screen_->GetDisplayMatching(active->GetBoundsInScreen()).work_area();
126 115
127 // This is a window / app. See if there is no window and try to place it. 116 // This is a window / app. See if there is no window and try to place it.
128 int count = GetNumberOfValidTopLevelBrowserWindows(work_area); 117 int count = GetNumberOfValidTopLevelBrowserWindows(work_area);
129 aura::Window* top_window = ash::GetTopWindowForNewWindow(active); 118 aura::Window* top_window = ash::GetTopWindowForNewWindow(active);
130 // Our window should not have any impact if we are already on top. 119 // Our window should not have any impact if we are already on top.
131 if (browser_->window() && 120 if (browser_->window() &&
132 top_window == browser_->window()->GetNativeWindow()) 121 top_window == browser_->window()->GetNativeWindow())
133 top_window = NULL; 122 top_window = NULL;
134 123
135 // If there is no valid other window we take the coordinates as is. 124 // If there is no valid other window we take the coordinates as is.
136 if ((!count || !top_window)) { 125 if ((!count || !top_window)) {
137 if (has_saved_bounds) { 126 if (has_saved_bounds) {
138 // Restore to previous state - if there is one. 127 // Restore to previous state - if there is one.
139 bounds_in_screen->AdjustToFit(work_area); 128 bounds_in_screen->AdjustToFit(work_area);
140 return true; 129 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 } 130 }
159 131
160 if (maximized) 132 // When using "small screens" we want to always open in full screen mode.
161 return true; 133 if (passed_show_state == ui::SHOW_STATE_DEFAULT &&
162 134 !browser_->is_session_restore() &&
163 // Use the size of the other window. The window's bound will be rearranged 135 work_area.width() <= GetForceMaximizedWidthLimit() &&
164 // in ash::WorkspaceLayoutManager using this location. 136 (!browser_->window() || !browser_->window()->IsFullscreen()))
Mr4D (OOO till 08-26) 2013/09/03 15:55:03 I know you asked me about the fullscreen controlle
oshima 2013/09/03 18:15:27 Yes, i'm pretty sure this isn't necessary. (you ca
165 *bounds_in_screen = top_window->GetBoundsInScreen(); 137 *show_state = ui::SHOW_STATE_MAXIMIZED;
166 138 return;
167 return true; 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698