summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-19 17:52:42 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-19 17:52:42 +0000
commit4762a9ed08ec93918b58269c21f78df72bc4961e (patch)
tree54d16d9220f4d075e14f9f2e5e32fbc4470c4d3d /chrome
parent0137991d3c78ec95d6d7fc386ae151d4359b308c (diff)
downloadchromium_src-4762a9ed08ec93918b58269c21f78df72bc4961e.zip
chromium_src-4762a9ed08ec93918b58269c21f78df72bc4961e.tar.gz
chromium_src-4762a9ed08ec93918b58269c21f78df72bc4961e.tar.bz2
Make a MenuModel for the popup favicon menu. For now only GTK uses it. Consolidate all accelerators for browser commands into one place.
BUG=28212,27535 TEST=1. enable custom frame and a popup window and test that the popup contains all the same (non-system) menu items as windows. 2. all context menus still display the correct shortcuts and the shortcuts work Review URL: http://codereview.chromium.org/551032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36527 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/gtk/accelerators_gtk.cc183
-rw-r--r--chrome/browser/gtk/accelerators_gtk.h37
-rw-r--r--chrome/browser/gtk/browser_titlebar.cc109
-rw-r--r--chrome/browser/gtk/browser_titlebar.h31
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc108
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc165
-rw-r--r--chrome/browser/gtk/standard_menus.cc154
-rw-r--r--chrome/browser/gtk/tabs/tab_gtk.cc22
-rw-r--r--chrome/browser/page_menu_model.cc30
-rw-r--r--chrome/browser/page_menu_model.h21
-rwxr-xr-xchrome/chrome_browser.gypi3
11 files changed, 366 insertions, 497 deletions
diff --git a/chrome/browser/gtk/accelerators_gtk.cc b/chrome/browser/gtk/accelerators_gtk.cc
new file mode 100644
index 0000000..04a2a02
--- /dev/null
+++ b/chrome/browser/gtk/accelerators_gtk.cc
@@ -0,0 +1,183 @@
+// Copyright (c) 2010 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/gtk/accelerators_gtk.h"
+
+#include <gdk/gdk.h>
+#include <gdk/gdkkeysyms.h>
+#include <X11/XF86keysym.h>
+
+#include "chrome/app/chrome_dll_resource.h"
+
+namespace {
+
+// A mostly complete list of chrome's accelerators. When one command has
+// multiple shortcuts, the first one in this list is considered "primary",
+// meaning that it will be displayed in context menus.
+const struct AcceleratorMapping {
+ guint keyval;
+ int command_id;
+ GdkModifierType modifier_type;
+} kAcceleratorMap[] = {
+ // Focus.
+ { GDK_k, IDC_FOCUS_SEARCH, GDK_CONTROL_MASK },
+ { GDK_e, IDC_FOCUS_SEARCH, GDK_CONTROL_MASK },
+ { XF86XK_Search, IDC_FOCUS_SEARCH, GdkModifierType(0) },
+ { GDK_l, IDC_FOCUS_LOCATION, GDK_CONTROL_MASK },
+ { GDK_d, IDC_FOCUS_LOCATION, GDK_MOD1_MASK },
+ { GDK_F6, IDC_FOCUS_LOCATION, GdkModifierType(0) },
+ { XF86XK_OpenURL, IDC_FOCUS_LOCATION, GdkModifierType(0) },
+ { XF86XK_Go, IDC_FOCUS_LOCATION, GdkModifierType(0) },
+
+ // Tab/window controls.
+ { GDK_Page_Down, IDC_SELECT_NEXT_TAB, GDK_CONTROL_MASK },
+ { GDK_Page_Up, IDC_SELECT_PREVIOUS_TAB, GDK_CONTROL_MASK },
+ { GDK_Page_Down, IDC_MOVE_TAB_NEXT,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+ { GDK_Page_Up, IDC_MOVE_TAB_PREVIOUS,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+ { GDK_Page_Up, IDC_SELECT_PREVIOUS_TAB, GDK_CONTROL_MASK },
+ { GDK_w, IDC_CLOSE_TAB, GDK_CONTROL_MASK },
+ { GDK_t, IDC_RESTORE_TAB,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+ { GDK_t, IDC_NEW_TAB, GDK_CONTROL_MASK },
+ { GDK_n, IDC_NEW_WINDOW, GDK_CONTROL_MASK },
+ { GDK_n, IDC_NEW_INCOGNITO_WINDOW,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+
+ { GDK_1, IDC_SELECT_TAB_0, GDK_CONTROL_MASK },
+ { GDK_2, IDC_SELECT_TAB_1, GDK_CONTROL_MASK },
+ { GDK_3, IDC_SELECT_TAB_2, GDK_CONTROL_MASK },
+ { GDK_4, IDC_SELECT_TAB_3, GDK_CONTROL_MASK },
+ { GDK_5, IDC_SELECT_TAB_4, GDK_CONTROL_MASK },
+ { GDK_6, IDC_SELECT_TAB_5, GDK_CONTROL_MASK },
+ { GDK_7, IDC_SELECT_TAB_6, GDK_CONTROL_MASK },
+ { GDK_8, IDC_SELECT_TAB_7, GDK_CONTROL_MASK },
+ { GDK_9, IDC_SELECT_LAST_TAB, GDK_CONTROL_MASK },
+
+ { GDK_1, IDC_SELECT_TAB_0, GDK_MOD1_MASK },
+ { GDK_2, IDC_SELECT_TAB_1, GDK_MOD1_MASK },
+ { GDK_3, IDC_SELECT_TAB_2, GDK_MOD1_MASK },
+ { GDK_4, IDC_SELECT_TAB_3, GDK_MOD1_MASK },
+ { GDK_5, IDC_SELECT_TAB_4, GDK_MOD1_MASK },
+ { GDK_6, IDC_SELECT_TAB_5, GDK_MOD1_MASK },
+ { GDK_7, IDC_SELECT_TAB_6, GDK_MOD1_MASK },
+ { GDK_8, IDC_SELECT_TAB_7, GDK_MOD1_MASK },
+ { GDK_9, IDC_SELECT_LAST_TAB, GDK_MOD1_MASK },
+
+ { GDK_KP_1, IDC_SELECT_TAB_0, GDK_CONTROL_MASK },
+ { GDK_KP_2, IDC_SELECT_TAB_1, GDK_CONTROL_MASK },
+ { GDK_KP_3, IDC_SELECT_TAB_2, GDK_CONTROL_MASK },
+ { GDK_KP_4, IDC_SELECT_TAB_3, GDK_CONTROL_MASK },
+ { GDK_KP_5, IDC_SELECT_TAB_4, GDK_CONTROL_MASK },
+ { GDK_KP_6, IDC_SELECT_TAB_5, GDK_CONTROL_MASK },
+ { GDK_KP_7, IDC_SELECT_TAB_6, GDK_CONTROL_MASK },
+ { GDK_KP_8, IDC_SELECT_TAB_7, GDK_CONTROL_MASK },
+ { GDK_KP_9, IDC_SELECT_LAST_TAB, GDK_CONTROL_MASK },
+
+ { GDK_KP_1, IDC_SELECT_TAB_0, GDK_MOD1_MASK },
+ { GDK_KP_2, IDC_SELECT_TAB_1, GDK_MOD1_MASK },
+ { GDK_KP_3, IDC_SELECT_TAB_2, GDK_MOD1_MASK },
+ { GDK_KP_4, IDC_SELECT_TAB_3, GDK_MOD1_MASK },
+ { GDK_KP_5, IDC_SELECT_TAB_4, GDK_MOD1_MASK },
+ { GDK_KP_6, IDC_SELECT_TAB_5, GDK_MOD1_MASK },
+ { GDK_KP_7, IDC_SELECT_TAB_6, GDK_MOD1_MASK },
+ { GDK_KP_8, IDC_SELECT_TAB_7, GDK_MOD1_MASK },
+ { GDK_KP_9, IDC_SELECT_LAST_TAB, GDK_MOD1_MASK },
+
+ { GDK_F4, IDC_CLOSE_TAB, GDK_CONTROL_MASK },
+ { GDK_F4, IDC_CLOSE_WINDOW, GDK_MOD1_MASK },
+
+ // Zoom level.
+ { GDK_plus, IDC_ZOOM_PLUS,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+ { GDK_equal, IDC_ZOOM_PLUS, GDK_CONTROL_MASK },
+ { XF86XK_ZoomIn, IDC_ZOOM_PLUS, GdkModifierType(0) },
+ { GDK_0, IDC_ZOOM_NORMAL, GDK_CONTROL_MASK },
+ { GDK_minus, IDC_ZOOM_MINUS, GDK_CONTROL_MASK },
+ { GDK_underscore, IDC_ZOOM_MINUS,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+ { XF86XK_ZoomOut, IDC_ZOOM_MINUS, GdkModifierType(0) },
+
+ // Find in page.
+ { GDK_g, IDC_FIND_NEXT, GDK_CONTROL_MASK },
+ { GDK_F3, IDC_FIND_NEXT, GdkModifierType(0) },
+ { GDK_g, IDC_FIND_PREVIOUS,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+ { GDK_F3, IDC_FIND_PREVIOUS, GDK_SHIFT_MASK },
+
+ // Navigation / toolbar buttons.
+ { GDK_Home, IDC_HOME, GDK_MOD1_MASK },
+ { XF86XK_HomePage, IDC_HOME, GdkModifierType(0) },
+ { GDK_Escape, IDC_STOP, GdkModifierType(0) },
+ { XF86XK_Stop, IDC_STOP, GdkModifierType(0) },
+ { GDK_Left, IDC_BACK, GDK_MOD1_MASK },
+ { GDK_BackSpace, IDC_BACK, GdkModifierType(0) },
+ { XF86XK_Back, IDC_BACK, GdkModifierType(0) },
+ { GDK_Right, IDC_FORWARD, GDK_MOD1_MASK },
+ { GDK_BackSpace, IDC_FORWARD, GDK_SHIFT_MASK },
+ { XF86XK_Forward, IDC_FORWARD, GdkModifierType(0) },
+ { GDK_r, IDC_RELOAD, GDK_CONTROL_MASK },
+ { GDK_F5, IDC_RELOAD, GdkModifierType(0) },
+ { GDK_F5, IDC_RELOAD, GDK_CONTROL_MASK },
+ { GDK_F5, IDC_RELOAD, GDK_SHIFT_MASK },
+ { XF86XK_Reload, IDC_RELOAD, GdkModifierType(0) },
+ { XF86XK_Refresh, IDC_RELOAD, GdkModifierType(0) },
+
+ // Dev tools.
+ { GDK_u, IDC_VIEW_SOURCE, GDK_CONTROL_MASK },
+ { GDK_i, IDC_DEV_TOOLS, GDK_CONTROL_MASK },
+ { GDK_j, IDC_DEV_TOOLS_CONSOLE,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+ { GDK_Escape, IDC_TASK_MANAGER, GDK_SHIFT_MASK },
+
+ // Miscellany.
+ { GDK_d, IDC_BOOKMARK_ALL_TABS,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+ { GDK_d, IDC_BOOKMARK_PAGE, GDK_CONTROL_MASK },
+ { GDK_o, IDC_OPEN_FILE, GDK_CONTROL_MASK },
+ { GDK_f, IDC_FIND, GDK_CONTROL_MASK },
+ { GDK_p, IDC_PRINT, GDK_CONTROL_MASK },
+ { GDK_b, IDC_SHOW_BOOKMARK_BAR, GDK_CONTROL_MASK },
+ { GDK_b, IDC_SHOW_BOOKMARK_MANAGER,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+ { GDK_F11, IDC_FULLSCREEN, GdkModifierType(0) },
+ { GDK_Delete, IDC_CLEAR_BROWSING_DATA,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+ { GDK_h, IDC_SHOW_HISTORY, GDK_CONTROL_MASK },
+ { GDK_j, IDC_SHOW_DOWNLOADS, GDK_CONTROL_MASK },
+ { GDK_F1, IDC_HELP_PAGE, GdkModifierType(0) },
+ { XF86XK_AddFavorite, IDC_BOOKMARK_PAGE, GdkModifierType(0) },
+ { XF86XK_Favorites, IDC_SHOW_BOOKMARK_BAR, GdkModifierType(0) },
+ { XF86XK_History, IDC_SHOW_HISTORY, GdkModifierType(0) },
+ { GDK_q, IDC_EXIT, GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
+};
+
+} // namespace
+
+AcceleratorsGtk::AcceleratorsGtk() {
+ for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) {
+ int command_id = kAcceleratorMap[i].command_id;
+ menus::AcceleratorGtk accelerator(kAcceleratorMap[i].keyval,
+ kAcceleratorMap[i].modifier_type);
+ all_accelerators_.push_back(
+ std::pair<int, menus::AcceleratorGtk>(command_id, accelerator));
+
+ if (primary_accelerators_.find(command_id) ==
+ primary_accelerators_.end()) {
+ primary_accelerators_[command_id] = accelerator;
+ }
+ }
+}
+
+const menus::AcceleratorGtk* AcceleratorsGtk::GetPrimaryAcceleratorForCommand(
+ int command_id) {
+ base::hash_map<int, menus::AcceleratorGtk>::const_iterator iter =
+ primary_accelerators_.find(command_id);
+
+ if (iter == primary_accelerators_.end())
+ return NULL;
+
+ return &iter->second;
+}
diff --git a/chrome/browser/gtk/accelerators_gtk.h b/chrome/browser/gtk/accelerators_gtk.h
new file mode 100644
index 0000000..677caea
--- /dev/null
+++ b/chrome/browser/gtk/accelerators_gtk.h
@@ -0,0 +1,37 @@
+// Copyright (c) 2010 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_GTK_ACCELERATORS_GTK_H_
+#define CHROME_BROWSER_GTK_ACCELERATORS_GTK_H_
+
+#include "app/menus/accelerator_gtk.h"
+#include "base/hash_tables.h"
+
+class AcceleratorsGtk {
+ public:
+ AcceleratorsGtk();
+ ~AcceleratorsGtk() { }
+
+ typedef std::vector<std::pair<int, menus::AcceleratorGtk> >
+ AcceleratorGtkList;
+ typedef AcceleratorGtkList::const_iterator const_iterator;
+
+ const_iterator const begin() {
+ return all_accelerators_.begin();
+ }
+
+ const_iterator const end() {
+ return all_accelerators_.end();
+ }
+
+ // Returns NULL if there is no accelerator for the command.
+ const menus::AcceleratorGtk* GetPrimaryAcceleratorForCommand(int command_id);
+
+ private:
+ base::hash_map<int, menus::AcceleratorGtk> primary_accelerators_;
+
+ AcceleratorGtkList all_accelerators_;
+};
+
+#endif // CHROME_BROWSER_GTK_ACCELERATORS_GTK_H_
diff --git a/chrome/browser/gtk/browser_titlebar.cc b/chrome/browser/gtk/browser_titlebar.cc
index aa89a5b..95f5a25 100644
--- a/chrome/browser/gtk/browser_titlebar.cc
+++ b/chrome/browser/gtk/browser_titlebar.cc
@@ -15,9 +15,11 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/command_line.h"
+#include "base/singleton.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/encoding_menu_controller.h"
+#include "chrome/browser/gtk/accelerators_gtk.h"
#include "chrome/browser/gtk/browser_window_gtk.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
@@ -25,6 +27,7 @@
#include "chrome/browser/gtk/nine_box.h"
#include "chrome/browser/gtk/standard_menus.h"
#include "chrome/browser/gtk/tabs/tab_strip_gtk.h"
+#include "chrome/browser/page_menu_model.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/gtk_util.h"
@@ -123,59 +126,6 @@ GdkColor PickLuminosityContrastingColor(const GdkColor* base,
return *one;
}
-MenuCreateMaterial g_favicon_menu[] = {
- { MENU_NORMAL, IDC_BACK, IDS_CONTENT_CONTEXT_BACK, 0, NULL,
- GDK_Left, GDK_MOD1_MASK },
- { MENU_NORMAL, IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD, 0, NULL,
- GDK_Right, GDK_MOD1_MASK },
- { MENU_NORMAL, IDC_RELOAD, IDS_APP_MENU_RELOAD, 0, NULL,
- GDK_R, GDK_CONTROL_MASK },
- { MENU_SEPARATOR },
- { MENU_NORMAL, IDC_RESTORE_TAB, IDS_RESTORE_TAB, 0, NULL,
- GDK_T, GDK_CONTROL_MASK | GDK_SHIFT_MASK },
- { MENU_NORMAL, IDC_DUPLICATE_TAB, IDS_APP_MENU_DUPLICATE_APP_WINDOW },
- { MENU_NORMAL, IDC_COPY_URL, IDS_APP_MENU_COPY_URL },
- { MENU_NORMAL, IDC_SHOW_AS_TAB, IDS_SHOW_AS_TAB },
- { MENU_NORMAL, IDC_NEW_TAB, IDS_APP_MENU_NEW_WEB_PAGE, 0, NULL,
- GDK_T, GDK_CONTROL_MASK },
-};
-
-const MenuCreateMaterial* GetFaviconMenu(Profile* profile,
- MenuGtk::Delegate* delegate) {
- static bool favicon_menu_built = false;
- static MenuCreateMaterial* favicon_menu;
- if (!favicon_menu_built) {
- const MenuCreateMaterial* standard_page =
- GetStandardPageMenu(profile, delegate);
- int standard_page_menu_length = 1;
- // Don't include the Create App Shortcut menu item.
- int start_offset = 0;
- for (int i = 0; standard_page[i].type != MENU_END; ++i) {
- if (standard_page[i].id == IDC_CREATE_SHORTCUTS) {
- // Pass the separator as well.
- start_offset = i + 2;
- ++i;
- continue;
- } else if (start_offset == 0) {
- // The Create App Shortcut menu item is the first menu item, and if that
- // ever changes we'll probably have to re-evaluate this code.
- NOTREACHED();
- continue;
- }
-
- standard_page_menu_length++;
- }
- favicon_menu = new MenuCreateMaterial[arraysize(g_favicon_menu) +
- standard_page_menu_length];
- memcpy(favicon_menu, g_favicon_menu,
- arraysize(g_favicon_menu) * sizeof(MenuCreateMaterial));
- memcpy(favicon_menu + arraysize(g_favicon_menu),
- standard_page + start_offset,
- (standard_page_menu_length) * sizeof(MenuCreateMaterial));
- }
- return favicon_menu;
-}
-
} // namespace
BrowserTitlebar::BrowserTitlebar(BrowserWindowGtk* browser_window,
@@ -499,9 +449,11 @@ void BrowserTitlebar::UpdateTextColor() {
}
void BrowserTitlebar::ShowFaviconMenu(GdkEventButton* event) {
- if (!favicon_menu_.get()) {
- favicon_menu_.reset(new MenuGtk(this,
- GetFaviconMenu(browser_window_->browser()->profile(), this)));
+ if (!favicon_menu_model_.get()) {
+ favicon_menu_model_.reset(
+ new PopupPageMenuModel(this, browser_window_->browser()));
+
+ favicon_menu_.reset(new MenuGtk(NULL, favicon_menu_model_.get()));
}
favicon_menu_->Popup(app_mode_favicon_, reinterpret_cast<GdkEvent*>(event));
@@ -594,27 +546,14 @@ gboolean BrowserTitlebar::OnButtonPressed(GtkWidget* widget,
void BrowserTitlebar::ShowContextMenu() {
if (!context_menu_.get()) {
- static const MenuCreateMaterial context_menu_blueprint[] = {
- { MENU_NORMAL, IDC_NEW_TAB, IDS_TAB_CXMENU_NEWTAB, 0, NULL,
- GDK_t, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_RESTORE_TAB, IDS_RESTORE_TAB, 0, NULL,
- GDK_t, GDK_CONTROL_MASK | GDK_SHIFT_MASK },
- { MENU_SEPARATOR },
- { MENU_NORMAL, IDC_TASK_MANAGER, IDS_TASK_MANAGER, 0, NULL,
- GDK_Escape, GDK_SHIFT_MASK },
- { MENU_SEPARATOR },
- { MENU_CHECKBOX, kShowWindowDecorationsCommand,
- IDS_SHOW_WINDOW_DECORATIONS_MENU },
- { MENU_END },
- };
-
- context_menu_.reset(new MenuGtk(this, context_menu_blueprint));
+ context_menu_model_.reset(new ContextMenuModel(this));
+ context_menu_.reset(new MenuGtk(NULL, context_menu_model_.get()));
}
context_menu_->PopupAsContext(gtk_get_current_event_time());
}
-bool BrowserTitlebar::IsCommandEnabled(int command_id) const {
+bool BrowserTitlebar::IsCommandIdEnabled(int command_id) const {
if (command_id == kShowWindowDecorationsCommand)
return true;
@@ -622,7 +561,7 @@ bool BrowserTitlebar::IsCommandEnabled(int command_id) const {
IsCommandEnabled(command_id);
}
-bool BrowserTitlebar::IsItemChecked(int command_id) const {
+bool BrowserTitlebar::IsCommandIdChecked(int command_id) const {
if (command_id == kShowWindowDecorationsCommand) {
PrefService* prefs = browser_window_->browser()->profile()->GetPrefs();
return !prefs->GetBoolean(prefs::kUseCustomChromeFrame);
@@ -644,7 +583,7 @@ bool BrowserTitlebar::IsItemChecked(int command_id) const {
return false;
}
-void BrowserTitlebar::ExecuteCommandById(int command_id) {
+void BrowserTitlebar::ExecuteCommand(int command_id) {
if (command_id == kShowWindowDecorationsCommand) {
PrefService* prefs = browser_window_->browser()->profile()->GetPrefs();
prefs->SetBoolean(prefs::kUseCustomChromeFrame,
@@ -655,6 +594,16 @@ void BrowserTitlebar::ExecuteCommandById(int command_id) {
browser_window_->browser()->ExecuteCommand(command_id);
}
+bool BrowserTitlebar::GetAcceleratorForCommandId(
+ int command_id, menus::Accelerator* accelerator) {
+ const menus::AcceleratorGtk* accelerator_gtk =
+ Singleton<AcceleratorsGtk>()->GetPrimaryAcceleratorForCommand(
+ command_id);
+ if (accelerator_gtk)
+ *accelerator = *accelerator_gtk;
+ return accelerator_gtk;
+}
+
void BrowserTitlebar::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -733,3 +682,15 @@ void BrowserTitlebar::Throbber::InitFrames() {
g_throbber_waiting_frames = new std::vector<GdkPixbuf*>;
MakeThrobberFrames(IDR_THROBBER_WAITING_LIGHT, g_throbber_waiting_frames);
}
+
+BrowserTitlebar::ContextMenuModel::ContextMenuModel(
+ menus::SimpleMenuModel::Delegate* delegate)
+ : SimpleMenuModel(delegate) {
+ AddItemWithStringId(IDC_NEW_TAB, IDS_TAB_CXMENU_NEWTAB);
+ AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB);
+ AddSeparator();
+ AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER);
+ AddSeparator();
+ AddCheckItemWithStringId(kShowWindowDecorationsCommand,
+ IDS_SHOW_WINDOW_DECORATIONS_MENU);
+}
diff --git a/chrome/browser/gtk/browser_titlebar.h b/chrome/browser/gtk/browser_titlebar.h
index fe468ec..5c09692 100644
--- a/chrome/browser/gtk/browser_titlebar.h
+++ b/chrome/browser/gtk/browser_titlebar.h
@@ -13,19 +13,21 @@
#include <gtk/gtk.h>
#include "app/active_window_watcher_x.h"
+#include "app/menus/simple_menu_model.h"
#include "base/scoped_ptr.h"
-#include "chrome/browser/gtk/menu_gtk.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
class BrowserWindowGtk;
class CustomDrawButton;
class GtkThemeProvider;
+class MenuGtk;
+class PopupPageMenuModel;
class TabContents;
-class BrowserTitlebar : public MenuGtk::Delegate,
- public NotificationObserver,
- public ActiveWindowWatcherX::Observer {
+class BrowserTitlebar : public NotificationObserver,
+ public ActiveWindowWatcherX::Observer,
+ public menus::SimpleMenuModel::Delegate {
public:
BrowserTitlebar(BrowserWindowGtk* browser_window, GtkWindow* window);
virtual ~BrowserTitlebar();
@@ -76,6 +78,11 @@ class BrowserTitlebar : public MenuGtk::Delegate,
int current_waiting_frame_;
};
+ class ContextMenuModel : public menus::SimpleMenuModel {
+ public:
+ explicit ContextMenuModel(menus::SimpleMenuModel::Delegate* delegate);
+ };
+
// Build the titlebar, the space above the tab
// strip, and (maybe) the min, max, close buttons. |container| is the gtk
// continer that we put the widget into.
@@ -120,10 +127,12 @@ class BrowserTitlebar : public MenuGtk::Delegate,
// -- Context Menu -----------------------------------------------------------
- // MenuGtk::Delegate implementation:
- virtual bool IsCommandEnabled(int command_id) const;
- virtual bool IsItemChecked(int command_id) const;
- virtual void ExecuteCommandById(int command_id);
+ // SimpleMenuModel::Delegate implementation:
+ virtual bool IsCommandIdEnabled(int command_id) const;
+ virtual bool IsCommandIdChecked(int command_id) const;
+ virtual void ExecuteCommand(int command_id);
+ virtual bool GetAcceleratorForCommandId(int command_id,
+ menus::Accelerator* accelerator);
// Overridden from NotificationObserver:
virtual void Observe(NotificationType type,
@@ -173,11 +182,13 @@ class BrowserTitlebar : public MenuGtk::Delegate,
scoped_ptr<CustomDrawButton> restore_button_;
scoped_ptr<CustomDrawButton> close_button_;
- // The context menu.
+ // The context menu view and model.
scoped_ptr<MenuGtk> context_menu_;
+ scoped_ptr<ContextMenuModel> context_menu_model_;
- // The favicon menu.
+ // The favicon menu view and model.
scoped_ptr<MenuGtk> favicon_menu_;
+ scoped_ptr<PopupPageMenuModel> favicon_menu_model_;
// The throbber used when the window is in app mode or popup window mode.
Throbber throbber_;
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index e258e7f..3a6debd 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -17,10 +17,12 @@
#include "base/keyboard_codes_posix.h"
#include "base/logging.h"
#include "base/path_service.h"
+#include "base/singleton.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_theme_provider.h"
#include "chrome/browser/encoding_menu_controller.h"
+#include "chrome/browser/gtk/accelerators_gtk.h"
#include "chrome/browser/gtk/back_forward_button_gtk.h"
#include "chrome/browser/gtk/browser_actions_toolbar_gtk.h"
#include "chrome/browser/gtk/browser_window_gtk.h"
@@ -367,107 +369,11 @@ void BrowserToolbarGtk::ExecuteCommand(int id) {
bool BrowserToolbarGtk::GetAcceleratorForCommandId(
int id,
menus::Accelerator* accelerator) {
- switch (id) {
- case IDC_ZOOM_PLUS:
- *accelerator = menus::AcceleratorGtk(base::VKEY_ADD, false, true, false);
- break;
-
- case IDC_ZOOM_NORMAL:
- *accelerator = menus::AcceleratorGtk(base::VKEY_NUMPAD0,
- false, true, false);
- break;
-
- case IDC_ZOOM_MINUS:
- *accelerator = menus::AcceleratorGtk(base::VKEY_SUBTRACT,
- false, true, false);
- break;
-
- case IDC_VIEW_SOURCE:
- *accelerator = menus::AcceleratorGtk(base::VKEY_U, false, true, false);
- break;
-
- case IDC_DEV_TOOLS:
- *accelerator = menus::AcceleratorGtk(base::VKEY_I, true, true, false);
- break;
-
- case IDC_DEV_TOOLS_CONSOLE:
- *accelerator = menus::AcceleratorGtk(base::VKEY_J, true, true, false);
- break;
-
- case IDC_TASK_MANAGER:
- *accelerator = menus::AcceleratorGtk(base::VKEY_ESCAPE,
- true, false, false);
- break;
-
- case IDC_CUT:
- *accelerator = menus::AcceleratorGtk(base::VKEY_X, false, true, false);
- break;
-
- case IDC_COPY:
- *accelerator = menus::AcceleratorGtk(base::VKEY_C, false, true, false);
- break;
-
- case IDC_PASTE:
- *accelerator = menus::AcceleratorGtk(base::VKEY_V, false, true, false);
- break;
-
- case IDC_FIND:
- *accelerator = menus::AcceleratorGtk(base::VKEY_F, false, true, false);
- break;
-
- case IDC_SAVE_PAGE:
- *accelerator = menus::AcceleratorGtk(base::VKEY_S, false, true, false);
- break;
-
- case IDC_PRINT:
- *accelerator = menus::AcceleratorGtk(base::VKEY_P, false, true, false);
- break;
-
- case IDC_NEW_TAB:
- *accelerator = menus::AcceleratorGtk(base::VKEY_T, false, true, false);
- break;
-
- case IDC_NEW_WINDOW:
- *accelerator = menus::AcceleratorGtk(base::VKEY_N, false, true, false);
- break;
-
- case IDC_NEW_INCOGNITO_WINDOW:
- *accelerator = menus::AcceleratorGtk(base::VKEY_N, true, true, false);
- break;
-
- case IDC_SHOW_BOOKMARK_BAR:
- *accelerator = menus::AcceleratorGtk(base::VKEY_B, false, true, false);
- break;
-
- case IDC_FULLSCREEN:
- *accelerator = menus::AcceleratorGtk(base::VKEY_F11, false, false, false);
- break;
-
- case IDC_SHOW_HISTORY:
- *accelerator = menus::AcceleratorGtk(base::VKEY_H, false, true, false);
- break;
-
- case IDC_SHOW_BOOKMARK_MANAGER:
- *accelerator = menus::AcceleratorGtk(base::VKEY_B, true, true, false);
- break;
-
- case IDC_SHOW_DOWNLOADS:
- *accelerator = menus::AcceleratorGtk(base::VKEY_J, false, true, false);
- break;
-
- case IDC_HELP_PAGE:
- *accelerator = menus::AcceleratorGtk(base::VKEY_F1, false, false, false);
- break;
-
- case IDC_EXIT:
- *accelerator = menus::AcceleratorGtk(base::VKEY_Q, true, true, false);
- break;
-
- default:
- return false;
- }
-
- return true;
+ const menus::AcceleratorGtk* accelerator_gtk =
+ Singleton<AcceleratorsGtk>()->GetPrimaryAcceleratorForCommand(id);
+ if (accelerator_gtk)
+ *accelerator = *accelerator_gtk;
+ return !!accelerator_gtk;
}
// NotificationObserver --------------------------------------------------------
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 65c61881..3a2d070 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -5,7 +5,6 @@
#include "chrome/browser/gtk/browser_window_gtk.h"
#include <gdk/gdkkeysyms.h>
-#include <X11/XF86keysym.h>
#include <string>
@@ -22,6 +21,7 @@
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/scoped_ptr.h"
+#include "base/singleton.h"
#include "base/string_util.h"
#include "base/time.h"
#include "chrome/app/chrome_dll_resource.h"
@@ -37,6 +37,7 @@
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/find_bar_controller.h"
#include "chrome/browser/gtk/about_chrome_dialog.h"
+#include "chrome/browser/gtk/accelerators_gtk.h"
#include "chrome/browser/gtk/bookmark_bar_gtk.h"
#include "chrome/browser/gtk/bookmark_manager_gtk.h"
#include "chrome/browser/gtk/browser_titlebar.h"
@@ -171,146 +172,6 @@ gfx::Rect GetInitialWindowBounds(GtkWindow* window) {
return gfx::Rect(x, y, width, height);
}
-// Keep this in sync with various context menus which display the accelerators.
-const struct AcceleratorMapping {
- guint keyval;
- int command_id;
- GdkModifierType modifier_type;
-} kAcceleratorMap[] = {
- // Focus.
- { GDK_k, IDC_FOCUS_SEARCH, GDK_CONTROL_MASK },
- { GDK_e, IDC_FOCUS_SEARCH, GDK_CONTROL_MASK },
- { XF86XK_Search, IDC_FOCUS_SEARCH, GdkModifierType(0) },
- { GDK_l, IDC_FOCUS_LOCATION, GDK_CONTROL_MASK },
- { GDK_d, IDC_FOCUS_LOCATION, GDK_MOD1_MASK },
- { GDK_F6, IDC_FOCUS_LOCATION, GdkModifierType(0) },
- { XF86XK_OpenURL, IDC_FOCUS_LOCATION, GdkModifierType(0) },
- { XF86XK_Go, IDC_FOCUS_LOCATION, GdkModifierType(0) },
-
- // Tab/window controls.
- { GDK_Page_Down, IDC_SELECT_NEXT_TAB, GDK_CONTROL_MASK },
- { GDK_Page_Up, IDC_SELECT_PREVIOUS_TAB, GDK_CONTROL_MASK },
- { GDK_Page_Down, IDC_MOVE_TAB_NEXT,
- GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
- { GDK_Page_Up, IDC_MOVE_TAB_PREVIOUS,
- GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
- { GDK_Page_Up, IDC_SELECT_PREVIOUS_TAB, GDK_CONTROL_MASK },
- { GDK_w, IDC_CLOSE_TAB, GDK_CONTROL_MASK },
- { GDK_t, IDC_RESTORE_TAB,
- GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
- { GDK_t, IDC_NEW_TAB, GDK_CONTROL_MASK },
- { GDK_n, IDC_NEW_WINDOW, GDK_CONTROL_MASK },
- { GDK_n, IDC_NEW_INCOGNITO_WINDOW,
- GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
-
- { GDK_1, IDC_SELECT_TAB_0, GDK_CONTROL_MASK },
- { GDK_2, IDC_SELECT_TAB_1, GDK_CONTROL_MASK },
- { GDK_3, IDC_SELECT_TAB_2, GDK_CONTROL_MASK },
- { GDK_4, IDC_SELECT_TAB_3, GDK_CONTROL_MASK },
- { GDK_5, IDC_SELECT_TAB_4, GDK_CONTROL_MASK },
- { GDK_6, IDC_SELECT_TAB_5, GDK_CONTROL_MASK },
- { GDK_7, IDC_SELECT_TAB_6, GDK_CONTROL_MASK },
- { GDK_8, IDC_SELECT_TAB_7, GDK_CONTROL_MASK },
- { GDK_9, IDC_SELECT_LAST_TAB, GDK_CONTROL_MASK },
-
- { GDK_1, IDC_SELECT_TAB_0, GDK_MOD1_MASK },
- { GDK_2, IDC_SELECT_TAB_1, GDK_MOD1_MASK },
- { GDK_3, IDC_SELECT_TAB_2, GDK_MOD1_MASK },
- { GDK_4, IDC_SELECT_TAB_3, GDK_MOD1_MASK },
- { GDK_5, IDC_SELECT_TAB_4, GDK_MOD1_MASK },
- { GDK_6, IDC_SELECT_TAB_5, GDK_MOD1_MASK },
- { GDK_7, IDC_SELECT_TAB_6, GDK_MOD1_MASK },
- { GDK_8, IDC_SELECT_TAB_7, GDK_MOD1_MASK },
- { GDK_9, IDC_SELECT_LAST_TAB, GDK_MOD1_MASK },
-
- { GDK_KP_1, IDC_SELECT_TAB_0, GDK_CONTROL_MASK },
- { GDK_KP_2, IDC_SELECT_TAB_1, GDK_CONTROL_MASK },
- { GDK_KP_3, IDC_SELECT_TAB_2, GDK_CONTROL_MASK },
- { GDK_KP_4, IDC_SELECT_TAB_3, GDK_CONTROL_MASK },
- { GDK_KP_5, IDC_SELECT_TAB_4, GDK_CONTROL_MASK },
- { GDK_KP_6, IDC_SELECT_TAB_5, GDK_CONTROL_MASK },
- { GDK_KP_7, IDC_SELECT_TAB_6, GDK_CONTROL_MASK },
- { GDK_KP_8, IDC_SELECT_TAB_7, GDK_CONTROL_MASK },
- { GDK_KP_9, IDC_SELECT_LAST_TAB, GDK_CONTROL_MASK },
-
- { GDK_KP_1, IDC_SELECT_TAB_0, GDK_MOD1_MASK },
- { GDK_KP_2, IDC_SELECT_TAB_1, GDK_MOD1_MASK },
- { GDK_KP_3, IDC_SELECT_TAB_2, GDK_MOD1_MASK },
- { GDK_KP_4, IDC_SELECT_TAB_3, GDK_MOD1_MASK },
- { GDK_KP_5, IDC_SELECT_TAB_4, GDK_MOD1_MASK },
- { GDK_KP_6, IDC_SELECT_TAB_5, GDK_MOD1_MASK },
- { GDK_KP_7, IDC_SELECT_TAB_6, GDK_MOD1_MASK },
- { GDK_KP_8, IDC_SELECT_TAB_7, GDK_MOD1_MASK },
- { GDK_KP_9, IDC_SELECT_LAST_TAB, GDK_MOD1_MASK },
-
- { GDK_F4, IDC_CLOSE_TAB, GDK_CONTROL_MASK },
- { GDK_F4, IDC_CLOSE_WINDOW, GDK_MOD1_MASK },
-
- // Zoom level.
- { GDK_plus, IDC_ZOOM_PLUS,
- GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
- { GDK_equal, IDC_ZOOM_PLUS, GDK_CONTROL_MASK },
- { XF86XK_ZoomIn, IDC_ZOOM_PLUS, GdkModifierType(0) },
- { GDK_0, IDC_ZOOM_NORMAL, GDK_CONTROL_MASK },
- { GDK_minus, IDC_ZOOM_MINUS, GDK_CONTROL_MASK },
- { GDK_underscore, IDC_ZOOM_MINUS,
- GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
- { XF86XK_ZoomOut, IDC_ZOOM_MINUS, GdkModifierType(0) },
-
- // Find in page.
- { GDK_g, IDC_FIND_NEXT, GDK_CONTROL_MASK },
- { GDK_F3, IDC_FIND_NEXT, GdkModifierType(0) },
- { GDK_g, IDC_FIND_PREVIOUS,
- GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
- { GDK_F3, IDC_FIND_PREVIOUS, GDK_SHIFT_MASK },
-
- // Navigation / toolbar buttons.
- { GDK_Home, IDC_HOME, GDK_MOD1_MASK },
- { XF86XK_HomePage, IDC_HOME, GdkModifierType(0) },
- { GDK_Escape, IDC_STOP, GdkModifierType(0) },
- { XF86XK_Stop, IDC_STOP, GdkModifierType(0) },
- { GDK_Left, IDC_BACK, GDK_MOD1_MASK },
- { GDK_BackSpace, IDC_BACK, GdkModifierType(0) },
- { XF86XK_Back, IDC_BACK, GdkModifierType(0) },
- { GDK_Right, IDC_FORWARD, GDK_MOD1_MASK },
- { GDK_BackSpace, IDC_FORWARD, GDK_SHIFT_MASK },
- { XF86XK_Forward, IDC_FORWARD, GdkModifierType(0) },
- { GDK_r, IDC_RELOAD, GDK_CONTROL_MASK },
- { GDK_F5, IDC_RELOAD, GdkModifierType(0) },
- { GDK_F5, IDC_RELOAD, GDK_CONTROL_MASK },
- { GDK_F5, IDC_RELOAD, GDK_SHIFT_MASK },
- { XF86XK_Reload, IDC_RELOAD, GdkModifierType(0) },
- { XF86XK_Refresh, IDC_RELOAD, GdkModifierType(0) },
-
- // Dev tools.
- { GDK_u, IDC_VIEW_SOURCE, GDK_CONTROL_MASK },
- { GDK_i, IDC_DEV_TOOLS, GDK_CONTROL_MASK },
- { GDK_j, IDC_DEV_TOOLS_CONSOLE,
- GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
- { GDK_Escape, IDC_TASK_MANAGER, GDK_SHIFT_MASK },
-
- // Miscellany.
- { GDK_d, IDC_BOOKMARK_ALL_TABS,
- GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
- { GDK_d, IDC_BOOKMARK_PAGE, GDK_CONTROL_MASK },
- { XF86XK_AddFavorite, IDC_BOOKMARK_PAGE, GdkModifierType(0) },
- { XF86XK_Favorites, IDC_SHOW_BOOKMARK_BAR, GdkModifierType(0) },
- { XF86XK_History, IDC_SHOW_HISTORY, GdkModifierType(0) },
- { GDK_o, IDC_OPEN_FILE, GDK_CONTROL_MASK },
- { GDK_f, IDC_FIND, GDK_CONTROL_MASK },
- { GDK_p, IDC_PRINT, GDK_CONTROL_MASK },
- { GDK_b, IDC_SHOW_BOOKMARK_BAR, GDK_CONTROL_MASK },
- { GDK_b, IDC_SHOW_BOOKMARK_MANAGER,
- GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
- { GDK_F11, IDC_FULLSCREEN, GdkModifierType(0) },
- { GDK_Delete, IDC_CLEAR_BROWSING_DATA,
- GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
- { GDK_h, IDC_SHOW_HISTORY, GDK_CONTROL_MASK },
- { GDK_j, IDC_SHOW_DOWNLOADS, GDK_CONTROL_MASK },
- { GDK_F1, IDC_HELP_PAGE, GdkModifierType(0) },
- { GDK_q, IDC_EXIT, GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
-};
-
// Get the command ids of the key combinations that are not valid gtk
// accelerators.
int GetCustomCommandId(GdkEventKey* event) {
@@ -733,10 +594,12 @@ void BrowserWindowGtk::Close() {
if (accel_group_) {
// Disconnecting the keys we connected to our accelerator group frees the
// closures allocated in ConnectAccelerators.
- for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) {
+ AcceleratorsGtk* accelerators = Singleton<AcceleratorsGtk>().get();
+ for (AcceleratorsGtk::const_iterator iter = accelerators->begin();
+ iter != accelerators->end(); ++iter) {
gtk_accel_group_disconnect_key(accel_group_,
- kAcceleratorMap[i].keyval,
- kAcceleratorMap[i].modifier_type);
+ iter->second.GetGdkKeyCode(),
+ static_cast<GdkModifierType>(iter->second.modifiers()));
}
gtk_window_remove_accel_group(window_, accel_group_);
g_object_unref(accel_group_);
@@ -1077,9 +940,7 @@ bool BrowserWindowGtk::PreHandleKeyboardEvent(
// |browser_| object.
//
// Pros of this approach:
- // 1. We can handle accelerators defined not only in above
- // |kAcceleratorMap| table, but also those in standard_menus.cc.
- // 2. We don't need to care about keyboard layout problem, as
+ // 1. We don't need to care about keyboard layout problem, as
// gtk_window_activate_key() method handles it for us.
//
// Cons:
@@ -1712,14 +1573,16 @@ void BrowserWindowGtk::ConnectAccelerators() {
accel_group_ = gtk_accel_group_new();
gtk_window_add_accel_group(window_, accel_group_);
- for (size_t i = 0; i < arraysize(kAcceleratorMap); ++i) {
+ AcceleratorsGtk* accelerators = Singleton<AcceleratorsGtk>().get();
+ for (AcceleratorsGtk::const_iterator iter = accelerators->begin();
+ iter != accelerators->end(); ++iter) {
gtk_accel_group_connect(
accel_group_,
- kAcceleratorMap[i].keyval,
- kAcceleratorMap[i].modifier_type,
+ iter->second.GetGdkKeyCode(),
+ static_cast<GdkModifierType>(iter->second.modifiers()),
GtkAccelFlags(0),
g_cclosure_new(G_CALLBACK(OnGtkAccelerator),
- GINT_TO_POINTER(kAcceleratorMap[i].command_id), NULL));
+ GINT_TO_POINTER(iter->first), NULL));
}
}
diff --git a/chrome/browser/gtk/standard_menus.cc b/chrome/browser/gtk/standard_menus.cc
deleted file mode 100644
index bf72167..0000000
--- a/chrome/browser/gtk/standard_menus.cc
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright (c) 2006-2009 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/gtk/standard_menus.h"
-
-#include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
-
-#include "app/l10n_util.h"
-#include "base/basictypes.h"
-#include "chrome/app/chrome_dll_resource.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/encoding_menu_controller.h"
-#include "chrome/browser/profile.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-
-namespace {
-
-struct MenuCreateMaterial zoom_menu_materials[] = {
- { MENU_NORMAL, IDC_ZOOM_PLUS, IDS_ZOOM_PLUS, 0, NULL,
- GDK_KP_Add, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL, 0, NULL,
- GDK_KP_0, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_ZOOM_MINUS, IDS_ZOOM_MINUS, 0, NULL,
- GDK_KP_Subtract, GDK_CONTROL_MASK },
- { MENU_END }
-};
-
-struct MenuCreateMaterial developer_menu_materials[] = {
- { MENU_NORMAL, IDC_VIEW_SOURCE, IDS_VIEW_SOURCE, 0, NULL,
- GDK_u, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_DEV_TOOLS, IDS_DEV_TOOLS, 0, NULL,
- GDK_i, GDK_CONTROL_MASK | GDK_SHIFT_MASK },
- { MENU_NORMAL, IDC_DEV_TOOLS_CONSOLE, IDS_DEV_TOOLS_CONSOLE, 0, NULL,
- GDK_j, GDK_CONTROL_MASK | GDK_SHIFT_MASK },
- { MENU_NORMAL, IDC_TASK_MANAGER, IDS_TASK_MANAGER, 0, NULL,
- GDK_Escape, GDK_SHIFT_MASK },
- { MENU_END }
-};
-
-struct MenuCreateMaterial developer_menu_materials_no_inspector[] = {
- { MENU_NORMAL, IDC_VIEW_SOURCE, IDS_VIEW_SOURCE, 0, NULL,
- GDK_u, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_TASK_MANAGER, IDS_TASK_MANAGER, 0, NULL,
- GDK_Escape, GDK_SHIFT_MASK },
- { MENU_END }
-};
-
-struct MenuCreateMaterial standard_page_menu_materials[] = {
- { MENU_NORMAL, IDC_CREATE_SHORTCUTS, IDS_CREATE_SHORTCUTS },
- { MENU_SEPARATOR },
- { MENU_NORMAL, IDC_CUT, IDS_CUT, 0, NULL, GDK_x, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_COPY, IDS_COPY, 0, NULL, GDK_c, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_PASTE, IDS_PASTE, 0, NULL, GDK_v, GDK_CONTROL_MASK },
- { MENU_SEPARATOR },
- { MENU_NORMAL, IDC_FIND, IDS_FIND, 0, NULL, GDK_f, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_SAVE_PAGE, IDS_SAVE_PAGE, 0, NULL, GDK_s,
- GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_PRINT, IDS_PRINT, 0, NULL, GDK_p, GDK_CONTROL_MASK },
- { MENU_SEPARATOR },
- { MENU_NORMAL, IDC_ZOOM_MENU, IDS_ZOOM_MENU, 0, zoom_menu_materials },
- // The encoding menu submenu is filled in by code below.
- { MENU_NORMAL, IDC_ENCODING_MENU, IDS_ENCODING_MENU },
- { MENU_SEPARATOR },
- // The developer menu submenu is filled in by code below.
- { MENU_NORMAL, IDC_DEVELOPER_MENU, IDS_DEVELOPER_MENU },
-
- // The Report Bug menu hasn't been implemented yet. Remove it until it is.
- // http://code.google.com/p/chromium/issues/detail?id=11600
- // { MENU_SEPARATOR },
- // { MENU_NORMAL, IDC_REPORT_BUG, IDS_REPORT_BUG },
-
- { MENU_END }
-};
-
-// -----------------------------------------------------------------------
-
-struct MenuCreateMaterial standard_app_menu_materials[] = {
- { MENU_NORMAL, IDC_NEW_TAB, IDS_NEW_TAB, 0, NULL,
- GDK_t, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_NEW_WINDOW, IDS_NEW_WINDOW, 0, NULL,
- GDK_n, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW, 0, NULL,
- GDK_n, GDK_CONTROL_MASK | GDK_SHIFT_MASK },
- { MENU_SEPARATOR },
- { MENU_CHECKBOX, IDC_SHOW_BOOKMARK_BAR, IDS_SHOW_BOOKMARK_BAR, 0, NULL,
- GDK_b, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_FULLSCREEN, IDS_FULLSCREEN, 0, NULL, GDK_F11 },
- { MENU_SEPARATOR },
- { MENU_NORMAL, IDC_SHOW_HISTORY, IDS_SHOW_HISTORY, 0, NULL,
- GDK_h, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_SHOW_BOOKMARK_MANAGER, IDS_BOOKMARK_MANAGER, 0, NULL,
- GDK_b, GDK_CONTROL_MASK | GDK_SHIFT_MASK },
- { MENU_NORMAL, IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS, 0, NULL,
- GDK_j, GDK_CONTROL_MASK },
- { MENU_NORMAL, IDC_MANAGE_EXTENSIONS, IDS_SHOW_EXTENSIONS },
- { MENU_SEPARATOR },
- { MENU_NORMAL, IDC_SYNC_BOOKMARKS, IDS_SYNC_MY_BOOKMARKS_LABEL},
- { MENU_SEPARATOR },
- { MENU_NORMAL, IDC_OPTIONS, IDS_OPTIONS, IDS_PRODUCT_NAME },
- { MENU_NORMAL, IDC_ABOUT, IDS_ABOUT, IDS_PRODUCT_NAME },
- { MENU_NORMAL, IDC_HELP_PAGE, IDS_HELP_PAGE, 0, NULL, GDK_F1 },
- { MENU_SEPARATOR },
- { MENU_NORMAL, IDC_EXIT, IDS_EXIT, 0, NULL, GDK_q,
- GDK_CONTROL_MASK | GDK_SHIFT_MASK },
- { MENU_END }
-};
-
-} // namespace
-
-const MenuCreateMaterial* GetStandardPageMenu(Profile* profile,
- MenuGtk::Delegate* delegate) {
- EncodingMenuController controller;
- EncodingMenuController::EncodingMenuItemList items;
- controller.GetEncodingMenuItems(profile, &items);
-
- MenuGtk* encodings_menu = new MenuGtk(delegate);
- GSList* radio_group = NULL;
- for (EncodingMenuController::EncodingMenuItemList::const_iterator i =
- items.begin();
- i != items.end(); ++i) {
- if (i == items.begin()) {
- encodings_menu->AppendCheckMenuItemWithLabel(i->first,
- UTF16ToUTF8(i->second));
- } else if (i->first == 0) {
- encodings_menu->AppendSeparator();
- } else {
- GtkWidget* item =
- gtk_radio_menu_item_new_with_label(radio_group,
- UTF16ToUTF8(i->second).c_str());
- radio_group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item));
- encodings_menu->AppendMenuItem(i->first, item);
- }
- }
-
- // Find the encoding menu and attach this menu.
- for (MenuCreateMaterial* entry = standard_page_menu_materials;
- entry->type != MENU_END; ++entry) {
- if (entry->id == IDC_ENCODING_MENU) {
- entry->custom_submenu = encodings_menu;
- } else if (entry->id == IDC_DEVELOPER_MENU) {
- entry->submenu = g_browser_process->have_inspector_files() ?
- developer_menu_materials : developer_menu_materials_no_inspector;
- }
- }
-
- return standard_page_menu_materials;
-}
-
-const MenuCreateMaterial* GetStandardAppMenu() {
- return standard_app_menu_materials;
-}
diff --git a/chrome/browser/gtk/tabs/tab_gtk.cc b/chrome/browser/gtk/tabs/tab_gtk.cc
index 023e272..dad8918 100644
--- a/chrome/browser/gtk/tabs/tab_gtk.cc
+++ b/chrome/browser/gtk/tabs/tab_gtk.cc
@@ -12,6 +12,9 @@
#include "app/menus/accelerator_gtk.h"
#include "app/resource_bundle.h"
#include "base/keyboard_codes_posix.h"
+#include "base/singleton.h"
+#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/gtk/accelerators_gtk.h"
#include "chrome/browser/gtk/menu_gtk.h"
#include "chrome/browser/gtk/standard_menus.h"
#include "chrome/browser/tab_menu_model.h"
@@ -65,26 +68,33 @@ class TabGtk::ContextMenuController : public menus::SimpleMenuModel::Delegate {
virtual bool GetAcceleratorForCommandId(
int command_id,
menus::Accelerator* accelerator) {
+ int browser_command = 0;
switch (command_id) {
case TabStripModel::CommandNewTab:
- *accelerator = menus::AcceleratorGtk(base::VKEY_T, false, true, false);
+ browser_command = IDC_NEW_TAB;
break;
case TabStripModel::CommandReload:
- *accelerator = menus::AcceleratorGtk(base::VKEY_R, false, true, false);
+ browser_command = IDC_RELOAD;
break;
case TabStripModel::CommandCloseTab:
- *accelerator = menus::AcceleratorGtk(base::VKEY_W, false, true, false);
+ browser_command = IDC_CLOSE_TAB;
break;
case TabStripModel::CommandRestoreTab:
- *accelerator = menus::AcceleratorGtk(base::VKEY_T, true, true, false);
+ browser_command = IDC_RESTORE_TAB;
break;
case TabStripModel::CommandBookmarkAllTabs:
- *accelerator = menus::AcceleratorGtk(base::VKEY_D, true, true, false);
+ browser_command = IDC_BOOKMARK_ALL_TABS;
break;
default:
return false;
}
- return true;
+
+ const menus::AcceleratorGtk* accelerator_gtk =
+ Singleton<AcceleratorsGtk>()->GetPrimaryAcceleratorForCommand(
+ browser_command);
+ if (accelerator_gtk)
+ *accelerator = *accelerator_gtk;
+ return !!accelerator_gtk;
}
virtual void ExecuteCommand(int command_id) {
if (!tab_)
diff --git a/chrome/browser/page_menu_model.cc b/chrome/browser/page_menu_model.cc
index 2e9f2c2..e66c41b 100644
--- a/chrome/browser/page_menu_model.cc
+++ b/chrome/browser/page_menu_model.cc
@@ -141,3 +141,33 @@ void DevToolsMenuModel::Build() {
}
AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER);
}
+
+////////////////////////////////////////////////////////////////////////////////
+// PopupPageMenuModel
+
+PopupPageMenuModel::PopupPageMenuModel(
+ menus::SimpleMenuModel::Delegate* delegate,
+ Browser* browser)
+ : menus::SimpleMenuModel(delegate), browser_(browser) {
+ Build();
+}
+
+void PopupPageMenuModel::Build() {
+ AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK);
+ AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD);
+ AddItemWithStringId(IDC_RELOAD, IDS_APP_MENU_RELOAD);
+ AddSeparator();
+ AddItemWithStringId(IDC_CUT, IDS_CUT);
+ AddItemWithStringId(IDC_COPY, IDS_COPY);
+ AddItemWithStringId(IDC_PASTE, IDS_PASTE);
+ AddSeparator();
+ AddItemWithStringId(IDC_FIND, IDS_FIND);
+#if !defined(OS_CHROMEOS)
+ AddItemWithStringId(IDC_PRINT, IDS_PRINT);
+#endif
+ zoom_menu_model_.reset(new ZoomMenuModel(delegate()));
+ AddSubMenuWithStringId(IDS_ZOOM_MENU, zoom_menu_model_.get());
+
+ encoding_menu_model_.reset(new EncodingMenuModel(browser_));
+ AddSubMenuWithStringId(IDS_ENCODING_MENU, encoding_menu_model_.get());
+}
diff --git a/chrome/browser/page_menu_model.h b/chrome/browser/page_menu_model.h
index 59994a9..a143adc 100644
--- a/chrome/browser/page_menu_model.h
+++ b/chrome/browser/page_menu_model.h
@@ -78,4 +78,25 @@ class PageMenuModel : public menus::SimpleMenuModel {
DISALLOW_COPY_AND_ASSIGN(PageMenuModel);
};
+// A menu model that builds the contents of the menu shown for popups (when the
+// user clicks on the favicon) and all of its submenus.
+class PopupPageMenuModel : public menus::SimpleMenuModel {
+ public:
+ explicit PopupPageMenuModel(menus::SimpleMenuModel::Delegate* delegate,
+ Browser* browser);
+ virtual ~PopupPageMenuModel() { }
+
+ private:
+ void Build();
+
+ // Models for submenus referenced by this model. SimpleMenuModel only uses
+ // weak references so these must be kept for the lifetime of the top-level
+ // model.
+ scoped_ptr<ZoomMenuModel> zoom_menu_model_;
+ scoped_ptr<EncodingMenuModel> encoding_menu_model_;
+ Browser* browser_; // weak
+
+ DISALLOW_COPY_AND_ASSIGN(PopupPageMenuModel);
+};
+
#endif // CHROME_BROWSER_PAGE_MENU_MODEL_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 2cb2692..6ef45fc 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -826,6 +826,8 @@
'browser/gpu_process_host.h',
'browser/gtk/about_chrome_dialog.cc',
'browser/gtk/about_chrome_dialog.h',
+ 'browser/gtk/accelerators_gtk.cc',
+ 'browser/gtk/accelerators_gtk.h',
'browser/gtk/back_forward_button_gtk.cc',
'browser/gtk/back_forward_button_gtk.h',
'browser/gtk/blocked_popup_container_view_gtk.cc',
@@ -978,7 +980,6 @@
'browser/gtk/sad_tab_gtk.h',
'browser/gtk/slide_animator_gtk.cc',
'browser/gtk/slide_animator_gtk.h',
- 'browser/gtk/standard_menus.cc',
'browser/gtk/standard_menus.h',
'browser/gtk/status_bubble_gtk.cc',
'browser/gtk/status_bubble_gtk.h',