Chromium Code Reviews| Index: ui/gfx/icon_family.cc |
| diff --git a/ui/gfx/icon_family.cc b/ui/gfx/icon_family.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..177bde53ef96f0c4f1bd354870712baa882af531 |
| --- /dev/null |
| +++ b/ui/gfx/icon_family.cc |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/gfx/icon_family.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "ui/gfx/image/image.h" |
| +#include "ui/gfx/image/image_skia.h" |
| + |
| +namespace gfx { |
| + |
| +IconFamily::IconFamily() {} |
| +IconFamily::~IconFamily() {} |
| + |
| +void IconFamily::Add(const gfx::Image& icon) |
| +{ |
| + const gfx::ImageSkia* imageskia = icon.ToImageSkia(); |
|
pkotwicz
2013/03/18 03:22:43
Nit: You can use AsImageSkia() instead.
Matt Giuca
2013/03/18 07:41:16
I looked at that, but it doesn't return a referenc
pkotwicz
2013/03/18 16:30:23
ImageSkia is ref counted so a copy is not that exp
Matt Giuca
2013/03/18 22:45:20
Fair enough, but also the second reason (don't wan
|
| + if (imageskia) |
| + Add(*imageskia); |
| +} |
| + |
| +void IconFamily::Add(const gfx::ImageSkia& icon) |
| +{ |
| + int size = std::min(icon.width(), icon.height()); |
| + map_[size] = icon; |
| +} |
| + |
| +const gfx::ImageSkia* IconFamily::Get(int size) const |
| +{ |
| + const gfx::ImageSkia* smallest_larger = NULL; |
| + const gfx::ImageSkia* largest_smaller = NULL; |
| + int smallest_larger_size = 0; |
| + int largest_smaller_size = 0; |
| + |
| + for (const_iterator it = begin(); it != end(); ++it) { |
| + int image_size = it->first; |
| + const gfx::ImageSkia& image = it->second; |
| + if (image_size >= size) { |
| + if (!smallest_larger || image_size < smallest_larger_size) { |
| + smallest_larger = ℑ |
| + smallest_larger_size = image_size; |
| + } |
| + } else { |
| + if (!largest_smaller || image_size > largest_smaller_size) { |
| + largest_smaller = ℑ |
| + largest_smaller_size = image_size; |
| + } |
| + } |
| + } |
| + |
| + return smallest_larger ? smallest_larger : largest_smaller; |
| +} |
| + |
| +} // namespace gfx |