summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/ui/views/app_menu_button_win.cc23
-rw-r--r--chrome/browser/ui/views/app_menu_button_win.h24
-rw-r--r--chrome/browser/ui/views/toolbar_view.cc5
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--ui/base/win/hwnd_util.cc12
-rw-r--r--ui/base/win/hwnd_util.h4
-rw-r--r--views/widget/native_widget_win.cc8
7 files changed, 71 insertions, 7 deletions
diff --git a/chrome/browser/ui/views/app_menu_button_win.cc b/chrome/browser/ui/views/app_menu_button_win.cc
new file mode 100644
index 0000000..0bf0990
--- /dev/null
+++ b/chrome/browser/ui/views/app_menu_button_win.cc
@@ -0,0 +1,23 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/app_menu_button_win.h"
+
+#include "ui/base/win/hwnd_util.h"
+#include "views/widget/widget.h"
+
+AppMenuButtonWin::AppMenuButtonWin(views::ViewMenuDelegate* menu_delegate)
+ : views::MenuButton(NULL, std::wstring(), menu_delegate, false) {
+}
+
+bool AppMenuButtonWin::OnKeyPressed(const views::KeyEvent& event) {
+ if (event.key_code() == ui::VKEY_SPACE) {
+ // Typical windows behavior is to show the system menu on space.
+ views::Widget* widget = GetWidget();
+ gfx::Rect bounds = widget->GetClientAreaScreenBounds();
+ ui::ShowSystemMenu(widget->GetNativeView(), bounds.x(), bounds.y() + 10);
+ return false;
+ }
+ return views::MenuButton::OnKeyPressed(event);
+}
diff --git a/chrome/browser/ui/views/app_menu_button_win.h b/chrome/browser/ui/views/app_menu_button_win.h
new file mode 100644
index 0000000..30c11a9
--- /dev/null
+++ b/chrome/browser/ui/views/app_menu_button_win.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_VIEWS_APP_MENU_BUTTON_WIN_H_
+#define CHROME_BROWSER_UI_VIEWS_APP_MENU_BUTTON_WIN_H_
+#pragma once
+
+#include "views/controls/button/menu_button.h"
+
+// Button used for showing the app menu. Special cases space to show the system
+// menu.
+class AppMenuButtonWin : public views::MenuButton {
+ public:
+ explicit AppMenuButtonWin(views::ViewMenuDelegate* menu_delegate);
+
+ // MenuButton:
+ virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AppMenuButtonWin);
+};
+
+#endif // CHROME_BROWSER_UI_VIEWS_APP_MENU_BUTTON_WIN_H_
diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc
index d9c1958..b1edf03 100644
--- a/chrome/browser/ui/views/toolbar_view.cc
+++ b/chrome/browser/ui/views/toolbar_view.cc
@@ -39,6 +39,7 @@
#if defined(OS_WIN)
#include "chrome/browser/enumerate_modules_model_win.h"
+#include "chrome/browser/ui/views/app_menu_button_win.h"
#endif
// static
@@ -165,7 +166,11 @@ void ToolbarView::Init(Profile* profile) {
browser_actions_ = new BrowserActionsContainer(browser_, this);
+#if defined(OS_WIN)
+ app_menu_ = new AppMenuButtonWin(this);
+#else
app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false);
+#endif
app_menu_->set_border(NULL);
app_menu_->EnableCanvasFlippingForRTLUI(true);
app_menu_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_APP));
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 74ad6dc..cd08c55 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2994,6 +2994,8 @@
'browser/ui/views/accessible_pane_view.h',
'browser/ui/views/appcache_info_view.cc',
'browser/ui/views/appcache_info_view.h',
+ 'browser/ui/views/app_menu_button_win.cc',
+ 'browser/ui/views/app_menu_button_win.h',
'browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc',
'browser/ui/views/autocomplete/autocomplete_popup_contents_view.h',
'browser/ui/views/autocomplete/autocomplete_result_view.cc',
diff --git a/ui/base/win/hwnd_util.cc b/ui/base/win/hwnd_util.cc
index 923c85c..58dbff2 100644
--- a/ui/base/win/hwnd_util.cc
+++ b/ui/base/win/hwnd_util.cc
@@ -4,6 +4,7 @@
#include "ui/base/win/hwnd_util.h"
+#include "base/i18n/rtl.h"
#include "base/string_util.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
@@ -174,4 +175,15 @@ void CheckWindowCreated(HWND hwnd) {
LOG_GETLASTERROR(FATAL);
}
+void ShowSystemMenu(HWND window, int screen_x, int screen_y) {
+ UINT flags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD;
+ if (base::i18n::IsRTL())
+ flags |= TPM_RIGHTALIGN;
+ HMENU system_menu = GetSystemMenu(window, FALSE);
+ int command = TrackPopupMenu(system_menu, flags, screen_x, screen_y, 0,
+ window, NULL);
+ if (command)
+ SendMessage(window, WM_SYSCOMMAND, command, 0);
+}
+
} // namespace ui
diff --git a/ui/base/win/hwnd_util.h b/ui/base/win/hwnd_util.h
index 9fce57c..a004654 100644
--- a/ui/base/win/hwnd_util.h
+++ b/ui/base/win/hwnd_util.h
@@ -44,6 +44,10 @@ void CenterAndSizeWindow(HWND parent,
// CreateWindow.
void CheckWindowCreated(HWND hwnd);
+// Shows the system menu for |window| and sends the selected command (if the
+// user selected something.
+void ShowSystemMenu(HWND window, int screen_x, int screen_y);
+
} // namespace ui
#endif // UI_BASE_WIN_HWND_UTIL_H_
diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc
index 877434c..8d2420e 100644
--- a/views/widget/native_widget_win.cc
+++ b/views/widget/native_widget_win.cc
@@ -1489,13 +1489,7 @@ LRESULT NativeWidgetWin::OnMouseRange(UINT message,
w_param = SendMessage(GetNativeView(), WM_NCHITTEST, 0,
MAKELPARAM(screen_point.x, screen_point.y));
if (w_param == HTCAPTION || w_param == HTSYSMENU) {
- UINT flags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD;
- if (base::i18n::IsRTL())
- flags |= TPM_RIGHTALIGN;
- HMENU system_menu = GetSystemMenu(GetNativeView(), FALSE);
- int id = TrackPopupMenu(system_menu, flags, screen_point.x,
- screen_point.y, 0, GetNativeView(), NULL);
- ExecuteSystemMenuCommand(id);
+ ui::ShowSystemMenu(GetNativeView(), screen_point.x, screen_point.y);
return 0;
}
} else if (message == WM_NCLBUTTONDOWN &&