diff options
-rw-r--r-- | chrome/browser/gtk/tabs/tab_renderer_gtk.cc | 19 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_renderer_gtk.h | 3 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.cc | 20 |
3 files changed, 35 insertions, 7 deletions
diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc index 8f6e5e4..90c2828 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc @@ -62,6 +62,16 @@ const int kCloseButtonHorzFuzz = 5; SkBitmap* crashed_fav_icon = NULL; +// Gets the bounds of |widget| relative to |parent|. +gfx::Rect GetWidgetBoundsRelativeToParent(GtkWidget* parent, + GtkWidget* widget) { + gfx::Point parent_pos = gtk_util::GetWidgetScreenPosition(parent); + gfx::Point widget_pos = gtk_util::GetWidgetScreenPosition(widget); + return gfx::Rect(widget_pos.x() - parent_pos.x(), + widget_pos.y() - parent_pos.y(), + widget->allocation.width, widget->allocation.height); +} + } // namespace TabRendererGtk::LoadingAnimation::Data::Data(ThemeProvider* theme_provider) { @@ -374,6 +384,15 @@ void TabRendererGtk::SetUnselectedTitleColor(SkColor color) { unselected_title_color_ = color; } +gfx::Rect TabRendererGtk::GetNonMirroredBounds(GtkWidget* parent) const { + // The tabstrip widget is a windowless widget so the tab widget's allocation + // is relative to the browser titlebar. We need the bounds relative to the + // tabstrip. + gfx::Rect bounds = GetWidgetBoundsRelativeToParent(parent, widget()); + bounds.set_x(gtk_util::MirroredLeftPointForRect(parent, bounds)); + return bounds; +} + void TabRendererGtk::SetBounds(const gfx::Rect& bounds) { gtk_widget_set_size_request(tab_.get(), bounds.width(), bounds.height()); } diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.h b/chrome/browser/gtk/tabs/tab_renderer_gtk.h index aec1464..5669658 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.h +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.h @@ -160,6 +160,9 @@ class TabRendererGtk : public AnimationDelegate { gfx::Rect bounds() const { return bounds_; } + // Returns the non-mirrored (LTR) bounds of this tab. + gfx::Rect GetNonMirroredBounds(GtkWidget* parent) const; + // Sets the bounds of the tab. void SetBounds(const gfx::Rect& bounds); diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index 7607cbb..27a1d02 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -1426,14 +1426,16 @@ gfx::Rect TabStripGtk::GetDropBounds(int drop_index, int center_x; if (drop_index < GetTabCount()) { TabGtk* tab = GetTabAt(drop_index); + gfx::Rect bounds = tab->GetNonMirroredBounds(tabstrip_.get()); // TODO(sky): update these for pinned tabs. if (drop_before) - center_x = tab->x() - (kTabHOffset / 2); + center_x = bounds.x() - (kTabHOffset / 2); else - center_x = tab->x() + (tab->width() / 2); + center_x = bounds.x() + (bounds.width() / 2); } else { TabGtk* last_tab = GetTabAt(drop_index - 1); - center_x = last_tab->x() + last_tab->width() + (kTabHOffset / 2); + gfx::Rect bounds = last_tab->GetNonMirroredBounds(tabstrip_.get()); + center_x = bounds.x() + bounds.width() + (kTabHOffset / 2); } center_x = gtk_util::MirroredXCoordinate(tabstrip_.get(), center_x); @@ -1455,13 +1457,17 @@ gfx::Rect TabStripGtk::GetDropBounds(int drop_index, } void TabStripGtk::UpdateDropIndex(GdkDragContext* context, gint x, gint y) { - // TODO(jhawkins): Handle RTL layout. + // If the UI layout is right-to-left, we need to mirror the mouse + // coordinates since we calculate the drop index based on the + // original (and therefore non-mirrored) positions of the tabs. + x = gtk_util::MirroredXCoordinate(tabstrip_.get(), x); for (int i = 0; i < GetTabCount(); ++i) { TabGtk* tab = GetTabAt(i); - const int tab_max_x = tab->x() + tab->width(); - const int hot_width = tab->width() / 3; + gfx::Rect bounds = tab->GetNonMirroredBounds(tabstrip_.get()); + const int tab_max_x = bounds.x() + bounds.width(); + const int hot_width = bounds.width() / 3; if (x < tab_max_x) { - if (x < tab->x() + hot_width) + if (x < bounds.x() + hot_width) SetDropIndex(i, true); else if (x >= tab_max_x - hot_width) SetDropIndex(i + 1, true); |