OLD | NEW |
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 Loading... |
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 Loading... |
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 kIconPreviewSizePixels); |
90 // found, find the biggest icon smaller than the desired size. | 90 if (!icon) |
91 const gfx::ImageSkiaRep* smallest_larger = NULL; | 91 // The family has no icons. Leave the pixbuf as NULL. |
92 const gfx::ImageSkiaRep* largest_smaller = NULL; | 92 return; |
93 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin(); | 93 |
94 it != image_reps.end(); ++it) { | 94 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(*icon->bitmap()); |
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. | 95 // Prepare the icon. Scale it to the correct size to display in the dialog. |
118 int pixbuf_width = gdk_pixbuf_get_width(pixbuf); | 96 int pixbuf_width = gdk_pixbuf_get_width(pixbuf); |
119 int pixbuf_height = gdk_pixbuf_get_height(pixbuf); | 97 int pixbuf_height = gdk_pixbuf_get_height(pixbuf); |
120 if (pixbuf_width == pixbuf_height) { | 98 if (pixbuf_width == pixbuf_height) { |
121 // Only scale the pixbuf if it's a square (for simplicity). | 99 // 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. | 100 // Generally it should be square, if it's a favicon or app icon. |
123 // Use the highest quality interpolation. | 101 // Use the highest quality interpolation. |
124 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf, | 102 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf, |
125 kIconPreviewSizePixels, | 103 kIconPreviewSizePixels, |
126 kIconPreviewSizePixels, | 104 kIconPreviewSizePixels, |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
378 | 356 |
379 if (web_app::CreateShortcutsOnFileThread(shortcut_info, creation_locations)) { | 357 if (web_app::CreateShortcutsOnFileThread(shortcut_info, creation_locations)) { |
380 Release(); | 358 Release(); |
381 } else { | 359 } else { |
382 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 360 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
383 base::Bind(&CreateChromeApplicationShortcutsDialogGtk::ShowErrorDialog, | 361 base::Bind(&CreateChromeApplicationShortcutsDialogGtk::ShowErrorDialog, |
384 this)); | 362 this)); |
385 } | 363 } |
386 } | 364 } |
OLD | NEW |