Bug 1936325 - Miscellaneous windows widget clean-ups. r=win-reviewers,rkraesig
Did these while debugging bug 1936164. No behavior change intended. Differential Revision: https://phabricator.services.mozilla.com/D231706
This commit is contained in:
@@ -306,7 +306,7 @@ class WinUtils {
|
|||||||
* | | TRUE | FALSE |
|
* | | TRUE | FALSE |
|
||||||
+ +-----------------+-------+-----------------------+-----------------------+
|
+ +-----------------+-------+-----------------------+-----------------------+
|
||||||
* | | | * an independent top level window |
|
* | | | * an independent top level window |
|
||||||
* | | TRUE | * a pupup window (WS_POPUP) |
|
* | | TRUE | * a popup window (WS_POPUP) |
|
||||||
* | | | * an owned top level window (like dialog) |
|
* | | | * an owned top level window (like dialog) |
|
||||||
* | aStopIfNotChild +-------+-----------------------+-----------------------+
|
* | aStopIfNotChild +-------+-----------------------+-----------------------+
|
||||||
* | | | * independent window | * only an independent |
|
* | | | * independent window | * only an independent |
|
||||||
|
|||||||
@@ -515,75 +515,73 @@ class TIPMessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MOZ_RAII A11yInstantiationBlocker {
|
class MOZ_RAII A11yInstantiationBlocker{public : A11yInstantiationBlocker(){
|
||||||
public:
|
if (!TIPMessageHandler::sInstance){return;
|
||||||
A11yInstantiationBlocker() {
|
} ++TIPMessageHandler::sInstance->mA11yBlockCount;
|
||||||
if (!TIPMessageHandler::sInstance) {
|
} // namespace mozilla
|
||||||
return;
|
|
||||||
}
|
|
||||||
++TIPMessageHandler::sInstance->mA11yBlockCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
~A11yInstantiationBlocker() {
|
~A11yInstantiationBlocker() {
|
||||||
if (!TIPMessageHandler::sInstance) {
|
if (!TIPMessageHandler::sInstance) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MOZ_ASSERT(TIPMessageHandler::sInstance->mA11yBlockCount > 0);
|
MOZ_ASSERT(TIPMessageHandler::sInstance->mA11yBlockCount > 0);
|
||||||
--TIPMessageHandler::sInstance->mA11yBlockCount;
|
--TIPMessageHandler::sInstance->mA11yBlockCount;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
friend class A11yInstantiationBlocker;
|
friend class A11yInstantiationBlocker;
|
||||||
|
|
||||||
static LRESULT CALLBACK TIPHook(int aCode, WPARAM aWParam, LPARAM aLParam) {
|
|
||||||
if (aCode < 0 || !sInstance) {
|
|
||||||
return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
MSG* msg = reinterpret_cast<MSG*>(aLParam);
|
|
||||||
UINT& msgCode = msg->message;
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < std::size(sInstance->mMessages); ++i) {
|
|
||||||
if (msgCode == sInstance->mMessages[i]) {
|
|
||||||
A11yInstantiationBlocker block;
|
|
||||||
return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
static LRESULT CALLBACK TIPHook(int aCode, WPARAM aWParam, LPARAM aLParam) {
|
||||||
|
if (aCode < 0 || !sInstance) {
|
||||||
return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
|
return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
static LRESULT WINAPI SendMessageTimeoutWHook(HWND aHwnd, UINT aMsgCode,
|
MSG* msg = reinterpret_cast<MSG*>(aLParam);
|
||||||
WPARAM aWParam, LPARAM aLParam,
|
UINT& msgCode = msg->message;
|
||||||
UINT aFlags, UINT aTimeout,
|
|
||||||
PDWORD_PTR aMsgResult) {
|
for (uint32_t i = 0; i < std::size(sInstance->mMessages); ++i) {
|
||||||
// We don't want to handle this unless the message is a WM_GETOBJECT that we
|
if (msgCode == sInstance->mMessages[i]) {
|
||||||
// want to block, and the aHwnd is a nsWindow that belongs to the current
|
A11yInstantiationBlocker block;
|
||||||
// (i.e., main) thread.
|
return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
|
||||||
if (!aMsgResult || aMsgCode != WM_GETOBJECT ||
|
|
||||||
static_cast<LONG>(aLParam) != OBJID_CLIENT || !::NS_IsMainThread() ||
|
|
||||||
!WinUtils::GetNSWindowPtr(aHwnd) || !IsA11yBlocked()) {
|
|
||||||
return sSendMessageTimeoutWStub(aHwnd, aMsgCode, aWParam, aLParam, aFlags,
|
|
||||||
aTimeout, aMsgResult);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// In this case we want to fake the result that would happen if we had
|
|
||||||
// decided not to handle WM_GETOBJECT in our WndProc. We hand the message
|
|
||||||
// off to DefWindowProc to accomplish this.
|
|
||||||
*aMsgResult = static_cast<DWORD_PTR>(
|
|
||||||
::DefWindowProcW(aHwnd, aMsgCode, aWParam, aLParam));
|
|
||||||
|
|
||||||
return static_cast<LRESULT>(TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static WindowsDllInterceptor::FuncHookType<decltype(&SendMessageTimeoutW)>
|
return ::CallNextHookEx(nullptr, aCode, aWParam, aLParam);
|
||||||
sSendMessageTimeoutWStub;
|
}
|
||||||
static StaticAutoPtr<TIPMessageHandler> sInstance;
|
|
||||||
|
|
||||||
HHOOK mHook;
|
static LRESULT WINAPI SendMessageTimeoutWHook(HWND aHwnd, UINT aMsgCode,
|
||||||
UINT mMessages[7];
|
WPARAM aWParam, LPARAM aLParam,
|
||||||
uint32_t mA11yBlockCount;
|
UINT aFlags, UINT aTimeout,
|
||||||
};
|
PDWORD_PTR aMsgResult) {
|
||||||
|
// We don't want to handle this unless the message is a WM_GETOBJECT that we
|
||||||
|
// want to block, and the aHwnd is a nsWindow that belongs to the current
|
||||||
|
// (i.e., main) thread.
|
||||||
|
if (!aMsgResult || aMsgCode != WM_GETOBJECT ||
|
||||||
|
static_cast<LONG>(aLParam) != OBJID_CLIENT || !::NS_IsMainThread() ||
|
||||||
|
!WinUtils::GetNSWindowPtr(aHwnd) || !IsA11yBlocked()) {
|
||||||
|
return sSendMessageTimeoutWStub(aHwnd, aMsgCode, aWParam, aLParam, aFlags,
|
||||||
|
aTimeout, aMsgResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
// In this case we want to fake the result that would happen if we had
|
||||||
|
// decided not to handle WM_GETOBJECT in our WndProc. We hand the message
|
||||||
|
// off to DefWindowProc to accomplish this.
|
||||||
|
*aMsgResult = static_cast<DWORD_PTR>(
|
||||||
|
::DefWindowProcW(aHwnd, aMsgCode, aWParam, aLParam));
|
||||||
|
|
||||||
|
return static_cast<LRESULT>(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static WindowsDllInterceptor::FuncHookType<decltype(&SendMessageTimeoutW)>
|
||||||
|
sSendMessageTimeoutWStub;
|
||||||
|
static StaticAutoPtr<TIPMessageHandler> sInstance;
|
||||||
|
|
||||||
|
HHOOK mHook;
|
||||||
|
UINT mMessages[7];
|
||||||
|
uint32_t mA11yBlockCount;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
WindowsDllInterceptor::FuncHookType<decltype(&SendMessageTimeoutW)>
|
WindowsDllInterceptor::FuncHookType<decltype(&SendMessageTimeoutW)>
|
||||||
TIPMessageHandler::sSendMessageTimeoutWStub;
|
TIPMessageHandler::sSendMessageTimeoutWStub;
|
||||||
@@ -1202,7 +1200,7 @@ void nsWindow::Destroy() {
|
|||||||
|
|
||||||
// Our windows can be subclassed which may prevent us receiving WM_DESTROY. If
|
// Our windows can be subclassed which may prevent us receiving WM_DESTROY. If
|
||||||
// OnDestroy() didn't get called, call it now.
|
// OnDestroy() didn't get called, call it now.
|
||||||
if (false == mOnDestroyCalled) {
|
if (!mOnDestroyCalled) {
|
||||||
MSGResult msgResult;
|
MSGResult msgResult;
|
||||||
mWindowHook.Notify(mWnd, WM_DESTROY, 0, 0, msgResult);
|
mWindowHook.Notify(mWnd, WM_DESTROY, 0, 0, msgResult);
|
||||||
OnDestroy();
|
OnDestroy();
|
||||||
@@ -2324,23 +2322,24 @@ bool nsWindow::IsEnabled() const {
|
|||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
|
||||||
void nsWindow::SetFocus(Raise aRaise, mozilla::dom::CallerType aCallerType) {
|
void nsWindow::SetFocus(Raise aRaise, mozilla::dom::CallerType aCallerType) {
|
||||||
if (mWnd) {
|
if (!mWnd) {
|
||||||
#ifdef WINSTATE_DEBUG_OUTPUT
|
return;
|
||||||
if (mWnd == WinUtils::GetTopLevelHWND(mWnd)) {
|
|
||||||
MOZ_LOG(gWindowsLog, LogLevel::Info,
|
|
||||||
("*** SetFocus: [ top] raise=%d\n", aRaise == Raise::Yes));
|
|
||||||
} else {
|
|
||||||
MOZ_LOG(gWindowsLog, LogLevel::Info,
|
|
||||||
("*** SetFocus: [child] raise=%d\n", aRaise == Raise::Yes));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
// Uniconify, if necessary
|
|
||||||
HWND toplevelWnd = WinUtils::GetTopLevelHWND(mWnd);
|
|
||||||
if (aRaise == Raise::Yes && ::IsIconic(toplevelWnd)) {
|
|
||||||
::ShowWindow(toplevelWnd, SW_RESTORE);
|
|
||||||
}
|
|
||||||
::SetFocus(mWnd);
|
|
||||||
}
|
}
|
||||||
|
#ifdef WINSTATE_DEBUG_OUTPUT
|
||||||
|
if (mWnd == WinUtils::GetTopLevelHWND(mWnd)) {
|
||||||
|
MOZ_LOG(gWindowsLog, LogLevel::Info,
|
||||||
|
("*** SetFocus: [ top] raise=%d\n", aRaise == Raise::Yes));
|
||||||
|
} else {
|
||||||
|
MOZ_LOG(gWindowsLog, LogLevel::Info,
|
||||||
|
("*** SetFocus: [child] raise=%d\n", aRaise == Raise::Yes));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// Uniconify, if necessary
|
||||||
|
HWND toplevelWnd = WinUtils::GetTopLevelHWND(mWnd);
|
||||||
|
if (aRaise == Raise::Yes && ::IsIconic(toplevelWnd)) {
|
||||||
|
::ShowWindow(toplevelWnd, SW_RESTORE);
|
||||||
|
}
|
||||||
|
::SetFocus(mWnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************
|
/**************************************************************
|
||||||
@@ -4631,8 +4630,9 @@ LRESULT CALLBACK nsWindow::WindowProcInternal(HWND hWnd, UINT msg,
|
|||||||
nsAutoRollup autoRollup;
|
nsAutoRollup autoRollup;
|
||||||
|
|
||||||
LRESULT popupHandlingResult;
|
LRESULT popupHandlingResult;
|
||||||
if (DealWithPopups(hWnd, msg, wParam, lParam, &popupHandlingResult))
|
if (DealWithPopups(hWnd, msg, wParam, lParam, &popupHandlingResult)) {
|
||||||
return popupHandlingResult;
|
return popupHandlingResult;
|
||||||
|
}
|
||||||
|
|
||||||
// Call ProcessMessage
|
// Call ProcessMessage
|
||||||
LRESULT retValue;
|
LRESULT retValue;
|
||||||
@@ -5559,40 +5559,42 @@ bool nsWindow::ProcessMessageInternal(UINT msg, WPARAM& wParam, LPARAM& lParam,
|
|||||||
// events arrive.
|
// events arrive.
|
||||||
case WM_ACTIVATE: {
|
case WM_ACTIVATE: {
|
||||||
int32_t fActive = LOWORD(wParam);
|
int32_t fActive = LOWORD(wParam);
|
||||||
if (mWidgetListener) {
|
if (!mWidgetListener) {
|
||||||
if (WA_INACTIVE == fActive) {
|
break;
|
||||||
// when minimizing a window, the deactivation and focus events will
|
}
|
||||||
// be fired in the reverse order. Instead, just deactivate right away.
|
if (WA_INACTIVE == fActive) {
|
||||||
// This can also happen when a modal system dialog is opened, so check
|
// when minimizing a window, the deactivation and focus events will
|
||||||
// if the last window to receive the WM_KILLFOCUS message was this one
|
// be fired in the reverse order. Instead, just deactivate right away.
|
||||||
// or a child of this one.
|
// This can also happen when a modal system dialog is opened, so check
|
||||||
if (HIWORD(wParam) ||
|
// if the last window to receive the WM_KILLFOCUS message was this one
|
||||||
(mLastKillFocusWindow &&
|
// or a child of this one.
|
||||||
(GetTopLevelForFocus(mLastKillFocusWindow) == mWnd))) {
|
if (HIWORD(wParam) ||
|
||||||
DispatchFocusToTopLevelWindow(false);
|
(mLastKillFocusWindow &&
|
||||||
} else {
|
(GetTopLevelForFocus(mLastKillFocusWindow) == mWnd))) {
|
||||||
sJustGotDeactivate = true;
|
DispatchFocusToTopLevelWindow(false);
|
||||||
}
|
|
||||||
if (IsTopLevelWidget()) {
|
|
||||||
mLastKeyboardLayout = KeyboardLayout::GetLayout();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
StopFlashing();
|
sJustGotDeactivate = true;
|
||||||
|
}
|
||||||
|
if (IsTopLevelWidget()) {
|
||||||
|
mLastKeyboardLayout = KeyboardLayout::GetLayout();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
StopFlashing();
|
||||||
|
|
||||||
sJustGotActivate = true;
|
sJustGotActivate = true;
|
||||||
WidgetMouseEvent event(true, eMouseActivate, this,
|
WidgetMouseEvent event(true, eMouseActivate, this,
|
||||||
WidgetMouseEvent::eReal);
|
WidgetMouseEvent::eReal);
|
||||||
InitEvent(event);
|
InitEvent(event);
|
||||||
ModifierKeyState modifierKeyState;
|
ModifierKeyState modifierKeyState;
|
||||||
modifierKeyState.InitInputEvent(event);
|
modifierKeyState.InitInputEvent(event);
|
||||||
DispatchInputEvent(&event);
|
DispatchInputEvent(&event);
|
||||||
if (sSwitchKeyboardLayout && mLastKeyboardLayout)
|
if (sSwitchKeyboardLayout && mLastKeyboardLayout) {
|
||||||
ActivateKeyboardLayout(mLastKeyboardLayout, 0);
|
ActivateKeyboardLayout(mLastKeyboardLayout, 0);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ACCESSIBILITY
|
#ifdef ACCESSIBILITY
|
||||||
a11y::LazyInstantiator::ResetUiaDetectionCache();
|
a11y::LazyInstantiator::ResetUiaDetectionCache();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user