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_IMAGE_UTILS_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_IMAGE_UTILS_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "chrome/common/extensions/extension_resource.h" |
| 12 #include "ui/base/layout.h" |
| 13 #include "ui/gfx/size.h" |
| 14 |
| 15 namespace extensions { |
| 16 class Extension; |
| 17 } |
| 18 |
| 19 namespace gfx { |
| 20 class Image; |
| 21 } |
| 22 |
| 23 namespace extension_image_utils { |
| 24 |
| 25 // Checks whether image is a component extension resource. Returns false |
| 26 // if a given |resource| does not have a corresponding image in bundled |
| 27 // resources. Otherwise fills |resource_id|. |
| 28 bool IsComponentExtensionResource(const extensions::Extension* extension, |
| 29 const FilePath& resource_path, |
| 30 int* resource_id); |
| 31 |
| 32 void LoadImageAsync(const extensions::Extension* extension, |
| 33 const ExtensionResource& resource, |
| 34 const gfx::Size& max_size, |
| 35 const base::Callback<void(const gfx::Image&)>& callback); |
| 36 |
| 37 // Information about a singe image representation to load from an extension |
| 38 // resource. |
| 39 struct ImageRepresentation { |
| 40 // Enum values to indicate whether to resize loaded bitmap when it is larger |
| 41 // than |desired_size| or always resize it. |
| 42 enum ResizeCondition { |
| 43 RESIZE_WHEN_LARGER, |
| 44 ALWAYS_RESIZE, |
| 45 }; |
| 46 |
| 47 ImageRepresentation(const ExtensionResource& resource, |
| 48 ResizeCondition resize_condition, |
| 49 const gfx::Size& desired_size, |
| 50 ui::ScaleFactor scale_factor); |
| 51 ~ImageRepresentation(); |
| 52 |
| 53 // Extension resource to load. |
| 54 ExtensionResource resource; |
| 55 |
| 56 ResizeCondition resize_condition; |
| 57 |
| 58 // When |resize_method| is ALWAYS_RESIZE or when the loaded image is larger |
| 59 // than |desired_size| it will be resized to these dimensions. |
| 60 gfx::Size desired_size; |
| 61 |
| 62 // |scale_factor| is used to construct the loaded gfx::ImageSkia. |
| 63 ui::ScaleFactor scale_factor; |
| 64 }; |
| 65 |
| 66 void LoadImagesAsync(const extensions::Extension* extension, |
| 67 const std::vector<ImageRepresentation>& info_list, |
| 68 const base::Callback<void(const gfx::Image&)>& callback); |
| 69 |
| 70 } // namespace extension_image_utils |
| 71 |
| 72 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_UTILS_H_ |
OLD | NEW |