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

Side by Side Diff: ash/wm/window_positioner.cc

Issue 964503002: Implemented ForceMaximizeBrowserWindowOnFirstRun policy, added unit test and browser test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed description Created 5 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/wm/window_positioner.h" 5 #include "ash/wm/window_positioner.h"
6 6
7 #include "ash/screen_util.h" 7 #include "ash/screen_util.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_delegate.h"
9 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
10 #include "ash/wm/mru_window_tracker.h" 11 #include "ash/wm/mru_window_tracker.h"
11 #include "ash/wm/window_resizer.h" 12 #include "ash/wm/window_resizer.h"
12 #include "ash/wm/window_state.h" 13 #include "ash/wm/window_state.h"
13 #include "ash/wm/window_util.h" 14 #include "ash/wm/window_util.h"
14 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
15 #include "ui/aura/window_delegate.h" 16 #include "ui/aura/window_delegate.h"
16 #include "ui/aura/window_event_dispatcher.h" 17 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/compositor/layer.h" 18 #include "ui/compositor/layer.h"
18 #include "ui/compositor/scoped_layer_animation_settings.h" 19 #include "ui/compositor/scoped_layer_animation_settings.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 240 }
240 241
241 // static 242 // static
242 void WindowPositioner::GetBoundsAndShowStateForNewWindow( 243 void WindowPositioner::GetBoundsAndShowStateForNewWindow(
243 const gfx::Screen* screen, 244 const gfx::Screen* screen,
244 const aura::Window* new_window, 245 const aura::Window* new_window,
245 bool is_saved_bounds, 246 bool is_saved_bounds,
246 ui::WindowShowState show_state_in, 247 ui::WindowShowState show_state_in,
247 gfx::Rect* bounds_in_out, 248 gfx::Rect* bounds_in_out,
248 ui::WindowShowState* show_state_out) { 249 ui::WindowShowState* show_state_out) {
249
250 // Always open new window in the target display. 250 // Always open new window in the target display.
251 aura::Window* target = Shell::GetTargetRootWindow(); 251 aura::Window* target = Shell::GetTargetRootWindow();
252 252
253 aura::Window* top_window = GetReferenceWindow(target, NULL, NULL); 253 aura::Window* top_window = GetReferenceWindow(target, NULL, NULL);
254 // Our window should not have any impact if we are already on top. 254 // Our window should not have any impact if we are already on top.
255 if (top_window == new_window) 255 if (top_window == new_window)
256 top_window = NULL; 256 top_window = NULL;
257 257
258 // If there is no valid other window we take and adjust the passed coordinates 258 // If there is no valid other window we take and adjust the passed coordinates
259 // and show state. 259 // and show state.
260 if (!top_window) { 260 if (!top_window) {
261 gfx::Rect work_area = screen->GetDisplayNearestWindow(target).work_area(); 261 gfx::Rect work_area = screen->GetDisplayNearestWindow(target).work_area();
262 262
263 bounds_in_out->AdjustToFit(work_area); 263 bounds_in_out->AdjustToFit(work_area);
264 // Use adjusted saved bounds, if there is one. 264 // Use adjusted saved bounds, if there is one.
265 if (is_saved_bounds) 265 if (is_saved_bounds)
266 return; 266 return;
267 // When using "small screens" we want to always open in full screen mode. 267
268 if (show_state_in == ui::SHOW_STATE_DEFAULT && (maximize_first_window || 268 // Policy to maximize window on the first run works only for Chrome OS.
bartfab (slow) 2015/03/12 11:54:43 Nit: No need for this comment. Ash is cross-plafor
peletskyi 2015/03/18 13:28:09 Done.
269 (work_area.width() <= GetForceMaximizedWidthLimit() && 269 const bool maximized_first_run =
bartfab (slow) 2015/03/12 11:54:43 1: Nit: How about s/maximized_first_run/maximize_f
peletskyi 2015/03/18 13:28:09 Done.
270 (!new_window || !wm::GetWindowState(new_window)->IsFullscreen())))) { 270 Shell::GetInstance()->delegate()->IsFirstTimeMaximized();
271 // When using "small screens" we want to always open in full screen mode,
bartfab (slow) 2015/03/12 11:54:43 Nit: How about "We want to always open maximized o
peletskyi 2015/03/18 13:28:09 Done.
272 // or when the policy ForceMaximizeBrowserWindowOnFirstRun is set to true.
273 const bool set_maximized =
274 maximize_first_window ||
275 ((work_area.width() <= GetForceMaximizedWidthLimit() ||
276 maximized_first_run) &&
bartfab (slow) 2015/03/12 11:54:43 Where is the code that ensures we only enforce thi
277 (!new_window || !wm::GetWindowState(new_window)->IsFullscreen()));
278 if (show_state_in == ui::SHOW_STATE_DEFAULT && set_maximized) {
bartfab (slow) 2015/03/12 11:54:43 Nit: You should rearrange this so that |set_maximi
peletskyi 2015/03/18 13:28:09 Done.
271 *show_state_out = ui::SHOW_STATE_MAXIMIZED; 279 *show_state_out = ui::SHOW_STATE_MAXIMIZED;
272 } 280 }
273 return; 281 return;
274 } 282 }
283
275 wm::WindowState* top_window_state = wm::GetWindowState(top_window); 284 wm::WindowState* top_window_state = wm::GetWindowState(top_window);
276 bool maximized = top_window_state->IsMaximized(); 285 bool maximized = top_window_state->IsMaximized();
277 // We ignore the saved show state, but look instead for the top level 286 // We ignore the saved show state, but look instead for the top level
278 // window's show state. 287 // window's show state.
279 if (show_state_in == ui::SHOW_STATE_DEFAULT) { 288 if (show_state_in == ui::SHOW_STATE_DEFAULT) {
280 *show_state_out = maximized ? ui::SHOW_STATE_MAXIMIZED : 289 *show_state_out = maximized ? ui::SHOW_STATE_MAXIMIZED :
281 ui::SHOW_STATE_DEFAULT; 290 ui::SHOW_STATE_DEFAULT;
282 } 291 }
283 292
284 if (maximized) { 293 if (maximized) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 // If the alignment was pushing the window out of the screen, we ignore the 591 // If the alignment was pushing the window out of the screen, we ignore the
583 // alignment for that call. 592 // alignment for that call.
584 if (abs(pos.right() - work_area.right()) < grid) 593 if (abs(pos.right() - work_area.right()) < grid)
585 x = work_area.right() - w; 594 x = work_area.right() - w;
586 if (abs(pos.bottom() - work_area.bottom()) < grid) 595 if (abs(pos.bottom() - work_area.bottom()) < grid)
587 y = work_area.bottom() - h; 596 y = work_area.bottom() - h;
588 return gfx::Rect(x, y, w, h); 597 return gfx::Rect(x, y, w, h);
589 } 598 }
590 599
591 } // namespace ash 600 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698