diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-17 19:02:45 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-17 19:02:45 +0000 |
commit | fa990bb1e3c09ffb4f47418fcad2b8f6d322a75a (patch) | |
tree | 28d314754a9859626f9d66518912761e86502b2e | |
parent | 500c9f12f3f90e82ad0108edbfd35fc499d5b21d (diff) | |
download | chromium_src-fa990bb1e3c09ffb4f47418fcad2b8f6d322a75a.zip chromium_src-fa990bb1e3c09ffb4f47418fcad2b8f6d322a75a.tar.gz chromium_src-fa990bb1e3c09ffb4f47418fcad2b8f6d322a75a.tar.bz2 |
Create a menu wrapper class for GTK menus, and use it for the page and app menus.
Review URL: http://codereview.chromium.org/20245
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9893 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser.scons | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_view_gtk.cc | 106 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_view_gtk.h | 43 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 151 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.h | 61 | ||||
-rw-r--r-- | chrome/browser/gtk/standard_menus.cc | 94 | ||||
-rw-r--r-- | chrome/browser/gtk/standard_menus.h | 44 |
7 files changed, 470 insertions, 31 deletions
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons index b4c0b6e..f29fe40 100644 --- a/chrome/browser/browser.scons +++ b/chrome/browser/browser.scons @@ -789,6 +789,8 @@ if env.Bit('linux'): 'gtk/browser_toolbar_view_gtk.cc', 'gtk/browser_window_factory_gtk.cc', 'gtk/browser_window_gtk.cc', + 'gtk/standard_menus.cc', + 'gtk/menu_gtk.cc', 'renderer_host/render_widget_host_view_gtk.cc', 'tab_contents/web_contents_view_gtk.cc', ]) diff --git a/chrome/browser/gtk/browser_toolbar_view_gtk.cc b/chrome/browser/gtk/browser_toolbar_view_gtk.cc index 57f481a..67840c7 100644 --- a/chrome/browser/gtk/browser_toolbar_view_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_view_gtk.cc @@ -9,6 +9,8 @@ #include "base/path_service.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser.h" +#include "chrome/browser/gtk/menu_gtk.h" +#include "chrome/browser/gtk/standard_menus.h" #include "chrome/common/l10n_util.h" #include "chromium_strings.h" @@ -21,7 +23,7 @@ class BrowserToolbarGtk::CustomDrawButton { // The constructor takes a filename, which is used as the base filename // in loading the theme graphics pngs. This will be replaced by the // ResourceBundle graphics soon. - CustomDrawButton(const std::string& filename); + explicit CustomDrawButton(const std::string& filename); ~CustomDrawButton(); GtkWidget* widget() const { return widget_; } @@ -140,36 +142,41 @@ void BrowserToolbarGtk::Init(Profile* profile) { toolbar_tooltips_ = gtk_tooltips_new(); back_.reset(BuildToolbarButton("back", - l10n_util::GetString(IDS_TOOLTIP_BACK))); + l10n_util::GetString(IDS_TOOLTIP_BACK), + false)); forward_.reset(BuildToolbarButton("forward", - l10n_util::GetString(IDS_TOOLTIP_FORWARD))); + l10n_util::GetString(IDS_TOOLTIP_FORWARD), + false)); gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); reload_.reset(BuildToolbarButton("reload", - l10n_util::GetString(IDS_TOOLTIP_RELOAD))); + l10n_util::GetString(IDS_TOOLTIP_RELOAD), + false)); home_.reset(BuildToolbarButton("home", - l10n_util::GetString(IDS_TOOLTIP_HOME))); + l10n_util::GetString(IDS_TOOLTIP_HOME), + false)); gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); star_.reset(BuildToolbarButton("star", - l10n_util::GetString(IDS_TOOLTIP_STAR))); + l10n_util::GetString(IDS_TOOLTIP_STAR), + false)); GtkWidget* entry = gtk_entry_new(); gtk_widget_set_size_request(entry, 0, 27); gtk_box_pack_start(GTK_BOX(toolbar_), entry, TRUE, TRUE, 0); - go_.reset(BuildToolbarButton("go", L"")); + go_.reset(BuildToolbarButton("go", L"", false)); // TODO(port): these buttons need even stranger drawing than the others. - page_menu_.reset(BuildToolbarButton("menu_page", - l10n_util::GetString(IDS_PAGEMENU_TOOLTIP))); + page_menu_button_.reset(BuildToolbarButton("menu_page", + l10n_util::GetString(IDS_PAGEMENU_TOOLTIP), true)); // TODO(port): Need to get l10n_util::GetStringF working under linux to get // the correct string here. - app_menu_.reset(BuildToolbarButton("menu_chrome", - l10n_util::GetString(IDS_APPMENU_TOOLTIP))); + app_menu_button_.reset(BuildToolbarButton("menu_chrome", + l10n_util::GetString(IDS_APPMENU_TOOLTIP), true)); // TODO(erg): wchar_t mismatch on linux. Fix later. // show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); @@ -204,6 +211,23 @@ void BrowserToolbarGtk::EnabledStateChangedForCommand(int id, bool enabled) { gtk_widget_set_sensitive(widget, enabled); } +bool BrowserToolbarGtk::IsCommandEnabled(int command_id) const { + return browser_->command_updater()->IsCommandEnabled(command_id); +} + +bool BrowserToolbarGtk::IsItemChecked(int id) const { + if (!profile_) + return false; + if (id == IDC_SHOW_BOOKMARK_BAR) + return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); + // TODO(port): Fix this when we get some items that want checking! + return false; +} + +void BrowserToolbarGtk::ExecuteCommand(int id) { + browser_->ExecuteCommand(id); +} + void BrowserToolbarGtk::SetProfile(Profile* profile) { if (profile == profile_) return; @@ -217,23 +241,29 @@ void BrowserToolbarGtk::SetProfile(Profile* profile) { // TODO(port): This needs to deal with our styled pixmaps. BrowserToolbarGtk::CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton( const std::string& filename, - const std::wstring& localized_tooltip) { + const std::wstring& localized_tooltip, + bool menu_button) { CustomDrawButton* button = new CustomDrawButton(filename); // TODO(erg): Mismatch between wstring and string. // gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tooltips_), // GTK_WIDGET(back_), // localized_tooltip, localized_tooltip); - g_signal_connect(G_OBJECT(button->widget()), "clicked", - G_CALLBACK(ButtonClickCallback), this); - gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); + if (menu_button) { + g_signal_connect(G_OBJECT(button->widget()), "button_press_event", + G_CALLBACK(OnMenuButtonPressEvent), this); + } else { + g_signal_connect(G_OBJECT(button->widget()), "clicked", + G_CALLBACK(OnButtonClick), this); + } + gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); return button; } /* static */ -void BrowserToolbarGtk::ButtonClickCallback(GtkWidget* button, - BrowserToolbarGtk* toolbar) { +void BrowserToolbarGtk::OnButtonClick(GtkWidget* button, + BrowserToolbarGtk* toolbar) { int tag = -1; if (button == toolbar->back_->widget()) tag = IDC_BACK; @@ -246,9 +276,43 @@ void BrowserToolbarGtk::ButtonClickCallback(GtkWidget* button, else if (button == toolbar->star_->widget()) tag = IDC_STAR; - if (tag != -1) { - toolbar->browser_->ExecuteCommand(tag); - } else { - // TODO(erg): The menu buttons are special; they need to spawn menus. + DCHECK(tag != -1) << "Impossible button click callback"; + toolbar->browser_->ExecuteCommand(tag); +} + +/* static */ +gint BrowserToolbarGtk::OnMenuButtonPressEvent(GtkWidget* button, + GdkEvent* event, + BrowserToolbarGtk* toolbar) { + if (event->type == GDK_BUTTON_PRESS) { + GdkEventButton* event_button = reinterpret_cast<GdkEventButton*>(event); + if (event_button->button == 1) { + // We have a button press we should respond to. + if (button == toolbar->page_menu_button_->widget()) { + toolbar->RunPageMenu(event); + return TRUE; + } else if (button == toolbar->app_menu_button_->widget()) { + toolbar->RunAppMenu(event); + return TRUE; + } + } + } + + return FALSE; +} + +void BrowserToolbarGtk::RunPageMenu(GdkEvent* button_press_event) { + if (page_menu_ == NULL) { + page_menu_.reset(new MenuGtk(this, GetStandardPageMenu())); } + + page_menu_->Popup(page_menu_button_->widget(), button_press_event); +} + +void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { + if (app_menu_ == NULL) { + app_menu_.reset(new MenuGtk(this, GetStandardAppMenu())); + } + + app_menu_->Popup(app_menu_button_->widget(), button_press_event); } diff --git a/chrome/browser/gtk/browser_toolbar_view_gtk.h b/chrome/browser/gtk/browser_toolbar_view_gtk.h index 36b9464f..48d278d 100644 --- a/chrome/browser/gtk/browser_toolbar_view_gtk.h +++ b/chrome/browser/gtk/browser_toolbar_view_gtk.h @@ -2,21 +2,25 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_BROWSER_TOOLBAR_VIEW_GTK_H_ -#define CHROME_BROWSER_BROWSER_TOOLBAR_VIEW_GTK_H_ +#ifndef CHROME_BROWSER_GTK_BROWSER_TOOLBAR_VIEW_GTK_H_ +#define CHROME_BROWSER_GTK_BROWSER_TOOLBAR_VIEW_GTK_H_ +#include <gtk/gtk.h> +#include <string> + +#include "base/scoped_ptr.h" #include "chrome/browser/command_updater.h" +#include "chrome/browser/gtk/menu_gtk.h" #include "chrome/common/pref_member.h" -#include <gtk/gtk.h> - class Browser; class Profile; class ToolbarModel; // View class that displays the GTK version of the toolbar and routes gtk // events back to the Browser. -class BrowserToolbarGtk : public CommandUpdater::CommandObserver { +class BrowserToolbarGtk : public CommandUpdater::CommandObserver, + public MenuGtk::Delegate { public: explicit BrowserToolbarGtk(Browser* browser); virtual ~BrowserToolbarGtk(); @@ -30,6 +34,11 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver { // Overridden from CommandUpdater::CommandObserver: virtual void EnabledStateChangedForCommand(int id, bool enabled); + // Overridden from MenuGtk::Delegate: + virtual bool IsCommandEnabled(int command_id) const; + virtual bool IsItemChecked(int id) const; + virtual void ExecuteCommand(int command_id); + void SetProfile(Profile* profile); private: @@ -37,11 +46,22 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver { // Builds a toolbar button with all the properties set. CustomDrawButton* BuildToolbarButton(const std::string& filename, - const std::wstring& localized_tooltip); + const std::wstring& localized_tooltip, + bool menu_button); // Gtk callback for the "clicked" signal. - static void ButtonClickCallback(GtkWidget* button, - BrowserToolbarGtk* toolbar); + static void OnButtonClick(GtkWidget* button, BrowserToolbarGtk* toolbar); + + // Gtk callback to intercept mouse clicks to the menu buttons. + static gint OnMenuButtonPressEvent(GtkWidget* button, + GdkEvent *event, + BrowserToolbarGtk* toolbar); + + // Displays the page menu. + void RunPageMenu(GdkEvent* button_press_event); + + // Displays the app menu. + void RunAppMenu(GdkEvent* button_press_event); // Gtk widgets. The toolbar is an hbox with each of the other pieces of the // toolbar placed side by side. @@ -54,11 +74,14 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver { scoped_ptr<CustomDrawButton> back_, forward_; scoped_ptr<CustomDrawButton> reload_, home_; scoped_ptr<CustomDrawButton> star_, go_; - scoped_ptr<CustomDrawButton> page_menu_, app_menu_; + scoped_ptr<CustomDrawButton> page_menu_button_, app_menu_button_; // The model that contains the security level, text, icon to display... ToolbarModel* model_; + scoped_ptr<MenuGtk> page_menu_; + scoped_ptr<MenuGtk> app_menu_; + // TODO(port): Port BackForwardMenuModel // scoped_ptr<BackForwardMenuModel> back_menu_model_; // scoped_ptr<BackForwardMenuModel> forward_menu_model_; @@ -70,4 +93,4 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver { BooleanPrefMember show_home_button_; }; -#endif +#endif // CHROME_BROWSER_GTK_BROWSER_TOOLBAR_VIEW_GTK_H_ diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc new file mode 100644 index 0000000..7eaab60 --- /dev/null +++ b/chrome/browser/gtk/menu_gtk.cc @@ -0,0 +1,151 @@ +// Copyright (c) 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/menu_gtk.h" + +#include "base/logging.h" +#include "base/string_util.h" +#include "chrome/common/l10n_util.h" + +MenuGtk::MenuGtk(MenuGtk::Delegate* delegate, + const MenuCreateMaterial* menu_data) + : delegate_(delegate), + menu_(gtk_menu_new()) { + BuildMenuIn(menu_, menu_data); +} + +MenuGtk::~MenuGtk() { + g_object_unref(menu_); +} + +void MenuGtk::Popup(GtkWidget* widget, GdkEvent* event) { + DCHECK(event->type == GDK_BUTTON_PRESS) + << "Non-button press event sent to RunMenuAt"; + + gtk_container_foreach(GTK_CONTAINER(menu_), SetMenuItemInfo, this); + + GdkEventButton* event_button = reinterpret_cast<GdkEventButton*>(event); + gtk_menu_popup(GTK_MENU(menu_), NULL, NULL, + MenuPositionFunc, + widget, + event_button->button, event_button->time); +} + +void MenuGtk::BuildMenuIn(GtkWidget* menu, + const MenuCreateMaterial* menu_data) { + for (; menu_data->type != MENU_END; menu_data++) { + GtkWidget* menu_item = NULL; + + std::wstring label; + if (menu_data->label_argument) { + label = l10n_util::GetStringF( + menu_data->label_id, + l10n_util::GetString(menu_data->label_argument)); + } else if (menu_data->label_id) { + label = l10n_util::GetString(menu_data->label_id); + } else { + DCHECK(menu_data->type == MENU_SEPARATOR) << "Menu definition broken"; + } + + switch (menu_data->type) { + case MENU_CHECKBOX: + menu_item = gtk_check_menu_item_new_with_label( + WideToUTF8(label).c_str()); + break; + case MENU_SEPARATOR: + menu_item = gtk_separator_menu_item_new(); + break; + case MENU_NORMAL: + default: + menu_item = gtk_menu_item_new_with_label(WideToUTF8(label).c_str()); + break; + } + + if (menu_data->submenu) { + GtkWidget* submenu = gtk_menu_new(); + BuildMenuIn(submenu, menu_data->submenu); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), submenu); + } + + g_object_set_data(G_OBJECT(menu_item), "menu-data", + const_cast<MenuCreateMaterial*>(menu_data)); + + g_signal_connect(G_OBJECT(menu_item), "activate", + G_CALLBACK(OnMenuItemActivated), this); + + gtk_widget_show(menu_item); + gtk_menu_append(menu, menu_item); + } +} + +/* static */ +void MenuGtk::OnMenuItemActivated(GtkMenuItem* menuitem, MenuGtk* menu) { + // We receive activation messages when highlighting a menu that has a + // submenu. Ignore them. + if (!gtk_menu_item_get_submenu(menuitem)) { + const MenuCreateMaterial* data = + reinterpret_cast<const MenuCreateMaterial*>( + g_object_get_data(G_OBJECT(menuitem), "menu-data")); + menu->delegate_->ExecuteCommand(data->id); + } +} + +/* static */ +void MenuGtk::MenuPositionFunc(GtkMenu* menu, + int* x, + int* y, + gboolean* push_in, + void* void_widget) { + GtkWidget* widget = GTK_WIDGET(void_widget); + GtkRequisition menu_req; + GdkRectangle monitor; + + gtk_widget_size_request(GTK_WIDGET(menu), &menu_req); + + GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET(menu)); + gint monitor_num = gdk_screen_get_monitor_at_window(screen, widget->window); + if (monitor_num < 0) + monitor_num = 0; + gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor); + + gdk_window_get_origin(widget->window, x, y); + *x += widget->allocation.x + widget->allocation.width; + *y += widget->allocation.y + widget->allocation.height; + + *x -= menu_req.width; + + // TODO(erg): Deal with this scrolling off the bottom of the screen. + + // Regretfully, we can't rely on push_in to alter the coordinates above to + // always make the menu fit on screen. It'd make the above calculations just + // work though... + *push_in = FALSE; +} + +/* static */ +void MenuGtk::SetMenuItemInfo(GtkWidget* widget, void* raw_menu) { + MenuGtk* menu = static_cast<MenuGtk*>(raw_menu); + const MenuCreateMaterial* data = + reinterpret_cast<const MenuCreateMaterial*>( + g_object_get_data(G_OBJECT(widget), "menu-data")); + + if (data) { + if (GTK_IS_CHECK_MENU_ITEM(widget)) { + GtkCheckMenuItem* item = GTK_CHECK_MENU_ITEM(widget); + gtk_check_menu_item_set_active( + item, menu->delegate_->IsItemChecked(data->id)); + } + + if (GTK_IS_MENU_ITEM(widget)) { + gtk_widget_set_sensitive( + widget, menu->delegate_->IsCommandEnabled(data->id)); + + GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); + if (submenu) { + gtk_container_foreach(GTK_CONTAINER(submenu), &MenuGtk::SetMenuItemInfo, + raw_menu); + } + } + } +} diff --git a/chrome/browser/gtk/menu_gtk.h b/chrome/browser/gtk/menu_gtk.h new file mode 100644 index 0000000..462c122 --- /dev/null +++ b/chrome/browser/gtk/menu_gtk.h @@ -0,0 +1,61 @@ +// Copyright (c) 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. + +#ifndef CHROME_BROWSER_GTK_MENU_GTK_H_ +#define CHROME_BROWSER_GTK_MENU_GTK_H_ + +#include <gtk/gtk.h> + +#include "chrome/browser/gtk/standard_menus.h" + +class MenuGtk { + public: + // Delegate class that lets another class control the status of the menu. + class Delegate { + public: + virtual ~Delegate() { } + + // Returns whether the menu item for this command should be enabled. + virtual bool IsCommandEnabled(int command_id) const = 0; + + // Returns whether this command. + virtual bool IsItemChecked(int command_id) const = 0; + + // Executes the command. + virtual void ExecuteCommand(int command_id) = 0; + }; + + MenuGtk(MenuGtk::Delegate* delegate, const MenuCreateMaterial* menu_data); + ~MenuGtk(); + + // Displays the menu + void Popup(GtkWidget* widget, GdkEvent* event); + + private: + // A recursive function that transforms a MenuCreateMaterial tree into a set + // of GtkMenuItems. + void BuildMenuIn(GtkWidget* menu, const MenuCreateMaterial* menu_data); + + // Callback for when a menu item is clicked. + static void OnMenuItemActivated(GtkMenuItem* menuitem, MenuGtk* menu); + + // Repositions the menu to be right under the button. + static void MenuPositionFunc(GtkMenu* menu, + int* x, + int* y, + gboolean* push_in, + void* void_widget); + + // Sets the check mark and enabled/disabled state on our menu items. + static void SetMenuItemInfo(GtkWidget* widget, void* raw_menu); + + // Queries this object about the menu state. + MenuGtk::Delegate* delegate_; + + // gtk_menu_popup() does not appear to take ownership of popup menus, so + // MenuGtk explicitly manages the lifetime of the menu. + GtkWidget* menu_; +}; + +#endif // CHROME_BROWSER_GTK_MENU_GTK_H_ diff --git a/chrome/browser/gtk/standard_menus.cc b/chrome/browser/gtk/standard_menus.cc new file mode 100644 index 0000000..ceb75d5 --- /dev/null +++ b/chrome/browser/gtk/standard_menus.cc @@ -0,0 +1,94 @@ +// Copyright (c) 2006-2008 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 "base/basictypes.h" +#include "chrome/app/chrome_dll_resource.h" +#include "chrome/common/l10n_util.h" + +#include "chromium_strings.h" +#include "generated_resources.h" + +namespace { + +struct MenuCreateMaterial zoom_menu_materials[] = { + { MENU_NORMAL, IDC_ZOOM_PLUS, IDS_ZOOM_MENU, 0, NULL }, + { MENU_NORMAL, IDC_ZOOM_PLUS, IDS_ZOOM_PLUS, 0, NULL }, + { MENU_NORMAL, IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL, 0, NULL }, + { MENU_NORMAL, IDC_ZOOM_MINUS, IDS_ZOOM_MINUS, 0, NULL }, + { MENU_END, 0, 0, NULL } +}; + +struct MenuCreateMaterial encoding_menu_materials[] = { + { MENU_CHECKBOX, IDC_ENCODING_AUTO_DETECT, IDS_ENCODING_AUTO_DETECT, 0, + NULL }, + { MENU_END, 0, 0, NULL } +}; + +struct MenuCreateMaterial developer_menu_materials[] = { + { MENU_NORMAL, IDC_VIEW_SOURCE, IDS_VIEW_SOURCE, 0, NULL }, + { MENU_NORMAL, IDC_DEBUGGER, IDS_DEBUGGER, 0, NULL }, + { MENU_NORMAL, IDC_JS_CONSOLE, IDS_JS_CONSOLE, 0, NULL }, + { MENU_NORMAL, IDC_TASK_MANAGER, IDS_TASK_MANAGER, 0, NULL }, + { MENU_END, 0, 0, NULL } +}; + +struct MenuCreateMaterial standard_page_menu_materials[] = { + { MENU_NORMAL, IDC_CREATE_SHORTCUTS, IDS_CREATE_SHORTCUTS, 0, NULL }, + { MENU_SEPARATOR, 0, 0, 0, NULL }, + { MENU_NORMAL, IDC_CUT, IDS_CUT, 0, NULL }, + { MENU_NORMAL, IDC_COPY, IDS_COPY, 0, NULL }, + { MENU_NORMAL, IDC_PASTE, IDS_PASTE, 0, NULL }, + { MENU_SEPARATOR, 0, 0, 0, NULL }, + { MENU_NORMAL, IDC_FIND, IDS_FIND, 0, NULL }, + { MENU_NORMAL, IDC_SAVE_PAGE, IDS_SAVE_PAGE, 0, NULL }, + { MENU_NORMAL, IDC_PRINT, IDS_PRINT, 0, NULL }, + { MENU_SEPARATOR, 0, 0, 0, NULL }, + { MENU_NORMAL, IDC_ZOOM_MENU, IDS_ZOOM_MENU, 0, zoom_menu_materials }, + { MENU_NORMAL, IDC_ENCODING_MENU, IDS_ENCODING_MENU, 0, + encoding_menu_materials }, + { MENU_SEPARATOR, 0, 0, 0, NULL }, + { MENU_NORMAL, IDC_DEVELOPER_MENU, IDS_DEVELOPER_MENU, 0, + developer_menu_materials }, + { MENU_SEPARATOR, 0, 0, 0, NULL }, + { MENU_NORMAL, IDC_REPORT_BUG, IDS_REPORT_BUG, 0, NULL }, + { MENU_END, 0, 0, NULL } +}; + +// ----------------------------------------------------------------------- + +struct MenuCreateMaterial standard_app_menu_materials[] = { + { MENU_NORMAL, IDC_NEW_TAB, IDS_NEW_TAB, 0, NULL }, + { MENU_NORMAL, IDC_NEW_WINDOW, IDS_NEW_WINDOW, 0, NULL }, + { MENU_NORMAL, IDC_NEW_INCOGNITO_WINDOW, IDS_NEW_INCOGNITO_WINDOW, 0, NULL }, + { MENU_NORMAL, IDC_PROFILE_MENU, IDS_PROFILE_MENU, 0, NULL }, + { MENU_SEPARATOR, 0, 0, NULL }, + { MENU_NORMAL, IDC_SHOW_BOOKMARK_BAR, IDS_SHOW_BOOKMARK_BAR }, + { MENU_SEPARATOR, 0, 0, NULL }, + { MENU_NORMAL, IDC_SHOW_HISTORY, IDS_SHOW_HISTORY }, + { MENU_NORMAL, IDC_SHOW_BOOKMARK_MANAGER, IDS_BOOKMARK_MANAGER }, + { MENU_NORMAL, IDC_SHOW_DOWNLOADS, IDS_SHOW_DOWNLOADS }, + { MENU_SEPARATOR, 0, 0, NULL }, + // TODO(erg): P13N stuff goes here as soon as they get IDS strings. + { MENU_NORMAL, IDC_CLEAR_BROWSING_DATA, IDS_CLEAR_BROWSING_DATA, 0, NULL }, + { MENU_NORMAL, IDC_IMPORT_SETTINGS, IDS_IMPORT_SETTINGS, 0, NULL }, + { MENU_SEPARATOR, 0, 0, 0, NULL }, + { MENU_NORMAL, IDC_OPTIONS, IDS_OPTIONS, IDS_PRODUCT_NAME, NULL }, + { MENU_NORMAL, IDC_ABOUT, IDS_ABOUT, IDS_PRODUCT_NAME, NULL }, + { MENU_NORMAL, IDC_HELP_PAGE, IDS_HELP_PAGE, 0, NULL }, + { MENU_SEPARATOR, 0, 0, 0, NULL }, + { MENU_NORMAL, IDC_EXIT, IDS_EXIT, 0, NULL }, + { MENU_END, 0, 0, NULL } +}; + +} // namespace + +const MenuCreateMaterial* GetStandardPageMenu() { + return standard_page_menu_materials; +} + +const MenuCreateMaterial* GetStandardAppMenu() { + return standard_app_menu_materials; +} diff --git a/chrome/browser/gtk/standard_menus.h b/chrome/browser/gtk/standard_menus.h new file mode 100644 index 0000000..a26643e --- /dev/null +++ b/chrome/browser/gtk/standard_menus.h @@ -0,0 +1,44 @@ +// Copyright (c) 2006-2008 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_VIEWS_STANDARD_MENUS_H_ +#define CHROME_VIEWS_STANDARD_MENUS_H_ + +class Menu; +class Profile; + +enum MenuItemType { + MENU_NORMAL = 0, + MENU_CHECKBOX, + MENU_SEPARATOR, + + // Speical value to stop processing this MenuCreateMaterial. + MENU_END +}; + +struct MenuCreateMaterial { + // This menu item type + MenuItemType type; + + // The command id (an IDC_* value) + unsigned int id; + + // The label id (an IDS_* value) + unsigned int label_id; + + // An argument to GetStringF(menu_label_id, ...). When 0, the value of + // menu_label_id is just passed to GetString(). + unsigned int label_argument; + + // If non-NULL, a pointer to the struct we're supposed to use + MenuCreateMaterial* submenu; +}; + +// Returns the menu construction data structure for the page menu. +const MenuCreateMaterial* GetStandardPageMenu(); + +// Returns the menu construction data structure for the app menu. +const MenuCreateMaterial* GetStandardAppMenu(); + +#endif // CHROME_VIEWS_STANDARD_MENUS_H_ |