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

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

Issue 1572773002: Use better algorithm to scale browser action icons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: just on md Created 4 years, 11 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 014d9f77c2eac17d3857caa3349a67f3f17faf21..322dcce754393993d52697e5b51d0e816e847550 100644
--- a/chrome/browser/ui/extensions/icon_with_badge_image_source.cc
+++ b/chrome/browser/ui/extensions/icon_with_badge_image_source.cc
@@ -89,6 +89,17 @@ SkPaint* GetBadgeTextPaintSingleton() {
return text_paint;
}
+gfx::ImageSkiaRep ScaleImageSkiaRep(const gfx::ImageSkiaRep& rep,
+ float target_scale) {
+ gfx::Size scaled_size =
+ gfx::ScaleToCeiledSize(rep.pixel_size(), target_scale / rep.scale());
+ return gfx::ImageSkiaRep(skia::ImageOperations::Resize(
+ rep.sk_bitmap(),
+ skia::ImageOperations::RESIZE_BEST,
+ scaled_size.width(),
+ scaled_size.height()), target_scale);
+}
+
} // namespace
IconWithBadgeImageSource::Badge::Badge(const std::string& text,
@@ -117,11 +128,18 @@ void IconWithBadgeImageSource::Draw(gfx::Canvas* canvas) {
if (icon_.IsEmpty())
return;
- int x_offset = std::floor((size().width() - icon_.Width()) / 2.0);
- int y_offset = std::floor((size().height() - icon_.Height()) / 2.0);
gfx::ImageSkia skia = icon_.AsImageSkia();
+ // TODO(estade): Fix setIcon and enable this on !MD.
+ if (ui::MaterialDesignController::IsModeMaterial()) {
+ gfx::ImageSkiaRep rep = skia.GetRepresentation(canvas->image_scale());
+ if (rep.scale() != canvas->image_scale())
+ skia.AddRepresentation(ScaleImageSkiaRep(rep, canvas->image_scale()));
+ }
if (grayscale_)
skia = gfx::ImageSkiaOperations::CreateHSLShiftedImage(skia, {-1, 0, 0.6});
+
+ int x_offset = std::floor((size().width() - icon_.Width()) / 2.0);
+ int y_offset = std::floor((size().height() - icon_.Height()) / 2.0);
canvas->DrawImageInt(skia, x_offset, y_offset);
// Draw a badge on the provided browser action icon's canvas.
« 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