Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 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 UI_GFX_ICON_FAMILY_H_ | |
| 6 #define UI_GFX_ICON_FAMILY_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "ui/base/ui_export.h" | |
| 11 #include "ui/gfx/image/image_skia.h" | |
| 12 | |
| 13 namespace gfx { | |
| 14 class Image; | |
| 15 | |
| 16 // A collection of images, representing icons at different sizes. Each image is | |
| 17 // an ImageSkia, which may contain multi-resolution bitmaps. | |
| 18 class UI_EXPORT IconFamily { | |
| 19 public: | |
| 20 // Type for iterating over all icons in the family, in order. | |
| 21 typedef std::map<int, gfx::ImageSkia>::const_iterator const_iterator; | |
| 22 | |
| 23 IconFamily(); | |
| 24 ~IconFamily(); | |
| 25 | |
| 26 // Gets an iterator to the first icon. | |
| 27 inline const_iterator begin() const { return map_.begin(); } | |
| 28 // Gets an iterator to one after the last icon. | |
| 29 inline const_iterator end() const { return map_.end(); } | |
| 30 | |
| 31 // Determines whether the icon family has no icons in it. | |
| 32 inline bool empty() const { return map_.empty(); } | |
| 33 | |
| 34 // Removes all icons from the family. | |
| 35 inline void clear() { return map_.clear(); } | |
| 36 | |
| 37 // Adds an icon to the family. If another icon is already present at the | |
| 38 // same size, it will be overwritten. If |icon| does not contain an image, | |
| 39 // does nothing. | |
| 40 // The icon SHOULD be square; if not, its size will be whichever is smaller | |
|
benwells
2013/03/17 22:42:36
What's the reasoning behind this recommendation-bu
Matt Giuca
2013/03/17 22:51:18
Basically that it works fine if images are not squ
Matt Giuca
2013/03/18 07:41:16
Note: I chatted with Ben about this some more.
He
| |
| 41 // of the width and height. | |
| 42 void Add(const gfx::Image& icon); | |
| 43 | |
| 44 // Adds an icon to the family. If another icon is already present at the | |
| 45 // same size, it will be overwritten. | |
| 46 // The icon SHOULD be square; if not, its size will be whichever is smaller | |
| 47 // of the width and height. | |
| 48 void Add(const gfx::ImageSkia& icon); | |
| 49 | |
| 50 // Gets the best icon to use at |size|. | |
| 51 // Returns the smallest icon bigger or equal to |size|. If none exists, | |
| 52 // returns the largest icon smaller than |size|. If there are no icons in the | |
| 53 // family, returns NULL. | |
| 54 const gfx::ImageSkia* Get(int size) const; | |
| 55 | |
| 56 private: | |
| 57 // Map from base icon size to multi-resolution image. If an image is | |
| 58 // non-square, its size refers to the minimum of its width and height | |
| 59 // (although this is not recommended). | |
| 60 // If an image contains multiple resolution bitmaps, the size refers to the | |
| 61 // width/height at the 100% representation. | |
| 62 std::map<int, gfx::ImageSkia> map_; | |
|
pkotwicz
2013/03/18 03:22:43
If you want, you can make this into std::map<int,
Matt Giuca
2013/03/18 07:41:16
Well we (Ben and I) designed it so that we could h
pkotwicz
2013/03/18 16:30:23
Comment: Right now I don't think we 2x images into
Matt Giuca
2013/03/18 22:45:20
Correct. But this representation would easily allo
| |
| 63 }; | |
| 64 | |
| 65 } // namespace gfx | |
| 66 | |
| 67 #endif // UI_GFX_ICON_FAMILY_H_ | |
| OLD | NEW |