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

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

Issue 10559054: Animate the script badges. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: move to extension action Created 8 years, 6 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.h
diff --git a/chrome/common/extensions/extension_action.h b/chrome/common/extensions/extension_action.h
index f29066d90274f19f4da24666525a68e1955c2953..1f24a519865e41d180accd2ad1d8f985555382a2 100644
--- a/chrome/common/extensions/extension_action.h
+++ b/chrome/common/extensions/extension_action.h
@@ -11,16 +11,22 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/memory/linked_ptr.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/base/animation/linear_animation.h"
+
+class GURL;
+class SkBitmap;
+class SkDevice;
namespace gfx {
class Canvas;
class Rect;
}
-class GURL;
-class SkBitmap;
-
// ExtensionAction encapsulates the state of a browser action, page action, or
// script badge.
// Instances can have both global and per-tab state. If a property does not have
@@ -38,6 +44,44 @@ class ExtensionAction {
TYPE_SCRIPT_BADGE,
};
+ // A fade-in animation.
+ class IconAnimation : public ui::LinearAnimation,
+ public base::SupportsWeakPtr<IconAnimation> {
+ public:
+ // Observes changes to icon animation state.
+ class Observer {
+ public:
+ virtual void OnIconChanged(const IconAnimation& animation) = 0;
+
+ protected:
+ virtual ~Observer() {}
+ };
+
+ virtual ~IconAnimation();
+
+ // Returns the icon derived from the current animation state applied to
+ // |icon|. Ownership remains with this.
+ const SkBitmap& Apply(const SkBitmap& icon) const;
+
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ private:
+ // Construct using ExtensionAction::RunIconAnimation().
+ friend class ExtensionAction;
+ explicit IconAnimation(ui::AnimationDelegate* delegate);
+
+ // ui::LinearAnimation implementation.
+ virtual void AnimateToState(double state) OVERRIDE;
+
+ // Device we use to paint icons to.
+ mutable scoped_ptr<SkDevice> device_;
+
+ ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(IconAnimation);
+ };
+
ExtensionAction(const std::string& extension_id, Type action_type);
~ExtensionAction();
@@ -150,6 +194,12 @@ class ExtensionAction {
// If the specified tab has a badge, paint it into the provided bounds.
void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id);
+ // Gets the icon animation for a tab.
Yoyo Zhou 2012/06/26 18:38:15 , if it is running?
not at google - send to devlin 2012/06/27 06:26:54 Done.
+ base::WeakPtr<IconAnimation> GetIconAnimation(int tab_id) const;
+
+ // Runs an animation on a tab.
+ void RunIconAnimation(int tab_id);
+
private:
template <class T>
struct ValueTraits {
@@ -191,6 +241,9 @@ class ExtensionAction {
std::map<int, SkColor> badge_text_color_;
std::map<int, bool> visible_;
+ class IconAnimationWrapper;
+ std::map<int, linked_ptr<IconAnimationWrapper> > icon_animation_;
+
std::string default_icon_path_;
// The id for the ExtensionAction, for example: "RssPageAction". This is

Powered by Google App Engine
This is Rietveld 408576698