OLD | NEW |
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 void IconWithBadgeImageSource::SetBadge(scoped_ptr<Badge> badge) { | 123 void IconWithBadgeImageSource::SetBadge(scoped_ptr<Badge> badge) { |
124 badge_ = std::move(badge); | 124 badge_ = std::move(badge); |
125 } | 125 } |
126 | 126 |
127 void IconWithBadgeImageSource::Draw(gfx::Canvas* canvas) { | 127 void IconWithBadgeImageSource::Draw(gfx::Canvas* canvas) { |
128 if (icon_.IsEmpty()) | 128 if (icon_.IsEmpty()) |
129 return; | 129 return; |
130 | 130 |
131 gfx::ImageSkia skia = icon_.AsImageSkia(); | 131 gfx::ImageSkia skia = icon_.AsImageSkia(); |
132 // TODO(estade): Fix setIcon and enable this on !MD. | 132 gfx::ImageSkiaRep rep = skia.GetRepresentation(canvas->image_scale()); |
133 if (ui::MaterialDesignController::IsModeMaterial()) { | 133 if (rep.scale() != canvas->image_scale()) |
134 gfx::ImageSkiaRep rep = skia.GetRepresentation(canvas->image_scale()); | 134 skia.AddRepresentation(ScaleImageSkiaRep(rep, canvas->image_scale())); |
135 if (rep.scale() != canvas->image_scale()) | |
136 skia.AddRepresentation(ScaleImageSkiaRep(rep, canvas->image_scale())); | |
137 } | |
138 if (grayscale_) | 135 if (grayscale_) |
139 skia = gfx::ImageSkiaOperations::CreateHSLShiftedImage(skia, {-1, 0, 0.6}); | 136 skia = gfx::ImageSkiaOperations::CreateHSLShiftedImage(skia, {-1, 0, 0.6}); |
140 | 137 |
141 int x_offset = std::floor((size().width() - icon_.Width()) / 2.0); | 138 int x_offset = std::floor((size().width() - icon_.Width()) / 2.0); |
142 int y_offset = std::floor((size().height() - icon_.Height()) / 2.0); | 139 int y_offset = std::floor((size().height() - icon_.Height()) / 2.0); |
143 canvas->DrawImageInt(skia, x_offset, y_offset); | 140 canvas->DrawImageInt(skia, x_offset, y_offset); |
144 | 141 |
145 // Draw a badge on the provided browser action icon's canvas. | 142 // Draw a badge on the provided browser action icon's canvas. |
146 PaintBadge(canvas); | 143 PaintBadge(canvas); |
147 | 144 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 gfx::Point center_point(major_radius + 1, size().height() - (major_radius)-1); | 270 gfx::Point center_point(major_radius + 1, size().height() - (major_radius)-1); |
274 SkPaint paint; | 271 SkPaint paint; |
275 paint.setAntiAlias(true); | 272 paint.setAntiAlias(true); |
276 paint.setStyle(SkPaint::kFill_Style); | 273 paint.setStyle(SkPaint::kFill_Style); |
277 paint.setColor(SK_ColorTRANSPARENT); | 274 paint.setColor(SK_ColorTRANSPARENT); |
278 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 275 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
279 canvas->DrawCircle(center_point, major_radius, paint); | 276 canvas->DrawCircle(center_point, major_radius, paint); |
280 paint.setColor(decoration_color); | 277 paint.setColor(decoration_color); |
281 canvas->DrawCircle(center_point, minor_radius, paint); | 278 canvas->DrawCircle(center_point, minor_radius, paint); |
282 } | 279 } |
OLD | NEW |