1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_widget_WinUtils_h__
7 #define mozilla_widget_WinUtils_h__
12 #include "nsAutoPtr.h"
17 #include "nsThreadUtils.h"
18 #include "nsICryptoHash.h"
20 #include "nsIFaviconService.h"
22 #include "nsIDownloader.h"
25 #include "mozilla/Attributes.h"
32 class myDownloadObserver MOZ_FINAL
: public nsIDownloadObserver
36 NS_DECL_NSIDOWNLOADOBSERVER
42 WINXP_VERSION
= 0x501,
43 WIN2K3_VERSION
= 0x502,
44 VISTA_VERSION
= 0x600,
45 // WIN2K8_VERSION = VISTA_VERSION,
47 // WIN2K8R2_VERSION = WIN7_VERSION
50 static WinVersion
GetWindowsVersion();
52 // Retrieves the Service Pack version number.
53 // Returns true on success, false on failure.
54 static bool GetWindowsServicePackVersion(UINT
& aOutMajor
, UINT
& aOutMinor
);
57 * PeekMessage() and GetMessage() are wrapper methods for PeekMessageW(),
58 * GetMessageW(), ITfMessageMgr::PeekMessageW() and
59 * ITfMessageMgr::GetMessageW().
60 * Don't call the native APIs directly. You MUST use these methods instead.
62 static bool PeekMessage(LPMSG aMsg
, HWND aWnd
, UINT aFirstMessage
,
63 UINT aLastMessage
, UINT aOption
);
64 static bool GetMessage(LPMSG aMsg
, HWND aWnd
, UINT aFirstMessage
,
67 * Gets the value of a string-typed registry value.
69 * @param aRoot The registry root to search in.
70 * @param aKeyName The name of the registry key to open.
71 * @param aValueName The name of the registry value in the specified key whose
72 * value is to be retrieved. Can be null, to retrieve the key's unnamed/
74 * @param aBuffer The buffer into which to store the string value. Can be
75 * null, in which case the return value indicates just whether the value
77 * @param aBufferLength The size of aBuffer, in bytes.
78 * @return Whether the value exists and is a string.
80 static bool GetRegistryKey(HKEY aRoot
,
81 const PRUnichar
* aKeyName
,
82 const PRUnichar
* aValueName
,
87 * Checks whether the registry key exists in either 32bit or 64bit branch on
90 * @param aRoot The registry root of aName.
91 * @param aKeyName The name of the registry key to check.
92 * @return TRUE if it exists and is readable. Otherwise, FALSE.
94 static bool HasRegistryKey(HKEY aRoot
,
95 const PRUnichar
* aKeyName
);
98 * GetTopLevelHWND() returns a window handle of the top level window which
99 * aWnd belongs to. Note that the result may not be our window, i.e., it
100 * may not be managed by nsWindow.
102 * See follwing table for the detail of the result window type.
104 * +-------------------------+-----------------------------------------------+
105 * | | aStopIfNotPopup |
106 * +-------------------------+-----------------------+-----------------------+
108 + +-----------------+-------+-----------------------+-----------------------+
109 * | | | * an independent top level window |
110 * | | TRUE | * a pupup window (WS_POPUP) |
111 * | | | * an owned top level window (like dialog) |
112 * | aStopIfNotChild +-------+-----------------------+-----------------------+
113 * | | | * independent window | * only an independent |
114 * | | FALSE | * non-popup-owned- | top level window |
115 * | | | window like dialog | |
116 * +-----------------+-------+-----------------------+-----------------------+
118 static HWND
GetTopLevelHWND(HWND aWnd
,
119 bool aStopIfNotChild
= false,
120 bool aStopIfNotPopup
= true);
123 * SetNSWindowPtr() associates an nsWindow to aWnd. If aWindow is NULL,
124 * it dissociate any nsWindow pointer from aWnd.
125 * GetNSWindowPtr() returns an nsWindow pointer which was associated by
128 static bool SetNSWindowPtr(HWND aWnd
, nsWindow
* aWindow
);
129 static nsWindow
* GetNSWindowPtr(HWND aWnd
);
132 * GetMonitorCount() returns count of monitors on the environment.
134 static int32_t GetMonitorCount();
137 * IsOurProcessWindow() returns TRUE if aWnd belongs our process.
140 static bool IsOurProcessWindow(HWND aWnd
);
143 * FindOurProcessWindow() returns the nearest ancestor window which
144 * belongs to our process. If it fails to find our process's window by the
145 * top level window, returns NULL. And note that this is using ::GetParent()
146 * for climbing the window hierarchy, therefore, it gives up at an owned top
147 * level window except popup window (e.g., dialog).
149 static HWND
FindOurProcessWindow(HWND aWnd
);
152 * FindOurWindowAtPoint() returns the topmost child window which belongs to
153 * our process's top level window.
155 * NOTE: the topmost child window may NOT be our process's window like a
158 static HWND
FindOurWindowAtPoint(const POINT
& aPointInScreen
);
161 * InitMSG() returns an MSG struct which was initialized by the params.
162 * Don't trust the other members in the result.
164 static MSG
InitMSG(UINT aMessage
, WPARAM wParam
, LPARAM lParam
);
167 * GetScanCode() returns a scan code for the LPARAM of WM_KEYDOWN, WM_KEYUP,
168 * WM_CHAR and WM_UNICHAR.
171 static WORD
GetScanCode(LPARAM aLParam
)
173 return (aLParam
>> 16) & 0xFF;
177 * IsExtendedScanCode() returns TRUE if the LPARAM indicates the key message
178 * is an extended key event.
180 static bool IsExtendedScanCode(LPARAM aLParam
)
182 return (aLParam
& 0x1000000) != 0;
186 * GetInternalMessage() converts a native message to an internal message.
187 * If there is no internal message for the given native message, returns
188 * the native message itself.
190 static UINT
GetInternalMessage(UINT aNativeMessage
);
193 * GetNativeMessage() converts an internal message to a native message.
194 * If aInternalMessage is a native message, returns the native message itself.
196 static UINT
GetNativeMessage(UINT aInternalMessage
);
199 * GetMouseInputSource() returns a pointing device information. The value is
200 * one of nsIDOMMouseEvent::MOZ_SOURCE_*. This method MUST be called during
201 * mouse message handling.
203 static uint16_t GetMouseInputSource();
206 * SHCreateItemFromParsingName() calls native SHCreateItemFromParsingName()
207 * API which is available on Vista and up.
209 static HRESULT
SHCreateItemFromParsingName(PCWSTR pszPath
, IBindCtx
*pbc
,
210 REFIID riid
, void **ppv
);
213 * SHGetKnownFolderPath() calls native SHGetKnownFolderPath()
214 * API which is available on Vista and up.
216 static HRESULT
SHGetKnownFolderPath(REFKNOWNFOLDERID rfid
,
221 * GetShellItemPath return the file or directory path of a shell item.
222 * Internally calls IShellItem's GetDisplayName.
224 * aItem the shell item containing the path.
225 * aResultString the resulting string path.
226 * returns true if a path was retreived.
228 static bool GetShellItemPath(IShellItem
* aItem
,
229 nsString
& aResultString
);
232 * ConvertHRGNToRegion converts a Windows HRGN to an nsIntRegion.
234 * aRgn the HRGN to convert.
235 * returns the nsIntRegion.
237 static nsIntRegion
ConvertHRGNToRegion(HRGN aRgn
);
240 * ToIntRect converts a Windows RECT to a nsIntRect.
242 * aRect the RECT to convert.
243 * returns the nsIntRect.
245 static nsIntRect
ToIntRect(const RECT
& aRect
);
248 typedef HRESULT (WINAPI
* SHCreateItemFromParsingNamePtr
)(PCWSTR pszPath
,
252 static SHCreateItemFromParsingNamePtr sCreateItemFromParsingName
;
253 typedef HRESULT (WINAPI
* SHGetKnownFolderPathPtr
)(REFKNOWNFOLDERID rfid
,
257 static SHGetKnownFolderPathPtr sGetKnownFolderPath
;
261 class AsyncFaviconDataReady MOZ_FINAL
: public nsIFaviconDataCallback
265 NS_DECL_NSIFAVICONDATACALLBACK
267 AsyncFaviconDataReady(nsIURI
*aNewURI
,
268 nsCOMPtr
<nsIThread
> &aIOThread
,
269 const bool aURLShortcut
);
270 nsresult
OnFaviconDataNotAvailable(void);
272 nsCOMPtr
<nsIURI
> mNewURI
;
273 nsCOMPtr
<nsIThread
> mIOThread
;
274 const bool mURLShortcut
;
279 * Asynchronously tries add the list to the build
281 class AsyncWriteIconToDisk
: public nsIRunnable
284 const bool mURLShortcut
;
288 // Warning: AsyncWriteIconToDisk assumes ownership of the aData buffer passed in
289 AsyncWriteIconToDisk(const nsAString
&aIconPath
,
290 const nsACString
&aMimeTypeOfInputData
,
293 const bool aURLShortcut
);
294 virtual ~AsyncWriteIconToDisk();
297 nsAutoString mIconPath
;
298 nsAutoCString mMimeTypeOfInputData
;
299 nsAutoArrayPtr
<uint8_t> mBuffer
;
300 uint32_t mBufferLength
;
303 class AsyncDeleteIconFromDisk
: public nsIRunnable
309 AsyncDeleteIconFromDisk(const nsAString
&aIconPath
);
310 virtual ~AsyncDeleteIconFromDisk();
313 nsAutoString mIconPath
;
316 class AsyncDeleteAllFaviconsFromDisk
: public nsIRunnable
322 AsyncDeleteAllFaviconsFromDisk();
323 virtual ~AsyncDeleteAllFaviconsFromDisk();
329 static const char kJumpListCacheDir
[];
330 static const char kShortcutCacheDir
[];
331 static nsresult
ObtainCachedIconFile(nsCOMPtr
<nsIURI
> aFaviconPageURI
,
332 nsString
&aICOFilePath
,
333 nsCOMPtr
<nsIThread
> &aIOThread
,
336 static nsresult
HashURI(nsCOMPtr
<nsICryptoHash
> &aCryptoHash
,
338 nsACString
& aUriHash
);
340 static nsresult
GetOutputIconPath(nsCOMPtr
<nsIURI
> aFaviconPageURI
,
341 nsCOMPtr
<nsIFile
> &aICOFile
,
345 CacheIconFileFromFaviconURIAsync(nsCOMPtr
<nsIURI
> aFaviconPageURI
,
346 nsCOMPtr
<nsIFile
> aICOFile
,
347 nsCOMPtr
<nsIThread
> &aIOThread
,
350 static int32_t GetICOCacheSecondsTimeout();
355 } // namespace widget
356 } // namespace mozilla
358 #endif // mozilla_widget_WinUtils_h__