| 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/views/create_application_shortcut_view.h" | 5 #include "chrome/browser/ui/views/create_application_shortcut_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 169 |
| 170 void AppInfoView::UpdateText(const base::string16& title, | 170 void AppInfoView::UpdateText(const base::string16& title, |
| 171 const base::string16& description) { | 171 const base::string16& description) { |
| 172 title_->SetText(title); | 172 title_->SetText(title); |
| 173 PrepareDescriptionLabel(description); | 173 PrepareDescriptionLabel(description); |
| 174 | 174 |
| 175 SetupLayout(); | 175 SetupLayout(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void AppInfoView::UpdateIcon(const gfx::ImageFamily& image) { | 178 void AppInfoView::UpdateIcon(const gfx::ImageFamily& image) { |
| 179 // Get the icon closest to the desired preview size. | 179 // Get an icon at the desired preview size (scaling from a larger image if |
| 180 const gfx::Image* icon = image.GetBest(kIconPreviewSizePixels, | 180 // none is available at that exact size). |
| 181 kIconPreviewSizePixels); | 181 gfx::Image icon = |
| 182 if (!icon || icon->IsEmpty()) | 182 image.CreateExact(kIconPreviewSizePixels, kIconPreviewSizePixels); |
| 183 // The family has no icons. Leave the image blank. | 183 icon_->SetImage(icon.ToImageSkia()); |
| 184 return; | |
| 185 const SkBitmap& bitmap = *icon->ToSkBitmap(); | |
| 186 if (bitmap.width() == kIconPreviewSizePixels && | |
| 187 bitmap.height() == kIconPreviewSizePixels) { | |
| 188 icon_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(bitmap)); | |
| 189 } else { | |
| 190 // Resize the image to the desired size. | |
| 191 SkBitmap resized_bitmap = skia::ImageOperations::Resize( | |
| 192 bitmap, skia::ImageOperations::RESIZE_LANCZOS3, | |
| 193 kIconPreviewSizePixels, kIconPreviewSizePixels); | |
| 194 | |
| 195 icon_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(resized_bitmap)); | |
| 196 } | |
| 197 } | 184 } |
| 198 | 185 |
| 199 void AppInfoView::OnPaint(gfx::Canvas* canvas) { | 186 void AppInfoView::OnPaint(gfx::Canvas* canvas) { |
| 200 gfx::Rect bounds = GetLocalBounds(); | 187 gfx::Rect bounds = GetLocalBounds(); |
| 201 | 188 |
| 202 SkRect border_rect = { | 189 SkRect border_rect = { |
| 203 SkIntToScalar(bounds.x()), | 190 SkIntToScalar(bounds.x()), |
| 204 SkIntToScalar(bounds.y()), | 191 SkIntToScalar(bounds.y()), |
| 205 SkIntToScalar(bounds.right()), | 192 SkIntToScalar(bounds.right()), |
| 206 SkIntToScalar(bounds.bottom()) | 193 SkIntToScalar(bounds.bottom()) |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 close_callback_.Run(false); | 551 close_callback_.Run(false); |
| 565 return CreateApplicationShortcutView::Cancel(); | 552 return CreateApplicationShortcutView::Cancel(); |
| 566 } | 553 } |
| 567 | 554 |
| 568 void CreateChromeApplicationShortcutView::OnAppInfoLoaded( | 555 void CreateChromeApplicationShortcutView::OnAppInfoLoaded( |
| 569 scoped_ptr<web_app::ShortcutInfo> shortcut_info, | 556 scoped_ptr<web_app::ShortcutInfo> shortcut_info, |
| 570 const extensions::FileHandlersInfo& file_handlers_info) { | 557 const extensions::FileHandlersInfo& file_handlers_info) { |
| 571 shortcut_info_ = shortcut_info.Pass(); | 558 shortcut_info_ = shortcut_info.Pass(); |
| 572 file_handlers_info_ = file_handlers_info; | 559 file_handlers_info_ = file_handlers_info; |
| 573 } | 560 } |
| OLD | NEW |