| 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 #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" | 14 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "chrome/common/extensions/icon_transform.h" |
| 18 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
| 19 #include "ui/base/animation/linear_animation.h" | 20 #include "ui/base/animation/linear_animation.h" |
| 20 | 21 |
| 21 class GURL; | 22 class GURL; |
| 22 class SkBitmap; | 23 class SkBitmap; |
| 23 class SkDevice; | |
| 24 | 24 |
| 25 namespace gfx { | 25 namespace gfx { |
| 26 class Canvas; | 26 class Canvas; |
| 27 class Rect; | 27 class Rect; |
| 28 } | 28 } |
| 29 | 29 |
| 30 // ExtensionAction encapsulates the state of a browser action, page action, or | 30 // ExtensionAction encapsulates the state of a browser action, page action, or |
| 31 // script badge. | 31 // script badge. |
| 32 // 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 |
| 33 // a per-tab value, the global value is used instead. | 33 // a per-tab value, the global value is used instead. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 void RemoveObserver(Observer* observer); | 86 void RemoveObserver(Observer* observer); |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 // Construct using ExtensionAction::RunIconAnimation(). | 89 // Construct using ExtensionAction::RunIconAnimation(). |
| 90 friend class ExtensionAction; | 90 friend class ExtensionAction; |
| 91 explicit IconAnimation(ui::AnimationDelegate* delegate); | 91 explicit IconAnimation(ui::AnimationDelegate* delegate); |
| 92 | 92 |
| 93 // ui::LinearAnimation implementation. | 93 // ui::LinearAnimation implementation. |
| 94 virtual void AnimateToState(double state) OVERRIDE; | 94 virtual void AnimateToState(double state) OVERRIDE; |
| 95 | 95 |
| 96 // Device we use to paint icons to. | 96 // Transformation to apply to the icon when rendered. |
| 97 mutable scoped_ptr<SkDevice> device_; | 97 mutable extensions::IconTransform icon_transform_; |
| 98 | 98 |
| 99 ObserverList<Observer> observers_; | 99 ObserverList<Observer> observers_; |
| 100 | 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(IconAnimation); | 101 DISALLOW_COPY_AND_ASSIGN(IconAnimation); |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 ExtensionAction(const std::string& extension_id, Type action_type); | 104 ExtensionAction(const std::string& extension_id, Type action_type); |
| 105 ~ExtensionAction(); | 105 ~ExtensionAction(); |
| 106 | 106 |
| 107 // Gets a copy of this, ownership passed to caller. | 107 // Gets a copy of this, ownership passed to caller. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // If the specified tab has a badge, paint it into the provided bounds. | 217 // If the specified tab has a badge, paint it into the provided bounds. |
| 218 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id); | 218 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id); |
| 219 | 219 |
| 220 // Gets a weak reference to the icon animation for a tab, if any. The | 220 // Gets a weak reference to the icon animation for a tab, if any. The |
| 221 // reference will only have a value while the animation is running. | 221 // reference will only have a value while the animation is running. |
| 222 base::WeakPtr<IconAnimation> GetIconAnimation(int tab_id) const; | 222 base::WeakPtr<IconAnimation> GetIconAnimation(int tab_id) const; |
| 223 | 223 |
| 224 // Runs an animation on a tab. | 224 // Runs an animation on a tab. |
| 225 void RunIconAnimation(int tab_id); | 225 void RunIconAnimation(int tab_id); |
| 226 | 226 |
| 227 // Renders |icon| in the "visible" state for |tab_id|: if visible then |
| 228 // normal, if invisible then faded. This function only makes sense for |
| 229 // browser actions; for page actions, not-visibile should imply not showing at |
| 230 // all for that tab. |
| 231 const SkBitmap& RenderIconVisibility(const SkBitmap& icon, int tab_id) const; |
| 232 |
| 227 private: | 233 private: |
| 228 template <class T> | 234 template <class T> |
| 229 struct ValueTraits { | 235 struct ValueTraits { |
| 230 static T CreateEmpty() { | 236 static T CreateEmpty() { |
| 231 return T(); | 237 return T(); |
| 232 } | 238 } |
| 233 }; | 239 }; |
| 234 | 240 |
| 235 template<class T> | 241 template<class T> |
| 236 void SetValue(std::map<int, T>* map, int tab_id, const T& val) { | 242 void SetValue(std::map<int, T>* map, int tab_id, const T& val) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 std::string default_icon_path_; | 277 std::string default_icon_path_; |
| 272 | 278 |
| 273 // The id for the ExtensionAction, for example: "RssPageAction". This is | 279 // The id for the ExtensionAction, for example: "RssPageAction". This is |
| 274 // needed for compat with an older version of the page actions API. | 280 // needed for compat with an older version of the page actions API. |
| 275 std::string id_; | 281 std::string id_; |
| 276 | 282 |
| 277 // A list of paths to icons this action might show. This is needed to support | 283 // A list of paths to icons this action might show. This is needed to support |
| 278 // the legacy setIcon({iconIndex:...} method of the page actions API. | 284 // the legacy setIcon({iconIndex:...} method of the page actions API. |
| 279 std::vector<std::string> icon_paths_; | 285 std::vector<std::string> icon_paths_; |
| 280 | 286 |
| 287 // Transformation to apply to the icon when rendered. |
| 288 mutable extensions::IconTransform icon_transform_; |
| 289 |
| 281 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); | 290 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); |
| 282 }; | 291 }; |
| 283 | 292 |
| 284 template<> | 293 template<> |
| 285 struct ExtensionAction::ValueTraits<int> { | 294 struct ExtensionAction::ValueTraits<int> { |
| 286 static int CreateEmpty() { | 295 static int CreateEmpty() { |
| 287 return -1; | 296 return -1; |
| 288 } | 297 } |
| 289 }; | 298 }; |
| 290 | 299 |
| 291 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ | 300 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ |
| OLD | NEW |