diff options
35 files changed, 265 insertions, 224 deletions
diff --git a/chrome/browser/chromeos/frame/browser_view.cc b/chrome/browser/chromeos/frame/browser_view.cc index c25ccbd..9efb707 100644 --- a/chrome/browser/chromeos/frame/browser_view.cc +++ b/chrome/browser/chromeos/frame/browser_view.cc @@ -449,7 +449,9 @@ void BrowserView::ChildPreferredSizeChanged(View* child) { Layout(); } -bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { +bool BrowserView::GetSavedWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const { if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeosFrame)) { // Typically we don't request a full screen size. This means we'll request a // non-full screen size, layout/paint at that size, then the window manager @@ -457,9 +459,10 @@ bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { // resize/paint. To avoid this we always request a full screen size. *bounds = gfx::Screen::GetMonitorWorkAreaNearestWindow( GTK_WIDGET(GetWidget()->GetNativeWindow())); + *show_state = ui::SHOW_STATE_NORMAL; return true; } - return ::BrowserView::GetSavedWindowBounds(bounds); + return ::BrowserView::GetSavedWindowPlacement(bounds, show_state); } void BrowserView::Cut() { diff --git a/chrome/browser/chromeos/frame/browser_view.h b/chrome/browser/chromeos/frame/browser_view.h index 9d7ae95..b938e21 100644 --- a/chrome/browser/chromeos/frame/browser_view.h +++ b/chrome/browser/chromeos/frame/browser_view.h @@ -61,7 +61,9 @@ class BrowserView : public ::BrowserView, virtual void FocusChromeOSStatus() OVERRIDE; virtual views::LayoutManager* CreateLayoutManager() const OVERRIDE; virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; - virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const OVERRIDE; + virtual bool GetSavedWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE; virtual void Cut() OVERRIDE; virtual void Copy() OVERRIDE; virtual void Paste() OVERRIDE; diff --git a/chrome/browser/chromeos/frame/panel_browser_view.cc b/chrome/browser/chromeos/frame/panel_browser_view.cc index fba8fa8..de39b0e 100644 --- a/chrome/browser/chromeos/frame/panel_browser_view.cc +++ b/chrome/browser/chromeos/frame/panel_browser_view.cc @@ -110,16 +110,16 @@ WindowOpenDisposition PanelBrowserView::GetDispositionForPopupBounds( return chromeos::BrowserView::DispositionForPopupBounds(bounds); } -bool PanelBrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { - bool res = ::BrowserView::GetSavedWindowBounds(bounds); - if (res) +bool PanelBrowserView::GetSavedWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const { + bool result = ::BrowserView::GetSavedWindowPlacement(bounds, show_state); + if (result) { LimitBounds(bounds); - return res; -} - -bool PanelBrowserView::GetSavedMaximizedState(bool* maximized) const { - // Panels have no maximized state. - return false; + // Panels have no maximized state. + *show_state = ui::SHOW_STATE_NORMAL; + } + return result; } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/chromeos/frame/panel_browser_view.h b/chrome/browser/chromeos/frame/panel_browser_view.h index 819419e..99ec9ab 100644 --- a/chrome/browser/chromeos/frame/panel_browser_view.h +++ b/chrome/browser/chromeos/frame/panel_browser_view.h @@ -35,8 +35,9 @@ class PanelBrowserView : public ::BrowserView, virtual void UpdateTitleBar() OVERRIDE; virtual WindowOpenDisposition GetDispositionForPopupBounds( const gfx::Rect& bounds) OVERRIDE; - virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const OVERRIDE; - virtual bool GetSavedMaximizedState(bool* maximized) const OVERRIDE; + virtual bool GetSavedWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE; // views::Widget::Observer overrides. virtual void OnWidgetActivationChanged(views::Widget* widget, diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc index b18eb7b..2cbe188 100644 --- a/chrome/browser/sessions/session_restore.cc +++ b/chrome/browser/sessions/session_restore.cc @@ -598,6 +598,15 @@ class SessionRestoreImpl : public NotificationObserver { // tabbed browsers exist. Browser* last_browser = NULL; bool has_tabbed_browser = false; + + // Determine if there is a visible window. + bool has_visible_browser = false; + for (std::vector<SessionWindow*>::iterator i = windows->begin(); + i != windows->end(); ++i) { + if ((*i)->show_state != ui::SHOW_STATE_MINIMIZED) + has_visible_browser = true; + } + for (std::vector<SessionWindow*>::iterator i = windows->begin(); i != windows->end(); ++i) { Browser* browser = NULL; @@ -613,10 +622,15 @@ class SessionRestoreImpl : public NotificationObserver { chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( "SessionRestore-CreateRestoredBrowser-Start", false); #endif + // Show the first window if none are visible. + ui::WindowShowState show_state = (*i)->show_state; + if (!has_visible_browser) { + show_state = ui::SHOW_STATE_NORMAL; + has_visible_browser = true; + } + browser = CreateRestoredBrowser( - static_cast<Browser::Type>((*i)->type), - (*i)->bounds, - (*i)->show_state); + static_cast<Browser::Type>((*i)->type), (*i)->bounds, show_state); #if defined(OS_CHROMEOS) chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( "SessionRestore-CreateRestoredBrowser-End", false); diff --git a/chrome/browser/sessions/session_service.cc b/chrome/browser/sessions/session_service.cc index dbb0f94..8e3f1d73 100644 --- a/chrome/browser/sessions/session_service.cc +++ b/chrome/browser/sessions/session_service.cc @@ -970,9 +970,11 @@ bool SessionService::CreateTabsAndWindows( payload.y, payload.w, payload.h); + // SHOW_STATE_INACTIVE is not persisted. ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; if (payload.show_state > ui::SHOW_STATE_DEFAULT && - payload.show_state < ui::SHOW_STATE_MAX) { + payload.show_state < ui::SHOW_STATE_MAX && + payload.show_state != ui::SHOW_STATE_INACTIVE) { show_state = static_cast<ui::WindowShowState>(payload.show_state); } else { NOTREACHED(); diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc index 9735848..61b2020 100644 --- a/chrome/browser/ui/browser_browsertest.cc +++ b/chrome/browser/ui/browser_browsertest.cc @@ -974,6 +974,20 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, StartMaximized) { } } +// Makes sure the browser doesn't crash when +// set_show_state(ui::SHOW_STATE_MINIMIZED) has been invoked. +IN_PROC_BROWSER_TEST_F(BrowserTest, StartMinimized) { + // Can't test TYPE_PANEL as they are currently created differently (and can't + // end up minimized). + Browser::Type types[] = { Browser::TYPE_TABBED, Browser::TYPE_POPUP }; + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(types); ++i) { + Browser* min_browser = new Browser(types[i], browser()->profile()); + min_browser->set_show_state(ui::SHOW_STATE_MINIMIZED); + min_browser->InitBrowserWindow(); + AddBlankTabAndShow(min_browser); + } +} + // TODO(ben): this test was never enabled. It has bit-rotted since being added. // It originally lived in browser_unittest.cc, but has been moved here to make // room for real browser unit tests. diff --git a/chrome/browser/ui/panels/panel_browser_view.cc b/chrome/browser/ui/panels/panel_browser_view.cc index 603b6d6..a6ffc55 100644 --- a/chrome/browser/ui/panels/panel_browser_view.cc +++ b/chrome/browser/ui/panels/panel_browser_view.cc @@ -107,8 +107,11 @@ void PanelBrowserView::UpdateTitleBar() { GetFrameView()->UpdateTitleBar(); } -bool PanelBrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { +bool PanelBrowserView::GetSavedWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const { *bounds = GetPanelBounds(); + *show_state = ui::SHOW_STATE_NORMAL; return true; } diff --git a/chrome/browser/ui/panels/panel_browser_view.h b/chrome/browser/ui/panels/panel_browser_view.h index 5ecbfbe..c855fd0 100644 --- a/chrome/browser/ui/panels/panel_browser_view.h +++ b/chrome/browser/ui/panels/panel_browser_view.h @@ -56,7 +56,9 @@ class PanelBrowserView : public BrowserView, virtual bool CanMaximize() const OVERRIDE; virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; virtual void UpdateTitleBar() OVERRIDE; - virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const OVERRIDE; + virtual bool GetSavedWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE; virtual bool AcceleratorPressed(const views::Accelerator& accelerator) OVERRIDE; diff --git a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc index 24649bd..3526b0a 100644 --- a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc +++ b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc @@ -35,14 +35,12 @@ class AccessibilityViewsDelegate : public views::ViewsDelegate { virtual void SaveWindowPlacement(const views::Widget* window, const std::wstring& window_name, const gfx::Rect& bounds, - bool maximized) OVERRIDE { + ui::WindowShowState show_state) OVERRIDE { } - virtual bool GetSavedWindowBounds(const std::wstring& window_name, - gfx::Rect* bounds) const OVERRIDE { - return false; - } - virtual bool GetSavedMaximizedState(const std::wstring& window_name, - bool* maximized) const OVERRIDE { + virtual bool GetSavedWindowPlacement( + const std::wstring& window_name, + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE { return false; } virtual void NotifyAccessibilityEvent( diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc index c033a9d..0667da3 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc @@ -74,13 +74,11 @@ class ViewsDelegateImpl : public views::ViewsDelegate { virtual void SaveWindowPlacement(const views::Widget* window, const std::wstring& window_name, const gfx::Rect& bounds, - bool maximized) OVERRIDE {} - virtual bool GetSavedWindowBounds(const std::wstring& window_name, - gfx::Rect* bounds) const OVERRIDE { - return false; - } - virtual bool GetSavedMaximizedState(const std::wstring& window_name, - bool* maximized) const OVERRIDE { + ui::WindowShowState show_state) OVERRIDE {} + virtual bool GetSavedWindowPlacement( + const std::wstring& window_name, + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE { return false; } diff --git a/chrome/browser/ui/views/chrome_views_delegate.cc b/chrome/browser/ui/views/chrome_views_delegate.cc index a471e6f..a6b7eef 100644 --- a/chrome/browser/ui/views/chrome_views_delegate.cc +++ b/chrome/browser/ui/views/chrome_views_delegate.cc @@ -61,7 +61,7 @@ views::View* ChromeViewsDelegate::GetDefaultParentView() { void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, const std::wstring& window_name, const gfx::Rect& bounds, - bool maximized) { + ui::WindowShowState show_state) { PrefService* prefs = GetPrefsForWindow(window); if (!prefs) return; @@ -73,7 +73,8 @@ void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, window_preferences->SetInteger("top", bounds.y()); window_preferences->SetInteger("right", bounds.right()); window_preferences->SetInteger("bottom", bounds.bottom()); - window_preferences->SetBoolean("maximized", maximized); + window_preferences->SetBoolean("maximized", + show_state == ui::SHOW_STATE_MAXIMIZED); scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info_provider( WindowSizer::CreateDefaultMonitorInfoProvider()); @@ -85,8 +86,10 @@ void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, window_preferences->SetInteger("work_area_bottom", work_area.bottom()); } -bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name, - gfx::Rect* bounds) const { +bool ChromeViewsDelegate::GetSavedWindowPlacement( + const std::wstring& window_name, + gfx::Rect* bounds, + ui::WindowShowState* show_state) const { PrefService* prefs = g_browser_process->local_state(); if (!prefs) return false; @@ -102,22 +105,13 @@ bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name, return false; bounds->SetRect(left, top, right - left, bottom - top); - return true; -} - -bool ChromeViewsDelegate::GetSavedMaximizedState( - const std::wstring& window_name, - bool* maximized) const { - PrefService* prefs = g_browser_process->local_state(); - if (!prefs) - return false; - DCHECK(prefs->FindPreference(WideToUTF8(window_name).c_str())); - const DictionaryValue* dictionary = - prefs->GetDictionary(WideToUTF8(window_name).c_str()); + bool maximized = false; + if (dictionary) + dictionary->GetBoolean("maximized", &maximized); + *show_state = maximized ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL; - return dictionary && dictionary->GetBoolean("maximized", maximized) && - maximized; + return true; } void ChromeViewsDelegate::NotifyAccessibilityEvent( diff --git a/chrome/browser/ui/views/chrome_views_delegate.h b/chrome/browser/ui/views/chrome_views_delegate.h index fb3121e..a874348 100644 --- a/chrome/browser/ui/views/chrome_views_delegate.h +++ b/chrome/browser/ui/views/chrome_views_delegate.h @@ -25,11 +25,11 @@ class ChromeViewsDelegate : public views::ViewsDelegate { virtual void SaveWindowPlacement(const views::Widget* window, const std::wstring& window_name, const gfx::Rect& bounds, - bool maximized) OVERRIDE; - virtual bool GetSavedWindowBounds(const std::wstring& window_name, - gfx::Rect* bounds) const OVERRIDE; - virtual bool GetSavedMaximizedState(const std::wstring& window_name, - bool* maximized) const OVERRIDE; + ui::WindowShowState show_state) OVERRIDE; + virtual bool GetSavedWindowPlacement( + const std::wstring& window_name, + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE; virtual void NotifyAccessibilityEvent( views::View* view, ui::AccessibilityTypes::Event event_type) OVERRIDE; virtual void NotifyMenuItemFocused( diff --git a/chrome/browser/ui/views/frame/browser_frame.cc b/chrome/browser/ui/views/frame/browser_frame.cc index 20f685a..31d2b67b 100644 --- a/chrome/browser/ui/views/frame/browser_frame.cc +++ b/chrome/browser/ui/views/frame/browser_frame.cc @@ -48,8 +48,7 @@ void BrowserFrame::InitBrowserFrame() { // Typed panel/popup can only return a size once the widget has been // created. params.bounds = browser_view_->browser()->GetSavedWindowBounds(); - params.maximize = browser_view_->browser()->GetSavedWindowShowState() == - ui::SHOW_STATE_MAXIMIZED; + params.show_state = browser_view_->browser()->GetSavedWindowShowState(); } Init(params); #if defined(OS_CHROMEOS) diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index d246005..4020129 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -790,9 +790,7 @@ bool BrowserView::IsMaximized() const { } bool BrowserView::IsMinimized() const { - // TODO(dhollowa): Add support for session restore of minimized state. - // http://crbug.com/43274 - return false; + return frame_->IsMinimized(); } void BrowserView::SetFullscreen(bool fullscreen) { @@ -1634,23 +1632,22 @@ std::wstring BrowserView::GetWindowName() const { } void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds, - bool maximized) { - // TODO(dhollowa): Add support for session restore of minimized state. - // http://crbug.com/43274 - + ui::WindowShowState show_state) { // If IsFullscreen() is true, we've just changed into fullscreen mode, and // we're catching the going-into-fullscreen sizing and positioning calls, // which we want to ignore. if (!IsFullscreen() && browser_->ShouldSaveWindowPlacement()) { - WidgetDelegate::SaveWindowPlacement(bounds, maximized); - browser_->SaveWindowPlacement(bounds, - maximized ? ui::SHOW_STATE_MAXIMIZED : - ui::SHOW_STATE_NORMAL); + WidgetDelegate::SaveWindowPlacement(bounds, show_state); + browser_->SaveWindowPlacement(bounds, show_state); } } -bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { +bool BrowserView::GetSavedWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const { *bounds = browser_->GetSavedWindowBounds(); + *show_state = browser_->GetSavedWindowShowState(); + if ((browser_->is_type_popup() || browser_->is_type_panel()) && !browser_->is_devtools()) { // We are a popup window. The value passed in |bounds| represents two @@ -1689,13 +1686,6 @@ bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { return true; } -bool BrowserView::GetSavedMaximizedState(bool* maximized) const { - // TODO(dhollowa): Add support for session restore of minimized state. - // http://crbug.com/43274 - *maximized = browser_->GetSavedWindowShowState() == ui::SHOW_STATE_MAXIMIZED; - return true; -} - views::View* BrowserView::GetContentsView() { return contents_container_; } diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index 9cf273c..bb660ad 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -394,9 +394,10 @@ class BrowserView : public BrowserBubbleHost, virtual bool ExecuteWindowsCommand(int command_id) OVERRIDE; virtual std::wstring GetWindowName() const OVERRIDE; virtual void SaveWindowPlacement(const gfx::Rect& bounds, - bool maximized) OVERRIDE; - virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const OVERRIDE; - virtual bool GetSavedMaximizedState(bool* maximized) const OVERRIDE; + ui::WindowShowState show_state) OVERRIDE; + virtual bool GetSavedWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE; virtual views::View* GetContentsView() OVERRIDE; virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE; virtual void OnWindowBeginUserBoundsChange() OVERRIDE; diff --git a/chrome/browser/ui/views/menu_model_adapter_test.cc b/chrome/browser/ui/views/menu_model_adapter_test.cc index a13e165..39a15da 100644 --- a/chrome/browser/ui/views/menu_model_adapter_test.cc +++ b/chrome/browser/ui/views/menu_model_adapter_test.cc @@ -44,16 +44,13 @@ class TestViewsDelegate : public views::ViewsDelegate { virtual void SaveWindowPlacement(const views::Widget* widget, const std::wstring& window_name, const gfx::Rect& bounds, - bool maximized) OVERRIDE { + ui::WindowShowState show_state) OVERRIDE { } - virtual bool GetSavedWindowBounds(const std::wstring& window_name, - gfx::Rect* bounds) const OVERRIDE { - return false; - } - - virtual bool GetSavedMaximizedState(const std::wstring& window_name, - bool* maximized) const OVERRIDE { + virtual bool GetSavedWindowPlacement( + const std::wstring& window_name, + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE { return false; } diff --git a/ui/base/ui_base_types.h b/ui/base/ui_base_types.h index 6a20bb5..89a00a2 100644 --- a/ui/base/ui_base_types.h +++ b/ui/base/ui_base_types.h @@ -16,7 +16,8 @@ enum WindowShowState { SHOW_STATE_NORMAL = 1, SHOW_STATE_MINIMIZED = 2, SHOW_STATE_MAXIMIZED = 3, - SHOW_STATE_MAX = 4 + SHOW_STATE_INACTIVE = 4, // Views only, not persisted. + SHOW_STATE_MAX = 5 }; } // namespace ui diff --git a/views/desktop/desktop_views_delegate.cc b/views/desktop/desktop_views_delegate.cc index 6e64702..b0f7ea2 100644 --- a/views/desktop/desktop_views_delegate.cc +++ b/views/desktop/desktop_views_delegate.cc @@ -35,17 +35,13 @@ View* DesktopViewsDelegate::GetDefaultParentView() { void DesktopViewsDelegate::SaveWindowPlacement(const Widget* widget, const std::wstring& window_name, const gfx::Rect& bounds, - bool maximized) { + ui::WindowShowState show_state) { } -bool DesktopViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name, - gfx::Rect* bounds) const { - return false; -} - -bool DesktopViewsDelegate::GetSavedMaximizedState( +bool DesktopViewsDelegate::GetSavedWindowPlacement( const std::wstring& window_name, - bool* maximized) const { + gfx::Rect* bounds, + ui::WindowShowState* show_state) const { return false; } diff --git a/views/desktop/desktop_views_delegate.h b/views/desktop/desktop_views_delegate.h index 145a29f..1704a97 100644 --- a/views/desktop/desktop_views_delegate.h +++ b/views/desktop/desktop_views_delegate.h @@ -23,11 +23,11 @@ class DesktopViewsDelegate : public ViewsDelegate { virtual void SaveWindowPlacement(const Widget* widget, const std::wstring& window_name, const gfx::Rect& bounds, - bool maximized) OVERRIDE; - virtual bool GetSavedWindowBounds(const std::wstring& window_name, - gfx::Rect* bounds) const OVERRIDE; - virtual bool GetSavedMaximizedState(const std::wstring& window_name, - bool* maximized) const OVERRIDE; + ui::WindowShowState show_state) OVERRIDE; + virtual bool GetSavedWindowPlacement( + const std::wstring& window_name, + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE; virtual void NotifyAccessibilityEvent( views::View* view, ui::AccessibilityTypes::Event event_type) OVERRIDE; virtual void NotifyMenuItemFocused( diff --git a/views/desktop/desktop_window_view.cc b/views/desktop/desktop_window_view.cc index dcd8a6a..f3033b2 100644 --- a/views/desktop/desktop_window_view.cc +++ b/views/desktop/desktop_window_view.cc @@ -135,7 +135,7 @@ void DesktopWindowView::CreateDesktopWindow(DesktopType type) { params.native_widget = new views::NativeWidgetWayland(window); #elif defined(TOOLKIT_USES_GTK) params.native_widget = new views::NativeWidgetGtk(window); - params.maximize = true; + params.show_state = ui::SHOW_STATE_MAXIMIZED; #endif params.bounds = gfx::Rect(20, 20, 1920, 1200); window->Init(params); diff --git a/views/test/test_views_delegate.cc b/views/test/test_views_delegate.cc index d25e729..7793dc4 100644 --- a/views/test/test_views_delegate.cc +++ b/views/test/test_views_delegate.cc @@ -31,13 +31,16 @@ View* TestViewsDelegate::GetDefaultParentView() { return default_parent_view_; } -bool TestViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name, - gfx::Rect* bounds) const { - return false; +void TestViewsDelegate::SaveWindowPlacement(const Widget* window, + const std::wstring& window_name, + const gfx::Rect& bounds, + ui::WindowShowState show_state) { } -bool TestViewsDelegate::GetSavedMaximizedState(const std::wstring& window_name, - bool* maximized) const { +bool TestViewsDelegate::GetSavedWindowPlacement( + const std::wstring& window_name, + gfx::Rect* bounds, + ui:: WindowShowState* show_state) const { return false; } diff --git a/views/test/test_views_delegate.h b/views/test/test_views_delegate.h index 82618ff..8d07bfc 100644 --- a/views/test/test_views_delegate.h +++ b/views/test/test_views_delegate.h @@ -35,12 +35,11 @@ class TestViewsDelegate : public ViewsDelegate { virtual void SaveWindowPlacement(const Widget* window, const std::wstring& window_name, const gfx::Rect& bounds, - bool maximized) OVERRIDE {} - virtual bool GetSavedWindowBounds(const std::wstring& window_name, - gfx::Rect* bounds) const OVERRIDE; - - virtual bool GetSavedMaximizedState(const std::wstring& window_name, - bool* maximized) const OVERRIDE; + ui::WindowShowState show_state) OVERRIDE; + virtual bool GetSavedWindowPlacement( + const std::wstring& window_name, + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE; virtual void NotifyAccessibilityEvent( View* view, ui::AccessibilityTypes::Event event_type) OVERRIDE {} diff --git a/views/views_delegate.h b/views/views_delegate.h index 13baff0..4b032c3 100644 --- a/views/views_delegate.h +++ b/views/views_delegate.h @@ -12,6 +12,7 @@ #endif #include "ui/base/accessibility/accessibility_types.h" +#include "ui/base/ui_base_types.h" #include "views/views_export.h" namespace gfx { @@ -46,22 +47,19 @@ class VIEWS_EXPORT ViewsDelegate { // TODO(beng): perhaps this should be a Widget. virtual View* GetDefaultParentView() = 0; - // Saves the position, size and maximized state for the window with the + // Saves the position, size and "show" state for the window with the // specified name. virtual void SaveWindowPlacement(const Widget* widget, const std::wstring& window_name, const gfx::Rect& bounds, - bool maximized) = 0; - - // Retrieves the saved position and size for the window with the specified - // name. - virtual bool GetSavedWindowBounds(const std::wstring& window_name, - gfx::Rect* bounds) const = 0; - - // Retrieves the saved maximized state for the window with the specified - // name. - virtual bool GetSavedMaximizedState(const std::wstring& window_name, - bool* maximized) const = 0; + ui::WindowShowState show_state) = 0; + + // Retrieves the saved position and size and "show" state for the window with + // the specified name. + virtual bool GetSavedWindowPlacement( + const std::wstring& window_name, + gfx::Rect* bounds, + ui::WindowShowState* show_state) const = 0; virtual void NotifyAccessibilityEvent( views::View* view, ui::AccessibilityTypes::Event event_type) = 0; diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc index dd57b00..3db5d91 100644 --- a/views/widget/native_widget_gtk.cc +++ b/views/widget/native_widget_gtk.cc @@ -1004,8 +1004,9 @@ void NativeWidgetGtk::CenterWindow(const gfx::Size& size) { SetBoundsConstrained(bounds, NULL); } -void NativeWidgetGtk::GetWindowBoundsAndMaximizedState(gfx::Rect* bounds, - bool* maximized) const { +void NativeWidgetGtk::GetWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const { // Do nothing for now. ChromeOS isn't yet saving window placement. } @@ -1186,9 +1187,9 @@ void NativeWidgetGtk::ShowMaximizedWithBounds( Show(); } -void NativeWidgetGtk::ShowWithState(ShowState state) { +void NativeWidgetGtk::ShowWithWindowState(ui::WindowShowState show_state) { // No concept of maximization (yet) on ChromeOS. - if (state == internal::NativeWidgetPrivate::SHOW_INACTIVE) + if (show_state == ui::SHOW_STATE_INACTIVE) gtk_window_set_focus_on_map(GetNativeWindow(), false); gtk_widget_show(GetNativeView()); } @@ -2076,10 +2077,14 @@ void NativeWidgetGtk::SaveWindowPosition() { if (!GetWidget()->widget_delegate()) return; - bool maximized = window_state_ & GDK_WINDOW_STATE_MAXIMIZED; + ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; + if (IsMaximized()) + show_state = ui::SHOW_STATE_MAXIMIZED; + else if (IsMinimized()) + show_state = ui::SHOW_STATE_MINIMIZED; GetWidget()->widget_delegate()->SaveWindowPlacement( GetWidget()->GetWindowScreenBounds(), - maximized); + show_state); } //////////////////////////////////////////////////////////////////////////////// diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h index 659db5f..798d035 100644 --- a/views/widget/native_widget_gtk.h +++ b/views/widget/native_widget_gtk.h @@ -166,8 +166,9 @@ class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate, virtual bool HasMouseCapture() const OVERRIDE; virtual InputMethod* CreateInputMethod() OVERRIDE; virtual void CenterWindow(const gfx::Size& size) OVERRIDE; - virtual void GetWindowBoundsAndMaximizedState(gfx::Rect* bounds, - bool* maximized) const OVERRIDE; + virtual void GetWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE; virtual void SetWindowTitle(const std::wstring& title) OVERRIDE; virtual void SetWindowIcons(const SkBitmap& window_icon, const SkBitmap& app_icon) OVERRIDE; @@ -192,7 +193,7 @@ class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate, virtual void Hide() OVERRIDE; virtual void ShowMaximizedWithBounds( const gfx::Rect& restored_bounds) OVERRIDE; - virtual void ShowWithState(ShowState state) OVERRIDE; + virtual void ShowWithWindowState(ui::WindowShowState window_state) OVERRIDE; virtual bool IsVisible() const OVERRIDE; virtual void Activate() OVERRIDE; virtual void Deactivate() OVERRIDE; diff --git a/views/widget/native_widget_private.h b/views/widget/native_widget_private.h index df332cf..dbeab12 100644 --- a/views/widget/native_widget_private.h +++ b/views/widget/native_widget_private.h @@ -137,10 +137,11 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget, // Centers the window and sizes it to the specified size. virtual void CenterWindow(const gfx::Size& size) = 0; - // Retrieves the window's current restored bounds and maximized state, for + // Retrieves the window's current restored bounds and "show" state, for // persisting. - virtual void GetWindowBoundsAndMaximizedState(gfx::Rect* bounds, - bool* maximized) const = 0; + virtual void GetWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const = 0; // Sets the NativeWindow title. virtual void SetWindowTitle(const std::wstring& title) = 0; @@ -156,12 +157,6 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget, virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) = 0; virtual void SetAccessibleState(ui::AccessibilityTypes::State state) = 0; - enum ShowState { - SHOW_RESTORED, - SHOW_MAXIMIZED, - SHOW_INACTIVE - }; - // Makes the NativeWindow modal. virtual void BecomeModal() = 0; @@ -184,7 +179,7 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget, // Invoked if the initial show should maximize the window. |restored_bounds| // is the bounds of the window when not maximized. virtual void ShowMaximizedWithBounds(const gfx::Rect& restored_bounds) = 0; - virtual void ShowWithState(ShowState state) = 0; + virtual void ShowWithWindowState(ui::WindowShowState show_state) = 0; virtual bool IsVisible() const = 0; virtual void Activate() = 0; virtual void Deactivate() = 0; diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc index eb7047f..017c80c 100644 --- a/views/widget/native_widget_views.cc +++ b/views/widget/native_widget_views.cc @@ -251,11 +251,11 @@ void NativeWidgetViews::CenterWindow(const gfx::Size& size) { size.width(), size.height()); } -void NativeWidgetViews::GetWindowBoundsAndMaximizedState( +void NativeWidgetViews::GetWindowPlacement( gfx::Rect* bounds, - bool* maximized) const { + ui::WindowShowState* show_state) const { *bounds = GetView()->bounds(); - *maximized = false; + *show_state = ui::SHOW_STATE_NORMAL; } void NativeWidgetViews::SetWindowTitle(const std::wstring& title) { @@ -349,7 +349,7 @@ void NativeWidgetViews::Hide() { ReleaseMouseCapture(); } -void NativeWidgetViews::ShowWithState(ShowState state) { +void NativeWidgetViews::ShowWithWindowState(ui::WindowShowState show_state) { Show(); } diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h index 2095d12..ceaccc4 100644 --- a/views/widget/native_widget_views.h +++ b/views/widget/native_widget_views.h @@ -78,8 +78,9 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate { virtual bool HasMouseCapture() const OVERRIDE; virtual InputMethod* CreateInputMethod() OVERRIDE; virtual void CenterWindow(const gfx::Size& size) OVERRIDE; - virtual void GetWindowBoundsAndMaximizedState(gfx::Rect* bounds, - bool* maximized) const OVERRIDE; + virtual void GetWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE; virtual void SetWindowTitle(const std::wstring& title) OVERRIDE; virtual void SetWindowIcons(const SkBitmap& window_icon, const SkBitmap& app_icon) OVERRIDE; @@ -104,7 +105,7 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate { virtual void Hide() OVERRIDE; virtual void ShowMaximizedWithBounds( const gfx::Rect& restored_bounds) OVERRIDE; - virtual void ShowWithState(ShowState state) OVERRIDE; + virtual void ShowWithWindowState(ui::WindowShowState window_state) OVERRIDE; virtual bool IsVisible() const OVERRIDE; virtual void Activate() OVERRIDE; virtual void Deactivate() OVERRIDE; diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc index 0e459c7..173ad25 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -627,11 +627,12 @@ void NativeWidgetWin::CenterWindow(const gfx::Size& size) { ui::CenterAndSizeWindow(parent, GetNativeView(), size, false); } -void NativeWidgetWin::GetWindowBoundsAndMaximizedState(gfx::Rect* bounds, - bool* maximized) const { +void NativeWidgetWin::GetWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const { WINDOWPLACEMENT wp; wp.length = sizeof(wp); - const bool succeeded = !!GetWindowPlacement(GetNativeView(), &wp); + const bool succeeded = !!::GetWindowPlacement(GetNativeView(), &wp); DCHECK(succeeded); if (bounds != NULL) { @@ -646,8 +647,14 @@ void NativeWidgetWin::GetWindowBoundsAndMaximizedState(gfx::Rect* bounds, mi.rcWork.top - mi.rcMonitor.top); } - if (maximized != NULL) - *maximized = (wp.showCmd == SW_SHOWMAXIMIZED); + if (show_state != NULL) { + if (wp.showCmd == SW_SHOWMAXIMIZED) + *show_state = ui::SHOW_STATE_MAXIMIZED; + else if (wp.showCmd == SW_SHOWMINIMIZED) + *show_state = ui::SHOW_STATE_MINIMIZED; + else + *show_state = ui::SHOW_STATE_NORMAL; + } } void NativeWidgetWin::SetWindowTitle(const std::wstring& title) { @@ -749,7 +756,7 @@ gfx::Rect NativeWidgetWin::GetRestoredBounds() const { return gfx::Rect(saved_window_info_.window_rect); gfx::Rect bounds; - GetWindowBoundsAndMaximizedState(&bounds, NULL); + GetWindowPlacement(&bounds, NULL); return bounds; } @@ -865,15 +872,18 @@ void NativeWidgetWin::ShowMaximizedWithBounds( SetWindowPlacement(hwnd(), &placement); } -void NativeWidgetWin::ShowWithState(ShowState state) { +void NativeWidgetWin::ShowWithWindowState(ui::WindowShowState show_state) { DWORD native_show_state; - switch (state) { - case SHOW_INACTIVE: + switch (show_state) { + case ui::SHOW_STATE_INACTIVE: native_show_state = SW_SHOWNOACTIVATE; break; - case SHOW_MAXIMIZED: + case ui::SHOW_STATE_MAXIMIZED: native_show_state = SW_SHOWMAXIMIZED; break; + case ui::SHOW_STATE_MINIMIZED: + native_show_state = SW_SHOWMINIMIZED; + break; default: native_show_state = GetShowState(); break; @@ -2164,8 +2174,10 @@ void NativeWidgetWin::SetInitParams(const Widget::InitParams& params) { // Set type-independent style attributes. if (params.child) style |= WS_CHILD | WS_VISIBLE; - if (params.maximize) + if (params.show_state == ui::SHOW_STATE_MAXIMIZED) style |= WS_MAXIMIZE; + if (params.show_state == ui::SHOW_STATE_MINIMIZED) + style |= WS_MINIMIZE; if (!params.accept_events) ex_style |= WS_EX_TRANSPARENT; if (!params.can_activate) diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h index c29d354..3cfa9c6 100644 --- a/views/widget/native_widget_win.h +++ b/views/widget/native_widget_win.h @@ -209,8 +209,9 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, virtual bool HasMouseCapture() const OVERRIDE; virtual InputMethod* CreateInputMethod() OVERRIDE; virtual void CenterWindow(const gfx::Size& size) OVERRIDE; - virtual void GetWindowBoundsAndMaximizedState(gfx::Rect* bounds, - bool* maximized) const OVERRIDE; + virtual void GetWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE; virtual void SetWindowTitle(const std::wstring& title) OVERRIDE; virtual void SetWindowIcons(const SkBitmap& window_icon, const SkBitmap& app_icon) OVERRIDE; @@ -235,7 +236,7 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, virtual void Hide() OVERRIDE; virtual void ShowMaximizedWithBounds( const gfx::Rect& restored_bounds) OVERRIDE; - virtual void ShowWithState(ShowState state) OVERRIDE; + virtual void ShowWithWindowState(ui::WindowShowState show_state) OVERRIDE; virtual bool IsVisible() const OVERRIDE; virtual void Activate() OVERRIDE; virtual void Deactivate() OVERRIDE; diff --git a/views/widget/widget.cc b/views/widget/widget.cc index 80ca73d..8ed6c8d 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -109,7 +109,7 @@ Widget::InitParams::InitParams() ownership(NATIVE_WIDGET_OWNS_WIDGET), mirror_origin_in_rtl(false), has_dropshadow(false), - maximize(false), + show_state(ui::SHOW_STATE_DEFAULT), double_buffer(false), parent(NULL), parent_widget(NULL), @@ -129,7 +129,7 @@ Widget::InitParams::InitParams(Type type) ownership(NATIVE_WIDGET_OWNS_WIDGET), mirror_origin_in_rtl(false), has_dropshadow(false), - maximize(false), + show_state(ui::SHOW_STATE_DEFAULT), double_buffer(false), parent(NULL), parent_widget(NULL), @@ -158,10 +158,11 @@ Widget::Widget() frame_type_(FRAME_TYPE_DEFAULT), disable_inactive_rendering_(false), widget_closed_(false), - saved_maximized_state_(false), + saved_show_state_(ui::SHOW_STATE_DEFAULT), minimum_size_(100, 100), focus_on_creation_(true), - is_top_level_(false) { + is_top_level_(false), + native_widget_initialized_(false) { } Widget::~Widget() { @@ -311,10 +312,13 @@ void Widget::Init(const InitParams& params) { non_client_view_->set_client_view(widget_delegate_->CreateClientView(this)); SetContentsView(non_client_view_); SetInitialBounds(params.bounds); - if (params.maximize) + if (params.show_state == ui::SHOW_STATE_MAXIMIZED) Maximize(); + else if (params.show_state == ui::SHOW_STATE_MINIMIZED) + Minimize(); UpdateWindowTitle(); } + native_widget_initialized_ = true; } // Unconverted methods (see header) -------------------------------------------- @@ -446,7 +450,7 @@ void Widget::Close() { if (non_client_view_) can_close = non_client_view_->CanClose(); if (can_close) { - SaveWindowPosition(); + SaveWindowPlacement(); // During tear-down the top-level focus manager becomes unavailable to // GTK tabbed panes and their children, so normal deregistration via @@ -473,17 +477,16 @@ void Widget::EnableClose(bool enable) { void Widget::Show() { if (non_client_view_) { - if (saved_maximized_state_ && !initial_restored_bounds_.IsEmpty()) { + if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED && + !initial_restored_bounds_.IsEmpty()) { native_widget_->ShowMaximizedWithBounds(initial_restored_bounds_); } else { - native_widget_->ShowWithState(saved_maximized_state_ ? - internal::NativeWidgetPrivate::SHOW_MAXIMIZED : - internal::NativeWidgetPrivate::SHOW_RESTORED); + native_widget_->ShowWithWindowState(saved_show_state_); } - // |saved_maximized_state_| only applies the first time the window is shown. - // If we don't reset the value the window will be shown maximized every time + // |saved_show_state_| only applies the first time the window is shown. + // If we don't reset the value the window may be shown maximized every time // it is subsequently shown after being hidden. - saved_maximized_state_ = false; + saved_show_state_ = ui::SHOW_STATE_NORMAL; } else { native_widget_->Show(); } @@ -494,14 +497,16 @@ void Widget::Hide() { } void Widget::ShowInactive() { - // If this gets called with saved_maximized_state_ == true, call SetBounds() - // with the restored bounds to set the correct size. This normally should - // not happen, but if it does we should avoid showing unsized windows. - if (saved_maximized_state_ && !initial_restored_bounds_.IsEmpty()) { + // If this gets called with saved_show_state_ == ui::SHOW_STATE_MAXIMIZED, + // call SetBounds()with the restored bounds to set the correct size. This + // normally should not happen, but if it does we should avoid showing unsized + // windows. + if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED && + !initial_restored_bounds_.IsEmpty()) { SetBounds(initial_restored_bounds_); - saved_maximized_state_ = false; + saved_show_state_ = ui::SHOW_STATE_NORMAL; } - native_widget_->ShowWithState(internal::NativeWidgetPrivate::SHOW_INACTIVE); + native_widget_->ShowWithWindowState(ui::SHOW_STATE_INACTIVE); } void Widget::Activate() { @@ -825,7 +830,7 @@ void Widget::EnableInactiveRendering() { void Widget::OnNativeWidgetActivationChanged(bool active) { if (!active) { - SaveWindowPosition(); + SaveWindowPlacement(); // Close any open menus. MenuController* menu_controller = MenuController::GetActiveInstance(); @@ -886,6 +891,12 @@ gfx::Size Widget::GetMinimumSize() { void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) { root_view_->SetSize(new_size); + + // Size changed notifications can fire prior to full initialization + // i.e. during session restore. Avoid saving session state during these + // startup procedures. + if (native_widget_initialized_) + SaveWindowPlacement(); } void Widget::OnNativeWidgetBeginUserBoundsChange() { @@ -1055,7 +1066,7 @@ bool Widget::ShouldReleaseCaptureOnMouseReleased() const { return true; } -void Widget::SaveWindowPosition() { +void Widget::SaveWindowPlacement() { // The window delegate does the actual saving for us. It seems like (judging // by go/crash) that in some circumstances we can end up here after // WM_DESTROY, at which point the window delegate is likely gone. So just @@ -1063,10 +1074,10 @@ void Widget::SaveWindowPosition() { if (!widget_delegate_) return; - bool maximized = false; + ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL; gfx::Rect bounds; - native_widget_->GetWindowBoundsAndMaximizedState(&bounds, &maximized); - widget_delegate_->SaveWindowPlacement(bounds, maximized); + native_widget_->GetWindowPlacement(&bounds, &show_state); + widget_delegate_->SaveWindowPlacement(bounds, show_state); } void Widget::SetInitialBounds(const gfx::Rect& bounds) { @@ -1074,8 +1085,8 @@ void Widget::SetInitialBounds(const gfx::Rect& bounds) { return; gfx::Rect saved_bounds; - if (GetSavedBounds(&saved_bounds, &saved_maximized_state_)) { - if (saved_maximized_state_) { + if (GetSavedWindowPlacement(&saved_bounds, &saved_show_state_)) { + if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED) { // If we're going to maximize, wait until Show is invoked to set the // bounds. That way we avoid a noticable resize. initial_restored_bounds_ = saved_bounds; @@ -1094,17 +1105,17 @@ void Widget::SetInitialBounds(const gfx::Rect& bounds) { } } -bool Widget::GetSavedBounds(gfx::Rect* bounds, bool* maximize) { +bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds, + ui::WindowShowState* show_state) { // First we obtain the window's saved show-style and store it. We need to do // this here, rather than in Show() because by the time Show() is called, // the window's size will have been reset (below) and the saved maximized // state will have been lost. Sadly there's no way to tell on Windows when // a window is restored from maximized state, so we can't more accurately // track maximized state independently of sizing information. - widget_delegate_->GetSavedMaximizedState(maximize); // Restore the window's placement from the controller. - if (widget_delegate_->GetSavedWindowBounds(bounds)) { + if (widget_delegate_->GetSavedWindowPlacement(bounds, show_state)) { if (!widget_delegate_->ShouldRestoreWindowSize()) { bounds->set_size(non_client_view_->GetPreferredSize()); } else { diff --git a/views/widget/widget.h b/views/widget/widget.h index a85b619..dd23dd6 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -12,6 +12,7 @@ #include "base/memory/scoped_ptr.h" #include "base/observer_list.h" #include "ui/base/accessibility/accessibility_types.h" +#include "ui/base/ui_base_types.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" #include "views/focus/focus_manager.h" @@ -144,8 +145,8 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, Ownership ownership; bool mirror_origin_in_rtl; bool has_dropshadow; - // Whether the widget should be maximized. - bool maximize; + // Whether the widget should be maximized or minimized. + ui::WindowShowState show_state; // Should the widget be double buffered? Default is false. bool double_buffer; gfx::NativeView parent; @@ -635,16 +636,17 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, // Returns whether capture should be released on mouse release. virtual bool ShouldReleaseCaptureOnMouseReleased() const; - // Persists the window's restored position and maximized state using the + // Persists the window's restored position and "show" state using the // window delegate. - void SaveWindowPosition(); + void SaveWindowPlacement(); // Sizes and positions the window just after it is created. void SetInitialBounds(const gfx::Rect& bounds); - // Returns the bounds and maximized state from the delegate. Returns true if + // Returns the bounds and "show" state from the delegate. Returns true if // the delegate wants to use a specified bounds. - bool GetSavedBounds(gfx::Rect* bounds, bool* maximize); + bool GetSavedWindowPlacement(gfx::Rect* bounds, + ui::WindowShowState* show_state); // Sets a different InputMethod instance to this widget. The instance // must not be initialized, the ownership will be assumed by the widget. @@ -703,12 +705,12 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, // Set to true if the widget is in the process of closing. bool widget_closed_; - // The saved maximized state for this window. See note in SetInitialBounds + // The saved "show" state for this window. See note in SetInitialBounds // that explains why we save this. - bool saved_maximized_state_; + ui::WindowShowState saved_show_state_; // The restored bounds used for the initial show. This is only used if - // |saved_maximized_state_| is true. + // |saved_show_state_| is maximized. gfx::Rect initial_restored_bounds_; // The smallest size the window can be. @@ -727,6 +729,9 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, // Factory used to create Compositors. Settable by tests. static ui::Compositor*(*compositor_factory_)(); + // Tracks whether native widget has been initialized. + bool native_widget_initialized_; + DISALLOW_COPY_AND_ASSIGN(Widget); }; diff --git a/views/widget/widget_delegate.cc b/views/widget/widget_delegate.cc index d031295..25cb54a 100644 --- a/views/widget/widget_delegate.cc +++ b/views/widget/widget_delegate.cc @@ -98,31 +98,24 @@ std::wstring WidgetDelegate::GetWindowName() const { } void WidgetDelegate::SaveWindowPlacement(const gfx::Rect& bounds, - bool maximized) { + ui::WindowShowState show_state) { std::wstring window_name = GetWindowName(); if (!ViewsDelegate::views_delegate || window_name.empty()) return; ViewsDelegate::views_delegate->SaveWindowPlacement( - GetWidget(), window_name, bounds, maximized); + GetWidget(), window_name, bounds, show_state); } -bool WidgetDelegate::GetSavedWindowBounds(gfx::Rect* bounds) const { +bool WidgetDelegate::GetSavedWindowPlacement( + gfx::Rect* bounds, + ui::WindowShowState* show_state) const { std::wstring window_name = GetWindowName(); if (!ViewsDelegate::views_delegate || window_name.empty()) return false; - return ViewsDelegate::views_delegate->GetSavedWindowBounds( - window_name, bounds); -} - -bool WidgetDelegate::GetSavedMaximizedState(bool* maximized) const { - std::wstring window_name = GetWindowName(); - if (!ViewsDelegate::views_delegate || window_name.empty()) - return false; - - return ViewsDelegate::views_delegate->GetSavedMaximizedState( - window_name, maximized); + return ViewsDelegate::views_delegate->GetSavedWindowPlacement( + window_name, bounds, show_state); } bool WidgetDelegate::ShouldRestoreWindowSize() const { diff --git a/views/widget/widget_delegate.h b/views/widget/widget_delegate.h index 85485e6..5c73d4d 100644 --- a/views/widget/widget_delegate.h +++ b/views/widget/widget_delegate.h @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "ui/base/accessibility/accessibility_types.h" +#include "ui/base/ui_base_types.h" #include "views/view.h" class SkBitmap; @@ -97,15 +98,16 @@ class VIEWS_EXPORT WidgetDelegate { // state restoration. virtual std::wstring GetWindowName() const; - // Saves the window's bounds and maximized states. By default this uses the + // Saves the window's bounds and "show" state. By default this uses the // process' local state keyed by window name (See GetWindowName above). This // behavior can be overridden to provide additional functionality. - virtual void SaveWindowPlacement(const gfx::Rect& bounds, bool maximized); + virtual void SaveWindowPlacement(const gfx::Rect& bounds, + ui::WindowShowState show_state); - // Retrieves the window's bounds and maximized states. + // Retrieves the window's bounds and "show" states. // This behavior can be overridden to provide additional functionality. - virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const; - virtual bool GetSavedMaximizedState(bool* maximized) const; + virtual bool GetSavedWindowPlacement(gfx::Rect* bounds, + ui::WindowShowState* show_state) const; // Returns true if the window's size should be restored. If this is false, // only the window's origin is restored and the window is given its |