From fc1accc688f7cb6a35120640aa0e02a5c9055032 Mon Sep 17 00:00:00 2001 From: "jhawkins@chromium.org" Date: Wed, 3 Jun 2009 18:39:45 +0000 Subject: Display tooltips for gtk tabs that have elided titles. BUG=none TEST=Navigate to a URL with an elided title in the tab. Hover the mouse over the tab. A tooltip should appear with the full title. Navigate to google.com and hover over the tab. A tooltip should not appear (unless the tab is small enough). Review URL: http://codereview.chromium.org/118161 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17507 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/gtk/tabs/tab_gtk.cc | 14 ++++++++++++++ chrome/browser/gtk/tabs/tab_gtk.h | 1 + chrome/browser/gtk/tabs/tab_renderer_gtk.h | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) (limited to 'chrome/browser') diff --git a/chrome/browser/gtk/tabs/tab_gtk.cc b/chrome/browser/gtk/tabs/tab_gtk.cc index 55062dc..02b1b03 100644 --- a/chrome/browser/gtk/tabs/tab_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_gtk.cc @@ -270,6 +270,20 @@ void TabGtk::CloseButtonClicked() { delegate_->CloseTab(this); } +void TabGtk::UpdateData(TabContents* contents, bool loading_only) { + TabRendererGtk::UpdateData(contents, loading_only); + std::wstring title = GetTitle(); + if (!title.empty()) { + // Only show the tooltip if the title is truncated. + gfx::Font font; + if (font.GetStringWidth(title) > title_bounds().width()) { + gtk_widget_set_tooltip_text(widget(), WideToUTF8(title).c_str()); + } else { + gtk_widget_set_has_tooltip(widget(), FALSE); + } + } +} + /////////////////////////////////////////////////////////////////////////////// // TabGtk, private: diff --git a/chrome/browser/gtk/tabs/tab_gtk.h b/chrome/browser/gtk/tabs/tab_gtk.h index 6e2296e..195d04c 100644 --- a/chrome/browser/gtk/tabs/tab_gtk.h +++ b/chrome/browser/gtk/tabs/tab_gtk.h @@ -81,6 +81,7 @@ class TabGtk : public TabRendererGtk { virtual bool IsVisible() const; virtual void SetVisible(bool visible) const; virtual void CloseButtonClicked(); + virtual void UpdateData(TabContents* contents, bool loading_only); // The callback that is called for every gdk event. We use it to inspect for // drag-motion events when the drag is outside of the source tab. diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.h b/chrome/browser/gtk/tabs/tab_renderer_gtk.h index 2cff947..4f555a1 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.h +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.h @@ -77,7 +77,7 @@ class TabRendererGtk : public AnimationDelegate { // TabContents. If only the loading state was updated, the loading_only flag // should be specified. If other things change, set this flag to false to // update everything. - void UpdateData(TabContents* contents, bool loading_only); + virtual void UpdateData(TabContents* contents, bool loading_only); // Updates the display to reflect the contents of this TabRenderer's model. void UpdateFromModel(); -- cgit v1.1