Fix for PDT+ bug #9701. Also fixes the crasher holding the tree closed. r=saari

git-svn-id: svn://10.0.0.236/trunk@60578 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
hyatt%netscape.com 2000-02-12 03:10:01 +00:00
parent 4270972196
commit 1214b16f13
2 changed files with 86 additions and 0 deletions

View File

@ -75,6 +75,14 @@
#include "nsIPref.h"
#include "nsLegendFrame.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#ifdef INCLUDE_XUL
#include "nsIDOMXULCommandDispatcher.h"
#include "nsIDOMXULDocument.h"
#endif
#include "nsInlineFrame.h"
#include "nsBlockFrame.h"
@ -2392,6 +2400,41 @@ nsCSSFrameConstructor::ConstructDocElementFrame(nsIPresShell* aPresShell,
}
}
#ifdef INCLUDE_XUL
// XXX This is a terrible place for this, but you aren't able to send
// events to a presshell until a frame exists.
// Restore focus if we're the active window.
nsCOMPtr<nsIDocument> document;
aDocElement->GetDocument(*getter_AddRefs(document));
nsCOMPtr<nsIScriptGlobalObject> globalObject;
document->GetScriptGlobalObject(getter_AddRefs(globalObject));
nsCOMPtr<nsIDOMWindow> rootWindow;
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(globalObject);
ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow));
nsCOMPtr<nsIDOMDocument> rootDocument;
rootWindow->GetDocument(getter_AddRefs(rootDocument));
nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;
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);
nsCOMPtr<nsIDOMWindow> focusedWindow;
commandDispatcher->GetFocusedWindow(getter_AddRefs(focusedWindow));
nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(ourWindow);
if (domWindow == focusedWindow) {
// We need to restore focus and make sure we null
// out the focused element.
commandDispatcher->SetFocusedElement(nsnull);
domWindow->Focus();
}
commandDispatcher->SetSuppressFocus(PR_FALSE);
}
}
#endif
return NS_OK;
}

View File

@ -75,6 +75,14 @@
#include "nsIPref.h"
#include "nsLegendFrame.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#ifdef INCLUDE_XUL
#include "nsIDOMXULCommandDispatcher.h"
#include "nsIDOMXULDocument.h"
#endif
#include "nsInlineFrame.h"
#include "nsBlockFrame.h"
@ -2392,6 +2400,41 @@ nsCSSFrameConstructor::ConstructDocElementFrame(nsIPresShell* aPresShell,
}
}
#ifdef INCLUDE_XUL
// XXX This is a terrible place for this, but you aren't able to send
// events to a presshell until a frame exists.
// Restore focus if we're the active window.
nsCOMPtr<nsIDocument> document;
aDocElement->GetDocument(*getter_AddRefs(document));
nsCOMPtr<nsIScriptGlobalObject> globalObject;
document->GetScriptGlobalObject(getter_AddRefs(globalObject));
nsCOMPtr<nsIDOMWindow> rootWindow;
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(globalObject);
ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow));
nsCOMPtr<nsIDOMDocument> rootDocument;
rootWindow->GetDocument(getter_AddRefs(rootDocument));
nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;
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);
nsCOMPtr<nsIDOMWindow> focusedWindow;
commandDispatcher->GetFocusedWindow(getter_AddRefs(focusedWindow));
nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(ourWindow);
if (domWindow == focusedWindow) {
// We need to restore focus and make sure we null
// out the focused element.
commandDispatcher->SetFocusedElement(nsnull);
domWindow->Focus();
}
commandDispatcher->SetSuppressFocus(PR_FALSE);
}
}
#endif
return NS_OK;
}