diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-04 01:16:12 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-04 01:16:12 +0000 |
commit | e9ef1db24e1468bc378dffa650a0e56c794ee761 (patch) | |
tree | 46f1e10eae2eaf5c4ba2bb895f37768db468b9e1 /chrome | |
parent | 46c74e569cb53ab4e283fa08d9938282a9a21a1e (diff) | |
download | chromium_src-e9ef1db24e1468bc378dffa650a0e56c794ee761.zip chromium_src-e9ef1db24e1468bc378dffa650a0e56c794ee761.tar.gz chromium_src-e9ef1db24e1468bc378dffa650a0e56c794ee761.tar.bz2 |
gtk: simplify menuing API
Bug 71821 looks like it was caused by using the wrong menu API, but
it wasn't obvious because there were so many entry points. This
change simplifies it to two main entry points -- one for context
menus (which belong at the mouse position) and one for button-initiated
menus (which belong alongside the button, like the wrench menu).
This also makes the right-click menu in the task manager come up on
mouse-down on GTK, as that is how right-click menus should work.
BUG=71821
TEST=bring up a notification, click the wrench, pick an item from
the submenu; the selection should take effect
Review URL: http://codereview.chromium.org/6250145
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73726 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
24 files changed, 95 insertions, 128 deletions
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 dc7b783..5478d6f 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc @@ -44,7 +44,7 @@ void RenderViewContextMenuGtk::Popup(const gfx::Point& point) { RenderWidgetHostView* rwhv = source_tab_contents_->GetRenderWidgetHostView(); if (rwhv) rwhv->ShowingContextMenu(true); - menu_gtk_->PopupAsContextAt(triggering_event_time_, point); + menu_gtk_->PopupAsContext(point, triggering_event_time_); } void RenderViewContextMenuGtk::StoppedShowing() { diff --git a/chrome/browser/ui/gtk/back_forward_button_gtk.cc b/chrome/browser/ui/gtk/back_forward_button_gtk.cc index f7b7094..2810126 100644 --- a/chrome/browser/ui/gtk/back_forward_button_gtk.cc +++ b/chrome/browser/ui/gtk/back_forward_button_gtk.cc @@ -78,16 +78,10 @@ bool BackForwardButtonGtk::AlwaysShowIconForCmd(int command_id) const { return true; } -void BackForwardButtonGtk::ShowBackForwardMenu() { +void BackForwardButtonGtk::ShowBackForwardMenu(int button, guint32 event_time) { menu_.reset(new MenuGtk(this, menu_model_.get())); button_->SetPaintOverride(GTK_STATE_ACTIVE); - - // gtk_menu_popup will ignore the first mouse button release if it matches - // the button type and is within a short span of the time we pass here. - // Since this menu is not popped up by a button press (instead, it is popped - // up either on a timer or on a drag) this doesn't apply to us and we can - // pass arbitrary values. - menu_->Popup(widget(), 1, gtk_get_current_event_time()); + menu_->PopupForWidget(widget(), button, event_time); } void BackForwardButtonGtk::OnClick(GtkWidget* widget) { @@ -101,7 +95,7 @@ void BackForwardButtonGtk::OnClick(GtkWidget* widget) { gboolean BackForwardButtonGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event) { if (event->button == 3) - ShowBackForwardMenu(); + ShowBackForwardMenu(event->button, event->time); if (event->button != 1) return FALSE; @@ -109,7 +103,8 @@ gboolean BackForwardButtonGtk::OnButtonPress(GtkWidget* widget, y_position_of_last_press_ = static_cast<int>(event->y); MessageLoop::current()->PostDelayedTask(FROM_HERE, show_menu_factory_.NewRunnableMethod( - &BackForwardButtonGtk::ShowBackForwardMenu), + &BackForwardButtonGtk::ShowBackForwardMenu, + event->button, event->time), kMenuTimerDelay); return FALSE; } @@ -129,6 +124,6 @@ gboolean BackForwardButtonGtk::OnMouseMove(GtkWidget* widget, // We will show the menu now. Cancel the delayed event. show_menu_factory_.RevokeAll(); - ShowBackForwardMenu(); + ShowBackForwardMenu(/* button */ 1, event->time); return FALSE; } diff --git a/chrome/browser/ui/gtk/back_forward_button_gtk.h b/chrome/browser/ui/gtk/back_forward_button_gtk.h index 630e552..6a5806a 100644 --- a/chrome/browser/ui/gtk/back_forward_button_gtk.h +++ b/chrome/browser/ui/gtk/back_forward_button_gtk.h @@ -45,7 +45,7 @@ class BackForwardButtonGtk : MenuGtk::Delegate { GdkEventMotion*); // Shows the dropdown menu. - void ShowBackForwardMenu(); + void ShowBackForwardMenu(int button, guint32 event_time); // The menu gets reset every time it is shown. scoped_ptr<MenuGtk> menu_; diff --git a/chrome/browser/ui/gtk/bookmark_bar_gtk.cc b/chrome/browser/ui/gtk/bookmark_bar_gtk.cc index 4a59881..605a7705 100644 --- a/chrome/browser/ui/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/ui/gtk/bookmark_bar_gtk.cc @@ -975,7 +975,9 @@ void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender, window, this, profile_, page_navigator_, parent, nodes)); current_context_menu_.reset( new MenuGtk(NULL, current_context_menu_controller_->menu_model())); - current_context_menu_->PopupAsContext(event->time); + current_context_menu_->PopupAsContext( + gfx::Point(event->x_root, event->y_root), + event->time); } gboolean BookmarkBarGtk::OnButtonPressed(GtkWidget* sender, diff --git a/chrome/browser/ui/gtk/bookmark_editor_gtk.cc b/chrome/browser/ui/gtk/bookmark_editor_gtk.cc index 788ed60..31fab64 100644 --- a/chrome/browser/ui/gtk/bookmark_editor_gtk.cc +++ b/chrome/browser/ui/gtk/bookmark_editor_gtk.cc @@ -64,14 +64,14 @@ class BookmarkEditorGtk::ContextMenuController } virtual ~ContextMenuController() {} - void RunMenu(const gfx::Point& point) { + void RunMenu(const gfx::Point& point, guint32 event_time) { const BookmarkNode* selected_node = GetSelectedNode(); if (selected_node) running_menu_for_root_ = selected_node->GetParent()->IsRoot(); #if defined(TOOLKIT_VIEWS) menu_->RunContextMenuAt(point); #else - menu_->PopupAsContextAt(gtk_get_current_event_time(), point); + menu_->PopupAsContext(point, event_time); #endif } @@ -549,20 +549,15 @@ void BookmarkEditorGtk::OnNewFolderClicked(GtkWidget* button) { gboolean BookmarkEditorGtk::OnTreeViewButtonPressEvent(GtkWidget* widget, GdkEventButton* event) { if (event->button == 3) { - gfx::Point pt(event->x_root, event->y_root); - ShowContextMenu(pt); + if (!menu_controller_.get()) + menu_controller_.reset(new ContextMenuController(this)); + menu_controller_->RunMenu(gfx::Point(event->x_root, event->y_root), + event->time); } return FALSE; } -void BookmarkEditorGtk::ShowContextMenu(const gfx::Point& point) { - if (!menu_controller_.get()) - menu_controller_.reset(new ContextMenuController(this)); - - menu_controller_->RunMenu(point); -} - void BookmarkEditorGtk::NewFolder() { GtkTreeIter iter; if (!gtk_tree_selection_get_selected(tree_selection_, diff --git a/chrome/browser/ui/gtk/bookmark_editor_gtk.h b/chrome/browser/ui/gtk/bookmark_editor_gtk.h index e500ae8..cba0c95 100644 --- a/chrome/browser/ui/gtk/bookmark_editor_gtk.h +++ b/chrome/browser/ui/gtk/bookmark_editor_gtk.h @@ -117,8 +117,6 @@ class BookmarkEditorGtk : public BookmarkEditor, CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnTreeViewButtonPressEvent, GdkEventButton*); - void ShowContextMenu(const gfx::Point& point); - void NewFolder(); // Profile the entry is from. diff --git a/chrome/browser/ui/gtk/bookmark_menu_controller_gtk.cc b/chrome/browser/ui/gtk/bookmark_menu_controller_gtk.cc index 61a44c2..1bced32 100644 --- a/chrome/browser/ui/gtk/bookmark_menu_controller_gtk.cc +++ b/chrome/browser/ui/gtk/bookmark_menu_controller_gtk.cc @@ -275,7 +275,8 @@ gboolean BookmarkMenuController::OnMenuButtonPressedOrReleased( signals_.Connect(context_menu_->widget(), "hide", G_CALLBACK(OnContextMenuHide), grabbing_menu); - context_menu_->PopupAsContext(event->time); + context_menu_->PopupAsContext(gfx::Point(event->x_root, event->y_root), + event->time); return TRUE; } diff --git a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc index f2f6020..761a85c 100644 --- a/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc +++ b/chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc @@ -266,9 +266,9 @@ class BrowserActionButton : public NotificationObserver, } static gboolean OnButtonPress(GtkWidget* widget, - GdkEvent* event, + GdkEventButton* event, BrowserActionButton* action) { - if (event->button.button != 3) + if (event->button != 3) return FALSE; MenuGtk* menu = action->GetContextMenu(); @@ -276,7 +276,7 @@ class BrowserActionButton : public NotificationObserver, return FALSE; action->button_->SetPaintOverride(GTK_STATE_ACTIVE); - menu->Popup(widget, event); + menu->PopupForWidget(widget, event->button, event->time); return TRUE; } @@ -950,7 +950,8 @@ gboolean BrowserActionsToolbarGtk::OnOverflowMenuButtonPress( if (!menu) return FALSE; - menu->PopupAsContext(event->time); + menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), + event->time); return TRUE; } diff --git a/chrome/browser/ui/gtk/browser_titlebar.cc b/chrome/browser/ui/gtk/browser_titlebar.cc index 58f1236..738f5d6 100644 --- a/chrome/browser/ui/gtk/browser_titlebar.cc +++ b/chrome/browser/ui/gtk/browser_titlebar.cc @@ -709,7 +709,7 @@ void BrowserTitlebar::ShowFaviconMenu(GdkEventButton* event) { favicon_menu_.reset(new MenuGtk(NULL, favicon_menu_model_.get())); } - favicon_menu_->Popup(app_mode_favicon_, reinterpret_cast<GdkEvent*>(event)); + favicon_menu_->PopupForWidget(app_mode_favicon_, event->button, event->time); } void BrowserTitlebar::MaximizeButtonClicked() { @@ -796,13 +796,14 @@ gboolean BrowserTitlebar::OnButtonPressed(GtkWidget* widget, return TRUE; } -void BrowserTitlebar::ShowContextMenu() { +void BrowserTitlebar::ShowContextMenu(GdkEventButton* event) { if (!context_menu_.get()) { context_menu_model_.reset(new ContextMenuModel(this)); context_menu_.reset(new MenuGtk(NULL, context_menu_model_.get())); } - context_menu_->PopupAsContext(gtk_get_current_event_time()); + context_menu_->PopupAsContext(gfx::Point(event->x_root, event->y_root), + event->time); } bool BrowserTitlebar::IsCommandIdEnabled(int command_id) const { diff --git a/chrome/browser/ui/gtk/browser_titlebar.h b/chrome/browser/ui/gtk/browser_titlebar.h index 2bf2f7c..7d841dd 100644 --- a/chrome/browser/ui/gtk/browser_titlebar.h +++ b/chrome/browser/ui/gtk/browser_titlebar.h @@ -63,7 +63,7 @@ class BrowserTitlebar : public NotificationObserver, // On Windows, right clicking in the titlebar background brings up the system // menu. There's no such thing on linux, so we just show the menu items we // add to the menu. - void ShowContextMenu(); + void ShowContextMenu(GdkEventButton* event); private: // A helper class to keep track of which frame of the throbber animation diff --git a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc index 7ee3b34..6ff777e 100644 --- a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc @@ -590,7 +590,7 @@ gboolean BrowserToolbarGtk::OnMenuButtonPressEvent(GtkWidget* button, return FALSE; wrench_menu_button_->SetPaintOverride(GTK_STATE_ACTIVE); - wrench_menu_->Popup(button, reinterpret_cast<GdkEvent*>(event)); + wrench_menu_->PopupForWidget(button, event->button, event->time); return TRUE; } diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index f081672..baa6be5 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -2048,7 +2048,7 @@ gboolean BrowserWindowGtk::OnButtonPressEvent(GtkWidget* widget, return TRUE; } else if (event->button == 3) { if (has_hit_titlebar) { - titlebar_->ShowContextMenu(); + titlebar_->ShowContextMenu(event); return TRUE; } } diff --git a/chrome/browser/ui/gtk/download_item_gtk.cc b/chrome/browser/ui/gtk/download_item_gtk.cc index 709218d..1543ed8 100644 --- a/chrome/browser/ui/gtk/download_item_gtk.cc +++ b/chrome/browser/ui/gtk/download_item_gtk.cc @@ -96,14 +96,14 @@ class DownloadShelfContextMenuGtk : public DownloadShelfContextMenu, ~DownloadShelfContextMenuGtk() { } - void Popup(GtkWidget* widget, GdkEvent* event) { + void Popup(GtkWidget* widget, GdkEventButton* event) { // Create the menu if we have not created it yet or we created it for // an in-progress download that has since completed. if (download_->state() == DownloadItem::COMPLETE) menu_.reset(new MenuGtk(this, GetFinishedMenuModel())); else menu_.reset(new MenuGtk(this, GetInProgressMenuModel())); - menu_->Popup(widget, event); + menu_->PopupForWidget(widget, event->button, event->time); } // MenuGtk::Delegate implementation: @@ -835,7 +835,7 @@ gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, } gboolean DownloadItemGtk::OnMenuButtonPressEvent(GtkWidget* button, - GdkEvent* event) { + GdkEventButton* event) { // Stop any completion animation. if (complete_animation_.get() && complete_animation_->is_animating()) complete_animation_->End(); diff --git a/chrome/browser/ui/gtk/download_item_gtk.h b/chrome/browser/ui/gtk/download_item_gtk.h index a3b67e3..d8fd8ae 100644 --- a/chrome/browser/ui/gtk/download_item_gtk.h +++ b/chrome/browser/ui/gtk/download_item_gtk.h @@ -113,7 +113,7 @@ class DownloadItemGtk : public DownloadItem::Observer, GdkEventExpose*); CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnMenuButtonPressEvent, - GdkEvent*); + GdkEventButton*); // Dangerous download related. ----------------------------------------------- CHROMEGTK_CALLBACK_1(DownloadItemGtk, gboolean, OnDangerousPromptExpose, diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc index cddb57e..63f99825 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc @@ -1482,8 +1482,8 @@ void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( } void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { - GdkEvent event; - event.button.button = 1; + GdkEventButton event = {}; + event.button = 1; OnButtonPressed(widget(), &event); } @@ -1506,8 +1506,8 @@ bool LocationBarViewGtk::PageActionViewGtk::ShowPopup(bool devtools) { gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed( GtkWidget* sender, - GdkEvent* event) { - if (event->button.button != 3) { + GdkEventButton* event) { + if (event->button != 3) { if (!ShowPopup(false)) { ExtensionService* service = profile_->GetExtensionService(); service->browser_event_router()->PageActionExecuted( @@ -1516,7 +1516,7 @@ gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed( page_action_->id(), current_tab_id_, current_url_.spec(), - event->button.button); + event->button); } } else { const Extension* extension = profile_->GetExtensionService()-> @@ -1527,7 +1527,7 @@ gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed( new ExtensionContextMenuModel(extension, owner_->browser_, this); context_menu_.reset( new MenuGtk(NULL, context_menu_model_.get())); - context_menu_->Popup(sender, event); + context_menu_->PopupForWidget(sender, event->button, event->time); } } diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.h b/chrome/browser/ui/gtk/location_bar_view_gtk.h index 2bc9ba5..33b6111 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.h +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.h @@ -223,7 +223,7 @@ class LocationBarViewGtk : public AutocompleteEditController, bool ShowPopup(bool devtools); CHROMEGTK_CALLBACK_1(PageActionViewGtk, gboolean, OnButtonPressed, - GdkEvent*); + GdkEventButton*); CHROMEGTK_CALLBACK_1(PageActionViewGtk, gboolean, OnExposeEvent, GdkEventExpose*); diff --git a/chrome/browser/ui/gtk/menu_gtk.cc b/chrome/browser/ui/gtk/menu_gtk.cc index 2df1f56..49ca7a1 100644 --- a/chrome/browser/ui/gtk/menu_gtk.cc +++ b/chrome/browser/ui/gtk/menu_gtk.cc @@ -369,29 +369,20 @@ GtkWidget* MenuGtk::AppendMenuItemToMenu(int index, return menu_item; } -void MenuGtk::Popup(GtkWidget* widget, GdkEvent* event) { - DCHECK(event->type == GDK_BUTTON_PRESS) - << "Non-button press event sent to RunMenuAt"; - - Popup(widget, event->button.button, event->button.time); -} - -void MenuGtk::Popup(GtkWidget* widget, gint button_type, guint32 timestamp) { +void MenuGtk::PopupForWidget(GtkWidget* widget, int button, + guint32 event_time) { gtk_menu_popup(GTK_MENU(menu_), NULL, NULL, WidgetMenuPositionFunc, widget, - button_type, timestamp); -} - -void MenuGtk::PopupAsContext(guint32 event_time) { - // TODO(estade): |button| value of 3 (6th argument) is not strictly true, - // but does it matter? - gtk_menu_popup(GTK_MENU(menu_), NULL, NULL, NULL, NULL, 3, event_time); + button, event_time); } -void MenuGtk::PopupAsContextAt(guint32 event_time, gfx::Point point) { +void MenuGtk::PopupAsContext(const gfx::Point& point, guint32 event_time) { + // gtk_menu_popup doesn't like the "const" qualifier on point. + gfx::Point nonconst_point(point); gtk_menu_popup(GTK_MENU(menu_), NULL, NULL, - PointMenuPositionFunc, &point, 3, event_time); + PointMenuPositionFunc, &nonconst_point, + 3, event_time); } void MenuGtk::PopupAsContextForStatusIcon(guint32 event_time, guint32 button, @@ -401,7 +392,7 @@ void MenuGtk::PopupAsContextForStatusIcon(guint32 event_time, guint32 button, } void MenuGtk::PopupAsFromKeyEvent(GtkWidget* widget) { - Popup(widget, 0, gtk_get_current_event_time()); + PopupForWidget(widget, 0, gtk_get_current_event_time()); gtk_menu_shell_select_first(GTK_MENU_SHELL(menu_), FALSE); } diff --git a/chrome/browser/ui/gtk/menu_gtk.h b/chrome/browser/ui/gtk/menu_gtk.h index 2fdb2eb..fc9a048 100644 --- a/chrome/browser/ui/gtk/menu_gtk.h +++ b/chrome/browser/ui/gtk/menu_gtk.h @@ -75,20 +75,17 @@ class MenuGtk { GtkWidget* menu, bool connect_to_activate); - // Displays the menu. |timestamp| is the time of activation. The popup is - // statically positioned at |widget|. - void Popup(GtkWidget* widget, gint button_type, guint32 timestamp); - - // Displays the menu using the button type and timestamp of |event|. The popup - // is statically positioned at |widget|. - void Popup(GtkWidget* widget, GdkEvent* event); - - // Displays the menu as a context menu, i.e. at the current cursor location. + // Displays the menu near a widget, as if the widget were a menu bar. + // Example: the wrench menu button. + // |button| is the mouse button that brought up the menu. + // |event_time| is the time from the GdkEvent. + void PopupForWidget(GtkWidget* widget, int button, guint32 event_time); + + // Displays the menu as a context menu, i.e. at the cursor location. + // It is implicit that it was brought up using the right mouse button. + // |point| is the point where to put the menu. // |event_time| is the time of the event that triggered the menu's display. - void PopupAsContext(guint32 event_time); - - // Displays the menu at the given coords. |point| is intentionally not const. - void PopupAsContextAt(guint32 event_time, gfx::Point point); + void PopupAsContext(const gfx::Point& point, guint32 event_time); // Displays the menu as a context menu for the passed status icon. void PopupAsContextForStatusIcon(guint32 event_time, guint32 button, diff --git a/chrome/browser/ui/gtk/notifications/balloon_view_gtk.cc b/chrome/browser/ui/gtk/notifications/balloon_view_gtk.cc index ec57678..d760f36 100644 --- a/chrome/browser/ui/gtk/notifications/balloon_view_gtk.cc +++ b/chrome/browser/ui/gtk/notifications/balloon_view_gtk.cc @@ -454,7 +454,7 @@ gboolean BalloonViewImpl::OnExpose(GtkWidget* sender, GdkEventExpose* event) { void BalloonViewImpl::OnOptionsMenuButton(GtkWidget* widget, GdkEventButton* event) { menu_showing_ = true; - options_menu_->PopupAsContext(event->time); + options_menu_->PopupForWidget(widget, event->button, event->time); } // Called when the menu stops showing. diff --git a/chrome/browser/ui/gtk/tabs/tab_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_gtk.cc index 01f91f1..63f2af8 100644 --- a/chrome/browser/ui/gtk/tabs/tab_gtk.cc +++ b/chrome/browser/ui/gtk/tabs/tab_gtk.cc @@ -42,8 +42,8 @@ class TabGtk::ContextMenuController : public ui::SimpleMenuModel::Delegate, virtual ~ContextMenuController() {} - void RunMenu() { - menu_->PopupAsContext(gtk_get_current_event_time()); + void RunMenu(const gfx::Point& point, guint32 event_time) { + menu_->PopupAsContext(point, event_time); } void Cancel() { @@ -189,8 +189,11 @@ gboolean TabGtk::OnButtonPressEvent(GtkWidget* widget, GdkEventButton* event) { } else if (event->button == 3) { // Only show the context menu if the left mouse button isn't down (i.e., // the user might want to drag instead). - if (!last_mouse_down_) - ShowContextMenu(); + if (!last_mouse_down_) { + menu_controller_.reset(new ContextMenuController(this)); + menu_controller_->RunMenu(gfx::Point(event->x_root, event->y_root), + event->time); + } } return TRUE; @@ -326,11 +329,6 @@ void TabGtk::SetBounds(const gfx::Rect& bounds) { /////////////////////////////////////////////////////////////////////////////// // TabGtk, private: -void TabGtk::ShowContextMenu() { - menu_controller_.reset(new ContextMenuController(this)); - menu_controller_->RunMenu(); -} - void TabGtk::ContextMenuClosed() { delegate()->StopAllHighlighting(); menu_controller_.reset(); diff --git a/chrome/browser/ui/gtk/tabs/tab_gtk.h b/chrome/browser/ui/gtk/tabs/tab_gtk.h index b80039c..460d25d 100644 --- a/chrome/browser/ui/gtk/tabs/tab_gtk.h +++ b/chrome/browser/ui/gtk/tabs/tab_gtk.h @@ -139,9 +139,6 @@ class TabGtk : public TabRendererGtk, // user presses space or return. CHROMEGTK_CALLBACK_1(TabGtk, gboolean, OnDragButtonReleased, GdkEventButton*); - // Shows the context menu. - void ShowContextMenu(); - // Invoked when the context menu closes. void ContextMenuClosed(); diff --git a/chrome/browser/ui/gtk/task_manager_gtk.cc b/chrome/browser/ui/gtk/task_manager_gtk.cc index 7d3e54c..8365b65 100644 --- a/chrome/browser/ui/gtk/task_manager_gtk.cc +++ b/chrome/browser/ui/gtk/task_manager_gtk.cc @@ -232,15 +232,13 @@ class TaskManagerGtk::ContextMenuController virtual ~ContextMenuController() {} + void RunMenu(const gfx::Point& point, guint32 event_time) { #if defined(TOOLKIT_VIEWS) - void RunMenu(const gfx::Point& point) { menu_->RunContextMenuAt(point); - } #else - void RunMenu() { - menu_->PopupAsContext(gtk_get_current_event_time()); - } + menu_->PopupAsContext(point, event_time); #endif + } void Cancel() { task_manager_ = NULL; @@ -460,8 +458,15 @@ void TaskManagerGtk::Init() { destroy_handler_id_ = g_signal_connect(dialog_, "destroy", G_CALLBACK(OnDestroyThunk), this); g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); + // GTK does menu on mouse-up while views does menu on mouse-down, + // so connect to different handlers. +#if defined(TOOLKIT_VIEWS) g_signal_connect(dialog_, "button-release-event", - G_CALLBACK(OnButtonReleaseEventThunk), this); + G_CALLBACK(OnButtonEventThunk), this); +#else + g_signal_connect(dialog_, "button-press-event", + G_CALLBACK(OnButtonEventThunk), this); +#endif gtk_widget_add_events(dialog_, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); @@ -762,21 +767,13 @@ void TaskManagerGtk::KillSelectedProcesses() { g_list_free(paths); } -#if defined(TOOLKIT_VIEWS) -void TaskManagerGtk::ShowContextMenu(const gfx::Point& point) { - if (!menu_controller_.get()) - menu_controller_.reset(new ContextMenuController(this)); - - menu_controller_->RunMenu(point); -} -#else -void TaskManagerGtk::ShowContextMenu() { +void TaskManagerGtk::ShowContextMenu(const gfx::Point& point, + guint32 event_time) { if (!menu_controller_.get()) menu_controller_.reset(new ContextMenuController(this)); - menu_controller_->RunMenu(); + menu_controller_->RunMenu(point, event_time); } -#endif void TaskManagerGtk::OnLinkActivated() { task_manager_->OpenAboutMemory(); @@ -931,15 +928,13 @@ void TaskManagerGtk::OnRowActivated(GtkWidget* widget, task_manager_->ActivateProcess(row); } -gboolean TaskManagerGtk::OnButtonReleaseEvent(GtkWidget* widget, - GdkEventButton* event) { +gboolean TaskManagerGtk::OnButtonEvent(GtkWidget* widget, + GdkEventButton* event) { + // GTK does menu on mouse-up while views does menu on mouse-down, + // so this function does different handlers. if (event->button == 3) { -#if defined(TOOLKIT_VIEWS) - gfx::Point pt(event->x_root, event->y_root); - ShowContextMenu(pt); -#else - ShowContextMenu(); -#endif + ShowContextMenu(gfx::Point(event->x_root, event->y_root), + event->time); } return FALSE; diff --git a/chrome/browser/ui/gtk/task_manager_gtk.h b/chrome/browser/ui/gtk/task_manager_gtk.h index e72d29a..30797bd 100644 --- a/chrome/browser/ui/gtk/task_manager_gtk.h +++ b/chrome/browser/ui/gtk/task_manager_gtk.h @@ -15,11 +15,9 @@ #include "grit/generated_resources.h" #include "ui/base/gtk/gtk_signal.h" -#if defined(TOOLKIT_VIEWS) namespace gfx { class Point; } -#endif class TaskManagerGtk : public TaskManagerModelObserver { public: @@ -66,11 +64,7 @@ class TaskManagerGtk : public TaskManagerModelObserver { void KillSelectedProcesses(); // Opens the context menu used to select the task manager columns. -#if defined(TOOLKIT_VIEWS) - void ShowContextMenu(const gfx::Point& point); -#else - void ShowContextMenu(); -#endif + void ShowContextMenu(const gfx::Point& point, guint32 event_time); // Opens about:memory in a new foreground tab. void OnLinkActivated(); @@ -97,8 +91,10 @@ class TaskManagerGtk : public TaskManagerModelObserver { CHROMEGTK_CALLBACK_2(TaskManagerGtk, void, OnRowActivated, GtkTreePath*, GtkTreeViewColumn*); - // button-release-event handler that opens the right-click context menu. - CHROMEGTK_CALLBACK_1(TaskManagerGtk, gboolean, OnButtonReleaseEvent, + // button-event handler that opens the right-click context menu. + // Note: GTK does menu on mouse-up while views does menu on mouse-down; + // this handler is used for both. + CHROMEGTK_CALLBACK_1(TaskManagerGtk, gboolean, OnButtonEvent, GdkEventButton*); // Handles an accelerator being pressed. diff --git a/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc b/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc index ad98bdd..c6c6d2d 100644 --- a/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc +++ b/chrome/browser/ui/gtk/translate/translate_infobar_base_gtk.cc @@ -213,7 +213,7 @@ void TranslateInfoBarBase::OnOptionsClicked(GtkWidget* sender) { options_menu_model_.reset(new OptionsMenuModel(GetDelegate())); options_menu_menu_.reset(new MenuGtk(NULL, options_menu_model_.get())); } - options_menu_menu_->Popup(sender, 1, gtk_get_current_event_time()); + options_menu_menu_->PopupForWidget(sender, 1, gtk_get_current_event_time()); } // TranslateInfoBarDelegate specific method: |