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

Unified Diff: ui/gfx/paint_vector_icon.cc

Issue 2892563004: Use animated vector icon for app menu notification animation. (Closed)
Patch Set: git add Created 3 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
Index: ui/gfx/paint_vector_icon.cc
diff --git a/ui/gfx/paint_vector_icon.cc b/ui/gfx/paint_vector_icon.cc
index 49063b67ab8f62e1a55ffab25e1f3b63204405a1..58d56d843e082f4ae0b4f16487e8e8d5bc9a9834 100644
--- a/ui/gfx/paint_vector_icon.cc
+++ b/ui/gfx/paint_vector_icon.cc
@@ -19,6 +19,7 @@
#include "third_party/skia/include/core/SkPath.h"
#include "ui/gfx/animation/tween.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/vector_icon_types.h"
@@ -437,43 +438,36 @@ void PaintPath(Canvas* canvas,
class VectorIconSource : public CanvasImageSource {
public:
- VectorIconSource(const VectorIcon& icon,
- int dip_size,
- SkColor color,
- const VectorIcon& badge_icon)
- : CanvasImageSource(Size(dip_size, dip_size), false),
- color_(color),
- icon_(icon),
- badge_(badge_icon) {}
+ explicit VectorIconSource(const IconDescription& data)
+ : CanvasImageSource(Size(data.dip_size, data.dip_size), false),
+ data_(data) {}
VectorIconSource(const std::string& definition, int dip_size, SkColor color)
: CanvasImageSource(Size(dip_size, dip_size), false),
- color_(color),
- icon_(kNoneIcon),
- badge_(kNoneIcon),
+ data_(kNoneIcon, dip_size, color, base::TimeDelta(), kNoneIcon),
path_(PathFromSource(definition)) {}
~VectorIconSource() override {}
// CanvasImageSource:
bool HasRepresentationAtAllScales() const override {
- return !icon_.is_empty();
+ return !data_.icon.is_empty();
}
void Draw(Canvas* canvas) override {
if (path_.empty()) {
- PaintVectorIcon(canvas, icon_, size_.width(), color_);
- if (!badge_.is_empty())
- PaintVectorIcon(canvas, badge_, size_.width(), color_);
+ PaintVectorIcon(canvas, data_.icon, size_.width(), data_.color,
+ data_.elapsed_time);
+ if (!data_.badge_icon.is_empty())
+ PaintVectorIcon(canvas, data_.badge_icon, size_.width(), data_.color);
} else {
- PaintPath(canvas, path_.data(), size_.width(), color_, base::TimeDelta());
+ PaintPath(canvas, path_.data(), size_.width(), data_.color,
+ base::TimeDelta());
}
}
private:
- const SkColor color_;
- const VectorIcon& icon_;
- const VectorIcon& badge_;
+ const IconDescription data_;
const std::vector<PathElement> path_;
DISALLOW_COPY_AND_ASSIGN(VectorIconSource);
@@ -487,45 +481,18 @@ class VectorIconCache {
VectorIconCache() {}
~VectorIconCache() {}
- ImageSkia GetOrCreateIcon(const VectorIcon& icon,
- int dip_size,
- SkColor color,
- const VectorIcon& badge_icon) {
- IconDescription description(&icon, dip_size, color, &badge_icon);
+ ImageSkia GetOrCreateIcon(const IconDescription& description) {
auto iter = images_.find(description);
if (iter != images_.end())
return iter->second;
- ImageSkia icon_image(
- new VectorIconSource(icon, dip_size, color, badge_icon),
- Size(dip_size, dip_size));
+ ImageSkia icon_image(new VectorIconSource(description),
+ Size(description.dip_size, description.dip_size));
images_.insert(std::make_pair(description, icon_image));
return icon_image;
}
private:
- struct IconDescription {
- IconDescription(const VectorIcon* icon,
- int dip_size,
- SkColor color,
- const VectorIcon* badge_icon)
- : icon(icon),
- dip_size(dip_size),
- color(color),
- badge_icon(badge_icon) {}
-
- bool operator<(const IconDescription& other) const {
- return std::tie(icon, dip_size, color, badge_icon) <
- std::tie(other.icon, other.dip_size, other.color,
- other.badge_icon);
- }
-
- const VectorIcon* icon;
- int dip_size;
- SkColor color;
- const VectorIcon* badge_icon;
- };
-
std::map<IconDescription, ImageSkia> images_;
DISALLOW_COPY_AND_ASSIGN(VectorIconCache);
@@ -536,6 +503,34 @@ static base::LazyInstance<VectorIconCache>::DestructorAtExit g_icon_cache =
} // namespace
+IconDescription::IconDescription(const IconDescription& other) = default;
+
+IconDescription::IconDescription(const VectorIcon& icon,
+ int dip_size,
+ SkColor color,
+ const base::TimeDelta& elapsed_time,
+ const VectorIcon& badge_icon)
+ : icon(icon),
+ dip_size(dip_size),
+ color(color),
+ elapsed_time(elapsed_time),
+ badge_icon(badge_icon) {
+ if (dip_size == 0)
+ this->dip_size = GetDefaultSizeOfVectorIcon(icon);
+}
+
+IconDescription::~IconDescription() {}
+
+bool IconDescription::operator<(const IconDescription& other) const {
+ const VectorIcon* this_icon = &icon;
+ const VectorIcon* other_icon = &other.icon;
+ const VectorIcon* this_badge = &badge_icon;
+ const VectorIcon* other_badge = &other.badge_icon;
+ return std::tie(this_icon, dip_size, color, elapsed_time, this_badge) <
+ std::tie(other_icon, other.dip_size, other.color, other.elapsed_time,
sadrul 2017/05/24 17:35:13 This is .. comparing pointers?
Evan Stade 2017/05/24 17:47:53 yes. This is not new. Our code is already doing th
+ other_badge);
+}
+
const VectorIcon kNoneIcon = {};
void PaintVectorIcon(Canvas* canvas,
@@ -557,6 +552,13 @@ void PaintVectorIcon(Canvas* canvas,
PaintPath(canvas, path, dip_size, color, elapsed_time);
}
+ImageSkia CreateVectorIcon(const IconDescription& params) {
+ if (params.icon.is_empty())
+ return gfx::ImageSkia();
+
+ return g_icon_cache.Get().GetOrCreateIcon(params);
+}
+
ImageSkia CreateVectorIcon(const VectorIcon& icon, SkColor color) {
return CreateVectorIcon(icon, GetDefaultSizeOfVectorIcon(icon), color);
}
@@ -564,16 +566,16 @@ ImageSkia CreateVectorIcon(const VectorIcon& icon, SkColor color) {
ImageSkia CreateVectorIcon(const VectorIcon& icon,
int dip_size,
SkColor color) {
- return CreateVectorIconWithBadge(icon, dip_size, color, kNoneIcon);
+ return CreateVectorIcon(
+ IconDescription(icon, dip_size, color, base::TimeDelta(), kNoneIcon));
}
ImageSkia CreateVectorIconWithBadge(const VectorIcon& icon,
int dip_size,
SkColor color,
const VectorIcon& badge_icon) {
- return icon.is_empty() ? ImageSkia()
- : g_icon_cache.Get().GetOrCreateIcon(
- icon, dip_size, color, badge_icon);
+ return CreateVectorIcon(
+ IconDescription(icon, dip_size, color, base::TimeDelta(), badge_icon));
}
ImageSkia CreateVectorIconFromSource(const std::string& source,

Powered by Google App Engine
This is Rietveld 408576698