diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 055ee76cd0c..755d0d39198 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -71,6 +71,7 @@ #include "nsIPrincipal.h" #include "nsPIDOMWindow.h" +#include "nsIDOMDocument.h" // For reporting errors with the console service. // These can go away if error reporting is propagated up past nsDocShell. @@ -1971,11 +1972,19 @@ NS_IMETHODIMP nsDocShell::GetMainWidget(nsIWidget** aMainWidget) NS_IMETHODIMP nsDocShell::SetFocus() { - nsCOMPtr mainWidget; - GetMainWidget(getter_AddRefs(mainWidget)); - if(mainWidget) - mainWidget->SetFocus(); - return NS_OK; + nsCOMPtr domDoc; + mContentViewer->GetDOMDocument(getter_AddRefs(domDoc)); + nsCOMPtr doc(do_QueryInterface(domDoc)); + if (doc) { + nsCOMPtr sgo; + doc->GetScriptGlobalObject(getter_AddRefs(sgo)); + if (sgo) { + nsCOMPtr domwin(do_QueryInterface(sgo)); + if (domwin) + domwin->Focus(); + } + } + return NS_OK; } NS_IMETHODIMP nsDocShell::FocusAvailable(nsIBaseWindow* aCurrentFocus,