diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-11 23:51:20 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-11 23:51:20 +0000 |
commit | 14831ef6c6fb54bd7aafa1006c5a2650ee6e9097 (patch) | |
tree | 7fb7b566271922e09a25997488b2d9137d50a051 | |
parent | 755fd4806a674e254387e3053857b5475453c8b8 (diff) | |
download | chromium_src-14831ef6c6fb54bd7aafa1006c5a2650ee6e9097.zip chromium_src-14831ef6c6fb54bd7aafa1006c5a2650ee6e9097.tar.gz chromium_src-14831ef6c6fb54bd7aafa1006c5a2650ee6e9097.tar.bz2 |
Re-organize RenderViewContextMenu to the use cross-platform MenuModel class.
Benefits:
- less code
- more straightforward code
- more shared code
unresolved issues:
- RenderViewContextMenu{Gtk,Mac,Views} should not be a subclass of RenderViewContextMenu
- On Linux, IMEs are added in the wrong place (not near the other editable stuff)
BUG=31365
TEST=manual + trybots
Review URL: http://codereview.chromium.org/2017001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46987 0039d316-1c4b-4281-b951-d872f2087c98
39 files changed, 553 insertions, 1317 deletions
diff --git a/app/menus/simple_menu_model.cc b/app/menus/simple_menu_model.cc index f6de9ad..0561c5a 100644 --- a/app/menus/simple_menu_model.cc +++ b/app/menus/simple_menu_model.cc @@ -6,6 +6,8 @@ #include "app/l10n_util.h" +static const int kSeparatorId = -1; + namespace menus { //////////////////////////////////////////////////////////////////////////////// @@ -19,31 +21,40 @@ SimpleMenuModel::~SimpleMenuModel() { void SimpleMenuModel::AddItem(int command_id, const string16& label) { Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL }; - items_.push_back(item); + AppendItem(item); } void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) { AddItem(command_id, l10n_util::GetStringUTF16(string_id)); } +void SimpleMenuModel::AddItemIdentifiedByStringId(int string_id) { + AddItemWithStringId(string_id, string_id); +} + void SimpleMenuModel::AddSeparator() { - Item item = { -1, string16(), SkBitmap(), TYPE_SEPARATOR, -1, NULL }; - items_.push_back(item); + Item item = { kSeparatorId, string16(), SkBitmap(), TYPE_SEPARATOR, -1, + NULL }; + AppendItem(item); } void SimpleMenuModel::AddCheckItem(int command_id, const string16& label) { Item item = { command_id, label, SkBitmap(), TYPE_CHECK, -1, NULL }; - items_.push_back(item); + AppendItem(item); } void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) { AddCheckItem(command_id, l10n_util::GetStringUTF16(string_id)); } +void SimpleMenuModel::AddCheckItemIdentifiedByStringId(int string_id) { + AddCheckItemWithStringId(string_id, string_id); +} + void SimpleMenuModel::AddRadioItem(int command_id, const string16& label, int group_id) { Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL }; - items_.push_back(item); + AppendItem(item); } void SimpleMenuModel::AddRadioItemWithStringId(int command_id, int string_id, @@ -51,19 +62,21 @@ void SimpleMenuModel::AddRadioItemWithStringId(int command_id, int string_id, AddRadioItem(command_id, l10n_util::GetStringUTF16(string_id), group_id); } -void SimpleMenuModel::AddSubMenu(const string16& label, MenuModel* model) { - Item item = { -1, label, SkBitmap(), TYPE_SUBMENU, -1, model }; - items_.push_back(item); +void SimpleMenuModel::AddSubMenu(int command_id, const string16& label, + MenuModel* model) { + Item item = { command_id, label, SkBitmap(), TYPE_SUBMENU, -1, model }; + AppendItem(item); } -void SimpleMenuModel::AddSubMenuWithStringId(int string_id, MenuModel* model) { - AddSubMenu(l10n_util::GetStringUTF16(string_id), model); +void SimpleMenuModel::AddSubMenuWithStringId(int command_id, + int string_id, MenuModel* model) { + AddSubMenu(command_id, l10n_util::GetStringUTF16(string_id), model); } void SimpleMenuModel::InsertItemAt( int index, int command_id, const string16& label) { Item item = { command_id, label, SkBitmap(), TYPE_COMMAND, -1, NULL }; - items_.insert(items_.begin() + FlipIndex(index), item); + InsertItemAtIndex(item, index); } void SimpleMenuModel::InsertItemWithStringIdAt( @@ -72,14 +85,15 @@ void SimpleMenuModel::InsertItemWithStringIdAt( } void SimpleMenuModel::InsertSeparatorAt(int index) { - Item item = { -1, string16(), SkBitmap(), TYPE_SEPARATOR, -1, NULL }; - items_.insert(items_.begin() + FlipIndex(index), item); + Item item = { kSeparatorId, string16(), SkBitmap(), TYPE_SEPARATOR, -1, + NULL }; + InsertItemAtIndex(item, index); } void SimpleMenuModel::InsertCheckItemAt( int index, int command_id, const string16& label) { Item item = { command_id, label, SkBitmap(), TYPE_CHECK, -1, NULL }; - items_.insert(items_.begin() + FlipIndex(index), item); + InsertItemAtIndex(item, index); } void SimpleMenuModel::InsertCheckItemWithStringIdAt( @@ -91,7 +105,7 @@ void SimpleMenuModel::InsertCheckItemWithStringIdAt( void SimpleMenuModel::InsertRadioItemAt( int index, int command_id, const string16& label, int group_id) { Item item = { command_id, label, SkBitmap(), TYPE_RADIO, group_id, NULL }; - items_.insert(items_.begin() + FlipIndex(index), item); + InsertItemAtIndex(item, index); } void SimpleMenuModel::InsertRadioItemWithStringIdAt( @@ -101,14 +115,15 @@ void SimpleMenuModel::InsertRadioItemWithStringIdAt( } void SimpleMenuModel::InsertSubMenuAt( - int index, const string16& label, MenuModel* model) { - Item item = { -1, label, SkBitmap(), TYPE_SUBMENU, -1, model }; - items_.insert(items_.begin() + FlipIndex(index), item); + int index, int command_id, const string16& label, MenuModel* model) { + Item item = { command_id, label, SkBitmap(), TYPE_SUBMENU, -1, model }; + InsertItemAtIndex(item, index); } void SimpleMenuModel::InsertSubMenuWithStringIdAt( - int index, int string_id, MenuModel* model) { - InsertSubMenuAt(index, l10n_util::GetStringUTF16(string_id), model); + int index, int command_id, int string_id, MenuModel* model) { + InsertSubMenuAt(index, command_id, l10n_util::GetStringUTF16(string_id), + model); } void SimpleMenuModel::SetIcon(int index, const SkBitmap& icon) { @@ -194,8 +209,7 @@ bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const { bool SimpleMenuModel::IsEnabledAt(int index) const { int command_id = GetCommandIdAt(index); - // Submenus have a command id of -1, they should always be enabled. - if (!delegate_ || command_id == -1) + if (!delegate_ || command_id == kSeparatorId) return true; return delegate_->IsCommandIdEnabled(command_id); } @@ -214,4 +228,27 @@ MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const { return items_.at(FlipIndex(index)).submenu; } +//////////////////////////////////////////////////////////////////////////////// +// SimpleMenuModel, Private: + +void SimpleMenuModel::AppendItem(const Item& item) { + ValidateItem(item); + items_.push_back(item); +} + +void SimpleMenuModel::InsertItemAtIndex(const Item& item, int index) { + ValidateItem(item); + items_.insert(items_.begin() + FlipIndex(index), item); +} + +void SimpleMenuModel::ValidateItem(const Item& item) { +#ifndef NDEBUG + if (item.type == TYPE_SEPARATOR) { + DCHECK_EQ(item.command_id, kSeparatorId); + } else { + DCHECK_GE(item.command_id, 0); + } +#endif // NDEBUG +} + } // namespace menus diff --git a/app/menus/simple_menu_model.h b/app/menus/simple_menu_model.h index 5307f12..f183166b 100644 --- a/app/menus/simple_menu_model.h +++ b/app/menus/simple_menu_model.h @@ -60,8 +60,14 @@ class SimpleMenuModel : public MenuModel { void AddCheckItemWithStringId(int command_id, int string_id); void AddRadioItem(int command_id, const string16& label, int group_id); void AddRadioItemWithStringId(int command_id, int string_id, int group_id); - void AddSubMenu(const string16& label, MenuModel* model); - void AddSubMenuWithStringId(int string_id, MenuModel* model); + void AddSubMenu(int command_id, const string16& label, MenuModel* model); + void AddSubMenuWithStringId(int command_id, int string_id, MenuModel* model); + + // Helpers for the above that use the |string_id| for the |command_id| + // as well. + // TODO(estade): remove these. + void AddItemIdentifiedByStringId(int string_id); + void AddCheckItemIdentifiedByStringId(int string_id); // Methods for inserting items into the model. void InsertItemAt(int index, int command_id, const string16& label); @@ -73,8 +79,10 @@ class SimpleMenuModel : public MenuModel { int index, int command_id, const string16& label, int group_id); void InsertRadioItemWithStringIdAt( int index, int command_id, int string_id, int group_id); - void InsertSubMenuAt(int index, const string16& label, MenuModel* model); - void InsertSubMenuWithStringIdAt(int index, int string_id, MenuModel* model); + void InsertSubMenuAt( + int index, int command_id, const string16& label, MenuModel* model); + void InsertSubMenuWithStringIdAt( + int index, int command_id, int string_id, MenuModel* model); // Sets the icon for the item at |index|. void SetIcon(int index, const SkBitmap& icon); @@ -126,6 +134,11 @@ class SimpleMenuModel : public MenuModel { }; std::vector<Item> items_; + // Functions for inserting items into |items_|. + void AppendItem(const Item& item); + void InsertItemAtIndex(const Item& item, int index); + void ValidateItem(const Item& item); + Delegate* delegate_; DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); diff --git a/chrome/browser/app_menu_model.cc b/chrome/browser/app_menu_model.cc index 67ec6b2..a4cb383 100644 --- a/chrome/browser/app_menu_model.cc +++ b/chrome/browser/app_menu_model.cc @@ -50,7 +50,8 @@ void AppMenuModel::Build() { profiles_menu_contents_.reset(new menus::SimpleMenuModel(delegate())); BuildProfileSubMenu(); } - AddSubMenuWithStringId(IDS_PROFILE_MENU, profiles_menu_contents_.get()); + AddSubMenuWithStringId(IDC_PROFILE_MENU, IDS_PROFILE_MENU, + profiles_menu_contents_.get()); } AddSeparator(); diff --git a/chrome/browser/chromeos/login/language_switch_model.cc b/chrome/browser/chromeos/login/language_switch_model.cc index 4a2c29c..896a2c9 100644 --- a/chrome/browser/chromeos/login/language_switch_model.cc +++ b/chrome/browser/chromeos/login/language_switch_model.cc @@ -19,6 +19,7 @@ namespace { const int kLanguageMainMenuSize = 5; // TODO(glotov): need to specify the list as a part of the image customization. const char kLanguagesTopped[] = "es,it,de,fr,en-US"; +const int kMoreLanguagesSubMenu = 200; } // namespace @@ -44,8 +45,9 @@ void LanguageSwitchModel::InitLanguageMenu() { line, WideToUTF16(language_list_->GetLanguageNameAt(line))); } menu_model_.AddSeparator(); - menu_model_.AddSubMenu(WideToUTF16(l10n_util::GetString(IDS_LANGUAGES_MORE)), - &menu_model_submenu_); + menu_model_.AddSubMenuWithStringId(kMoreLanguagesSubMenu, + IDS_LANGUAGES_MORE, + &menu_model_submenu_); for (int line = kLanguageMainMenuSize; line != language_list_->get_languages_count(); line++) { menu_model_submenu_.AddItem( diff --git a/chrome/browser/chromeos/status/browser_status_area_view.cc b/chrome/browser/chromeos/status/browser_status_area_view.cc index 4b89aac..a3489c3 100644 --- a/chrome/browser/chromeos/status/browser_status_area_view.cc +++ b/chrome/browser/chromeos/status/browser_status_area_view.cc @@ -131,6 +131,7 @@ AppMenuModel* BrowserStatusAreaView::CreateAppMenuModel( DCHECK_GE(options_index, 0); menu_model->InsertSubMenuAt( options_index + 1, + IDC_COMPACT_NAVBAR, ASCIIToUTF16("Compact nav bar"), options_menu_contents_.get()); return menu_model; } diff --git a/chrome/browser/cocoa/menu_controller_unittest.mm b/chrome/browser/cocoa/menu_controller_unittest.mm index 4d75725..f41ef42 100644 --- a/chrome/browser/cocoa/menu_controller_unittest.mm +++ b/chrome/browser/cocoa/menu_controller_unittest.mm @@ -75,8 +75,8 @@ TEST_F(MenuControllerTest, Submenus) { submodel.AddItem(2, WideToUTF16(L"sub-one")); submodel.AddItem(3, WideToUTF16(L"sub-two")); submodel.AddItem(4, WideToUTF16(L"sub-three")); - model.AddSubMenuWithStringId(IDS_ZOOM_MENU, &submodel); - model.AddItem(5, WideToUTF16(L"three")); + model.AddSubMenuWithStringId(5, IDS_ZOOM_MENU, &submodel); + model.AddItem(6, WideToUTF16(L"three")); scoped_nsobject<MenuController> menu( [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); @@ -109,7 +109,7 @@ TEST_F(MenuControllerTest, EmptySubmenu) { menus::SimpleMenuModel model(&delegate); model.AddItem(1, WideToUTF16(L"one")); menus::SimpleMenuModel submodel(&delegate); - model.AddSubMenuWithStringId(IDS_ZOOM_MENU, &submodel); + model.AddSubMenuWithStringId(2, IDS_ZOOM_MENU, &submodel); scoped_nsobject<MenuController> menu( [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); @@ -167,7 +167,7 @@ TEST_F(MenuControllerTest, Validate) { model.AddItem(2, WideToUTF16(L"two")); menus::SimpleMenuModel submodel(&delegate); submodel.AddItem(2, WideToUTF16(L"sub-one")); - model.AddSubMenuWithStringId(IDS_ZOOM_MENU, &submodel); + model.AddSubMenuWithStringId(3, IDS_ZOOM_MENU, &submodel); scoped_nsobject<MenuController> menu( [[MenuController alloc] initWithModel:&model useWithPopUpButtonCell:NO]); diff --git a/chrome/browser/external_tab_container.cc b/chrome/browser/external_tab_container.cc index c0c537d..0833a6c 100644 --- a/chrome/browser/external_tab_container.cc +++ b/chrome/browser/external_tab_container.cc @@ -22,7 +22,7 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" #include "chrome/browser/tab_contents/provisional_load_details.h" -#include "chrome/browser/views/tab_contents/render_view_context_menu_external_win.h" +#include "chrome/browser/views/tab_contents/render_view_context_menu_views.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/views/tab_contents/tab_contents_container.h" #include "chrome/common/bindings_policy.h" @@ -152,8 +152,6 @@ bool ExternalTabContainer::Init(Profile* profile, ::ShowWindow(tab_contents_->GetNativeView(), SW_SHOWNA); - disabled_context_menu_ids_.push_back( - IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD); LoadAccelerators(); SetupExternalTabView(); return true; @@ -519,9 +517,8 @@ bool ExternalTabContainer::HandleContextMenu(const ContextMenuParams& params) { } external_context_menu_.reset( - new RenderViewContextMenuExternalWin(tab_contents(), - params, - disabled_context_menu_ids_)); + new RenderViewContextMenuViews(tab_contents(), params)); + external_context_menu_->SetExternal(); external_context_menu_->Init(); POINT screen_pt = { params.x, params.y }; diff --git a/chrome/browser/external_tab_container.h b/chrome/browser/external_tab_container.h index c537839..a5bf26d 100644 --- a/chrome/browser/external_tab_container.h +++ b/chrome/browser/external_tab_container.h @@ -25,7 +25,7 @@ class AutomationProvider; class Profile; class TabContentsContainer; -class RenderViewContextMenuExternalWin; +class RenderViewContextMenuViews; namespace IPC { struct NavigationInfo; @@ -276,10 +276,7 @@ class ExternalTabContainer : public TabContentsDelegate, // is set when we need to ignore the next load notification. bool ignore_next_load_notification_; - // Contains the list of disabled context menu identifiers. - std::vector<int> disabled_context_menu_ids_; - - scoped_ptr<RenderViewContextMenuExternalWin> external_context_menu_; + scoped_ptr<RenderViewContextMenuViews> external_context_menu_; // A message filter to load resources via automation scoped_refptr<AutomationResourceMessageFilter> diff --git a/chrome/browser/gtk/browser_titlebar.cc b/chrome/browser/gtk/browser_titlebar.cc index 4261981..f4ce056 100644 --- a/chrome/browser/gtk/browser_titlebar.cc +++ b/chrome/browser/gtk/browser_titlebar.cc @@ -24,7 +24,6 @@ #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/menu_gtk.h" #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/pref_service.h" diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index bfe25fc..18ace5e 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -33,7 +33,6 @@ #include "chrome/browser/gtk/gtk_theme_provider.h" #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/location_bar_view_gtk.h" -#include "chrome/browser/gtk/standard_menus.h" #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" #include "chrome/browser/gtk/view_id_util.h" #include "chrome/browser/net/url_fixer_upper.h" @@ -611,24 +610,6 @@ void BrowserToolbarGtk::OnStateChanged() { std::string menu_label = UTF16ToUTF8( sync_ui_util::GetSyncMenuLabel(sync_service_)); - - gtk_container_foreach(GTK_CONTAINER(app_menu_->widget()), &SetSyncMenuLabel, - &menu_label); -} - -// static -void BrowserToolbarGtk::SetSyncMenuLabel(GtkWidget* widget, gpointer userdata) { - const MenuCreateMaterial* data = - reinterpret_cast<const MenuCreateMaterial*>( - g_object_get_data(G_OBJECT(widget), "menu-data")); - if (data) { - if (data->id == IDC_SYNC_BOOKMARKS) { - std::string label = gtk_util::ConvertAcceleratorsFromWindowsStyle( - *reinterpret_cast<const std::string*>(userdata)); - GtkWidget *menu_label = gtk_bin_get_child(GTK_BIN(widget)); - gtk_label_set_label(GTK_LABEL(menu_label), label.c_str()); - } - } } bool BrowserToolbarGtk::ShouldOnlyShowLocation() const { diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 1cbf8b5..ef053bb 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -1001,9 +1001,8 @@ bool BrowserWindowGtk::PreHandleKeyboardEvent( if (id == -1) { // This piece of code is based on the fact that calling // gtk_window_activate_key() method against |window_| may only trigger a - // browser command execution, by matching either a global accelerator - // defined in above |kAcceleratorMap| or the accelerator key of a menu - // item defined in chrome/browser/gtk/standard_menus.cc. + // browser command execution, by matching a global accelerator + // defined in above |kAcceleratorMap|. // // Here we need to retrieve the command id (if any) associated to the // keyboard event. Instead of looking up the command id in above diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc index 2439943..b74951b 100644 --- a/chrome/browser/gtk/download_item_gtk.cc +++ b/chrome/browser/gtk/download_item_gtk.cc @@ -26,7 +26,6 @@ #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/gtk/nine_box.h" -#include "chrome/browser/gtk/standard_menus.h" #include "chrome/common/notification_service.h" #include "gfx/canvas_paint.h" #include "gfx/color_utils.h" diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index 1e9a8e7..41c3c77 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -15,7 +15,6 @@ #include "base/stl_util-inl.h" #include "base/utf_string_conversions.h" #include "chrome/browser/gtk/gtk_util.h" -#include "chrome/browser/gtk/standard_menus.h" #include "gfx/gtk_util.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -37,15 +36,6 @@ void SetMenuItemID(GtkWidget* menu_item, int menu_id) { // Gets the ID of a menu item. // Returns true if the menu item has an ID. bool GetMenuItemID(GtkWidget* menu_item, int* menu_id) { - const MenuCreateMaterial* data = - reinterpret_cast<const MenuCreateMaterial*>( - g_object_get_data(G_OBJECT(menu_item), "menu-data")); - - if (data) { - *menu_id = data->id; - return true; - } - gpointer id_ptr = g_object_get_data(G_OBJECT(menu_item), "menu-id"); if (id_ptr != NULL) { *menu_id = GPOINTER_TO_INT(id_ptr) - 1; @@ -105,19 +95,6 @@ int CalculateMenuYPosition(const GdkRectangle* screen_rect, } // namespace MenuGtk::MenuGtk(MenuGtk::Delegate* delegate, - const MenuCreateMaterial* menu_data) - : delegate_(delegate), - model_(NULL), - dummy_accel_group_(gtk_accel_group_new()), - menu_(gtk_menu_new()), - factory_(this) { - DCHECK(menu_data); - g_object_ref_sink(menu_); - ConnectSignalHandlers(); - BuildMenuIn(menu_, menu_data); -} - -MenuGtk::MenuGtk(MenuGtk::Delegate* delegate, menus::MenuModel* model) : delegate_(delegate), model_(model), @@ -228,83 +205,6 @@ void MenuGtk::Cancel() { gtk_menu_popdown(GTK_MENU(menu_)); } -void MenuGtk::BuildMenuIn(GtkWidget* menu, - const MenuCreateMaterial* menu_data) { - // We keep track of the last menu item in order to group radio items. - GtkWidget* last_menu_item = NULL; - for (; menu_data->type != MENU_END; ++menu_data) { - GtkWidget* menu_item = NULL; - - std::string label; - if (menu_data->label_argument) { - label = l10n_util::GetStringFUTF8( - menu_data->label_id, - l10n_util::GetStringUTF16(menu_data->label_argument)); - } else if (menu_data->label_id) { - label = l10n_util::GetStringUTF8(menu_data->label_id); - } else if (menu_data->type != MENU_SEPARATOR) { - label = delegate_->GetLabel(menu_data->id); - DCHECK(!label.empty()); - } - - label = ConvertAcceleratorsFromWindowsStyle(label); - - switch (menu_data->type) { - case MENU_RADIO: - if (GTK_IS_RADIO_MENU_ITEM(last_menu_item)) { - menu_item = gtk_radio_menu_item_new_with_mnemonic_from_widget( - GTK_RADIO_MENU_ITEM(last_menu_item), label.c_str()); - } else { - menu_item = gtk_radio_menu_item_new_with_mnemonic( - NULL, label.c_str()); - } - break; - case MENU_CHECKBOX: - menu_item = gtk_check_menu_item_new_with_mnemonic(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_mnemonic(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); - } else if (menu_data->custom_submenu) { - gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), - menu_data->custom_submenu->menu_); - submenus_we_own_.push_back(menu_data->custom_submenu); - } - - if (menu_data->accel_key) { - // If we ever want to let the user do any key remaping, we'll need to - // change the following so we make a gtk_accel_map which keeps the actual - // keys. - gtk_widget_add_accelerator(menu_item, - "activate", - dummy_accel_group_, - menu_data->accel_key, - GdkModifierType(menu_data->accel_modifiers), - GTK_ACCEL_VISIBLE); - } - - g_object_set_data(G_OBJECT(menu_item), "menu-data", - const_cast<MenuCreateMaterial*>(menu_data)); - - g_signal_connect(menu_item, "activate", - G_CALLBACK(OnMenuItemActivated), this); - - gtk_widget_show(menu_item); - gtk_menu_append(menu, menu_item); - last_menu_item = menu_item; - } -} - GtkWidget* MenuGtk::BuildMenuItemWithImage(const std::string& label, const SkBitmap& icon) { GtkWidget* menu_item = @@ -420,7 +320,7 @@ void MenuGtk::OnMenuItemActivated(GtkMenuItem* menuitem, MenuGtk* menu) { menus::MenuModel* model = ModelForMenuItem(menuitem); // The menu item can still be activated by hotkeys even if it is disabled. - if (menu->IsCommandEnabled(model, id)) + if (model->IsEnabledAt(id)) menu->ExecuteCommand(model, id); } @@ -490,27 +390,11 @@ void MenuGtk::UpdateMenu() { gtk_container_foreach(GTK_CONTAINER(menu_), SetMenuItemInfo, this); } -// http://crbug.com/31365 -bool MenuGtk::IsCommandEnabled(menus::MenuModel* model, int id) { - return model ? model->IsEnabledAt(id) : - delegate_->IsCommandEnabled(id); -} - -// http://crbug.com/31365 void MenuGtk::ExecuteCommand(menus::MenuModel* model, int id) { if (delegate_) delegate_->CommandWillBeExecuted(); - if (model) - model->ActivatedAt(id); - else - delegate_->ExecuteCommandById(id); -} - -// http://crbug.com/31365 -bool MenuGtk::IsItemChecked(menus::MenuModel* model, int id) { - return model ? model->IsItemCheckedAt(id) : - delegate_->IsItemChecked(id); + model->ActivatedAt(id); } // static @@ -537,8 +421,11 @@ void MenuGtk::SetMenuItemInfo(GtkWidget* widget, gpointer userdata) { if (!GetMenuItemID(widget, &id)) return; - MenuGtk* menu = reinterpret_cast<MenuGtk*>(userdata); menus::MenuModel* model = ModelForMenuItem(GTK_MENU_ITEM(widget)); + if (!model) { + NOTREACHED(); + return; + } if (GTK_IS_CHECK_MENU_ITEM(widget)) { GtkCheckMenuItem* item = GTK_CHECK_MENU_ITEM(widget); @@ -554,12 +441,12 @@ void MenuGtk::SetMenuItemInfo(GtkWidget* widget, gpointer userdata) { // root of the MenuGtk and we want to disable *all* MenuGtks, including // submenus. block_activation_ = true; - gtk_check_menu_item_set_active(item, menu->IsItemChecked(model, id)); + gtk_check_menu_item_set_active(item, model->IsItemCheckedAt(id)); block_activation_ = false; } if (GTK_IS_MENU_ITEM(widget)) { - gtk_widget_set_sensitive(widget, menu->IsCommandEnabled(model, id)); + gtk_widget_set_sensitive(widget, model->IsEnabledAt(id)); GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); if (submenu) { diff --git a/chrome/browser/gtk/menu_gtk.h b/chrome/browser/gtk/menu_gtk.h index ed5342e..781b61d 100644 --- a/chrome/browser/gtk/menu_gtk.h +++ b/chrome/browser/gtk/menu_gtk.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -19,8 +19,6 @@ namespace menus { class MenuModel; } -struct MenuCreateMaterial; - class MenuGtk { public: // Delegate class that lets another class control the status of the menu. @@ -28,18 +26,6 @@ class MenuGtk { public: virtual ~Delegate() { } - // Returns whether the menu item for this command should be enabled. - virtual bool IsCommandEnabled(int command_id) const { return false; } - - // Returns whether this command is checked (for checkbox menu items only). - virtual bool IsItemChecked(int command_id) const { return false; } - - // Gets the label. Only needs to be implemented for custom (dynamic) labels. - virtual std::string GetLabel(int command_id) const { return std::string(); } - - // Executes the command. - virtual void ExecuteCommandById(int command_id) {} - // Called before a command is executed. This exists for the case where a // model is handling the actual execution of commands, but the delegate // still needs to know that some command got executed. This is called before @@ -57,11 +43,6 @@ class MenuGtk { virtual bool AlwaysShowImages() const { return false; } }; - // Builds a MenuGtk that uses |delegate| to perform actions and |menu_data| - // to create the menu. - MenuGtk(MenuGtk::Delegate* delegate, const MenuCreateMaterial* menu_data); - // Creates a MenuGtk that uses |delegate| to perform actions. Builds the - // menu using |model_|. MenuGtk(MenuGtk::Delegate* delegate, menus::MenuModel* model); ~MenuGtk(); @@ -125,11 +106,6 @@ class MenuGtk { GtkWidget* widget() const { return menu_; } private: - // A recursive function that transforms a MenuCreateMaterial tree into a set - // of GtkMenuItems. - void BuildMenuIn(GtkWidget* menu, - const MenuCreateMaterial* menu_data); - // Builds a GtkImageMenuItem. GtkWidget* BuildMenuItemWithImage(const std::string& label, const SkBitmap& icon); diff --git a/chrome/browser/gtk/standard_menus.h b/chrome/browser/gtk/standard_menus.h deleted file mode 100644 index 28fcefb..0000000 --- a/chrome/browser/gtk/standard_menus.h +++ /dev/null @@ -1,60 +0,0 @@ -// 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_BROWSER_GTK_STANDARD_MENUS_H_ -#define CHROME_BROWSER_GTK_STANDARD_MENUS_H_ - -#include "chrome/browser/gtk/menu_gtk.h" - -class Menu; -class Profile; - -enum MenuItemType { - MENU_NORMAL = 0, - MENU_CHECKBOX, - MENU_SEPARATOR, - MENU_RADIO, - - // 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 - // label_id is just passed to GetString(). If both are 0, the menu delegate - // is responsible for implementing GetLabel(). - unsigned int label_argument; - - // If non-NULL, a pointer to the struct we're supposed to use - MenuCreateMaterial* submenu; - - // A gdk keysym that is used to activate this item from outside the menu. - unsigned int accel_key; - - // GDK modifiers for the menu items (i.e., shift, ctrl, etc). - unsigned int accel_modifiers; - - // If non-NULL, specifies a custom submenu to be used. MenuGtk will take - // ownership of this submenu. - MenuGtk* custom_submenu; -}; - -// Returns the menu construction data structure for the page menu. -// The parameters are used to construct the encodings menu. -const MenuCreateMaterial* GetStandardPageMenu(Profile* profile, - MenuGtk::Delegate* delegate); - -// Returns the menu construction data structure for the app menu. -const MenuCreateMaterial* GetStandardAppMenu(); - -#endif // CHROME_BROWSER_GTK_STANDARD_MENUS_H_ diff --git a/chrome/browser/gtk/tabs/tab_gtk.cc b/chrome/browser/gtk/tabs/tab_gtk.cc index c5f7201..3ca4688 100644 --- a/chrome/browser/gtk/tabs/tab_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_gtk.cc @@ -16,7 +16,6 @@ #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" #include "gfx/path.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/page_menu_model.cc b/chrome/browser/page_menu_model.cc index bf5912a..992d5c6 100644 --- a/chrome/browser/page_menu_model.cc +++ b/chrome/browser/page_menu_model.cc @@ -38,14 +38,16 @@ void PageMenuModel::Build() { AddSeparator(); zoom_menu_model_.reset(new ZoomMenuModel(delegate())); - AddSubMenuWithStringId(IDS_ZOOM_MENU, zoom_menu_model_.get()); + AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_ZOOM_MENU, zoom_menu_model_.get()); encoding_menu_model_.reset(new EncodingMenuModel(browser_)); - AddSubMenuWithStringId(IDS_ENCODING_MENU, encoding_menu_model_.get()); + AddSubMenuWithStringId(IDC_ENCODING_MENU, IDS_ENCODING_MENU, + encoding_menu_model_.get()); AddSeparator(); devtools_menu_model_.reset(new DevToolsMenuModel(delegate())); - AddSubMenuWithStringId(IDS_DEVELOPER_MENU, devtools_menu_model_.get()); + AddSubMenuWithStringId(IDC_DEVELOPER_MENU, IDS_DEVELOPER_MENU, + devtools_menu_model_.get()); AddSeparator(); AddItemWithStringId(IDC_REPORT_BUG, IDS_REPORT_BUG); @@ -163,8 +165,9 @@ void PopupPageMenuModel::Build() { AddItemWithStringId(IDC_FIND, IDS_FIND); AddItemWithStringId(IDC_PRINT, IDS_PRINT); zoom_menu_model_.reset(new ZoomMenuModel(delegate())); - AddSubMenuWithStringId(IDS_ZOOM_MENU, zoom_menu_model_.get()); + AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_ZOOM_MENU, zoom_menu_model_.get()); encoding_menu_model_.reset(new EncodingMenuModel(browser_)); - AddSubMenuWithStringId(IDS_ENCODING_MENU, encoding_menu_model_.get()); + AddSubMenuWithStringId(IDC_ENCODING_MENU, IDS_ENCODING_MENU, + encoding_menu_model_.get()); } diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 1f208dc..8551265 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -55,12 +55,19 @@ bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { url.host() == chrome::kChromeUIDevToolsHost; } +static const int kSpellcheckRadioGroup = 1; +static const int kExtensionsRadioGroup = 2; + RenderViewContextMenu::RenderViewContextMenu( TabContents* tab_contents, const ContextMenuParams& params) : params_(params), source_tab_contents_(tab_contents), - profile_(tab_contents->profile()) { + profile_(tab_contents->profile()), + ALLOW_THIS_IN_INITIALIZER_LIST(menu_model_(this)), + external_(false), + ALLOW_THIS_IN_INITIALIZER_LIST(spellcheck_submenu_model_(this)), + ALLOW_THIS_IN_INITIALIZER_LIST(bidi_submenu_model_(this)) { } RenderViewContextMenu::~RenderViewContextMenu() { @@ -70,7 +77,7 @@ RenderViewContextMenu::~RenderViewContextMenu() { void RenderViewContextMenu::Init() { InitMenu(); - DoInit(); + PlatformInit(); } static bool ExtensionContextMatch(ContextMenuParams params, @@ -127,39 +134,6 @@ void RenderViewContextMenu::GetItemsForExtension( } } -bool RenderViewContextMenu::MaybeStartExtensionSubMenu( - const string16& selection_text, const std::string& extension_name, - std::vector<const ExtensionMenuItem*>* items, int* index) { - if (items->size() == 0 || - (items->size() == 1 && items->at(0)->child_count() == 0)) - return false; - - int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; - string16 title; - const ExtensionMenuItem* first_item = items->at(0); - if (first_item->child_count() > 0) { - title = first_item->TitleWithReplacement(selection_text); - extension_item_map_[menu_id] = first_item->id(); - } else { - title = UTF8ToUTF16(extension_name); - } - StartSubMenu(menu_id, title); - - // If we have 1 parent item with a submenu of children, pull the - // parent out of |items| and put the children in. - if (items->size() == 1 && first_item->child_count() > 0) { - const ExtensionMenuItem* parent = first_item; - items->clear(); - for (int j = 0; j < parent->child_count(); j++) { - const ExtensionMenuItem* child = parent->ChildAt(j); - if (ExtensionContextMatch(params_, child->contexts())) - items->push_back(child); - } - } - - return true; -} - void RenderViewContextMenu::AppendExtensionItems( const std::string& extension_id, int* index) { Extension* extension = @@ -179,30 +153,68 @@ void RenderViewContextMenu::AppendExtensionItems( // If this is the first extension-provided menu item, add a separator. if (*index == 0) - AppendSeparator(); + menu_model_.AddSeparator(); + + // When extensions have more than 1 top-level item or a single parent item + // with children, we will start a sub menu. In the case of 1 parent with + // children, we will remove the parent from |items| and insert the children + // into it. The |index| parameter is incremented if we start a submenu. This + // returns true if a submenu was started. If we had multiple top-level items + // that needed to be pushed into a submenu, we'll use |extension_name| as the + // title. + menus::SimpleMenuModel* menu_model; + if (items.empty() || (items.size() == 1 && items[0]->child_count() == 0)) { + menu_model = &menu_model_; + } else { + menu_model = new menus::SimpleMenuModel(this); + extension_menu_models_.push_back(menu_model); - bool submenu_started = MaybeStartExtensionSubMenu( - selection_text, extension->name(), &items, index); + int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; + string16 title; + if (items[0]->child_count() > 0) { + title = items[0]->TitleWithReplacement(selection_text); + extension_item_map_[menu_id] = items[0]->id(); + } else { + title = UTF8ToUTF16(extension->name()); + } + + menu_model_.AddSubMenu(menu_id, title, menu_model); + + // If we have 1 parent item with a submenu of children, pull the + // parent out of |items| and put the children in. + if (items.size() == 1 && items[0]->child_count() > 0) { + const ExtensionMenuItem* parent = items[0]; + items.clear(); + for (int j = 0; j < parent->child_count(); j++) { + const ExtensionMenuItem* child = parent->ChildAt(j); + if (ExtensionContextMatch(params_, child->contexts())) + items.push_back(child); + } + } + } ExtensionMenuItem::Type last_type = ExtensionMenuItem::NORMAL; + int radio_group_id = kExtensionsRadioGroup; for (std::vector<const ExtensionMenuItem*>::iterator i = items.begin(); i != items.end(); ++i) { const ExtensionMenuItem* item = *i; if (item->type() == ExtensionMenuItem::SEPARATOR) { // We don't want the case of an extension with one top-level item that is // just a separator, so make sure this is inside a submenu. - if (submenu_started) { - AppendSeparator(); + if (menu_model != &menu_model_) { + menu_model->AddSeparator(); last_type = ExtensionMenuItem::SEPARATOR; } continue; } - // Auto-prepend a separator, if needed, to group radio items together. + // Auto-prepend a separator, if needed, to visually group radio items + // together. if (item->type() != ExtensionMenuItem::RADIO && item->type() != ExtensionMenuItem::SEPARATOR && last_type == ExtensionMenuItem::RADIO) { - AppendSeparator(); + menu_model->AddSeparator(); + radio_group_id++; } int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; @@ -211,24 +223,24 @@ void RenderViewContextMenu::AppendExtensionItems( extension_item_map_[menu_id] = item->id(); string16 title = item->TitleWithReplacement(selection_text); if (item->type() == ExtensionMenuItem::NORMAL) { - AppendMenuItem(menu_id, title); + menu_model->AddItem(menu_id, title); } else if (item->type() == ExtensionMenuItem::CHECKBOX) { - AppendCheckboxMenuItem(menu_id, title); + menu_model->AddCheckItem(menu_id, title); } else if (item->type() == ExtensionMenuItem::RADIO) { - // Auto-append a separator if needed to group radio items together. + // Auto-append a separator if needed to visually group radio items + // together. if (*index > 0 && last_type != ExtensionMenuItem::RADIO && - last_type != ExtensionMenuItem::SEPARATOR) - AppendSeparator(); + last_type != ExtensionMenuItem::SEPARATOR) { + menu_model->AddSeparator(); + radio_group_id++; + } - AppendRadioMenuItem(menu_id, title); + menu_model->AddRadioItem(menu_id, title, radio_group_id); } else { NOTREACHED(); } last_type = item->type(); } - - if (submenu_started) - FinishSubMenu(); } void RenderViewContextMenu::AppendAllExtensionItems() { @@ -264,7 +276,7 @@ void RenderViewContextMenu::InitMenu() { bool has_selection = !params_.selection_text.empty(); if (AppendCustomItems()) { - AppendSeparator(); + menu_model_.AddSeparator(); AppendDeveloperItems(); return; } @@ -291,7 +303,7 @@ void RenderViewContextMenu::InitMenu() { if (has_link) { AppendLinkItems(); if (params_.media_type != WebContextMenuData::MediaTypeNone) - AppendSeparator(); + menu_model_.AddSeparator(); } switch (params_.media_type) { @@ -322,7 +334,7 @@ void RenderViewContextMenu::InitMenu() { // In the DevTools popup menu, "developer items" is normally the only section, // so omit the separator there. if (!is_devtools) - AppendSeparator(); + menu_model_.AddSeparator(); AppendDeveloperItems(); } @@ -331,111 +343,119 @@ bool RenderViewContextMenu::AppendCustomItems() { for (size_t i = 0; i < custom_items.size(); ++i) { DCHECK(IDC_CONTENT_CONTEXT_CUSTOM_FIRST + custom_items[i].action < IDC_CONTENT_CONTEXT_CUSTOM_LAST); - AppendMenuItem(custom_items[i].action + IDC_CONTENT_CONTEXT_CUSTOM_FIRST, - custom_items[i].label); + menu_model_.AddItem( + custom_items[i].action + IDC_CONTENT_CONTEXT_CUSTOM_FIRST, + custom_items[i].label); } return custom_items.size() > 0; } void RenderViewContextMenu::AppendDeveloperItems() { if (g_browser_process->have_inspector_files()) - AppendMenuItem(IDS_CONTENT_CONTEXT_INSPECTELEMENT); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_INSPECTELEMENT); } void RenderViewContextMenu::AppendLinkItems() { - AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKNEWTAB); - AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW); - AppendMenuItem(IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD); - AppendMenuItem(IDS_CONTENT_CONTEXT_SAVELINKAS); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_OPENLINKNEWTAB); + menu_model_.AddItemIdentifiedByStringId( + IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW); + if (!external_) { + menu_model_.AddItemIdentifiedByStringId( + IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD); + } + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_SAVELINKAS); if (params_.link_url.SchemeIs(chrome::kMailToScheme)) { - AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION, + menu_model_.AddItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION, l10n_util::GetStringUTF16( IDS_CONTENT_CONTEXT_COPYEMAILADDRESS)); } else { - AppendMenuItem(IDS_CONTENT_CONTEXT_COPYLINKLOCATION); + menu_model_.AddItemIdentifiedByStringId( + IDS_CONTENT_CONTEXT_COPYLINKLOCATION); } } void RenderViewContextMenu::AppendImageItems() { - AppendMenuItem(IDS_CONTENT_CONTEXT_SAVEIMAGEAS); - AppendMenuItem(IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); - AppendMenuItem(IDS_CONTENT_CONTEXT_COPYIMAGE); - AppendMenuItem(IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_SAVEIMAGEAS); + menu_model_.AddItemIdentifiedByStringId( + IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_COPYIMAGE); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); } void RenderViewContextMenu::AppendAudioItems() { AppendMediaItems(); - AppendSeparator(); - AppendMenuItem(IDS_CONTENT_CONTEXT_SAVEAUDIOAS); - AppendMenuItem(IDS_CONTENT_CONTEXT_COPYAUDIOLOCATION); - AppendMenuItem(IDS_CONTENT_CONTEXT_OPENAUDIONEWTAB); + menu_model_.AddSeparator(); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_SAVEAUDIOAS); + menu_model_.AddItemIdentifiedByStringId( + IDS_CONTENT_CONTEXT_COPYAUDIOLOCATION); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_OPENAUDIONEWTAB); } void RenderViewContextMenu::AppendVideoItems() { AppendMediaItems(); - AppendSeparator(); - AppendMenuItem(IDS_CONTENT_CONTEXT_SAVEVIDEOAS); - AppendMenuItem(IDS_CONTENT_CONTEXT_COPYVIDEOLOCATION); - AppendMenuItem(IDS_CONTENT_CONTEXT_OPENVIDEONEWTAB); + menu_model_.AddSeparator(); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_SAVEVIDEOAS); + menu_model_.AddItemIdentifiedByStringId( + IDS_CONTENT_CONTEXT_COPYVIDEOLOCATION); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_OPENVIDEONEWTAB); } void RenderViewContextMenu::AppendMediaItems() { int media_flags = params_.media_flags; if (media_flags & WebContextMenuData::MediaPaused) { - AppendMenuItem(IDS_CONTENT_CONTEXT_PLAY); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_PLAY); } else { - AppendMenuItem(IDS_CONTENT_CONTEXT_PAUSE); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_PAUSE); } if (media_flags & WebContextMenuData::MediaMuted) { - AppendMenuItem(IDS_CONTENT_CONTEXT_UNMUTE); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_UNMUTE); } else { - AppendMenuItem(IDS_CONTENT_CONTEXT_MUTE); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_MUTE); } - AppendCheckboxMenuItem(IDS_CONTENT_CONTEXT_LOOP, - l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_LOOP)); - - AppendCheckboxMenuItem(IDS_CONTENT_CONTEXT_CONTROLS, - l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_CONTROLS)); + menu_model_.AddCheckItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_LOOP); + menu_model_.AddCheckItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_CONTROLS); } void RenderViewContextMenu::AppendPageItems() { - AppendMenuItem(IDS_CONTENT_CONTEXT_BACK); - AppendMenuItem(IDS_CONTENT_CONTEXT_FORWARD); - AppendMenuItem(IDS_CONTENT_CONTEXT_RELOAD); - AppendSeparator(); - AppendMenuItem(IDS_CONTENT_CONTEXT_SAVEPAGEAS); - AppendMenuItem(IDS_CONTENT_CONTEXT_PRINT); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_BACK); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_FORWARD); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_RELOAD); + menu_model_.AddSeparator(); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_SAVEPAGEAS); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_PRINT); std::string locale = g_browser_process->GetApplicationLocale(); locale = TranslateManager::GetLanguageCode(locale); string16 language = l10n_util::GetDisplayNameForLocale(locale, locale, true); - AppendMenuItem(IDS_CONTENT_CONTEXT_TRANSLATE, + menu_model_.AddItem(IDS_CONTENT_CONTEXT_TRANSLATE, l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_TRANSLATE, language)); - AppendMenuItem(IDS_CONTENT_CONTEXT_VIEWPAGESOURCE); - AppendMenuItem(IDS_CONTENT_CONTEXT_VIEWPAGEINFO); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_VIEWPAGESOURCE); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_VIEWPAGEINFO); } void RenderViewContextMenu::AppendFrameItems() { - AppendMenuItem(IDS_CONTENT_CONTEXT_BACK); - AppendMenuItem(IDS_CONTENT_CONTEXT_FORWARD); - AppendSeparator(); - AppendMenuItem(IDS_CONTENT_CONTEXT_RELOADFRAME); - AppendMenuItem(IDS_CONTENT_CONTEXT_OPENFRAMENEWTAB); - AppendMenuItem(IDS_CONTENT_CONTEXT_OPENFRAMENEWWINDOW); - AppendMenuItem(IDS_CONTENT_CONTEXT_OPENFRAMEOFFTHERECORD); - AppendSeparator(); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_BACK); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_FORWARD); + menu_model_.AddSeparator(); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_RELOADFRAME); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_OPENFRAMENEWTAB); + menu_model_.AddItemIdentifiedByStringId( + IDS_CONTENT_CONTEXT_OPENFRAMENEWWINDOW); + menu_model_.AddItemIdentifiedByStringId( + IDS_CONTENT_CONTEXT_OPENFRAMEOFFTHERECORD); + menu_model_.AddSeparator(); // These two menu items have yet to be implemented. // http://code.google.com/p/chromium/issues/detail?id=11827 - // AppendMenuItem(IDS_CONTENT_CONTEXT_SAVEFRAMEAS); - // AppendMenuItem(IDS_CONTENT_CONTEXT_PRINTFRAME); - AppendMenuItem(IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE); - AppendMenuItem(IDS_CONTENT_CONTEXT_VIEWFRAMEINFO); + // menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_SAVEFRAMEAS); + // menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_PRINTFRAME); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_VIEWFRAMESOURCE); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_VIEWFRAMEINFO); } void RenderViewContextMenu::AppendCopyItem() { - AppendMenuItem(IDS_CONTENT_CONTEXT_COPY); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_COPY); } void RenderViewContextMenu::AppendSearchProvider() { @@ -461,19 +481,21 @@ void RenderViewContextMenu::AppendSearchProvider() { if (match.transition == PageTransition::TYPED) { if (ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( selection_navigation_url_.scheme())) { - AppendMenuItem(IDS_CONTENT_CONTEXT_GOTOURL, - l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_GOTOURL, - printable_selection_text)); + menu_model_.AddItem( + IDS_CONTENT_CONTEXT_GOTOURL, + l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_GOTOURL, + printable_selection_text)); } } else { const TemplateURL* const default_provider = profile_->GetTemplateURLModel()->GetDefaultSearchProvider(); if (!default_provider) return; - AppendMenuItem(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, - l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, - WideToUTF16(default_provider->short_name()), - printable_selection_text)); + menu_model_.AddItem( + IDS_CONTENT_CONTEXT_SEARCHWEBFOR, + l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFOR, + WideToUTF16(default_provider->short_name()), + printable_selection_text)); } } @@ -482,36 +504,47 @@ void RenderViewContextMenu::AppendEditableItems() { for (size_t i = 0; i < params_.dictionary_suggestions.size() && IDC_SPELLCHECK_SUGGESTION_0 + i <= IDC_SPELLCHECK_SUGGESTION_LAST; ++i) { - AppendMenuItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i), - params_.dictionary_suggestions[i]); + menu_model_.AddItem(IDC_SPELLCHECK_SUGGESTION_0 + static_cast<int>(i), + params_.dictionary_suggestions[i]); } if (params_.dictionary_suggestions.size() > 0) - AppendSeparator(); + menu_model_.AddSeparator(); // If word is misspelled, give option for "Add to dictionary" if (!params_.misspelled_word.empty()) { if (params_.dictionary_suggestions.size() == 0) { - AppendMenuItem(0, + menu_model_.AddItem(0, l10n_util::GetStringUTF16( IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS)); } - AppendMenuItem(IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY); - AppendSeparator(); + menu_model_.AddItemIdentifiedByStringId( + IDS_CONTENT_CONTEXT_ADD_TO_DICTIONARY); + menu_model_.AddSeparator(); } - AppendMenuItem(IDS_CONTENT_CONTEXT_UNDO); - AppendMenuItem(IDS_CONTENT_CONTEXT_REDO); - AppendSeparator(); - AppendMenuItem(IDS_CONTENT_CONTEXT_CUT); - AppendMenuItem(IDS_CONTENT_CONTEXT_COPY); - AppendMenuItem(IDS_CONTENT_CONTEXT_PASTE); - AppendMenuItem(IDS_CONTENT_CONTEXT_DELETE); - AppendSeparator(); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_UNDO); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_REDO); + menu_model_.AddSeparator(); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_CUT); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_COPY); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_PASTE); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_DELETE); + menu_model_.AddSeparator(); - // Add Spell Check options sub menu. - StartSubMenu(IDC_SPELLCHECK_MENU, - l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU)); + AppendSpellcheckOptionsSubMenu(); +#if defined(OS_MACOSX) + // OS X provides a contextual menu to set writing direction for BiDi + // languages. + // This functionality is exposed as a keyboard shortcut on Windows & Linux. + AppendBidiSubMenu(); +#endif // OS_MACOSX + + menu_model_.AddSeparator(); + menu_model_.AddItemIdentifiedByStringId(IDS_CONTENT_CONTEXT_SELECTALL); +} + +void RenderViewContextMenu::AppendSpellcheckOptionsSubMenu() { // Add Spell Check languages to sub menu. std::vector<std::string> spellcheck_languages; SpellCheckHost::GetSpellCheckLanguages(profile_, @@ -522,15 +555,19 @@ void RenderViewContextMenu::AppendEditableItems() { for (size_t i = 0; i < spellcheck_languages.size(); ++i) { string16 display_name(l10n_util::GetDisplayNameForLocale( spellcheck_languages[i], app_locale, true)); - AppendRadioMenuItem(IDC_SPELLCHECK_LANGUAGES_FIRST + i, display_name); + spellcheck_submenu_model_.AddRadioItem( + IDC_SPELLCHECK_LANGUAGES_FIRST + i, + display_name, + kSpellcheckRadioGroup); } // Add item in the sub menu to pop up the fonts and languages options menu. - AppendSeparator(); - AppendMenuItem(IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS); + spellcheck_submenu_model_.AddSeparator(); + spellcheck_submenu_model_.AddItemIdentifiedByStringId( + IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS); // Add 'Check the spelling of this field' item in the sub menu. - AppendCheckboxMenuItem( + spellcheck_submenu_model_.AddCheckItem( IDC_CHECK_SPELLING_OF_THIS_FIELD, l10n_util::GetStringUTF16( IDS_CONTENT_CONTEXT_CHECK_SPELLING_OF_THIS_FIELD)); @@ -539,35 +576,34 @@ void RenderViewContextMenu::AppendEditableItems() { // supports it. if (SpellCheckerPlatform::SpellCheckerAvailable() && SpellCheckerPlatform::SpellCheckerProvidesPanel()) { - AppendCheckboxMenuItem(IDC_SPELLPANEL_TOGGLE, l10n_util::GetStringUTF16( - SpellCheckerPlatform::SpellingPanelVisible() ? - IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : - IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); + spellcheck_submenu_model_.AddCheckItem( + IDC_SPELLPANEL_TOGGLE, + l10n_util::GetStringUTF16( + SpellCheckerPlatform::SpellingPanelVisible() ? + IDS_CONTENT_CONTEXT_HIDE_SPELLING_PANEL : + IDS_CONTENT_CONTEXT_SHOW_SPELLING_PANEL)); } - FinishSubMenu(); - -#if defined(OS_MACOSX) - // OS X provides a contextual menu to set writing direction for BiDi - // languages. - // This functionality is exposed as a keyboard shortcut on Windows & Linux. - // Add writing direction sub menu. - StartSubMenu(IDC_WRITING_DIRECTION_MENU, - l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU)); + menu_model_.AddSubMenu( + -1, l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLCHECK_MENU), + &spellcheck_submenu_model_); +} - AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_DEFAULT, +#if defined(OS_MACOSX) +void RenderViewContextMenu::AppendBidiSubMenu() { + bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_DEFAULT, l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_DEFAULT)); - AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_LTR, + bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_LTR, l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_LTR)); - AppendCheckboxMenuItem(IDC_WRITING_DIRECTION_RTL, + bidi_submenu_model_.AddCheckItem(IDC_WRITING_DIRECTION_RTL, l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_RTL)); - FinishSubMenu(); -#endif // OS_MACOSX - - AppendSeparator(); - AppendMenuItem(IDS_CONTENT_CONTEXT_SELECTALL); + menu_model_.AddSubMenu( + -1, + l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_WRITING_DIRECTION_MENU), + &bidi_submenu_model_); } +#endif // OS_MACOSX ExtensionMenuItem* RenderViewContextMenu::GetExtensionMenuItem(int id) const { ExtensionMenuManager* manager = @@ -583,7 +619,7 @@ ExtensionMenuItem* RenderViewContextMenu::GetExtensionMenuItem(int id) const { // Menu delegate functions ----------------------------------------------------- -bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { +bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { // Allow Spell Check language items on sub menu for text area context menu. if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && (id < IDC_SPELLCHECK_LANGUAGES_LAST)) { @@ -775,7 +811,6 @@ bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { case IDC_SPELLCHECK_SUGGESTION_2: case IDC_SPELLCHECK_SUGGESTION_3: case IDC_SPELLCHECK_SUGGESTION_4: - case IDC_SPELLCHECK_MENU: case IDC_SPELLPANEL_TOGGLE: #if !defined(OS_MACOSX) // TODO(jeremy): re-enable - http://crbug.com/34512 . @@ -806,22 +841,23 @@ bool RenderViewContextMenu::IsItemCommandEnabled(int id) const { #endif // OS_MACOSX #if defined(OS_LINUX) - // Enable the input methods context menu if the content is editable. - // TODO(suzhe): It should not be enabled in password boxes. Anyway, - // it's not a big issue. + // TODO(suzhe): this should not be enabled for password fields. case IDC_INPUT_METHODS_MENU: - return params_.is_editable; + return true; #endif case IDS_CONTENT_CONTEXT_SAVEFRAMEAS: case IDS_CONTENT_CONTEXT_PRINTFRAME: case IDS_CONTENT_CONTEXT_ADDSEARCHENGINE: // Not implemented. + return false; + default: + NOTREACHED(); return false; } } -bool RenderViewContextMenu::ItemIsChecked(int id) const { +bool RenderViewContextMenu::IsCommandIdChecked(int id) const { // See if the video is set to looping. if (id == IDS_CONTENT_CONTEXT_LOOP) { return (params_.media_flags & @@ -871,7 +907,7 @@ bool RenderViewContextMenu::ItemIsChecked(int id) const { (id - IDC_SPELLCHECK_LANGUAGES_FIRST); } -void RenderViewContextMenu::ExecuteItemCommand(int id) { +void RenderViewContextMenu::ExecuteCommand(int id) { // Check to see if one of the spell check language ids have been clicked. if (id >= IDC_SPELLCHECK_LANGUAGES_FIRST && id < IDC_SPELLCHECK_LANGUAGES_LAST) { @@ -1000,16 +1036,17 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) { MediaPlayerActionAt(gfx::Point(params_.x, params_.y), WebMediaPlayerAction( WebMediaPlayerAction::Loop, - !ItemIsChecked(IDS_CONTENT_CONTEXT_LOOP))); + !IsCommandIdChecked(IDS_CONTENT_CONTEXT_LOOP))); break; case IDS_CONTENT_CONTEXT_CONTROLS: UserMetrics::RecordAction(UserMetricsAction("MediaContextMenu_Controls"), profile_); - MediaPlayerActionAt(gfx::Point(params_.x, params_.y), - WebMediaPlayerAction( - WebMediaPlayerAction::Controls, - !ItemIsChecked(IDS_CONTENT_CONTEXT_CONTROLS))); + MediaPlayerActionAt( + gfx::Point(params_.x, params_.y), + WebMediaPlayerAction( + WebMediaPlayerAction::Controls, + !IsCommandIdChecked(IDS_CONTENT_CONTEXT_CONTROLS))); break; case IDS_CONTENT_CONTEXT_BACK: @@ -1025,7 +1062,9 @@ void RenderViewContextMenu::ExecuteItemCommand(int id) { break; case IDS_CONTENT_CONTEXT_RELOAD: - source_tab_contents_->controller().Reload(true); + // Prevent the modal "Resubmit form post" dialog from appearing in the + // context of an external context menu. + source_tab_contents_->controller().Reload(!external_); break; case IDS_CONTENT_CONTEXT_PRINT: diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h index aa90ca9..f6aafea 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.h +++ b/chrome/browser/tab_contents/render_view_context_menu.h @@ -9,7 +9,9 @@ #include <string> #include <vector> +#include "app/menus/simple_menu_model.h" #include "base/string16.h" +#include "base/scoped_vector.h" #include "chrome/common/page_transition_types.h" #include "webkit/glue/context_menu.h" #include "webkit/glue/window_open_disposition.h" @@ -26,7 +28,7 @@ namespace WebKit { struct WebMediaPlayerAction; } -class RenderViewContextMenu { +class RenderViewContextMenu : public menus::SimpleMenuModel::Delegate { public: RenderViewContextMenu(TabContents* tab_contents, const ContextMenuParams& params); @@ -36,50 +38,29 @@ class RenderViewContextMenu { // Initializes the context menu. void Init(); + // SimpleMenuModel::Delegate implementation. + virtual bool IsCommandIdChecked(int command_id) const; + virtual bool IsCommandIdEnabled(int command_id) const; + virtual void ExecuteCommand(int command_id); + protected: void InitMenu(); - // Functions to be implemented by platform-specific subclasses --------------- - - // Platform specific initialization goes here. - virtual void DoInit() {} - - // Append a normal menu item, taking the name from the id. - virtual void AppendMenuItem(int id) = 0; - - // Append a normal menu item, using |label| for the name. - virtual void AppendMenuItem(int id, const string16& label) = 0; - - // Append a radio menu item. - virtual void AppendRadioMenuItem(int id, const string16& label) = 0; - - // Append a checkbox menu item. - virtual void AppendCheckboxMenuItem(int id, const string16& label) = 0; - - // Append a separator. - virtual void AppendSeparator() = 0; - - // Start creating a submenu. Any calls to Append*() between calls to - // StartSubMenu() and FinishSubMenu() will apply to the submenu rather than - // the main menu we are building. We only support at most single-depth - // submenus, so calls to StartSubMenu() while we are already building a - // submenu will be ignored. - virtual void StartSubMenu(int id, const string16& label) = 0; - - // Finish creating the submenu and attach it to the main menu. - virtual void FinishSubMenu() = 0; + // Platform specific functions. + virtual void PlatformInit() = 0; + virtual bool GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) = 0; - // Delegate functions -------------------------------------------------------- - - bool IsItemCommandEnabled(int id) const; - bool ItemIsChecked(int id) const; - virtual void ExecuteItemCommand(int id); - - protected: ContextMenuParams params_; TabContents* source_tab_contents_; Profile* profile_; + menus::SimpleMenuModel menu_model_; + + // True if we are showing for an external tab contents. The default is false. + bool external_; + private: static bool IsDevToolsURL(const GURL& url); bool AppendCustomItems(); @@ -95,19 +76,9 @@ class RenderViewContextMenu { void AppendEditableItems(); void AppendSearchProvider(); void AppendAllExtensionItems(); - - // When extensions have more than 1 top-level item or a single parent item - // with children, we will start a sub menu. In the case of 1 parent with - // children, we will remove the parent from |items| and insert the children - // into it. The |index| parameter is incremented if we start a submenu. This - // returns true if a submenu was started. If we had multiple top-level items - // that needed to be pushed into a submenu, we'll use |extension_name| as the - // title. - bool MaybeStartExtensionSubMenu(const string16& selection_text, - const std::string& extension_name, - std::vector<const ExtensionMenuItem*>* items, - int* index); - + void AppendSpellcheckOptionsSubMenu(); + // Add writing direction sub menu (only used on Mac). + void AppendBidiSubMenu(); // Fills in |items| with matching items for extension with |extension_id|. void GetItemsForExtension(const std::string& extension_id, std::vector<const ExtensionMenuItem*>* items); @@ -152,6 +123,10 @@ class RenderViewContextMenu { // id. std::map<int, int> extension_item_map_; + menus::SimpleMenuModel spellcheck_submenu_model_; + menus::SimpleMenuModel bidi_submenu_model_; + ScopedVector<menus::SimpleMenuModel> extension_menu_models_; + DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); }; diff --git a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc index f335e14..45dcf0ee 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc @@ -7,6 +7,7 @@ #include <gtk/gtk.h> #include "base/string_util.h" +#include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "webkit/glue/context_menu.h" @@ -16,49 +17,28 @@ RenderViewContextMenuGtk::RenderViewContextMenuGtk( const ContextMenuParams& params, guint32 triggering_event_time) : RenderViewContextMenu(web_contents, params), - making_submenu_(false), triggering_event_time_(triggering_event_time) { } RenderViewContextMenuGtk::~RenderViewContextMenuGtk() { } -void RenderViewContextMenuGtk::DoInit() { - DoneMakingMenu(&menu_); - gtk_menu_.reset(new MenuGtk(this, menu_.data())); +void RenderViewContextMenuGtk::PlatformInit() { + menu_gtk_.reset(new MenuGtk(this, &menu_model_)); - RenderWidgetHostViewGtk* rwhv = static_cast<RenderWidgetHostViewGtk*>( - source_tab_contents_->GetRenderWidgetHostView()); - if (rwhv) - rwhv->AppendInputMethodsContextMenu(gtk_menu_.get()); + if (params_.is_editable) { + RenderWidgetHostViewGtk* rwhv = static_cast<RenderWidgetHostViewGtk*>( + source_tab_contents_->GetRenderWidgetHostView()); + if (rwhv) + rwhv->AppendInputMethodsContextMenu(menu_gtk_.get()); + } } void RenderViewContextMenuGtk::Popup(const gfx::Point& point) { RenderWidgetHostView* rwhv = source_tab_contents_->GetRenderWidgetHostView(); if (rwhv) rwhv->ShowingContextMenu(true); - gtk_menu_->PopupAsContextAt(triggering_event_time_, point); -} - -bool RenderViewContextMenuGtk::IsCommandEnabled(int id) const { - return IsItemCommandEnabled(id); -} - -bool RenderViewContextMenuGtk::IsItemChecked(int id) const { - return ItemIsChecked(id); -} - -void RenderViewContextMenuGtk::ExecuteCommandById(int id) { - ExecuteItemCommand(id); -} - -std::string RenderViewContextMenuGtk::GetLabel(int id) const { - std::map<int, std::string>::const_iterator label = label_map_.find(id); - - if (label != label_map_.end()) - return label->second; - - return std::string(); + menu_gtk_->PopupAsContextAt(triggering_event_time_, point); } void RenderViewContextMenuGtk::StoppedShowing() { @@ -66,62 +46,3 @@ void RenderViewContextMenuGtk::StoppedShowing() { if (rwhv) rwhv->ShowingContextMenu(false); } - -void RenderViewContextMenuGtk::AppendMenuItem(int id) { - AppendItem(id, string16(), MENU_NORMAL); -} - -void RenderViewContextMenuGtk::AppendMenuItem(int id, - const string16& label) { - AppendItem(id, label, MENU_NORMAL); -} - -void RenderViewContextMenuGtk::AppendRadioMenuItem(int id, - const string16& label) { - AppendItem(id, label, MENU_RADIO); -} - -void RenderViewContextMenuGtk::AppendCheckboxMenuItem(int id, - const string16& label) { - AppendItem(id, label, MENU_CHECKBOX); -} - -void RenderViewContextMenuGtk::AppendSeparator() { - AppendItem(0, string16(), MENU_SEPARATOR); -} - -void RenderViewContextMenuGtk::StartSubMenu(int id, const string16& label) { - AppendItem(id, label, MENU_NORMAL); - making_submenu_ = true; -} - -void RenderViewContextMenuGtk::FinishSubMenu() { - DoneMakingMenu(&submenu_); - menu_[menu_.size() - 1].submenu = submenu_.data(); - making_submenu_ = false; -} - -void RenderViewContextMenuGtk::AppendItem( - int id, const string16& label, MenuItemType type) { - MenuCreateMaterial menu_create_material = { - type, id, 0, 0, NULL - }; - - if (label.empty()) - menu_create_material.label_id = id; - else - label_map_[id] = UTF16ToUTF8(label); - - std::vector<MenuCreateMaterial>* menu = - making_submenu_ ? &submenu_ : &menu_; - menu->push_back(menu_create_material); -} - -// static -void RenderViewContextMenuGtk::DoneMakingMenu( - std::vector<MenuCreateMaterial>* menu) { - static MenuCreateMaterial end_menu_item = { - MENU_END, 0, 0, 0, NULL - }; - menu->push_back(end_menu_item); -} diff --git a/chrome/browser/tab_contents/render_view_context_menu_gtk.h b/chrome/browser/tab_contents/render_view_context_menu_gtk.h index 921b3de..6573ca5 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_gtk.h +++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -11,14 +11,12 @@ #include "base/scoped_ptr.h" #include "chrome/browser/gtk/menu_gtk.h" -#include "chrome/browser/gtk/standard_menus.h" #include "chrome/browser/tab_contents/render_view_context_menu.h" #include "gfx/point.h" class RenderWidgetHostView; struct ContextMenuParams; -// TODO(port): we need accelerator support for this class. class RenderViewContextMenuGtk : public RenderViewContextMenu, public MenuGtk::Delegate { public: @@ -32,32 +30,20 @@ class RenderViewContextMenuGtk : public RenderViewContextMenu, void Popup(const gfx::Point& point); // Menu::Delegate implementation --------------------------------------------- - virtual bool IsCommandEnabled(int id) const; - virtual bool IsItemChecked(int id) const; - virtual void ExecuteCommandById(int id); - virtual std::string GetLabel(int id) const; virtual void StoppedShowing(); protected: // RenderViewContextMenu implementation -------------------------------------- - virtual void DoInit(); - virtual void AppendMenuItem(int id); - virtual void AppendMenuItem(int id, const string16& label); - virtual void AppendRadioMenuItem(int id, const string16& label); - virtual void AppendCheckboxMenuItem(int id, const string16& label); - virtual void AppendSeparator(); - virtual void StartSubMenu(int id, const string16& label); - virtual void FinishSubMenu(); + virtual void PlatformInit(); + // TODO(port): implement. + virtual bool GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) { + return false; + } private: - void AppendItem(int id, const string16& label, MenuItemType type); - static void DoneMakingMenu(std::vector<MenuCreateMaterial>* menu); - - scoped_ptr<MenuGtk> gtk_menu_; - std::map<int, std::string> label_map_; - std::vector<MenuCreateMaterial> menu_; - std::vector<MenuCreateMaterial> submenu_; - bool making_submenu_; + scoped_ptr<MenuGtk> menu_gtk_; uint32_t triggering_event_time_; }; diff --git a/chrome/browser/tab_contents/render_view_context_menu_mac.h b/chrome/browser/tab_contents/render_view_context_menu_mac.h index ee42bce..2661ffe 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_mac.h +++ b/chrome/browser/tab_contents/render_view_context_menu_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -7,9 +7,10 @@ #import <Cocoa/Cocoa.h> +#include "base/scoped_nsobject.h" #include "chrome/browser/tab_contents/render_view_context_menu.h" -@class ContextMenuTarget; +@class MenuController; // Mac implementation of the context menu display code. Uses a Cocoa NSMenu // to display the context menu. Internally uses an obj-c object as the @@ -22,35 +23,17 @@ class RenderViewContextMenuMac : public RenderViewContextMenu { NSView* parent_view); virtual ~RenderViewContextMenuMac(); - // Elevate to public so that the obj-c target can call it. - void ExecuteCommand(int command_id) { ExecuteItemCommand(command_id); } - protected: // RenderViewContextMenu implementation- - virtual void DoInit(); - virtual void AppendMenuItem(int id); - virtual void AppendMenuItem(int id, const string16& label); - virtual void AppendRadioMenuItem(int id, const string16& label); - virtual void AppendCheckboxMenuItem(int id, const string16& label); - virtual void AppendSeparator(); - virtual void StartSubMenu(int id, const string16& label); - virtual void FinishSubMenu(); - - // Do things like remove the windows accelerators. - static NSString* PrepareLabelForDisplay(const string16& label); + virtual void PlatformInit(); + virtual bool GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) { + return false; + } private: - // Private helper method used by the implementations of the above methods. - // All MenuItems are represented as NSMenuItems no matter what kind they - // are (Normal, Radio, Checkbox). All of the above call this method, providing - // a useful value for |state| based upon some specific lookup, usually based - // on the id. - void AppendMenuItemWithState(int id, const string16& label, - NSCellStateValue state); - NSMenu* menu_; - NSMenu* insert_menu_; // weak, where new items are inserted (usually - // |menu_| unless there's a submenu in progress). - ContextMenuTarget* target_; // obj-c target for menu actions + scoped_nsobject<MenuController> menuController_; NSView* parent_view_; // parent view }; diff --git a/chrome/browser/tab_contents/render_view_context_menu_mac.mm b/chrome/browser/tab_contents/render_view_context_menu_mac.mm index 870831c..42fe061 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_mac.mm +++ b/chrome/browser/tab_contents/render_view_context_menu_mac.mm @@ -1,65 +1,33 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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/tab_contents/render_view_context_menu_mac.h" -#include "app/l10n_util_mac.h" #include "base/compiler_specific.h" #include "base/message_loop.h" #include "base/scoped_nsobject.h" -#include "base/sys_string_conversions.h" -#include "chrome/browser/profile.h" -#include "grit/generated_resources.h" +#import "chrome/browser/cocoa/menu_controller.h" // Obj-C bridge class that is the target of all items in the context menu. -// Relies on the tag being set to the command id. Uses |context_| to -// execute the command once it is selected and determine if commands should -// be enabled or disabled. - -@interface ContextMenuTarget : NSObject { - @private - RenderViewContextMenuMac* context_; // weak, owns us. -} -- (id)initWithContext:(RenderViewContextMenuMac*)context; -- (void)itemSelected:(id)sender; -@end - -@implementation ContextMenuTarget - -- (id)initWithContext:(RenderViewContextMenuMac*)context { - if ((self = [super init])) { - DCHECK(context); - context_ = context; - } - return self; -} - -- (void)itemSelected:(id)sender { - context_->ExecuteCommand([sender tag]); -} - -@end +// Relies on the tag being set to the command id. RenderViewContextMenuMac::RenderViewContextMenuMac( TabContents* web_contents, const ContextMenuParams& params, NSView* parent_view) : RenderViewContextMenu(web_contents, params), - menu_([[NSMenu alloc] init]), - insert_menu_(menu_), - target_(nil), parent_view_(parent_view) { - [menu_ setAutoenablesItems:NO]; - target_ = [[ContextMenuTarget alloc] initWithContext:this]; } RenderViewContextMenuMac::~RenderViewContextMenuMac() { - [target_ release]; - [menu_ release]; } -void RenderViewContextMenuMac::DoInit() { +void RenderViewContextMenuMac::PlatformInit() { + menuController_.reset( + [[MenuController alloc] initWithModel:&menu_model_ + useWithPopUpButtonCell:NO]); + // Synthesize an event for the click, as there is no certainty that // [NSApp currentEvent] will return a valid event. NSEvent* currentEvent = [NSApp currentEvent]; @@ -81,89 +49,8 @@ void RenderViewContextMenuMac::DoInit() { MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); // Show the menu. - [NSMenu popUpContextMenu:menu_ + [NSMenu popUpContextMenu:[menuController_ menu] withEvent:clickEvent forView:parent_view_]; } } - -// Do things like remove the windows accelerators. Since we control the -// contents of this context menu, we don't need to worry about maximum string -// lengths or middle-truncation. -NSString* RenderViewContextMenuMac::PrepareLabelForDisplay( - const string16& label) { - NSString* title = l10n_util::FixUpWindowsStyleLabel(label); - DCHECK(title); - return title ? title : @""; -} - -void RenderViewContextMenuMac::AppendMenuItem(int command_id) { - AppendMenuItem(command_id, l10n_util::GetStringUTF16(command_id)); -} - -void RenderViewContextMenuMac::AppendMenuItem(int command_id, - const string16& label) { - AppendMenuItemWithState(command_id, label, NSOffState); -} - -void RenderViewContextMenuMac::AppendRadioMenuItem(int command_id, - const string16& label) { - AppendMenuItemWithState(command_id, label, - ItemIsChecked(command_id) ? NSOnState : NSOffState); - -} -void RenderViewContextMenuMac::AppendCheckboxMenuItem(int command_id, - const string16& label) { - AppendMenuItemWithState(command_id, label, - ItemIsChecked(command_id) ? NSOnState : NSOffState); -} - -void RenderViewContextMenuMac::AppendSeparator() { - NSMenuItem* separator = [NSMenuItem separatorItem]; - [insert_menu_ addItem:separator]; -} - -void RenderViewContextMenuMac::StartSubMenu(int command_id, - const string16& label) { - // I'm not a fan of this kind of API, but the other platforms have similar - // guards so at least we know everyone will break together if someone - // tries to mis-use the API. - if (insert_menu_ != menu_) { - NOTREACHED(); - return; - } - - // We don't need to retain the submenu as the context menu already does, but - // we switch the "insert menu" so subsequent items are added to the submenu - // and not the main menu. This happens until someone calls FinishSubMenu(). - scoped_nsobject<NSMenuItem> submenu_item([[NSMenuItem alloc] - initWithTitle:PrepareLabelForDisplay(label) - action:nil - keyEquivalent:@""]); - insert_menu_ = [[[NSMenu alloc] init] autorelease]; - [insert_menu_ setAutoenablesItems:NO]; - [submenu_item setSubmenu:insert_menu_]; - [menu_ addItem:submenu_item]; -} - -void RenderViewContextMenuMac::FinishSubMenu() { - // Set the "insert menu" back to the main menu so that subsequently added - // items get added to the main context menu. - DCHECK(insert_menu_ != menu_); - insert_menu_ = menu_; -} - -void RenderViewContextMenuMac::AppendMenuItemWithState(int command_id, - const string16& label, - NSCellStateValue state) { - scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc] - initWithTitle:PrepareLabelForDisplay(label) - action:@selector(itemSelected:) - keyEquivalent:@""]); - [item setState:state]; - [item setTag:command_id]; - [item setTarget:target_]; - [item setEnabled:IsItemCommandEnabled(command_id) ? YES : NO]; - [insert_menu_ addItem:item]; -} - diff --git a/chrome/browser/translate/translate_manager_unittest.cc b/chrome/browser/translate/translate_manager_unittest.cc index a4b1f6c..e4d6539 100644 --- a/chrome/browser/translate/translate_manager_unittest.cc +++ b/chrome/browser/translate/translate_manager_unittest.cc @@ -239,30 +239,13 @@ class TestRenderViewContextMenu : public RenderViewContextMenu { } bool IsItemPresent(int id) { - return std::find(item_ids_.begin(), item_ids_.end(), id) != item_ids_.end(); + return menu_model_.GetIndexOfCommandId(id) != -1; } - bool TestIsItemCommandEnabled(int id) const { - return IsItemCommandEnabled(id); - } - void TestExecuteItemCommand(int id) { return ExecuteItemCommand(id); } - - protected: - virtual void AppendMenuItem(int id) { item_ids_.push_back(id); } - virtual void AppendMenuItem(int id, const string16& label) { - item_ids_.push_back(id); - } - virtual void AppendRadioMenuItem(int id, const string16& label) { - item_ids_.push_back(id); - } - virtual void AppendCheckboxMenuItem(int id, const string16& label) { - item_ids_.push_back(id); - } - virtual void AppendSeparator() {} - virtual void StartSubMenu(int id, const string16& label) { - item_ids_.push_back(id); - } - virtual void FinishSubMenu() {} + virtual void PlatformInit() { } + virtual bool GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) { return false; } private: TestRenderViewContextMenu(TabContents* tab_contents, @@ -270,8 +253,6 @@ class TestRenderViewContextMenu : public RenderViewContextMenu { : RenderViewContextMenu(tab_contents, params) { } - std::vector<int> item_ids_; - DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); }; @@ -851,10 +832,10 @@ TEST_F(TranslateManagerTest, ContextMenu) { TestRenderViewContextMenu::CreateContextMenu(contents())); menu->Init(); EXPECT_TRUE(menu->IsItemPresent(IDS_CONTENT_CONTEXT_TRANSLATE)); - EXPECT_TRUE(menu->TestIsItemCommandEnabled(IDS_CONTENT_CONTEXT_TRANSLATE)); + EXPECT_TRUE(menu->IsCommandIdEnabled(IDS_CONTENT_CONTEXT_TRANSLATE)); // Use the menu to translate the page. - menu->TestExecuteItemCommand(IDS_CONTENT_CONTEXT_TRANSLATE); + menu->ExecuteCommand(IDS_CONTENT_CONTEXT_TRANSLATE); // That should have triggered a translation. SimulateURLFetch(true); // Simulate the translate script being retrieved. @@ -878,7 +859,7 @@ TEST_F(TranslateManagerTest, ContextMenu) { menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); menu->Init(); EXPECT_TRUE(menu->IsItemPresent(IDS_CONTENT_CONTEXT_TRANSLATE)); - EXPECT_FALSE(menu->TestIsItemCommandEnabled(IDS_CONTENT_CONTEXT_TRANSLATE)); + EXPECT_FALSE(menu->IsCommandIdEnabled(IDS_CONTENT_CONTEXT_TRANSLATE)); // Test that selecting translate in the context menu WHILE the page is being // translated does nothing (this could happen if autotranslate kicks-in and @@ -892,8 +873,8 @@ TEST_F(TranslateManagerTest, ContextMenu) { process()->sink().ClearMessages(); menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); menu->Init(); - EXPECT_TRUE(menu->TestIsItemCommandEnabled(IDS_CONTENT_CONTEXT_TRANSLATE)); - menu->TestExecuteItemCommand(IDS_CONTENT_CONTEXT_TRANSLATE); + EXPECT_TRUE(menu->IsCommandIdEnabled(IDS_CONTENT_CONTEXT_TRANSLATE)); + menu->ExecuteCommand(IDS_CONTENT_CONTEXT_TRANSLATE); // No message expected since the translation should have been ignored. EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); @@ -908,10 +889,10 @@ TEST_F(TranslateManagerTest, ContextMenu) { process()->sink().ClearMessages(); menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); menu->Init(); - EXPECT_TRUE(menu->TestIsItemCommandEnabled(IDS_CONTENT_CONTEXT_TRANSLATE)); + EXPECT_TRUE(menu->IsCommandIdEnabled(IDS_CONTENT_CONTEXT_TRANSLATE)); rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "de", "en", TranslateErrors::NONE)); - menu->TestExecuteItemCommand(IDS_CONTENT_CONTEXT_TRANSLATE); + menu->ExecuteCommand(IDS_CONTENT_CONTEXT_TRANSLATE); // No message expected since the translation should have been ignored. EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); @@ -921,5 +902,5 @@ TEST_F(TranslateManagerTest, ContextMenu) { menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents())); menu->Init(); EXPECT_TRUE(menu->IsItemPresent(IDS_CONTENT_CONTEXT_TRANSLATE)); - EXPECT_FALSE(menu->TestIsItemCommandEnabled(IDS_CONTENT_CONTEXT_TRANSLATE)); + EXPECT_FALSE(menu->IsCommandIdEnabled(IDS_CONTENT_CONTEXT_TRANSLATE)); } diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 4f4c93f..2dd47f4 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -2118,10 +2118,11 @@ void BrowserView::BuildSystemMenuForAppOrPopupWindow(bool is_app) { } system_menu_contents_->AddSeparator(); encoding_menu_contents_.reset(new EncodingMenuModel(browser_.get())); - system_menu_contents_->AddSubMenuWithStringId(IDS_ENCODING_MENU, + system_menu_contents_->AddSubMenuWithStringId(IDC_ENCODING_MENU, + IDS_ENCODING_MENU, encoding_menu_contents_.get()); zoom_menu_contents_.reset(new ZoomMenuModel(this)); - system_menu_contents_->AddSubMenuWithStringId(IDS_ZOOM_MENU, + system_menu_contents_->AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_ZOOM_MENU, zoom_menu_contents_.get()); system_menu_contents_->AddItemWithStringId(IDC_PRINT, IDS_PRINT); system_menu_contents_->AddItemWithStringId(IDC_FIND, IDS_FIND); diff --git a/chrome/browser/views/tab_contents/render_view_context_menu_external_win.cc b/chrome/browser/views/tab_contents/render_view_context_menu_external_win.cc deleted file mode 100644 index b1b2316..0000000 --- a/chrome/browser/views/tab_contents/render_view_context_menu_external_win.cc +++ /dev/null @@ -1,55 +0,0 @@ -// 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/views/tab_contents/render_view_context_menu_external_win.h" - -#include <algorithm> - -#include "chrome/browser/tab_contents/tab_contents.h" -#include "grit/generated_resources.h" - -RenderViewContextMenuExternalWin::RenderViewContextMenuExternalWin( - TabContents* tab_contents, - const ContextMenuParams& params, - const std::vector<int> disabled_ids) - : RenderViewContextMenuWin(tab_contents, params), - disabled_menu_ids_(disabled_ids) { -} - -void RenderViewContextMenuExternalWin::AppendMenuItem(int id) { - std::vector<int>::iterator found = - std::find(disabled_menu_ids_.begin(), disabled_menu_ids_.end(), id); - - if (found == disabled_menu_ids_.end()) { - RenderViewContextMenuWin::AppendMenuItem(id); - } -} - -void RenderViewContextMenuExternalWin::DoInit() { - RenderViewContextMenuWin::DoInit(); - // The external tab container needs to be notified by command - // and not by index. So we are turning off the MNS_NOTIFYBYPOS - // style. - HMENU menu = GetMenuHandle(); - DCHECK(menu != NULL); - - MENUINFO mi = {0}; - mi.cbSize = sizeof(mi); - mi.fMask = MIM_STYLE | MIM_MENUDATA; - mi.dwMenuData = reinterpret_cast<ULONG_PTR>(this); - SetMenuInfo(menu, &mi); -} - -void RenderViewContextMenuExternalWin::ExecuteItemCommand(int id) { - switch (id) { - case IDS_CONTENT_CONTEXT_RELOAD: - // Prevent the modal "Resubmit form post" dialog from appearing in the - // context of an external context menu. - source_tab_contents_->controller().Reload(false); - break; - default: - RenderViewContextMenu::ExecuteItemCommand(id); - break; - } -} diff --git a/chrome/browser/views/tab_contents/render_view_context_menu_external_win.h b/chrome/browser/views/tab_contents/render_view_context_menu_external_win.h deleted file mode 100644 index 6f5e5cb5..0000000 --- a/chrome/browser/views/tab_contents/render_view_context_menu_external_win.h +++ /dev/null @@ -1,37 +0,0 @@ -// 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_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_EXTERNAL_WIN_H_ -#define CHROME_BROWSER_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_EXTERNAL_WIN_H_ - -#include <vector> - -#include "chrome/browser/views/tab_contents/render_view_context_menu_win.h" - -// This class provides a facility for an external host to customize the context -// menu displayed in Chrome. -class RenderViewContextMenuExternalWin : public RenderViewContextMenuWin { - public: - RenderViewContextMenuExternalWin(TabContents* tab_contents, - const ContextMenuParams& params, - const std::vector<int> disabled_menu_ids); - - virtual ~RenderViewContextMenuExternalWin() {} - - protected: - // RenderViewContextMenuWin overrides -------------------------------------- - virtual void AppendMenuItem(int id); - - // RenderViewContextMenu override - virtual void DoInit(); - - // RenderViewContextMenu override - virtual void ExecuteItemCommand(int id); - - private: - // Contains the list of context menu ids to be disabled. - std::vector<int> disabled_menu_ids_; -}; - -#endif // CHROME_BROWSER_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_EXTERNAL_WIN_H_ diff --git a/chrome/browser/views/tab_contents/render_view_context_menu_gtk.cc b/chrome/browser/views/tab_contents/render_view_context_menu_gtk.cc deleted file mode 100644 index 37433ea..0000000 --- a/chrome/browser/views/tab_contents/render_view_context_menu_gtk.cc +++ /dev/null @@ -1,143 +0,0 @@ -// 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/views/tab_contents/render_view_context_menu_gtk.h" - -#include "app/l10n_util.h" -#include "base/compiler_specific.h" -#include "base/keyboard_codes.h" -#include "chrome/browser/profile.h" -#include "grit/generated_resources.h" -#include "views/accelerator.h" -#include "views/controls/menu/menu_2.h" - -//////////////////////////////////////////////////////////////////////////////// -// RenderViewContextMenuGtk, public: - -RenderViewContextMenuGtk::RenderViewContextMenuGtk( - TabContents* tab_contents, - const ContextMenuParams& params) - : RenderViewContextMenu(tab_contents, params), - current_radio_group_id_(-1), - sub_menu_contents_(NULL) { - menu_contents_.reset(new menus::SimpleMenuModel(this)); -} - -RenderViewContextMenuGtk::~RenderViewContextMenuGtk() { -} - -void RenderViewContextMenuGtk::RunMenuAt(int x, int y) { - menu_->RunContextMenuAt(gfx::Point(x, y)); -} - -//////////////////////////////////////////////////////////////////////////////// -// RenderViewContextMenuGtk, menus::SimpleMenuModel::Delegate implementation: - -bool RenderViewContextMenuGtk::IsCommandIdChecked(int command_id) const { - return ItemIsChecked(command_id); -} - -bool RenderViewContextMenuGtk::IsCommandIdEnabled(int command_id) const { - return IsItemCommandEnabled(command_id); -} - -bool RenderViewContextMenuGtk::GetAcceleratorForCommandId( - int command_id, - menus::Accelerator* accel) { - // There are no formally defined accelerators we can query so we assume - // that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do. - switch (command_id) { - case IDS_CONTENT_CONTEXT_UNDO: - *accel = views::Accelerator(base::VKEY_Z, false, true, false); - return true; - - case IDS_CONTENT_CONTEXT_REDO: - // TODO(jcampan): should it be Ctrl-Y? - *accel = views::Accelerator(base::VKEY_Z, true, true, false); - return true; - - case IDS_CONTENT_CONTEXT_CUT: - *accel = views::Accelerator(base::VKEY_X, false, true, false); - return true; - - case IDS_CONTENT_CONTEXT_COPY: - *accel = views::Accelerator(base::VKEY_C, false, true, false); - return true; - - case IDS_CONTENT_CONTEXT_PASTE: - *accel = views::Accelerator(base::VKEY_V, false, true, false); - return true; - - case IDS_CONTENT_CONTEXT_SELECTALL: - *accel = views::Accelerator(base::VKEY_A, false, true, false); - return true; - - default: - return false; - } -} - -void RenderViewContextMenuGtk::ExecuteCommand(int command_id) { - ExecuteItemCommand(command_id); -} - -//////////////////////////////////////////////////////////////////////////////// -// RenderViewContextMenuGtk, protected: - -void RenderViewContextMenuGtk::DoInit() { - menu_.reset(new views::Menu2(menu_contents_.get())); -} - -void RenderViewContextMenuGtk::AppendMenuItem(int id) { - current_radio_group_id_ = -1; - GetTargetModel()->AddItemWithStringId(id, id); -} - -void RenderViewContextMenuGtk::AppendMenuItem(int id, - const string16& label) { - current_radio_group_id_ = -1; - GetTargetModel()->AddItem(id, label); -} - -void RenderViewContextMenuGtk::AppendRadioMenuItem(int id, - const string16& label) { - if (current_radio_group_id_ < 0) - current_radio_group_id_ = id; - GetTargetModel()->AddRadioItem(id, label, current_radio_group_id_); -} - -void RenderViewContextMenuGtk::AppendCheckboxMenuItem(int id, - const string16& label) { - current_radio_group_id_ = -1; - GetTargetModel()->AddCheckItem(id, label); -} - -void RenderViewContextMenuGtk::AppendSeparator() { - current_radio_group_id_ = -1; - GetTargetModel()->AddSeparator(); -} - -void RenderViewContextMenuGtk::StartSubMenu(int id, const string16& label) { - if (sub_menu_contents_) { - NOTREACHED() << "nested submenus not supported yet"; - return; - } - current_radio_group_id_ = -1; - sub_menu_contents_ = new menus::SimpleMenuModel(this); - menu_contents_->AddSubMenu(label, sub_menu_contents_); - submenu_models_.push_back(sub_menu_contents_); -} - -void RenderViewContextMenuGtk::FinishSubMenu() { - DCHECK(sub_menu_contents_); - current_radio_group_id_ = -1; - sub_menu_contents_ = NULL; -} - -//////////////////////////////////////////////////////////////////////////////// -// RenderViewContextMenuGtk, private: - -menus::SimpleMenuModel* RenderViewContextMenuGtk::GetTargetModel() const { - return sub_menu_contents_ ? sub_menu_contents_ : menu_contents_.get(); -} diff --git a/chrome/browser/views/tab_contents/render_view_context_menu_gtk.h b/chrome/browser/views/tab_contents/render_view_context_menu_gtk.h deleted file mode 100644 index 769ba06..0000000 --- a/chrome/browser/views/tab_contents/render_view_context_menu_gtk.h +++ /dev/null @@ -1,64 +0,0 @@ -// 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_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_GTK_H_ -#define CHROME_BROWSER_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_GTK_H_ - -#include "app/menus/simple_menu_model.h" -#include "base/scoped_ptr.h" -#include "base/scoped_vector.h" -#include "chrome/browser/tab_contents/render_view_context_menu.h" -#include "views/controls/menu/menu_2.h" - -class RenderViewContextMenuGtk : public RenderViewContextMenu, - public menus::SimpleMenuModel::Delegate { - public: - RenderViewContextMenuGtk(TabContents* tab_contents, - const ContextMenuParams& params); - - virtual ~RenderViewContextMenuGtk(); - - void RunMenuAt(int x, int y); - - // Overridden from menus::SimpleMenuModel::Delegate: - virtual bool IsCommandIdChecked(int command_id) const; - virtual bool IsCommandIdEnabled(int command_id) const; - virtual bool GetAcceleratorForCommandId(int command_id, - menus::Accelerator* accelerator); - virtual void ExecuteCommand(int command_id); - - gfx::NativeMenu GetMenuHandle() const { - return (menu_.get() ? menu_->GetNativeMenu() : NULL); - } - - protected: - // RenderViewContextMenu implementation -------------------------------------- - virtual void DoInit(); - virtual void AppendMenuItem(int id); - virtual void AppendMenuItem(int id, const string16& label); - virtual void AppendRadioMenuItem(int id, const string16& label); - virtual void AppendCheckboxMenuItem(int id, const string16& label); - virtual void AppendSeparator(); - virtual void StartSubMenu(int id, const string16& label); - virtual void FinishSubMenu(); - - private: - // Gets the target model to append items to. This is either the main context - // menu, or a submenu if we've descended into one. - menus::SimpleMenuModel* GetTargetModel() const; - - // The current radio group for radio menu items. - int current_radio_group_id_; - - // The context menu itself and its contents. - scoped_ptr<menus::SimpleMenuModel> menu_contents_; - scoped_ptr<views::Menu2> menu_; - // TODO(beng): This way of building submenus is kind of retarded, but it - // hasn't hurt us yet. It's just a bit awkward. - menus::SimpleMenuModel* sub_menu_contents_; - // We own submenu models that we create, so we store them here. - ScopedVector<menus::SimpleMenuModel> submenu_models_; -}; - -#endif // CHROME_BROWSER_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_GTK_H_ diff --git a/chrome/browser/views/tab_contents/render_view_context_menu_views.cc b/chrome/browser/views/tab_contents/render_view_context_menu_views.cc new file mode 100644 index 0000000..80535e1 --- /dev/null +++ b/chrome/browser/views/tab_contents/render_view_context_menu_views.cc @@ -0,0 +1,94 @@ +// 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/views/tab_contents/render_view_context_menu_views.h" + +#include "app/l10n_util.h" +#include "base/compiler_specific.h" +#include "base/keyboard_codes.h" +#include "chrome/browser/profile.h" +#include "grit/generated_resources.h" +#include "views/accelerator.h" +#include "views/controls/menu/menu_2.h" + +//////////////////////////////////////////////////////////////////////////////// +// RenderViewContextMenuViews, public: + +RenderViewContextMenuViews::RenderViewContextMenuViews( + TabContents* tab_contents, + const ContextMenuParams& params) + : RenderViewContextMenu(tab_contents, params) { +} + +RenderViewContextMenuViews::~RenderViewContextMenuViews() { +} + +void RenderViewContextMenuViews::RunMenuAt(int x, int y) { + menu_->RunContextMenuAt(gfx::Point(x, y)); +} + +#if defined(OS_WIN) +void RenderViewContextMenuViews::SetExternal() { + external_ = true; +} +#endif + +//////////////////////////////////////////////////////////////////////////////// +// RenderViewContextMenuViews, protected: + +void RenderViewContextMenuViews::PlatformInit() { + menu_.reset(new views::Menu2(&menu_model_)); + +#if defined(OS_WIN) + if (external_) { + // The external tab container needs to be notified by command + // and not by index. So we are turning off the MNS_NOTIFYBYPOS + // style. + HMENU menu = GetMenuHandle(); + DCHECK(menu != NULL); + + MENUINFO mi = {0}; + mi.cbSize = sizeof(mi); + mi.fMask = MIM_STYLE | MIM_MENUDATA; + mi.dwMenuData = reinterpret_cast<ULONG_PTR>(this); + SetMenuInfo(menu, &mi); + } +#endif +} + +bool RenderViewContextMenuViews::GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accel) { + // There are no formally defined accelerators we can query so we assume + // that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do. + switch (command_id) { + case IDS_CONTENT_CONTEXT_UNDO: + *accel = views::Accelerator(base::VKEY_Z, false, true, false); + return true; + + case IDS_CONTENT_CONTEXT_REDO: + // TODO(jcampan): should it be Ctrl-Y? + *accel = views::Accelerator(base::VKEY_Z, true, true, false); + return true; + + case IDS_CONTENT_CONTEXT_CUT: + *accel = views::Accelerator(base::VKEY_X, false, true, false); + return true; + + case IDS_CONTENT_CONTEXT_COPY: + *accel = views::Accelerator(base::VKEY_C, false, true, false); + return true; + + case IDS_CONTENT_CONTEXT_PASTE: + *accel = views::Accelerator(base::VKEY_V, false, true, false); + return true; + + case IDS_CONTENT_CONTEXT_SELECTALL: + *accel = views::Accelerator(base::VKEY_A, false, true, false); + return true; + + default: + return false; + } +} diff --git a/chrome/browser/views/tab_contents/render_view_context_menu_views.h b/chrome/browser/views/tab_contents/render_view_context_menu_views.h new file mode 100644 index 0000000..1203d4f --- /dev/null +++ b/chrome/browser/views/tab_contents/render_view_context_menu_views.h @@ -0,0 +1,48 @@ +// 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_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_VIEWS_H_ +#define CHROME_BROWSER_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_VIEWS_H_ + +#include "app/menus/simple_menu_model.h" +#include "base/scoped_ptr.h" +#include "base/scoped_vector.h" +#include "chrome/browser/tab_contents/render_view_context_menu.h" +#include "views/controls/menu/menu_2.h" + +class RenderViewContextMenuViews : public RenderViewContextMenu { + public: + RenderViewContextMenuViews(TabContents* tab_contents, + const ContextMenuParams& params); + + virtual ~RenderViewContextMenuViews(); + + void RunMenuAt(int x, int y); + + gfx::NativeMenu GetMenuHandle() const { + return (menu_.get() ? menu_->GetNativeMenu() : NULL); + } + +#if defined(OS_WIN) + // Set this menu to show for an external tab contents. This + // only has an effect before Init() is called. + void SetExternal(); +#endif + + protected: + // RenderViewContextMenu implementation -------------------------------------- + virtual void PlatformInit(); + virtual bool GetAcceleratorForCommandId(int command_id, + menus::Accelerator* accelerator); + private: + // The current radio group for radio menu items. + int current_radio_group_id_; + + // The context menu itself and its contents. + scoped_ptr<views::Menu2> menu_; + + DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuViews); +}; + +#endif // CHROME_BROWSER_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_VIEWS_H_ diff --git a/chrome/browser/views/tab_contents/render_view_context_menu_win.cc b/chrome/browser/views/tab_contents/render_view_context_menu_win.cc deleted file mode 100644 index 9159da2..0000000 --- a/chrome/browser/views/tab_contents/render_view_context_menu_win.cc +++ /dev/null @@ -1,143 +0,0 @@ -// 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/views/tab_contents/render_view_context_menu_win.h" - -#include "app/l10n_util.h" -#include "base/compiler_specific.h" -#include "base/keyboard_codes.h" -#include "chrome/browser/profile.h" -#include "grit/generated_resources.h" -#include "views/accelerator.h" -#include "views/controls/menu/menu_2.h" - -//////////////////////////////////////////////////////////////////////////////// -// RenderViewContextMenuWin, public: - -RenderViewContextMenuWin::RenderViewContextMenuWin( - TabContents* tab_contents, - const ContextMenuParams& params) - : RenderViewContextMenu(tab_contents, params), - current_radio_group_id_(-1), - sub_menu_contents_(NULL) { - menu_contents_.reset(new menus::SimpleMenuModel(this)); -} - -RenderViewContextMenuWin::~RenderViewContextMenuWin() { -} - -void RenderViewContextMenuWin::RunMenuAt(int x, int y) { - menu_->RunContextMenuAt(gfx::Point(x, y)); -} - -//////////////////////////////////////////////////////////////////////////////// -// RenderViewContextMenuWin, menus::SimpleMenuModel::Delegate implementation: - -bool RenderViewContextMenuWin::IsCommandIdChecked(int command_id) const { - return ItemIsChecked(command_id); -} - -bool RenderViewContextMenuWin::IsCommandIdEnabled(int command_id) const { - return IsItemCommandEnabled(command_id); -} - -bool RenderViewContextMenuWin::GetAcceleratorForCommandId( - int command_id, - menus::Accelerator* accel) { - // There are no formally defined accelerators we can query so we assume - // that Ctrl+C, Ctrl+V, Ctrl+X, Ctrl-A, etc do what they normally do. - switch (command_id) { - case IDS_CONTENT_CONTEXT_UNDO: - *accel = views::Accelerator(base::VKEY_Z, false, true, false); - return true; - - case IDS_CONTENT_CONTEXT_REDO: - // TODO(jcampan): should it be Ctrl-Y? - *accel = views::Accelerator(base::VKEY_Z, true, true, false); - return true; - - case IDS_CONTENT_CONTEXT_CUT: - *accel = views::Accelerator(base::VKEY_X, false, true, false); - return true; - - case IDS_CONTENT_CONTEXT_COPY: - *accel = views::Accelerator(base::VKEY_C, false, true, false); - return true; - - case IDS_CONTENT_CONTEXT_PASTE: - *accel = views::Accelerator(base::VKEY_V, false, true, false); - return true; - - case IDS_CONTENT_CONTEXT_SELECTALL: - *accel = views::Accelerator(base::VKEY_A, false, true, false); - return true; - - default: - return false; - } -} - -void RenderViewContextMenuWin::ExecuteCommand(int command_id) { - ExecuteItemCommand(command_id); -} - -//////////////////////////////////////////////////////////////////////////////// -// RenderViewContextMenuWin, protected: - -void RenderViewContextMenuWin::DoInit() { - menu_.reset(new views::Menu2(menu_contents_.get())); -} - -void RenderViewContextMenuWin::AppendMenuItem(int id) { - current_radio_group_id_ = -1; - GetTargetModel()->AddItemWithStringId(id, id); -} - -void RenderViewContextMenuWin::AppendMenuItem(int id, - const string16& label) { - current_radio_group_id_ = -1; - GetTargetModel()->AddItem(id, label); -} - -void RenderViewContextMenuWin::AppendRadioMenuItem(int id, - const string16& label) { - if (current_radio_group_id_ < 0) - current_radio_group_id_ = id; - GetTargetModel()->AddRadioItem(id, label, current_radio_group_id_); -} - -void RenderViewContextMenuWin::AppendCheckboxMenuItem(int id, - const string16& label) { - current_radio_group_id_ = -1; - GetTargetModel()->AddCheckItem(id, label); -} - -void RenderViewContextMenuWin::AppendSeparator() { - current_radio_group_id_ = -1; - GetTargetModel()->AddSeparator(); -} - -void RenderViewContextMenuWin::StartSubMenu(int id, const string16& label) { - if (sub_menu_contents_) { - NOTREACHED() << "nested submenus not supported yet"; - return; - } - current_radio_group_id_ = -1; - sub_menu_contents_ = new menus::SimpleMenuModel(this); - menu_contents_->AddSubMenu(label, sub_menu_contents_); - submenu_models_.push_back(sub_menu_contents_); -} - -void RenderViewContextMenuWin::FinishSubMenu() { - DCHECK(sub_menu_contents_); - current_radio_group_id_ = -1; - sub_menu_contents_ = NULL; -} - -//////////////////////////////////////////////////////////////////////////////// -// RenderViewContextMenuWin, private: - -menus::SimpleMenuModel* RenderViewContextMenuWin::GetTargetModel() const { - return sub_menu_contents_ ? sub_menu_contents_ : menu_contents_.get(); -} diff --git a/chrome/browser/views/tab_contents/render_view_context_menu_win.h b/chrome/browser/views/tab_contents/render_view_context_menu_win.h deleted file mode 100644 index e719469..0000000 --- a/chrome/browser/views/tab_contents/render_view_context_menu_win.h +++ /dev/null @@ -1,64 +0,0 @@ -// 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_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_WIN_H_ -#define CHROME_BROWSER_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_WIN_H_ - -#include "app/menus/simple_menu_model.h" -#include "base/scoped_ptr.h" -#include "base/scoped_vector.h" -#include "chrome/browser/tab_contents/render_view_context_menu.h" -#include "views/controls/menu/menu_2.h" - -class RenderViewContextMenuWin : public RenderViewContextMenu, - public menus::SimpleMenuModel::Delegate { - public: - RenderViewContextMenuWin(TabContents* tab_contents, - const ContextMenuParams& params); - - virtual ~RenderViewContextMenuWin(); - - void RunMenuAt(int x, int y); - - // Overridden from menus::SimpleMenuModel::Delegate: - virtual bool IsCommandIdChecked(int command_id) const; - virtual bool IsCommandIdEnabled(int command_id) const; - virtual bool GetAcceleratorForCommandId(int command_id, - menus::Accelerator* accelerator); - virtual void ExecuteCommand(int command_id); - - gfx::NativeMenu GetMenuHandle() const { - return (menu_.get() ? menu_->GetNativeMenu() : NULL); - } - - protected: - // RenderViewContextMenu implementation -------------------------------------- - virtual void DoInit(); - virtual void AppendMenuItem(int id); - virtual void AppendMenuItem(int id, const string16& label); - virtual void AppendRadioMenuItem(int id, const string16& label); - virtual void AppendCheckboxMenuItem(int id, const string16& label); - virtual void AppendSeparator(); - virtual void StartSubMenu(int id, const string16& label); - virtual void FinishSubMenu(); - - private: - // Gets the target model to append items to. This is either the main context - // menu, or a submenu if we've descended into one. - menus::SimpleMenuModel* GetTargetModel() const; - - // The current radio group for radio menu items. - int current_radio_group_id_; - - // The context menu itself and its contents. - scoped_ptr<menus::SimpleMenuModel> menu_contents_; - scoped_ptr<views::Menu2> menu_; - // TODO(beng): This way of building submenus is kind of retarded, but it - // hasn't hurt us yet. It's just a bit awkward. - menus::SimpleMenuModel* sub_menu_contents_; - // We own submenu models that we create, so we store them here. - ScopedVector<menus::SimpleMenuModel> submenu_models_; -}; - -#endif // CHROME_BROWSER_VIEWS_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_WIN_H_ diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc index 9742a95..d6fd5db 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc @@ -20,7 +20,7 @@ #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/tab_contents/web_drag_dest_gtk.h" #include "chrome/browser/views/sad_tab_view.h" -#include "chrome/browser/views/tab_contents/render_view_context_menu_gtk.h" +#include "chrome/browser/views/tab_contents/render_view_context_menu_views.h" #include "gfx/canvas_paint.h" #include "gfx/point.h" #include "gfx/rect.h" @@ -347,7 +347,7 @@ void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) { if (tab_contents()->delegate()->HandleContextMenu(params)) return; - context_menu_.reset(new RenderViewContextMenuGtk(tab_contents(), params)); + context_menu_.reset(new RenderViewContextMenuViews(tab_contents(), params)); context_menu_->Init(); gfx::Point screen_point(params.x, params.y); diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.h b/chrome/browser/views/tab_contents/tab_contents_view_gtk.h index 540274a..b4788c8 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.h +++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.h @@ -14,7 +14,7 @@ class ConstrainedWindowGtk; typedef struct _GtkFloatingContainer GtkFloatingContainer; -class RenderViewContextMenuGtk; +class RenderViewContextMenuViews; class SadTabView; class SkBitmap; class TabContentsDragSource; @@ -109,7 +109,7 @@ class TabContentsViewGtk : public TabContentsView, int last_focused_view_storage_id_; // The context menu. Callbacks are asynchronous so we need to keep it around. - scoped_ptr<RenderViewContextMenuGtk> context_menu_; + scoped_ptr<RenderViewContextMenuViews> context_menu_; // Handles drags from this TabContentsView. scoped_ptr<TabContentsDragSource> drag_source_; diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/views/tab_contents/tab_contents_view_win.cc index 9086d49..39190f0 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc @@ -23,7 +23,7 @@ #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/tab_contents/web_drop_target_win.h" #include "chrome/browser/views/sad_tab_view.h" -#include "chrome/browser/views/tab_contents/render_view_context_menu_win.h" +#include "chrome/browser/views/tab_contents/render_view_context_menu_views.h" #include "chrome/browser/views/tab_contents/tab_contents_drag_win.h" #include "gfx/canvas_paint.h" #include "views/focus/view_storage.h" @@ -325,7 +325,7 @@ void TabContentsViewWin::ShowContextMenu(const ContextMenuParams& params) { if (tab_contents()->delegate()->HandleContextMenu(params)) return; - context_menu_.reset(new RenderViewContextMenuWin(tab_contents(), params)); + context_menu_.reset(new RenderViewContextMenuViews(tab_contents(), params)); context_menu_->Init(); POINT screen_pt = { params.x, params.y }; diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.h b/chrome/browser/views/tab_contents/tab_contents_view_win.h index 27f50fe..2c080c1 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_win.h +++ b/chrome/browser/views/tab_contents/tab_contents_view_win.h @@ -11,7 +11,7 @@ #include "gfx/size.h" #include "views/widget/widget_win.h" -class RenderViewContextMenuWin; +class RenderViewContextMenuViews; class SadTabView; class SkBitmap; class TabContentsDragWin; @@ -123,7 +123,7 @@ class TabContentsViewWin : public TabContentsView, int last_focused_view_storage_id_; // The context menu. Callbacks are asynchronous so we need to keep it around. - scoped_ptr<RenderViewContextMenuWin> context_menu_; + scoped_ptr<RenderViewContextMenuViews> context_menu_; // The FocusManager associated with this tab. Stored as it is not directly // accessible when unparented. diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 2d841f1..d2a213e 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2435,12 +2435,8 @@ 'browser/views/tab_contents/native_tab_contents_container_gtk.h', 'browser/views/tab_contents/native_tab_contents_container_win.cc', 'browser/views/tab_contents/native_tab_contents_container_win.h', - 'browser/views/tab_contents/render_view_context_menu_gtk.cc', - 'browser/views/tab_contents/render_view_context_menu_gtk.h', - 'browser/views/tab_contents/render_view_context_menu_win.cc', - 'browser/views/tab_contents/render_view_context_menu_win.h', - 'browser/views/tab_contents/render_view_context_menu_external_win.cc', - 'browser/views/tab_contents/render_view_context_menu_external_win.h', + 'browser/views/tab_contents/render_view_context_menu_views.cc', + 'browser/views/tab_contents/render_view_context_menu_views.h', 'browser/views/tab_contents/tab_contents_drag_win.cc', 'browser/views/tab_contents/tab_contents_drag_win.h', 'browser/views/tab_contents/tab_contents_view_gtk.cc', @@ -3009,8 +3005,8 @@ ['include', '^browser/views/status_bubble_views.h'], ['include', '^browser/views/tab_contents/native_tab_contents_container_gtk.cc'], ['include', '^browser/views/tab_contents/native_tab_contents_container_gtk.h'], - ['include', '^browser/views/tab_contents/render_view_context_menu_gtk.cc'], - ['include', '^browser/views/tab_contents/render_view_context_menu_gtk.h'], + ['include', '^browser/views/tab_contents/render_view_context_menu_views.cc'], + ['include', '^browser/views/tab_contents/render_view_context_menu_views.h'], ['include', '^browser/views/tab_contents/tab_contents_container.cc'], ['include', '^browser/views/tab_contents/tab_contents_container.h'], ['include', '^browser/views/tab_contents/tab_contents_view_gtk.cc'], diff --git a/views/examples/menu_example.h b/views/examples/menu_example.h index 07d27d1..d43acde 100644 --- a/views/examples/menu_example.h +++ b/views/examples/menu_example.h @@ -57,7 +57,7 @@ class ExampleMenuContents : public menus::SimpleMenuModel, submenu_.reset(new menus::SimpleMenuModel(this)); submenu_->AddItem(kCommandDoSomething, WideToUTF16(L"Do Something 2")); - AddSubMenu(ASCIIToUTF16("Submenu"), submenu_.get()); + AddSubMenu(-1, ASCIIToUTF16("Submenu"), submenu_.get()); menu_.reset(new views::Menu2(this)); } |