Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: ui/gfx/icon_family.cc

Issue 12881003: ShortcutInfo::favicon is now a gfx::ImageFamily instead of gfx::Image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: web_app_mac: Fix compile error (no Mac to test it on so I'm building in the dark). Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "ui/gfx/icon_family.h"
6
7 #include <algorithm>
8
9 #include "ui/gfx/image/image.h"
10 #include "ui/gfx/image/image_skia.h"
11
12 namespace gfx {
13
14 IconFamily::IconFamily() {}
15 IconFamily::~IconFamily() {}
16
17 void IconFamily::Add(const gfx::Image& icon)
18 {
19 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
20 if (imageskia)
21 Add(*imageskia);
22 }
23
24 void IconFamily::Add(const gfx::ImageSkia& icon)
25 {
26 int size = std::min(icon.width(), icon.height());
27 map_[size] = icon;
28 }
29
30 const gfx::ImageSkia* IconFamily::Get(int size) const
31 {
32 const gfx::ImageSkia* smallest_larger = NULL;
33 const gfx::ImageSkia* largest_smaller = NULL;
34 int smallest_larger_size = 0;
35 int largest_smaller_size = 0;
36
37 for (const_iterator it = begin(); it != end(); ++it) {
38 int image_size = it->first;
39 const gfx::ImageSkia& image = it->second;
40 if (image_size >= size) {
41 if (!smallest_larger || image_size < smallest_larger_size) {
42 smallest_larger = &image;
43 smallest_larger_size = image_size;
44 }
45 } else {
46 if (!largest_smaller || image_size > largest_smaller_size) {
47 largest_smaller = &image;
48 largest_smaller_size = image_size;
49 }
50 }
51 }
52
53 return smallest_larger ? smallest_larger : largest_smaller;
54 }
55
56 } // namespace gfx
OLDNEW
« ui/gfx/icon_family.h ('K') | « ui/gfx/icon_family.h ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698