2012-01-04 14:21:44 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-01-04 14:21:44 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_widget_WinUtils_h__
|
|
|
|
#define mozilla_widget_WinUtils_h__
|
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include <windows.h>
|
2012-01-11 06:09:41 +04:00
|
|
|
#include <shobjidl.h>
|
2013-08-15 08:25:12 +04:00
|
|
|
#include <uxtheme.h>
|
2013-08-15 08:25:58 +04:00
|
|
|
#include <dwmapi.h>
|
2015-01-03 05:13:39 +03:00
|
|
|
|
|
|
|
// Undo the windows.h damage
|
|
|
|
#undef GetMessage
|
|
|
|
#undef CreateEvent
|
|
|
|
#undef GetClassName
|
|
|
|
#undef GetBinaryType
|
|
|
|
#undef RemoveDirectory
|
|
|
|
|
2012-02-17 04:36:04 +04:00
|
|
|
#include "nsString.h"
|
2012-11-02 15:54:44 +04:00
|
|
|
#include "nsRegion.h"
|
2015-04-21 18:04:57 +03:00
|
|
|
#include "nsRect.h"
|
2012-01-04 14:21:44 +04:00
|
|
|
|
2013-09-19 17:54:39 +04:00
|
|
|
#include "nsIRunnable.h"
|
2012-07-22 00:07:26 +04:00
|
|
|
#include "nsICryptoHash.h"
|
2012-11-09 13:55:56 +04:00
|
|
|
#ifdef MOZ_PLACES
|
|
|
|
#include "nsIFaviconService.h"
|
|
|
|
#endif
|
2012-07-22 00:07:26 +04:00
|
|
|
#include "nsIDownloader.h"
|
2012-11-09 13:55:56 +04:00
|
|
|
#include "nsIURI.h"
|
2013-05-29 10:34:49 +04:00
|
|
|
#include "nsIWidget.h"
|
2014-07-15 22:56:01 +04:00
|
|
|
#include "nsIThread.h"
|
2012-07-22 00:07:26 +04:00
|
|
|
|
2012-10-04 12:33:24 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2015-08-26 15:56:59 +03:00
|
|
|
#include "mozilla/EventForwards.h"
|
2015-10-26 21:31:12 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2012-07-22 00:07:26 +04:00
|
|
|
|
2014-07-11 21:09:59 +04:00
|
|
|
/**
|
|
|
|
* NS_INLINE_DECL_IUNKNOWN_REFCOUNTING should be used for defining and
|
|
|
|
* implementing AddRef() and Release() of IUnknown interface.
|
2017-01-23 17:24:01 +03:00
|
|
|
* This depends on xpcom/base/nsISupportsImpl.h.
|
2014-07-11 21:09:59 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define NS_INLINE_DECL_IUNKNOWN_REFCOUNTING(_class) \
|
|
|
|
public: \
|
|
|
|
STDMETHODIMP_(ULONG) AddRef() \
|
|
|
|
{ \
|
|
|
|
MOZ_ASSERT_TYPE_OK_FOR_REFCOUNTING(_class) \
|
|
|
|
MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt"); \
|
|
|
|
NS_ASSERT_OWNINGTHREAD(_class); \
|
|
|
|
++mRefCnt; \
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, #_class, sizeof(*this)); \
|
|
|
|
return static_cast<ULONG>(mRefCnt.get()); \
|
|
|
|
} \
|
|
|
|
STDMETHODIMP_(ULONG) Release() \
|
|
|
|
{ \
|
|
|
|
MOZ_ASSERT(int32_t(mRefCnt) > 0, \
|
|
|
|
"Release called on object that has already been released!"); \
|
|
|
|
NS_ASSERT_OWNINGTHREAD(_class); \
|
|
|
|
--mRefCnt; \
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, #_class); \
|
|
|
|
if (mRefCnt == 0) { \
|
|
|
|
NS_ASSERT_OWNINGTHREAD(_class); \
|
|
|
|
mRefCnt = 1; /* stabilize */ \
|
|
|
|
delete this; \
|
|
|
|
return 0; \
|
|
|
|
} \
|
|
|
|
return static_cast<ULONG>(mRefCnt.get()); \
|
|
|
|
} \
|
|
|
|
protected: \
|
|
|
|
nsAutoRefCnt mRefCnt; \
|
|
|
|
NS_DECL_OWNINGTHREAD \
|
|
|
|
public:
|
|
|
|
|
2012-01-04 14:21:44 +04:00
|
|
|
class nsWindow;
|
2013-08-09 14:12:38 +04:00
|
|
|
class nsWindowBase;
|
2013-05-29 10:34:49 +04:00
|
|
|
struct KeyPair;
|
2012-01-04 14:21:44 +04:00
|
|
|
|
2016-07-22 06:43:15 +03:00
|
|
|
#if !defined(DPI_AWARENESS_CONTEXT_DECLARED) && !defined(DPI_AWARENESS_CONTEXT_UNAWARE)
|
2016-07-02 01:42:32 +03:00
|
|
|
|
|
|
|
DECLARE_HANDLE(DPI_AWARENESS_CONTEXT);
|
|
|
|
|
|
|
|
typedef enum DPI_AWARENESS {
|
|
|
|
DPI_AWARENESS_INVALID = -1,
|
|
|
|
DPI_AWARENESS_UNAWARE = 0,
|
|
|
|
DPI_AWARENESS_SYSTEM_AWARE = 1,
|
|
|
|
DPI_AWARENESS_PER_MONITOR_AWARE = 2
|
|
|
|
} DPI_AWARENESS;
|
|
|
|
|
|
|
|
#define DPI_AWARENESS_CONTEXT_UNAWARE ((DPI_AWARENESS_CONTEXT)-1)
|
|
|
|
#define DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ((DPI_AWARENESS_CONTEXT)-2)
|
|
|
|
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ((DPI_AWARENESS_CONTEXT)-3)
|
|
|
|
|
|
|
|
#define DPI_AWARENESS_CONTEXT_DECLARED
|
|
|
|
#endif // (DPI_AWARENESS_CONTEXT_DECLARED)
|
|
|
|
|
2017-04-07 01:14:14 +03:00
|
|
|
#if WINVER < 0x0605
|
|
|
|
WINUSERAPI DPI_AWARENESS_CONTEXT WINAPI GetThreadDpiAwarenessContext();
|
|
|
|
WINUSERAPI BOOL WINAPI
|
|
|
|
AreDpiAwarenessContextsEqual(DPI_AWARENESS_CONTEXT, DPI_AWARENESS_CONTEXT);
|
|
|
|
#endif /* WINVER < 0x0605 */
|
2016-07-02 01:42:32 +03:00
|
|
|
typedef DPI_AWARENESS_CONTEXT(WINAPI * SetThreadDpiAwarenessContextProc)(DPI_AWARENESS_CONTEXT);
|
|
|
|
typedef BOOL(WINAPI * EnableNonClientDpiScalingProc)(HWND);
|
|
|
|
|
2012-01-04 14:21:44 +04:00
|
|
|
namespace mozilla {
|
2017-06-16 02:29:07 +03:00
|
|
|
#if defined(ACCESSIBILITY)
|
|
|
|
namespace a11y {
|
|
|
|
class Accessible;
|
|
|
|
} // namespace a11y
|
|
|
|
#endif // defined(ACCESSIBILITY)
|
|
|
|
|
2012-01-04 14:21:44 +04:00
|
|
|
namespace widget {
|
|
|
|
|
2014-08-12 23:06:00 +04:00
|
|
|
// Windows message debugging data
|
|
|
|
typedef struct {
|
|
|
|
const char * mStr;
|
|
|
|
UINT mId;
|
|
|
|
} EventMsgInfo;
|
|
|
|
extern EventMsgInfo gAllEvents[];
|
|
|
|
|
2013-09-06 17:11:14 +04:00
|
|
|
// More complete QS definitions for MsgWaitForMultipleObjects() and
|
|
|
|
// GetQueueStatus() that include newer win8 specific defines.
|
|
|
|
|
|
|
|
#ifndef QS_RAWINPUT
|
|
|
|
#define QS_RAWINPUT 0x0400
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef QS_TOUCH
|
|
|
|
#define QS_TOUCH 0x0800
|
|
|
|
#define QS_POINTER 0x1000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MOZ_QS_ALLEVENT (QS_KEY | QS_MOUSEMOVE | QS_MOUSEBUTTON | \
|
|
|
|
QS_POSTMESSAGE | QS_TIMER | QS_PAINT | \
|
|
|
|
QS_SENDMESSAGE | QS_HOTKEY | \
|
|
|
|
QS_ALLPOSTMESSAGE | QS_RAWINPUT | \
|
|
|
|
QS_TOUCH | QS_POINTER)
|
|
|
|
|
2013-11-01 14:09:32 +04:00
|
|
|
// Logging macros
|
|
|
|
#define LogFunction() mozilla::widget::WinUtils::Log(__FUNCTION__)
|
|
|
|
#define LogThread() mozilla::widget::WinUtils::Log("%s: IsMainThread:%d ThreadId:%X", __FUNCTION__, NS_IsMainThread(), GetCurrentThreadId())
|
|
|
|
#define LogThis() mozilla::widget::WinUtils::Log("[%X] %s", this, __FUNCTION__)
|
|
|
|
#define LogException(e) mozilla::widget::WinUtils::Log("%s Exception:%s", __FUNCTION__, e->ToString()->Data())
|
|
|
|
#define LogHRESULT(hr) mozilla::widget::WinUtils::Log("%s hr=%X", __FUNCTION__, hr)
|
|
|
|
|
2014-07-16 21:21:23 +04:00
|
|
|
#ifdef MOZ_PLACES
|
2015-03-21 19:28:04 +03:00
|
|
|
class myDownloadObserver final : public nsIDownloadObserver
|
2012-07-22 00:07:26 +04:00
|
|
|
{
|
2014-07-16 21:21:23 +04:00
|
|
|
~myDownloadObserver() {}
|
|
|
|
|
2012-07-22 00:07:26 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOWNLOADOBSERVER
|
|
|
|
};
|
2014-07-16 21:21:23 +04:00
|
|
|
#endif
|
2012-07-22 00:07:26 +04:00
|
|
|
|
2015-05-08 04:29:00 +03:00
|
|
|
class WinUtils
|
|
|
|
{
|
2016-07-02 01:42:32 +03:00
|
|
|
// Function pointers for APIs that may not be available depending on
|
|
|
|
// the Win10 update version -- will be set up in Initialize().
|
|
|
|
static SetThreadDpiAwarenessContextProc sSetThreadDpiAwarenessContext;
|
|
|
|
static EnableNonClientDpiScalingProc sEnableNonClientDpiScaling;
|
|
|
|
|
2012-01-04 14:21:44 +04:00
|
|
|
public:
|
2016-07-02 01:42:32 +03:00
|
|
|
class AutoSystemDpiAware
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoSystemDpiAware()
|
|
|
|
{
|
|
|
|
if (sSetThreadDpiAwarenessContext) {
|
|
|
|
mPrevContext = sSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_SYSTEM_AWARE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoSystemDpiAware()
|
|
|
|
{
|
|
|
|
if (sSetThreadDpiAwarenessContext) {
|
|
|
|
sSetThreadDpiAwarenessContext(mPrevContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DPI_AWARENESS_CONTEXT mPrevContext;
|
|
|
|
};
|
|
|
|
|
2017-08-23 06:59:40 +03:00
|
|
|
// Wrapper for DefWindowProc that will enable non-client dpi scaling on the
|
|
|
|
// window during creation.
|
|
|
|
static LRESULT WINAPI
|
|
|
|
NonClientDpiScalingDefWindowProcW(HWND hWnd, UINT msg,
|
|
|
|
WPARAM wParam, LPARAM lParam);
|
2016-07-14 19:46:26 +03:00
|
|
|
|
2016-01-28 18:08:33 +03:00
|
|
|
/**
|
|
|
|
* Get the system's default logical-to-physical DPI scaling factor,
|
|
|
|
* which is based on the primary display. Note however that unlike
|
|
|
|
* LogToPhysFactor(GetPrimaryMonitor()), this will not change during
|
|
|
|
* a session even if the displays are reconfigured. This scale factor
|
|
|
|
* is used by Windows theme metrics etc, which do not fully support
|
|
|
|
* dynamic resolution changes but are only updated on logout.
|
|
|
|
*/
|
|
|
|
static double SystemScaleFactor();
|
2015-12-02 18:09:29 +03:00
|
|
|
|
|
|
|
static bool IsPerMonitorDPIAware();
|
2017-06-15 20:11:41 +03:00
|
|
|
/**
|
|
|
|
* Get the DPI of the given monitor if it's per-monitor DPI aware, otherwise
|
|
|
|
* return the system DPI.
|
|
|
|
*/
|
|
|
|
static float MonitorDPI(HMONITOR aMonitor);
|
|
|
|
static float SystemDPI();
|
2013-12-15 00:40:55 +04:00
|
|
|
/**
|
|
|
|
* Functions to convert between logical pixels as used by most Windows APIs
|
|
|
|
* and physical (device) pixels.
|
|
|
|
*/
|
2015-12-02 18:09:29 +03:00
|
|
|
static double LogToPhysFactor(HMONITOR aMonitor);
|
|
|
|
static double LogToPhysFactor(HWND aWnd) {
|
2016-04-13 16:40:46 +03:00
|
|
|
// if there's an ancestor window, we want to share its DPI setting
|
|
|
|
HWND ancestor = ::GetAncestor(aWnd, GA_ROOTOWNER);
|
|
|
|
return LogToPhysFactor(::MonitorFromWindow(ancestor ? ancestor : aWnd,
|
|
|
|
MONITOR_DEFAULTTOPRIMARY));
|
2015-12-02 18:09:29 +03:00
|
|
|
}
|
|
|
|
static double LogToPhysFactor(HDC aDC) {
|
|
|
|
return LogToPhysFactor(::WindowFromDC(aDC));
|
|
|
|
}
|
|
|
|
static int32_t LogToPhys(HMONITOR aMonitor, double aValue);
|
|
|
|
static HMONITOR GetPrimaryMonitor();
|
|
|
|
static HMONITOR MonitorFromRect(const gfx::Rect& rect);
|
2013-12-15 00:40:55 +04:00
|
|
|
|
2013-11-01 14:09:32 +04:00
|
|
|
/**
|
|
|
|
* Logging helpers that dump output to prlog module 'Widget', console, and
|
|
|
|
* OutputDebugString. Note these output in both debug and release builds.
|
|
|
|
*/
|
|
|
|
static void Log(const char *fmt, ...);
|
|
|
|
static void LogW(const wchar_t *fmt, ...);
|
|
|
|
|
2013-03-18 08:41:24 +04:00
|
|
|
/**
|
|
|
|
* PeekMessage() and GetMessage() are wrapper methods for PeekMessageW(),
|
|
|
|
* GetMessageW(), ITfMessageMgr::PeekMessageW() and
|
|
|
|
* ITfMessageMgr::GetMessageW().
|
|
|
|
* Don't call the native APIs directly. You MUST use these methods instead.
|
|
|
|
*/
|
2017-06-05 15:52:16 +03:00
|
|
|
static bool PeekMessage(LPMSG aMsg, HWND aWnd, UINT aFirstMessage,
|
2013-03-18 08:41:24 +04:00
|
|
|
UINT aLastMessage, UINT aOption);
|
2017-06-05 15:52:16 +03:00
|
|
|
static bool GetMessage(LPMSG aMsg, HWND aWnd, UINT aFirstMessage,
|
2013-03-18 08:41:24 +04:00
|
|
|
UINT aLastMessage);
|
2013-07-31 00:51:45 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait until a message is ready to be processed.
|
|
|
|
* Prefer using this method to directly calling ::WaitMessage since
|
|
|
|
* ::WaitMessage will wait if there is an unread message in the queue.
|
|
|
|
* That can cause freezes until another message enters the queue if the
|
|
|
|
* message is marked read by a call to PeekMessage which the caller is
|
|
|
|
* not aware of (e.g., from a different thread).
|
|
|
|
* Note that this method may cause sync dispatch of sent (as opposed to
|
|
|
|
* posted) messages.
|
2014-09-25 22:39:15 +04:00
|
|
|
* @param aTimeoutMs Timeout for waiting in ms, defaults to INFINITE
|
2013-07-31 00:51:45 +04:00
|
|
|
*/
|
2014-09-25 22:39:15 +04:00
|
|
|
static void WaitForMessage(DWORD aTimeoutMs = INFINITE);
|
2013-07-31 00:51:45 +04:00
|
|
|
|
2012-01-04 14:21:44 +04:00
|
|
|
/**
|
|
|
|
* Gets the value of a string-typed registry value.
|
|
|
|
*
|
|
|
|
* @param aRoot The registry root to search in.
|
|
|
|
* @param aKeyName The name of the registry key to open.
|
|
|
|
* @param aValueName The name of the registry value in the specified key whose
|
|
|
|
* value is to be retrieved. Can be null, to retrieve the key's unnamed/
|
|
|
|
* default value.
|
|
|
|
* @param aBuffer The buffer into which to store the string value. Can be
|
|
|
|
* null, in which case the return value indicates just whether the value
|
|
|
|
* exists.
|
|
|
|
* @param aBufferLength The size of aBuffer, in bytes.
|
|
|
|
* @return Whether the value exists and is a string.
|
|
|
|
*/
|
|
|
|
static bool GetRegistryKey(HKEY aRoot,
|
2013-12-03 19:12:57 +04:00
|
|
|
char16ptr_t aKeyName,
|
|
|
|
char16ptr_t aValueName,
|
|
|
|
wchar_t* aBuffer,
|
2012-01-04 14:21:44 +04:00
|
|
|
DWORD aBufferLength);
|
|
|
|
|
2012-03-06 07:20:28 +04:00
|
|
|
/**
|
|
|
|
* Checks whether the registry key exists in either 32bit or 64bit branch on
|
|
|
|
* the environment.
|
|
|
|
*
|
|
|
|
* @param aRoot The registry root of aName.
|
|
|
|
* @param aKeyName The name of the registry key to check.
|
|
|
|
* @return TRUE if it exists and is readable. Otherwise, FALSE.
|
|
|
|
*/
|
|
|
|
static bool HasRegistryKey(HKEY aRoot,
|
2013-12-03 19:12:57 +04:00
|
|
|
char16ptr_t aKeyName);
|
2012-03-06 07:20:28 +04:00
|
|
|
|
2012-01-04 14:21:44 +04:00
|
|
|
/**
|
|
|
|
* GetTopLevelHWND() returns a window handle of the top level window which
|
|
|
|
* aWnd belongs to. Note that the result may not be our window, i.e., it
|
|
|
|
* may not be managed by nsWindow.
|
|
|
|
*
|
|
|
|
* See follwing table for the detail of the result window type.
|
|
|
|
*
|
|
|
|
* +-------------------------+-----------------------------------------------+
|
|
|
|
* | | aStopIfNotPopup |
|
|
|
|
* +-------------------------+-----------------------+-----------------------+
|
|
|
|
* | | TRUE | FALSE |
|
|
|
|
+ +-----------------+-------+-----------------------+-----------------------+
|
|
|
|
* | | | * an independent top level window |
|
|
|
|
* | | TRUE | * a pupup window (WS_POPUP) |
|
|
|
|
* | | | * an owned top level window (like dialog) |
|
|
|
|
* | aStopIfNotChild +-------+-----------------------+-----------------------+
|
|
|
|
* | | | * independent window | * only an independent |
|
|
|
|
* | | FALSE | * non-popup-owned- | top level window |
|
|
|
|
* | | | window like dialog | |
|
|
|
|
* +-----------------+-------+-----------------------+-----------------------+
|
|
|
|
*/
|
2016-07-22 11:56:13 +03:00
|
|
|
static HWND GetTopLevelHWND(HWND aWnd,
|
|
|
|
bool aStopIfNotChild = false,
|
2012-01-04 14:21:44 +04:00
|
|
|
bool aStopIfNotPopup = true);
|
|
|
|
|
|
|
|
/**
|
2013-10-08 22:48:34 +04:00
|
|
|
* SetNSWindowBasePtr() associates an nsWindowBase to aWnd. If aWidget is
|
|
|
|
* nullptr, it dissociate any nsBaseWidget pointer from aWnd.
|
2013-08-09 14:12:38 +04:00
|
|
|
* GetNSWindowBasePtr() returns an nsWindowBase pointer which was associated by
|
|
|
|
* SetNSWindowBasePtr().
|
|
|
|
* GetNSWindowPtr() is a legacy api for win32 nsWindow and should be avoided
|
|
|
|
* outside of nsWindow src.
|
2012-01-04 14:21:44 +04:00
|
|
|
*/
|
2013-08-09 14:12:38 +04:00
|
|
|
static bool SetNSWindowBasePtr(HWND aWnd, nsWindowBase* aWidget);
|
|
|
|
static nsWindowBase* GetNSWindowBasePtr(HWND aWnd);
|
2012-01-04 14:21:44 +04:00
|
|
|
static nsWindow* GetNSWindowPtr(HWND aWnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetMonitorCount() returns count of monitors on the environment.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t GetMonitorCount();
|
2012-01-04 14:21:44 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IsOurProcessWindow() returns TRUE if aWnd belongs our process.
|
|
|
|
* Otherwise, FALSE.
|
|
|
|
*/
|
|
|
|
static bool IsOurProcessWindow(HWND aWnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FindOurProcessWindow() returns the nearest ancestor window which
|
|
|
|
* belongs to our process. If it fails to find our process's window by the
|
2013-10-08 22:48:34 +04:00
|
|
|
* top level window, returns nullptr. And note that this is using
|
|
|
|
* ::GetParent() for climbing the window hierarchy, therefore, it gives
|
|
|
|
* up at an owned top level window except popup window (e.g., dialog).
|
2012-01-04 14:21:44 +04:00
|
|
|
*/
|
|
|
|
static HWND FindOurProcessWindow(HWND aWnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FindOurWindowAtPoint() returns the topmost child window which belongs to
|
|
|
|
* our process's top level window.
|
|
|
|
*
|
|
|
|
* NOTE: the topmost child window may NOT be our process's window like a
|
|
|
|
* plugin's window.
|
|
|
|
*/
|
|
|
|
static HWND FindOurWindowAtPoint(const POINT& aPointInScreen);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* InitMSG() returns an MSG struct which was initialized by the params.
|
|
|
|
* Don't trust the other members in the result.
|
|
|
|
*/
|
2013-05-29 10:34:48 +04:00
|
|
|
static MSG InitMSG(UINT aMessage, WPARAM wParam, LPARAM lParam, HWND aWnd);
|
2012-01-04 14:21:44 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GetScanCode() returns a scan code for the LPARAM of WM_KEYDOWN, WM_KEYUP,
|
|
|
|
* WM_CHAR and WM_UNICHAR.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static WORD GetScanCode(LPARAM aLParam)
|
|
|
|
{
|
|
|
|
return (aLParam >> 16) & 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IsExtendedScanCode() returns TRUE if the LPARAM indicates the key message
|
|
|
|
* is an extended key event.
|
|
|
|
*/
|
|
|
|
static bool IsExtendedScanCode(LPARAM aLParam)
|
|
|
|
{
|
|
|
|
return (aLParam & 0x1000000) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetInternalMessage() converts a native message to an internal message.
|
|
|
|
* If there is no internal message for the given native message, returns
|
|
|
|
* the native message itself.
|
|
|
|
*/
|
|
|
|
static UINT GetInternalMessage(UINT aNativeMessage);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetNativeMessage() converts an internal message to a native message.
|
|
|
|
* If aInternalMessage is a native message, returns the native message itself.
|
|
|
|
*/
|
|
|
|
static UINT GetNativeMessage(UINT aInternalMessage);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetMouseInputSource() returns a pointing device information. The value is
|
|
|
|
* one of nsIDOMMouseEvent::MOZ_SOURCE_*. This method MUST be called during
|
|
|
|
* mouse message handling.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint16_t GetMouseInputSource();
|
2012-01-11 06:09:41 +04:00
|
|
|
|
2016-09-01 11:12:15 +03:00
|
|
|
/**
|
|
|
|
* Windows also fires mouse window messages for pens and touches, so we should
|
|
|
|
* retrieve their pointer ID on receiving mouse events as well. Please refer to
|
|
|
|
* https://msdn.microsoft.com/en-us/library/windows/desktop/ms703320(v=vs.85).aspx
|
|
|
|
*/
|
|
|
|
static uint16_t GetMousePointerID();
|
|
|
|
|
2015-08-26 15:56:59 +03:00
|
|
|
static bool GetIsMouseFromTouch(EventMessage aEventType);
|
2014-02-27 01:37:01 +04:00
|
|
|
|
2012-02-17 04:36:04 +04:00
|
|
|
/**
|
|
|
|
* GetShellItemPath return the file or directory path of a shell item.
|
|
|
|
* Internally calls IShellItem's GetDisplayName.
|
|
|
|
*
|
|
|
|
* aItem the shell item containing the path.
|
|
|
|
* aResultString the resulting string path.
|
|
|
|
* returns true if a path was retreived.
|
|
|
|
*/
|
|
|
|
static bool GetShellItemPath(IShellItem* aItem,
|
|
|
|
nsString& aResultString);
|
|
|
|
|
2012-11-02 15:54:44 +04:00
|
|
|
/**
|
|
|
|
* ConvertHRGNToRegion converts a Windows HRGN to an nsIntRegion.
|
|
|
|
*
|
|
|
|
* aRgn the HRGN to convert.
|
|
|
|
* returns the nsIntRegion.
|
|
|
|
*/
|
|
|
|
static nsIntRegion ConvertHRGNToRegion(HRGN aRgn);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ToIntRect converts a Windows RECT to a nsIntRect.
|
|
|
|
*
|
|
|
|
* aRect the RECT to convert.
|
|
|
|
* returns the nsIntRect.
|
|
|
|
*/
|
|
|
|
static nsIntRect ToIntRect(const RECT& aRect);
|
|
|
|
|
2015-01-29 22:41:54 +03:00
|
|
|
/**
|
|
|
|
* Helper used in invalidating flash plugin windows owned
|
|
|
|
* by low rights flash containers.
|
|
|
|
*/
|
2015-11-17 08:18:31 +03:00
|
|
|
static void InvalidatePluginAsWorkaround(nsIWidget* aWidget,
|
|
|
|
const LayoutDeviceIntRect& aRect);
|
2015-01-29 22:41:54 +03:00
|
|
|
|
2013-05-29 10:34:49 +04:00
|
|
|
/**
|
|
|
|
* Returns true if the context or IME state is enabled. Otherwise, false.
|
|
|
|
*/
|
|
|
|
static bool IsIMEEnabled(const InputContext& aInputContext);
|
|
|
|
static bool IsIMEEnabled(IMEState::Enabled aIMEState);
|
|
|
|
|
2013-05-29 10:34:49 +04:00
|
|
|
/**
|
|
|
|
* Returns modifier key array for aModifiers. This is for
|
|
|
|
* nsIWidget::SynthethizeNative*Event().
|
|
|
|
*/
|
|
|
|
static void SetupKeyModifiersSequence(nsTArray<KeyPair>* aArray,
|
|
|
|
uint32_t aModifiers);
|
|
|
|
|
2015-05-08 04:29:00 +03:00
|
|
|
/**
|
|
|
|
* Does device have touch support
|
|
|
|
*/
|
|
|
|
static uint32_t IsTouchDeviceSupportPresent();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The maximum number of simultaneous touch contacts supported by the device.
|
|
|
|
* In the case of devices with multiple digitizers (e.g. multiple touch screens),
|
|
|
|
* the value will be the maximum of the set of maximum supported contacts by
|
|
|
|
* each individual digitizer.
|
|
|
|
*/
|
|
|
|
static uint32_t GetMaxTouchPoints();
|
|
|
|
|
2016-02-09 18:22:43 +03:00
|
|
|
/**
|
2017-06-09 06:29:46 +03:00
|
|
|
* Fully resolves a path to its final path name. So if path contains
|
|
|
|
* junction points or symlinks to other folders, we'll resolve the path
|
|
|
|
* fully to the actual path that the links target.
|
2016-02-09 18:22:43 +03:00
|
|
|
*
|
|
|
|
* @param aPath path to be resolved.
|
|
|
|
* @return true if successful, including if nothing needs to be changed.
|
|
|
|
* false if something failed or aPath does not exist, aPath will
|
|
|
|
* remain unchanged.
|
|
|
|
*/
|
2017-06-09 06:29:46 +03:00
|
|
|
static bool ResolveJunctionPointsAndSymLinks(std::wstring& aPath);
|
2017-06-23 18:29:15 +03:00
|
|
|
static bool ResolveJunctionPointsAndSymLinks(nsIFile* aPath);
|
2016-02-09 18:22:43 +03:00
|
|
|
|
2013-08-15 08:25:12 +04:00
|
|
|
static void Initialize();
|
|
|
|
|
2013-12-03 22:21:09 +04:00
|
|
|
static bool ShouldHideScrollbars();
|
|
|
|
|
2016-01-17 00:09:28 +03:00
|
|
|
/**
|
|
|
|
* This function normalizes the input path, converts short filenames to long
|
|
|
|
* filenames, and substitutes environment variables for system paths.
|
|
|
|
* The resulting output string length is guaranteed to be <= MAX_PATH.
|
|
|
|
*/
|
|
|
|
static bool SanitizePath(const wchar_t* aInputPath, nsAString& aOutput);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a semicolon-delimited list of DLL files derived from AppInit_DLLs
|
|
|
|
*/
|
|
|
|
static bool GetAppInitDLLs(nsAString& aOutput);
|
|
|
|
|
2016-09-23 00:07:01 +03:00
|
|
|
#ifdef ACCESSIBILITY
|
2017-06-16 02:29:07 +03:00
|
|
|
static a11y::Accessible* GetRootAccessibleForHWND(HWND aHwnd);
|
2016-09-23 00:07:01 +03:00
|
|
|
#endif
|
|
|
|
|
2012-01-11 06:09:41 +04:00
|
|
|
private:
|
2016-01-17 00:09:28 +03:00
|
|
|
static void GetWhitelistedPaths(
|
|
|
|
nsTArray<mozilla::Pair<nsString,nsDependentString>>& aOutput);
|
2012-01-04 14:21:44 +04:00
|
|
|
};
|
|
|
|
|
2012-11-09 13:55:56 +04:00
|
|
|
#ifdef MOZ_PLACES
|
2015-03-21 19:28:04 +03:00
|
|
|
class AsyncFaviconDataReady final : public nsIFaviconDataCallback
|
2012-07-22 00:07:26 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIFAVICONDATACALLBACK
|
2016-07-22 11:56:13 +03:00
|
|
|
|
|
|
|
AsyncFaviconDataReady(nsIURI *aNewURI,
|
|
|
|
nsCOMPtr<nsIThread> &aIOThread,
|
2012-07-22 00:07:26 +04:00
|
|
|
const bool aURLShortcut);
|
|
|
|
nsresult OnFaviconDataNotAvailable(void);
|
|
|
|
private:
|
2014-07-15 22:56:01 +04:00
|
|
|
~AsyncFaviconDataReady() {}
|
|
|
|
|
2012-07-22 00:07:26 +04:00
|
|
|
nsCOMPtr<nsIURI> mNewURI;
|
|
|
|
nsCOMPtr<nsIThread> mIOThread;
|
|
|
|
const bool mURLShortcut;
|
|
|
|
};
|
2012-11-09 13:55:56 +04:00
|
|
|
#endif
|
2012-07-22 00:07:26 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Asynchronously tries add the list to the build
|
|
|
|
*/
|
2013-05-28 22:08:48 +04:00
|
|
|
class AsyncEncodeAndWriteIcon : public nsIRunnable
|
2012-07-22 00:07:26 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
const bool mURLShortcut;
|
2013-07-19 06:24:15 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-07-22 00:07:26 +04:00
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
2013-05-28 22:08:48 +04:00
|
|
|
// Warning: AsyncEncodeAndWriteIcon assumes ownership of the aData buffer passed in
|
|
|
|
AsyncEncodeAndWriteIcon(const nsAString &aIconPath,
|
2015-11-05 22:19:20 +03:00
|
|
|
UniquePtr<uint8_t[]> aData,
|
2015-10-26 21:31:12 +03:00
|
|
|
uint32_t aStride, uint32_t aWidth, uint32_t aHeight,
|
2013-05-28 22:08:48 +04:00
|
|
|
const bool aURLShortcut);
|
2012-07-22 00:07:26 +04:00
|
|
|
|
|
|
|
private:
|
2014-07-15 22:56:01 +04:00
|
|
|
virtual ~AsyncEncodeAndWriteIcon();
|
|
|
|
|
2012-07-22 00:07:26 +04:00
|
|
|
nsAutoString mIconPath;
|
2015-10-26 21:31:12 +03:00
|
|
|
UniquePtr<uint8_t[]> mBuffer;
|
2013-05-28 22:08:48 +04:00
|
|
|
uint32_t mStride;
|
|
|
|
uint32_t mWidth;
|
|
|
|
uint32_t mHeight;
|
2012-07-22 00:07:26 +04:00
|
|
|
};
|
|
|
|
|
2013-05-28 22:08:48 +04:00
|
|
|
|
2012-07-22 00:07:26 +04:00
|
|
|
class AsyncDeleteIconFromDisk : public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-07-19 06:24:15 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-07-22 00:07:26 +04:00
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
2016-12-16 11:00:43 +03:00
|
|
|
explicit AsyncDeleteIconFromDisk(const nsAString &aIconPath);
|
2012-07-22 00:07:26 +04:00
|
|
|
|
|
|
|
private:
|
2014-07-15 22:56:01 +04:00
|
|
|
virtual ~AsyncDeleteIconFromDisk();
|
|
|
|
|
2012-07-22 00:07:26 +04:00
|
|
|
nsAutoString mIconPath;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AsyncDeleteAllFaviconsFromDisk : public nsIRunnable
|
|
|
|
{
|
|
|
|
public:
|
2013-07-19 06:24:15 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-07-22 00:07:26 +04:00
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
2016-12-16 11:00:43 +03:00
|
|
|
explicit AsyncDeleteAllFaviconsFromDisk(bool aIgnoreRecent = false);
|
2014-07-15 22:56:01 +04:00
|
|
|
|
2014-06-03 17:26:11 +04:00
|
|
|
private:
|
2014-07-15 22:56:01 +04:00
|
|
|
virtual ~AsyncDeleteAllFaviconsFromDisk();
|
|
|
|
|
2014-06-11 02:53:17 +04:00
|
|
|
int32_t mIcoNoDeleteSeconds;
|
2014-06-03 17:26:11 +04:00
|
|
|
bool mIgnoreRecent;
|
2017-05-24 11:38:57 +03:00
|
|
|
nsCOMPtr<nsIFile> mJumpListCacheDir;
|
2012-07-22 00:07:26 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class FaviconHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const char kJumpListCacheDir[];
|
|
|
|
static const char kShortcutCacheDir[];
|
|
|
|
static nsresult ObtainCachedIconFile(nsCOMPtr<nsIURI> aFaviconPageURI,
|
|
|
|
nsString &aICOFilePath,
|
|
|
|
nsCOMPtr<nsIThread> &aIOThread,
|
|
|
|
bool aURLShortcut);
|
|
|
|
|
2016-07-22 11:56:13 +03:00
|
|
|
static nsresult HashURI(nsCOMPtr<nsICryptoHash> &aCryptoHash,
|
2012-07-22 00:07:26 +04:00
|
|
|
nsIURI *aUri,
|
|
|
|
nsACString& aUriHash);
|
|
|
|
|
|
|
|
static nsresult GetOutputIconPath(nsCOMPtr<nsIURI> aFaviconPageURI,
|
|
|
|
nsCOMPtr<nsIFile> &aICOFile,
|
|
|
|
bool aURLShortcut);
|
|
|
|
|
2016-07-22 11:56:13 +03:00
|
|
|
static nsresult
|
2012-07-22 00:07:26 +04:00
|
|
|
CacheIconFileFromFaviconURIAsync(nsCOMPtr<nsIURI> aFaviconPageURI,
|
|
|
|
nsCOMPtr<nsIFile> aICOFile,
|
|
|
|
nsCOMPtr<nsIThread> &aIOThread,
|
|
|
|
bool aURLShortcut);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t GetICOCacheSecondsTimeout();
|
2012-07-22 00:07:26 +04:00
|
|
|
};
|
|
|
|
|
2012-01-04 14:21:44 +04:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_widget_WinUtils_h__
|