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

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

Issue 10905005: Change browser/page action default icon defined in manifest to support hidpi. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review feedback Created 8 years, 3 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/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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 DISALLOW_COPY_AND_ASSIGN(IconAnimation); 118 DISALLOW_COPY_AND_ASSIGN(IconAnimation);
117 }; 119 };
118 120
119 ExtensionAction(const std::string& extension_id, Type action_type); 121 ExtensionAction(const std::string& extension_id, Type action_type);
120 ~ExtensionAction(); 122 ~ExtensionAction();
121 123
122 // Gets a copy of this, ownership passed to caller. 124 // Gets a copy of this, ownership passed to caller.
123 // It doesn't make sense to copy of an ExtensionAction except in tests. 125 // It doesn't make sense to copy of an ExtensionAction except in tests.
124 scoped_ptr<ExtensionAction> CopyForTest() const; 126 scoped_ptr<ExtensionAction> CopyForTest() const;
125 127
128 // Given the extension action type, returns the size the extension action icon
129 // should have. The icon should be square, so only one dimension is
130 // returned.
131 static int GetIconSizeForType(Type type);
132
126 // extension id 133 // extension id
127 const std::string& extension_id() const { return extension_id_; } 134 const std::string& extension_id() const { return extension_id_; }
128 135
129 // What kind of action is this? 136 // What kind of action is this?
130 Type action_type() const { return action_type_; } 137 Type action_type() const { return action_type_; }
131 138
132 // action id -- only used with legacy page actions API 139 // action id -- only used with legacy page actions API
133 std::string id() const { return id_; } 140 std::string id() const { return id_; }
134 void set_id(const std::string& id) { id_ = id; } 141 void set_id(const std::string& id) { id_ = id; }
135 142
(...skipping 15 matching lines...) Expand all
151 SetValue(&title_, tab_id, title); 158 SetValue(&title_, tab_id, title);
152 } 159 }
153 160
154 // If tab |tab_id| has a set title, return it. Otherwise, return 161 // If tab |tab_id| has a set title, return it. Otherwise, return
155 // the default title. 162 // the default title.
156 std::string GetTitle(int tab_id) const { return GetValue(&title_, tab_id); } 163 std::string GetTitle(int tab_id) const { return GetValue(&title_, tab_id); }
157 164
158 // Icons are a bit different because the default value can be set to either a 165 // Icons are a bit different because the default value can be set to either a
159 // bitmap or a path. However, conceptually, there is only one default icon. 166 // 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. 167 // Setting the default icon using a path clears the bitmap and vice-versa.
161 168 // To retrieve the icon for the extension action, use
162 // Since ExtensionAction, living in common/, can't interact with the browser 169 // ExtensionActionIconFactory.
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 170
169 // Set this action's icon bitmap on a specific tab. 171 // Set this action's icon bitmap on a specific tab.
170 void SetIcon(int tab_id, const gfx::Image& image); 172 void SetIcon(int tab_id, const gfx::Image& image);
171 173
172 // Get the icon for a tab, or the default if no icon was set for this tab, 174 // Applies the attention and animation image transformations registered for
173 // retrieving icons that have been specified by path from the previous 175 // the tab on the provided icon.
174 // arguments to CacheIcon(). If the default icon isn't found in the cache, 176 gfx::Image ApplyAttentionAndAnimation(const gfx::ImageSkia& icon,
175 // returns the puzzle piece icon. 177 int tab_id) const;
176 gfx::Image GetIcon(int tab_id) const;
177 178
178 // Gets the icon that has been set using |SetIcon| for the tab. 179 // Gets the icon that has been set using |SetIcon| for the tab.
179 gfx::ImageSkia GetExplicitlySetIcon(int tab_id) const; 180 gfx::ImageSkia GetExplicitlySetIcon(int tab_id) const;
180 181
181 // Non-tab-specific icon path. This is used to support the default_icon key of 182 // Non-tab-specific icon path. This is used to support the default_icon key of
182 // page and browser actions. 183 // page and browser actions.
183 void set_default_icon_path(const std::string& path) { 184 void set_default_icon(scoped_ptr<ExtensionIconSet> icon_set) {
184 default_icon_path_ = path; 185 default_icon_ = icon_set.Pass();
185 } 186 }
186 const std::string& default_icon_path() const { 187
187 return default_icon_path_; 188 const ExtensionIconSet* default_icon() const {
189 return default_icon_.get();
188 } 190 }
189 191
190 // Set this action's badge text on a specific tab. 192 // Set this action's badge text on a specific tab.
191 void SetBadgeText(int tab_id, const std::string& text) { 193 void SetBadgeText(int tab_id, const std::string& text) {
192 SetValue(&badge_text_, tab_id, text); 194 SetValue(&badge_text_, tab_id, text);
193 } 195 }
194 // Get the badge text for a tab, or the default if no badge text was set. 196 // Get the badge text for a tab, or the default if no badge text was set.
195 std::string GetBadgeText(int tab_id) const { 197 std::string GetBadgeText(int tab_id) const {
196 return GetValue(&badge_text_, tab_id); 198 return GetValue(&badge_text_, tab_id);
197 } 199 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 class IconWithBadgeImageSource; 247 class IconWithBadgeImageSource;
246 248
247 // Runs an animation on a tab. 249 // Runs an animation on a tab.
248 void RunIconAnimation(int tab_id); 250 void RunIconAnimation(int tab_id);
249 251
250 // If the icon animation is running on tab |tab_id|, applies it to 252 // If the icon animation is running on tab |tab_id|, applies it to
251 // |orig| and returns the result. Otherwise, just returns |orig|. 253 // |orig| and returns the result. Otherwise, just returns |orig|.
252 gfx::ImageSkia ApplyIconAnimation(int tab_id, 254 gfx::ImageSkia ApplyIconAnimation(int tab_id,
253 const gfx::ImageSkia& orig) const; 255 const gfx::ImageSkia& orig) const;
254 256
257 // Returns width of the current icon for tab_id.
258 // TODO(tbarzic): The icon selection is done in ExtensionActionIconFactory.
259 // We should probably move this there too.
260 int GetIconWidth(int tab_id) const;
261
255 // Paints badge with specified parameters to |canvas|. 262 // Paints badge with specified parameters to |canvas|.
256 static void DoPaintBadge(gfx::Canvas* canvas, 263 static void DoPaintBadge(gfx::Canvas* canvas,
257 const gfx::Rect& bounds, 264 const gfx::Rect& bounds,
258 const std::string& text, 265 const std::string& text,
259 const SkColor& text_color_in, 266 const SkColor& text_color_in,
260 const SkColor& background_color_in, 267 const SkColor& background_color_in,
261 int icon_width); 268 int icon_width);
262 269
263 template <class T> 270 template <class T>
264 struct ValueTraits { 271 struct ValueTraits {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 std::map<int, SkColor> badge_text_color_; 306 std::map<int, SkColor> badge_text_color_;
300 std::map<int, Appearance> appearance_; 307 std::map<int, Appearance> appearance_;
301 308
302 // IconAnimations are destroyed by a delayed task on the UI message loop so 309 // 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 310 // 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 311 // 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 312 // causes the WeakPtr in this map to become NULL. GetIconAnimation() removes
306 // NULLs to prevent the map from growing without bound. 313 // NULLs to prevent the map from growing without bound.
307 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_; 314 mutable std::map<int, base::WeakPtr<IconAnimation> > icon_animation_;
308 315
309 std::string default_icon_path_; 316 // ExtensionIconSet containing paths to bitmaps from which default icon's
317 // image representations will be selected.
318 scoped_ptr<const ExtensionIconSet> default_icon_;
310 319
311 // The id for the ExtensionAction, for example: "RssPageAction". This is 320 // The id for the ExtensionAction, for example: "RssPageAction". This is
312 // needed for compat with an older version of the page actions API. 321 // needed for compat with an older version of the page actions API.
313 std::string id_; 322 std::string id_;
314 323
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 324 // True if the ExtensionAction's settings have changed from what was
319 // specified in the manifest. 325 // specified in the manifest.
320 bool has_changed_; 326 bool has_changed_;
321 327
322 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); 328 DISALLOW_COPY_AND_ASSIGN(ExtensionAction);
323 }; 329 };
324 330
325 template<> 331 template<>
326 struct ExtensionAction::ValueTraits<int> { 332 struct ExtensionAction::ValueTraits<int> {
327 static int CreateEmpty() { 333 static int CreateEmpty() {
328 return -1; 334 return -1;
329 } 335 }
330 }; 336 };
331 337
332 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ 338 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698