OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_COMMON_ICON_WITH_BADGE_IMAGE_SOURCE_H_ | |
6 #define CHROME_COMMON_ICON_WITH_BADGE_IMAGE_SOURCE_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "third_party/skia/include/core/SkColor.h" | |
11 #include "ui/gfx/image/canvas_image_source.h" | |
12 #include "ui/gfx/image/image.h" | |
13 | |
14 namespace gfx { | |
15 class Size; | |
16 } | |
17 | |
18 // CanvasImageSource for creating extension icon with a badge. | |
19 // TODO(devlin): This class and its buddy badge_util don't really belong in | |
20 // chrome/common/. | |
21 class IconWithBadgeImageSource : public gfx::CanvasImageSource { | |
22 public: | |
23 // The data representing a badge to be painted over the base image. | |
24 struct Badge { | |
25 Badge(const std::string& text, | |
26 SkColor text_color, | |
27 SkColor background_color); | |
28 ~Badge(); | |
29 | |
30 std::string text; | |
31 SkColor text_color; | |
32 SkColor background_color; | |
33 | |
34 private: | |
35 DISALLOW_COPY_AND_ASSIGN(Badge); | |
36 }; | |
37 | |
38 explicit IconWithBadgeImageSource(const gfx::Size& size); | |
39 ~IconWithBadgeImageSource() override; | |
40 | |
41 void SetIcon(const gfx::Image& icon); | |
42 void SetBadge(scoped_ptr<Badge> badge); | |
43 void set_grayscale(bool grayscale) { grayscale_ = grayscale; } | |
44 void set_paint_decoration(bool paint_decoration) { | |
45 paint_decoration_ = paint_decoration; | |
46 } | |
47 | |
48 bool grayscale() const { return grayscale_; } | |
49 bool paint_decoration() const { return paint_decoration_; } | |
50 | |
51 private: | |
52 // gfx::CanvasImageSource: | |
53 void Draw(gfx::Canvas* canvas) override; | |
54 | |
55 // Paints a decoration over the base icon to indicate that the action wants to | |
56 // run. | |
57 void PaintDecoration(gfx::Canvas* canvas); | |
58 | |
59 // The base icon to draw. | |
60 gfx::Image icon_; | |
61 | |
62 // An optional badge to draw over the base icon. | |
63 scoped_ptr<Badge> badge_; | |
64 | |
65 // Whether or not the icon should be grayscaled (e.g., to show it is | |
66 // disabled). | |
67 bool grayscale_; | |
68 | |
69 // Whether or not to paint a decoration over the base icon to indicate the | |
70 // represented action wants to run. | |
71 bool paint_decoration_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(IconWithBadgeImageSource); | |
74 }; | |
75 | |
76 #endif // CHROME_COMMON_ICON_WITH_BADGE_IMAGE_SOURCE_H_ | |
OLD | NEW |