| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_GFX_IMAGE_IMAGE_FAMILY_H_ | 5 #ifndef UI_GFX_IMAGE_IMAGE_FAMILY_H_ |
| 6 #define UI_GFX_IMAGE_IMAGE_FAMILY_H_ | 6 #define UI_GFX_IMAGE_IMAGE_FAMILY_H_ |
| 7 | 7 |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "ui/gfx/gfx_export.h" | 12 #include "ui/gfx/gfx_export.h" |
| 13 #include "ui/gfx/image/image.h" | 13 #include "ui/gfx/image/image.h" |
| 14 | 14 |
| 15 namespace gfx { | 15 namespace gfx { |
| 16 class ImageSkia; | 16 class ImageSkia; |
| 17 class Size; | 17 class Size; |
| 18 | 18 |
| 19 // A collection of images at different sizes. The images should be different | 19 // A collection of images at different sizes. The images should be different |
| 20 // representations of the same basic concept (for example, an icon) at various | 20 // representations of the same basic concept (for example, an icon) at various |
| 21 // sizes and (optionally) aspect ratios. A method is provided for finding the | 21 // sizes and (optionally) aspect ratios. A method is provided for finding the |
| 22 // most appropriate image to fit in a given rectangle. | 22 // most appropriate image to fit in a given rectangle. |
| 23 // | 23 // |
| 24 // NOTE: This is not appropriate for storing an image at a single logical pixel | 24 // NOTE: This is not appropriate for storing an image at a single logical pixel |
| 25 // size, with high-DPI bitmap versions; use an Image or ImageSkia for that. Each | 25 // size, with high-DPI bitmap versions; use an Image or ImageSkia for that. Each |
| 26 // image in an ImageFamily should have a different logical size (and may also | 26 // image in an ImageFamily should have a different logical size (and may also |
| 27 // include high-DPI representations). | 27 // include high-DPI representations). |
| 28 class UI_EXPORT ImageFamily { | 28 class GFX_EXPORT ImageFamily { |
| 29 private: | 29 private: |
| 30 // An <aspect ratio, DIP width> pair. | 30 // An <aspect ratio, DIP width> pair. |
| 31 // A 0x0 image has aspect ratio 1.0. 0xN and Nx0 images are treated as 0x0. | 31 // A 0x0 image has aspect ratio 1.0. 0xN and Nx0 images are treated as 0x0. |
| 32 struct MapKey : std::pair<float, int> { | 32 struct MapKey : std::pair<float, int> { |
| 33 MapKey(float aspect, int width) | 33 MapKey(float aspect, int width) |
| 34 : std::pair<float, int>(aspect, width) {} | 34 : std::pair<float, int>(aspect, width) {} |
| 35 | 35 |
| 36 float aspect() const { return first; } | 36 float aspect() const { return first; } |
| 37 | 37 |
| 38 int width() const { return second; } | 38 int width() const { return second; } |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 public: | 41 public: |
| 42 // Type for iterating over all images in the family, in order. | 42 // Type for iterating over all images in the family, in order. |
| 43 // Dereferencing this iterator returns a gfx::Image. | 43 // Dereferencing this iterator returns a gfx::Image. |
| 44 class UI_EXPORT const_iterator : | 44 class GFX_EXPORT const_iterator : |
| 45 std::iterator<std::bidirectional_iterator_tag, const gfx::Image> { | 45 std::iterator<std::bidirectional_iterator_tag, const gfx::Image> { |
| 46 public: | 46 public: |
| 47 const_iterator(); | 47 const_iterator(); |
| 48 | 48 |
| 49 const_iterator(const const_iterator& other); | 49 const_iterator(const const_iterator& other); |
| 50 | 50 |
| 51 const_iterator& operator++() { | 51 const_iterator& operator++() { |
| 52 ++map_iterator_; | 52 ++map_iterator_; |
| 53 return *this; | 53 return *this; |
| 54 } | 54 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // |map_| of aspect ratio |aspect|. | 147 // |map_| of aspect ratio |aspect|. |
| 148 const gfx::Image* GetWithExactAspect(float aspect, int width) const; | 148 const gfx::Image* GetWithExactAspect(float aspect, int width) const; |
| 149 | 149 |
| 150 // Map from (aspect ratio, width) to image. | 150 // Map from (aspect ratio, width) to image. |
| 151 std::map<MapKey, gfx::Image> map_; | 151 std::map<MapKey, gfx::Image> map_; |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 } // namespace gfx | 154 } // namespace gfx |
| 155 | 155 |
| 156 #endif // UI_GFX_IMAGE_IMAGE_FAMILY_H_ | 156 #endif // UI_GFX_IMAGE_IMAGE_FAMILY_H_ |
| OLD | NEW |