diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 2bb0a2c661e..41aa8e9617d 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -1359,6 +1359,109 @@ GlobalWindowImpl::Blur() return result; } +NS_IMETHODIMP +GlobalWindowImpl::Activate() +{ + nsIBrowserWindow *browser; + if (NS_OK == GetBrowserWindowInterface(browser)) { + browser->Show(); + NS_RELEASE( browser); + } + + 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; +} + +NS_IMETHODIMP +GlobalWindowImpl::Deactivate() +{ + 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) { + nsEventStatus status; + nsGUIEvent guiEvent; + guiEvent.eventStructType = NS_GUI_EVENT; + guiEvent.point.x = 0; + guiEvent.point.y = 0; + guiEvent.time = PR_IntervalNow(); + guiEvent.nativeMsg = nsnull; + guiEvent.message = NS_DEACTIVATE; + guiEvent.widget = widget; + + vm->DispatchEvent(&guiEvent, &status); + NS_RELEASE(widget); + } + } + NS_RELEASE(vm); + } + NS_RELEASE(shell); + } + NS_RELEASE(cx); + } + NS_RELEASE(docv); + } + NS_RELEASE(viewer); + } + return result; +} + NS_IMETHODIMP GlobalWindowImpl::Close() { diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index fc58865e609..af7fc2cff34 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -239,6 +239,8 @@ public: // nsPIDOMWindowInterface NS_IMETHOD GetPrivateParent(nsPIDOMWindow** aResult); + NS_IMETHOD Activate(); + NS_IMETHOD Deactivate(); friend void nsGlobalWindow_RunTimeout(nsITimer *aTimer, void *aClosure); diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index 893796a6f69..5bbc771f622 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -41,6 +41,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #include "nsVoidArray.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" +#include "nsPIDOMWindow.h" #include "nsIDOMEventTarget.h" #include "nsIDOMFocusListener.h" @@ -504,7 +505,32 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) } case NS_MOUSE_ACTIVATE: - case NS_ACTIVATE: + case NS_ACTIVATE: { + void* data; + aEvent->widget->GetClientData(data); + if (data) { + nsCOMPtr domWindow; + nsCOMPtr contentShell; + ((nsWebShellWindow *)data)->GetContentWebShell(getter_AddRefs(contentShell)); + if (contentShell) { + + if (NS_SUCCEEDED(((nsWebShellWindow *)data)-> + ConvertWebShellToDOMWindow(contentShell, getter_AddRefs(domWindow)))) { + nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); + if(privateDOMWindow) + privateDOMWindow->Activate(); + } + } + else if (webShell && NS_SUCCEEDED(((nsWebShellWindow *)data)-> + ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow)))) { + nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); + if(privateDOMWindow) + privateDOMWindow->Activate(); + } + } + break; + } + case NS_GOTFOCUS: { void* data; aEvent->widget->GetClientData(data); @@ -524,7 +550,35 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) domWindow->Focus(); } } + break; } + + case NS_DEACTIVATE: { + void* data; + aEvent->widget->GetClientData(data); + if (data) { + nsCOMPtr domWindow; + nsCOMPtr contentShell; + ((nsWebShellWindow *)data)->GetContentWebShell(getter_AddRefs(contentShell)); + if (contentShell) { + + if (NS_SUCCEEDED(((nsWebShellWindow *)data)-> + ConvertWebShellToDOMWindow(contentShell, getter_AddRefs(domWindow)))) { + nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); + if(privateDOMWindow) + privateDOMWindow->Deactivate(); + } + } + else if (webShell && NS_SUCCEEDED(((nsWebShellWindow *)data)-> + ConvertWebShellToDOMWindow(webShell, getter_AddRefs(domWindow)))) { + nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); + if(privateDOMWindow) + privateDOMWindow->Deactivate(); + } + } + break; + } + default: break;