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