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

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: 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
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 15 matching lines...) Expand all
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "content/public/browser/web_contents_delegate.h" 28 #include "content/public/browser/web_contents_delegate.h"
29 #include "grit/chromium_strings.h" 29 #include "grit/chromium_strings.h"
30 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
31 #include "grit/locale_settings.h" 31 #include "grit/locale_settings.h"
32 #include "grit/theme_resources.h" 32 #include "grit/theme_resources.h"
33 #include "ui/base/gtk/gtk_hig_constants.h" 33 #include "ui/base/gtk/gtk_hig_constants.h"
34 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/gfx/gtk_util.h" 35 #include "ui/gfx/gtk_util.h"
36 #include "ui/gfx/icon_family.h"
36 #include "ui/gfx/image/image_skia.h" 37 #include "ui/gfx/image/image_skia.h"
37 #include "ui/gfx/image/image_skia_rep.h"
38 38
39 using content::BrowserThread; 39 using content::BrowserThread;
40 using extensions::Extension; 40 using extensions::Extension;
41 41
42 namespace { 42 namespace {
43 43
44 // Size (in pixels) of the icon preview. 44 // Size (in pixels) of the icon preview.
45 const int kIconPreviewSizePixels = 32; 45 const int kIconPreviewSizePixels = 32;
46 46
47 // 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
76 favicon_pixbuf_(NULL), 76 favicon_pixbuf_(NULL),
77 create_dialog_(NULL), 77 create_dialog_(NULL),
78 error_dialog_(NULL) { 78 error_dialog_(NULL) {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
80 80
81 // Will be balanced by Release later. 81 // Will be balanced by Release later.
82 AddRef(); 82 AddRef();
83 } 83 }
84 84
85 void CreateApplicationShortcutsDialogGtk::CreateIconPixBuf( 85 void CreateApplicationShortcutsDialogGtk::CreateIconPixBuf(
86 const gfx::Image& image) { 86 const gfx::IconFamily& image) {
87 const gfx::ImageSkia& image_skia = *(image.ToImageSkia()); 87 // Get the icon closest to the desired preview size.
88 std::vector<gfx::ImageSkiaRep> image_reps = image_skia.image_reps(); 88 const gfx::ImageSkia* icon = image.Get(kIconPreviewSizePixels);
89 // Find the smallest icon bigger or equal to the desired size. If it cannot be 89 if (!icon)
90 // found, find the biggest icon smaller than the desired size. 90 // The family has no icons. Leave the pixbuf as NULL.
91 const gfx::ImageSkiaRep* smallest_larger = NULL; 91 return;
92 const gfx::ImageSkiaRep* largest_smaller = NULL; 92
93 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin(); 93 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(*icon->bitmap());
94 it != image_reps.end(); ++it) {
95 if (it->pixel_width() >= kIconPreviewSizePixels) {
96 if (!smallest_larger ||
97 it->pixel_width() < smallest_larger->pixel_width()) {
98 smallest_larger = &*it;
99 }
100 } else {
101 if (!largest_smaller ||
102 it->pixel_width() > largest_smaller->pixel_width()) {
103 largest_smaller = &*it;
104 }
105 }
106 }
107 GdkPixbuf* pixbuf;
108 if (smallest_larger) {
109 pixbuf = gfx::GdkPixbufFromSkBitmap(smallest_larger->sk_bitmap());
110 } else if (largest_smaller) {
111 pixbuf = gfx::GdkPixbufFromSkBitmap(largest_smaller->sk_bitmap());
112 } else {
113 // Should never happen unless the image has no representations. Call
114 // ToGdkPixbuf which will presumably return a null image representation.
115 pixbuf = static_cast<GdkPixbuf*>(g_object_ref(image.ToGdkPixbuf()));
116 }
117 // 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.
118 int pixbuf_width = gdk_pixbuf_get_width(pixbuf); 95 int pixbuf_width = gdk_pixbuf_get_width(pixbuf);
119 int pixbuf_height = gdk_pixbuf_get_height(pixbuf); 96 int pixbuf_height = gdk_pixbuf_get_height(pixbuf);
120 if (pixbuf_width == pixbuf_height) { 97 if (pixbuf_width == pixbuf_height) {
121 // Only scale the pixbuf if it's a square (for simplicity). 98 // Only scale the pixbuf if it's a square (for simplicity).
122 // 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.
123 // Use the highest quality interpolation. 100 // Use the highest quality interpolation.
124 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf, 101 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf,
125 kIconPreviewSizePixels, 102 kIconPreviewSizePixels,
126 kIconPreviewSizePixels, 103 kIconPreviewSizePixels,
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
378 355
379 if (web_app::CreateShortcutsOnFileThread(shortcut_info, creation_locations)) { 356 if (web_app::CreateShortcutsOnFileThread(shortcut_info, creation_locations)) {
380 Release(); 357 Release();
381 } else { 358 } else {
382 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 359 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
383 base::Bind(&CreateChromeApplicationShortcutsDialogGtk::ShowErrorDialog, 360 base::Bind(&CreateChromeApplicationShortcutsDialogGtk::ShowErrorDialog,
384 this)); 361 this));
385 } 362 }
386 } 363 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698