Fix for 54203. r=saari, a=brendan

git-svn-id: svn://10.0.0.236/trunk@82310 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
hyatt%netscape.com
2000-11-04 08:21:20 +00:00
parent 03edc947cd
commit 61b754fcae
37 changed files with 1773 additions and 1797 deletions

View File

@@ -81,11 +81,7 @@
#include "nsCExternalHandlerService.h"
#include "nsIExternalProtocolService.h"
// XXX Very unfortunate dependencies. These are required to fix
// some serious focus bugs. Please read my comment in
// SetupNewViewer. -- hyatt
#include "nsIDOMXULDocument.h"
#include "nsIDOMXULCommandDispatcher.h"
#include "nsIFocusController.h"
static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
static NS_DEFINE_CID(kPlatformCharsetCID, NS_PLATFORMCHARSET_CID);
@@ -1681,6 +1677,15 @@ NS_IMETHODIMP nsDocShell::Destroy()
if(docShellParentAsNode)
docShellParentAsNode->RemoveChild(this);
if (mScriptGlobal) {
nsCOMPtr<nsIFocusController> focusController;
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(mScriptGlobal);
ourWindow->GetRootFocusController(getter_AddRefs(focusController));
if (focusController) {
focusController->SetFocusedWindow(nsnull);
}
}
mContentViewer = nsnull;
DestroyChildren();
@@ -2811,39 +2816,24 @@ NS_IMETHODIMP nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer)
}
}
// XXX The command dispatcher is the only object that understands
// focus in our system truly, madly, and deeply. Right now it is attached to
// XUL documents, but eventually it will move into the embedding layer and be
// divorced from XUL.
//
// For 6.0, however, this isn't going to happen.
//
// It is necessary to obtain the command dispatcher to utilize its ability
// It is necessary to obtain the focus controller to utilize its ability
// to suppress focus. This is necessary to fix Win32-only bugs related to
// a loss of focus when mContentViewer is set to null. The internal window
// is destroyed, and the OS focuses the parent window. This call ends up
// notifying the command dispatcher that the outer window should focus
// notifying the focus controller that the outer window should focus
// and this hoses us on any link traversal.
//
// Please do not touch any of the command dispatcher code here without
// Please do not touch any of the focus controller code here without
// testing bugs #28580 and 50509. These are immensely important bugs,
// so PLEASE take care not to regress them if you decide to alter this
// code later -- hyatt
nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;
nsCOMPtr<nsIFocusController> focusController;
if (mScriptGlobal) {
nsCOMPtr<nsIDOMWindowInternal> rootWindow;
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(mScriptGlobal);
ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow));
nsCOMPtr<nsIDOMDocument> rootDocument;
rootWindow->GetDocument(getter_AddRefs(rootDocument));
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(rootDocument);
if (xulDoc) {
// See if we have a command dispatcher attached.
xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher));
if (commandDispatcher) {
// Suppress the command dispatcher.
commandDispatcher->SetSuppressFocus(PR_TRUE);
}
ourWindow->GetRootFocusController(getter_AddRefs(focusController));
if (focusController) {
// Suppress the command dispatcher.
focusController->SetSuppressFocus(PR_TRUE);
}
}
@@ -2856,12 +2846,10 @@ NS_IMETHODIMP nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer)
mContentViewer = nsnull;
// End copying block (Don't hold content/document viewer ref beyond here!!)
// See the book I wrote above regarding why the command dispatcher is
// being used here. I reiterate that this object is not really a XUL
// object and will move post-6.0, so please don't come into my cube
// and beat me for checking this in. -- hyatt
if (commandDispatcher)
commandDispatcher->SetSuppressFocus(PR_FALSE);
// See the book I wrote above regarding why the focus controller is
// being used here. -- hyatt
if (focusController)
focusController->SetSuppressFocus(PR_FALSE);
mContentViewer = aNewViewer;