license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 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. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame^] | 5 | #ifndef CHROME_BROWSER_ICON_LOADER_H_ |
| 6 | #define CHROME_BROWSER_ICON_LOADER_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | #include <string> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | |
[email protected] | 56d01f6 | 2009-03-12 22:41:54 | [diff] [blame] | 10 | #include "base/basictypes.h" |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame^] | 11 | #include "base/file_path.h" |
[email protected] | 56d01f6 | 2009-03-12 22:41:54 | [diff] [blame] | 12 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | namespace { |
| 14 | class IconLoaderProcessor; |
| 15 | } |
| 16 | |
| 17 | class SkBitmap; |
| 18 | |
| 19 | //////////////////////////////////////////////////////////////////////////////// |
| 20 | // |
| 21 | // A facility to read a file containing an icon asynchronously in the IO |
| 22 | // thread. Clients has the option to get the icon in the form of two HICON |
| 23 | // handles (one for a small icon size and one for a large icon) or in the form |
| 24 | // of an SkBitmap. |
| 25 | // |
| 26 | // This class currently only supports reading .ico files. Please extend as |
| 27 | // needed. |
| 28 | // |
| 29 | //////////////////////////////////////////////////////////////////////////////// |
| 30 | class IconLoader { |
| 31 | public: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 32 | enum IconSize { |
| 33 | SMALL = 0, // 16x16 |
| 34 | NORMAL, // 32x32 |
| 35 | LARGE |
| 36 | }; |
| 37 | |
| 38 | class Delegate { |
| 39 | public: |
| 40 | // Invoked when an icon has been read. |source| is the IconLoader. If the |
| 41 | // icon has been successfully loaded, result is non-null. This method must |
| 42 | // return true if it is taking ownership of the returned bitmap. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 43 | virtual bool OnSkBitmapLoaded(IconLoader* source, SkBitmap* result) = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | // Create a new IconLoader that loads the icon from the data at contained in |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame^] | 47 | // the file at |path|. |
| 48 | static IconLoader* CreateIconLoaderForFile(const FilePath& path, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 49 | Delegate* delegate); |
| 50 | |
| 51 | // Create a new IconLoader that loads the icon in the resource of the file |
| 52 | // at |path|. This is used with .exe/.dll files. |
| 53 | // Note that this generates a SkBitmap (and consequently OnSkBitmapLoaded is |
| 54 | // invoked on the delegate once the load has completed). |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame^] | 55 | static IconLoader* CreateIconLoaderForFileResource(const FilePath& path, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 56 | IconSize size, |
| 57 | Delegate* delegate); |
| 58 | |
| 59 | ~IconLoader(); |
| 60 | |
| 61 | // Start the read operation |
| 62 | void Start(); |
| 63 | |
| 64 | // Cancel the read operation. The delegate will no longer be contacted. Call |
| 65 | // this method if you need to delete the delegate. |
| 66 | void Cancel(); |
| 67 | |
| 68 | private: |
| 69 | friend class IconLoaderProcessor; |
| 70 | |
| 71 | // Use the factory methods CreateIconLoader* instead of using this constructor |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame^] | 72 | IconLoader(const FilePath& path, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 73 | bool from_resource, |
| 74 | IconSize size, |
| 75 | Delegate* delegate); |
| 76 | |
| 77 | // Invoked by the processor when the file has been read and an SkBitmap |
| 78 | // object was requested. |
| 79 | bool OnLoadComplete(SkBitmap* result); |
| 80 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 81 | // The path. |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame^] | 82 | FilePath path_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 83 | |
| 84 | // The delegate. |
| 85 | Delegate* delegate_; |
| 86 | |
| 87 | // Whether we are loading the icon from the resource in the file (if false, |
| 88 | // the icon is simply loaded from the file content). |
| 89 | bool loading_from_resource_; |
| 90 | |
| 91 | // The size of the icon that should be loaded from the file resource. |
| 92 | // Not used if loading_from_resource_ is false. |
| 93 | IconSize icon_size_; |
| 94 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 95 | // The underlying object performing the read. |
| 96 | IconLoaderProcessor* processor_; |
| 97 | |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame^] | 98 | DISALLOW_COPY_AND_ASSIGN(IconLoader); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 99 | }; |
| 100 | |
[email protected] | 7ced67af | 2009-04-14 23:25:16 | [diff] [blame^] | 101 | #endif // CHROME_BROWSER_ICON_LOADER_H_ |