Chromium Code Reviews| 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_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 | 27 |
| 28 // A class that provides an ImageSkia for UI code to use. It handles extension | 28 // A class that provides an ImageSkia for UI code to use. It handles extension |
| 29 // icon resource loading, screen scale factor change etc. UI code that uses | 29 // icon resource loading, screen scale factor change etc. UI code that uses |
| 30 // extension icon should host this class and be its observer. ExtensionIconImage | 30 // extension icon should host this class and be its observer. ExtensionIconImage |
| 31 // should be outlived by the observer. In painting code, UI code paints with the | 31 // should be outlived by the observer. In painting code, UI code paints with the |
| 32 // ImageSkia provided by this class. If required extension icon resource is not | 32 // ImageSkia provided by this class. If required extension icon resource is not |
| 33 // present, this class uses ImageLoadingTracker to load it and call on its | 33 // present, this class uses ImageLoadingTracker to load it and call on its |
| 34 // observer interface when the resource is loaded. | 34 // observer interface when the resource is loaded. Until the resource is loaded, |
| 35 // the UI code will be provided with blank, transparent image representation. | |
|
Jeffrey Yasskin
2012/08/31 18:43:14
Do we want to return a blank image or the default
tbarzic
2012/08/31 22:29:44
blank image.. Aaron had some concerns that returni
| |
| 36 // UI code can supply default icon whose representations will be added to the | |
|
Jeffrey Yasskin
2012/08/31 18:43:14
By "can supply", you mean |default_icon| can be em
Jeffrey Yasskin
2012/08/31 18:43:14
I think this comment could use a more detailed des
tbarzic
2012/08/31 22:29:44
yeah, and in that case, if image rep is not loaded
tbarzic
2012/08/31 22:29:44
ok, I've rewritten larger part of the comment, and
| |
| 37 // icon if a representation for some scale factor cannot be loaded from the | |
| 38 // extension. | |
| 39 // If default icon is supplied, it is assumed that it contains representations | |
|
Jeffrey Yasskin
2012/08/31 18:43:14
By "contains representations", do you mean that, f
tbarzic
2012/08/31 22:29:44
the latter, clarified the comment..
| |
| 40 // for all the scale factors supported by the current platform (e.g. MacOS). | |
| 35 class IconImage : public ImageLoadingTracker::Observer, | 41 class IconImage : public ImageLoadingTracker::Observer, |
| 36 public content::NotificationObserver { | 42 public content::NotificationObserver { |
| 37 public: | 43 public: |
| 38 class Observer { | 44 class Observer { |
| 39 public: | 45 public: |
| 40 // Invoked when a new image rep for an additional scale factor | 46 // Invoked when a new image rep for an additional scale factor |
| 41 // is loaded and added to |image|. | 47 // is loaded and added to |image|. |
| 42 virtual void OnExtensionIconImageChanged(IconImage* image) = 0; | 48 virtual void OnExtensionIconImageChanged(IconImage* image) = 0; |
| 43 | 49 |
| 44 // Invoked when the icon image couldn't be loaded. | |
| 45 virtual void OnIconImageLoadFailed(IconImage* image, | |
| 46 ui::ScaleFactor scale_factor) = 0; | |
| 47 | |
| 48 protected: | 50 protected: |
| 49 virtual ~Observer() {} | 51 virtual ~Observer() {} |
| 50 }; | 52 }; |
| 51 | 53 |
| 52 IconImage(const Extension* extension, | 54 IconImage(const Extension* extension, |
| 53 const ExtensionIconSet& icon_set, | 55 const ExtensionIconSet& icon_set, |
| 54 int resource_size_in_dip, | 56 int resource_size_in_dip, |
| 57 const gfx::ImageSkia& default_icon, | |
| 55 Observer* observer); | 58 Observer* observer); |
| 56 virtual ~IconImage(); | 59 virtual ~IconImage(); |
| 57 | 60 |
| 58 const gfx::ImageSkia& image_skia() const { return image_skia_; } | 61 const gfx::ImageSkia& image_skia() const { return image_skia_; } |
| 59 | 62 |
| 60 private: | 63 private: |
| 61 class Source; | 64 class Source; |
| 62 | 65 |
| 63 typedef std::map<int, ui::ScaleFactor> LoadMap; | 66 struct LoadRequest { |
| 67 ui::ScaleFactor scale_factor; | |
| 68 bool is_async; | |
| 69 }; | |
| 70 | |
| 71 typedef std::map<int, LoadRequest> LoadMap; | |
| 64 | 72 |
| 65 // Loads bitmap for additional scale factor. | 73 // Loads bitmap for additional scale factor. |
|
Jeffrey Yasskin
2012/08/31 18:43:14
Please describe the meaning of the return value an
tbarzic
2012/08/31 22:29:44
Done.
| |
| 66 void LoadImageForScaleFactor(ui::ScaleFactor scale_factor); | 74 gfx::ImageSkiaRep LoadImageForScaleFactor(ui::ScaleFactor scale_factor); |
| 67 | 75 |
| 68 // ImageLoadingTracker::Observer overrides: | 76 // ImageLoadingTracker::Observer overrides: |
| 69 virtual void OnImageLoaded(const gfx::Image& image, | 77 virtual void OnImageLoaded(const gfx::Image& image, |
| 70 const std::string& extension_id, | 78 const std::string& extension_id, |
| 71 int index) OVERRIDE; | 79 int index) OVERRIDE; |
| 72 | 80 |
| 73 // content::NotificationObserver overrides: | 81 // content::NotificationObserver overrides: |
| 74 virtual void Observe(int type, | 82 virtual void Observe(int type, |
| 75 const content::NotificationSource& source, | 83 const content::NotificationSource& source, |
| 76 const content::NotificationDetails& details) OVERRIDE; | 84 const content::NotificationDetails& details) OVERRIDE; |
| 77 | 85 |
| 78 const Extension* extension_; | 86 const Extension* extension_; |
| 79 const ExtensionIconSet& icon_set_; | 87 const ExtensionIconSet& icon_set_; |
| 80 const int resource_size_in_dip_; | 88 const int resource_size_in_dip_; |
| 81 const gfx::Size desired_size_in_dip_; | |
| 82 | 89 |
| 83 Observer* observer_; | 90 Observer* observer_; |
| 84 | 91 |
| 85 Source* source_; // Owned by ImageSkia storage. | 92 Source* source_; // Owned by ImageSkia storage. |
| 86 gfx::ImageSkia image_skia_; | 93 gfx::ImageSkia image_skia_; |
| 94 // The icon with whose representation |image_skia_| should be updated if | |
| 95 // its own representation load fails. | |
| 96 gfx::ImageSkia default_icon_; | |
| 87 | 97 |
| 88 ImageLoadingTracker tracker_; | 98 ImageLoadingTracker tracker_; |
| 89 content::NotificationRegistrar registrar_; | 99 content::NotificationRegistrar registrar_; |
| 90 | 100 |
| 91 LoadMap load_map_; | 101 LoadMap load_map_; |
| 92 | 102 |
| 93 DISALLOW_COPY_AND_ASSIGN(IconImage); | 103 DISALLOW_COPY_AND_ASSIGN(IconImage); |
| 94 }; | 104 }; |
| 95 | 105 |
| 96 } // namespace extensions | 106 } // namespace extensions |
| 97 | 107 |
| 98 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ | 108 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ |
| OLD | NEW |