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

Side by Side Diff: chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.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: Rebase to HEAD. Created 7 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.h" 5 #include "chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 14 matching lines...) Expand all
25 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "content/public/browser/web_contents_delegate.h" 27 #include "content/public/browser/web_contents_delegate.h"
28 #include "grit/chromium_strings.h" 28 #include "grit/chromium_strings.h"
29 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
30 #include "grit/locale_settings.h" 30 #include "grit/locale_settings.h"
31 #include "grit/theme_resources.h" 31 #include "grit/theme_resources.h"
32 #include "ui/base/gtk/gtk_hig_constants.h" 32 #include "ui/base/gtk/gtk_hig_constants.h"
33 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/gfx/gtk_util.h" 34 #include "ui/gfx/gtk_util.h"
35 #include "ui/gfx/image/image.h"
36 #include "ui/gfx/image/image_family.h"
35 #include "ui/gfx/image/image_skia.h" 37 #include "ui/gfx/image/image_skia.h"
36 #include "ui/gfx/image/image_skia_rep.h"
37 38
38 using content::BrowserThread; 39 using content::BrowserThread;
39 using extensions::Extension; 40 using extensions::Extension;
40 41
41 namespace { 42 namespace {
42 43
43 // Size (in pixels) of the icon preview. 44 // Size (in pixels) of the icon preview.
44 const int kIconPreviewSizePixels = 32; 45 const int kIconPreviewSizePixels = 32;
45 46
46 // Minimum width (in pixels) of the shortcut description label. 47 // Minimum width (in pixels) of the shortcut description label.
(...skipping 28 matching lines...) Expand all
75 favicon_pixbuf_(NULL), 76 favicon_pixbuf_(NULL),
76 create_dialog_(NULL), 77 create_dialog_(NULL),
77 error_dialog_(NULL) { 78 error_dialog_(NULL) {
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
79 80
80 // Will be balanced by Release later. 81 // Will be balanced by Release later.
81 AddRef(); 82 AddRef();
82 } 83 }
83 84
84 void CreateApplicationShortcutsDialogGtk::CreateIconPixBuf( 85 void CreateApplicationShortcutsDialogGtk::CreateIconPixBuf(
85 const gfx::Image& image) { 86 const gfx::ImageFamily& image) {
86 const gfx::ImageSkia& image_skia = *(image.ToImageSkia()); 87 // Get the icon closest to the desired preview size.
87 std::vector<gfx::ImageSkiaRep> image_reps = image_skia.image_reps(); 88 const gfx::Image* icon = image.GetBest(kIconPreviewSizePixels,
88 // Find the smallest icon bigger or equal to the desired size. If it cannot be 89 kIconPreviewSizePixels);
89 // found, find the biggest icon smaller than the desired size. 90 // There must be at least one icon in the image family.
90 const gfx::ImageSkiaRep* smallest_larger = NULL; 91 CHECK(icon);
91 const gfx::ImageSkiaRep* largest_smaller = NULL; 92 GdkPixbuf* pixbuf = icon->ToGdkPixbuf();
Robert Sesek 2013/04/10 13:20:17 Actually, since you're keeping a reference to this
Matt Giuca 2013/04/11 00:55:23 Done.
92 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin(); 93 g_object_ref(pixbuf);
93 it != image_reps.end(); ++it) {
94 if (it->pixel_width() >= kIconPreviewSizePixels) {
95 if (!smallest_larger ||
96 it->pixel_width() < smallest_larger->pixel_width()) {
97 smallest_larger = &*it;
98 }
99 } else {
100 if (!largest_smaller ||
101 it->pixel_width() > largest_smaller->pixel_width()) {
102 largest_smaller = &*it;
103 }
104 }
105 }
106 GdkPixbuf* pixbuf;
107 if (smallest_larger) {
108 pixbuf = gfx::GdkPixbufFromSkBitmap(smallest_larger->sk_bitmap());
109 } else if (largest_smaller) {
110 pixbuf = gfx::GdkPixbufFromSkBitmap(largest_smaller->sk_bitmap());
111 } else {
112 // Should never happen unless the image has no representations. Call
113 // ToGdkPixbuf which will presumably return a null image representation.
114 pixbuf = static_cast<GdkPixbuf*>(g_object_ref(image.ToGdkPixbuf()));
115 }
116 // Prepare the icon. Scale it to the correct size to display in the dialog. 94 // Prepare the icon. Scale it to the correct size to display in the dialog.
117 int pixbuf_width = gdk_pixbuf_get_width(pixbuf); 95 int pixbuf_width = gdk_pixbuf_get_width(pixbuf);
118 int pixbuf_height = gdk_pixbuf_get_height(pixbuf); 96 int pixbuf_height = gdk_pixbuf_get_height(pixbuf);
119 if (pixbuf_width == pixbuf_height) { 97 if (pixbuf_width == pixbuf_height) {
120 // Only scale the pixbuf if it's a square (for simplicity). 98 // Only scale the pixbuf if it's a square (for simplicity).
121 // Generally it should be square, if it's a favicon or app icon. 99 // Generally it should be square, if it's a favicon or app icon.
122 // Use the highest quality interpolation. 100 // Use the highest quality interpolation.
123 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf, 101 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf,
124 kIconPreviewSizePixels, 102 kIconPreviewSizePixels,
125 kIconPreviewSizePixels, 103 kIconPreviewSizePixels,
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
377 355
378 if (web_app::CreateShortcutsOnFileThread(shortcut_info, creation_locations)) { 356 if (web_app::CreateShortcutsOnFileThread(shortcut_info, creation_locations)) {
379 Release(); 357 Release();
380 } else { 358 } else {
381 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 359 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
382 base::Bind(&CreateChromeApplicationShortcutsDialogGtk::ShowErrorDialog, 360 base::Bind(&CreateChromeApplicationShortcutsDialogGtk::ShowErrorDialog,
383 this)); 361 this));
384 } 362 }
385 } 363 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698