diff options
author | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 21:35:59 +0000 |
---|---|---|
committer | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 21:35:59 +0000 |
commit | 5623c4aa4307e2a4843ffca845d8bc2c932d110a (patch) | |
tree | 60caf94fcc4c44514af3ff199a5ed2eb8a131eef /views | |
parent | 9f0728516ece1c689a11332819c9bd0be83dd6f2 (diff) | |
download | chromium_src-5623c4aa4307e2a4843ffca845d8bc2c932d110a.zip chromium_src-5623c4aa4307e2a4843ffca845d8bc2c932d110a.tar.gz chromium_src-5623c4aa4307e2a4843ffca845d8bc2c932d110a.tar.bz2 |
Move Always On Top setting out of Window/WindowDelegate and into task manager. It's the only one who uses this setting and the UI for exposing it is very specific to the task manager. Window retains a setter to set always on top state, but persistence and the system menu is Task Manager's responsbility. This allows us to sever the second-to-last chrome dependency from views.
http://crbug.com/11674
Review URL: http://codereview.chromium.org/115378
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16107 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/DEPS | 6 | ||||
-rw-r--r-- | views/views_delegate.h | 12 | ||||
-rw-r--r-- | views/window/window.h | 3 | ||||
-rw-r--r-- | views/window/window_delegate.cc | 15 | ||||
-rw-r--r-- | views/window/window_delegate.h | 34 | ||||
-rw-r--r-- | views/window/window_gtk.cc | 4 | ||||
-rw-r--r-- | views/window/window_gtk.h | 1 | ||||
-rw-r--r-- | views/window/window_win.cc | 84 | ||||
-rw-r--r-- | views/window/window_win.h | 17 |
9 files changed, 30 insertions, 146 deletions
@@ -3,12 +3,6 @@ include_rules = [ "+skia/ext", "+skia/include", - # TODO(beng): sever these dependencies into chrome by either refactoring or - # moving code into app/ - - # widget_win.cc - "+chrome/app/chrome_dll_resource.h", - # TODO(beng): swap these with app/views specific generated resources. "+grit/generated_resources.h", "+grit/theme_resources.h", diff --git a/views/views_delegate.h b/views/views_delegate.h index 082689c..6fe7f74 100644 --- a/views/views_delegate.h +++ b/views/views_delegate.h @@ -28,12 +28,11 @@ class ViewsDelegate { // Gets the clipboard. virtual Clipboard* GetClipboard() const = 0; - // Saves the position, size, maximized and always-on-top state for the - // window with the specified name. + // Saves the position, size and maximized state for the window with the + // specified name. virtual void SaveWindowPlacement(const std::wstring& window_name, const gfx::Rect& bounds, - bool maximized, - bool always_on_top) = 0; + bool maximized) = 0; // Retrieves the saved position and size for the window with the specified // name. @@ -45,11 +44,6 @@ class ViewsDelegate { virtual bool GetSavedMaximizedState(const std::wstring& window_name, bool* maximized) const = 0; - // Retrieves the saved always-on-top state for the window with the specified - // name. - virtual bool GetSavedAlwaysOnTopState(const std::wstring& window_name, - bool* always_on_top) const = 0; - #if defined(OS_WIN) // Retrieves the default window icon to use for windows if none is specified. virtual HICON GetDefaultWindowIcon() const = 0; diff --git a/views/window/window.h b/views/window/window.h index 17a2ff5..9d29a81 100644 --- a/views/window/window.h +++ b/views/window/window.h @@ -111,6 +111,9 @@ class Window { // Tell the window to update its icon from the delegate. virtual void UpdateWindowIcon() = 0; + // Sets whether or not the window is always-on-top. + virtual void SetIsAlwaysOnTop(bool always_on_top) = 0; + // Creates an appropriate NonClientFrameView for this window. virtual NonClientFrameView* CreateFrameViewForWindow() = 0; diff --git a/views/window/window_delegate.cc b/views/window/window_delegate.cc index ac5816f..4ac4d80 100644 --- a/views/window/window_delegate.cc +++ b/views/window/window_delegate.cc @@ -23,14 +23,13 @@ SkBitmap WindowDelegate::GetWindowIcon() { } void WindowDelegate::SaveWindowPlacement(const gfx::Rect& bounds, - bool maximized, - bool always_on_top) { + bool maximized) { std::wstring window_name = GetWindowName(); if (!ViewsDelegate::views_delegate || window_name.empty()) return; ViewsDelegate::views_delegate->SaveWindowPlacement( - window_name, bounds, maximized, always_on_top); + window_name, bounds, maximized); } bool WindowDelegate::GetSavedWindowBounds(gfx::Rect* bounds) const { @@ -51,16 +50,6 @@ bool WindowDelegate::GetSavedMaximizedState(bool* maximized) const { window_name, maximized); } -bool WindowDelegate::GetSavedAlwaysOnTopState(bool* always_on_top) const { - std::wstring window_name = GetWindowName(); - if (!ViewsDelegate::views_delegate || window_name.empty()) - return false; - - return ViewsDelegate::views_delegate->GetSavedAlwaysOnTopState( - window_name, always_on_top); -} - - ClientView* WindowDelegate::CreateClientView(Window* window) { return new ClientView(window, GetContentsView()); } diff --git a/views/window/window_delegate.h b/views/window/window_delegate.h index 992e94a..e790ff6 100644 --- a/views/window/window_delegate.h +++ b/views/window/window_delegate.h @@ -53,20 +53,6 @@ class WindowDelegate { return false; } - // Returns true if the window should be placed on top of all other windows on - // the system, even when it is not active. If HasAlwaysOnTopMenu() returns - // true, then this method is only used the first time the window is opened, it - // is stored in the preferences for next runs. - virtual bool IsAlwaysOnTop() const { - return false; - } - - // Returns whether an "always on top" menu should be added to the system menu - // of the window. - virtual bool HasAlwaysOnTopMenu() const { - return false; - } - // Returns true if the dialog should be displayed modally to the window that // opened it. Only windows with WindowType == DIALOG can be modal. virtual bool IsModal() const { @@ -105,21 +91,15 @@ class WindowDelegate { return std::wstring(); } - // Saves the window's bounds, maximized and always-on-top states. 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, - bool always_on_top); - - // Retrieves the window's bounds, maximized and always-on-top states. By - // default, this uses the process' local state keyed by window name (See - // GetWindowName above). This behavior can be overridden to provide - // additional functionality. + // Saves the window's bounds and maximized states. 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); + + // Retrieves the window's bounds and maximized 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 GetSavedAlwaysOnTopState(bool* always_on_top) const; // Called when the window closes. virtual void WindowClosing() { } diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc index a8c710c..37ff816 100644 --- a/views/window/window_gtk.cc +++ b/views/window/window_gtk.cc @@ -129,6 +129,10 @@ void WindowGtk::UpdateWindowIcon() { NOTIMPLEMENTED(); } +void WindowGtk::SetIsAlwaysOnTop(bool always_on_top) { + NOTIMPLEMENTED(); +} + NonClientFrameView* WindowGtk::CreateFrameViewForWindow() { // TODO(erg): Always use a custom frame view? Are there cases where we let // the window manager deal with the X11 equivalent of the "non-client" area? diff --git a/views/window/window_gtk.h b/views/window/window_gtk.h index 224c85a5..ac33495 100644 --- a/views/window/window_gtk.h +++ b/views/window/window_gtk.h @@ -46,6 +46,7 @@ class WindowGtk : public WidgetGtk, public Window { virtual void DisableInactiveRendering(); virtual void UpdateWindowTitle(); virtual void UpdateWindowIcon(); + virtual void SetIsAlwaysOnTop(bool always_on_top); virtual NonClientFrameView* CreateFrameViewForWindow(); virtual void UpdateFrameAfterFrameChange(); virtual WindowDelegate* GetDelegate() const; diff --git a/views/window/window_win.cc b/views/window/window_win.cc index 40ec924..c5c92c7 100644 --- a/views/window/window_win.cc +++ b/views/window/window_win.cc @@ -14,7 +14,6 @@ #include "app/resource_bundle.h" #include "app/win_util.h" #include "base/win_util.h" -#include "chrome/app/chrome_dll_resource.h" #include "grit/generated_resources.h" #include "views/widget/root_view.h" #include "views/window/client_view.h" @@ -401,6 +400,13 @@ void WindowWin::UpdateWindowIcon() { } } +void WindowWin::SetIsAlwaysOnTop(bool always_on_top) { + ::SetWindowPos(GetNativeView(), + always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST, + 0, 0, 0, 0, + SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); +} + NonClientFrameView* WindowWin::CreateFrameViewForWindow() { if (non_client_view_->UseNativeFrame()) return new NativeFrameView(this); @@ -440,7 +446,6 @@ WindowWin::WindowWin(WindowDelegate* window_delegate) minimum_size_(100, 100), is_modal_(false), restored_enabled_(false), - is_always_on_top_(false), fullscreen_(false), window_closed_(false), disable_inactive_rendering_(false), @@ -471,7 +476,6 @@ void WindowWin::Init(HWND parent, const gfx::Rect& bounds) { is_modal_ = window_delegate_->IsModal(); if (is_modal_) BecomeModal(); - is_always_on_top_ = window_delegate_->IsAlwaysOnTop(); if (window_style() == 0) set_window_style(CalculateWindowStyle()); @@ -489,7 +493,6 @@ void WindowWin::Init(HWND parent, const gfx::Rect& bounds) { UpdateWindowTitle(); SetInitialBounds(bounds); - InitAlwaysOnTopState(); GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_, &last_work_area_); @@ -1056,25 +1059,7 @@ void WindowWin::OnSysCommand(UINT notification_code, CPoint click) { if (window_delegate_->ExecuteWindowsCommand(notification_code)) return; - if (notification_code == IDC_ALWAYS_ON_TOP) { - is_always_on_top_ = !is_always_on_top_; - - // Change the menu check state. - HMENU system_menu = GetSystemMenu(GetNativeView(), FALSE); - MENUITEMINFO menu_info; - memset(&menu_info, 0, sizeof(MENUITEMINFO)); - menu_info.cbSize = sizeof(MENUITEMINFO); - BOOL r = GetMenuItemInfo(system_menu, IDC_ALWAYS_ON_TOP, - FALSE, &menu_info); - DCHECK(r); - menu_info.fMask = MIIM_STATE; - if (is_always_on_top_) - menu_info.fState = MFS_CHECKED; - r = SetMenuItemInfo(system_menu, IDC_ALWAYS_ON_TOP, FALSE, &menu_info); - - // Now change the actual window's behavior. - AlwaysOnTopChanged(); - } else if ((notification_code == SC_KEYMENU) && (click.x == VK_SPACE)) { + if ((notification_code == SC_KEYMENU) && (click.x == VK_SPACE)) { // Run the system menu at the NonClientView's desired location. RunSystemMenu(non_client_view_->GetSystemMenuPoint()); } else { @@ -1229,48 +1214,6 @@ void WindowWin::SetInitialBounds(const gfx::Rect& create_bounds) { } } -void WindowWin::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 WindowWin::AddAlwaysOnTopSystemMenuItem() { - // The Win32 API requires that we own the text. - always_on_top_menu_text_ = l10n_util::GetString(IDS_ALWAYS_ON_TOP); - - // Let's insert a menu to the window. - HMENU system_menu = ::GetSystemMenu(GetNativeView(), FALSE); - int index = ::GetMenuItemCount(system_menu) - 1; - if (index < 0) { - // Paranoia check. - NOTREACHED(); - index = 0; - } - // First we add the separator. - MENUITEMINFO menu_info; - memset(&menu_info, 0, sizeof(MENUITEMINFO)); - menu_info.cbSize = sizeof(MENUITEMINFO); - menu_info.fMask = MIIM_FTYPE; - menu_info.fType = MFT_SEPARATOR; - ::InsertMenuItem(system_menu, index, TRUE, &menu_info); - - // Then the actual menu. - menu_info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE; - menu_info.fType = MFT_STRING; - menu_info.fState = MFS_ENABLED; - if (is_always_on_top_) - menu_info.fState |= MFS_CHECKED; - menu_info.wID = IDC_ALWAYS_ON_TOP; - menu_info.dwTypeData = const_cast<wchar_t*>(always_on_top_menu_text_.c_str()); - ::InsertMenuItem(system_menu, index, TRUE, &menu_info); -} - void WindowWin::RestoreEnabledIfNecessary() { if (is_modal_ && !restored_enabled_) { restored_enabled_ = true; @@ -1284,13 +1227,6 @@ void WindowWin::RestoreEnabledIfNecessary() { } } -void WindowWin::AlwaysOnTopChanged() { - ::SetWindowPos(GetNativeView(), - is_always_on_top_ ? HWND_TOPMOST : HWND_NOTOPMOST, - 0, 0, 0, 0, - SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); -} - DWORD WindowWin::CalculateWindowStyle() { DWORD window_styles = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_SYSMENU | WS_CAPTION; @@ -1316,8 +1252,6 @@ DWORD WindowWin::CalculateWindowExStyle() { DWORD window_ex_styles = 0; if (window_delegate_->AsDialogDelegate()) window_ex_styles |= WS_EX_DLGMODALFRAME; - if (window_delegate_->IsAlwaysOnTop()) - window_ex_styles |= WS_EX_TOPMOST; return window_ex_styles; } @@ -1338,7 +1272,7 @@ void WindowWin::SaveWindowPosition() { bool maximized = (win_placement.showCmd == SW_SHOWMAXIMIZED); CRect window_bounds(win_placement.rcNormalPosition); window_delegate_->SaveWindowPlacement( - gfx::Rect(win_placement.rcNormalPosition), maximized, is_always_on_top_); + gfx::Rect(win_placement.rcNormalPosition), maximized); } void WindowWin::LockUpdates() { diff --git a/views/window/window_win.h b/views/window/window_win.h index 5a90835..1760caa 100644 --- a/views/window/window_win.h +++ b/views/window/window_win.h @@ -80,6 +80,7 @@ class WindowWin : public WidgetWin, virtual void DisableInactiveRendering(); virtual void UpdateWindowTitle(); virtual void UpdateWindowIcon(); + virtual void SetIsAlwaysOnTop(bool always_on_top); virtual NonClientFrameView* CreateFrameViewForWindow(); virtual void UpdateFrameAfterFrameChange(); virtual WindowDelegate* GetDelegate() const; @@ -163,19 +164,9 @@ class WindowWin : public WidgetWin, // bounds used when the window was created. void SetInitialBounds(const gfx::Rect& create_bounds); - // Restore saved always on stop state and add the always on top system menu - // if needed. - void InitAlwaysOnTopState(); - - // Add an item for "Always on Top" to the System Menu. - void AddAlwaysOnTopSystemMenuItem(); - // If necessary, enables all ancestors. void RestoreEnabledIfNecessary(); - // Update the window style to reflect the always on top state. - void AlwaysOnTopChanged(); - // Calculate the appropriate window styles for this window. DWORD CalculateWindowStyle(); DWORD CalculateWindowExStyle(); @@ -245,12 +236,6 @@ class WindowWin : public WidgetWin, // true. bool restored_enabled_; - // Whether the window is currently always on top. - bool is_always_on_top_; - - // We need to own the text of the menu, the Windows API does not copy it. - std::wstring always_on_top_menu_text_; - // True if we're in fullscreen mode. bool fullscreen_; |