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 class ExtensionIconImageDelegate; | |
| 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. In painting code, | |
| 31 // UI code paints with the ImageSkia provided by this class. If required | |
| 32 // extension icon resource is not present, this class uses ImageLoadingTracker | |
| 33 // to load it and call on its delegate interface when the resource is loaded. | |
|
tbarzic
2012/07/25 19:37:34
pkotwicz 2012/07/25 02:00:39
Can you comment about
tbarzic
2012/07/25 19:53:53
Done.
| |
| 34 class ExtensionIconImage : public ImageLoadingTracker::Observer, | |
| 35 public content::NotificationObserver { | |
| 36 public: | |
| 37 ExtensionIconImage(const extensions::Extension* extension, | |
| 38 const ExtensionIconSet& icon_set, | |
| 39 int resource_size_in_dip, | |
| 40 ExtensionIconSet::MatchType resource_match_type, | |
| 41 const gfx::Size& desired_size_in_dip, | |
| 42 ImageLoadingTracker::CacheParam cache_param, | |
| 43 ExtensionIconImageDelegate* delegate); | |
| 44 virtual ~ExtensionIconImage(); | |
| 45 | |
| 46 bool IsEmpty() const { return image_skia_.empty(); } | |
|
tbarzic
2012/07/25 19:37:34
pkotwicz 2012/07/25 02:00:39
Can you change the na
tbarzic
2012/07/25 19:53:53
Done.
| |
| 47 | |
| 48 const gfx::ImageSkia& image_skia() const { return image_skia_; } | |
| 49 | |
| 50 private: | |
| 51 class Source; | |
| 52 typedef std::map<int, ui::ScaleFactor> LoadMap; | |
| 53 | |
| 54 // Loads bitmap for additional scale factor. | |
| 55 void LoadImageForScaleFactor(ui::ScaleFactor scale_factor); | |
| 56 | |
| 57 // ImageLoadingTracker::Observer overrides: | |
| 58 virtual void OnImageLoaded(const gfx::Image& image, | |
| 59 const std::string& extension_id, | |
| 60 int index) OVERRIDE; | |
| 61 | |
| 62 // content::NotificationObserver overrides: | |
| 63 virtual void Observe(int type, | |
| 64 const content::NotificationSource& source, | |
| 65 const content::NotificationDetails& details) OVERRIDE; | |
| 66 | |
| 67 const extensions::Extension* extension_; | |
| 68 const ExtensionIconSet& icon_set_; | |
| 69 const int resource_size_in_dip_; | |
| 70 const ExtensionIconSet::MatchType resource_match_type_; | |
| 71 const gfx::Size desired_size_in_dip_; | |
| 72 const ImageLoadingTracker::CacheParam cache_param_; | |
| 73 | |
| 74 ExtensionIconImageDelegate* delegate_; | |
| 75 | |
| 76 Source* source_; // Owned by ImageSkia storage. | |
| 77 gfx::ImageSkia image_skia_; | |
| 78 | |
| 79 ImageLoadingTracker tracker_; | |
| 80 content::NotificationRegistrar registrar_; | |
| 81 | |
| 82 LoadMap load_map_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(ExtensionIconImage); | |
| 85 }; | |
| 86 | |
| 87 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ICON_IMAGE_H_ | |
| OLD | NEW |