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

Unified 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 side-by-side diff with in-line comments
Download patch
« ui/gfx/icon_family.h ('K') | « ui/gfx/icon_family.h ('k') | ui/ui.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = &image;
+ smallest_larger_size = image_size;
+ }
+ } else {
+ if (!largest_smaller || image_size > largest_smaller_size) {
+ largest_smaller = &image;
+ largest_smaller_size = image_size;
+ }
+ }
+ }
+
+ return smallest_larger ? smallest_larger : largest_smaller;
+}
+
+} // namespace gfx
« 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