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

Unified Diff: chrome/browser/ui/app_list/extension_app_item.cc

Issue 2819413003: Refactor extension app icon. (Closed)
Patch Set: nit Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/app_list/extension_app_item.cc
diff --git a/chrome/browser/ui/app_list/extension_app_item.cc b/chrome/browser/ui/app_list/extension_app_item.cc
index 4d4f0dd0ec58c2078233e004d796a54378fbe0ee..153762665db164815a9aa3362f6d44c41bfca8cd 100644
--- a/chrome/browser/ui/app_list/extension_app_item.cc
+++ b/chrome/browser/ui/app_list/extension_app_item.cc
@@ -9,6 +9,8 @@
#include "base/macros.h"
#include "base/metrics/user_metrics.h"
#include "build/build_config.h"
+#include "chrome/browser/extensions/chrome_app_icon.h"
+#include "chrome/browser/extensions/chrome_app_icon_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile.h"
@@ -33,74 +35,9 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/skia_util.h"
-#include "chrome/browser/chromeos/extensions/gfx_utils.h"
using extensions::Extension;
-namespace {
-
-// Overlays a shortcut icon over the bottom left corner of a given image.
-class ShortcutOverlayImageSource : public gfx::CanvasImageSource {
- public:
- explicit ShortcutOverlayImageSource(const gfx::ImageSkia& icon)
- : gfx::CanvasImageSource(icon.size(), false),
- icon_(icon) {
- }
- ~ShortcutOverlayImageSource() override {}
-
- private:
- // gfx::CanvasImageSource overrides:
- void Draw(gfx::Canvas* canvas) override {
- canvas->DrawImageInt(icon_, 0, 0);
-
- // Draw the overlay in the bottom left corner of the icon.
- const gfx::ImageSkia& overlay = *ui::ResourceBundle::GetSharedInstance().
- GetImageSkiaNamed(IDR_APP_LIST_TAB_OVERLAY);
- canvas->DrawImageInt(overlay, 0, icon_.height() - overlay.height());
- }
-
- gfx::ImageSkia icon_;
-
- DISALLOW_COPY_AND_ASSIGN(ShortcutOverlayImageSource);
-};
-
-// Rounds the corners of a given image.
-class RoundedCornersImageSource : public gfx::CanvasImageSource {
- public:
- explicit RoundedCornersImageSource(const gfx::ImageSkia& icon)
- : gfx::CanvasImageSource(icon.size(), false),
- icon_(icon) {
- }
- ~RoundedCornersImageSource() override {}
-
- private:
- // gfx::CanvasImageSource overrides:
- void Draw(gfx::Canvas* canvas) override {
- // The radius used to round the app icon.
- const size_t kRoundingRadius = 2;
-
- canvas->DrawImageInt(icon_, 0, 0);
-
- cc::PaintFlags masking_flags;
- masking_flags.setBlendMode(SkBlendMode::kDstIn);
- canvas->SaveLayerWithFlags(masking_flags);
-
- cc::PaintFlags mask_flags;
- mask_flags.setAntiAlias(true);
- mask_flags.setColor(SK_ColorWHITE);
- canvas->DrawRoundRect(gfx::Rect(icon_.width(), icon_.height()),
- kRoundingRadius, mask_flags);
-
- canvas->Restore();
- }
-
- gfx::ImageSkia icon_;
-
- DISALLOW_COPY_AND_ASSIGN(RoundedCornersImageSource);
-};
-
-} // namespace
-
ExtensionAppItem::ExtensionAppItem(
Profile* profile,
const app_list::AppListSyncableService::SyncItem* sync_item,
@@ -129,31 +66,20 @@ void ExtensionAppItem::Reload() {
SetIsInstalling(is_installing);
if (is_installing) {
SetName(extension_name_);
- UpdateIcon();
+ SetIcon(installing_icon_);
return;
}
SetNameAndShortName(extension->name(), extension->short_name());
- LoadImage(extension);
+ if (!icon_) {
+ icon_ = extensions::ChromeAppIconService::Get(profile())->CreateIcon(
+ this, extension_id(), extension_misc::EXTENSION_ICON_MEDIUM);
+ } else {
+ icon_->Reload();
+ }
}
-void ExtensionAppItem::UpdateIcon() {
- gfx::ImageSkia icon = installing_icon_;
-
- // Use the app icon if the app exists. Turn the image greyscale if the app is
- // not launchable.
- if (GetExtension() && icon_) {
- icon = icon_->image_skia();
- const bool enabled = extensions::util::IsAppLaunchable(extension_id(),
- profile());
- extensions::util::MaybeApplyChromeBadge(profile(), id(), &icon);
-
- if (!enabled)
- icon = CreateDisabledIcon(icon);
-
- if (GetExtension()->from_bookmark())
- icon = gfx::ImageSkia(new RoundedCornersImageSource(icon), icon.size());
- }
- SetIcon(icon);
+void ExtensionAppItem::OnIconUpdated(extensions::ChromeAppIcon* icon) {
+ SetIcon(icon->IsValid() ? icon->image_skia() : installing_icon_);
}
const Extension* ExtensionAppItem::GetExtension() const {
@@ -164,17 +90,6 @@ const Extension* ExtensionAppItem::GetExtension() const {
return extension;
}
-void ExtensionAppItem::LoadImage(const Extension* extension) {
- icon_.reset(new extensions::IconImage(
- profile(),
- extension,
- extensions::IconsInfo::GetIcons(extension),
- extension_misc::EXTENSION_ICON_MEDIUM,
- extensions::util::GetDefaultAppIcon(),
- this));
- UpdateIcon();
-}
-
bool ExtensionAppItem::RunExtensionEnableFlow() {
if (extensions::util::IsAppLaunchableWithoutEnabling(extension_id(),
profile()))
@@ -211,17 +126,6 @@ void ExtensionAppItem::Launch(int event_flags) {
event_flags);
}
-void ExtensionAppItem::OnExtensionIconImageChanged(
- extensions::IconImage* image) {
- DCHECK(icon_.get() == image);
- UpdateIcon();
-}
-
-void ExtensionAppItem::OnExtensionIconImageDestroyed(
- extensions::IconImage* image) {
- SetIcon(gfx::ImageSkia());
-}
-
void ExtensionAppItem::ExtensionEnableFlowFinished() {
extension_enable_flow_.reset();
extension_enable_flow_controller_->OnCloseChildDialog();
« no previous file with comments | « chrome/browser/ui/app_list/extension_app_item.h ('k') | chrome/browser/ui/app_list/extension_app_model_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698