Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: ui/gfx/icon_util.h

Issue 11778073: Add support for getting the 256x256 app icon on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/profiles/profile_shortcut_manager_win.cc ('k') | ui/gfx/icon_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
14 #include "ui/base/ui_export.h" 15 #include "ui/base/ui_export.h"
15 #include "ui/gfx/point.h" 16 #include "ui/gfx/point.h"
16 #include "ui/gfx/size.h" 17 #include "ui/gfx/size.h"
17 18
18 namespace gfx { 19 namespace gfx {
19 class Size; 20 class Size;
20 } 21 }
21 class FilePath; 22 class FilePath;
22 class SkBitmap; 23 class SkBitmap;
23 24
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // the icon into an SkBitmap object containing an ARGB bitmap using the 67 // the icon into an SkBitmap object containing an ARGB bitmap using the
67 // dimensions specified in |s|. |s| must specify valid dimensions (both 68 // dimensions specified in |s|. |s| must specify valid dimensions (both
68 // width() an height() must be greater than zero). If the function cannot 69 // width() an height() must be greater than zero). If the function cannot
69 // convert the icon to a bitmap (most probably due to an invalid parameter), 70 // convert the icon to a bitmap (most probably due to an invalid parameter),
70 // the return value is NULL. 71 // the return value is NULL.
71 // 72 //
72 // The client owns the returned bitmap object and is responsible for deleting 73 // The client owns the returned bitmap object and is responsible for deleting
73 // it when it is no longer needed. 74 // it when it is no longer needed.
74 static SkBitmap* CreateSkBitmapFromHICON(HICON icon, const gfx::Size& s); 75 static SkBitmap* CreateSkBitmapFromHICON(HICON icon, const gfx::Size& s);
75 76
77 // Loads an icon resource as a SkBitmap for the specified |size| from a
78 // loaded .dll or .exe |module|. Supports loading smaller icon sizes as well
79 // as the Vista+ 256x256 PNG icon size. If the icon could not be loaded or
80 // found, returns a NULL scoped_ptr.
81 static scoped_ptr<SkBitmap> CreateSkBitmapFromIconResource(HMODULE module,
82 int resource_id,
83 int size);
84
76 // Given a valid HICON handle representing an icon, this function converts 85 // Given a valid HICON handle representing an icon, this function converts
77 // the icon into an SkBitmap object containing an ARGB bitmap using the 86 // the icon into an SkBitmap object containing an ARGB bitmap using the
78 // dimensions of HICON. If the function cannot convert the icon to a bitmap 87 // dimensions of HICON. If the function cannot convert the icon to a bitmap
79 // (most probably due to an invalid parameter), the return value is NULL. 88 // (most probably due to an invalid parameter), the return value is NULL.
80 // 89 //
81 // The client owns the returned bitmap object and is responsible for deleting 90 // The client owns the returned bitmap object and is responsible for deleting
82 // it when it is no longer needed. 91 // it when it is no longer needed.
83 static SkBitmap* CreateSkBitmapFromHICON(HICON icon); 92 static SkBitmap* CreateSkBitmapFromHICON(HICON icon);
84 93
85 // Creates Windows .ico file at |icon_path|. The icon file is created with 94 // Creates Windows .ico file at |icon_path|. The icon file is created with
(...skipping 16 matching lines...) Expand all
102 static HICON CreateCursorFromDIB(const gfx::Size& icon_size, 111 static HICON CreateCursorFromDIB(const gfx::Size& icon_size,
103 const gfx::Point& hotspot, 112 const gfx::Point& hotspot,
104 const void* dib_bits, 113 const void* dib_bits,
105 size_t dib_size); 114 size_t dib_size);
106 115
107 private: 116 private:
108 // The icon format is published in the MSDN but there is no definition of 117 // The icon format is published in the MSDN but there is no definition of
109 // the icon file structures in any of the Windows header files so we need to 118 // the icon file structures in any of the Windows header files so we need to
110 // define these structure within the class. We must make sure we use 2 byte 119 // define these structure within the class. We must make sure we use 2 byte
111 // packing so that the structures are layed out properly within the file. 120 // packing so that the structures are layed out properly within the file.
121 // See: http://msdn.microsoft.com/en-us/library/ms997538.aspx
112 #pragma pack(push) 122 #pragma pack(push)
113 #pragma pack(2) 123 #pragma pack(2)
114 124
115 // ICONDIRENTRY contains meta data for an individual icon image within a 125 // ICONDIRENTRY contains meta data for an individual icon image within a
116 // .ico file. 126 // .ico file.
117 struct ICONDIRENTRY { 127 struct ICONDIRENTRY {
118 BYTE bWidth; 128 BYTE bWidth;
119 BYTE bHeight; 129 BYTE bHeight;
120 BYTE bColorCount; 130 BYTE bColorCount;
121 BYTE bReserved; 131 BYTE bReserved;
122 WORD wPlanes; 132 WORD wPlanes;
123 WORD wBitCount; 133 WORD wBitCount;
124 DWORD dwBytesInRes; 134 DWORD dwBytesInRes;
125 DWORD dwImageOffset; 135 DWORD dwImageOffset;
126 }; 136 };
127 137
128 // ICONDIR Contains information about all the icon images contained within a 138 // ICONDIR Contains information about all the icon images contained within a
129 // single .ico file. 139 // single .ico file.
130 struct ICONDIR { 140 struct ICONDIR {
131 WORD idReserved; 141 WORD idReserved;
132 WORD idType; 142 WORD idType;
133 WORD idCount; 143 WORD idCount;
134 ICONDIRENTRY idEntries[1]; 144 ICONDIRENTRY idEntries[1];
135 }; 145 };
136 146
147 // GRPICONDIRENTRY contains meta data for an individual icon image within a
148 // RT_GROUP_ICON resource in an .exe or .dll.
149 struct GRPICONDIRENTRY {
150 BYTE bWidth;
151 BYTE bHeight;
152 BYTE bColorCount;
153 BYTE bReserved;
154 WORD wPlanes;
155 WORD wBitCount;
156 DWORD dwBytesInRes;
157 WORD nID;
158 };
159
160 // GRPICONDIR Contains information about all the icon images contained within
161 // a RT_GROUP_ICON resource in an .exe or .dll.
162 struct GRPICONDIR {
163 WORD idReserved;
164 WORD idType;
165 WORD idCount;
166 GRPICONDIRENTRY idEntries[1];
167 };
168
137 // Contains the actual icon image. 169 // Contains the actual icon image.
138 struct ICONIMAGE { 170 struct ICONIMAGE {
139 BITMAPINFOHEADER icHeader; 171 BITMAPINFOHEADER icHeader;
140 RGBQUAD icColors[1]; 172 RGBQUAD icColors[1];
141 BYTE icXOR[1]; 173 BYTE icXOR[1];
142 BYTE icAND[1]; 174 BYTE icAND[1];
143 }; 175 };
144 #pragma pack(pop) 176 #pragma pack(pop)
145 177
146 FRIEND_TEST_ALL_PREFIXES(IconUtilTest, TestCreateIconFileWithLargeBitmap); 178 FRIEND_TEST_ALL_PREFIXES(IconUtilTest, TestCreateIconFileWithLargeBitmap);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // A helper function of CreateSkBitmapFromHICON. 246 // A helper function of CreateSkBitmapFromHICON.
215 static SkBitmap CreateSkBitmapFromHICONHelper(HICON icon, 247 static SkBitmap CreateSkBitmapFromHICONHelper(HICON icon,
216 const gfx::Size& s); 248 const gfx::Size& s);
217 249
218 // Prevent clients from instantiating objects of that class by declaring the 250 // Prevent clients from instantiating objects of that class by declaring the
219 // ctor/dtor as private. 251 // ctor/dtor as private.
220 DISALLOW_IMPLICIT_CONSTRUCTORS(IconUtil); 252 DISALLOW_IMPLICIT_CONSTRUCTORS(IconUtil);
221 }; 253 };
222 254
223 #endif // UI_GFX_ICON_UTIL_H_ 255 #endif // UI_GFX_ICON_UTIL_H_
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_shortcut_manager_win.cc ('k') | ui/gfx/icon_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698