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
Esse commit está contido em:
@@ -5,6 +5,7 @@
|
||||
#include "chrome/browser/task_manager.h"
|
||||
|
||||
#include "base/stats_table.h"
|
||||
#include "chrome/app/chrome_dll_resource.h"
|
||||
#include "chrome/browser/browser_list.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/common/pref_names.h"
|
||||
@@ -190,8 +191,7 @@ class TaskManagerViewImpl : public TaskManagerView,
|
||||
// views::DialogDelegate
|
||||
virtual bool CanResize() const;
|
||||
virtual bool CanMaximize() const;
|
||||
virtual bool IsAlwaysOnTop() const;
|
||||
virtual bool HasAlwaysOnTopMenu() const;
|
||||
virtual bool ExecuteWindowsCommand(int command_id);
|
||||
virtual std::wstring GetWindowTitle() const;
|
||||
virtual std::wstring GetWindowName() const;
|
||||
virtual int GetDialogButtons() const;
|
||||
@@ -220,6 +220,15 @@ class TaskManagerViewImpl : public TaskManagerView,
|
||||
virtual void ExecuteCommand(int id);
|
||||
|
||||
private:
|
||||
// Initializes the state of the always-on-top setting as the window is shown.
|
||||
void InitAlwaysOnTopState();
|
||||
|
||||
// Adds an always on top item to the window's system menu.
|
||||
void AddAlwaysOnTopSystemMenuItem();
|
||||
|
||||
// Restores saved always on top state from a previous session.
|
||||
bool GetSavedAlwaysOnTopState(bool* always_on_top) const;
|
||||
|
||||
scoped_ptr<views::NativeButton> kill_button_;
|
||||
scoped_ptr<views::Link> about_memory_link_;
|
||||
views::GroupTableView* tab_table_;
|
||||
@@ -233,13 +242,20 @@ class TaskManagerViewImpl : public TaskManagerView,
|
||||
|
||||
scoped_ptr<TaskManagerTableModel> table_model_;
|
||||
|
||||
// True when the Task Manager window should be shown on top of other windows.
|
||||
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_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(TaskManagerViewImpl);
|
||||
};
|
||||
|
||||
TaskManagerViewImpl::TaskManagerViewImpl(TaskManager* task_manager,
|
||||
TaskManagerModel* model)
|
||||
: task_manager_(task_manager),
|
||||
model_(model) {
|
||||
model_(model),
|
||||
is_always_on_top_(false) {
|
||||
Init();
|
||||
}
|
||||
|
||||
@@ -410,6 +426,7 @@ void TaskManagerViewImpl::OpenWindow() {
|
||||
window()->Activate();
|
||||
} else {
|
||||
views::Window::CreateChromeWindow(NULL, gfx::Rect(), this);
|
||||
InitAlwaysOnTopState();
|
||||
model_->StartUpdating();
|
||||
window()->Show();
|
||||
}
|
||||
@@ -430,13 +447,37 @@ bool TaskManagerViewImpl::CanMaximize() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TaskManagerViewImpl::IsAlwaysOnTop() const {
|
||||
return true;
|
||||
}
|
||||
bool TaskManagerViewImpl::ExecuteWindowsCommand(int command_id) {
|
||||
if (command_id == IDC_ALWAYS_ON_TOP) {
|
||||
is_always_on_top_ = !is_always_on_top_;
|
||||
|
||||
bool TaskManagerViewImpl::HasAlwaysOnTopMenu() const {
|
||||
return true;
|
||||
};
|
||||
// Change the menu check state.
|
||||
HMENU system_menu = GetSystemMenu(GetWindow()->GetNativeWindow(), 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.
|
||||
window()->SetIsAlwaysOnTop(is_always_on_top_);
|
||||
|
||||
// Save the state.
|
||||
if (g_browser_process->local_state()) {
|
||||
DictionaryValue* window_preferences =
|
||||
g_browser_process->local_state()->GetMutableDictionary(
|
||||
GetWindowName().c_str());
|
||||
window_preferences->SetBoolean(L"always_on_top", is_always_on_top_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring TaskManagerViewImpl::GetWindowTitle() const {
|
||||
return l10n_util::GetString(IDS_TASK_MANAGER_TITLE);
|
||||
@@ -515,6 +556,54 @@ void TaskManagerViewImpl::ExecuteCommand(int id) {
|
||||
tab_table_->SetColumnVisibility(id, !tab_table_->IsColumnVisible(id));
|
||||
}
|
||||
|
||||
void TaskManagerViewImpl::InitAlwaysOnTopState() {
|
||||
is_always_on_top_ = false;
|
||||
if (GetSavedAlwaysOnTopState(&is_always_on_top_))
|
||||
window()->SetIsAlwaysOnTop(is_always_on_top_);
|
||||
AddAlwaysOnTopSystemMenuItem();
|
||||
}
|
||||
|
||||
void TaskManagerViewImpl::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(GetWindow()->GetNativeWindow(), 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);
|
||||
}
|
||||
|
||||
bool TaskManagerViewImpl::GetSavedAlwaysOnTopState(bool* always_on_top) const {
|
||||
if (!g_browser_process->local_state())
|
||||
return false;
|
||||
|
||||
const DictionaryValue* dictionary =
|
||||
g_browser_process->local_state()->GetDictionary(GetWindowName().c_str());
|
||||
return dictionary &&
|
||||
dictionary->GetBoolean(L"always_on_top", always_on_top) && always_on_top;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void TaskManager::Init() {
|
||||
|
||||
@@ -19,8 +19,7 @@ Clipboard* ChromeViewsDelegate::GetClipboard() const {
|
||||
|
||||
void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name,
|
||||
const gfx::Rect& bounds,
|
||||
bool maximized,
|
||||
bool always_on_top) {
|
||||
bool maximized) {
|
||||
if (!g_browser_process->local_state())
|
||||
return;
|
||||
|
||||
@@ -32,7 +31,6 @@ void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name,
|
||||
window_preferences->SetInteger(L"right", bounds.right());
|
||||
window_preferences->SetInteger(L"bottom", bounds.bottom());
|
||||
window_preferences->SetBoolean(L"maximized", maximized);
|
||||
window_preferences->SetBoolean(L"always_on_top", always_on_top);
|
||||
}
|
||||
|
||||
bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name,
|
||||
@@ -65,18 +63,6 @@ bool ChromeViewsDelegate::GetSavedMaximizedState(
|
||||
maximized;
|
||||
}
|
||||
|
||||
bool ChromeViewsDelegate::GetSavedAlwaysOnTopState(
|
||||
const std::wstring& window_name,
|
||||
bool* always_on_top) const {
|
||||
if (!g_browser_process->local_state())
|
||||
return false;
|
||||
|
||||
const DictionaryValue* dictionary =
|
||||
g_browser_process->local_state()->GetDictionary(window_name.c_str());
|
||||
return dictionary && dictionary->GetBoolean(L"always_on_top", always_on_top) &&
|
||||
always_on_top;
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
HICON ChromeViewsDelegate::GetDefaultWindowIcon() const {
|
||||
return LoadIcon(GetModuleHandle(L"chrome.dll"),
|
||||
|
||||
@@ -17,14 +17,11 @@ class ChromeViewsDelegate : public views::ViewsDelegate {
|
||||
virtual Clipboard* GetClipboard() const;
|
||||
virtual void SaveWindowPlacement(const std::wstring& window_name,
|
||||
const gfx::Rect& bounds,
|
||||
bool maximized,
|
||||
bool always_on_top);
|
||||
bool maximized);
|
||||
virtual bool GetSavedWindowBounds(const std::wstring& window_name,
|
||||
gfx::Rect* bounds) const;
|
||||
virtual bool GetSavedMaximizedState(const std::wstring& window_name,
|
||||
bool* maximized) const;
|
||||
virtual bool GetSavedAlwaysOnTopState(const std::wstring& window_name,
|
||||
bool* always_on_top) const;
|
||||
#if defined(OS_WIN)
|
||||
virtual HICON GetDefaultWindowIcon() const;
|
||||
#endif
|
||||
|
||||
@@ -1008,13 +1008,12 @@ std::wstring BrowserView::GetWindowName() const {
|
||||
}
|
||||
|
||||
void BrowserView::SaveWindowPlacement(const gfx::Rect& bounds,
|
||||
bool maximized,
|
||||
bool always_on_top) {
|
||||
bool maximized) {
|
||||
// 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()) {
|
||||
WindowDelegate::SaveWindowPlacement(bounds, maximized, always_on_top);
|
||||
WindowDelegate::SaveWindowPlacement(bounds, maximized);
|
||||
browser_->SaveWindowPlacement(bounds, maximized);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,8 +235,7 @@ class BrowserView : public BrowserWindow,
|
||||
virtual bool ExecuteWindowsCommand(int command_id);
|
||||
virtual std::wstring GetWindowName() const;
|
||||
virtual void SaveWindowPlacement(const gfx::Rect& bounds,
|
||||
bool maximized,
|
||||
bool always_on_top);
|
||||
bool maximized);
|
||||
virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const;
|
||||
virtual bool GetSavedMaximizedState(bool* maximized) const;
|
||||
virtual views::View* GetContentsView();
|
||||
|
||||
@@ -562,7 +562,7 @@ void PageInfoWindow::Init(Profile* profile,
|
||||
if (GetSavedWindowBounds(&bounds) && GetSavedMaximizedState(&maximized)) {
|
||||
CRect bounds_crect(bounds.ToRECT());
|
||||
CalculateWindowBounds(&bounds_crect);
|
||||
SaveWindowPlacement(gfx::Rect(bounds_crect), maximized, false);
|
||||
SaveWindowPlacement(gfx::Rect(bounds_crect), maximized);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
// 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, 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.
|
||||
// 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() { }
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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_;
|
||||
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário