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> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // Adds an image to the family. If another image is already present at the | 102 // Adds an image to the family. If another image is already present at the |
103 // same size, it will be overwritten. | 103 // same size, it will be overwritten. |
104 void Add(const gfx::ImageSkia& image_skia); | 104 void Add(const gfx::ImageSkia& image_skia); |
105 | 105 |
106 // Gets the best image to use in a rectangle of |width|x|height|. | 106 // Gets the best image to use in a rectangle of |width|x|height|. |
107 // Gets an image at the same aspect ratio as |width|:|height|, if possible, or | 107 // Gets an image at the same aspect ratio as |width|:|height|, if possible, or |
108 // if not, the closest aspect ratio. Among images of that aspect ratio, | 108 // if not, the closest aspect ratio. Among images of that aspect ratio, |
109 // returns the smallest image with both its width and height bigger or equal | 109 // returns the smallest image with both its width and height bigger or equal |
110 // to the requested size. If none exists, returns the largest image of that | 110 // to the requested size. If none exists, returns the largest image of that |
111 // aspect ratio. If there are no images in the family, returns NULL. | 111 // aspect ratio. If there are no images in the family, returns NULL. |
112 const gfx::Image* Get(int width, int height) const; | 112 const gfx::Image* GetBest(int width, int height) const; |
113 | 113 |
114 private: | 114 private: |
115 // An <aspect ratio, DIP width> pair. | 115 // An <aspect ratio, DIP width> pair. |
116 // A 0x0 image has aspect ratio 1.0. 0xN and Nx0 images are treated as 0x0. | 116 // A 0x0 image has aspect ratio 1.0. 0xN and Nx0 images are treated as 0x0. |
117 struct MapKey : std::pair<float, int> { | 117 struct MapKey : std::pair<float, int> { |
118 MapKey(float aspect, int width) | 118 MapKey(float aspect, int width) |
119 : std::pair<float, int>(aspect, width) {} | 119 : std::pair<float, int>(aspect, width) {} |
120 | 120 |
121 float aspect() const { return first; } | 121 float aspect() const { return first; } |
122 | 122 |
(...skipping 12 matching lines...) Expand all Loading... |
135 // |map_| of aspect ratio |aspect|. | 135 // |map_| of aspect ratio |aspect|. |
136 const gfx::Image* GetWithExactAspect(float aspect, int width) const; | 136 const gfx::Image* GetWithExactAspect(float aspect, int width) const; |
137 | 137 |
138 // Map from (aspect ratio, width) to image. | 138 // Map from (aspect ratio, width) to image. |
139 std::map<MapKey, gfx::Image> map_; | 139 std::map<MapKey, gfx::Image> map_; |
140 }; | 140 }; |
141 | 141 |
142 } // namespace gfx | 142 } // namespace gfx |
143 | 143 |
144 #endif // UI_GFX_IMAGE_IMAGE_FAMILY_H_ | 144 #endif // UI_GFX_IMAGE_IMAGE_FAMILY_H_ |
OLD | NEW |