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

Side by Side Diff: chrome/common/extensions/extension_action.h

Issue 10827191: Convert extension action icons code to use ImageSkia instead of SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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 | Annotate | Revision Log
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 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/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "third_party/skia/include/core/SkColor.h" 17 #include "third_party/skia/include/core/SkColor.h"
18 #include "ui/base/animation/linear_animation.h" 18 #include "ui/base/animation/linear_animation.h"
19 19
20 class GURL; 20 class GURL;
21 class SkBitmap; 21 class SkBitmap;
22 class SkDevice; 22 class SkDevice;
23 23
24 namespace gfx { 24 namespace gfx {
25 class Canvas; 25 class Canvas;
26 class Image; 26 class Image;
27 class ImageSkia;
27 class Rect; 28 class Rect;
29 class Size;
28 } 30 }
29 31
30 // ExtensionAction encapsulates the state of a browser action, page action, or 32 // ExtensionAction encapsulates the state of a browser action, page action, or
31 // script badge. 33 // script badge.
32 // Instances can have both global and per-tab state. If a property does not have 34 // 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. 35 // a per-tab value, the global value is used instead.
34 class ExtensionAction { 36 class ExtensionAction {
35 public: 37 public:
36 // Use this ID to indicate the default state for properties that take a tab_id 38 // Use this ID to indicate the default state for properties that take a tab_id
37 // parameter. 39 // parameter.
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 bool GetIsVisible(int tab_id) const { 235 bool GetIsVisible(int tab_id) const {
234 return GetValue(&appearance_, tab_id) != INVISIBLE; 236 return GetValue(&appearance_, tab_id) != INVISIBLE;
235 } 237 }
236 238
237 // Remove all tab-specific state. 239 // Remove all tab-specific state.
238 void ClearAllValuesForTab(int tab_id); 240 void ClearAllValuesForTab(int tab_id);
239 241
240 // If the specified tab has a badge, paint it into the provided bounds. 242 // If the specified tab has a badge, paint it into the provided bounds.
241 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id); 243 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id);
242 244
245 // Returns icon image with badge for specified tab.
246 gfx::ImageSkia GetIconWithBadge(const gfx::ImageSkia& icon,
247 int tab_id,
248 const gfx::Size& spacing) const;
249
243 // Gets a weak reference to the icon animation for a tab, if any. The 250 // Gets a weak reference to the icon animation for a tab, if any. The
244 // reference will only have a value while the animation is running. 251 // reference will only have a value while the animation is running.
245 base::WeakPtr<IconAnimation> GetIconAnimation(int tab_id) const; 252 base::WeakPtr<IconAnimation> GetIconAnimation(int tab_id) const;
246 253
247 private: 254 private:
255 class IconAnimationWrapper;
256 class IconWithBadgeImageSource;
257
248 // Runs an animation on a tab. 258 // Runs an animation on a tab.
249 void RunIconAnimation(int tab_id); 259 void RunIconAnimation(int tab_id);
250 260
251 class IconAnimationWrapper;
252
253 // Finds the icon animation wrapper for a tab, if any. If the animation for 261 // Finds the icon animation wrapper for a tab, if any. If the animation for
254 // this tab has recently completed, also removes up any other dead wrappers 262 // this tab has recently completed, also removes up any other dead wrappers
255 // from the map. 263 // from the map.
256 IconAnimationWrapper* GetIconAnimationWrapper(int tab_id) const; 264 IconAnimationWrapper* GetIconAnimationWrapper(int tab_id) const;
257 265
258 // If the icon animation is running on tab |tab_id|, applies it to 266 // If the icon animation is running on tab |tab_id|, applies it to
259 // |orig| and returns the result. Otherwise, just returns |orig|. 267 // |orig| and returns the result. Otherwise, just returns |orig|.
260 gfx::Image ApplyIconAnimation(int tab_id, const gfx::Image& orig) const; 268 gfx::ImageSkia ApplyIconAnimation(int tab_id,
269 const gfx::ImageSkia& orig) const;
270
271 // Paints badge with specified parameters to |canvas|.
272 static void DoPaintBadge(gfx::Canvas* canvas,
273 const gfx::Rect& bounds,
274 const std::string& text,
275 const SkColor& text_color_in,
276 const SkColor& background_color_in,
277 int icon_width);
261 278
262 template <class T> 279 template <class T>
263 struct ValueTraits { 280 struct ValueTraits {
264 static T CreateEmpty() { 281 static T CreateEmpty() {
265 return T(); 282 return T();
266 } 283 }
267 }; 284 };
268 285
269 template<class T> 286 template<class T>
270 void SetValue(std::map<int, T>* map, int tab_id, const T& val) { 287 void SetValue(std::map<int, T>* map, int tab_id, const T& val) {
(...skipping 14 matching lines...) Expand all
285 // The id for the extension this action belongs to (as defined in the 302 // The id for the extension this action belongs to (as defined in the
286 // extension manifest). 303 // extension manifest).
287 const std::string extension_id_; 304 const std::string extension_id_;
288 305
289 const Type action_type_; 306 const Type action_type_;
290 307
291 // Each of these data items can have both a global state (stored with the key 308 // Each of these data items can have both a global state (stored with the key
292 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key). 309 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key).
293 std::map<int, GURL> popup_url_; 310 std::map<int, GURL> popup_url_;
294 std::map<int, std::string> title_; 311 std::map<int, std::string> title_;
295 std::map<int, gfx::Image> icon_; 312 std::map<int, gfx::ImageSkia> icon_;
296 std::map<int, int> icon_index_; // index into icon_paths_ 313 std::map<int, int> icon_index_; // index into icon_paths_
297 std::map<int, std::string> badge_text_; 314 std::map<int, std::string> badge_text_;
298 std::map<int, SkColor> badge_background_color_; 315 std::map<int, SkColor> badge_background_color_;
299 std::map<int, SkColor> badge_text_color_; 316 std::map<int, SkColor> badge_text_color_;
300 std::map<int, Appearance> appearance_; 317 std::map<int, Appearance> appearance_;
301 318
302 // IconAnimationWrappers own themselves so that even if the Extension and 319 // IconAnimationWrappers own themselves so that even if the Extension and
303 // ExtensionAction are destroyed on a non-UI thread, the animation will still 320 // ExtensionAction are destroyed on a non-UI thread, the animation will still
304 // only be touched from the UI thread. When an animation finishes, it deletes 321 // only be touched from the UI thread. When an animation finishes, it deletes
305 // itself, which causes the WeakPtr in this map to become NULL. 322 // itself, which causes the WeakPtr in this map to become NULL.
306 // GetIconAnimationWrapper() removes NULLs to prevent the map from growing 323 // GetIconAnimationWrapper() removes NULLs to prevent the map from growing
307 // without bound. 324 // without bound.
308 mutable std::map<int, base::WeakPtr<IconAnimationWrapper> > icon_animation_; 325 mutable std::map<int, base::WeakPtr<IconAnimationWrapper> > icon_animation_;
309 326
310 std::string default_icon_path_; 327 std::string default_icon_path_;
311 328
312 // The id for the ExtensionAction, for example: "RssPageAction". This is 329 // The id for the ExtensionAction, for example: "RssPageAction". This is
313 // needed for compat with an older version of the page actions API. 330 // needed for compat with an older version of the page actions API.
314 std::string id_; 331 std::string id_;
315 332
316 // A list of paths to icons this action might show. This is needed to support 333 // A list of paths to icons this action might show. This is needed to support
317 // the legacy setIcon({iconIndex:...} method of the page actions API. 334 // the legacy setIcon({iconIndex:...} method of the page actions API.
318 std::vector<std::string> icon_paths_; 335 std::vector<std::string> icon_paths_;
319 336
320 // Saves the arguments from CacheIcon() calls. 337 // Saves the arguments from CacheIcon() calls.
321 std::map<std::string, gfx::Image> path_to_icon_cache_; 338 std::map<std::string, gfx::ImageSkia> path_to_icon_cache_;
322 339
323 // True if the ExtensionAction's settings have changed from what was 340 // True if the ExtensionAction's settings have changed from what was
324 // specified in the manifest. 341 // specified in the manifest.
325 bool has_changed_; 342 bool has_changed_;
326 343
327 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); 344 DISALLOW_COPY_AND_ASSIGN(ExtensionAction);
328 }; 345 };
329 346
330 template<> 347 template<>
331 struct ExtensionAction::ValueTraits<int> { 348 struct ExtensionAction::ValueTraits<int> {
332 static int CreateEmpty() { 349 static int CreateEmpty() {
333 return -1; 350 return -1;
334 } 351 }
335 }; 352 };
336 353
337 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ 354 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698