| Index: ui/gfx/paint_vector_icon.cc
|
| diff --git a/ui/gfx/paint_vector_icon.cc b/ui/gfx/paint_vector_icon.cc
|
| index 304ed4c08fc10c203d97027e1ae1e5f805abf97e..c747c97d097b67974a0580c0eafdd8c9c2ad1d2d 100644
|
| --- a/ui/gfx/paint_vector_icon.cc
|
| +++ b/ui/gfx/paint_vector_icon.cc
|
| @@ -68,6 +68,7 @@ void PaintPath(Canvas* canvas,
|
| const PathElement* path_elements,
|
| size_t dip_size,
|
| SkColor color) {
|
| + canvas->Save();
|
| SkPath path;
|
| path.setFillType(SkPath::kEvenOdd_FillType);
|
|
|
| @@ -238,16 +239,21 @@ void PaintPath(Canvas* canvas,
|
| DCHECK_EQ(paints.size(), paths.size());
|
| for (size_t i = 0; i < paths.size(); ++i)
|
| canvas->DrawPath(paths[i], paints[i]);
|
| + canvas->Restore();
|
| }
|
|
|
| class VectorIconSource : public CanvasImageSource {
|
| public:
|
| - VectorIconSource(VectorIconId id, size_t dip_size, SkColor color)
|
| + VectorIconSource(VectorIconId id,
|
| + size_t dip_size,
|
| + SkColor color,
|
| + VectorIconId badge_id)
|
| : CanvasImageSource(
|
| gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size)),
|
| false),
|
| id_(id),
|
| - color_(color) {}
|
| + color_(color),
|
| + badge_id_(badge_id) {}
|
|
|
| VectorIconSource(const std::string& definition,
|
| size_t dip_size,
|
| @@ -257,22 +263,27 @@ class VectorIconSource : public CanvasImageSource {
|
| false),
|
| id_(VectorIconId::VECTOR_ICON_NONE),
|
| path_(PathFromSource(definition)),
|
| - color_(color) {}
|
| + color_(color),
|
| + badge_id_(VectorIconId::VECTOR_ICON_NONE) {}
|
|
|
| ~VectorIconSource() override {}
|
|
|
| // CanvasImageSource:
|
| void Draw(gfx::Canvas* canvas) override {
|
| - if (path_.empty())
|
| + if (path_.empty()) {
|
| PaintVectorIcon(canvas, id_, size_.width(), color_);
|
| - else
|
| + if (badge_id_ != VectorIconId::VECTOR_ICON_NONE)
|
| + PaintVectorIcon(canvas, badge_id_, size_.width(), color_);
|
| + } else {
|
| PaintPath(canvas, path_.data(), size_.width(), color_);
|
| + }
|
| }
|
|
|
| private:
|
| const VectorIconId id_;
|
| const std::vector<PathElement> path_;
|
| const SkColor color_;
|
| + const VectorIconId badge_id_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(VectorIconSource);
|
| };
|
| @@ -285,14 +296,17 @@ class VectorIconCache {
|
| VectorIconCache() {}
|
| ~VectorIconCache() {}
|
|
|
| - ImageSkia GetOrCreateIcon(VectorIconId id, size_t dip_size, SkColor color) {
|
| - IconDescription description(id, dip_size, color);
|
| + ImageSkia GetOrCreateIcon(VectorIconId id,
|
| + size_t dip_size,
|
| + SkColor color,
|
| + VectorIconId badge_id) {
|
| + IconDescription description(id, dip_size, color, badge_id);
|
| auto iter = images_.find(description);
|
| if (iter != images_.end())
|
| return iter->second;
|
|
|
| ImageSkia icon(
|
| - new VectorIconSource(id, dip_size, color),
|
| + new VectorIconSource(id, dip_size, color, badge_id),
|
| gfx::Size(static_cast<int>(dip_size), static_cast<int>(dip_size)));
|
| images_.insert(std::make_pair(description, icon));
|
| return icon;
|
| @@ -300,20 +314,26 @@ class VectorIconCache {
|
|
|
| private:
|
| struct IconDescription {
|
| - IconDescription(VectorIconId id, size_t dip_size, SkColor color)
|
| - : id(id), dip_size(dip_size), color(color) {}
|
| + IconDescription(VectorIconId id,
|
| + size_t dip_size,
|
| + SkColor color,
|
| + VectorIconId badge_id)
|
| + : id(id), dip_size(dip_size), color(color), badge_id(badge_id) {}
|
|
|
| bool operator<(const IconDescription& other) const {
|
| if (id != other.id)
|
| return id < other.id;
|
| if (dip_size != other.dip_size)
|
| return dip_size < other.dip_size;
|
| - return color < other.color;
|
| + if (color != other.color)
|
| + return color < other.color;
|
| + return badge_id < other.badge_id;
|
| }
|
|
|
| VectorIconId id;
|
| size_t dip_size;
|
| SkColor color;
|
| + VectorIconId badge_id;
|
| };
|
|
|
| std::map<IconDescription, ImageSkia> images_;
|
| @@ -338,7 +358,15 @@ void PaintVectorIcon(Canvas* canvas,
|
| }
|
|
|
| ImageSkia CreateVectorIcon(VectorIconId id, size_t dip_size, SkColor color) {
|
| - return g_icon_cache.Get().GetOrCreateIcon(id, dip_size, color);
|
| + return CreateVectorIconWithBadge(id, dip_size, color,
|
| + VectorIconId::VECTOR_ICON_NONE);
|
| +}
|
| +
|
| +ImageSkia CreateVectorIconWithBadge(VectorIconId id,
|
| + size_t dip_size,
|
| + SkColor color,
|
| + VectorIconId badge_id) {
|
| + return g_icon_cache.Get().GetOrCreateIcon(id, dip_size, color, badge_id);
|
| }
|
|
|
| ImageSkia CreateVectorIconFromSource(const std::string& source,
|
|
|