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>
|
2022-03-26 01:20:42 +03:00
|
|
|
#include <unordered_map>
|
2022-06-07 20:07:42 +03:00
|
|
|
#include <utility>
|
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"
|
2022-02-16 15:55:56 +03:00
|
|
|
#include "mozilla/HalScreenConfiguration.h"
|
2022-10-28 21:19:39 +03:00
|
|
|
#include "mozilla/HashTable.h"
|
2023-03-02 18:52:32 +03:00
|
|
|
#include "mozilla/LazyIdleThread.h"
|
2015-10-26 21:31:12 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/Vector.h"
|
2020-09-16 23:14:40 +03:00
|
|
|
#include "mozilla/WindowsDpiAwareness.h"
|
2021-06-21 16:50:31 +03:00
|
|
|
#include "mozilla/WindowsProcessMitigations.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/gfx/2D.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()); \
|
|
|
|
} \
|
2018-11-30 13:46:48 +03:00
|
|
|
\
|
2014-07-11 21:09:59 +04:00
|
|
|
protected: \
|
|
|
|
nsAutoRefCnt mRefCnt; \
|
|
|
|
NS_DECL_OWNINGTHREAD \
|
|
|
|
public:
|
|
|
|
|
2012-01-04 14:21:44 +04:00
|
|
|
class nsWindow;
|
2013-05-29 10:34:49 +04:00
|
|
|
struct KeyPair;
|
2012-01-04 14:21:44 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2018-08-14 10:38:03 +03:00
|
|
|
enum class PointerCapabilities : uint8_t;
|
2017-06-16 02:29:07 +03:00
|
|
|
#if defined(ACCESSIBILITY)
|
|
|
|
namespace a11y {
|
2021-02-20 02:14:32 +03:00
|
|
|
class LocalAccessible;
|
2017-06-16 02:29:07 +03:00
|
|
|
} // namespace a11y
|
|
|
|
#endif // defined(ACCESSIBILITY)
|
|
|
|
|
2022-06-07 20:07:42 +03:00
|
|
|
// Helper function: enumerate all the toplevel HWNDs attached to the current
|
|
|
|
// thread via ::EnumThreadWindows().
|
|
|
|
//
|
|
|
|
// Note that this use of ::EnumThreadWindows() is, unfortunately, not an
|
|
|
|
// abstract implementation detail.
|
|
|
|
template <typename F>
|
|
|
|
void EnumerateThreadWindows(F&& f)
|
|
|
|
// requires requires(F f, HWND h) { f(h); }
|
|
|
|
{
|
|
|
|
class Impl {
|
|
|
|
public:
|
|
|
|
F f;
|
|
|
|
explicit Impl(F&& f) : f(std::forward<F>(f)) {}
|
|
|
|
|
|
|
|
void invoke() {
|
|
|
|
WNDENUMPROC proc = &Impl::Callback;
|
|
|
|
::EnumThreadWindows(::GetCurrentThreadId(), proc,
|
|
|
|
reinterpret_cast<LPARAM>(&f));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static BOOL CALLBACK Callback(HWND hwnd, LPARAM lp) {
|
|
|
|
(*reinterpret_cast<F*>(lp))(hwnd);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Impl(std::forward<F>(f)).invoke();
|
|
|
|
}
|
|
|
|
|
2012-01-04 14:21:44 +04:00
|
|
|
namespace widget {
|
|
|
|
|
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 {
|
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;
|
2018-09-26 18:40:48 +03:00
|
|
|
static GetSystemMetricsForDpiProc sGetSystemMetricsForDpi;
|
2016-07-02 01:42:32 +03:00
|
|
|
|
2021-07-12 22:08:10 +03:00
|
|
|
// Set on Initialize().
|
|
|
|
static bool sHasPackageIdentity;
|
|
|
|
|
2012-01-04 14:21:44 +04:00
|
|
|
public:
|
2016-07-02 01:42:32 +03:00
|
|
|
class AutoSystemDpiAware {
|
|
|
|
public:
|
|
|
|
AutoSystemDpiAware() {
|
2021-06-21 16:50:31 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!IsWin32kLockedDown());
|
|
|
|
|
2016-07-02 01:42:32 +03:00
|
|
|
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);
|
2021-08-19 20:13:55 +03:00
|
|
|
static double LogToPhysFactor(HWND aWnd);
|
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
|
|
|
|
2018-09-26 18:40:48 +03:00
|
|
|
static bool HasSystemMetricsForDpi();
|
|
|
|
static int GetSystemMetricsForDpi(int nIndex, UINT dpi);
|
|
|
|
|
2022-10-28 21:19:40 +03:00
|
|
|
/**
|
|
|
|
* @param msg Windows event message
|
|
|
|
* @return User-friendly event name, or nullptr if no
|
|
|
|
* match is found.
|
|
|
|
*/
|
|
|
|
static const char* WinEventToEventName(UINT msg);
|
|
|
|
|
2020-07-22 18:08:13 +03:00
|
|
|
/**
|
|
|
|
* @param aHdc HDC for printer
|
|
|
|
* @return unwritable margins for currently set page on aHdc or empty margins
|
|
|
|
* if aHdc is null
|
|
|
|
*/
|
|
|
|
static gfx::MarginDouble GetUnwriteableMarginsForDeviceInInches(HDC aHdc);
|
|
|
|
|
2021-07-12 22:08:10 +03:00
|
|
|
static bool HasPackageIdentity() { return sHasPackageIdentity; }
|
|
|
|
|
2021-07-30 22:09:47 +03:00
|
|
|
/*
|
|
|
|
* The "family name" of a Windows app package is the full name without any of
|
|
|
|
* the components that might change during the life cycle of the app (such as
|
|
|
|
* the version number, or the architecture). This leaves only those properties
|
|
|
|
* which together serve to uniquely identify the app within one Windows
|
|
|
|
* installation, namely the base name and the publisher name. Meaning, this
|
|
|
|
* string is safe to use anywhere that a string uniquely identifying an app
|
|
|
|
* installation is called for (because multiple copies of the same app on the
|
|
|
|
* same system is not a supported feature in the app framework).
|
|
|
|
*/
|
|
|
|
static nsString GetPackageFamilyName();
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
/**
|
2022-06-07 20:07:41 +03:00
|
|
|
* SetNSWindowPtr() associates aWindow with aWnd. If aWidget is nullptr, it
|
|
|
|
* instead dissociates any nsWindow from aWnd.
|
|
|
|
*
|
|
|
|
* No AddRef is performed. May not be used off of the main thread.
|
|
|
|
*/
|
|
|
|
static void SetNSWindowPtr(HWND aWnd, nsWindow* aWindow);
|
|
|
|
/**
|
|
|
|
* GetNSWindowPtr() returns a pointer to the associated nsWindow pointer, if
|
|
|
|
* one exists, or nullptr, if not.
|
|
|
|
*
|
|
|
|
* No AddRef is performed. May not be used off of the main thread.
|
2012-01-04 14:21:44 +04:00
|
|
|
*/
|
|
|
|
static nsWindow* GetNSWindowPtr(HWND aWnd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2018-06-26 00:20:54 +03:00
|
|
|
* one of MouseEvent_Binding::MOZ_SOURCE_*. This method MUST be called during
|
2012-01-04 14:21:44 +04:00
|
|
|
* 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-11-02 15:54:44 +04:00
|
|
|
/**
|
2018-03-06 09:20:41 +03:00
|
|
|
* ConvertHRGNToRegion converts a Windows HRGN to an LayoutDeviceIntRegion.
|
2012-11-02 15:54:44 +04:00
|
|
|
*
|
|
|
|
* aRgn the HRGN to convert.
|
2018-03-06 09:20:41 +03:00
|
|
|
* returns the LayoutDeviceIntRegion.
|
2012-11-02 15:54:44 +04:00
|
|
|
*/
|
2018-03-06 09:20:41 +03:00
|
|
|
static LayoutDeviceIntRegion ConvertHRGNToRegion(HRGN aRgn);
|
2012-11-02 15:54:44 +04:00
|
|
|
|
|
|
|
/**
|
2018-03-06 09:20:41 +03:00
|
|
|
* ToIntRect converts a Windows RECT to a LayoutDeviceIntRect.
|
2012-11-02 15:54:44 +04:00
|
|
|
*
|
|
|
|
* aRect the RECT to convert.
|
2018-03-06 09:20:41 +03:00
|
|
|
* returns the LayoutDeviceIntRect.
|
2012-11-02 15:54:44 +04:00
|
|
|
*/
|
2018-03-06 09:20:41 +03:00
|
|
|
static LayoutDeviceIntRect ToIntRect(const RECT& aRect);
|
2012-11-02 15:54:44 +04: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);
|
2020-12-21 08:52:03 +03:00
|
|
|
static bool IsIMEEnabled(IMEEnabled aIMEState);
|
2013-05-29 10:34:49 +04:00
|
|
|
|
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,
|
Bug 900750 - part 2: Make ModifierKeyState and VirtualKey treat AltGraph as new modifier and won't set Control and Alt state while AltGraph is active r=m_kato,smaug
By the proposal from Google, <https://github.com/w3c/uievents/issues/147>,
Chromium treat AltRight key as "AltGraph" modifier if the keyboard layout
has AltGr key.
When AltRight key is pressed with a keyboard layout which has AltGr key,
modifiers should as following:
1. "keydown" for ControlLeft:
ctrlKey: true, altKey: false, getModifierState("AltGraph"): false
2. "keydown" for AltRight:
ctrlKey: false, altKey: false, getModifierState("AltGraph"): true
3. Some "keydown", "keypress" and "keyup" events:
ctrlKey: false, altKey: false, getModifierState("AltGraph"): true
4. "keyup" for ControlLeft:
ctrlKey: false, altKey: false, getModifierState("AltGraph"): true
5. "keyup" for AltRight:
ctrlKey: false, altKey: false, getModifierState("AltGraph"): false
So, only when the preceding "keydown" event for ControlLeft, ctrlKey should
be set to true as usual. However, after AltRight key is pressed actually,
we should treat "AltGraph" modifier is true and both ctrlKey and altKey
should be set to false for web apps can handle text input normally.
So, MODIFIER_ALTGRAPH and MODIFIER_CONTROL/MODIFIER_ALT should not be set
at the same time.
This patch makes ModifierKeyState have only MODIFIER_ALTGRAPH or
MODIFIER_CONTROL/MODIFIER_ALT.
Additionally, this patch makes VirtualKey::ShiftState treat "AltGraph" as a
modifier. So, now, VirtualKey needs to convert ShiftState to index value when
it accesses its mShiftStates array. Therefore, this patch adds
VirtualKey::ToIndex() and make each VirtualKey method use it before
accessing mShiftStates.
Note that this patch also fixes bug of WinUtils::SetupKeyModifiersSequence().
The constructor of KeyPair takes 2 keycode values, but the second virtual
keycode can have scancode to distinguish if the key is left or right.
However, WinUtils::SetupKeyModifiersSequence() never sets scancode to
KeyPair. Therefore, it fails to dispatch AltRight key event.
MozReview-Commit-ID: 7ealxJH9KlZ
--HG--
extra : rebase_source : 761bc4416222def020a0731d6ae7940ef074ebe0
2018-05-30 11:27:31 +03:00
|
|
|
uint32_t aModifiers, UINT aMessage);
|
2013-05-29 10:34:49 +04:00
|
|
|
|
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();
|
|
|
|
|
2018-08-14 10:38:03 +03:00
|
|
|
/**
|
|
|
|
* Returns the windows power platform role, which is useful for detecting
|
|
|
|
* tablets.
|
|
|
|
*/
|
|
|
|
static POWER_PLATFORM_ROLE GetPowerPlatformRole();
|
|
|
|
|
2018-08-14 10:38:03 +03:00
|
|
|
// For pointer and hover media queries features.
|
|
|
|
static PointerCapabilities GetPrimaryPointerCapabilities();
|
|
|
|
// For any-pointer and any-hover media queries features.
|
|
|
|
static PointerCapabilities GetAllPointerCapabilities();
|
2023-07-24 22:04:51 +03:00
|
|
|
// Returns a string containing a comma-separated list of Fluent IDs
|
|
|
|
// representing the currently active pointing devices
|
|
|
|
static void GetPointerExplanation(nsAString* aExplanation);
|
2018-08-14 10:38:03 +03:00
|
|
|
|
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
|
|
|
|
2018-03-27 16:09:32 +03:00
|
|
|
/**
|
|
|
|
* Returns true if executable's path is on a network drive.
|
|
|
|
*/
|
|
|
|
static bool RunningFromANetworkDrive();
|
|
|
|
|
2013-08-15 08:25:12 +04:00
|
|
|
static void Initialize();
|
|
|
|
|
2018-03-23 23:41:58 +03:00
|
|
|
static nsresult WriteBitmap(nsIFile* aFile,
|
|
|
|
mozilla::gfx::SourceSurface* surface);
|
|
|
|
// This function is a helper, but it cannot be called from the main thread.
|
|
|
|
// Use the one above!
|
|
|
|
static nsresult WriteBitmap(nsIFile* aFile, imgIContainer* aImage);
|
|
|
|
|
2016-01-17 00:09:28 +03:00
|
|
|
/**
|
2018-11-02 10:59:17 +03:00
|
|
|
* Wrapper for PathCanonicalize().
|
|
|
|
* Upon success, the resulting output string length is <= MAX_PATH.
|
|
|
|
* @param aPath [in,out] The path to transform.
|
|
|
|
* @return true on success, false on failure.
|
2016-01-17 00:09:28 +03:00
|
|
|
*/
|
2018-11-02 10:59:17 +03:00
|
|
|
static bool CanonicalizePath(nsAString& aPath);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts short paths (e.g. "C:\\PROGRA~1\\XYZ") to full paths.
|
|
|
|
* Upon success, the resulting output string length is <= MAX_PATH.
|
|
|
|
* @param aPath [in,out] The path to transform.
|
|
|
|
* @return true on success, false on failure.
|
|
|
|
*/
|
|
|
|
static bool MakeLongPath(nsAString& aPath);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper for PathUnExpandEnvStringsW().
|
|
|
|
* Upon success, the resulting output string length is <= MAX_PATH.
|
|
|
|
* @param aPath [in,out] The path to transform.
|
|
|
|
* @return true on success, false on failure.
|
|
|
|
*/
|
|
|
|
static bool UnexpandEnvVars(nsAString& aPath);
|
2016-01-17 00:09:28 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a semicolon-delimited list of DLL files derived from AppInit_DLLs
|
|
|
|
*/
|
|
|
|
static bool GetAppInitDLLs(nsAString& aOutput);
|
|
|
|
|
2018-11-02 10:59:17 +03:00
|
|
|
enum class PathTransformFlags : uint32_t {
|
|
|
|
Canonicalize = 1,
|
|
|
|
Lengthen = 2,
|
|
|
|
UnexpandEnvVars = 4,
|
2019-11-11 18:39:21 +03:00
|
|
|
RequireFilePath = 8,
|
|
|
|
|
|
|
|
Default = 7, // Default omits RequireFilePath
|
2018-11-02 10:59:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a path, transforms it in preparation to be reported via telemetry.
|
|
|
|
* That can include canonicalization, converting short to long paths,
|
|
|
|
* unexpanding environment strings, and removing potentially sensitive data
|
|
|
|
* from the path.
|
|
|
|
*
|
|
|
|
* @param aPath [in,out] The path to transform.
|
|
|
|
* @param aFlags [in] Specifies which transformations to perform, allowing
|
|
|
|
* the caller to skip operations they know have already been
|
|
|
|
* performed.
|
|
|
|
* @return true on success, false on failure.
|
|
|
|
*/
|
|
|
|
static bool PreparePathForTelemetry(
|
|
|
|
nsAString& aPath,
|
|
|
|
PathTransformFlags aFlags = PathTransformFlags::Default);
|
|
|
|
|
2019-08-21 23:59:43 +03:00
|
|
|
static const size_t kMaxWhitelistedItems = 3;
|
|
|
|
using WhitelistVec =
|
2020-03-17 15:42:12 +03:00
|
|
|
Vector<std::pair<nsString, nsDependentString>, kMaxWhitelistedItems>;
|
2018-11-02 10:59:17 +03:00
|
|
|
|
2019-08-21 23:59:43 +03:00
|
|
|
static const WhitelistVec& GetWhitelistedPaths();
|
|
|
|
|
2021-10-06 10:21:59 +03:00
|
|
|
static bool GetClassName(HWND aHwnd, nsAString& aName);
|
|
|
|
|
2021-10-26 05:37:42 +03:00
|
|
|
static void EnableWindowOcclusion(const bool aEnable);
|
|
|
|
|
2022-06-14 22:41:30 +03:00
|
|
|
static bool GetTimezoneName(wchar_t* aBuffer);
|
|
|
|
|
2022-09-15 13:13:14 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
static nsresult SetHiDPIMode(bool aHiDPI);
|
|
|
|
static nsresult RestoreHiDPIMode();
|
|
|
|
#endif
|
|
|
|
|
2022-11-24 18:10:15 +03:00
|
|
|
static bool GetAutoRotationState(AR_STATE* aRotationState);
|
|
|
|
|
2023-10-07 00:23:45 +03:00
|
|
|
static void GetClipboardFormatAsString(UINT aFormat, nsAString& aOutput);
|
|
|
|
|
2019-08-21 23:59:43 +03:00
|
|
|
private:
|
|
|
|
static WhitelistVec BuildWhitelist();
|
|
|
|
|
|
|
|
public:
|
2016-09-23 00:07:01 +03:00
|
|
|
#ifdef ACCESSIBILITY
|
2021-02-20 02:14:32 +03:00
|
|
|
static a11y::LocalAccessible* GetRootAccessibleForHWND(HWND aHwnd);
|
2016-09-23 00:07:01 +03:00
|
|
|
#endif
|
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
|
|
|
|
2023-03-02 18:52:32 +03:00
|
|
|
AsyncFaviconDataReady(nsIURI* aNewURI, RefPtr<LazyIdleThread>& aIOThread,
|
2020-01-06 16:31:54 +03:00
|
|
|
const bool aURLShortcut,
|
|
|
|
already_AddRefed<nsIRunnable> aRunnable);
|
2012-07-22 00:07:26 +04:00
|
|
|
nsresult OnFaviconDataNotAvailable(void);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-07-22 00:07:26 +04:00
|
|
|
private:
|
2014-07-15 22:56:01 +04:00
|
|
|
~AsyncFaviconDataReady() {}
|
|
|
|
|
2012-07-22 00:07:26 +04:00
|
|
|
nsCOMPtr<nsIURI> mNewURI;
|
2023-03-02 18:52:32 +03:00
|
|
|
RefPtr<LazyIdleThread> mIOThread;
|
2020-01-06 16:31:54 +03:00
|
|
|
nsCOMPtr<nsIRunnable> mRunnable;
|
2012-07-22 00:07:26 +04:00
|
|
|
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:
|
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, uint32_t aStride,
|
2015-10-26 21:31:12 +03:00
|
|
|
uint32_t aWidth, uint32_t aHeight,
|
2020-01-06 16:31:54 +03:00
|
|
|
already_AddRefed<nsIRunnable> aRunnable);
|
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;
|
2020-01-06 16:31:54 +03:00
|
|
|
nsCOMPtr<nsIRunnable> mRunnable;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
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[];
|
2020-01-06 16:31:54 +03:00
|
|
|
static nsresult ObtainCachedIconFile(
|
|
|
|
nsCOMPtr<nsIURI> aFaviconPageURI, nsString& aICOFilePath,
|
2023-03-02 18:52:32 +03:00
|
|
|
RefPtr<LazyIdleThread>& aIOThread, bool aURLShortcut,
|
2020-01-06 16:31:54 +03:00
|
|
|
already_AddRefed<nsIRunnable> aRunnable = nullptr);
|
2012-07-22 00:07:26 +04:00
|
|
|
|
2016-07-22 11:56:13 +03:00
|
|
|
static nsresult HashURI(nsCOMPtr<nsICryptoHash>& aCryptoHash, nsIURI* aUri,
|
2012-07-22 00:07:26 +04:00
|
|
|
nsACString& aUriHash);
|
|
|
|
|
|
|
|
static nsresult GetOutputIconPath(nsCOMPtr<nsIURI> aFaviconPageURI,
|
|
|
|
nsCOMPtr<nsIFile>& aICOFile,
|
|
|
|
bool aURLShortcut);
|
|
|
|
|
|
|
|
static nsresult CacheIconFileFromFaviconURIAsync(
|
|
|
|
nsCOMPtr<nsIURI> aFaviconPageURI, nsCOMPtr<nsIFile> aICOFile,
|
2023-03-02 18:52:32 +03:00
|
|
|
RefPtr<LazyIdleThread>& aIOThread, bool aURLShortcut,
|
2020-01-06 16:31:54 +03:00
|
|
|
already_AddRefed<nsIRunnable> aRunnable);
|
2012-07-22 00:07:26 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t GetICOCacheSecondsTimeout();
|
2012-07-22 00:07:26 +04:00
|
|
|
};
|
|
|
|
|
2018-11-02 10:59:17 +03:00
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(WinUtils::PathTransformFlags);
|
|
|
|
|
2023-05-11 04:13:05 +03:00
|
|
|
// RTL shim windows are temporary child windows of our nsWindows created to
|
|
|
|
// address RTL issues in picker dialogs. (See bug 588735.)
|
|
|
|
class MOZ_STACK_CLASS ScopedRtlShimWindow {
|
|
|
|
public:
|
|
|
|
explicit ScopedRtlShimWindow(nsIWidget* aParent);
|
|
|
|
~ScopedRtlShimWindow();
|
|
|
|
|
|
|
|
ScopedRtlShimWindow(const ScopedRtlShimWindow&) = delete;
|
|
|
|
ScopedRtlShimWindow(ScopedRtlShimWindow&&) = delete;
|
|
|
|
|
|
|
|
HWND get() const { return mWnd; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
HWND mWnd;
|
|
|
|
};
|
|
|
|
|
2012-01-04 14:21:44 +04:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_widget_WinUtils_h__
|