Chromium Code Reviews| Index: chrome/browser/ui/views/create_application_shortcut_view.cc |
| diff --git a/chrome/browser/ui/views/create_application_shortcut_view.cc b/chrome/browser/ui/views/create_application_shortcut_view.cc |
| index 1d27d3a29107a50731b50ebc1acc253fa197fb77..84026e63c456d3dd7384dadb5b019aefcf6f9f22 100644 |
| --- a/chrome/browser/ui/views/create_application_shortcut_view.cc |
| +++ b/chrome/browser/ui/views/create_application_shortcut_view.cc |
| @@ -42,8 +42,8 @@ |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/codec/png_codec.h" |
| +#include "ui/gfx/icon_family.h" |
| #include "ui/gfx/image/image_skia.h" |
| -#include "ui/gfx/image/image_skia_rep.h" |
| #include "ui/views/controls/button/checkbox.h" |
| #include "ui/views/controls/image_view.h" |
| #include "ui/views/controls/label.h" |
| @@ -61,13 +61,13 @@ class AppInfoView : public views::View { |
| public: |
| AppInfoView(const string16& title, |
| const string16& description, |
| - const SkBitmap& icon); |
| + const gfx::IconFamily& icon); |
| // Updates the title/description of the web app. |
| void UpdateText(const string16& title, const string16& description); |
| // Updates the icon of the web app. |
| - void UpdateIcon(const gfx::Image& image); |
| + void UpdateIcon(const gfx::IconFamily& image); |
| // Overridden from views::View: |
| virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| @@ -75,7 +75,7 @@ class AppInfoView : public views::View { |
| private: |
| // Initializes the controls |
| void Init(const string16& title, |
| - const string16& description, const SkBitmap& icon); |
| + const string16& description, const gfx::IconFamily& icon); |
| // Creates or updates description label. |
| void PrepareDescriptionLabel(const string16& description); |
| @@ -90,7 +90,7 @@ class AppInfoView : public views::View { |
| AppInfoView::AppInfoView(const string16& title, |
| const string16& description, |
| - const SkBitmap& icon) |
| + const gfx::IconFamily& icon) |
| : icon_(NULL), |
| title_(NULL), |
| description_(NULL) { |
| @@ -99,9 +99,9 @@ AppInfoView::AppInfoView(const string16& title, |
| void AppInfoView::Init(const string16& title_text, |
| const string16& description_text, |
| - const SkBitmap& icon) { |
| + const gfx::IconFamily& icon) { |
| icon_ = new views::ImageView(); |
| - icon_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(icon)); |
| + UpdateIcon(icon); |
| icon_->SetImageSize(gfx::Size(kIconPreviewSizePixels, |
| kIconPreviewSizePixels)); |
| @@ -170,44 +170,13 @@ void AppInfoView::UpdateText(const string16& title, |
| SetupLayout(); |
| } |
| -void AppInfoView::UpdateIcon(const gfx::Image& image) { |
| - if (image.IsEmpty()) |
| +void AppInfoView::UpdateIcon(const gfx::IconFamily& image) { |
| + // Get the icon closest to the desired preview size. |
| + const gfx::ImageSkia* icon = image.Get(kIconPreviewSizePixels); |
| + if (!icon) |
| + // The family has no icons. Leave the image blank. |
| return; |
| - |
| - // image contains a single ImageSkia with all of the icons at different sizes. |
| - // Create a new ImageSkia with just a single icon at the preferred size. |
| - const gfx::ImageSkia& multires_image_skia = *(image.ToImageSkia()); |
| - std::vector<gfx::ImageSkiaRep> image_reps = multires_image_skia.image_reps(); |
| - // Find the smallest icon bigger or equal to the desired size. If it cannot be |
| - // found, find the biggest icon smaller than the desired size. An icon's size |
| - // is measured as the minimum of its width and height. |
| - const gfx::ImageSkiaRep* smallest_larger = NULL; |
| - const gfx::ImageSkiaRep* largest_smaller = NULL; |
| - int smallest_larger_size = 0; |
| - int largest_smaller_size = 0; |
| - for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin(); |
| - it != image_reps.end(); ++it) { |
| - const gfx::ImageSkiaRep& image = *it; |
| - int image_size = std::min(image.pixel_width(), image.pixel_height()); |
| - if (image_size >= kIconPreviewSizePixels) { |
| - if (!smallest_larger || image_size < smallest_larger_size) { |
| - smallest_larger = ℑ |
| - smallest_larger_size = image_size; |
| - } |
| - } else { |
| - if (!largest_smaller || image_size > largest_smaller_size) { |
| - largest_smaller = ℑ |
| - largest_smaller_size = image_size; |
| - } |
| - } |
| - } |
| - if (!smallest_larger && !largest_smaller) { |
| - // Should never happen unless the image has no representations. |
| - return; |
| - } |
| - const SkBitmap& bitmap = smallest_larger ? |
| - smallest_larger->sk_bitmap() : |
| - largest_smaller->sk_bitmap(); |
| + const SkBitmap& bitmap = *icon->bitmap(); |
| if (bitmap.width() == kIconPreviewSizePixels && |
| bitmap.height() == kIconPreviewSizePixels) { |
| icon_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(bitmap)); |
|
pkotwicz
2013/03/18 03:22:43
Comment: In a separate CL, it would be nice to cal
|
| @@ -286,8 +255,7 @@ CreateApplicationShortcutView::~CreateApplicationShortcutView() {} |
| void CreateApplicationShortcutView::InitControls() { |
| // Create controls |
| app_info_ = new AppInfoView(shortcut_info_.title, shortcut_info_.description, |
| - shortcut_info_.favicon.IsEmpty() ? SkBitmap() : |
| - *shortcut_info_.favicon.ToSkBitmap()); |
| + shortcut_info_.favicon); |
| create_shortcuts_label_ = new views::Label( |
| l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_LABEL)); |
| create_shortcuts_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| @@ -473,10 +441,10 @@ bool CreateUrlApplicationShortcutView::Accept() { |
| if (!CreateApplicationShortcutView::Accept()) |
| return false; |
| - extensions::TabHelper::FromWebContents(web_contents_)-> |
| - SetAppIcon(shortcut_info_.favicon.IsEmpty() |
| - ? SkBitmap() |
| - : *shortcut_info_.favicon.ToSkBitmap()); |
| + // Get the smallest icon in the icon family (should have only 1). |
| + const gfx::ImageSkia* icon = shortcut_info_.favicon.Get(0); |
| + SkBitmap bitmap = icon ? *icon->bitmap() : SkBitmap(); |
| + extensions::TabHelper::FromWebContents(web_contents_)->SetAppIcon(bitmap); |
| Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
| if (browser) |
| chrome::ConvertTabToAppWindow(browser, web_contents_); |
| @@ -524,7 +492,7 @@ void CreateUrlApplicationShortcutView::DidDownloadFavicon( |
| } |
| if (!image.isNull()) { |
| - shortcut_info_.favicon = gfx::Image::CreateFrom1xBitmap(image); |
| + shortcut_info_.favicon.Add(gfx::ImageSkia::CreateFrom1xBitmap(image)); |
| static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); |
| } else { |
| FetchIcon(); |