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

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

Issue 10843014: Generalize ExtensionIconSet to store icon paths for custom size sets (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits 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_ICON_SET_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_ICON_SET_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_ICON_SET_H_ 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_ICON_SET_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 // Represents the set of icons for an extension. 11 // Represents the set of icons for an extension.
12 class ExtensionIconSet { 12 class ExtensionIconSet {
13 public: 13 public:
14 // NOTE: If you change this list, you should also change kIconSizes in the cc 14 // TODO(tbarzic): add types for extension actions and script badges.
15 // file. 15 enum IconSetType {
16 enum Icons { 16 ICON_SET_MANIFEST_ICONS
17 };
18
19 // NOTE: If you change this list, you should also change kManifestIconSizes in
20 // the cc file Icons {
Aaron Boodman 2012/08/10 23:01:57 s/ file Icons {/./
tbarzic 2012/08/11 00:58:45 Done.
21 enum ExtensionIcons {
17 EXTENSION_ICON_GIGANTOR = 512, 22 EXTENSION_ICON_GIGANTOR = 512,
18 EXTENSION_ICON_EXTRA_LARGE = 256, 23 EXTENSION_ICON_EXTRA_LARGE = 256,
19 EXTENSION_ICON_LARGE = 128, 24 EXTENSION_ICON_LARGE = 128,
20 EXTENSION_ICON_MEDIUM = 48, 25 EXTENSION_ICON_MEDIUM = 48,
21 EXTENSION_ICON_SMALL = 32, 26 EXTENSION_ICON_SMALL = 32,
22 EXTENSION_ICON_SMALLISH = 24, 27 EXTENSION_ICON_SMALLISH = 24,
23 EXTENSION_ICON_BITTY = 16, 28 EXTENSION_ICON_BITTY = 16,
24 EXTENSION_ICON_INVALID = 0, 29 EXTENSION_ICON_INVALID = 0,
25 }; 30 };
26 31
27 // Get an icon from the set, optionally falling back to a smaller or bigger 32 // Get an icon from the set, optionally falling back to a smaller or bigger
28 // size. MatchType is exclusive (do not OR them together). 33 // size. MatchType is exclusive (do not OR them together).
29 enum MatchType { 34 enum MatchType {
30 MATCH_EXACTLY, 35 MATCH_EXACTLY,
31 MATCH_BIGGER, 36 MATCH_BIGGER,
32 MATCH_SMALLER 37 MATCH_SMALLER
33 }; 38 };
34 39
35 // Access to the underlying map from icon size->path. 40 // Access to the underlying map from icon size->{path, bitmap}.
36 typedef std::map<Icons, std::string> IconMap; 41 typedef std::map<int, std::string> IconMap;
37 42
38 // Icon sizes used by the extension system. 43 explicit ExtensionIconSet(IconSetType type);
39 static const Icons kIconSizes[];
40 static const size_t kNumIconSizes;
41
42 ExtensionIconSet();
43 ~ExtensionIconSet(); 44 ~ExtensionIconSet();
44 45
45 const IconMap& map() const { return map_; } 46 const IconMap& map() const { return map_; }
46 47
47 // Remove all icons from the set. 48 // Remove all icons from the set.
48 void Clear(); 49 void Clear();
49 50
50 // Add an icon to the set. If the specified size is already present, it is 51 // Add an icon path to the set. If a path for the specified size is already
51 // overwritten. 52 // present, it is overwritten.
52 void Add(Icons size, const std::string& path); 53 void Add(int size, const std::string& path);
53 54
55 // Gets path value of the icon found when searching for |size| using
56 // |mathc_type|.
54 std::string Get(int size, MatchType match_type) const; 57 std::string Get(int size, MatchType match_type) const;
55 58
56 // Returns true if the set contains the specified path. 59 // Returns true iff the set contains the specified path.
57 bool ContainsPath(const std::string& path) const; 60 bool ContainsPath(const std::string& path) const;
58 61
59 // Returns icon size if the set contains the specified path or 0 if not found. 62 // Returns icon size if the set contains the specified path or 0 if not found.
60 Icons GetIconSizeFromPath(const std::string& path) const; 63 int GetIconSizeFromPath(const std::string& path) const;
64
65 const int* const allowed_sizes() const { return allowed_sizes_; }
66
67 size_t num_allowed_sizes() const { return num_allowed_sizes_; }
61 68
62 private: 69 private:
70 const int* allowed_sizes_;
71 size_t num_allowed_sizes_;
63 IconMap map_; 72 IconMap map_;
64 }; 73 };
65 74
66 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ICON_SET_H_ 75 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ICON_SET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698