From bfbeb5f588b8ca5d326b84e5645cbfd03faafc49 Mon Sep 17 00:00:00 2001 From: "joki%netscape.com" Date: Fri, 2 Jul 1999 19:43:26 +0000 Subject: [PATCH] New focus stuff for getting focus to the content area of the apprunner window. git-svn-id: svn://10.0.0.236/trunk@38125 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/dom/src/base/nsGlobalWindow.cpp | 46 +++++++++++++++++-- mozilla/widget/src/windows/nsWindow.cpp | 7 ++- .../xpfe/appshell/src/nsWebShellWindow.cpp | 15 ++++++ 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 585c092636e..0868f1b8a95 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -59,6 +59,8 @@ #include "nsINetSupport.h" #endif #include "nsIContentViewer.h" +#include "nsIDocumentViewer.h" +#include "nsIPresShell.h" #include "nsScreen.h" #include "nsHistory.h" #include "nsBarProps.h" @@ -102,6 +104,7 @@ static NS_DEFINE_IID(kIDOMEventTargetIID, NS_IDOMEVENTTARGET_IID); static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID); static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID); static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); +static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID); #ifndef NECKO static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID); static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID); @@ -1122,18 +1125,51 @@ GlobalWindowImpl::Prompt(JSContext *cx, jsval *argv, PRUint32 argc, nsString& aR NS_IMETHODIMP GlobalWindowImpl::Focus() { - nsresult result = NS_OK; - nsIBrowserWindow *browser; if (NS_OK == GetBrowserWindowInterface( browser)) { browser->Show(); NS_RELEASE( browser); } - - if (nsnull != mWebShell) { - result = mWebShell->SetFocus(); + + nsresult result = NS_OK; + + nsIContentViewer *viewer = nsnull; + mWebShell->GetContentViewer(&viewer); + if (viewer) { + nsIDocumentViewer* docv = nsnull; + viewer->QueryInterface(kIDocumentViewerIID, (void**) &docv); + if (nsnull != docv) { + nsIPresContext* cx = nsnull; + docv->GetPresContext(cx); + if (nsnull != cx) { + nsIPresShell *shell = nsnull; + cx->GetShell(&shell); + if (nsnull != shell) { + nsIViewManager *vm = nsnull; + shell->GetViewManager(&vm); + if (nsnull != vm) { + nsIView *rootview = nsnull; + vm->GetRootView(rootview); + if (rootview) { + nsIWidget* widget; + rootview->GetWidget(widget); + if (widget) { + result = widget->SetFocus(); + NS_RELEASE(widget); + } + } + NS_RELEASE(vm); + } + NS_RELEASE(shell); + } + NS_RELEASE(cx); + } + NS_RELEASE(docv); + } + NS_RELEASE(viewer); } + return result; } diff --git a/mozilla/widget/src/windows/nsWindow.cpp b/mozilla/widget/src/windows/nsWindow.cpp index 8cb891fe832..e20c8af05e8 100644 --- a/mozilla/widget/src/windows/nsWindow.cpp +++ b/mozilla/widget/src/windows/nsWindow.cpp @@ -3190,9 +3190,12 @@ PRBool nsWindow::DispatchFocus(PRUint32 aEventType) { // call the event callback if (mEventCallback) { - if ((nsnull != gCurrentWindow) && (!gCurrentWindow->mIsDestroying)) { + //XXX Commenting this out becaus its blocking all focus events and + // I don't think it still works. If I'm wrong we might start getting + // crashes due to focus events during window destruction again. + //if ((nsnull != gCurrentWindow) && (!gCurrentWindow->mIsDestroying)) { return(DispatchStandardEvent(aEventType)); - } + //} } return PR_FALSE; diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index 3577385f09e..b979dd14a65 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -463,6 +463,21 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) break; } + case NS_GOTFOCUS: { + void* data; + aEvent->widget->GetClientData(data); + if (data) { + nsCOMPtr contentShell; + ((nsWebShellWindow *)data)->GetContentWebShell(getter_AddRefs(contentShell)); + if (contentShell) { + nsCOMPtr domWindow; + if (NS_SUCCEEDED(((nsWebShellWindow *)data)-> + ConvertWebShellToDOMWindow(contentShell, getter_AddRefs(domWindow)))) { + domWindow->Focus(); + } + } + } + } default: break;