diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-24 21:24:53 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-24 21:24:53 +0000 |
commit | 1302ece5eab6d9fefbf274f33dd61797e8ab5f69 (patch) | |
tree | 13207e51ce1eaa18f2eef3709816edb7946a7057 | |
parent | f6422553a95c2548f4eda8eb56cef5c6fa1cb55b (diff) | |
download | chromium_src-1302ece5eab6d9fefbf274f33dd61797e8ab5f69.zip chromium_src-1302ece5eab6d9fefbf274f33dd61797e8ab5f69.tar.gz chromium_src-1302ece5eab6d9fefbf274f33dd61797e8ab5f69.tar.bz2 |
gtk: Clip the cairo context to the extents provided to the DrawStringInt function. This fixes an issue when rendering the tab title where the ellipses are rendered no matter how small the tab is sized. This change also fixes an issue where we were using the default font to determine whether to show the tooltip.
BUG=19741
TEST=Open many tabs. See that the ellipses should disappear when there's no room left in the tab to display them.
Review URL: http://codereview.chromium.org/173300
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24149 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | app/gfx/canvas_linux.cc | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_gtk.cc | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_renderer_gtk.h | 2 |
3 files changed, 13 insertions, 4 deletions
diff --git a/app/gfx/canvas_linux.cc b/app/gfx/canvas_linux.cc index d1d391b..5d644ad 100644 --- a/app/gfx/canvas_linux.cc +++ b/app/gfx/canvas_linux.cc @@ -196,6 +196,7 @@ void Canvas::DrawStringInt(const std::wstring& text, pango_layout_set_width(layout, w * PANGO_SCALE); pango_layout_set_height(layout, h * PANGO_SCALE); + cairo_save(cr); cairo_set_source_rgb(cr, SkColorGetR(color) / 255.0, SkColorGetG(color) / 255.0, @@ -217,7 +218,13 @@ void Canvas::DrawStringInt(const std::wstring& text, } cairo_move_to(cr, x, y); + cairo_rectangle(cr, x, y, x + w, y + h); + // We use cairo_clip_preserve so that we can reset the clip region with + // cairo_restore; otherwise, any further drawing operations on this context + // will be clipped to this region. + cairo_clip_preserve(cr); pango_cairo_show_layout(cr, layout); + cairo_restore(cr); g_object_unref(layout); // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. diff --git a/chrome/browser/gtk/tabs/tab_gtk.cc b/chrome/browser/gtk/tabs/tab_gtk.cc index 547c655..ee7789a 100644 --- a/chrome/browser/gtk/tabs/tab_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_gtk.cc @@ -24,10 +24,10 @@ void SetEmptyDragIcon(GtkWidget* widget) { } // Returns the width of the title for the current font, in pixels. -int GetTitleWidth(std::wstring title) { +int GetTitleWidth(gfx::Font* font, std::wstring title) { + DCHECK(font); if (!title.empty()) { - gfx::Font font; - return font.GetStringWidth(title); + return font->GetStringWidth(title); } return 0; } @@ -290,7 +290,7 @@ void TabGtk::UpdateData(TabContents* contents, bool loading_only) { TabRendererGtk::UpdateData(contents, loading_only); // Cache the title width so we don't recalculate it every time the tab is // resized. - title_width_ = GetTitleWidth(GetTitle()); + title_width_ = GetTitleWidth(title_font(), GetTitle()); UpdateTooltipState(); } diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.h b/chrome/browser/gtk/tabs/tab_renderer_gtk.h index b996f5d..7029f7e 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.h +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.h @@ -157,6 +157,8 @@ class TabRendererGtk : public AnimationDelegate { static void SetSelectedTitleColor(SkColor color); static void SetUnselectedTitleColor(SkColor color); + static gfx::Font* title_font() { return title_font_; } + // Returns the bounds of the Tab. int x() const { return bounds_.x(); } int y() const { return bounds_.y(); } |