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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
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 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/memory/linked_ptr.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h"
14 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
19 #include "ui/base/animation/linear_animation.h"
20
21 class GURL;
22 class SkBitmap;
23 class SkDevice;
15 24
16 namespace gfx { 25 namespace gfx {
17 class Canvas; 26 class Canvas;
18 class Rect; 27 class Rect;
19 } 28 }
20 29
21 class GURL;
22 class SkBitmap;
23
24 // ExtensionAction encapsulates the state of a browser action, page action, or 30 // ExtensionAction encapsulates the state of a browser action, page action, or
25 // script badge. 31 // script badge.
26 // Instances can have both global and per-tab state. If a property does not have 32 // Instances can have both global and per-tab state. If a property does not have
27 // a per-tab value, the global value is used instead. 33 // a per-tab value, the global value is used instead.
28 class ExtensionAction { 34 class ExtensionAction {
29 public: 35 public:
30 // Use this ID to indicate the default state for properties that take a tab_id 36 // Use this ID to indicate the default state for properties that take a tab_id
31 // parameter. 37 // parameter.
32 static const int kDefaultTabId; 38 static const int kDefaultTabId;
33 39
34 // The types of extension actions. 40 // The types of extension actions.
35 enum Type { 41 enum Type {
36 TYPE_BROWSER, 42 TYPE_BROWSER,
37 TYPE_PAGE, 43 TYPE_PAGE,
38 TYPE_SCRIPT_BADGE, 44 TYPE_SCRIPT_BADGE,
39 }; 45 };
40 46
47 // A fade-in animation.
48 class IconAnimation : public ui::LinearAnimation,
49 public base::SupportsWeakPtr<IconAnimation> {
50 public:
51 // Observes changes to icon animation state.
52 class Observer {
53 public:
54 virtual void OnIconChanged(const IconAnimation& animation) = 0;
55
56 protected:
57 virtual ~Observer() {}
58 };
59
60 virtual ~IconAnimation();
61
62 // Returns the icon derived from the current animation state applied to
63 // |icon|. Ownership remains with this.
64 const SkBitmap& Apply(const SkBitmap& icon) const;
65
66 void AddObserver(Observer* observer);
67 void RemoveObserver(Observer* observer);
68
69 private:
70 // Construct using ExtensionAction::RunIconAnimation().
71 friend class ExtensionAction;
72 explicit IconAnimation(ui::AnimationDelegate* delegate);
73
74 // ui::LinearAnimation implementation.
75 virtual void AnimateToState(double state) OVERRIDE;
76
77 // Device we use to paint icons to.
78 mutable scoped_ptr<SkDevice> device_;
79
80 ObserverList<Observer> observers_;
81
82 DISALLOW_COPY_AND_ASSIGN(IconAnimation);
83 };
84
41 ExtensionAction(const std::string& extension_id, Type action_type); 85 ExtensionAction(const std::string& extension_id, Type action_type);
42 ~ExtensionAction(); 86 ~ExtensionAction();
43 87
44 // extension id 88 // extension id
45 const std::string& extension_id() const { return extension_id_; } 89 const std::string& extension_id() const { return extension_id_; }
46 90
47 // What kind of action is this? 91 // What kind of action is this?
48 Type action_type() const { return action_type_; } 92 Type action_type() const { return action_type_; }
49 93
50 // action id -- only used with legacy page actions API 94 // action id -- only used with legacy page actions API
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 bool GetIsVisible(int tab_id) const { 187 bool GetIsVisible(int tab_id) const {
144 return GetValue(&visible_, tab_id); 188 return GetValue(&visible_, tab_id);
145 } 189 }
146 190
147 // Remove all tab-specific state. 191 // Remove all tab-specific state.
148 void ClearAllValuesForTab(int tab_id); 192 void ClearAllValuesForTab(int tab_id);
149 193
150 // If the specified tab has a badge, paint it into the provided bounds. 194 // If the specified tab has a badge, paint it into the provided bounds.
151 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id); 195 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id);
152 196
197 // 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.
198 base::WeakPtr<IconAnimation> GetIconAnimation(int tab_id) const;
199
200 // Runs an animation on a tab.
201 void RunIconAnimation(int tab_id);
202
153 private: 203 private:
154 template <class T> 204 template <class T>
155 struct ValueTraits { 205 struct ValueTraits {
156 static T CreateEmpty() { 206 static T CreateEmpty() {
157 return T(); 207 return T();
158 } 208 }
159 }; 209 };
160 210
161 template<class T> 211 template<class T>
162 void SetValue(std::map<int, T>* map, int tab_id, const T& val) { 212 void SetValue(std::map<int, T>* map, int tab_id, const T& val) {
(...skipping 21 matching lines...) Expand all
184 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key). 234 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key).
185 std::map<int, GURL> popup_url_; 235 std::map<int, GURL> popup_url_;
186 std::map<int, std::string> title_; 236 std::map<int, std::string> title_;
187 std::map<int, SkBitmap> icon_; 237 std::map<int, SkBitmap> icon_;
188 std::map<int, int> icon_index_; // index into icon_paths_ 238 std::map<int, int> icon_index_; // index into icon_paths_
189 std::map<int, std::string> badge_text_; 239 std::map<int, std::string> badge_text_;
190 std::map<int, SkColor> badge_background_color_; 240 std::map<int, SkColor> badge_background_color_;
191 std::map<int, SkColor> badge_text_color_; 241 std::map<int, SkColor> badge_text_color_;
192 std::map<int, bool> visible_; 242 std::map<int, bool> visible_;
193 243
244 class IconAnimationWrapper;
245 std::map<int, linked_ptr<IconAnimationWrapper> > icon_animation_;
246
194 std::string default_icon_path_; 247 std::string default_icon_path_;
195 248
196 // The id for the ExtensionAction, for example: "RssPageAction". This is 249 // The id for the ExtensionAction, for example: "RssPageAction". This is
197 // needed for compat with an older version of the page actions API. 250 // needed for compat with an older version of the page actions API.
198 std::string id_; 251 std::string id_;
199 252
200 // A list of paths to icons this action might show. This is needed to support 253 // A list of paths to icons this action might show. This is needed to support
201 // the legacy setIcon({iconIndex:...} method of the page actions API. 254 // the legacy setIcon({iconIndex:...} method of the page actions API.
202 std::vector<std::string> icon_paths_; 255 std::vector<std::string> icon_paths_;
203 }; 256 };
204 257
205 template<> 258 template<>
206 struct ExtensionAction::ValueTraits<int> { 259 struct ExtensionAction::ValueTraits<int> {
207 static int CreateEmpty() { 260 static int CreateEmpty() {
208 return -1; 261 return -1;
209 } 262 }
210 }; 263 };
211 264
212 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ 265 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698