Chromium Code Reviews| Index: chrome/browser/ui/window_sizer/window_sizer.cc |
| diff --git a/chrome/browser/ui/window_sizer/window_sizer.cc b/chrome/browser/ui/window_sizer/window_sizer.cc |
| index ba299daf4df930caafeac701f7c13eccd3a2cb92..a7161d99145b5f59adc78dfa77a0c617afb9cbc1 100644 |
| --- a/chrome/browser/ui/window_sizer/window_sizer.cc |
| +++ b/chrome/browser/ui/window_sizer/window_sizer.cc |
| @@ -14,7 +14,9 @@ |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/browser_window_state.h" |
| #include "chrome/common/pref_names.h" |
| +#include "chrome/common/chrome_switches.cc" |
| #include "ui/gfx/screen.h" |
| +#include "ui/views/widget/widget.h" |
|
sky
2012/10/05 22:54:03
This is cross platform code, don't use views
Mr4D (OOO till 08-26)
2012/10/06 01:10:10
When I checked for minimize that was the only way
|
| // Minimum height of the visible part of a window. |
| const int kMinVisibleHeight = 30; |
| @@ -47,7 +49,8 @@ class DefaultStateProvider : public WindowSizer::StateProvider { |
| // Overridden from WindowSizer::StateProvider: |
| virtual bool GetPersistentState(gfx::Rect* bounds, |
| - gfx::Rect* work_area) const { |
| + gfx::Rect* work_area, |
| + ui::WindowShowState& show_state) const { |
| DCHECK(bounds); |
| if (!browser_ || !browser_->profile()->GetPrefs()) |
| @@ -57,11 +60,13 @@ class DefaultStateProvider : public WindowSizer::StateProvider { |
| const DictionaryValue* wp_pref = |
| browser_->profile()->GetPrefs()->GetDictionary(window_name.c_str()); |
| int top = 0, left = 0, bottom = 0, right = 0; |
| + bool maximized = false; |
| bool has_prefs = wp_pref && |
| wp_pref->GetInteger("top", &top) && |
| wp_pref->GetInteger("left", &left) && |
| wp_pref->GetInteger("bottom", &bottom) && |
| - wp_pref->GetInteger("right", &right); |
| + wp_pref->GetInteger("right", &right) && |
| + wp_pref->GetBoolean("maximized", &maximized); |
| bounds->SetRect(left, top, std::max(0, right - left), |
| std::max(0, bottom - top)); |
| @@ -74,6 +79,8 @@ class DefaultStateProvider : public WindowSizer::StateProvider { |
| wp_pref->GetInteger("work_area_left", &work_area_left); |
| wp_pref->GetInteger("work_area_bottom", &work_area_bottom); |
| wp_pref->GetInteger("work_area_right", &work_area_right); |
| + if (show_state == ui::SHOW_STATE_DEFAULT && maximized) |
| + show_state = ui::SHOW_STATE_MAXIMIZED; |
| } |
| work_area->SetRect(work_area_left, work_area_top, |
| std::max(0, work_area_right - work_area_left), |
| @@ -82,7 +89,8 @@ class DefaultStateProvider : public WindowSizer::StateProvider { |
| return has_prefs; |
| } |
| - virtual bool GetLastActiveWindowState(gfx::Rect* bounds) const { |
| + virtual bool GetLastActiveWindowState(gfx::Rect* bounds, |
| + ui::WindowShowState& show_state) const { |
| // Applications are always restored with the same position. |
| if (!app_name_.empty()) |
| return false; |
| @@ -109,6 +117,10 @@ class DefaultStateProvider : public WindowSizer::StateProvider { |
| if (window) { |
| *bounds = window->GetRestoredBounds(); |
| + bool maximized = views::Widget::GetWidgetForNativeWindow( |
|
sky
2012/10/05 22:54:03
You want window->IsMaximized(), which works on all
Mr4D (OOO till 08-26)
2012/10/06 01:10:10
This is now funny. I was looking all over the syst
|
| + window->GetNativeWindow())->IsMaximized(); |
| + if (show_state == ui::SHOW_STATE_DEFAULT && maximized) |
| + show_state = ui::SHOW_STATE_MAXIMIZED; |
| return true; |
| } |
| @@ -153,26 +165,46 @@ WindowSizer::~WindowSizer() { |
| } |
| // static |
| +void WindowSizer::GetBrowserWindowBoundsAndShowState( |
| + const std::string& app_name, |
| + const gfx::Rect& specified_bounds, |
| + const Browser* browser, |
| + gfx::Rect* window_bounds, |
| + ui::WindowShowState& show_state) { |
| + const WindowSizer sizer(new DefaultStateProvider(app_name, browser), browser); |
| + sizer.DetermineWindowBoundsAndShowState(specified_bounds, |
| + window_bounds, |
| + show_state); |
| +} |
| + |
| +// static |
| void WindowSizer::GetBrowserWindowBounds(const std::string& app_name, |
| const gfx::Rect& specified_bounds, |
| const Browser* browser, |
| gfx::Rect* window_bounds) { |
| const WindowSizer sizer(new DefaultStateProvider(app_name, browser), browser); |
| - sizer.DetermineWindowBounds(specified_bounds, window_bounds); |
| + ui::WindowShowState show_state; |
| + sizer.DetermineWindowBoundsAndShowState(specified_bounds, |
| + window_bounds, |
| + show_state); |
| } |
| /////////////////////////////////////////////////////////////////////////////// |
| // WindowSizer, private: |
| -void WindowSizer::DetermineWindowBounds(const gfx::Rect& specified_bounds, |
| - gfx::Rect* bounds) const { |
| +void WindowSizer::DetermineWindowBoundsAndShowState( |
| + const gfx::Rect& specified_bounds, |
| + gfx::Rect* bounds, |
| + ui::WindowShowState& show_state) const { |
| + // Pre-populate the window state with our default. |
| + show_state = GetWindowDefaultShowState(); |
| *bounds = specified_bounds; |
| if (bounds->IsEmpty()) { |
| - if (GetBoundsOverride(specified_bounds, bounds)) |
| + if (GetBoundsOverride(specified_bounds, bounds, show_state)) |
| return; |
| // See if there's saved placement information. |
| - if (!GetLastWindowBounds(bounds)) { |
| - if (!GetSavedWindowBounds(bounds)) { |
| + if (!GetLastWindowBounds(bounds, show_state)) { |
| + if (!GetSavedWindowBounds(bounds, show_state)) { |
| // No saved placement, figure out some sensible default size based on |
| // the user's screen size. |
| GetDefaultWindowBounds(bounds); |
| @@ -192,10 +224,11 @@ void WindowSizer::DetermineWindowBounds(const gfx::Rect& specified_bounds, |
| } |
| } |
| -bool WindowSizer::GetLastWindowBounds(gfx::Rect* bounds) const { |
| +bool WindowSizer::GetLastWindowBounds(gfx::Rect* bounds, |
| + ui::WindowShowState& show_state) const { |
| DCHECK(bounds); |
| if (!state_provider_.get() || |
| - !state_provider_->GetLastActiveWindowState(bounds)) |
| + !state_provider_->GetLastActiveWindowState(bounds, show_state)) |
| return false; |
| gfx::Rect last_window_bounds = *bounds; |
| bounds->Offset(kWindowTilePixels, kWindowTilePixels); |
| @@ -205,11 +238,14 @@ bool WindowSizer::GetLastWindowBounds(gfx::Rect* bounds) const { |
| return true; |
| } |
| -bool WindowSizer::GetSavedWindowBounds(gfx::Rect* bounds) const { |
| +bool WindowSizer::GetSavedWindowBounds(gfx::Rect* bounds, |
| + ui::WindowShowState& show_state) const { |
| DCHECK(bounds); |
| gfx::Rect saved_work_area; |
| if (!state_provider_.get() || |
| - !state_provider_->GetPersistentState(bounds, &saved_work_area)) |
| + !state_provider_->GetPersistentState(bounds, |
| + &saved_work_area, |
| + show_state)) |
| return false; |
| AdjustBoundsToBeVisibleOnMonitorContaining(*bounds, saved_work_area, bounds); |
| return true; |
| @@ -332,11 +368,38 @@ void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining( |
| bool WindowSizer::GetBoundsOverride( |
| const gfx::Rect& specified_bounds, |
| - gfx::Rect* bounds) const { |
| + gfx::Rect* bounds, |
| + ui::WindowShowState& show_state) const { |
| #if defined(USE_ASH) |
| // TODO(beng): insufficient but currently necessary. http://crbug.com/133312 |
| if (chrome::ShouldOpenAshOnStartup()) |
| - return GetBoundsOverrideAsh(specified_bounds, bounds); |
| + return GetBoundsOverrideAsh(specified_bounds, bounds, show_state); |
| #endif |
| return false; |
| } |
| + |
| +ui::WindowShowState WindowSizer::GetWindowDefaultShowState() const { |
| + if (!browser_) |
| + return ui::SHOW_STATE_DEFAULT; |
| + |
| + // Only tabbed browsers use the command line or preference state, with the |
| + // exception of devtools. |
| + bool show_state = !browser_->is_type_tabbed() && !browser_->is_devtools(); |
| + |
| +#if defined(USE_AURA) |
| + // We use the apps save state on aura. |
| + show_state &= !browser_->is_app(); |
| +#endif |
| + |
| + if (show_state) |
| + return browser_->initial_show_state(); |
| + |
| + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) |
| + return ui::SHOW_STATE_MAXIMIZED; |
| + |
| + if (browser_->initial_show_state() != ui::SHOW_STATE_DEFAULT) |
| + return browser_->initial_show_state(); |
| + |
| + // Otherwise we use the default which can be overridden later on. |
| + return ui::SHOW_STATE_DEFAULT; |
| +} |