diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 21:24:20 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 21:24:20 +0000 |
commit | 535e9640458af3ddbf13339b706b589d7b3e945e (patch) | |
tree | 5efb722f14b48b0c6c05db18f929a0c154b9b136 /chrome/browser/gtk | |
parent | f89aa1d84880734cd0f6afec2197a89ff0ec85c2 (diff) | |
download | chromium_src-535e9640458af3ddbf13339b706b589d7b3e945e.zip chromium_src-535e9640458af3ddbf13339b706b589d7b3e945e.tar.gz chromium_src-535e9640458af3ddbf13339b706b589d7b3e945e.tar.bz2 |
GTK: Fix context menu positioning.
There are still some issues with context menus. The context menu doesn't respect links, for example. That is, if you tab to a link and hit the menu button, it will act as if you right clicked on the upper left pixel of the web page (both in content and position of the menu). This seems to be a webkit bug/missing feature as safari 4 on windows does the same. However, some cases do work as expected, for example if you select text and hit the menu button. Anyway, I'll do the webkit side of this fix as some later patch.
BUG=26811
Review URL: http://codereview.chromium.org/371033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31301 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/bookmark_menu_controller_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 30 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.h | 23 |
3 files changed, 41 insertions, 14 deletions
diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc index 6b4ca8c..4ddda23 100644 --- a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc +++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc @@ -121,7 +121,7 @@ void BookmarkMenuController::Popup(GtkWidget* widget, gint button_type, gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(widget), GTK_STATE_ACTIVE); gtk_menu_popup(GTK_MENU(menu_), NULL, NULL, - &MenuGtk::MenuPositionFunc, + &MenuGtk::WidgetMenuPositionFunc, widget, button_type, timestamp); } diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index 421cfb3..862039e 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -103,7 +103,7 @@ void MenuGtk::Popup(GtkWidget* widget, GdkEvent* event) { void MenuGtk::Popup(GtkWidget* widget, gint button_type, guint32 timestamp) { gtk_menu_popup(GTK_MENU(menu_.get()), NULL, NULL, - MenuPositionFunc, + WidgetMenuPositionFunc, widget, button_type, timestamp); } @@ -114,6 +114,11 @@ void MenuGtk::PopupAsContext(guint32 event_time) { gtk_menu_popup(GTK_MENU(menu_.get()), NULL, NULL, NULL, NULL, 3, event_time); } +void MenuGtk::PopupAsContextAt(guint32 event_time, gfx::Point point) { + gtk_menu_popup(GTK_MENU(menu_.get()), NULL, NULL, + PointMenuPositionFunc, &point, 3, event_time); +} + void MenuGtk::PopupAsFromKeyEvent(GtkWidget* widget) { Popup(widget, 0, gtk_get_current_event_time()); gtk_menu_shell_select_first(GTK_MENU_SHELL(menu_.get()), FALSE); @@ -264,11 +269,11 @@ void MenuGtk::OnMenuItemActivated(GtkMenuItem* menuitem, MenuGtk* menu) { } // static -void MenuGtk::MenuPositionFunc(GtkMenu* menu, - int* x, - int* y, - gboolean* push_in, - void* void_widget) { +void MenuGtk::WidgetMenuPositionFunc(GtkMenu* menu, + int* x, + int* y, + gboolean* push_in, + void* void_widget) { GtkWidget* widget = GTK_WIDGET(void_widget); GtkRequisition menu_req; @@ -306,6 +311,19 @@ void MenuGtk::MenuPositionFunc(GtkMenu* menu, *push_in = FALSE; } +// static +void MenuGtk::PointMenuPositionFunc(GtkMenu* menu, + int* x, + int* y, + gboolean* push_in, + gpointer userdata) { + *push_in = TRUE; + + gfx::Point* point = reinterpret_cast<gfx::Point*>(userdata); + *x = point->x(); + *y = point->y(); +} + void MenuGtk::UpdateMenu() { gtk_container_foreach(GTK_CONTAINER(menu_.get()), SetMenuItemInfo, this); } diff --git a/chrome/browser/gtk/menu_gtk.h b/chrome/browser/gtk/menu_gtk.h index 7ce8800..1e984e4 100644 --- a/chrome/browser/gtk/menu_gtk.h +++ b/chrome/browser/gtk/menu_gtk.h @@ -10,6 +10,7 @@ #include <string> #include <vector> +#include "base/gfx/point.h" #include "base/task.h" #include "chrome/common/owned_widget_gtk.h" @@ -79,10 +80,11 @@ class MenuGtk { // Displays the menu as a context menu, i.e. at the current cursor location. // |event_time| is the time of the event that triggered the menu's display. - // In the future we may need to modify this to act differently based on the - // triggering event (e.g. right mouse click, context menu key, etc.). 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); + // Displays the menu following a keyboard event (such as selecting |widget| // and pressing "enter"). void PopupAsFromKeyEvent(GtkWidget* widget); @@ -96,11 +98,18 @@ class MenuGtk { // button. Otherwise it aligns the right side of the menu with the right side // of the button. Public since some menus have odd requirements that don't // belong in a public class. - static void MenuPositionFunc(GtkMenu* menu, - int* x, - int* y, - gboolean* push_in, - void* void_widget); + static void WidgetMenuPositionFunc(GtkMenu* menu, + int* x, + int* y, + gboolean* push_in, + void* void_widget); + + // Positions the menu to appear at the gfx::Point represented by |userdata|. + static void PointMenuPositionFunc(GtkMenu* menu, + int* x, + int* y, + gboolean* push_in, + gpointer userdata); GtkWidget* widget() const { return menu_.get(); } |