summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-03 23:19:02 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-03 23:19:02 +0000
commit2c0a3347e89dab58e3528c3a2bca61db4ef32d6c (patch)
treeee24fe7cbc671a71c15ba9591b954a42eaa10b96
parenta1bb3d1d459517caa85a0c534994d5efe8b4b3b0 (diff)
downloadchromium_src-2c0a3347e89dab58e3528c3a2bca61db4ef32d6c.zip
chromium_src-2c0a3347e89dab58e3528c3a2bca61db4ef32d6c.tar.gz
chromium_src-2c0a3347e89dab58e3528c3a2bca61db4ef32d6c.tar.bz2
Gtk: pass the correct event time when we show right click context menus in the render view.
Review URL: http://codereview.chromium.org/62024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13127 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/menu_gtk.cc7
-rw-r--r--chrome/browser/gtk/menu_gtk.h5
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_gtk.cc8
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_gtk.h4
-rw-r--r--chrome/browser/tab_contents/web_contents_view_gtk.cc11
-rw-r--r--chrome/browser/tab_contents/web_contents_view_gtk.h8
6 files changed, 33 insertions, 10 deletions
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc
index dac60ab..2a804cb 100644
--- a/chrome/browser/gtk/menu_gtk.cc
+++ b/chrome/browser/gtk/menu_gtk.cc
@@ -69,13 +69,12 @@ void MenuGtk::Popup(GtkWidget* widget, gint button_type, guint32 timestamp) {
button_type, timestamp);
}
-void MenuGtk::PopupAsContext() {
+void MenuGtk::PopupAsContext(guint32 event_time) {
gtk_container_foreach(GTK_CONTAINER(menu_.get()), SetMenuItemInfo, this);
- // TODO(estade): |button| value of 0 (6th argument) is not strictly true,
+ // TODO(estade): |button| value of 3 (6th argument) is not strictly true,
// but does it matter?
- gtk_menu_popup(GTK_MENU(menu_.get()), NULL, NULL, NULL, NULL, 0,
- gtk_get_current_event_time());
+ gtk_menu_popup(GTK_MENU(menu_.get()), NULL, NULL, NULL, NULL, 3, event_time);
}
void MenuGtk::BuildMenuIn(GtkWidget* menu,
diff --git a/chrome/browser/gtk/menu_gtk.h b/chrome/browser/gtk/menu_gtk.h
index f9060e1..0506ff3 100644
--- a/chrome/browser/gtk/menu_gtk.h
+++ b/chrome/browser/gtk/menu_gtk.h
@@ -55,7 +55,10 @@ class MenuGtk {
void Popup(GtkWidget* widget, GdkEvent* event);
// Displays the menu as a context menu, i.e. at the current cursor location.
- void PopupAsContext();
+ // |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);
private:
// A recursive function that transforms a MenuCreateMaterial tree into a set
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 da49aca..1ccb4c0 100644
--- a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc
@@ -9,9 +9,11 @@
RenderViewContextMenuGtk::RenderViewContextMenuGtk(
WebContents* web_contents,
- const ContextMenuParams& params)
+ const ContextMenuParams& params,
+ guint32 triggering_event_time)
: RenderViewContextMenu(web_contents, params),
- making_submenu_(false) {
+ making_submenu_(false),
+ triggering_event_time_(triggering_event_time) {
InitMenu(params.node);
DoneMakingMenu(&menu_);
gtk_menu_.reset(new MenuGtk(this, menu_.data(), NULL));
@@ -21,7 +23,7 @@ RenderViewContextMenuGtk::~RenderViewContextMenuGtk() {
}
void RenderViewContextMenuGtk::Popup() {
- gtk_menu_->PopupAsContext();
+ gtk_menu_->PopupAsContext(triggering_event_time_);
}
bool RenderViewContextMenuGtk::IsCommandEnabled(int id) const {
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 0776010..5563dc5 100644
--- a/chrome/browser/tab_contents/render_view_context_menu_gtk.h
+++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.h
@@ -20,7 +20,8 @@ class RenderViewContextMenuGtk : public RenderViewContextMenu,
public MenuGtk::Delegate {
public:
RenderViewContextMenuGtk(WebContents* web_contents,
- const ContextMenuParams& params);
+ const ContextMenuParams& params,
+ uint32_t triggering_event_time);
~RenderViewContextMenuGtk();
@@ -52,6 +53,7 @@ class RenderViewContextMenuGtk : public RenderViewContextMenu,
std::vector<MenuCreateMaterial> menu_;
std::vector<MenuCreateMaterial> submenu_;
bool making_submenu_;
+ uint32_t triggering_event_time_;
};
#endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_GTK_H_
diff --git a/chrome/browser/tab_contents/web_contents_view_gtk.cc b/chrome/browser/tab_contents/web_contents_view_gtk.cc
index 431b10a..0a12082 100644
--- a/chrome/browser/tab_contents/web_contents_view_gtk.cc
+++ b/chrome/browser/tab_contents/web_contents_view_gtk.cc
@@ -92,6 +92,8 @@ RenderWidgetHostView* WebContentsViewGtk::CreateViewForWidget(
G_CALLBACK(OnMouseMove), web_contents());
gtk_widget_add_events(view->native_view(), GDK_LEAVE_NOTIFY_MASK |
GDK_POINTER_MOTION_MASK);
+ g_signal_connect(view->native_view(), "button-press-event",
+ G_CALLBACK(OnMouseDown), this);
gtk_container_foreach(GTK_CONTAINER(vbox_.get()), RemoveWidget, vbox_.get());
gtk_box_pack_start(GTK_BOX(vbox_.get()), content_view_, TRUE, TRUE, 0);
return view;
@@ -216,7 +218,8 @@ void WebContentsViewGtk::OnFindReply(int request_id,
}
void WebContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) {
- context_menu_.reset(new RenderViewContextMenuGtk(web_contents(), params));
+ context_menu_.reset(new RenderViewContextMenuGtk(web_contents(), params,
+ last_mouse_down_time_));
context_menu_->Popup();
}
@@ -230,3 +233,9 @@ void WebContentsViewGtk::StartDragging(const WebDropData& drop_data) {
if (web_contents()->render_view_host())
web_contents()->render_view_host()->DragSourceSystemDragEnded();
}
+
+gboolean WebContentsViewGtk::OnMouseDown(GtkWidget* widget,
+ GdkEventButton* event, WebContentsViewGtk* view) {
+ view->last_mouse_down_time_ = event->time;
+ return FALSE;
+}
diff --git a/chrome/browser/tab_contents/web_contents_view_gtk.h b/chrome/browser/tab_contents/web_contents_view_gtk.h
index f755af6..0a56287 100644
--- a/chrome/browser/tab_contents/web_contents_view_gtk.h
+++ b/chrome/browser/tab_contents/web_contents_view_gtk.h
@@ -55,6 +55,10 @@ class WebContentsViewGtk : public WebContentsView {
int active_match_ordinal,
bool final_update);
private:
+ // We keep track of the timestamp of the latest mousedown event.
+ static gboolean OnMouseDown(GtkWidget* widget,
+ GdkEventButton* event, WebContentsViewGtk* view);
+
// The native widget for the tab.
OwnedWidgetGtk vbox_;
@@ -65,6 +69,10 @@ class WebContentsViewGtk : public WebContentsView {
// between uses so that it won't go out of scope before we're done with it.
scoped_ptr<RenderViewContextMenuGtk> context_menu_;
+ // The event time for the last mouse down we handled. We need this to properly
+ // show context menus.
+ guint32 last_mouse_down_time_;
+
DISALLOW_COPY_AND_ASSIGN(WebContentsViewGtk);
};