Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7841)

Unified Diff: chrome/browser/ui/views/tabs/base_tab.cc

Issue 6579050: Elides the beginning of tab titles that have common prefixes. ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Elides the beginning of tab titles that have common prefixes. ... Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/title_prefix_matcher_unittest.cc ('k') | chrome/browser/ui/views/tabs/base_tab_strip.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/tabs/base_tab.cc
===================================================================
--- chrome/browser/ui/views/tabs/base_tab.cc (revision 77820)
+++ chrome/browser/ui/views/tabs/base_tab.cc (working copy)
@@ -21,6 +21,7 @@
#include "ui/base/animation/throb_animation.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/text/text_elider.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/favicon_size.h"
@@ -442,6 +443,7 @@
void BaseTab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) {
// Paint the Title.
+ const gfx::Rect& title_bounds = GetTitleBounds();
string16 title = data().title;
if (title.empty()) {
title = data().loading ?
@@ -449,8 +451,15 @@
TabContentsWrapper::GetDefaultTitle();
} else {
Browser::FormatTitleForDisplay(&title);
+ // If we'll need to truncate, check if we should also truncate
+ // a common prefix, but only if there is enough room for it.
+ // We arbitrarily choose to request enough room for 10 average chars.
+ if (data().common_prefix_length > 0 &&
+ font_->GetExpectedTextWidth(10) < title_bounds.width() &&
+ font_->GetStringWidth(title) > title_bounds.width()) {
+ title.replace(0, data().common_prefix_length, UTF8ToUTF16(ui::kEllipsis));
+ }
}
- const gfx::Rect& title_bounds = GetTitleBounds();
canvas->DrawStringInt(title, *font_, title_color,
title_bounds.x(), title_bounds.y(),
title_bounds.width(), title_bounds.height());
« no previous file with comments | « chrome/browser/ui/title_prefix_matcher_unittest.cc ('k') | chrome/browser/ui/views/tabs/base_tab_strip.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698