Fix for bug 261074: OnFocus fires twice when window restored

Patch by Oliver Yeoh
r=emaijala
sr=roc
This commit is contained in:
emaijala%kolumbus.fi 2007-02-20 19:45:17 +00:00
Родитель 13b88e4e05
Коммит 0202c36b7e
5 изменённых файлов: 42 добавлений и 91 удалений

Просмотреть файл

@ -52,9 +52,9 @@ class nsIController;
class nsIControllers;
class nsAString;
// {f9004db3-5272-4a8c-8b19-70a4adb8f8b6}
// {da47ea2a-5e9a-4281-9b5b-a08c0e6b1fa5}
#define NS_IFOCUSCONTROLLER_IID \
{ 0xf9004db3, 0x5272, 0x4a8c, { 0x8b, 0x19, 0x70, 0xa4, 0xad, 0xb8, 0xf8, 0xb6 } }
{ 0xda47ea2a, 0x5e9a, 0x4281, { 0x9b, 0x5b, 0xa0, 0x8c, 0x0e, 0x6b, 0x1f, 0xa5 } }
class nsIFocusController : public nsISupports {
public:
@ -85,7 +85,6 @@ public:
NS_IMETHOD GetControllers(nsIControllers** aResult)=0;
NS_IMETHOD MoveFocus(PRBool aForward, nsIDOMElement* aElt)=0;
NS_IMETHOD RewindFocusState()=0;
NS_IMETHOD ResetElementFocus() = 0;
};

Просмотреть файл

@ -123,11 +123,6 @@ nsFocusController::GetFocusedWindow(nsIDOMWindowInternal** aWindow)
NS_IMETHODIMP
nsFocusController::SetFocusedElement(nsIDOMElement* aElement)
{
if (mCurrentElement)
mPreviousElement = mCurrentElement;
else if (aElement)
mPreviousElement = aElement;
mNeedUpdateCommands = mNeedUpdateCommands || mCurrentElement != aElement;
mCurrentElement = aElement;
@ -140,15 +135,6 @@ nsFocusController::SetFocusedElement(nsIDOMElement* aElement)
return NS_OK;
}
NS_IMETHODIMP
nsFocusController::RewindFocusState()
{
mCurrentElement = mPreviousElement;
mCurrentWindow = mPreviousWindow;
return NS_OK;
}
NS_IMETHODIMP
nsFocusController::SetFocusedWindow(nsIDOMWindowInternal* aWindow)
{
@ -167,12 +153,6 @@ nsFocusController::SetFocusedWindow(nsIDOMWindowInternal* aWindow)
basewin->SetFocus();
}
if (mCurrentWindow) {
mPreviousWindow = mCurrentWindow;
} else if (win) {
mPreviousWindow = win;
}
mNeedUpdateCommands = mNeedUpdateCommands || mCurrentWindow != win;
mCurrentWindow = win;
@ -350,10 +330,8 @@ nsFocusController::Focus(nsIDOMEvent* aEvent)
nsCOMPtr<nsIDOMDocument> windowDoc;
mCurrentWindow->GetDocument(getter_AddRefs(windowDoc));
if (ownerDoc != windowDoc)
mCurrentElement = mPreviousElement = nsnull;
mCurrentElement = nsnull;
}
else
mPreviousElement = nsnull;
if (!mCurrentElement) {
UpdateCommands();
@ -545,7 +523,7 @@ nsFocusController::SetActive(PRBool aActive)
NS_IMETHODIMP
nsFocusController::ResetElementFocus()
{
mCurrentElement = mPreviousElement = nsnull;
mCurrentElement = nsnull;
return NS_OK;
}

Просмотреть файл

@ -93,7 +93,6 @@ public:
NS_IMETHOD GetControllers(nsIControllers** aResult);
NS_IMETHOD MoveFocus(PRBool aForward, nsIDOMElement* aElt);
NS_IMETHOD RewindFocusState();
NS_IMETHOD ResetElementFocus();
@ -114,9 +113,7 @@ public:
// Members
protected:
nsCOMPtr<nsIDOMElement> mCurrentElement; // [OWNER]
nsCOMPtr<nsIDOMElement> mPreviousElement; // [OWNER]
nsCOMPtr<nsPIDOMWindow> mCurrentWindow; // [OWNER]
nsCOMPtr<nsPIDOMWindow> mPreviousWindow; // [OWNER]
nsCOMPtr<nsIDOMNode> mPopupNode; // [OWNER]
nsCOMPtr<nsIDOMEvent> mPopupEvent;

Просмотреть файл

@ -2210,7 +2210,7 @@ NS_METHOD nsWindow::Enable(PRBool bState)
NS_METHOD nsWindow::IsEnabled(PRBool *aState)
{
NS_ENSURE_ARG_POINTER(aState);
*aState = !mWnd || ::IsWindowEnabled(mWnd);
*aState = !mWnd || (::IsWindowEnabled(mWnd) && ::IsWindowEnabled(::GetAncestor(mWnd, GA_ROOT)));
return NS_OK;
}
@ -2572,7 +2572,7 @@ NS_METHOD nsWindow::SetCursor(nsCursor aCursor)
gHCursor = NULL;
}
}
//}
return NS_OK;
}
@ -3819,8 +3819,6 @@ void nsWindow::ConstrainZLevel(HWND *aAfter)
// Process all nsWindows messages
//
//-------------------------------------------------------------------------
static PRBool gJustGotDeactivate = PR_FALSE;
static PRBool gJustGotActivate = PR_FALSE;
#ifdef NS_DEBUG
@ -4294,7 +4292,6 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
PRBool result = PR_FALSE; // call the default nsWindow proc
static PRBool getWheelInfo = PR_TRUE;
*aRetValue = 0;
PRBool isMozWindowTakingFocus = PR_TRUE;
nsPaletteInfo palInfo;
// Uncomment this to see all windows messages
@ -4854,11 +4851,9 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
PRInt32 fActive = LOWORD(wParam);
if (WA_INACTIVE == fActive) {
gJustGotDeactivate = PR_TRUE;
if (mIsTopWidgetWindow)
mLastKeyboardLayout = gKeyboardLayout;
} else {
gJustGotActivate = PR_TRUE;
nsMouseEvent event(PR_TRUE, NS_MOUSE_ACTIVATE, this,
nsMouseEvent::eReal);
InitEvent(event);
@ -4876,6 +4871,8 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
if (gSwitchKeyboardLayout && mLastKeyboardLayout)
ActivateKeyboardLayout(mLastKeyboardLayout, 0);
}
result = PR_TRUE;
}
break;
@ -4894,12 +4891,18 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
#endif
case WM_SETFOCUS:
result = DispatchFocus(NS_GOTFOCUS, isMozWindowTakingFocus);
if (gJustGotActivate) {
gJustGotActivate = PR_FALSE;
gJustGotDeactivate = PR_FALSE;
result = DispatchFocus(NS_ACTIVATE, isMozWindowTakingFocus);
}
{
nsWindow* topWindow = GetNSWindowPtr(::GetAncestor(mWnd, GA_ROOT));
if ((HWND)wParam == NULL ||
(topWindow && topWindow->mWnd != ::GetAncestor((HWND)wParam, GA_ROOT))) {
result = DispatchFocus(NS_ACTIVATE, PR_TRUE);
}
else {
result = DispatchFocus(NS_GOTFOCUS, PR_TRUE);
}
}
#ifdef ACCESSIBILITY
if (nsWindow::gIsAccessibilityOn) {
// Create it for the first time so that it can start firing events
@ -4943,20 +4946,29 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
ImmSetOpenStatus(hC, FALSE);
}
#endif
WCHAR className[kMaxClassNameLength];
::GetClassNameW((HWND)wParam, className, kMaxClassNameLength);
if (wcscmp(className, kWClassNameUI) &&
wcscmp(className, kWClassNameContent) &&
wcscmp(className, kWClassNameContentFrame) &&
wcscmp(className, kWClassNameDialog) &&
wcscmp(className, kWClassNameGeneral)) {
isMozWindowTakingFocus = PR_FALSE;
{
nsWindow* topWindow = GetNSWindowPtr(::GetAncestor(mWnd, GA_ROOT));
if ((HWND)wParam == NULL ||
(topWindow && topWindow->mWnd != ::GetAncestor((HWND)wParam, GA_ROOT))) {
result = DispatchFocus(NS_DEACTIVATE, PR_FALSE);
}
else {
PRBool isMozWindowTakingFocus = PR_TRUE;
WCHAR className[kMaxClassNameLength];
::GetClassNameW((HWND)wParam, className, kMaxClassNameLength);
if (wcscmp(className, kWClassNameUI) &&
wcscmp(className, kWClassNameContent) &&
wcscmp(className, kWClassNameContentFrame) &&
wcscmp(className, kWClassNameDialog) &&
wcscmp(className, kWClassNameGeneral)) {
isMozWindowTakingFocus = PR_FALSE;
}
result = DispatchFocus(NS_LOSTFOCUS, isMozWindowTakingFocus);
}
}
if (gJustGotDeactivate) {
gJustGotDeactivate = PR_FALSE;
result = DispatchFocus(NS_DEACTIVATE, isMozWindowTakingFocus);
}
result = DispatchFocus(NS_LOSTFOCUS, isMozWindowTakingFocus);
break;
case WM_WINDOWPOSCHANGED:
@ -5054,26 +5066,6 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
InitEvent(event);
result = DispatchWindowEvent(&event);
if (pl.showCmd == SW_SHOWMINIMIZED) {
// Deactivate
WCHAR className[kMaxClassNameLength];
::GetClassNameW((HWND)wParam, className, kMaxClassNameLength);
if (wcscmp(className, kWClassNameUI) &&
wcscmp(className, kWClassNameContent) &&
wcscmp(className, kWClassNameContentFrame) &&
wcscmp(className, kWClassNameDialog) &&
wcscmp(className, kWClassNameGeneral)) {
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);
}
}

Просмотреть файл

@ -354,21 +354,6 @@ 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<nsPIDOMWindow> privateDOMWindow = do_GetInterface(docShell);
if(privateDOMWindow) {
nsIFocusController *focusController =
privateDOMWindow->GetRootFocusController();
if (focusController)
focusController->RewindFocusState();
}
}
#endif
break;
}
case NS_OS_TOOLBAR: {