OLD | NEW |
---|---|
1 // Copyright (c) 2012 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> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 // // Use the icon with a WM_SETICON message | 52 // // Use the icon with a WM_SETICON message |
53 // ::SendMessage(hwnd, WM_SETICON, static_cast<WPARAM>(ICON_BIG), | 53 // ::SendMessage(hwnd, WM_SETICON, static_cast<WPARAM>(ICON_BIG), |
54 // reinterpret_cast<LPARAM>(icon)); | 54 // reinterpret_cast<LPARAM>(icon)); |
55 // | 55 // |
56 // // Destroy the icon when we are done | 56 // // Destroy the icon when we are done |
57 // ::DestroyIcon(icon); | 57 // ::DestroyIcon(icon); |
58 // | 58 // |
59 /////////////////////////////////////////////////////////////////////////////// | 59 /////////////////////////////////////////////////////////////////////////////// |
60 class GFX_EXPORT IconUtil { | 60 class GFX_EXPORT IconUtil { |
61 public: | 61 public: |
62 enum WriteType { ATOMIC_WRITE, NORMAL_WRITE }; | |
Alexei Svitkine (slow)
2015/09/30 21:26:23
Nit: Add a comment.
brucedawson
2015/09/30 22:13:59
Good point. Done.
| |
62 // The size of the large icon entries in .ico files on Windows Vista+. | 63 // The size of the large icon entries in .ico files on Windows Vista+. |
63 static const int kLargeIconSize = 256; | 64 static const int kLargeIconSize = 256; |
64 // The size of icons in the medium icons view on Windows Vista+. This is the | 65 // The size of icons in the medium icons view on Windows Vista+. This is the |
65 // maximum size Windows will display an icon that does not have a 256x256 | 66 // maximum size Windows will display an icon that does not have a 256x256 |
66 // image, even at the large or extra large icons views. | 67 // image, even at the large or extra large icons views. |
67 static const int kMediumIconSize = 48; | 68 static const int kMediumIconSize = 48; |
68 | 69 |
69 // The dimensions for icon images in Windows icon files. All sizes are square; | 70 // The dimensions for icon images in Windows icon files. All sizes are square; |
70 // that is, the value 48 means a 48x48 pixel image. Sizes are listed in | 71 // that is, the value 48 means a 48x48 pixel image. Sizes are listed in |
71 // ascending order. | 72 // ascending order. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 // | 121 // |
121 // If |image_family| contains an image larger than 48x48, the resulting icon | 122 // If |image_family| contains an image larger than 48x48, the resulting icon |
122 // will contain all sizes up to 256x256. The 256x256 image will be stored in | 123 // will contain all sizes up to 256x256. The 256x256 image will be stored in |
123 // PNG format inside the .ico file. If not, the resulting icon will contain | 124 // PNG format inside the .ico file. If not, the resulting icon will contain |
124 // all sizes up to 48x48. | 125 // all sizes up to 48x48. |
125 // | 126 // |
126 // The function returns true on success and false otherwise. Returns false if | 127 // The function returns true on success and false otherwise. Returns false if |
127 // |image_family| is empty. | 128 // |image_family| is empty. |
128 static bool CreateIconFileFromImageFamily( | 129 static bool CreateIconFileFromImageFamily( |
129 const gfx::ImageFamily& image_family, | 130 const gfx::ImageFamily& image_family, |
130 const base::FilePath& icon_path); | 131 const base::FilePath& icon_path, |
132 WriteType write_type = ATOMIC_WRITE); | |
131 | 133 |
132 // Creates a cursor of the specified size from the DIB passed in. | 134 // Creates a cursor of the specified size from the DIB passed in. |
133 // Returns the cursor on success or NULL on failure. | 135 // Returns the cursor on success or NULL on failure. |
134 static HICON CreateCursorFromDIB(const gfx::Size& icon_size, | 136 static HICON CreateCursorFromDIB(const gfx::Size& icon_size, |
135 const gfx::Point& hotspot, | 137 const gfx::Point& hotspot, |
136 const void* dib_bits, | 138 const void* dib_bits, |
137 size_t dib_size); | 139 size_t dib_size); |
138 | 140 |
139 private: | 141 private: |
140 // The icon format is published in the MSDN but there is no definition of | 142 // The icon format is published in the MSDN but there is no definition of |
141 // the icon file structures in any of the Windows header files so we need to | 143 // the icon file structures in any of the Windows header files so we need to |
142 // define these structure within the class. We must make sure we use 2 byte | 144 // define these structure within the class. We must make sure we use 2 byte |
143 // packing so that the structures are layed out properly within the file. | 145 // packing so that the structures are laid out properly within the file. |
144 // See: http://msdn.microsoft.com/en-us/library/ms997538.aspx | 146 // See: http://msdn.microsoft.com/en-us/library/ms997538.aspx |
145 #pragma pack(push) | 147 #pragma pack(push) |
146 #pragma pack(2) | 148 #pragma pack(2) |
147 | 149 |
148 // ICONDIRENTRY contains meta data for an individual icon image within a | 150 // ICONDIRENTRY contains meta data for an individual icon image within a |
149 // .ico file. | 151 // .ico file. |
150 struct ICONDIRENTRY { | 152 struct ICONDIRENTRY { |
151 BYTE bWidth; | 153 BYTE bWidth; |
152 BYTE bHeight; | 154 BYTE bHeight; |
153 BYTE bColorCount; | 155 BYTE bColorCount; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 // A helper function of CreateSkBitmapFromHICON. | 266 // A helper function of CreateSkBitmapFromHICON. |
265 static SkBitmap CreateSkBitmapFromHICONHelper(HICON icon, | 267 static SkBitmap CreateSkBitmapFromHICONHelper(HICON icon, |
266 const gfx::Size& s); | 268 const gfx::Size& s); |
267 | 269 |
268 // Prevent clients from instantiating objects of that class by declaring the | 270 // Prevent clients from instantiating objects of that class by declaring the |
269 // ctor/dtor as private. | 271 // ctor/dtor as private. |
270 DISALLOW_IMPLICIT_CONSTRUCTORS(IconUtil); | 272 DISALLOW_IMPLICIT_CONSTRUCTORS(IconUtil); |
271 }; | 273 }; |
272 | 274 |
273 #endif // UI_GFX_ICON_UTIL_H_ | 275 #endif // UI_GFX_ICON_UTIL_H_ |
OLD | NEW |