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

Side by Side 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, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/extensions/icon_with_badge_image_source.h" 5 #include "chrome/browser/ui/extensions/icon_with_badge_image_source.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 background_color = badge_->background_color; 173 background_color = badge_->background_color;
174 174
175 canvas->Save(); 175 canvas->Save();
176 176
177 SkPaint* text_paint = nullptr; 177 SkPaint* text_paint = nullptr;
178 int text_width = 0; 178 int text_width = 0;
179 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); 179 ResourceBundle* rb = &ResourceBundle::GetSharedInstance();
180 gfx::FontList base_font = rb->GetFontList(ResourceBundle::BaseFont) 180 gfx::FontList base_font = rb->GetFontList(ResourceBundle::BaseFont)
181 .DeriveWithHeightUpperBound(kBadgeHeight); 181 .DeriveWithHeightUpperBound(kBadgeHeight);
182 base::string16 utf16_text = base::UTF8ToUTF16(badge_->text); 182 base::string16 utf16_text = base::UTF8ToUTF16(badge_->text);
183
184 // See if we can squeeze a slightly larger font into the badge given the
185 // actual string that is to be displayed.
186 const int kMaxIncrementAttempts = 5;
187 for (size_t i = 0; i < kMaxIncrementAttempts; ++i) {
188 int w = 0;
189 int h = 0;
190 gfx::FontList bigger_font = base_font.Derive(1, 0);
191 gfx::Canvas::SizeStringInt(utf16_text, bigger_font, &w, &h, 0,
192 gfx::Canvas::NO_ELLIPSIS);
193 if (h > kBadgeHeight)
194 break;
195 base_font = bigger_font;
196 }
197
183 if (ui::MaterialDesignController::IsModeMaterial()) { 198 if (ui::MaterialDesignController::IsModeMaterial()) {
184 text_width = 199 text_width =
185 std::min(kMaxTextWidth, canvas->GetStringWidth(utf16_text, base_font)); 200 std::min(kMaxTextWidth, canvas->GetStringWidth(utf16_text, base_font));
186 } else { 201 } else {
187 text_paint = GetBadgeTextPaintSingleton(); 202 text_paint = GetBadgeTextPaintSingleton();
188 text_paint->setColor(text_color); 203 text_paint->setColor(text_color);
189 float scale = canvas->image_scale(); 204 float scale = canvas->image_scale();
190 205
191 // Calculate text width. Font width may not be linear with respect to the 206 // Calculate text width. Font width may not be linear with respect to the
192 // scale factor (e.g. when hinting is applied), so we need to use the font 207 // scale factor (e.g. when hinting is applied), so we need to use the font
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 305 }
291 306
292 void IconWithBadgeImageSource::PaintBlockedActionDecoration( 307 void IconWithBadgeImageSource::PaintBlockedActionDecoration(
293 gfx::Canvas* canvas) { 308 gfx::Canvas* canvas) {
294 canvas->Save(); 309 canvas->Save();
295 gfx::ImageSkia img = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 310 gfx::ImageSkia img = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
296 IDR_BLOCKED_EXTENSION_SCRIPT); 311 IDR_BLOCKED_EXTENSION_SCRIPT);
297 canvas->DrawImageInt(img, size().width() - img.width(), 0); 312 canvas->DrawImageInt(img, size().width() - img.width(), 0);
298 canvas->Restore(); 313 canvas->Restore();
299 } 314 }
OLDNEW
« 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