diff options
author | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 20:47:40 +0000 |
---|---|---|
committer | erg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 20:47:40 +0000 |
commit | 107a46c110cb49a04c7e7daa0e04ea9941a71fc8 (patch) | |
tree | 08b7144276faf9643b78d2b01f7d42d55210a7f3 /chrome/browser | |
parent | 5a0b12cd1c5bb121f5f5caa922e0f9a15e488037 (diff) | |
download | chromium_src-107a46c110cb49a04c7e7daa0e04ea9941a71fc8.zip chromium_src-107a46c110cb49a04c7e7daa0e04ea9941a71fc8.tar.gz chromium_src-107a46c110cb49a04c7e7daa0e04ea9941a71fc8.tar.bz2 |
GTK: Use new macros to hide thunk declaration and cleanup callback declaration.
We have two conventions for declaring GTK+ callbacks in our code: We either
declare a bunch of static thunks in the header that redirect to the correct
object (and bloat up the header) OR we declare the callback methods static and
pass the object as the final parameter (and litter the implementation with
"context->"). The two styles are now about half/half...including mixing these
two styles in the same files. This madness must end!
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/661010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41202 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/gtk/back_forward_button_gtk.cc | 36 | ||||
-rw-r--r-- | chrome/browser/gtk/back_forward_button_gtk.h | 13 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 252 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.h | 78 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_instructions_gtk.cc | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_instructions_gtk.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bubble_gtk.cc | 28 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bubble_gtk.h | 57 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_editor_gtk.cc | 85 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_editor_gtk.h | 20 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 92 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.h | 26 | ||||
-rw-r--r-- | chrome/browser/gtk/download_in_progress_dialog_gtk.cc | 12 | ||||
-rw-r--r-- | chrome/browser/gtk/download_in_progress_dialog_gtk.h | 4 |
14 files changed, 291 insertions, 424 deletions
diff --git a/chrome/browser/gtk/back_forward_button_gtk.cc b/chrome/browser/gtk/back_forward_button_gtk.cc index abd71f8..3519502 100644 --- a/chrome/browser/gtk/back_forward_button_gtk.cc +++ b/chrome/browser/gtk/back_forward_button_gtk.cc @@ -58,12 +58,12 @@ BackForwardButtonGtk::BackForwardButtonGtk(Browser* browser, bool is_forward) BackForwardMenuModel::BACKWARD_MENU)); g_signal_connect(widget(), "clicked", - G_CALLBACK(OnClick), this); + G_CALLBACK(OnClickThunk), this); g_signal_connect(widget(), "button-press-event", - G_CALLBACK(OnButtonPress), this); + G_CALLBACK(OnButtonPressThunk), this); gtk_widget_add_events(widget(), GDK_POINTER_MOTION_MASK); g_signal_connect(widget(), "motion-notify-event", - G_CALLBACK(OnMouseMove), this); + G_CALLBACK(OnMouseMoveThunk), this); // Popup the menu as left-aligned relative to this widget rather than the // default of right aligned. @@ -96,50 +96,46 @@ void BackForwardButtonGtk::ShowBackForwardMenu() { menu_->Popup(widget(), 1, gtk_get_current_event_time()); } -// static -void BackForwardButtonGtk::OnClick(GtkWidget* widget, - BackForwardButtonGtk* button) { - button->show_menu_factory_.RevokeAll(); +void BackForwardButtonGtk::OnClick(GtkWidget* widget) { + show_menu_factory_.RevokeAll(); - button->browser_->ExecuteCommandWithDisposition( - button->is_forward_ ? IDC_FORWARD : IDC_BACK, + browser_->ExecuteCommandWithDisposition( + is_forward_ ? IDC_FORWARD : IDC_BACK, gtk_util::DispositionForCurrentButtonPressEvent()); } -// static gboolean BackForwardButtonGtk::OnButtonPress(GtkWidget* widget, - GdkEventButton* event, BackForwardButtonGtk* button) { + GdkEventButton* event) { if (event->button == 3) - button->ShowBackForwardMenu(); + ShowBackForwardMenu(); if (event->button != 1) return FALSE; - button->y_position_of_last_press_ = static_cast<int>(event->y); + y_position_of_last_press_ = static_cast<int>(event->y); MessageLoop::current()->PostDelayedTask(FROM_HERE, - button->show_menu_factory_.NewRunnableMethod( + show_menu_factory_.NewRunnableMethod( &BackForwardButtonGtk::ShowBackForwardMenu), kMenuTimerDelay); return FALSE; } -// static gboolean BackForwardButtonGtk::OnMouseMove(GtkWidget* widget, - GdkEventMotion* event, BackForwardButtonGtk* button) { + GdkEventMotion* event) { // If we aren't waiting to show the back forward menu, do nothing. - if (button->show_menu_factory_.empty()) + if (show_menu_factory_.empty()) return FALSE; // We only count moves about a certain threshold. GtkSettings* settings = gtk_widget_get_settings(widget); int drag_min_distance; g_object_get(settings, "gtk-dnd-drag-threshold", &drag_min_distance, NULL); - if (event->y - button->y_position_of_last_press_ < drag_min_distance) + if (event->y - y_position_of_last_press_ < drag_min_distance) return FALSE; // We will show the menu now. Cancel the delayed event. - button->show_menu_factory_.RevokeAll(); - button->ShowBackForwardMenu(); + show_menu_factory_.RevokeAll(); + ShowBackForwardMenu(); return FALSE; } diff --git a/chrome/browser/gtk/back_forward_button_gtk.h b/chrome/browser/gtk/back_forward_button_gtk.h index 2e91c6d..7138ecf 100644 --- a/chrome/browser/gtk/back_forward_button_gtk.h +++ b/chrome/browser/gtk/back_forward_button_gtk.h @@ -9,6 +9,7 @@ #include "base/task.h" #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/menu_gtk.h" +#include "chrome/common/gtk_signal.h" class BackForwardMenuModel; class Browser; @@ -30,19 +31,17 @@ class BackForwardButtonGtk : MenuGtk::Delegate { private: // Executes the browser command. - static void OnClick(GtkWidget* widget, BackForwardButtonGtk* button); + CHROMEGTK_CALLBACK_0(BackForwardButtonGtk, void, OnClick); // Starts a timer to show the dropdown menu. - static gboolean OnButtonPress(GtkWidget* button, - GdkEventButton* event, - BackForwardButtonGtk* toolbar); + CHROMEGTK_CALLBACK_1(BackForwardButtonGtk, gboolean, OnButtonPress, + GdkEventButton*); // If there is a timer to show the dropdown menu, and the mouse has moved // sufficiently down the screen, cancel the timer and immediately show the // menu. - static gboolean OnMouseMove(GtkWidget* widget, - GdkEventMotion* event, - BackForwardButtonGtk* toolbar); + CHROMEGTK_CALLBACK_1(BackForwardButtonGtk, gboolean, OnMouseMove, + GdkEventMotion*); // Shows the dropdown menu. void ShowBackForwardMenu(); diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index 1105bf9b..027c4705 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -189,9 +189,9 @@ void BookmarkBarGtk::SetPageNavigator(PageNavigator* navigator) { void BookmarkBarGtk::Init(Profile* profile) { event_box_.Own(gtk_event_box_new()); g_signal_connect(event_box_.get(), "destroy", - G_CALLBACK(&OnEventBoxDestroy), this); + G_CALLBACK(&OnEventBoxDestroyThunk), this); g_signal_connect(event_box_.get(), "button-press-event", - G_CALLBACK(&OnButtonPressed), this); + G_CALLBACK(&OnButtonPressedThunk), this); ntp_padding_box_ = gtk_alignment_new(0, 0, 1, 1); gtk_container_add(GTK_CONTAINER(event_box_.get()), ntp_padding_box_); @@ -220,10 +220,10 @@ void BookmarkBarGtk::Init(Profile* profile) { NULL, 0, kDragAction); gtk_dnd_util::SetDestTargetList(instructions_, kDestTargetList); g_signal_connect(instructions_, "drag-data-received", - G_CALLBACK(&OnDragReceived), this); + G_CALLBACK(&OnDragReceivedThunk), this); g_signal_connect(event_box_.get(), "expose-event", - G_CALLBACK(&OnEventBoxExpose), this); + G_CALLBACK(&OnEventBoxExposeThunk), this); UpdateEventBoxPaintability(); bookmark_toolbar_.Own(gtk_toolbar_new()); @@ -231,7 +231,7 @@ void BookmarkBarGtk::Init(Profile* profile) { gtk_widget_set_name(bookmark_toolbar_.get(), "chrome-bookmark-toolbar"); gtk_util::SuppressDefaultPainting(bookmark_toolbar_.get()); g_signal_connect(bookmark_toolbar_.get(), "size-allocate", - G_CALLBACK(&OnToolbarSizeAllocate), this); + G_CALLBACK(&OnToolbarSizeAllocateThunk), this); gtk_box_pack_start(GTK_BOX(bookmark_hbox_), bookmark_toolbar_.get(), TRUE, TRUE, 0); @@ -247,17 +247,17 @@ void BookmarkBarGtk::Init(Profile* profile) { NULL, 0, kDragAction); gtk_dnd_util::SetDestTargetList(bookmark_toolbar_.get(), kDestTargetList); g_signal_connect(bookmark_toolbar_.get(), "drag-motion", - G_CALLBACK(&OnToolbarDragMotion), this); + G_CALLBACK(&OnToolbarDragMotionThunk), this); g_signal_connect(bookmark_toolbar_.get(), "drag-leave", - G_CALLBACK(&OnToolbarDragLeave), this); + G_CALLBACK(&OnToolbarDragLeaveThunk), this); g_signal_connect(bookmark_toolbar_.get(), "drag-data-received", - G_CALLBACK(&OnDragReceived), this); + G_CALLBACK(&OnDragReceivedThunk), this); GtkWidget* vseparator = gtk_vseparator_new(); gtk_box_pack_start(GTK_BOX(bookmark_hbox_), vseparator, FALSE, FALSE, 0); g_signal_connect(vseparator, "expose-event", - G_CALLBACK(OnSeparatorExpose), this); + G_CALLBACK(OnSeparatorExposeThunk), this); // We pack the button manually (rather than using gtk_button_set_*) so that // we can have finer control over its label. @@ -272,7 +272,7 @@ void BookmarkBarGtk::Init(Profile* profile) { gtk_image_new_from_pixbuf( ResourceBundle::GetSharedInstance().GetPixbufNamed(IDR_WARNING))); g_signal_connect(sync_error_button_, "button-press-event", - G_CALLBACK(OnSyncErrorButtonPressed), this); + G_CALLBACK(OnSyncErrorButtonPressedThunk), this); gtk_box_pack_start(GTK_BOX(bookmark_hbox_), sync_error_button_, FALSE, FALSE, 0); @@ -665,10 +665,10 @@ void BookmarkBarGtk::UpdateFloatingState() { if (floating_ && widget()->parent) { // Only connect once. if (g_signal_handler_find(widget()->parent, G_SIGNAL_MATCH_FUNC, - 0, NULL, NULL, reinterpret_cast<gpointer>(OnParentSizeAllocate), + 0, NULL, NULL, reinterpret_cast<gpointer>(OnParentSizeAllocateThunk), NULL) == 0) { g_signal_connect(widget()->parent, "size-allocate", - G_CALLBACK(OnParentSizeAllocate), this); + G_CALLBACK(OnParentSizeAllocateThunk), this); } } } @@ -757,7 +757,7 @@ void BookmarkBarGtk::SetThrobbingWidget(GtkWidget* widget) { g_signal_handlers_disconnect_by_func( throbbing_widget_, - reinterpret_cast<gpointer>(OnThrobbingWidgetDestroy), + reinterpret_cast<gpointer>(OnThrobbingWidgetDestroyThunk), this); g_object_unref(throbbing_widget_); throbbing_widget_ = NULL; @@ -767,7 +767,7 @@ void BookmarkBarGtk::SetThrobbingWidget(GtkWidget* widget) { throbbing_widget_ = widget; g_object_ref(throbbing_widget_); g_signal_connect(throbbing_widget_, "destroy", - G_CALLBACK(OnThrobbingWidgetDestroy), this); + G_CALLBACK(OnThrobbingWidgetDestroyThunk), this); HoverControllerGtk* hover_controller = HoverControllerGtk::GetHoverControllerGtk(throbbing_widget_); @@ -845,11 +845,11 @@ GtkWidget* BookmarkBarGtk::CreateBookmarkButton(const BookmarkNode* node) { } gtk_dnd_util::SetSourceTargetListFromCodeMask(button, target_mask); g_signal_connect(button, "drag-begin", - G_CALLBACK(&OnButtonDragBegin), this); + G_CALLBACK(&OnButtonDragBeginThunk), this); g_signal_connect(button, "drag-end", - G_CALLBACK(&OnButtonDragEnd), this); + G_CALLBACK(&OnButtonDragEndThunk), this); g_signal_connect(button, "drag-data-get", - G_CALLBACK(&OnButtonDragGet), this); + G_CALLBACK(&OnButtonDragGetThunk), this); // We deliberately don't connect to "drag-data-delete" because the action of // moving a button will regenerate all the contents of the bookmarks bar // anyway. @@ -859,9 +859,9 @@ GtkWidget* BookmarkBarGtk::CreateBookmarkButton(const BookmarkNode* node) { // access to the modifier keys and we do different things on each // button. g_signal_connect(button, "button-press-event", - G_CALLBACK(OnButtonPressed), this); + G_CALLBACK(OnButtonPressedThunk), this); g_signal_connect(button, "clicked", - G_CALLBACK(OnClicked), this); + G_CALLBACK(OnClickedThunk), this); gtk_util::SetButtonTriggersNavigation(button); } else { ConnectFolderButtonEvents(button); @@ -886,12 +886,12 @@ void BookmarkBarGtk::ConnectFolderButtonEvents(GtkWidget* widget) { gtk_drag_dest_set(widget, GTK_DEST_DEFAULT_ALL, NULL, 0, kDragAction); gtk_dnd_util::SetDestTargetList(widget, kDestTargetList); g_signal_connect(widget, "drag-data-received", - G_CALLBACK(&OnDragReceived), this); + G_CALLBACK(&OnDragReceivedThunk), this); g_signal_connect(widget, "button-press-event", - G_CALLBACK(OnButtonPressed), this); + G_CALLBACK(OnButtonPressedThunk), this); g_signal_connect(widget, "clicked", - G_CALLBACK(OnFolderClicked), this); + G_CALLBACK(OnFolderClickedThunk), this); // Accept middle mouse clicking (which opens all). This must be called after // connecting to "button-press-event" because the handler it attaches stops @@ -958,63 +958,55 @@ void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender, current_context_menu_->PopupAsContext(event->time); } -// static gboolean BookmarkBarGtk::OnButtonPressed(GtkWidget* sender, - GdkEventButton* event, - BookmarkBarGtk* bar) { + GdkEventButton* event) { if (event->button == 3) { - const BookmarkNode* node = bar->GetNodeForToolButton(sender); + const BookmarkNode* node = GetNodeForToolButton(sender); DCHECK(node); - DCHECK(bar->page_navigator_); - bar->PopupMenuForNode(sender, node, event); + DCHECK(page_navigator_); + PopupMenuForNode(sender, node, event); } return FALSE; } -// static gboolean BookmarkBarGtk::OnSyncErrorButtonPressed(GtkWidget* sender, - GdkEventButton* event, - BookmarkBarGtk* bar) { - if (sender == bar->sync_error_button_) { - DCHECK(bar->sync_service_); - bar->sync_service_->ShowLoginDialog(); + GdkEventButton* event) { + if (sender == sync_error_button_) { + DCHECK(sync_service_); + sync_service_->ShowLoginDialog(); } return FALSE; } -// static -void BookmarkBarGtk::OnClicked(GtkWidget* sender, - BookmarkBarGtk* bar) { - const BookmarkNode* node = bar->GetNodeForToolButton(sender); +void BookmarkBarGtk::OnClicked(GtkWidget* sender) { + const BookmarkNode* node = GetNodeForToolButton(sender); DCHECK(node); DCHECK(node->is_url()); - DCHECK(bar->page_navigator_); + DCHECK(page_navigator_); - bar->page_navigator_->OpenURL( + page_navigator_->OpenURL( node->GetURL(), GURL(), gtk_util::DispositionForCurrentButtonPressEvent(), PageTransition::AUTO_BOOKMARK); - UserMetrics::RecordAction("ClickedBookmarkBarURLButton", bar->profile_); + UserMetrics::RecordAction("ClickedBookmarkBarURLButton", profile_); } -// static void BookmarkBarGtk::OnButtonDragBegin(GtkWidget* button, - GdkDragContext* drag_context, - BookmarkBarGtk* bar) { + GdkDragContext* drag_context) { // The parent tool item might be removed during the drag. Ref it so |button| // won't get destroyed. g_object_ref(button->parent); - const BookmarkNode* node = bar->GetNodeForToolButton(button); - DCHECK(!bar->dragged_node_); - bar->dragged_node_ = node; - DCHECK(bar->dragged_node_); + const BookmarkNode* node = GetNodeForToolButton(button); + DCHECK(!dragged_node_); + dragged_node_ = node; + DCHECK(dragged_node_); GtkWidget* window = bookmark_utils::GetDragRepresentation( - node, bar->model_, bar->theme_provider_); + node, model_, theme_provider_); gint x, y; gtk_widget_get_pointer(button, &x, &y); gtk_drag_set_icon_widget(drag_context, window, x, y); @@ -1025,37 +1017,31 @@ void BookmarkBarGtk::OnButtonDragBegin(GtkWidget* button, gtk_widget_set_no_show_all(button, TRUE); } -// static void BookmarkBarGtk::OnButtonDragEnd(GtkWidget* button, - GdkDragContext* drag_context, - BookmarkBarGtk* bar) { + GdkDragContext* drag_context) { gtk_widget_show(button); gtk_widget_set_no_show_all(button, FALSE); - if (bar->toolbar_drop_item_) { - g_object_unref(bar->toolbar_drop_item_); - bar->toolbar_drop_item_ = NULL; + if (toolbar_drop_item_) { + g_object_unref(toolbar_drop_item_); + toolbar_drop_item_ = NULL; } - DCHECK(bar->dragged_node_); - bar->dragged_node_ = NULL; + DCHECK(dragged_node_); + dragged_node_ = NULL; g_object_unref(button->parent); } -// static void BookmarkBarGtk::OnButtonDragGet(GtkWidget* widget, GdkDragContext* context, GtkSelectionData* selection_data, - guint target_type, guint time, - BookmarkBarGtk* bar) { + guint target_type, guint time) { const BookmarkNode* node = bookmark_utils::BookmarkNodeForWidget(widget); bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type, - bar->profile_); + profile_); } -// static -void BookmarkBarGtk::OnFolderClicked(GtkWidget* sender, - BookmarkBarGtk* bar) { +void BookmarkBarGtk::OnFolderClicked(GtkWidget* sender) { // Stop its throbbing, if any. HoverControllerGtk* hover_controller = HoverControllerGtk::GetHoverControllerGtk(sender); @@ -1064,48 +1050,46 @@ void BookmarkBarGtk::OnFolderClicked(GtkWidget* sender, GdkEvent* event = gtk_get_current_event(); if (event->button.button == 1) { - bar->PopupForButton(sender); + PopupForButton(sender); } else if (event->button.button == 2) { - const BookmarkNode* node = bar->GetNodeForToolButton(sender); - bookmark_utils::OpenAll(bar->window_->GetNativeHandle(), - bar->profile_, bar->page_navigator_, + const BookmarkNode* node = GetNodeForToolButton(sender); + bookmark_utils::OpenAll(window_->GetNativeHandle(), + profile_, page_navigator_, node, NEW_BACKGROUND_TAB); } } -// static -gboolean BookmarkBarGtk::OnToolbarDragMotion(GtkToolbar* toolbar, +gboolean BookmarkBarGtk::OnToolbarDragMotion(GtkWidget* toolbar, GdkDragContext* context, gint x, gint y, - guint time, - BookmarkBarGtk* bar) { + guint time) { GdkAtom target_type = - gtk_drag_dest_find_target(GTK_WIDGET(toolbar), context, NULL); + gtk_drag_dest_find_target(toolbar, context, NULL); if (target_type == GDK_NONE) { // We shouldn't act like a drop target when something that we can't deal // with is dragged over the toolbar. return FALSE; } - if (!bar->toolbar_drop_item_) { - if (bar->dragged_node_) { - bar->toolbar_drop_item_ = bar->CreateBookmarkToolItem(bar->dragged_node_); - g_object_ref_sink(GTK_OBJECT(bar->toolbar_drop_item_)); + if (!toolbar_drop_item_) { + if (dragged_node_) { + toolbar_drop_item_ = CreateBookmarkToolItem(dragged_node_); + g_object_ref_sink(GTK_OBJECT(toolbar_drop_item_)); } else { // Create a fake item the size of other_node(). // // TODO(erg): Maybe somehow figure out the real size for the drop target? - bar->toolbar_drop_item_ = - bar->CreateBookmarkToolItem(bar->model_->other_node()); - g_object_ref_sink(GTK_OBJECT(bar->toolbar_drop_item_)); + toolbar_drop_item_ = + CreateBookmarkToolItem(model_->other_node()); + g_object_ref_sink(GTK_OBJECT(toolbar_drop_item_)); } } - if (bar->toolbar_drop_item_) { - gint index = gtk_toolbar_get_drop_index(toolbar, x, y); - gtk_toolbar_set_drop_highlight_item(toolbar, - GTK_TOOL_ITEM(bar->toolbar_drop_item_), + if (toolbar_drop_item_) { + gint index = gtk_toolbar_get_drop_index(GTK_TOOLBAR(toolbar), x, y); + gtk_toolbar_set_drop_highlight_item(GTK_TOOLBAR(toolbar), + GTK_TOOL_ITEM(toolbar_drop_item_), index); } @@ -1119,57 +1103,51 @@ gboolean BookmarkBarGtk::OnToolbarDragMotion(GtkToolbar* toolbar, return TRUE; } -// static -void BookmarkBarGtk::OnToolbarDragLeave(GtkToolbar* toolbar, +void BookmarkBarGtk::OnToolbarDragLeave(GtkWidget* toolbar, GdkDragContext* context, - guint time, - BookmarkBarGtk* bar) { - if (bar->toolbar_drop_item_) { - g_object_unref(bar->toolbar_drop_item_); - bar->toolbar_drop_item_ = NULL; + guint time) { + if (toolbar_drop_item_) { + g_object_unref(toolbar_drop_item_); + toolbar_drop_item_ = NULL; } - gtk_toolbar_set_drop_highlight_item(toolbar, NULL, 0); + gtk_toolbar_set_drop_highlight_item(GTK_TOOLBAR(toolbar), NULL, 0); } -// static void BookmarkBarGtk::OnToolbarSizeAllocate(GtkWidget* widget, - GtkAllocation* allocation, - BookmarkBarGtk* bar) { - if (bar->bookmark_toolbar_.get()->allocation.width == - bar->last_allocation_width_) { + GtkAllocation* allocation) { + if (bookmark_toolbar_.get()->allocation.width == + last_allocation_width_) { // If the width hasn't changed, then the visibility of the chevron // doesn't need to change. This check prevents us from getting stuck in a // loop where allocates are queued indefinitely while the visibility of // overflow chevron toggles without actual resizes of the toolbar. return; } - bar->last_allocation_width_ = bar->bookmark_toolbar_.get()->allocation.width; + last_allocation_width_ = bookmark_toolbar_.get()->allocation.width; - bar->SetChevronState(); + SetChevronState(); } -// static void BookmarkBarGtk::OnDragReceived(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData* selection_data, - guint target_type, guint time, - BookmarkBarGtk* bar) { + guint target_type, guint time) { gboolean dnd_success = FALSE; gboolean delete_selection_data = FALSE; const BookmarkNode* dest_node; gint index; - if (widget == bar->bookmark_toolbar_.get()) { - dest_node = bar->model_->GetBookmarkBarNode(); + if (widget == bookmark_toolbar_.get()) { + dest_node = model_->GetBookmarkBarNode(); index = gtk_toolbar_get_drop_index( - GTK_TOOLBAR(bar->bookmark_toolbar_.get()), x, y); - } else if (widget == bar->instructions_) { - dest_node = bar->model_->GetBookmarkBarNode(); + GTK_TOOLBAR(bookmark_toolbar_.get()), x, y); + } else if (widget == instructions_) { + dest_node = model_->GetBookmarkBarNode(); index = 0; } else { - dest_node = bar->GetNodeForToolButton(widget); + dest_node = GetNodeForToolButton(widget); index = dest_node->GetChildCount(); } @@ -1178,13 +1156,13 @@ void BookmarkBarGtk::OnDragReceived(GtkWidget* widget, std::vector<const BookmarkNode*> nodes = bookmark_utils::GetNodesFromSelection(context, selection_data, target_type, - bar->profile_, + profile_, &delete_selection_data, &dnd_success); DCHECK(!nodes.empty()); for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it) { - bar->model_->Move(*it, dest_node, index); + model_->Move(*it, dest_node, index); index = dest_node->IndexOfChild(*it) + 1; } break; @@ -1192,13 +1170,13 @@ void BookmarkBarGtk::OnDragReceived(GtkWidget* widget, case gtk_dnd_util::CHROME_NAMED_URL: { dnd_success = bookmark_utils::CreateNewBookmarkFromNamedUrl( - selection_data, bar->model_, dest_node, index); + selection_data, model_, dest_node, index); break; } case gtk_dnd_util::TEXT_URI_LIST: { dnd_success = bookmark_utils::CreateNewBookmarksFromURIList( - selection_data, bar->model_, dest_node, index); + selection_data, model_, dest_node, index); break; } @@ -1213,7 +1191,7 @@ void BookmarkBarGtk::OnDragReceived(GtkWidget* widget, if (!url.is_valid()) break; std::string title = bookmark_utils::GetNameForURL(url); - bar->model_->AddURL(dest_node, index, UTF8ToWide(title), url); + model_->AddURL(dest_node, index, UTF8ToWide(title), url); dnd_success = TRUE; break; } @@ -1222,32 +1200,30 @@ void BookmarkBarGtk::OnDragReceived(GtkWidget* widget, gtk_drag_finish(context, dnd_success, delete_selection_data, time); } -// static gboolean BookmarkBarGtk::OnEventBoxExpose(GtkWidget* widget, - GdkEventExpose* event, - BookmarkBarGtk* bar) { - GtkThemeProvider* theme_provider = bar->theme_provider_; + GdkEventExpose* event) { + GtkThemeProvider* theme_provider = theme_provider_; // We don't need to render the toolbar image in GTK mode, except when // detached. - if (theme_provider->UseGtkTheme() && !bar->floating_) + if (theme_provider->UseGtkTheme() && !floating_) return FALSE; - if (!bar->floating_) { + if (!floating_) { cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); gdk_cairo_rectangle(cr, &event->area); cairo_clip(cr); // Paint the background theme image. gfx::Point tabstrip_origin = - bar->tabstrip_origin_provider_->GetTabStripOriginForWidget(widget); + tabstrip_origin_provider_->GetTabStripOriginForWidget(widget); gtk_util::DrawThemedToolbarBackground(widget, cr, event, tabstrip_origin, theme_provider); cairo_destroy(cr); } else { gfx::Size tab_contents_size; - if (!bar->GetTabContentsSize(&tab_contents_size)) + if (!GetTabContentsSize(&tab_contents_size)) return FALSE; gfx::CanvasPaint canvas(event, true); @@ -1261,37 +1237,31 @@ gboolean BookmarkBarGtk::OnEventBoxExpose(GtkWidget* widget, return FALSE; // Propagate expose to children. } -// static -void BookmarkBarGtk::OnEventBoxDestroy(GtkWidget* widget, - BookmarkBarGtk* bar) { - if (bar->model_) - bar->model_->RemoveObserver(bar); +void BookmarkBarGtk::OnEventBoxDestroy(GtkWidget* widget) { + if (model_) + model_->RemoveObserver(this); - if (bar->sync_service_) - bar->sync_service_->RemoveObserver(bar); + if (sync_service_) + sync_service_->RemoveObserver(this); } -// static void BookmarkBarGtk::OnParentSizeAllocate(GtkWidget* widget, - GtkAllocation* allocation, - BookmarkBarGtk* bar) { + GtkAllocation* allocation) { // In floating mode, our layout depends on the size of the tab contents. // We get the size-allocate signal before the tab contents does, hence we // need to post a delayed task so we will paint correctly. Note that // gtk_widget_queue_draw by itself does not work, despite that it claims to // be asynchronous. - if (bar->floating_) { + if (floating_) { MessageLoop::current()->PostTask(FROM_HERE, - bar->method_factory_.NewRunnableMethod( + method_factory_.NewRunnableMethod( &BookmarkBarGtk::PaintEventBox)); } } -// static gboolean BookmarkBarGtk::OnSeparatorExpose(GtkWidget* widget, - GdkEventExpose* event, - BookmarkBarGtk* bar) { - if (bar->theme_provider_->UseGtkTheme()) + GdkEventExpose* event) { + if (theme_provider_->UseGtkTheme()) return FALSE; cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); @@ -1299,7 +1269,7 @@ gboolean BookmarkBarGtk::OnSeparatorExpose(GtkWidget* widget, cairo_clip(cr); GdkColor bottom_color = - bar->theme_provider_->GetGdkColor(BrowserThemeProvider::COLOR_TOOLBAR); + theme_provider_->GetGdkColor(BrowserThemeProvider::COLOR_TOOLBAR); double bottom_color_rgb[] = { static_cast<double>(bottom_color.red / 257) / 255.0, static_cast<double>(bottom_color.green / 257) / 255.0, @@ -1334,10 +1304,8 @@ gboolean BookmarkBarGtk::OnSeparatorExpose(GtkWidget* widget, return TRUE; } -// static -void BookmarkBarGtk::OnThrobbingWidgetDestroy(GtkWidget* widget, - BookmarkBarGtk* bar) { - bar->SetThrobbingWidget(NULL); +void BookmarkBarGtk::OnThrobbingWidgetDestroy(GtkWidget* widget) { + SetThrobbingWidget(NULL); } // MenuBarHelper::Delegate implementation -------------------------------------- diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h index df433dc..5e2d048 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.h +++ b/chrome/browser/gtk/bookmark_bar_gtk.h @@ -19,6 +19,7 @@ #include "chrome/browser/gtk/menu_bar_helper.h" #include "chrome/browser/gtk/view_id_util.h" #include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/common/gtk_signal.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/owned_widget_gtk.h" @@ -217,69 +218,48 @@ class BookmarkBarGtk : public AnimationDelegate, GdkEventButton* event); // GtkButton callbacks. - static gboolean OnButtonPressed(GtkWidget* sender, - GdkEventButton* event, - BookmarkBarGtk* bar); - static gboolean OnSyncErrorButtonPressed(GtkWidget* sender, - GdkEventButton* event, - BookmarkBarGtk* bar); - static void OnClicked(GtkWidget* sender, - BookmarkBarGtk* bar); - static void OnButtonDragBegin(GtkWidget* widget, - GdkDragContext* drag_context, - BookmarkBarGtk* bar); - static void OnButtonDragEnd(GtkWidget* button, - GdkDragContext* drag_context, - BookmarkBarGtk* bar); - static void OnButtonDragGet(GtkWidget* widget, GdkDragContext* context, - GtkSelectionData* selection_data, - guint target_type, guint time, - BookmarkBarGtk* bar); + CHROMEGTK_CALLBACK_1(BookmarkBarGtk, gboolean, OnButtonPressed, + GdkEventButton*); + CHROMEGTK_CALLBACK_1(BookmarkBarGtk, gboolean, OnSyncErrorButtonPressed, + GdkEventButton*); + CHROMEGTK_CALLBACK_0(BookmarkBarGtk, void, OnClicked); + CHROMEGTK_CALLBACK_1(BookmarkBarGtk, void, OnButtonDragBegin, + GdkDragContext*); + CHROMEGTK_CALLBACK_1(BookmarkBarGtk, void, OnButtonDragEnd, GdkDragContext*); + CHROMEGTK_CALLBACK_4(BookmarkBarGtk, void, OnButtonDragGet, + GdkDragContext*, GtkSelectionData*, guint, guint); // GtkButton callbacks for folder buttons. - static void OnFolderClicked(GtkWidget* sender, - BookmarkBarGtk* bar); + CHROMEGTK_CALLBACK_0(BookmarkBarGtk, void, OnFolderClicked); // GtkToolbar callbacks. - static gboolean OnToolbarDragMotion(GtkToolbar* toolbar, - GdkDragContext* context, - gint x, - gint y, - guint time, - BookmarkBarGtk* bar); - static void OnToolbarDragLeave(GtkToolbar* toolbar, - GdkDragContext* context, - guint time, - BookmarkBarGtk* bar); - static void OnToolbarSizeAllocate(GtkWidget* widget, - GtkAllocation* allocation, - BookmarkBarGtk* bar); + CHROMEGTK_CALLBACK_4(BookmarkBarGtk, gboolean, OnToolbarDragMotion, + GdkDragContext*, gint, gint, guint); + CHROMEGTK_CALLBACK_2(BookmarkBarGtk, void, OnToolbarDragLeave, + GdkDragContext*, guint); + CHROMEGTK_CALLBACK_1(BookmarkBarGtk, void, OnToolbarSizeAllocate, + GtkAllocation*); // Used for both folder buttons and the toolbar. - static void OnDragReceived(GtkWidget* widget, - GdkDragContext* context, - gint x, gint y, - GtkSelectionData* selection_data, - guint target_type, guint time, - BookmarkBarGtk* bar); + CHROMEGTK_CALLBACK_6(BookmarkBarGtk, void, OnDragReceived, + GdkDragContext*, gint, gint, GtkSelectionData*, + guint, guint); // GtkEventBox callbacks. - static gboolean OnEventBoxExpose(GtkWidget* widget, GdkEventExpose* event, - BookmarkBarGtk* bar); - static void OnEventBoxDestroy(GtkWidget* widget, BookmarkBarGtk* bar); + CHROMEGTK_CALLBACK_1(BookmarkBarGtk, gboolean, OnEventBoxExpose, + GdkEventExpose*); + CHROMEGTK_CALLBACK_0(BookmarkBarGtk, void, OnEventBoxDestroy); // GtkVSeparator callbacks. - static gboolean OnSeparatorExpose(GtkWidget* widget, GdkEventExpose* event, - BookmarkBarGtk* bar); + CHROMEGTK_CALLBACK_1(BookmarkBarGtk, gboolean, OnSeparatorExpose, + GdkEventExpose*); // Callbacks on our parent widget. - static void OnParentSizeAllocate(GtkWidget* widget, - GtkAllocation* allocation, - BookmarkBarGtk* bar); + CHROMEGTK_CALLBACK_1(BookmarkBarGtk, void, OnParentSizeAllocate, + GtkAllocation*); // |throbbing_widget_| callback. - static void OnThrobbingWidgetDestroy(GtkWidget* widget, - BookmarkBarGtk* bar); + CHROMEGTK_CALLBACK_0(BookmarkBarGtk, void, OnThrobbingWidgetDestroy); // ProfileSyncServiceObserver method. virtual void OnStateChanged(); diff --git a/chrome/browser/gtk/bookmark_bar_instructions_gtk.cc b/chrome/browser/gtk/bookmark_bar_instructions_gtk.cc index ce380c3..3734888 100644 --- a/chrome/browser/gtk/bookmark_bar_instructions_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_instructions_gtk.cc @@ -54,7 +54,7 @@ BookmarkBarInstructionsGtk::BookmarkBarInstructionsGtk(Delegate* delegate, gtk_misc_set_alignment( GTK_MISC(GTK_CHROME_LINK_BUTTON(instructions_link_)->label), 0, 0.5); g_signal_connect(instructions_link_, "clicked", - G_CALLBACK(OnButtonClick), this); + G_CALLBACK(OnButtonClickThunk), this); gtk_util::SetButtonTriggersNavigation(instructions_link_); // Until we switch to vector graphics, force the font size. // 13.4px == 10pt @ 96dpi @@ -77,10 +77,8 @@ void BookmarkBarInstructionsGtk::Observe(NotificationType type, UpdateColors(); } -// static -void BookmarkBarInstructionsGtk::OnButtonClick( - GtkWidget* button, BookmarkBarInstructionsGtk* instructions) { - instructions->delegate_->ShowImportDialog(); +void BookmarkBarInstructionsGtk::OnButtonClick(GtkWidget* button) { + delegate_->ShowImportDialog(); } void BookmarkBarInstructionsGtk::UpdateColors() { diff --git a/chrome/browser/gtk/bookmark_bar_instructions_gtk.h b/chrome/browser/gtk/bookmark_bar_instructions_gtk.h index 13a324b..d8d2e49 100644 --- a/chrome/browser/gtk/bookmark_bar_instructions_gtk.h +++ b/chrome/browser/gtk/bookmark_bar_instructions_gtk.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_GTK_BOOKMARK_BAR_INSTRUCTIONS_GTK_H_ #include "base/basictypes.h" +#include "chrome/common/gtk_signal.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" @@ -32,8 +33,7 @@ class BookmarkBarInstructionsGtk : public NotificationObserver { const NotificationSource& source, const NotificationDetails& details); - static void OnButtonClick(GtkWidget* button, - BookmarkBarInstructionsGtk* instructions); + CHROMEGTK_CALLBACK_0(BookmarkBarInstructionsGtk, void, OnButtonClick); // Sets the correct color for |instructions_label_| and |instructions_link_|. void UpdateColors(); diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.cc b/chrome/browser/gtk/bookmark_bubble_gtk.cc index 355d314..7b16fb8 100644 --- a/chrome/browser/gtk/bookmark_bubble_gtk.cc +++ b/chrome/browser/gtk/bookmark_bubble_gtk.cc @@ -237,19 +237,19 @@ BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* toplevel_window, } g_signal_connect(content, "destroy", - G_CALLBACK(&HandleDestroyThunk), this); + G_CALLBACK(&OnDestroyThunk), this); g_signal_connect(name_entry_, "activate", - G_CALLBACK(&HandleNameActivateThunk), this); + G_CALLBACK(&OnNameActivateThunk), this); g_signal_connect(folder_combo_, "changed", - G_CALLBACK(&HandleFolderChangedThunk), this); + G_CALLBACK(&OnFolderChangedThunk), this); g_signal_connect(folder_combo_, "notify::popup-shown", - G_CALLBACK(&HandleFolderPopupShownThunk), this); + G_CALLBACK(&OnFolderPopupShownThunk), this); g_signal_connect(edit_button, "clicked", - G_CALLBACK(&HandleEditButtonThunk), this); + G_CALLBACK(&OnEditClickedThunk), this); g_signal_connect(close_button, "clicked", - G_CALLBACK(&HandleCloseButtonThunk), this); + G_CALLBACK(&OnCloseClickedThunk), this); g_signal_connect(remove_button_, "clicked", - G_CALLBACK(&HandleRemoveButtonThunk), this); + G_CALLBACK(&OnRemoveClickedThunk), this); registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, NotificationService::AllSources()); @@ -272,18 +272,18 @@ BookmarkBubbleGtk::~BookmarkBubbleGtk() { } } -void BookmarkBubbleGtk::HandleDestroy() { +void BookmarkBubbleGtk::OnDestroy(GtkWidget* widget) { // We are self deleting, we have a destroy signal setup to catch when we // destroyed (via the InfoBubble being destroyed), and delete ourself. content_ = NULL; // We are being destroyed. delete this; } -void BookmarkBubbleGtk::HandleNameActivate() { +void BookmarkBubbleGtk::OnNameActivate(GtkWidget* widget) { bubble_->Close(); } -void BookmarkBubbleGtk::HandleFolderChanged() { +void BookmarkBubbleGtk::OnFolderChanged(GtkWidget* widget) { size_t cur_folder = gtk_combo_box_get_active(GTK_COMBO_BOX(folder_combo_)); if (cur_folder == folder_nodes_.size()) { UserMetrics::RecordAction("BookmarkBubble_EditFromCombobox", profile_); @@ -296,7 +296,7 @@ void BookmarkBubbleGtk::HandleFolderChanged() { } } -void BookmarkBubbleGtk::HandleFolderPopupShown() { +void BookmarkBubbleGtk::OnFolderPopupShown(GtkWidget* widget) { // GtkComboBox grabs the keyboard and pointer when it displays its popup, // which steals the grabs that InfoBubbleGtk had installed. When the popup is // hidden, we notify InfoBubbleGtk so it can try to reacquire the grabs @@ -307,16 +307,16 @@ void BookmarkBubbleGtk::HandleFolderPopupShown() { bubble_->HandlePointerAndKeyboardUngrabbedByContent(); } -void BookmarkBubbleGtk::HandleEditButton() { +void BookmarkBubbleGtk::OnEditClicked(GtkWidget* widget) { UserMetrics::RecordAction("BookmarkBubble_Edit", profile_); ShowEditor(); } -void BookmarkBubbleGtk::HandleCloseButton() { +void BookmarkBubbleGtk::OnCloseClicked(GtkWidget* widget) { bubble_->Close(); } -void BookmarkBubbleGtk::HandleRemoveButton() { +void BookmarkBubbleGtk::OnRemoveClicked(GtkWidget* widget) { UserMetrics::RecordAction("BookmarkBubble_Unstar", profile_); apply_edits_ = false; diff --git a/chrome/browser/gtk/bookmark_bubble_gtk.h b/chrome/browser/gtk/bookmark_bubble_gtk.h index a071ca57..ff8688b 100644 --- a/chrome/browser/gtk/bookmark_bubble_gtk.h +++ b/chrome/browser/gtk/bookmark_bubble_gtk.h @@ -20,6 +20,7 @@ #include "base/basictypes.h" #include "base/task.h" #include "chrome/browser/gtk/info_bubble_gtk.h" +#include "chrome/common/gtk_signal.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "googleurl/src/gurl.h" @@ -59,56 +60,14 @@ class BookmarkBubbleGtk : public InfoBubbleGtkDelegate, bool newly_bookmarked); ~BookmarkBubbleGtk(); - static void HandleDestroyThunk(GtkWidget* widget, - gpointer userdata) { - reinterpret_cast<BookmarkBubbleGtk*>(userdata)-> - HandleDestroy(); - } // Notified when |content_| is destroyed so we can delete our instance. - void HandleDestroy(); - - static void HandleNameActivateThunk(GtkWidget* widget, - gpointer user_data) { - reinterpret_cast<BookmarkBubbleGtk*>(user_data)-> - HandleNameActivate(); - } - void HandleNameActivate(); - - static void HandleFolderChangedThunk(GtkWidget* widget, - gpointer user_data) { - reinterpret_cast<BookmarkBubbleGtk*>(user_data)-> - HandleFolderChanged(); - } - void HandleFolderChanged(); - - static void HandleFolderPopupShownThunk(GObject* object, - GParamSpec* property, - gpointer user_data) { - return reinterpret_cast<BookmarkBubbleGtk*>(user_data)-> - HandleFolderPopupShown(); - } - void HandleFolderPopupShown(); - - static void HandleEditButtonThunk(GtkWidget* widget, - gpointer user_data) { - reinterpret_cast<BookmarkBubbleGtk*>(user_data)-> - HandleEditButton(); - } - void HandleEditButton(); - - static void HandleCloseButtonThunk(GtkWidget* widget, - gpointer user_data) { - reinterpret_cast<BookmarkBubbleGtk*>(user_data)-> - HandleCloseButton(); - } - void HandleCloseButton(); - - static void HandleRemoveButtonThunk(GtkWidget* widget, - gpointer user_data) { - reinterpret_cast<BookmarkBubbleGtk*>(user_data)-> - HandleRemoveButton(); - } - void HandleRemoveButton(); + CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnDestroy); + CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnNameActivate); + CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnFolderChanged); + CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnFolderPopupShown); + CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnEditClicked); + CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnCloseClicked); + CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnRemoveClicked); // Update the bookmark with any edits that have been made. void ApplyEdits(); diff --git a/chrome/browser/gtk/bookmark_editor_gtk.cc b/chrome/browser/gtk/bookmark_editor_gtk.cc index f73ed6a..c16164c 100644 --- a/chrome/browser/gtk/bookmark_editor_gtk.cc +++ b/chrome/browser/gtk/bookmark_editor_gtk.cc @@ -94,7 +94,7 @@ void BookmarkEditorGtk::Init(GtkWindow* parent_window) { new_folder_button_ = gtk_button_new_with_label( l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NEW_FOLDER_BUTTON).c_str()); g_signal_connect(new_folder_button_, "clicked", - G_CALLBACK(OnNewFolderClicked), this); + G_CALLBACK(OnNewFolderClickedThunk), this); gtk_container_add(GTK_CONTAINER(action_area), new_folder_button_); gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(action_area), new_folder_button_, TRUE); @@ -141,7 +141,7 @@ void BookmarkEditorGtk::Init(GtkWindow* parent_window) { } gtk_entry_set_text(GTK_ENTRY(name_entry_), title.c_str()); g_signal_connect(name_entry_, "changed", - G_CALLBACK(OnEntryChanged), this); + G_CALLBACK(OnEntryChangedThunk), this); gtk_entry_set_activates_default(GTK_ENTRY(name_entry_), TRUE); GtkWidget* table; @@ -152,7 +152,7 @@ void BookmarkEditorGtk::Init(GtkWindow* parent_window) { url_spec = details_.existing_node->GetURL().spec(); gtk_entry_set_text(GTK_ENTRY(url_entry_), url_spec.c_str()); g_signal_connect(url_entry_, "changed", - G_CALLBACK(OnEntryChanged), this); + G_CALLBACK(OnEntryChangedThunk), this); gtk_entry_set_activates_default(GTK_ENTRY(url_entry_), TRUE); table = gtk_util::CreateLabeledControlsGroup(NULL, l10n_util::GetStringUTF8(IDS_BOOMARK_EDITOR_NAME_LABEL).c_str(), @@ -210,22 +210,22 @@ void BookmarkEditorGtk::Init(GtkWindow* parent_window) { gtk_box_pack_start(GTK_BOX(vbox), scroll_window, TRUE, TRUE, 0); g_signal_connect(gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view_)), - "changed", G_CALLBACK(OnSelectionChanged), this); + "changed", G_CALLBACK(OnSelectionChangedThunk), this); } gtk_box_pack_start(GTK_BOX(content_area), vbox, TRUE, TRUE, 0); g_signal_connect(dialog_, "response", - G_CALLBACK(OnResponse), this); + G_CALLBACK(OnResponseThunk), this); g_signal_connect(dialog_, "delete-event", - G_CALLBACK(OnWindowDeleteEvent), this); + G_CALLBACK(OnWindowDeleteEventThunk), this); g_signal_connect(dialog_, "destroy", - G_CALLBACK(OnWindowDestroy), this); + G_CALLBACK(OnWindowDestroyThunk), this); } void BookmarkEditorGtk::Show() { // Manually call our OnEntryChanged handler to set the initial state. - OnEntryChanged(NULL, this); + OnEntryChanged(NULL); gtk_widget_show_all(dialog_); } @@ -347,30 +347,23 @@ void BookmarkEditorGtk::AddNewGroup(GtkTreeIter* parent, GtkTreeIter* child) { -1); } -// static -void BookmarkEditorGtk::OnSelectionChanged(GtkTreeSelection* selection, - BookmarkEditorGtk* dialog) { - if (!gtk_tree_selection_get_selected(dialog->tree_selection_, NULL, NULL)) - gtk_widget_set_sensitive(dialog->new_folder_button_, FALSE); +void BookmarkEditorGtk::OnSelectionChanged(GtkWidget* selection) { + if (!gtk_tree_selection_get_selected(tree_selection_, NULL, NULL)) + gtk_widget_set_sensitive(new_folder_button_, FALSE); else - gtk_widget_set_sensitive(dialog->new_folder_button_, TRUE); + gtk_widget_set_sensitive(new_folder_button_, TRUE); } -// static -void BookmarkEditorGtk::OnResponse(GtkDialog* dialog, int response_id, - BookmarkEditorGtk* window) { +void BookmarkEditorGtk::OnResponse(GtkWidget* dialog, int response_id) { if (response_id == GTK_RESPONSE_ACCEPT) - window->ApplyEdits(); + ApplyEdits(); - window->Close(); + Close(); } -// static -gboolean BookmarkEditorGtk::OnWindowDeleteEvent( - GtkWidget* widget, - GdkEvent* event, - BookmarkEditorGtk* dialog) { - dialog->Close(); +gboolean BookmarkEditorGtk::OnWindowDeleteEvent(GtkWidget* widget, + GdkEvent* event) { + Close(); // Return true to prevent the gtk dialog from being destroyed. Close will // destroy it for us and the default gtk_dialog_delete_event_handler() will @@ -378,45 +371,39 @@ gboolean BookmarkEditorGtk::OnWindowDeleteEvent( return TRUE; } -// static -void BookmarkEditorGtk::OnWindowDestroy(GtkWidget* widget, - BookmarkEditorGtk* dialog) { - MessageLoop::current()->DeleteSoon(FROM_HERE, dialog); +void BookmarkEditorGtk::OnWindowDestroy(GtkWidget* widget) { + MessageLoop::current()->DeleteSoon(FROM_HERE, this); } -// static -void BookmarkEditorGtk::OnEntryChanged(GtkEditable* entry, - BookmarkEditorGtk* dialog) { +void BookmarkEditorGtk::OnEntryChanged(GtkWidget* entry) { gboolean can_close = TRUE; - if (dialog->details_.type == EditDetails::NEW_FOLDER) { - if (dialog->GetInputTitle().empty()) { - gtk_widget_modify_base(dialog->name_entry_, GTK_STATE_NORMAL, + if (details_.type == EditDetails::NEW_FOLDER) { + if (GetInputTitle().empty()) { + gtk_widget_modify_base(name_entry_, GTK_STATE_NORMAL, &kErrorColor); can_close = FALSE; } else { - gtk_widget_modify_base(dialog->name_entry_, GTK_STATE_NORMAL, NULL); + gtk_widget_modify_base(name_entry_, GTK_STATE_NORMAL, NULL); } } else { - GURL url(dialog->GetInputURL()); + GURL url(GetInputURL()); if (!url.is_valid()) { - gtk_widget_modify_base(dialog->url_entry_, GTK_STATE_NORMAL, + gtk_widget_modify_base(url_entry_, GTK_STATE_NORMAL, &kErrorColor); can_close = FALSE; } else { - gtk_widget_modify_base(dialog->url_entry_, GTK_STATE_NORMAL, NULL); + gtk_widget_modify_base(url_entry_, GTK_STATE_NORMAL, NULL); } } - gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog->dialog_), + gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT, can_close); } -// static -void BookmarkEditorGtk::OnNewFolderClicked(GtkWidget* button, - BookmarkEditorGtk* dialog) { +void BookmarkEditorGtk::OnNewFolderClicked(GtkWidget* button) { // TODO(erg): Make the inserted item here editable and edit it. If that's // impossible (it's probably possible), fall back on the folder editor. GtkTreeIter iter; - if (!gtk_tree_selection_get_selected(dialog->tree_selection_, + if (!gtk_tree_selection_get_selected(tree_selection_, NULL, &iter)) { NOTREACHED() << "Something should always be selected if New Folder " << @@ -425,15 +412,15 @@ void BookmarkEditorGtk::OnNewFolderClicked(GtkWidget* button, } GtkTreeIter new_item_iter; - dialog->AddNewGroup(&iter, &new_item_iter); + AddNewGroup(&iter, &new_item_iter); GtkTreePath* path = gtk_tree_model_get_path( - GTK_TREE_MODEL(dialog->tree_store_), &new_item_iter); - gtk_tree_view_expand_to_path(GTK_TREE_VIEW(dialog->tree_view_), path); + GTK_TREE_MODEL(tree_store_), &new_item_iter); + gtk_tree_view_expand_to_path(GTK_TREE_VIEW(tree_view_), path); // Make the folder name editable. - gtk_tree_view_set_cursor(GTK_TREE_VIEW(dialog->tree_view_), path, - gtk_tree_view_get_column(GTK_TREE_VIEW(dialog->tree_view_), 0), + gtk_tree_view_set_cursor(GTK_TREE_VIEW(tree_view_), path, + gtk_tree_view_get_column(GTK_TREE_VIEW(tree_view_), 0), TRUE); gtk_tree_path_free(path); diff --git a/chrome/browser/gtk/bookmark_editor_gtk.h b/chrome/browser/gtk/bookmark_editor_gtk.h index d2ab6eb..671bc6d 100644 --- a/chrome/browser/gtk/bookmark_editor_gtk.h +++ b/chrome/browser/gtk/bookmark_editor_gtk.h @@ -12,6 +12,7 @@ #include "base/scoped_ptr.h" #include "chrome/browser/bookmarks/bookmark_editor.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" +#include "chrome/common/gtk_signal.h" #include "testing/gtest/include/gtest/gtest_prod.h" class GURL; @@ -90,20 +91,15 @@ class BookmarkEditorGtk : public BookmarkEditor, // new group. void AddNewGroup(GtkTreeIter* parent, GtkTreeIter* child); - static void OnSelectionChanged(GtkTreeSelection* treeselection, - BookmarkEditorGtk* dialog); + CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnSelectionChanged); + CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, void, OnResponse, int); + CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnWindowDeleteEvent, + GdkEvent*); - static void OnResponse(GtkDialog* dialog, int response_id, - BookmarkEditorGtk* window); + CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnWindowDestroy); + CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnEntryChanged); - static gboolean OnWindowDeleteEvent(GtkWidget* widget, - GdkEvent* event, - BookmarkEditorGtk* dialog); - - static void OnWindowDestroy(GtkWidget* widget, BookmarkEditorGtk* dialog); - static void OnEntryChanged(GtkEditable* entry, BookmarkEditorGtk* dialog); - - static void OnNewFolderClicked(GtkWidget* button, BookmarkEditorGtk* dialog); + CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnNewFolderClicked); // Profile the entry is from. Profile* profile_; diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 403e38e..8650770 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -139,7 +139,7 @@ void BrowserToolbarGtk::Init(Profile* profile, alignment_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); UpdateForBookmarkBarVisibility(false); g_signal_connect(alignment_, "expose-event", - G_CALLBACK(&OnAlignmentExpose), this); + G_CALLBACK(&OnAlignmentExposeThunk), this); gtk_container_add(GTK_CONTAINER(event_box_), alignment_); gtk_container_add(GTK_CONTAINER(alignment_), toolbar_); // Force the height of the toolbar so we get the right amount of padding @@ -155,13 +155,13 @@ void BrowserToolbarGtk::Init(Profile* profile, gtk_box_pack_start(GTK_BOX(back_forward_hbox_), back_->widget(), FALSE, FALSE, 0); g_signal_connect(back_->widget(), "clicked", - G_CALLBACK(OnButtonClick), this); + G_CALLBACK(OnButtonClickThunk), this); forward_.reset(new BackForwardButtonGtk(browser_, true)); gtk_box_pack_start(GTK_BOX(back_forward_hbox_), forward_->widget(), FALSE, FALSE, 0); g_signal_connect(forward_->widget(), "clicked", - G_CALLBACK(OnButtonClick), this); + G_CALLBACK(OnButtonClickThunk), this); gtk_box_pack_start(GTK_BOX(toolbar_), back_forward_hbox_, FALSE, FALSE, 0); reload_.reset(BuildToolbarButton(IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0, @@ -189,7 +189,7 @@ void BrowserToolbarGtk::Init(Profile* profile, gtk_box_pack_start(GTK_BOX(location_hbox), go_->widget(), FALSE, FALSE, 0); g_signal_connect(location_hbox, "expose-event", - G_CALLBACK(OnLocationHboxExpose), this); + G_CALLBACK(OnLocationHboxExposeThunk), this); gtk_box_pack_start(GTK_BOX(toolbar_), location_hbox, TRUE, TRUE, ShouldOnlyShowLocation() ? 1 : 0); @@ -490,7 +490,7 @@ CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton( gtk_widget_set_tooltip_text(button->widget(), localized_tooltip.c_str()); g_signal_connect(button->widget(), "clicked", - G_CALLBACK(OnButtonClick), this); + G_CALLBACK(OnButtonClickThunk), this); gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); return button; @@ -503,7 +503,7 @@ ToolbarStarToggleGtk* BrowserToolbarGtk::BuildStarButton( gtk_widget_set_tooltip_text(button->widget(), localized_tooltip.c_str()); g_signal_connect(button->widget(), "clicked", - G_CALLBACK(OnButtonClick), this); + G_CALLBACK(OnButtonClickThunk), this); return button; } @@ -516,7 +516,7 @@ GtkWidget* BrowserToolbarGtk::BuildToolbarMenuButton( gtk_widget_set_tooltip_text(button, localized_tooltip.c_str()); g_signal_connect(button, "button-press-event", - G_CALLBACK(OnMenuButtonPressEvent), this); + G_CALLBACK(OnMenuButtonPressEventThunk), this); GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); return button; @@ -530,7 +530,7 @@ void BrowserToolbarGtk::SetUpDragForHomeButton() { gtk_dnd_util::SetDestTargetList(home_->widget(), targets); g_signal_connect(home_->widget(), "drag-data-received", - G_CALLBACK(OnDragDataReceived), this); + G_CALLBACK(OnDragDataReceivedThunk), this); } void BrowserToolbarGtk::ChangeActiveMenu(GtkWidget* active_menu, @@ -554,12 +554,10 @@ void BrowserToolbarGtk::ChangeActiveMenu(GtkWidget* active_menu, new_menu->Popup(relevant_button, 0, timestamp); } -// static gboolean BrowserToolbarGtk::OnAlignmentExpose(GtkWidget* widget, - GdkEventExpose* e, - BrowserToolbarGtk* toolbar) { + GdkEventExpose* e) { // We don't need to render the toolbar image in GTK mode. - if (toolbar->theme_provider_->UseGtkTheme()) + if (theme_provider_->UseGtkTheme()) return FALSE; cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); @@ -567,36 +565,34 @@ gboolean BrowserToolbarGtk::OnAlignmentExpose(GtkWidget* widget, cairo_clip(cr); gfx::Point tabstrip_origin = - toolbar->window_->tabstrip()->GetTabStripOriginForWidget(widget); + window_->tabstrip()->GetTabStripOriginForWidget(widget); gtk_util::DrawThemedToolbarBackground(widget, cr, e, tabstrip_origin, - toolbar->theme_provider_); + theme_provider_); cairo_destroy(cr); return FALSE; // Allow subwidgets to paint. } -// static gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox, - GdkEventExpose* e, - BrowserToolbarGtk* toolbar) { - if (toolbar->theme_provider_->UseGtkTheme()) { + GdkEventExpose* e) { + if (theme_provider_->UseGtkTheme()) { // To get the proper look surrounding the location bar, we issue raw gtk // painting commands to the theme engine. We figure out the region from the // leftmost widget to the rightmost and then tell GTK to perform the same // drawing commands that draw a GtkEntry on that region. - GtkWidget* star = toolbar->star_->widget(); + GtkWidget* star = star_->widget(); GtkWidget* left = NULL; GtkWidget* right = NULL; - if (toolbar->ShouldOnlyShowLocation()) { + if (ShouldOnlyShowLocation()) { left = location_hbox; right = location_hbox; } else if (gtk_widget_get_direction(star) == GTK_TEXT_DIR_LTR) { - left = toolbar->star_->widget(); - right = toolbar->go_->widget(); + left = star_->widget(); + right = go_->widget(); } else { - left = toolbar->go_->widget(); - right = toolbar->star_->widget(); + left = go_->widget(); + right = star_->widget(); } GdkRectangle rec = { @@ -609,12 +605,12 @@ gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox, // Make sure our off screen entry has the correct base color if we're in // secure mode. gtk_widget_modify_base( - toolbar->offscreen_entry_.get(), GTK_STATE_NORMAL, - (toolbar->browser_->toolbar_model()->GetSchemeSecurityLevel() == + offscreen_entry_.get(), GTK_STATE_NORMAL, + (browser_->toolbar_model()->GetSchemeSecurityLevel() == ToolbarModel::SECURE) ? &kSecureColor : NULL); - gtk_util::DrawTextEntryBackground(toolbar->offscreen_entry_.get(), + gtk_util::DrawTextEntryBackground(offscreen_entry_.get(), location_hbox, &e->area, &rec); } @@ -622,17 +618,15 @@ gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox, return FALSE; } -// static -void BrowserToolbarGtk::OnButtonClick(GtkWidget* button, - BrowserToolbarGtk* toolbar) { - if ((button == toolbar->back_->widget()) || - (button == toolbar->forward_->widget())) { - toolbar->location_bar_->Revert(); +void BrowserToolbarGtk::OnButtonClick(GtkWidget* button) { + if ((button == back_->widget()) || + (button == forward_->widget())) { + location_bar_->Revert(); return; } int tag = -1; - if (button == toolbar->reload_->widget()) { + if (button == reload_->widget()) { GdkModifierType modifier_state; if (gtk_get_current_event_state(&modifier_state) && modifier_state & GDK_SHIFT_MASK) { @@ -640,40 +634,36 @@ void BrowserToolbarGtk::OnButtonClick(GtkWidget* button, } else { tag = IDC_RELOAD; } - toolbar->location_bar_->Revert(); - } else if (toolbar->home_.get() && button == toolbar->home_->widget()) { + location_bar_->Revert(); + } else if (home_.get() && button == home_->widget()) { tag = IDC_HOME; - } else if (button == toolbar->star_->widget()) { + } else if (button == star_->widget()) { tag = IDC_BOOKMARK_PAGE; } DCHECK_NE(tag, -1) << "Unexpected button click callback"; - toolbar->browser_->ExecuteCommandWithDisposition(tag, + browser_->ExecuteCommandWithDisposition(tag, gtk_util::DispositionForCurrentButtonPressEvent()); } -// static gboolean BrowserToolbarGtk::OnMenuButtonPressEvent(GtkWidget* button, - GdkEventButton* event, - BrowserToolbarGtk* toolbar) { + GdkEventButton* event) { if (event->button != 1) return FALSE; gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(button), GTK_STATE_ACTIVE); - MenuGtk* menu = button == toolbar->page_menu_button_.get() ? - toolbar->page_menu_.get() : toolbar->app_menu_.get(); + MenuGtk* menu = button == page_menu_button_.get() ? + page_menu_.get() : app_menu_.get(); menu->Popup(button, reinterpret_cast<GdkEvent*>(event)); - toolbar->menu_bar_helper_.MenuStartedShowing(button, menu->widget()); + menu_bar_helper_.MenuStartedShowing(button, menu->widget()); return TRUE; } -// static void BrowserToolbarGtk::OnDragDataReceived(GtkWidget* widget, GdkDragContext* drag_context, gint x, gint y, - GtkSelectionData* data, guint info, guint time, - BrowserToolbarGtk* toolbar) { + GtkSelectionData* data, guint info, guint time) { if (info != gtk_dnd_util::TEXT_PLAIN) { NOTIMPLEMENTED() << "Only support plain text drops for now, sorry!"; return; @@ -684,11 +674,11 @@ void BrowserToolbarGtk::OnDragDataReceived(GtkWidget* widget, return; bool url_is_newtab = url.spec() == chrome::kChromeUINewTabURL; - toolbar->profile_->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, - url_is_newtab); + profile_->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, + url_is_newtab); if (!url_is_newtab) { - toolbar->profile_->GetPrefs()->SetString(prefs::kHomePage, - UTF8ToWide(url.spec())); + profile_->GetPrefs()->SetString(prefs::kHomePage, + UTF8ToWide(url.spec())); } } diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h index 8624659..aab7041 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.h +++ b/chrome/browser/gtk/browser_toolbar_gtk.h @@ -18,6 +18,7 @@ #include "chrome/browser/page_menu_model.h" #include "chrome/browser/pref_member.h" #include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/common/gtk_signal.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/owned_widget_gtk.h" @@ -151,27 +152,22 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver, // Gtk callback for the "expose-event" signal. // The alignment contains the toolbar. - static gboolean OnAlignmentExpose(GtkWidget* widget, GdkEventExpose* e, - BrowserToolbarGtk* toolbar); - static gboolean OnLocationHboxExpose(GtkWidget* omnibox_hbox, - GdkEventExpose* e, - BrowserToolbarGtk* toolbar); + CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnAlignmentExpose, + GdkEventExpose*); + CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnLocationHboxExpose, + GdkEventExpose*); // Gtk callback for the "clicked" signal. - static void OnButtonClick(GtkWidget* button, BrowserToolbarGtk* toolbar); + CHROMEGTK_CALLBACK_0(BrowserToolbarGtk, void, OnButtonClick); // Gtk callback to intercept mouse clicks to the menu buttons. - static gboolean OnMenuButtonPressEvent(GtkWidget* button, - GdkEventButton* event, - BrowserToolbarGtk* toolbar); + CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnMenuButtonPressEvent, + GdkEventButton*); // Used for drags onto home button. - static void OnDragDataReceived(GtkWidget* widget, - GdkDragContext* drag_context, - gint x, gint y, - GtkSelectionData* data, - guint info, guint time, - BrowserToolbarGtk* toolbar); + CHROMEGTK_CALLBACK_6(BrowserToolbarGtk, void, OnDragDataReceived, + GdkDragContext*, gint, gint, GtkSelectionData*, + guint, guint); // ProfileSyncServiceObserver method. virtual void OnStateChanged(); diff --git a/chrome/browser/gtk/download_in_progress_dialog_gtk.cc b/chrome/browser/gtk/download_in_progress_dialog_gtk.cc index 3c81df1..8ee6b30 100644 --- a/chrome/browser/gtk/download_in_progress_dialog_gtk.cc +++ b/chrome/browser/gtk/download_in_progress_dialog_gtk.cc @@ -69,16 +69,14 @@ DownloadInProgressDialogGtk::DownloadInProgressDialogGtk(Browser* browser) "%s", explanation_text.c_str()); - g_signal_connect(dialog, "response", G_CALLBACK(OnResponse), this); + g_signal_connect(dialog, "response", G_CALLBACK(OnResponseThunk), this); gtk_widget_show_all(dialog); } -void DownloadInProgressDialogGtk::OnResponse( - GtkWidget* widget, - int response, - DownloadInProgressDialogGtk* dialog) { +void DownloadInProgressDialogGtk::OnResponse(GtkWidget* widget, + int response) { gtk_widget_destroy(widget); - dialog->browser_->InProgressDownloadResponse(response == GTK_RESPONSE_ACCEPT); - delete dialog; + browser_->InProgressDownloadResponse(response == GTK_RESPONSE_ACCEPT); + delete this; } diff --git a/chrome/browser/gtk/download_in_progress_dialog_gtk.h b/chrome/browser/gtk/download_in_progress_dialog_gtk.h index 268a5b0..21c0eef 100644 --- a/chrome/browser/gtk/download_in_progress_dialog_gtk.h +++ b/chrome/browser/gtk/download_in_progress_dialog_gtk.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_GTK_DOWNLOAD_IN_PROGRESS_DIALOG_GTK_H_ #include "base/basictypes.h" +#include "chrome/common/gtk_signal.h" class Browser; @@ -16,8 +17,7 @@ class DownloadInProgressDialogGtk { explicit DownloadInProgressDialogGtk(Browser* browser); private: - static void OnResponse(GtkWidget* widget, int response, - DownloadInProgressDialogGtk* dialog); + CHROMEGTK_CALLBACK_1(DownloadInProgressDialogGtk, void, OnResponse, int); Browser* browser_; |