diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-14 00:29:05 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-14 00:29:05 +0000 |
commit | 15952e462a8d6ef6d555219d0af62ceae093a173 (patch) | |
tree | 530c1a3e238e3ca7488b5589c49480df51f7378d /chrome/views/window.cc | |
parent | d6dfe0d2402e2dbf997833f2deaf5b4a55b9b40a (diff) | |
download | chromium_src-15952e462a8d6ef6d555219d0af62ceae093a173.zip chromium_src-15952e462a8d6ef6d555219d0af62ceae093a173.tar.gz chromium_src-15952e462a8d6ef6d555219d0af62ceae093a173.tar.bz2 |
Re-do the way browser windows are shown:
- Remove the path from WinMain to the Browser object passing the show_command. For the Browser object, this is a problem since this value isn't portable. For the code in general it involves a lot of ugly wiring. It's completely unnecessary since the value is obtainable via GetStartupInfo.
- Remove show_command plumbing from all over the place (session restore, web app launcher, etc)
Change the way browser windows are constructed:
- The browser constructor now takes just a type and a profile, and simply initializes the object.
- Some configuration that used to be part of the constructor that was only used in one or two use cases (initial bounds, maximized state, web app name) are split into separate setters.
- Window creation is split out into a separate step to be called post configuration.
- Assorted static helper functions added to Browser to make construction of common types easy.
- Remove Browser::Show in favor of BrowserWindow::Show
- Adjust all callers to use the new helpers.
Change the way ChromeViews restores window placement:
- Split restored size determination from restored maximized determination. They are needed by the code at different times. Size restoration happens when the window is constructed and Window::SetInitialBounds is called. Maximized state restoration happens when the window is shown for the first time and SW_SHOWMAXIMIZED or SW_SHOWNORMAL is needed. Thus, replace WindowDelegate::RestoreWindowPosition with WindowDelegate::RestoreWindowBounds and WindowDelegate::RestoreMaximizedState.
- Window::SetInitialBounds calls WindowDelegate::RestoreWindowBounds
- Window::Show calls WindowDelegate::RestoreMaximizedState
- Adjusts all WindowDelegate implementations that override RestoreWindowPosition to implement these new methods instead.
- Move "playback/record" mode window size setting from browser_init to Browser::RestoreWindowBounds.
- Provide a virtual function on Window called GetShowState that determines the default show state to be used when Window::Show is called. For most windows and dialogs this is SW_SHOWNORMAL. AeroGlassFrame/OpaqueFrame (the browser window frames) override this since they're the app's main windows to return the value provided by GetStartupInfo which gives the value from the app shortcut.
http://crbug.com/3557
Review URL: http://codereview.chromium.org/10896
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5417 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views/window.cc')
-rw-r--r-- | chrome/views/window.cc | 122 |
1 files changed, 39 insertions, 83 deletions
diff --git a/chrome/views/window.cc b/chrome/views/window.cc index 2f7b4f6..fb7d945 100644 --- a/chrome/views/window.cc +++ b/chrome/views/window.cc @@ -85,14 +85,22 @@ gfx::Size Window::CalculateMaximumSize() const { } void Window::Show() { - Show(SW_SHOW); + int show_state = GetShowState(); + bool maximized = false; + if (window_delegate_->GetSavedMaximizedState(&maximized) && maximized) + show_state = SW_SHOWMAXIMIZED; + Show(show_state); } -void Window::Show(int show_style) { - ShowWindow(show_style); +void Window::Show(int show_state) { + ShowWindow(show_state); SetInitialFocus(); } +int Window::GetShowState() const { + return SW_SHOWNORMAL; +} + void Window::Activate() { if (IsMinimized()) ::ShowWindow(GetHWND(), SW_RESTORE); @@ -193,56 +201,6 @@ void Window::ExecuteSystemMenuCommand(int command) { } // static -bool Window::SaveWindowPositionToPrefService(PrefService* pref_service, - const std::wstring& entry, - const CRect& bounds, - bool maximized, - bool always_on_top) { - DCHECK(pref_service); - DictionaryValue* win_pref = pref_service->GetMutableDictionary(entry.c_str()); - DCHECK(win_pref); - - win_pref->SetInteger(L"left", bounds.left); - win_pref->SetInteger(L"top", bounds.top); - win_pref->SetInteger(L"right", bounds.right); - win_pref->SetInteger(L"bottom", bounds.bottom); - win_pref->SetBoolean(L"maximized", maximized); - win_pref->SetBoolean(L"always_on_top", always_on_top); - return true; -} - -// static -bool Window::RestoreWindowPositionFromPrefService(PrefService* pref_service, - const std::wstring& entry, - CRect* bounds, - bool* maximized, - bool* always_on_top) { - DCHECK(pref_service); - DCHECK(bounds); - DCHECK(maximized); - DCHECK(always_on_top); - - const DictionaryValue* dictionary = pref_service->GetDictionary(entry.c_str()); - if (!dictionary) - return false; - - int left, top, right, bottom; - bool temp_maximized, temp_always_on_top; - if (!dictionary || !dictionary->GetInteger(L"left", &left) || - !dictionary->GetInteger(L"top", &top) || - !dictionary->GetInteger(L"right", &right) || - !dictionary->GetInteger(L"bottom", &bottom) || - !dictionary->GetBoolean(L"maximized", &temp_maximized) || - !dictionary->GetBoolean(L"always_on_top", &temp_always_on_top)) - return false; - - bounds->SetRect(left, top, right, bottom); - *maximized = temp_maximized; - *always_on_top = temp_always_on_top; - return true; -} - -// static gfx::Size Window::GetLocalizedContentsSize(int col_resource_id, int row_resource_id) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); @@ -312,9 +270,7 @@ void Window::Init(HWND parent, const gfx::Rect& bounds) { SetClientView(window_delegate_->CreateClientView(this)); SetInitialBounds(bounds); - - if (window_delegate_->HasAlwaysOnTopMenu()) - AddAlwaysOnTopSystemMenuItem(); + InitAlwaysOnTopState(); } void Window::SetClientView(ClientView* client_view) { @@ -513,35 +469,25 @@ void Window::SetInitialFocus() { void Window::SetInitialBounds(const gfx::Rect& create_bounds) { // Restore the window's placement from the controller. - CRect saved_bounds(create_bounds.ToRECT()); - bool maximized = false; - if (window_delegate_->RestoreWindowPosition(&saved_bounds, - &maximized, - &is_always_on_top_)) { + gfx::Rect saved_bounds(create_bounds.ToRECT()); + if (window_delegate_->GetSavedWindowBounds(&saved_bounds)) { // Make sure the bounds are at least the minimum size. - if (saved_bounds.Width() < minimum_size_.cx) { - saved_bounds.SetRect(saved_bounds.left, saved_bounds.top, - saved_bounds.right + minimum_size_.cx - - saved_bounds.Width(), - saved_bounds.bottom); + if (saved_bounds.width() < minimum_size_.cx) { + saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(), + saved_bounds.right() + minimum_size_.cx - + saved_bounds.width(), + saved_bounds.bottom()); } - if (saved_bounds.Height() < minimum_size_.cy) { - saved_bounds.SetRect(saved_bounds.left, saved_bounds.top, - saved_bounds.right, - saved_bounds.bottom + minimum_size_.cy - - saved_bounds.Height()); + if (saved_bounds.height() < minimum_size_.cy) { + saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(), + saved_bounds.right(), + saved_bounds.bottom() + minimum_size_.cy - + saved_bounds.height()); } - WINDOWPLACEMENT placement = {0}; - placement.length = sizeof(WINDOWPLACEMENT); - placement.rcNormalPosition = saved_bounds; - if (maximized) - placement.showCmd = SW_SHOWMAXIMIZED; - ::SetWindowPlacement(GetHWND(), &placement); - - if (is_always_on_top_ != window_delegate_->IsAlwaysOnTop()) - AlwaysOnTopChanged(); + // "Show state" (maximized, minimized, etc) is handled by Show(). + SetBounds(saved_bounds, NULL); } else { if (create_bounds.IsEmpty()) { // No initial bounds supplied, so size the window to its content and @@ -554,6 +500,17 @@ void Window::SetInitialBounds(const gfx::Rect& create_bounds) { } } +void Window::InitAlwaysOnTopState() { + is_always_on_top_ = false; + if (window_delegate_->GetSavedAlwaysOnTopState(&is_always_on_top_) && + is_always_on_top_ != window_delegate_->IsAlwaysOnTop()) { + AlwaysOnTopChanged(); + } + + if (window_delegate_->HasAlwaysOnTopMenu()) + AddAlwaysOnTopSystemMenuItem(); +} + void Window::AddAlwaysOnTopSystemMenuItem() { // The Win32 API requires that we own the text. always_on_top_menu_text_ = l10n_util::GetString(IDS_ALWAYS_ON_TOP); @@ -643,9 +600,8 @@ void Window::SaveWindowPosition() { bool maximized = (win_placement.showCmd == SW_SHOWMAXIMIZED); CRect window_bounds(win_placement.rcNormalPosition); - window_delegate_->SaveWindowPosition(window_bounds, - maximized, - is_always_on_top_); + window_delegate_->SaveWindowPlacement( + gfx::Rect(win_placement.rcNormalPosition), maximized, is_always_on_top_); } void Window::InitClass() { |