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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 class AppInfoView : public views::View { | 50 class AppInfoView : public views::View { |
51 public: | 51 public: |
52 AppInfoView(const string16& title, | 52 AppInfoView(const string16& title, |
53 const string16& description, | 53 const string16& description, |
54 const SkBitmap& icon); | 54 const SkBitmap& icon); |
55 | 55 |
56 // Updates the title/description of the web app. | 56 // Updates the title/description of the web app. |
57 void UpdateText(const string16& title, const string16& description); | 57 void UpdateText(const string16& title, const string16& description); |
58 | 58 |
59 // Updates the icon of the web app. | 59 // Updates the icon of the web app. |
60 void UpdateIcon(const SkBitmap& new_icon); | 60 void UpdateIcon(const gfx::Image& image); |
61 | 61 |
62 // Overridden from views::View: | 62 // Overridden from views::View: |
63 virtual void OnPaint(gfx::Canvas* canvas); | 63 virtual void OnPaint(gfx::Canvas* canvas); |
64 | 64 |
65 private: | 65 private: |
66 // Initializes the controls | 66 // Initializes the controls |
67 void Init(const string16& title, | 67 void Init(const string16& title, |
68 const string16& description, const SkBitmap& icon); | 68 const string16& description, const SkBitmap& icon); |
69 | 69 |
70 // Creates or updates description label. | 70 // Creates or updates description label. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 152 } |
153 | 153 |
154 void AppInfoView::UpdateText(const string16& title, | 154 void AppInfoView::UpdateText(const string16& title, |
155 const string16& description) { | 155 const string16& description) { |
156 title_->SetText(title); | 156 title_->SetText(title); |
157 PrepareDescriptionLabel(description); | 157 PrepareDescriptionLabel(description); |
158 | 158 |
159 SetupLayout(); | 159 SetupLayout(); |
160 } | 160 } |
161 | 161 |
162 void AppInfoView::UpdateIcon(const SkBitmap& new_icon) { | 162 void AppInfoView::UpdateIcon(const gfx::Image& image) { |
163 icon_->SetImage(new_icon); | 163 if (!image.IsEmpty()) |
| 164 icon_->SetImage(image.ToSkBitmap()); |
164 } | 165 } |
165 | 166 |
166 void AppInfoView::OnPaint(gfx::Canvas* canvas) { | 167 void AppInfoView::OnPaint(gfx::Canvas* canvas) { |
167 gfx::Rect bounds = GetLocalBounds(); | 168 gfx::Rect bounds = GetLocalBounds(); |
168 | 169 |
169 SkRect border_rect = { | 170 SkRect border_rect = { |
170 SkIntToScalar(bounds.x()), | 171 SkIntToScalar(bounds.x()), |
171 SkIntToScalar(bounds.y()), | 172 SkIntToScalar(bounds.y()), |
172 SkIntToScalar(bounds.right()), | 173 SkIntToScalar(bounds.right()), |
173 SkIntToScalar(bounds.bottom()) | 174 SkIntToScalar(bounds.bottom()) |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 base::Unretained(pending_download_))); | 463 base::Unretained(pending_download_))); |
463 | 464 |
464 unprocessed_icons_.pop_back(); | 465 unprocessed_icons_.pop_back(); |
465 } | 466 } |
466 | 467 |
467 void CreateUrlApplicationShortcutView::OnIconDownloaded(bool errored, | 468 void CreateUrlApplicationShortcutView::OnIconDownloaded(bool errored, |
468 const SkBitmap& image) { | 469 const SkBitmap& image) { |
469 pending_download_ = NULL; | 470 pending_download_ = NULL; |
470 | 471 |
471 if (!errored && !image.isNull()) { | 472 if (!errored && !image.isNull()) { |
472 shortcut_info_.favicon = image; | 473 shortcut_info_.favicon = gfx::Image(image); |
473 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); | 474 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); |
474 } else { | 475 } else { |
475 FetchIcon(); | 476 FetchIcon(); |
476 } | 477 } |
477 } | 478 } |
478 | 479 |
479 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( | 480 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( |
480 Profile* profile, | 481 Profile* profile, |
481 const Extension* app) : | 482 const Extension* app) : |
482 CreateApplicationShortcutView(profile), | 483 CreateApplicationShortcutView(profile), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 tracker_.LoadImage(app_, | 516 tracker_.LoadImage(app_, |
516 icon_resource, | 517 icon_resource, |
517 max_size, | 518 max_size, |
518 ImageLoadingTracker::DONT_CACHE); | 519 ImageLoadingTracker::DONT_CACHE); |
519 } | 520 } |
520 | 521 |
521 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} | 522 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} |
522 | 523 |
523 // Called by tracker_ when the app's icon is loaded. | 524 // Called by tracker_ when the app's icon is loaded. |
524 void CreateChromeApplicationShortcutView::OnImageLoaded( | 525 void CreateChromeApplicationShortcutView::OnImageLoaded( |
525 SkBitmap* image, const ExtensionResource& resource, int index) { | 526 const gfx::Image& image, |
526 if (!image || image->isNull()) | 527 const std::string& extension_id, |
527 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); | 528 int index) { |
| 529 if (image.IsEmpty()) { |
| 530 shortcut_info_.favicon = ui::ResourceBundle::GetSharedInstance(). |
| 531 GetImageNamed(IDR_APP_DEFAULT_ICON); |
| 532 } else { |
| 533 shortcut_info_.favicon = image; |
| 534 } |
528 | 535 |
529 shortcut_info_.favicon = *image; | |
530 CHECK(app_info_); | 536 CHECK(app_info_); |
531 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); | 537 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); |
532 } | 538 } |
OLD | NEW |