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

Side by Side Diff: chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc

Issue 9586018: Add support for multiple icon sizes for Mac platform apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build Created 8 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 | Annotate | Revision Log
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"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/shell_integration.h" 12 #include "chrome/browser/shell_integration.h"
13 #include "chrome/browser/ui/gtk/gtk_util.h" 13 #include "chrome/browser/ui/gtk/gtk_util.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
15 #include "chrome/browser/ui/web_applications/web_app_ui.h" 15 #include "chrome/browser/ui/web_applications/web_app_ui.h"
16 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 16 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
17 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_resource.h" 18 #include "chrome/common/extensions/extension_resource.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "content/public/browser/web_contents_delegate.h" 21 #include "content/public/browser/web_contents_delegate.h"
22 #include "grit/chromium_strings.h" 22 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
24 #include "grit/locale_settings.h" 24 #include "grit/locale_settings.h"
25 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
26 #include "ui/base/gtk/gtk_hig_constants.h" 26 #include "ui/base/gtk/gtk_hig_constants.h"
27 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/gtk_util.h" 29 #include "ui/gfx/gtk_util.h"
29 30
30 using content::BrowserThread; 31 using content::BrowserThread;
31 32
32 namespace { 33 namespace {
33 34
34 // Size (in pixels) of the icon preview. 35 // Size (in pixels) of the icon preview.
35 const int kIconPreviewSizePixels = 32; 36 const int kIconPreviewSizePixels = 32;
36 37
37 // Height (in lines) of the shortcut description label. 38 // Height (in lines) of the shortcut description label.
(...skipping 21 matching lines...) Expand all
59 favicon_pixbuf_(NULL), 60 favicon_pixbuf_(NULL),
60 create_dialog_(NULL), 61 create_dialog_(NULL),
61 error_dialog_(NULL) { 62 error_dialog_(NULL) {
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
63 64
64 // Will be balanced by Release later. 65 // Will be balanced by Release later.
65 AddRef(); 66 AddRef();
66 } 67 }
67 68
68 void CreateApplicationShortcutsDialogGtk::CreateIconPixBuf( 69 void CreateApplicationShortcutsDialogGtk::CreateIconPixBuf(
69 const SkBitmap& bitmap) { 70 const gfx::Image& image) {
70 // Prepare the icon. Try to scale it if it's too small, otherwise it would 71 // Prepare the icon. Try to scale it if it's too small, otherwise it would
71 // look weird. 72 // look weird.
72 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&shortcut_info_.favicon); 73 GdkPixbuf* pixbuf =
74 static_cast<GdkPixbuf*>(g_object_ref(image.ToGdkPixbuf()));
73 int pixbuf_width = gdk_pixbuf_get_width(pixbuf); 75 int pixbuf_width = gdk_pixbuf_get_width(pixbuf);
74 int pixbuf_height = gdk_pixbuf_get_height(pixbuf); 76 int pixbuf_height = gdk_pixbuf_get_height(pixbuf);
75 if (pixbuf_width == pixbuf_height && pixbuf_width < kIconPreviewSizePixels) { 77 if (pixbuf_width == pixbuf_height && pixbuf_width < kIconPreviewSizePixels) {
76 // Only scale the pixbuf if it's a square (for simplicity). 78 // Only scale the pixbuf if it's a square (for simplicity).
77 // Generally it should be square, if it's a favicon or app icon. 79 // Generally it should be square, if it's a favicon or app icon.
78 // Use the highest quality interpolation. The scaling is 80 // Use the highest quality interpolation. The scaling is
79 // going to have low quality anyway, because the initial image 81 // going to have low quality anyway, because the initial image
80 // is likely small. 82 // is likely small.
81 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf, 83 favicon_pixbuf_ = gdk_pixbuf_scale_simple(pixbuf,
82 kIconPreviewSizePixels, 84 kIconPreviewSizePixels,
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // if the image is cached. This is very rare. Do not do anything after 327 // if the image is cached. This is very rare. Do not do anything after
326 // calling LoadImage() that OnImageLoaded() depends on. 328 // calling LoadImage() that OnImageLoaded() depends on.
327 tracker_.LoadImage(app_, 329 tracker_.LoadImage(app_,
328 icon_resource, 330 icon_resource,
329 max_size, 331 max_size,
330 ImageLoadingTracker::DONT_CACHE); 332 ImageLoadingTracker::DONT_CACHE);
331 } 333 }
332 334
333 // Called by tracker_ when the app's icon is loaded. 335 // Called by tracker_ when the app's icon is loaded.
334 void CreateChromeApplicationShortcutsDialogGtk::OnImageLoaded( 336 void CreateChromeApplicationShortcutsDialogGtk::OnImageLoaded(
335 SkBitmap* image, const ExtensionResource& resource, int index) { 337 const gfx::Image& image,
336 if (!image || image->isNull()) 338 const std::string& extension_id,
337 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); 339 int index) {
340 if (image.IsEmpty()) {
341 shortcut_info_.favicon =
342 ResourceBundle::GetSharedInstance().GetImageNamed(IDR_APP_DEFAULT_ICON);
343 } else {
344 shortcut_info_.favicon = image;
345 }
338 346
339 shortcut_info_.favicon = *image; 347 CreateIconPixBuf(shortcut_info_.favicon);
340
341 CreateIconPixBuf(*image);
342 CreateDialogBox(parent_); 348 CreateDialogBox(parent_);
343 } 349 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698