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

Unified Diff: chrome/browser/ui/extensions/icon_with_badge_image_source.cc

Issue 2012313002: Use a larger font in the extension badge when possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix failure to revert Created 4 years, 7 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/extensions/icon_with_badge_image_source.cc
diff --git a/chrome/browser/ui/extensions/icon_with_badge_image_source.cc b/chrome/browser/ui/extensions/icon_with_badge_image_source.cc
index a1ed4b846515cf55a16466d1dd0c86d736a37a66..2e01d6755fb3521b36e003e5baace866e009545e 100644
--- a/chrome/browser/ui/extensions/icon_with_badge_image_source.cc
+++ b/chrome/browser/ui/extensions/icon_with_badge_image_source.cc
@@ -180,6 +180,21 @@ void IconWithBadgeImageSource::PaintBadge(gfx::Canvas* canvas) {
gfx::FontList base_font = rb->GetFontList(ResourceBundle::BaseFont)
.DeriveWithHeightUpperBound(kBadgeHeight);
base::string16 utf16_text = base::UTF8ToUTF16(badge_->text);
+
+ // See if we can squeeze a slightly larger font into the badge given the
+ // actual string that is to be displayed.
+ const int kMaxIncrementAttempts = 5;
+ for (size_t i = 0; i < kMaxIncrementAttempts; ++i) {
+ int w = 0;
+ int h = 0;
+ gfx::FontList bigger_font = base_font.Derive(1, 0);
+ gfx::Canvas::SizeStringInt(utf16_text, bigger_font, &w, &h, 0,
+ gfx::Canvas::NO_ELLIPSIS);
+ if (h > kBadgeHeight)
+ break;
+ base_font = bigger_font;
+ }
+
if (ui::MaterialDesignController::IsModeMaterial()) {
text_width =
std::min(kMaxTextWidth, canvas->GetStringWidth(utf16_text, base_font));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698