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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/window_sizer/window_sizer.h"
8 #include "ash/wm/window_positioner.h"
9 #include "ash/wm/window_state.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/gfx/screen.h"
16 bool WindowSizer::GetBrowserBoundsAsh(gfx::Rect
* bounds
,
17 ui::WindowShowState
* show_state
) const {
19 browser_
->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH
)
22 if (bounds
->IsEmpty()) {
23 if (browser_
->is_type_tabbed()) {
24 GetTabbedBrowserBoundsAsh(bounds
, show_state
);
28 if (browser_
->is_trusted_source()) {
29 // For trusted popups (v1 apps and system windows), do not use the last
30 // active window bounds, only use saved or default bounds.
31 if (!GetSavedWindowBounds(bounds
, show_state
))
32 GetDefaultWindowBounds(GetTargetDisplay(gfx::Rect()), bounds
);
36 // In Ash, prioritize the last saved |show_state|. If you have questions
37 // or comments about this behavior please contact oshima@chromium.org.
38 if (state_provider_
) {
39 gfx::Rect ignored_bounds
, ignored_work_area
;
40 state_provider_
->GetPersistentState(&ignored_bounds
,
47 // In case of a popup with an 'unspecified' location in ash, we are
48 // looking for a good screen location. We are interpreting (0,0) as an
49 // unspecified location.
50 if (browser_
->is_type_popup() && bounds
->origin().IsOrigin()) {
51 *bounds
= ash::Shell::GetInstance()->window_positioner()->
52 GetPopupPosition(*bounds
);
58 void WindowSizer::GetTabbedBrowserBoundsAsh(
59 gfx::Rect
* bounds_in_screen
,
60 ui::WindowShowState
* show_state
) const {
62 DCHECK(bounds_in_screen
);
63 DCHECK(browser_
->is_type_tabbed());
64 DCHECK(bounds_in_screen
->IsEmpty());
66 ui::WindowShowState passed_show_state
= *show_state
;
68 bool is_saved_bounds
= GetSavedWindowBounds(bounds_in_screen
, show_state
);
70 if (is_saved_bounds
) {
71 display
= screen_
->GetDisplayMatching(*bounds_in_screen
);
73 // If there is no saved bounds (hence bounds_in_screen is empty), use the
75 display
= target_display_provider_
->GetTargetDisplay(screen_
,
77 *bounds_in_screen
= ash::WindowPositioner::GetDefaultWindowBounds(display
);
80 if (browser_
->is_session_restore()) {
81 // This is a fall-through case when there is no bounds recorded
82 // for restored window, and should not be used except for the case
83 // above. The regular path is handled in
84 // |WindowSizer::DetermineWindowBoundsAndShowState|.
86 // Note: How restore bounds/show state data are passed.
87 // The restore bounds is passed via |Browser::override_bounds()| in
88 // |chrome::GetBrowserWindowBoundsAndShowState()|.
89 // The restore state is passed via |Browser::initial_state()| in
90 // |WindowSizer::GetWindowDefaultShowState|.
91 bounds_in_screen
->AdjustToFit(display
.work_area());
95 // The |browser_window| is non NULL when this is called after
96 // browser's aura window is created.
97 aura::Window
* browser_window
=
98 browser_
->window() ? browser_
->window()->GetNativeWindow() : NULL
;
100 ash::WindowPositioner::GetBoundsAndShowStateForNewWindow(