diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-27 20:03:59 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-27 20:03:59 +0000 |
commit | d3b2e75994860048bf89ccbfc55c5b9c8d53532d (patch) | |
tree | f1eda3b396843bfa5af85c72150a6ee1f5df67b6 /chrome/browser/gtk | |
parent | c6321d8e201af8f7b91cd0b134d4ad32844f66c1 (diff) | |
download | chromium_src-d3b2e75994860048bf89ccbfc55c5b9c8d53532d.zip chromium_src-d3b2e75994860048bf89ccbfc55c5b9c8d53532d.tar.gz chromium_src-d3b2e75994860048bf89ccbfc55c5b9c8d53532d.tar.bz2 |
Fix a few crashes when trying to drag a closing tab.
Review URL: http://codereview.chromium.org/99065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14640 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.cc | 32 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.h | 4 |
2 files changed, 32 insertions, 4 deletions
diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index e008cdb..0b917d7 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -547,6 +547,8 @@ void TabStripGtk::Init() { G_CALLBACK(&OnDragBegin), this); g_signal_connect_after(G_OBJECT(tabstrip_.get()), "drag-end", G_CALLBACK(&OnDragEnd), this); + g_signal_connect_after(G_OBJECT(tabstrip_.get()), "drag-failed", + G_CALLBACK(&OnDragFailed), this); g_signal_connect_after(G_OBJECT(tabstrip_.get()), "drag-motion", G_CALLBACK(&OnDragMotion), this); gtk_widget_add_events(tabstrip_.get(), @@ -1194,9 +1196,11 @@ gboolean TabStripGtk::OnMousePress(GtkWidget* widget, GdkEventButton* event, return TRUE; } - if (tabstrip->GetTabAt(tabstrip->hover_index_)->OnMousePress(point)) { + TabGtk* tab = tabstrip->GetTabAt(tabstrip->hover_index_); + if (tab->OnMousePress(point)) { gtk_widget_queue_draw(tabstrip->tabstrip_.get()); - } else if (tabstrip->hover_index_ != tabstrip->model()->selected_index()) { + } else if (tabstrip->hover_index_ != tabstrip->model()->selected_index() && + !tab->closing()) { tabstrip->model()->SelectTabContentsAt(tabstrip->hover_index_, true); } @@ -1269,8 +1273,12 @@ gboolean TabStripGtk::OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event, // static void TabStripGtk::OnDragBegin(GtkWidget* widget, GdkDragContext* context, TabStripGtk* tabstrip) { - if (tabstrip->hover_index_ == -1) + // No dragging should happen if the tab is closing. + if (tabstrip->hover_index_ == -1 || + tabstrip->GetTabAt(tabstrip->hover_index_)->closing()) { + gdk_drop_finish(context, FALSE, 0); return; + } // If we're in the middle of a snap animation, stop the animation. We only // set the snap bounds if the tab is snapped into a proper index, which is not @@ -1288,9 +1296,20 @@ void TabStripGtk::OnDragBegin(GtkWidget* widget, GdkDragContext* context, // static void TabStripGtk::OnDragEnd(GtkWidget* widget, GdkDragContext* context, TabStripGtk* tabstrip) { - tabstrip->StartSnapTabAnimation(tabstrip->snap_bounds_); + if (tabstrip->is_dragging_) { + tabstrip->StartSnapTabAnimation(tabstrip->snap_bounds_); + tabstrip->mouse_offset_ = gfx::Point(-1, -1); + tabstrip->is_dragging_ = false; + } +} + +// static +gboolean TabStripGtk::OnDragFailed(GtkWidget* widget, GdkDragContext* context, + GtkDragResult result, + TabStripGtk* tabstrip) { tabstrip->mouse_offset_ = gfx::Point(-1, -1); tabstrip->is_dragging_ = false; + return TRUE; } // static @@ -1299,6 +1318,11 @@ gboolean TabStripGtk::OnDragMotion(GtkWidget* widget, guint x, guint y, guint time, TabStripGtk* tabstrip) { + // gtk sends drag-motion signals even after the drag has failed, but before + // the drag-end signal is emitted. + if (!tabstrip->is_dragging_) + return TRUE; + TabGtk* tab = tabstrip->GetTabAt(tabstrip->hover_index_); gfx::Rect bounds = tab->bounds(); diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.h b/chrome/browser/gtk/tabs/tab_strip_gtk.h index 56e74d7..325c2f4 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.h +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.h @@ -134,6 +134,10 @@ class TabStripGtk : public TabStripModelObserver, guint x, guint y, guint time, TabStripGtk* tabstrip); + // drag-failed handler that is emitted when the drag fails. + static gboolean OnDragFailed(GtkWidget* widget, GdkDragContext* context, + GtkDragResult result, TabStripGtk* tabstrip); + // Finds the tab that is under |point| by iterating through all of the tabs // and checking if |point| is in their bounds. This method is only used when // the state of all the tabs cannot be calculated, as during a SnapTab |