| 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 icon_->SetImage(image.ToSkBitmap()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void AppInfoView::OnPaint(gfx::Canvas* canvas) { | 166 void AppInfoView::OnPaint(gfx::Canvas* canvas) { |
| 167 gfx::Rect bounds = GetLocalBounds(); | 167 gfx::Rect bounds = GetLocalBounds(); |
| 168 | 168 |
| 169 SkRect border_rect = { | 169 SkRect border_rect = { |
| 170 SkIntToScalar(bounds.x()), | 170 SkIntToScalar(bounds.x()), |
| 171 SkIntToScalar(bounds.y()), | 171 SkIntToScalar(bounds.y()), |
| 172 SkIntToScalar(bounds.right()), | 172 SkIntToScalar(bounds.right()), |
| 173 SkIntToScalar(bounds.bottom()) | 173 SkIntToScalar(bounds.bottom()) |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 base::Unretained(pending_download_))); | 462 base::Unretained(pending_download_))); |
| 463 | 463 |
| 464 unprocessed_icons_.pop_back(); | 464 unprocessed_icons_.pop_back(); |
| 465 } | 465 } |
| 466 | 466 |
| 467 void CreateUrlApplicationShortcutView::OnIconDownloaded(bool errored, | 467 void CreateUrlApplicationShortcutView::OnIconDownloaded(bool errored, |
| 468 const SkBitmap& image) { | 468 const SkBitmap& image) { |
| 469 pending_download_ = NULL; | 469 pending_download_ = NULL; |
| 470 | 470 |
| 471 if (!errored && !image.isNull()) { | 471 if (!errored && !image.isNull()) { |
| 472 shortcut_info_.favicon = image; | 472 shortcut_info_.favicon = gfx::Image(image); |
| 473 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); | 473 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); |
| 474 } else { | 474 } else { |
| 475 FetchIcon(); | 475 FetchIcon(); |
| 476 } | 476 } |
| 477 } | 477 } |
| 478 | 478 |
| 479 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( | 479 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( |
| 480 Profile* profile, | 480 Profile* profile, |
| 481 const Extension* app) : | 481 const Extension* app) : |
| 482 CreateApplicationShortcutView(profile), | 482 CreateApplicationShortcutView(profile), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 tracker_.LoadImage(app_, | 515 tracker_.LoadImage(app_, |
| 516 icon_resource, | 516 icon_resource, |
| 517 max_size, | 517 max_size, |
| 518 ImageLoadingTracker::DONT_CACHE); | 518 ImageLoadingTracker::DONT_CACHE); |
| 519 } | 519 } |
| 520 | 520 |
| 521 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} | 521 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} |
| 522 | 522 |
| 523 // Called by tracker_ when the app's icon is loaded. | 523 // Called by tracker_ when the app's icon is loaded. |
| 524 void CreateChromeApplicationShortcutView::OnImageLoaded( | 524 void CreateChromeApplicationShortcutView::OnImageLoaded( |
| 525 SkBitmap* image, const ExtensionResource& resource, int index) { | 525 const gfx::Image& image, |
| 526 if (!image || image->isNull()) | 526 const std::string& extension_id, |
| 527 image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON); | 527 int index) { |
| 528 if (image.IsEmpty()) { |
| 529 shortcut_info_.favicon = ui::ResourceBundle::GetSharedInstance(). |
| 530 GetImageNamed(IDR_APP_DEFAULT_ICON); |
| 531 } else { |
| 532 shortcut_info_.favicon = image; |
| 533 } |
| 528 | 534 |
| 529 shortcut_info_.favicon = *image; | |
| 530 CHECK(app_info_); | 535 CHECK(app_info_); |
| 531 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); | 536 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); |
| 532 } | 537 } |
| OLD | NEW |