From eecbbc3392feedda8782821f09f9d651b68d5ae8 Mon Sep 17 00:00:00 2001 From: "saari%netscape.com" Date: Thu, 20 Jun 2002 04:55:13 +0000 Subject: [PATCH] win32 only fix for 82534. focus goes wonky after minimizing a window. r=bryner, sr=jag git-svn-id: svn://10.0.0.236/trunk@123675 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/dom/public/base/nsIFocusController.h | 1 + mozilla/dom/src/base/nsFocusController.cpp | 13 +++++++++++++ mozilla/dom/src/base/nsFocusController.h | 3 +++ mozilla/widget/src/windows/nsWindow.cpp | 17 +++++++++++++++++ .../xpfe/appshell/src/nsWebShellWindow.cpp | 19 +++++++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/mozilla/dom/public/base/nsIFocusController.h b/mozilla/dom/public/base/nsIFocusController.h index c365a070c90..e1d56fa361c 100644 --- a/mozilla/dom/public/base/nsIFocusController.h +++ b/mozilla/dom/public/base/nsIFocusController.h @@ -63,6 +63,7 @@ public: NS_IMETHOD GetControllers(nsIControllers** aResult)=0; NS_IMETHOD MoveFocus(PRBool aForward, nsIDOMElement* aElt)=0; + NS_IMETHOD RewindFocusState()=0; }; #endif // nsIFocusController_h__ diff --git a/mozilla/dom/src/base/nsFocusController.cpp b/mozilla/dom/src/base/nsFocusController.cpp index 63bd692a9a2..ebac3b32b57 100644 --- a/mozilla/dom/src/base/nsFocusController.cpp +++ b/mozilla/dom/src/base/nsFocusController.cpp @@ -100,6 +100,7 @@ nsFocusController::GetFocusedWindow(nsIDOMWindowInternal** aWindow) NS_IMETHODIMP nsFocusController::SetFocusedElement(nsIDOMElement* aElement) { + mPreviousElement = mCurrentElement; mCurrentElement = aElement; if (!mSuppressFocus) { @@ -111,6 +112,15 @@ nsFocusController::SetFocusedElement(nsIDOMElement* aElement) return NS_OK; } +NS_IMETHODIMP +nsFocusController::RewindFocusState() +{ + mCurrentElement = mPreviousElement; + mCurrentWindow = mPreviousWindow; + + return NS_OK; +} + NS_IMETHODIMP nsFocusController::SetFocusedWindow(nsIDOMWindowInternal* aWindow) { @@ -124,6 +134,9 @@ nsFocusController::SetFocusedWindow(nsIDOMWindowInternal* aWindow) basewin->SetFocus(); } } + if(mCurrentWindow) mPreviousWindow = mCurrentWindow; + else if (aWindow) mPreviousWindow = aWindow; + mCurrentWindow = aWindow; return NS_OK; } diff --git a/mozilla/dom/src/base/nsFocusController.h b/mozilla/dom/src/base/nsFocusController.h index 8fa3ec0493a..3bb5186870b 100644 --- a/mozilla/dom/src/base/nsFocusController.h +++ b/mozilla/dom/src/base/nsFocusController.h @@ -72,6 +72,7 @@ public: NS_IMETHOD GetControllers(nsIControllers** aResult); NS_IMETHOD MoveFocus(PRBool aForward, nsIDOMElement* aElt); + NS_IMETHOD RewindFocusState(); // nsIDOMFocusListener NS_IMETHOD Focus(nsIDOMEvent* aEvent); @@ -89,7 +90,9 @@ public: // Members protected: nsCOMPtr mCurrentElement; // [OWNER] + nsCOMPtr mPreviousElement; // [OWNER] nsCOMPtr mCurrentWindow; // [OWNER] + nsCOMPtr mPreviousWindow; // [OWNER] nsCOMPtr mPopupNode; // [OWNER] PRUint32 mSuppressFocus; diff --git a/mozilla/widget/src/windows/nsWindow.cpp b/mozilla/widget/src/windows/nsWindow.cpp index 760715b7e47..324c8973cdd 100644 --- a/mozilla/widget/src/windows/nsWindow.cpp +++ b/mozilla/widget/src/windows/nsWindow.cpp @@ -3920,6 +3920,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT result = DispatchFocus(NS_GOTFOCUS, isMozWindowTakingFocus); if(gJustGotActivate) { gJustGotActivate = PR_FALSE; + gJustGotDeactivate = PR_FALSE; result = DispatchFocus(NS_ACTIVATE, isMozWindowTakingFocus); } #ifdef ACCESSIBILITY @@ -4035,6 +4036,22 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT InitEvent(event, NS_SIZEMODE); result = DispatchWindowEvent(&event); + + if (pl.showCmd == SW_SHOWMINIMIZED) { + // Deactivate + char className[19]; + ::GetClassName((HWND)wParam, className, 19); + if(strcmp(className, WindowClass())) + isMozWindowTakingFocus = PR_FALSE; + + gJustGotDeactivate = PR_FALSE; + result = DispatchFocus(NS_DEACTIVATE, isMozWindowTakingFocus); + } else if (pl.showCmd == SW_SHOWNORMAL){ + // Make sure we're active + result = DispatchFocus(NS_GOTFOCUS, PR_TRUE); + result = DispatchFocus(NS_ACTIVATE, PR_TRUE); + } + NS_RELEASE(event.widget); } break; diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index a187ec251ec..ed535603ab9 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -450,6 +450,25 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) // the state and pass the event on to the OS. The day is coming // when we'll handle the event here, and the return result will // then need to be different. +#ifdef XP_WIN + // This is a nasty hack to get around the fact that win32 sends the kill focus + // event in a different sequence than the deactivate depending on if you're + // minimizing the window vs. just clicking in a different window to cause + // the deactivation. Bug #82534 + if(modeEvent->mSizeMode = nsSizeMode_Minimized) { + nsCOMPtr domWindow; + eventWindow->ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow)); + if (domWindow) { + nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); + if(privateDOMWindow) { + nsCOMPtr focusController; + privateDOMWindow->GetRootFocusController(getter_AddRefs(focusController)); + if (focusController) + focusController->RewindFocusState(); + } + } + } +#endif break; } case NS_OS_TOOLBAR: {