diff options
-rw-r--r-- | chrome/browser/gtk/gtk_chrome_link_button.cc | 46 | ||||
-rw-r--r-- | chrome/browser/gtk/gtk_chrome_link_button.h | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/infobar_gtk.cc | 12 |
3 files changed, 63 insertions, 2 deletions
diff --git a/chrome/browser/gtk/gtk_chrome_link_button.cc b/chrome/browser/gtk/gtk_chrome_link_button.cc index 3fbb7e5..a635e73 100644 --- a/chrome/browser/gtk/gtk_chrome_link_button.cc +++ b/chrome/browser/gtk/gtk_chrome_link_button.cc @@ -61,6 +61,39 @@ static gboolean gtk_chrome_link_button_expose(GtkWidget* widget, return TRUE; } +static gboolean gtk_chrome_link_button_button_press(GtkWidget* widget, + GdkEventButton* event) { + GtkButton* button; + + if (event->type == GDK_BUTTON_PRESS) { + button = GTK_BUTTON(widget); + + if (button->focus_on_click && !GTK_WIDGET_HAS_FOCUS (widget)) + gtk_widget_grab_focus(widget); + + if (event->button == 1 || event->button == 2) + gtk_button_pressed(button); + } + + return TRUE; +} + +static gboolean gtk_chrome_link_button_button_release(GtkWidget* widget, + GdkEventButton* event) { + GtkButton* button = GTK_BUTTON(widget); + GtkChromeLinkButton* link_button = GTK_CHROME_LINK_BUTTON(widget); + + free(link_button->click_button_event); + link_button->click_button_event = static_cast<GdkEventButton*>( + malloc(sizeof(GdkEventButton))); + *link_button->click_button_event = *event; + + if (event->button == 1 || event->button == 2) + gtk_button_released(button); + + return TRUE; +} + static void gtk_chrome_link_button_enter(GtkButton* button) { GtkWidget* widget = GTK_WIDGET(button); GtkChromeLinkButton* link_button = GTK_CHROME_LINK_BUTTON(button); @@ -69,7 +102,10 @@ static void gtk_chrome_link_button_enter(GtkButton* button) { static void gtk_chrome_link_button_leave(GtkButton* button) { GtkWidget* widget = GTK_WIDGET(button); + GtkChromeLinkButton* link_button = GTK_CHROME_LINK_BUTTON(button); gdk_window_set_cursor(widget->window, NULL); + free(link_button->click_button_event); + link_button->click_button_event = NULL; } static void gtk_chrome_link_button_destroy(GtkObject* object) { @@ -86,6 +122,8 @@ static void gtk_chrome_link_button_destroy(GtkObject* object) { gdk_cursor_unref(button->hand_cursor); button->hand_cursor = NULL; } + free(button->click_button_event); + button->click_button_event = NULL; GTK_OBJECT_CLASS(gtk_chrome_link_button_parent_class)->destroy(object); } @@ -99,6 +137,8 @@ static void gtk_chrome_link_button_class_init( GtkObjectClass* object_class = reinterpret_cast<GtkObjectClass*>(link_button_class); widget_class->expose_event = >k_chrome_link_button_expose; + widget_class->button_press_event = >k_chrome_link_button_button_press; + widget_class->button_release_event = >k_chrome_link_button_button_release; button_class->enter = >k_chrome_link_button_enter; button_class->leave = >k_chrome_link_button_leave; object_class->destroy = >k_chrome_link_button_destroy; @@ -115,6 +155,7 @@ static void gtk_chrome_link_button_init(GtkChromeLinkButton* button) { button->red_markup = NULL; button->is_blue = TRUE; button->hand_cursor = gdk_cursor_new(GDK_HAND2); + button->click_button_event = NULL; gtk_container_add(GTK_CONTAINER(button), button->label); gtk_widget_set_name(GTK_WIDGET(button), "chrome-link-button"); @@ -138,4 +179,9 @@ GtkWidget* gtk_chrome_link_button_new(const char* text) { return lb; } +const GdkEventButton* gtk_chrome_link_button_get_event_for_click( + GtkChromeLinkButton* button) { + return button->click_button_event; +} + G_END_DECLS diff --git a/chrome/browser/gtk/gtk_chrome_link_button.h b/chrome/browser/gtk/gtk_chrome_link_button.h index 214b142..30f4d61 100644 --- a/chrome/browser/gtk/gtk_chrome_link_button.h +++ b/chrome/browser/gtk/gtk_chrome_link_button.h @@ -41,6 +41,7 @@ struct _GtkChromeLinkButton { char* red_markup; gboolean is_blue; GdkCursor* hand_cursor; + GdkEventButton* click_button_event; }; struct _GtkChromeLinkButtonClass { @@ -49,6 +50,12 @@ struct _GtkChromeLinkButtonClass { GtkWidget* gtk_chrome_link_button_new(const char* text); +// Call this from within a "clicked" handler to get the release event that +// triggered the click. It will return NULL if the click was triggered by a +// keyboard event. +const GdkEventButton* gtk_chrome_link_button_get_event_for_click( + GtkChromeLinkButton* button); + GType gtk_chrome_link_button_get_type(); G_END_DECLS diff --git a/chrome/browser/gtk/infobar_gtk.cc b/chrome/browser/gtk/infobar_gtk.cc index 727eff4..607908f 100644 --- a/chrome/browser/gtk/infobar_gtk.cc +++ b/chrome/browser/gtk/infobar_gtk.cc @@ -183,9 +183,17 @@ class LinkInfoBar : public InfoBar { private: static void OnLinkClick(GtkWidget* button, LinkInfoBar* link_info_bar) { - // TODO(estade): we need an equivalent for DispositionFromEventFlags(). + const GdkEventButton* button_click_event = + gtk_chrome_link_button_get_event_for_click( + GTK_CHROME_LINK_BUTTON(button)); + WindowOpenDisposition disposition = CURRENT_TAB; + if (button_click_event) { + disposition = event_utils::DispositionFromEventFlags( + button_click_event->state); + } + if (link_info_bar->delegate_->AsLinkInfoBarDelegate()-> - LinkClicked(CURRENT_TAB)) { + LinkClicked(disposition)) { link_info_bar->RemoveInfoBar(); } } |