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 14 matching lines...) Expand all Loading... | |
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 Loading... | |
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.Get(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 if (!icon || icon->IsEmpty()) |
pkotwicz
2013/04/04 18:34:40
Should we just CHECK() instead?
gdk_pixbuf_get_wid
Matt Giuca
2013/04/05 06:30:13
Done.
Note that the existing code didn't work pro
| |
90 const gfx::ImageSkiaRep* smallest_larger = NULL; | 91 // The family has no icons. Leave the pixbuf as NULL. |
91 const gfx::ImageSkiaRep* largest_smaller = NULL; | 92 return; |
92 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin(); | 93 |
93 it != image_reps.end(); ++it) { | 94 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(*icon->ToSkBitmap()); |
Robert Sesek
2013/04/04 18:39:02
icon->ToGdkPixbuf.
Matt Giuca
2013/04/05 06:30:13
Done.
| |
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. | 95 // Prepare the icon. Scale it to the correct size to display in the dialog. |
117 int pixbuf_width = gdk_pixbuf_get_width(pixbuf); | 96 int pixbuf_width = gdk_pixbuf_get_width(pixbuf); |
118 int pixbuf_height = gdk_pixbuf_get_height(pixbuf); | 97 int pixbuf_height = gdk_pixbuf_get_height(pixbuf); |
119 if (pixbuf_width == pixbuf_height) { | 98 if (pixbuf_width == pixbuf_height) { |
120 // Only scale the pixbuf if it's a square (for simplicity). | 99 // 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. | 100 // Generally it should be square, if it's a favicon or app icon. |
122 // Use the highest quality interpolation. | 101 // Use the highest quality interpolation. |
123 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf, | 102 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf, |
124 kIconPreviewSizePixels, | 103 kIconPreviewSizePixels, |
125 kIconPreviewSizePixels, | 104 kIconPreviewSizePixels, |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
377 | 356 |
378 if (web_app::CreateShortcutsOnFileThread(shortcut_info, creation_locations)) { | 357 if (web_app::CreateShortcutsOnFileThread(shortcut_info, creation_locations)) { |
379 Release(); | 358 Release(); |
380 } else { | 359 } else { |
381 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 360 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
382 base::Bind(&CreateChromeApplicationShortcutsDialogGtk::ShowErrorDialog, | 361 base::Bind(&CreateChromeApplicationShortcutsDialogGtk::ShowErrorDialog, |
383 this)); | 362 this)); |
384 } | 363 } |
385 } | 364 } |
OLD | NEW |