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> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/scoped_vector.h" | |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
18 #include "chrome/common/extensions/extension_icon_set.h" | |
17 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
18 #include "ui/base/animation/linear_animation.h" | 20 #include "ui/base/animation/linear_animation.h" |
19 | 21 |
20 class GURL; | 22 class GURL; |
21 class SkBitmap; | 23 class SkBitmap; |
22 class SkDevice; | 24 class SkDevice; |
23 | 25 |
24 namespace gfx { | 26 namespace gfx { |
25 class Canvas; | 27 class Canvas; |
26 class Image; | 28 class Image; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 | 150 |
149 // Set this action's title on a specific tab. | 151 // Set this action's title on a specific tab. |
150 void SetTitle(int tab_id, const std::string& title) { | 152 void SetTitle(int tab_id, const std::string& title) { |
151 SetValue(&title_, tab_id, title); | 153 SetValue(&title_, tab_id, title); |
152 } | 154 } |
153 | 155 |
154 // If tab |tab_id| has a set title, return it. Otherwise, return | 156 // If tab |tab_id| has a set title, return it. Otherwise, return |
155 // the default title. | 157 // the default title. |
156 std::string GetTitle(int tab_id) const { return GetValue(&title_, tab_id); } | 158 std::string GetTitle(int tab_id) const { return GetValue(&title_, tab_id); } |
157 | 159 |
158 // Icons are a bit different because the default value can be set to either a | 160 // Icons are a bit different because the default value can be set to either a |
Jeffrey Yasskin
2012/09/14 23:47:12
We should have a comment saying to retrieve an Ext
tbarzic
2012/09/15 00:29:10
Done.
| |
159 // bitmap or a path. However, conceptually, there is only one default icon. | 161 // bitmap or a path. However, conceptually, there is only one default icon. |
160 // Setting the default icon using a path clears the bitmap and vice-versa. | 162 // Setting the default icon using a path clears the bitmap and vice-versa. |
161 | 163 |
162 // Since ExtensionAction, living in common/, can't interact with the browser | |
163 // to load images, the UI code needs to load the icon. Load the image there | |
164 // using an ImageLoadingTracker and call CacheIcon(image) with the result. | |
165 // | |
166 // If an image is cached redundantly, the first load will be used. | |
167 void CacheIcon(const gfx::Image& icon); | |
168 | |
169 // Set this action's icon bitmap on a specific tab. | 164 // Set this action's icon bitmap on a specific tab. |
170 void SetIcon(int tab_id, const gfx::Image& image); | 165 void SetIcon(int tab_id, const gfx::Image& image); |
171 | 166 |
172 // Get the icon for a tab, or the default if no icon was set for this tab, | 167 // Applies the attention and animation image transformations registered for |
173 // retrieving icons that have been specified by path from the previous | 168 // the tab on the provided icon. |
174 // arguments to CacheIcon(). If the default icon isn't found in the cache, | 169 gfx::Image ApplyAttentionAndAnimation(const gfx::ImageSkia& icon, |
Jeffrey Yasskin
2012/09/14 23:47:12
At some point, the icon-manipulation code should m
tbarzic
2012/09/15 00:29:10
yeah, I agree..
| |
175 // returns the puzzle piece icon. | 170 int tab_id) const; |
176 gfx::Image GetIcon(int tab_id) const; | |
177 | 171 |
178 // Gets the icon that has been set using |SetIcon| for the tab. | 172 // Gets the icon that has been set using |SetIcon| for the tab. |
179 gfx::ImageSkia GetExplicitlySetIcon(int tab_id) const; | 173 gfx::ImageSkia GetExplicitlySetIcon(int tab_id) const; |
180 | 174 |
181 // Non-tab-specific icon path. This is used to support the default_icon key of | 175 // Non-tab-specific icon path. This is used to support the default_icon key of |
182 // page and browser actions. | 176 // page and browser actions. |
183 void set_default_icon_path(const std::string& path) { | 177 void set_default_icon(scoped_ptr<ExtensionIconSet> icon_set) { |
184 default_icon_path_ = path; | 178 default_icon_ = icon_set.Pass(); |
185 } | 179 } |
186 const std::string& default_icon_path() const { | 180 |
187 return default_icon_path_; | 181 const ExtensionIconSet* default_icon() const { |
182 return default_icon_.get(); | |
188 } | 183 } |
189 | 184 |
190 // Set this action's badge text on a specific tab. | 185 // Set this action's badge text on a specific tab. |
191 void SetBadgeText(int tab_id, const std::string& text) { | 186 void SetBadgeText(int tab_id, const std::string& text) { |
192 SetValue(&badge_text_, tab_id, text); | 187 SetValue(&badge_text_, tab_id, text); |
193 } | 188 } |
194 // Get the badge text for a tab, or the default if no badge text was set. | 189 // Get the badge text for a tab, or the default if no badge text was set. |
195 std::string GetBadgeText(int tab_id) const { | 190 std::string GetBadgeText(int tab_id) const { |
196 return GetValue(&badge_text_, tab_id); | 191 return GetValue(&badge_text_, tab_id); |
197 } | 192 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 class IconWithBadgeImageSource; | 240 class IconWithBadgeImageSource; |
246 | 241 |
247 // Runs an animation on a tab. | 242 // Runs an animation on a tab. |
248 void RunIconAnimation(int tab_id); | 243 void RunIconAnimation(int tab_id); |
249 | 244 |
250 // If the icon animation is running on tab |tab_id|, applies it to | 245 // If the icon animation is running on tab |tab_id|, applies it to |
251 // |orig| and returns the result. Otherwise, just returns |orig|. | 246 // |orig| and returns the result. Otherwise, just returns |orig|. |
252 gfx::ImageSkia ApplyIconAnimation(int tab_id, | 247 gfx::ImageSkia ApplyIconAnimation(int tab_id, |
253 const gfx::ImageSkia& orig) const; | 248 const gfx::ImageSkia& orig) const; |
254 | 249 |
250 // Returns width of the current icon for tab_id. | |
251 // TODO(tbarzic): The icon selection is done in ExtensionActionIconFactory. | |
252 // We should probably move this there too. | |
253 int GetIconWidth(int tab_id) const; | |
254 | |
255 // Paints badge with specified parameters to |canvas|. | 255 // Paints badge with specified parameters to |canvas|. |
256 static void DoPaintBadge(gfx::Canvas* canvas, | 256 static void DoPaintBadge(gfx::Canvas* canvas, |
257 const gfx::Rect& bounds, | 257 const gfx::Rect& bounds, |
258 const std::string& text, | 258 const std::string& text, |
259 const SkColor& text_color_in, | 259 const SkColor& text_color_in, |
260 const SkColor& background_color_in, | 260 const SkColor& background_color_in, |
261 int icon_width); | 261 int icon_width); |
262 | 262 |
263 template <class T> | 263 template <class T> |
264 struct ValueTraits { | 264 struct ValueTraits { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 std::map<int, SkColor> badge_text_color_; | 299 std::map<int, SkColor> badge_text_color_; |
300 std::map<int, Appearance> appearance_; | 300 std::map<int, Appearance> appearance_; |
301 | 301 |
302 // IconAnimations are destroyed by a delayed task on the UI message loop so | 302 // IconAnimations are destroyed by a delayed task on the UI message loop so |
303 // that even if the Extension and ExtensionAction are destroyed on a non-UI | 303 // that even if the Extension and ExtensionAction are destroyed on a non-UI |
304 // thread, the animation will still only be touched from the UI thread. This | 304 // thread, the animation will still only be touched from the UI thread. This |
305 // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes | 305 // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes |
306 // NULLs to prevent the map from growing without bound. | 306 // NULLs to prevent the map from growing without bound. |
307 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_; | 307 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_; |
308 | 308 |
309 std::string default_icon_path_; | 309 // ExtensionIconSet containing paths to bitmaps from which default icon's |
310 // image representations will be selected. | |
311 scoped_ptr<const ExtensionIconSet> default_icon_; | |
310 | 312 |
311 // The id for the ExtensionAction, for example: "RssPageAction". This is | 313 // The id for the ExtensionAction, for example: "RssPageAction". This is |
312 // needed for compat with an older version of the page actions API. | 314 // needed for compat with an older version of the page actions API. |
313 std::string id_; | 315 std::string id_; |
314 | 316 |
315 // Saves the arguments from CacheIcon() calls. | |
316 scoped_ptr<gfx::ImageSkia> cached_icon_; | |
317 | |
318 // True if the ExtensionAction's settings have changed from what was | 317 // True if the ExtensionAction's settings have changed from what was |
319 // specified in the manifest. | 318 // specified in the manifest. |
320 bool has_changed_; | 319 bool has_changed_; |
321 | 320 |
322 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); | 321 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); |
323 }; | 322 }; |
324 | 323 |
325 template<> | 324 template<> |
326 struct ExtensionAction::ValueTraits<int> { | 325 struct ExtensionAction::ValueTraits<int> { |
327 static int CreateEmpty() { | 326 static int CreateEmpty() { |
328 return -1; | 327 return -1; |
329 } | 328 } |
330 }; | 329 }; |
331 | 330 |
332 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ | 331 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ |
OLD | NEW |