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

Side by Side Diff: chrome/browser/ui/extensions/icon_with_badge_image_source.cc

Issue 1580983002: Fix the dynamic browser action setIcon path to work with any size icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: twiddle constant 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 unified diff | Download patch
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 DCHECK(typeface); 83 DCHECK(typeface);
84 } 84 }
85 85
86 text_paint->setTypeface(typeface.get()); 86 text_paint->setTypeface(typeface.get());
87 // |text_paint| adds its own ref. Release the ref from CreateFontName. 87 // |text_paint| adds its own ref. Release the ref from CreateFontName.
88 } 88 }
89 return text_paint; 89 return text_paint;
90 } 90 }
91 91
92 gfx::ImageSkiaRep ScaleImageSkiaRep(const gfx::ImageSkiaRep& rep, 92 gfx::ImageSkiaRep ScaleImageSkiaRep(const gfx::ImageSkiaRep& rep,
93 int target_width,
93 float target_scale) { 94 float target_scale) {
94 gfx::Size scaled_size = 95 return gfx::ImageSkiaRep(
95 gfx::ScaleToCeiledSize(rep.pixel_size(), target_scale / rep.scale()); 96 skia::ImageOperations::Resize(rep.sk_bitmap(),
96 return gfx::ImageSkiaRep(skia::ImageOperations::Resize( 97 skia::ImageOperations::RESIZE_BEST,
97 rep.sk_bitmap(), 98 target_width, target_width),
98 skia::ImageOperations::RESIZE_BEST, 99 target_scale);
99 scaled_size.width(),
100 scaled_size.height()), target_scale);
101 } 100 }
102 101
103 } // namespace 102 } // namespace
104 103
105 IconWithBadgeImageSource::Badge::Badge(const std::string& text, 104 IconWithBadgeImageSource::Badge::Badge(const std::string& text,
106 SkColor text_color, 105 SkColor text_color,
107 SkColor background_color) 106 SkColor background_color)
108 : text(text), text_color(text_color), background_color(background_color) {} 107 : text(text), text_color(text_color), background_color(background_color) {}
109 108
110 IconWithBadgeImageSource::Badge::~Badge() {} 109 IconWithBadgeImageSource::Badge::~Badge() {}
(...skipping 11 matching lines...) Expand all
122 121
123 void IconWithBadgeImageSource::SetBadge(scoped_ptr<Badge> badge) { 122 void IconWithBadgeImageSource::SetBadge(scoped_ptr<Badge> badge) {
124 badge_ = std::move(badge); 123 badge_ = std::move(badge);
125 } 124 }
126 125
127 void IconWithBadgeImageSource::Draw(gfx::Canvas* canvas) { 126 void IconWithBadgeImageSource::Draw(gfx::Canvas* canvas) {
128 if (icon_.IsEmpty()) 127 if (icon_.IsEmpty())
129 return; 128 return;
130 129
131 gfx::ImageSkia skia = icon_.AsImageSkia(); 130 gfx::ImageSkia skia = icon_.AsImageSkia();
132 // TODO(estade): Fix setIcon and enable this on !MD. 131 gfx::ImageSkiaRep rep = skia.GetRepresentation(canvas->image_scale());
133 if (ui::MaterialDesignController::IsModeMaterial()) { 132 if (rep.scale() != canvas->image_scale()) {
134 gfx::ImageSkiaRep rep = skia.GetRepresentation(canvas->image_scale()); 133 skia.AddRepresentation(
135 if (rep.scale() != canvas->image_scale()) 134 ScaleImageSkiaRep(rep, skia.width(), canvas->image_scale()));
136 skia.AddRepresentation(ScaleImageSkiaRep(rep, canvas->image_scale()));
137 } 135 }
138 if (grayscale_) 136 if (grayscale_)
139 skia = gfx::ImageSkiaOperations::CreateHSLShiftedImage(skia, {-1, 0, 0.6}); 137 skia = gfx::ImageSkiaOperations::CreateHSLShiftedImage(skia, {-1, 0, 0.6});
140 138
141 int x_offset = std::floor((size().width() - icon_.Width()) / 2.0); 139 int x_offset = std::floor((size().width() - icon_.Width()) / 2.0);
142 int y_offset = std::floor((size().height() - icon_.Height()) / 2.0); 140 int y_offset = std::floor((size().height() - icon_.Height()) / 2.0);
143 canvas->DrawImageInt(skia, x_offset, y_offset); 141 canvas->DrawImageInt(skia, x_offset, y_offset);
144 142
145 // Draw a badge on the provided browser action icon's canvas. 143 // Draw a badge on the provided browser action icon's canvas.
146 PaintBadge(canvas); 144 PaintBadge(canvas);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 gfx::Point center_point(major_radius + 1, size().height() - (major_radius)-1); 271 gfx::Point center_point(major_radius + 1, size().height() - (major_radius)-1);
274 SkPaint paint; 272 SkPaint paint;
275 paint.setAntiAlias(true); 273 paint.setAntiAlias(true);
276 paint.setStyle(SkPaint::kFill_Style); 274 paint.setStyle(SkPaint::kFill_Style);
277 paint.setColor(SK_ColorTRANSPARENT); 275 paint.setColor(SK_ColorTRANSPARENT);
278 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 276 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
279 canvas->DrawCircle(center_point, major_radius, paint); 277 canvas->DrawCircle(center_point, major_radius, paint);
280 paint.setColor(decoration_color); 278 paint.setColor(decoration_color);
281 canvas->DrawCircle(center_point, minor_radius, paint); 279 canvas->DrawCircle(center_point, minor_radius, paint);
282 } 280 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_action.cc ('k') | chrome/browser/ui/views/toolbar/toolbar_action_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698