Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "chrome/browser/extensions/image_loading_tracker.h" | |
| 13 #include "chrome/common/extensions/extension_icon_set.h" | |
| 14 #include "content/public/browser/notification_observer.h" | |
| 15 #include "content/public/browser/notification_registrar.h" | |
| 16 #include "ui/gfx/image/image_skia.h" | |
| 17 | |
| 18 namespace extensions { | |
| 19 class Extension; | |
| 20 } | |
| 21 | |
| 22 namespace gfx { | |
| 23 class Size; | |
| 24 } | |
| 25 | |
| 26 namespace extensions { | |
| 27 | |
| 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 | |
| 30 // extension icon should host this class and be its delegate. ExtensionIconImage | |
| 31 // should be outlived by the delegate. In painting code, UI code paints with the | |
| 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 | |
| 34 // delegate interface when the resource is loaded. | |
| 35 class IconImage : public ImageLoadingTracker::Observer, | |
| 36 public content::NotificationObserver { | |
| 37 public: | |
| 38 class Delegate { | |
|
oshima
2012/08/07 07:43:05
This should probably called Observer instead of De
tbarzic
2012/08/07 18:10:26
Done.
| |
| 39 public: | |
| 40 // Invoked when |image| is updated with image reps for additional scale | |
| 41 // factors. | |
|
oshima
2012/08/07 07:43:05
How about
// Invoked when a new image reps for add
tbarzic
2012/08/07 18:10:26
Done.
| |
| 42 virtual void OnExtensionIconImageChanged(IconImage* image) = 0; | |
| 43 | |
| 44 protected: | |
| 45 virtual ~Delegate() {} | |
| 46 }; | |
| 47 | |
| 48 IconImage(const Extension* extension, | |
| 49 const ExtensionIconSet& icon_set, | |
| 50 int resource_size_in_dip, | |
| 51 ExtensionIconSet::MatchType resource_match_type, | |
| 52 const gfx::Size& desired_size_in_dip, | |
| 53 ImageLoadingTracker::CacheParam cache_param, | |
| 54 Delegate* delegate); | |
| 55 virtual ~IconImage(); | |
| 56 | |
| 57 const gfx::ImageSkia& image_skia() const { return image_skia_; } | |
| 58 | |
| 59 private: | |
| 60 class Source; | |
| 61 typedef std::map<int, ui::ScaleFactor> LoadMap; | |
| 62 | |
| 63 // Loads bitmap for additional scale factor. | |
| 64 void LoadImageForScaleFactor(ui::ScaleFactor scale_factor); | |
| 65 | |
| 66 // ImageLoadingTracker::Observer overrides: | |
| 67 virtual void OnImageLoaded(const gfx::Image& image, | |
| 68 const std::string& extension_id, | |
| 69 int index) OVERRIDE; | |
| 70 | |
| 71 // content::NotificationObserver overrides: | |
| 72 virtual void Observe(int type, | |
| 73 const content::NotificationSource& source, | |
| 74 const content::NotificationDetails& details) OVERRIDE; | |
| 75 | |
| 76 const Extension* extension_; | |
| 77 const ExtensionIconSet& icon_set_; | |
| 78 const int resource_size_in_dip_; | |
| 79 const ExtensionIconSet::MatchType resource_match_type_; | |
| 80 const gfx::Size desired_size_in_dip_; | |
| 81 const ImageLoadingTracker::CacheParam cache_param_; | |
| 82 | |
| 83 Delegate* delegate_; | |
| 84 | |
| 85 Source* source_; // Owned by ImageSkia storage. | |
| 86 gfx::ImageSkia image_skia_; | |
| 87 | |
| 88 ImageLoadingTracker tracker_; | |
| 89 content::NotificationRegistrar registrar_; | |
| 90 | |
| 91 LoadMap load_map_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(IconImage); | |
| 94 }; | |
| 95 | |
| 96 } // namespace extensions | |
| 97 | |
| 98 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ | |
| OLD | NEW |