| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 UI_GFX_ICON_UTIL_H_ | 5 #ifndef UI_GFX_ICON_UTIL_H_ |
| 6 #define UI_GFX_ICON_UTIL_H_ | 6 #define UI_GFX_ICON_UTIL_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/gtest_prod_util.h" |
| 13 #include "ui/base/ui_export.h" | 14 #include "ui/base/ui_export.h" |
| 14 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
| 15 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 16 | 17 |
| 17 namespace gfx { | 18 namespace gfx { |
| 18 class Size; | 19 class Size; |
| 19 } | 20 } |
| 20 class FilePath; | 21 class FilePath; |
| 21 class SkBitmap; | 22 class SkBitmap; |
| 22 | 23 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 75 |
| 75 // Given a valid HICON handle representing an icon, this function converts | 76 // Given a valid HICON handle representing an icon, this function converts |
| 76 // the icon into an SkBitmap object containing an ARGB bitmap using the | 77 // the icon into an SkBitmap object containing an ARGB bitmap using the |
| 77 // dimensions of HICON. If the function cannot convert the icon to a bitmap | 78 // dimensions of HICON. If the function cannot convert the icon to a bitmap |
| 78 // (most probably due to an invalid parameter), the return value is NULL. | 79 // (most probably due to an invalid parameter), the return value is NULL. |
| 79 // | 80 // |
| 80 // The client owns the returned bitmap object and is responsible for deleting | 81 // The client owns the returned bitmap object and is responsible for deleting |
| 81 // it when it is no longer needed. | 82 // it when it is no longer needed. |
| 82 static SkBitmap* CreateSkBitmapFromHICON(HICON icon); | 83 static SkBitmap* CreateSkBitmapFromHICON(HICON icon); |
| 83 | 84 |
| 84 // Given an initialized SkBitmap object and a file name, this function | 85 // Creates Windows .ico file at |icon_path|. The icon file is created with |
| 85 // creates a .ico file with the given name using the provided bitmap. The | 86 // multiple BMP representations at varying predefined dimensions (by resizing |
| 86 // icon file is created with multiple icon images of varying predefined | 87 // |bitmap|) because Windows uses different image sizes when loading icons, |
| 87 // dimensions because Windows uses different image sizes when loading icons, | |
| 88 // depending on where the icon is drawn (ALT+TAB window, desktop shortcut, | 88 // depending on where the icon is drawn (ALT+TAB window, desktop shortcut, |
| 89 // Quick Launch, etc.). |icon_file_name| needs to specify the full path for | 89 // Quick Launch, etc.). |
| 90 // the desired .ico file. | 90 // |
| 91 // To create an icon file containing a 256x256 PNG entry, which is used by |
| 92 // Vista+ for high res icons, specify a non-empty 256x256 SkBitmap for the |
| 93 // |large_bitmap| parameter. |
| 91 // | 94 // |
| 92 // The function returns true on success and false otherwise. | 95 // The function returns true on success and false otherwise. |
| 93 static bool CreateIconFileFromSkBitmap(const SkBitmap& bitmap, | 96 static bool CreateIconFileFromSkBitmap(const SkBitmap& bitmap, |
| 97 const SkBitmap& large_bitmap, |
| 94 const FilePath& icon_path); | 98 const FilePath& icon_path); |
| 95 | 99 |
| 96 // Creates a cursor of the specified size from the DIB passed in. | 100 // Creates a cursor of the specified size from the DIB passed in. |
| 97 // Returns the cursor on success or NULL on failure. | 101 // Returns the cursor on success or NULL on failure. |
| 98 static HICON CreateCursorFromDIB(const gfx::Size& icon_size, | 102 static HICON CreateCursorFromDIB(const gfx::Size& icon_size, |
| 99 const gfx::Point& hotspot, | 103 const gfx::Point& hotspot, |
| 100 const void* dib_bits, | 104 const void* dib_bits, |
| 101 size_t dib_size); | 105 size_t dib_size); |
| 102 | 106 |
| 103 private: | 107 private: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 132 | 136 |
| 133 // Contains the actual icon image. | 137 // Contains the actual icon image. |
| 134 struct ICONIMAGE { | 138 struct ICONIMAGE { |
| 135 BITMAPINFOHEADER icHeader; | 139 BITMAPINFOHEADER icHeader; |
| 136 RGBQUAD icColors[1]; | 140 RGBQUAD icColors[1]; |
| 137 BYTE icXOR[1]; | 141 BYTE icXOR[1]; |
| 138 BYTE icAND[1]; | 142 BYTE icAND[1]; |
| 139 }; | 143 }; |
| 140 #pragma pack(pop) | 144 #pragma pack(pop) |
| 141 | 145 |
| 146 FRIEND_TEST_ALL_PREFIXES(IconUtilTest, TestCreateIconFileWithLargeBitmap); |
| 147 |
| 142 // Used for indicating that the .ico contains an icon (rather than a cursor) | 148 // Used for indicating that the .ico contains an icon (rather than a cursor) |
| 143 // image. This value is set in the |idType| field of the ICONDIR structure. | 149 // image. This value is set in the |idType| field of the ICONDIR structure. |
| 144 static const int kResourceTypeIcon = 1; | 150 static const int kResourceTypeIcon = 1; |
| 145 | 151 |
| 146 // The dimensions of the icon images we insert into the .ico file. | 152 // The dimensions of the icon images we insert into the .ico file. |
| 147 static const int icon_dimensions_[]; | 153 static const int icon_dimensions_[]; |
| 148 | 154 |
| 149 // Returns true if any pixel in the given pixels buffer has an non-zero alpha. | 155 // Returns true if any pixel in the given pixels buffer has an non-zero alpha. |
| 150 static bool PixelsHaveAlpha(const uint32* pixels, size_t num_pixels); | 156 static bool PixelsHaveAlpha(const uint32* pixels, size_t num_pixels); |
| 151 | 157 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 // A helper function of CreateSkBitmapFromHICON. | 214 // A helper function of CreateSkBitmapFromHICON. |
| 209 static SkBitmap CreateSkBitmapFromHICONHelper(HICON icon, | 215 static SkBitmap CreateSkBitmapFromHICONHelper(HICON icon, |
| 210 const gfx::Size& s); | 216 const gfx::Size& s); |
| 211 | 217 |
| 212 // Prevent clients from instantiating objects of that class by declaring the | 218 // Prevent clients from instantiating objects of that class by declaring the |
| 213 // ctor/dtor as private. | 219 // ctor/dtor as private. |
| 214 DISALLOW_IMPLICIT_CONSTRUCTORS(IconUtil); | 220 DISALLOW_IMPLICIT_CONSTRUCTORS(IconUtil); |
| 215 }; | 221 }; |
| 216 | 222 |
| 217 #endif // UI_GFX_ICON_UTIL_H_ | 223 #endif // UI_GFX_ICON_UTIL_H_ |
| OLD | NEW |