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 #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 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 26 matching lines...) Expand all Loading... |
37 // parameter. | 37 // parameter. |
38 static const int kDefaultTabId; | 38 static const int kDefaultTabId; |
39 | 39 |
40 // The types of extension actions. | 40 // The types of extension actions. |
41 enum Type { | 41 enum Type { |
42 TYPE_BROWSER, | 42 TYPE_BROWSER, |
43 TYPE_PAGE, | 43 TYPE_PAGE, |
44 TYPE_SCRIPT_BADGE, | 44 TYPE_SCRIPT_BADGE, |
45 }; | 45 }; |
46 | 46 |
| 47 enum Appearance { |
| 48 // The action icon is hidden. |
| 49 INVISIBLE, |
| 50 // The action is trying to get the user's attention but isn't yet |
| 51 // running on the page. Currently only used for script badges. |
| 52 WANTS_ATTENTION, |
| 53 // The action icon is visible with its normal appearance. |
| 54 ACTIVE, |
| 55 }; |
| 56 |
47 // A fade-in animation. | 57 // A fade-in animation. |
48 class IconAnimation : public ui::LinearAnimation, | 58 class IconAnimation : public ui::LinearAnimation, |
49 public base::SupportsWeakPtr<IconAnimation> { | 59 public base::SupportsWeakPtr<IconAnimation> { |
50 public: | 60 public: |
51 // Observes changes to icon animation state. | 61 // Observes changes to icon animation state. |
52 class Observer { | 62 class Observer { |
53 public: | 63 public: |
54 virtual void OnIconChanged(const IconAnimation& animation) = 0; | 64 virtual void OnIconChanged(const IconAnimation& animation) = 0; |
55 | 65 |
56 protected: | 66 protected: |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // Set this action's badge background color on a specific tab. | 214 // Set this action's badge background color on a specific tab. |
205 void SetBadgeBackgroundColor(int tab_id, SkColor color) { | 215 void SetBadgeBackgroundColor(int tab_id, SkColor color) { |
206 SetValue(&badge_background_color_, tab_id, color); | 216 SetValue(&badge_background_color_, tab_id, color); |
207 } | 217 } |
208 // Get the badge background color for a tab, or the default if no color | 218 // Get the badge background color for a tab, or the default if no color |
209 // was set. | 219 // was set. |
210 SkColor GetBadgeBackgroundColor(int tab_id) const { | 220 SkColor GetBadgeBackgroundColor(int tab_id) const { |
211 return GetValue(&badge_background_color_, tab_id); | 221 return GetValue(&badge_background_color_, tab_id); |
212 } | 222 } |
213 | 223 |
214 // Set this action's badge visibility on a specific tab. | 224 // Set this action's badge visibility on a specific tab. This takes |
215 void SetIsVisible(int tab_id, bool value) { | 225 // care of any appropriate transition animations. Returns true if |
216 SetValue(&visible_, tab_id, value); | 226 // the appearance has changed. |
217 } | 227 bool SetAppearance(int tab_id, Appearance value); |
218 // Get the badge visibility for a tab, or the default badge visibility | 228 // Get the badge visibility for a tab, or the default badge visibility |
219 // if none was set. | 229 // if none was set. |
220 bool GetIsVisible(int tab_id) const { | 230 bool GetIsVisible(int tab_id) const { |
221 return GetValue(&visible_, tab_id); | 231 return GetValue(&appearance_, tab_id) != INVISIBLE; |
222 } | 232 } |
223 | 233 |
224 // Remove all tab-specific state. | 234 // Remove all tab-specific state. |
225 void ClearAllValuesForTab(int tab_id); | 235 void ClearAllValuesForTab(int tab_id); |
226 | 236 |
227 // If the specified tab has a badge, paint it into the provided bounds. | 237 // If the specified tab has a badge, paint it into the provided bounds. |
228 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id); | 238 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id); |
229 | 239 |
230 // Gets a weak reference to the icon animation for a tab, if any. The | 240 // Gets a weak reference to the icon animation for a tab, if any. The |
231 // reference will only have a value while the animation is running. | 241 // reference will only have a value while the animation is running. |
232 base::WeakPtr<IconAnimation> GetIconAnimation(int tab_id) const; | 242 base::WeakPtr<IconAnimation> GetIconAnimation(int tab_id) const; |
233 | 243 |
| 244 private: |
234 // Runs an animation on a tab. | 245 // Runs an animation on a tab. |
235 void RunIconAnimation(int tab_id); | 246 void RunIconAnimation(int tab_id); |
236 | 247 |
237 private: | |
238 class IconAnimationWrapper; | 248 class IconAnimationWrapper; |
239 | 249 |
240 // Finds the icon animation wrapper for a tab, if any. If the animation for | 250 // Finds the icon animation wrapper for a tab, if any. If the animation for |
241 // this tab has recently completed, also removes up any other dead wrappers | 251 // this tab has recently completed, also removes up any other dead wrappers |
242 // from the map. | 252 // from the map. |
243 IconAnimationWrapper* GetIconAnimationWrapper(int tab_id) const; | 253 IconAnimationWrapper* GetIconAnimationWrapper(int tab_id) const; |
244 | 254 |
245 // If the icon animation is running on tab |tab_id|, applies it to | 255 // If the icon animation is running on tab |tab_id|, applies it to |
246 // |orig| and returns the result. Otherwise, just returns |orig|. | 256 // |orig| and returns the result. Otherwise, just returns |orig|. |
247 gfx::Image ApplyIconAnimation(int tab_id, const gfx::Image& orig) const; | 257 gfx::Image ApplyIconAnimation(int tab_id, const gfx::Image& orig) const; |
(...skipping 29 matching lines...) Expand all Loading... |
277 | 287 |
278 // Each of these data items can have both a global state (stored with the key | 288 // Each of these data items can have both a global state (stored with the key |
279 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key). | 289 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key). |
280 std::map<int, GURL> popup_url_; | 290 std::map<int, GURL> popup_url_; |
281 std::map<int, std::string> title_; | 291 std::map<int, std::string> title_; |
282 std::map<int, gfx::Image> icon_; | 292 std::map<int, gfx::Image> icon_; |
283 std::map<int, int> icon_index_; // index into icon_paths_ | 293 std::map<int, int> icon_index_; // index into icon_paths_ |
284 std::map<int, std::string> badge_text_; | 294 std::map<int, std::string> badge_text_; |
285 std::map<int, SkColor> badge_background_color_; | 295 std::map<int, SkColor> badge_background_color_; |
286 std::map<int, SkColor> badge_text_color_; | 296 std::map<int, SkColor> badge_text_color_; |
287 std::map<int, bool> visible_; | 297 std::map<int, Appearance> appearance_; |
288 | 298 |
289 // IconAnimationWrappers own themselves so that even if the Extension and | 299 // IconAnimationWrappers own themselves so that even if the Extension and |
290 // ExtensionAction are destroyed on a non-UI thread, the animation will still | 300 // ExtensionAction are destroyed on a non-UI thread, the animation will still |
291 // only be touched from the UI thread. When an animation finishes, it deletes | 301 // only be touched from the UI thread. When an animation finishes, it deletes |
292 // itself, which causes the WeakPtr in this map to become NULL. | 302 // itself, which causes the WeakPtr in this map to become NULL. |
293 // GetIconAnimationWrapper() removes NULLs to prevent the map from growing | 303 // GetIconAnimationWrapper() removes NULLs to prevent the map from growing |
294 // without bound. | 304 // without bound. |
295 mutable std::map<int, base::WeakPtr<IconAnimationWrapper> > icon_animation_; | 305 mutable std::map<int, base::WeakPtr<IconAnimationWrapper> > icon_animation_; |
296 | 306 |
297 std::string default_icon_path_; | 307 std::string default_icon_path_; |
(...skipping 13 matching lines...) Expand all Loading... |
311 }; | 321 }; |
312 | 322 |
313 template<> | 323 template<> |
314 struct ExtensionAction::ValueTraits<int> { | 324 struct ExtensionAction::ValueTraits<int> { |
315 static int CreateEmpty() { | 325 static int CreateEmpty() { |
316 return -1; | 326 return -1; |
317 } | 327 } |
318 }; | 328 }; |
319 | 329 |
320 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ | 330 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ |
OLD | NEW |