rdevlin.cronin | a437dab3 | 2015-05-14 21:16:27 | [diff] [blame] | 1 | // Copyright 2015 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 EXTENSIONS_BROWSER_EXTENSION_ICON_PLACEHOLDER_H_ |
| 6 | #define EXTENSIONS_BROWSER_EXTENSION_ICON_PLACEHOLDER_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/macros.h" |
| 11 | #include "base/strings/string16.h" |
| 12 | #include "extensions/common/constants.h" |
| 13 | #include "ui/gfx/image/canvas_image_source.h" |
| 14 | #include "ui/gfx/image/image.h" |
| 15 | |
| 16 | namespace gfx { |
| 17 | class Canvas; |
rdevlin.cronin | a437dab3 | 2015-05-14 21:16:27 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | namespace extensions { |
| 21 | |
| 22 | // An extension icon image with a gray background and the first letter of the |
| 23 | // extension name, so that not all extensions without an icon look the same. |
| 24 | class ExtensionIconPlaceholder : public gfx::CanvasImageSource { |
| 25 | public: |
| 26 | ExtensionIconPlaceholder(extension_misc::ExtensionIcons size, |
| 27 | const std::string& name); |
| 28 | ~ExtensionIconPlaceholder() override; |
| 29 | |
| 30 | // Creates an image backed by an ImageSkia with the ExtensionIconPlaceholder |
| 31 | // as its image source. |
| 32 | static gfx::Image CreateImage(extension_misc::ExtensionIcons size, |
| 33 | const std::string& name); |
| 34 | |
| 35 | private: |
| 36 | // gfx::CanvasImageSource: |
| 37 | void Draw(gfx::Canvas* canvas) override; |
| 38 | |
| 39 | // The size this placeholder is filling. |
| 40 | extension_misc::ExtensionIcons icon_size_; |
| 41 | |
| 42 | // The first letter of the extension's name. |
| 43 | base::string16 letter_; |
| 44 | |
| 45 | // The gray background image, on top of which the letter is drawn. |
| 46 | gfx::Image base_image_; |
| 47 | |
| 48 | DISALLOW_COPY_AND_ASSIGN(ExtensionIconPlaceholder); |
| 49 | }; |
| 50 | |
| 51 | } // namespace extensions |
| 52 | |
| 53 | #endif // EXTENSIONS_BROWSER_EXTENSION_ICON_PLACEHOLDER_H_ |