diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 01:16:27 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-03 01:16:27 +0000 |
commit | 993e6ea820a8b71c8f7767822de3b66bd2bb3c6f (patch) | |
tree | 89d2c2041a191dff5364604765e2cc89509d7126 | |
parent | 0a49fa28ef184ad40c406368d23c8079a34cd251 (diff) | |
download | chromium_src-993e6ea820a8b71c8f7767822de3b66bd2bb3c6f.zip chromium_src-993e6ea820a8b71c8f7767822de3b66bd2bb3c6f.tar.gz chromium_src-993e6ea820a8b71c8f7767822de3b66bd2bb3c6f.tar.bz2 |
GTK: fix some memory leaks, streamline a common operation.
BUG=none
TEST=trybots
Review URL: http://codereview.chromium.org/562019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37921 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/gtk/back_forward_button_gtk.cc | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 11 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_titlebar.cc | 9 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 3 | ||||
-rw-r--r-- | chrome/browser/gtk/go_button_gtk.cc | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/infobar_gtk.cc | 10 | ||||
-rw-r--r-- | chrome/common/gtk_util.cc | 12 | ||||
-rw-r--r-- | chrome/common/gtk_util.h | 5 |
8 files changed, 30 insertions, 28 deletions
diff --git a/chrome/browser/gtk/back_forward_button_gtk.cc b/chrome/browser/gtk/back_forward_button_gtk.cc index e58ede15..fb16d9f 100644 --- a/chrome/browser/gtk/back_forward_button_gtk.cc +++ b/chrome/browser/gtk/back_forward_button_gtk.cc @@ -100,12 +100,10 @@ void BackForwardButtonGtk::ShowBackForwardMenu() { void BackForwardButtonGtk::OnClick(GtkWidget* widget, BackForwardButtonGtk* button) { button->show_menu_factory_.RevokeAll(); - GdkEventButton* event = - reinterpret_cast<GdkEventButton*>(gtk_get_current_event()); button->browser_->ExecuteCommandWithDisposition( button->is_forward_ ? IDC_FORWARD : IDC_BACK, - event_utils::DispositionFromEventFlags(event->state)); + gtk_util::DispositionForCurrentButtonPressEvent()); } // static diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index f1a60c5..e35509e 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -959,12 +959,9 @@ void BookmarkBarGtk::OnClicked(GtkWidget* sender, DCHECK(node->is_url()); DCHECK(bar->page_navigator_); - GdkEventButton* event = - reinterpret_cast<GdkEventButton*>(gtk_get_current_event()); - bar->page_navigator_->OpenURL( node->GetURL(), GURL(), - event_utils::DispositionFromEventFlags(event->state), + gtk_util::DispositionForCurrentButtonPressEvent(), PageTransition::AUTO_BOOKMARK); UserMetrics::RecordAction("ClickedBookmarkBarURLButton", bar->profile_); @@ -1330,9 +1327,9 @@ void BookmarkBarGtk::PopupForButton(GtkWidget* button) { first_hidden : 0, false)); menu_bar_helper_.MenuStartedShowing(button, current_menu_->widget()); - GdkEventButton* event = - reinterpret_cast<GdkEventButton*>(gtk_get_current_event()); - current_menu_->Popup(button, event->button, event->time); + GdkEvent* event = gtk_get_current_event(); + current_menu_->Popup(button, event->button.button, event->button.time); + gdk_event_free(event); } void BookmarkBarGtk::PopupForButtonNextTo(GtkWidget* button, diff --git a/chrome/browser/gtk/browser_titlebar.cc b/chrome/browser/gtk/browser_titlebar.cc index 95f5a25..7ff717f 100644 --- a/chrome/browser/gtk/browser_titlebar.cc +++ b/chrome/browser/gtk/browser_titlebar.cc @@ -460,8 +460,8 @@ void BrowserTitlebar::ShowFaviconMenu(GdkEventButton* event) { } void BrowserTitlebar::MaximizeButtonClicked() { - GdkEventButton* event = >k_get_current_event()->button; - if (event->button == 1) { + GdkEvent* event = gtk_get_current_event(); + if (event->button.button == 1) { gtk_window_maximize(window_); } else { GtkWidget* widget = GTK_WIDGET(window_); @@ -475,16 +475,17 @@ void BrowserTitlebar::MaximizeButtonClicked() { gint width = widget->allocation.width; gint height = widget->allocation.height; - if (event->button == 3) { + if (event->button.button == 3) { x = 0; width = screen_rect.width; - } else if (event->button == 2) { + } else if (event->button.button == 2) { y = 0; height = screen_rect.height; } browser_window_->SetBounds(gfx::Rect(x, y, width, height)); } + gdk_event_free(event); } // static diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index 4a97b98..4652097 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -632,8 +632,7 @@ void BrowserToolbarGtk::OnButtonClick(GtkWidget* button, DCHECK_NE(tag, -1) << "Unexpected button click callback"; toolbar->browser_->ExecuteCommandWithDisposition(tag, - event_utils::DispositionFromEventFlags( - reinterpret_cast<GdkEventButton*>(gtk_get_current_event())->state)); + gtk_util::DispositionForCurrentButtonPressEvent()); } // static diff --git a/chrome/browser/gtk/go_button_gtk.cc b/chrome/browser/gtk/go_button_gtk.cc index 03bc77f..c865c36 100644 --- a/chrome/browser/gtk/go_button_gtk.cc +++ b/chrome/browser/gtk/go_button_gtk.cc @@ -153,11 +153,9 @@ gboolean GoButtonGtk::OnClicked(GtkButton* widget, GoButtonGtk* button) { button->ChangeMode(MODE_GO, true); } else if (button->visible_mode_ == MODE_GO && button->stop_timer_.empty()) { // If the go button is visible and not within the double click timer, go. - GdkEventButton* event = - reinterpret_cast<GdkEventButton*>(gtk_get_current_event()); if (button->browser_) { button->browser_->ExecuteCommandWithDisposition(IDC_GO, - event_utils::DispositionFromEventFlags(event->state)); + gtk_util::DispositionForCurrentButtonPressEvent()); } // Figure out the system double-click time. diff --git a/chrome/browser/gtk/infobar_gtk.cc b/chrome/browser/gtk/infobar_gtk.cc index 8626c78..859984f 100644 --- a/chrome/browser/gtk/infobar_gtk.cc +++ b/chrome/browser/gtk/infobar_gtk.cc @@ -257,16 +257,8 @@ class LinkInfoBar : public InfoBar { private: static void OnLinkClick(GtkWidget* button, LinkInfoBar* link_info_bar) { - const GdkEventButton* button_click_event = - reinterpret_cast<GdkEventButton*>(gtk_get_current_event()); - WindowOpenDisposition disposition = CURRENT_TAB; - if (button_click_event) { - disposition = event_utils::DispositionFromEventFlags( - button_click_event->state); - } - if (link_info_bar->delegate_->AsLinkInfoBarDelegate()-> - LinkClicked(disposition)) { + LinkClicked(gtk_util::DispositionForCurrentButtonPressEvent())) { link_info_bar->RemoveInfoBar(); } } diff --git a/chrome/common/gtk_util.cc b/chrome/common/gtk_util.cc index 37fb13e..b8e7aeb 100644 --- a/chrome/common/gtk_util.cc +++ b/chrome/common/gtk_util.cc @@ -692,4 +692,16 @@ void WrapLabelAtAllocationHack(GtkWidget* label) { G_CALLBACK(OnLabelAllocate), NULL); } +WindowOpenDisposition DispositionForCurrentButtonPressEvent() { + GdkEvent* event = gtk_get_current_event(); + if (!event) { + NOTREACHED(); + return NEW_FOREGROUND_TAB; + } + + guint state = event->button.state; + gdk_event_free(event); + return event_utils::DispositionFromEventFlags(state); +} + } // namespace gtk_util diff --git a/chrome/common/gtk_util.h b/chrome/common/gtk_util.h index c13b904..149253b 100644 --- a/chrome/common/gtk_util.h +++ b/chrome/common/gtk_util.h @@ -242,6 +242,11 @@ void SuppressDefaultPainting(GtkWidget* container); // proper width. void WrapLabelAtAllocationHack(GtkWidget* label); +// Get the window open disposition from the state in gtk_get_current_event(). +// This is designed to be called inside a "clicked" event handler. It is an +// error to call it when gtk_get_current_event() won't return a GdkEventButton*. +WindowOpenDisposition DispositionForCurrentButtonPressEvent(); + } // namespace gtk_util #endif // CHROME_COMMON_GTK_UTIL_H_ |