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

Unified Diff: chrome/common/extensions/extension_action.cc

Issue 10806058: Move icon fallbacks into ExtensionAction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix kalman's comments. Created 8 years, 5 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/common/extensions/extension_action.cc
diff --git a/chrome/common/extensions/extension_action.cc b/chrome/common/extensions/extension_action.cc
index 1e247210e4d4df856467317b18a664c9ebab4f92..2bfd352131e611154ef1ee5ea44c3b0256de3da7 100644
--- a/chrome/common/extensions/extension_action.cc
+++ b/chrome/common/extensions/extension_action.cc
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "chrome/common/badge_util.h"
#include "googleurl/src/gurl.h"
+#include "grit/theme_resources.h"
#include "grit/ui_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
@@ -191,11 +192,35 @@ GURL ExtensionAction::GetPopupUrl(int tab_id) const {
}
void ExtensionAction::SetIcon(int tab_id, const SkBitmap& bitmap) {
- SetValue(&icon_, tab_id, bitmap);
+ SetValue(&icon_, tab_id, gfx::Image(bitmap));
}
-SkBitmap ExtensionAction::GetIcon(int tab_id) const {
- return GetValue(&icon_, tab_id);
+gfx::Image ExtensionAction::GetIcon(int tab_id,
+ const PathToIconCache& cache) const {
+ // Check if a specific icon is set for this tab.
+ gfx::Image icon = GetValue(&icon_, tab_id);
+ if (icon.IsEmpty()) {
+ // Need to find an icon from a path.
+ const std::string* path = NULL;
+ // Check if one of the elements of icon_path() was selected.
+ int icon_index = GetIconIndex(tab_id);
+ if (icon_index >= 0) {
+ path = &icon_paths()->at(icon_index);
+ } else {
+ // Otherwise, use the default icon.
+ path = &default_icon_path();
+ }
+
+ PathToIconCache::const_iterator cached_icon = cache.find(*path);
+ if (cached_icon != cache.end()) {
+ icon = cached_icon->second;
+ } else {
+ icon = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
+ IDR_EXTENSIONS_FAVICON);
+ }
+ }
+
+ return ApplyIconAnimation(tab_id, icon);
}
void ExtensionAction::SetIconIndex(int tab_id, int index) {
@@ -218,6 +243,14 @@ void ExtensionAction::ClearAllValuesForTab(int tab_id) {
icon_animation_.erase(tab_id);
}
+namespace {
+int Width(const gfx::Image& image) {
+ if (image.IsEmpty())
+ return 0;
+ return image.ToSkBitmap()->width();
+}
+} // namespace
+
void ExtensionAction::PaintBadge(gfx::Canvas* canvas,
const gfx::Rect& bounds,
int tab_id) {
@@ -248,10 +281,10 @@ void ExtensionAction::PaintBadge(gfx::Canvas* canvas,
// Calculate badge size. It is clamped to a min width just because it looks
// silly if it is too skinny.
int badge_width = SkScalarFloor(text_width) + kPadding * 2;
- int icon_width = GetIcon(tab_id).width();
+ int icon_width = Width(GetValue(&icon_, tab_id));
// Force the pixel width of badge to be either odd (if the icon width is odd)
// or even otherwise. If there is a mismatch you get http://crbug.com/26400.
- if (icon_width != 0 && (badge_width % 2 != GetIcon(tab_id).width() % 2))
+ if (icon_width != 0 && (badge_width % 2 != icon_width % 2))
badge_width += 1;
badge_width = std::max(kBadgeHeight, badge_width);
@@ -315,6 +348,15 @@ base::WeakPtr<ExtensionAction::IconAnimation> ExtensionAction::GetIconAnimation(
: base::WeakPtr<IconAnimation>();
}
+gfx::Image ExtensionAction::ApplyIconAnimation(int tab_id,
+ const gfx::Image& orig) const {
+ std::map<int, linked_ptr<IconAnimationWrapper> >::const_iterator it =
+ icon_animation_.find(tab_id);
+ if (it == icon_animation_.end())
+ return orig;
+ return gfx::Image(it->second->animation()->Apply(*orig.ToSkBitmap()));
+}
+
void ExtensionAction::RunIconAnimation(int tab_id) {
IconAnimationWrapper* icon_animation =
new IconAnimationWrapper(this, tab_id);

Powered by Google App Engine
This is Rietveld 408576698