1998-12-03 04:35:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS"
|
|
|
|
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
* the License for the specific language governing rights and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
|
|
|
* Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "nsIAppShellService.h"
|
|
|
|
#include "nsISupportsArray.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
#include "nsIURL.h"
|
1999-01-21 10:22:58 +03:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIEventQueueService.h"
|
|
|
|
#include "nsXPComCIID.h"
|
|
|
|
#include "nsXPComFactory.h" /* template implementation of a XPCOM factory */
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
#include "nsIAppShell.h"
|
|
|
|
#include "nsIWidget.h"
|
1999-02-17 19:12:10 +03:00
|
|
|
#include "nsIWebShellWindow.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
#include "nsWebShellWindow.h"
|
|
|
|
|
|
|
|
#include "nsWidgetsCID.h"
|
1999-02-10 19:38:51 +03:00
|
|
|
#include "nsIStreamObserver.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
|
1999-02-04 21:17:02 +03:00
|
|
|
#ifdef MOZ_FULLCIRCLE
|
|
|
|
#include "fullsoft.h"
|
|
|
|
#endif
|
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
/* Define Class IDs */
|
1999-01-21 10:22:58 +03:00
|
|
|
static NS_DEFINE_IID(kAppShellCID, NS_APPSHELL_CID);
|
|
|
|
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
/* Define Interface IDs */
|
|
|
|
|
1999-01-21 10:22:58 +03:00
|
|
|
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
|
|
|
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
|
|
|
|
static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID);
|
|
|
|
static NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
|
1999-02-17 19:12:10 +03:00
|
|
|
static NS_DEFINE_IID(kIWebShellWindowIID, NS_IWEBSHELL_WINDOW_IID);
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class nsAppShellService : public nsIAppShellService
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsAppShellService(void);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD Initialize(void);
|
|
|
|
NS_IMETHOD Run(void);
|
1999-02-10 19:38:51 +03:00
|
|
|
NS_IMETHOD GetNativeEvent(void *& aEvent, nsIWidget* aWidget, PRBool &aIsInWindow, PRBool &aIsMouseEvent);
|
|
|
|
NS_IMETHOD DispatchNativeEvent(void * aEvent);
|
1998-12-03 04:35:53 +03:00
|
|
|
NS_IMETHOD Shutdown(void);
|
1999-02-26 05:22:42 +03:00
|
|
|
NS_IMETHOD CreateTopLevelWindow(nsIWidget * aParent,
|
|
|
|
nsIURL* aUrl,
|
|
|
|
nsString& aControllerIID,
|
1999-02-19 00:52:27 +03:00
|
|
|
nsIWidget*& aResult, nsIStreamObserver* anObserver,
|
1999-02-26 05:22:42 +03:00
|
|
|
nsIXULWindowCallbacks *aCallbacks,
|
|
|
|
PRInt32 aInitialWidth, PRInt32 aInitialHeight);
|
|
|
|
NS_IMETHOD CreateDialogWindow( nsIWidget * aParent,
|
|
|
|
nsIURL* aUrl,
|
|
|
|
nsString& aControllerIID,
|
|
|
|
nsIWidget*& aResult, nsIStreamObserver* anObserver,
|
|
|
|
nsIXULWindowCallbacks *aCallbacks,
|
1999-02-19 00:52:27 +03:00
|
|
|
PRInt32 aInitialWidth, PRInt32 aInitialHeight);
|
1998-12-03 04:35:53 +03:00
|
|
|
NS_IMETHOD CloseTopLevelWindow(nsIWidget* aWindow);
|
1999-02-15 08:38:15 +03:00
|
|
|
NS_IMETHOD RegisterTopLevelWindow(nsIWidget* aWindow);
|
|
|
|
NS_IMETHOD UnregisterTopLevelWindow(nsIWidget* aWindow);
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsAppShellService();
|
|
|
|
|
|
|
|
nsIAppShell* mAppShell;
|
|
|
|
nsISupportsArray* mWindowList;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsAppShellService::nsAppShellService()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
|
|
|
|
mAppShell = nsnull;
|
|
|
|
mWindowList = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShellService::~nsAppShellService()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mAppShell);
|
|
|
|
NS_IF_RELEASE(mWindowList);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implement the nsISupports methods...
|
|
|
|
*/
|
|
|
|
NS_IMPL_ISUPPORTS(nsAppShellService, kIAppShellServiceIID);
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::Initialize(void)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
1999-02-04 21:17:02 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_FULLCIRCLE
|
1999-02-05 01:57:13 +03:00
|
|
|
FCInitialize();
|
1999-02-04 21:17:02 +03:00
|
|
|
#endif
|
1999-01-21 10:22:58 +03:00
|
|
|
// Create the Event Queue for the UI thread...
|
|
|
|
nsIEventQueueService* mEventQService;
|
|
|
|
rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
|
|
|
kIEventQueueServiceIID,
|
|
|
|
(nsISupports **)&mEventQService);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
// XXX: What if this fails?
|
|
|
|
rv = mEventQService->CreateThreadEventQueue();
|
|
|
|
}
|
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
rv = NS_NewISupportsArray(&mWindowList);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create widget application shell
|
1999-03-09 12:44:27 +03:00
|
|
|
rv = nsComponentManager::CreateInstance(kAppShellCID, nsnull, kIAppShellIID,
|
1998-12-03 04:35:53 +03:00
|
|
|
(void**)&mAppShell);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mAppShell->Create(0, nsnull);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::Run(void)
|
|
|
|
{
|
|
|
|
return mAppShell->Run();
|
|
|
|
}
|
|
|
|
|
1999-02-10 19:38:51 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::GetNativeEvent(void *& aEvent, nsIWidget* aWidget, PRBool &aIsInWindow, PRBool &aIsMouseEvent)
|
|
|
|
{
|
|
|
|
return mAppShell->GetNativeEvent(aEvent, aWidget, aIsInWindow, aIsMouseEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::DispatchNativeEvent(void * aEvent)
|
|
|
|
{
|
|
|
|
return mAppShell->DispatchNativeEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::Shutdown(void)
|
|
|
|
{
|
1999-02-17 19:18:17 +03:00
|
|
|
|
|
|
|
#if 1
|
|
|
|
mAppShell->Exit();
|
|
|
|
#else
|
1999-02-17 19:12:10 +03:00
|
|
|
while (mWindowList->Count() > 0) {
|
|
|
|
nsISupports * winSupports = mWindowList->ElementAt(0);
|
|
|
|
nsCOMPtr<nsIWidget> window(do_QueryInterface(winSupports));
|
|
|
|
if (window) {
|
|
|
|
mWindowList->RemoveElementAt(0);
|
|
|
|
CloseTopLevelWindow(window);
|
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIWebShellWindow> webShellWin(do_QueryInterface(winSupports));
|
|
|
|
if (webShellWin) {
|
|
|
|
nsIWidget * win;
|
|
|
|
webShellWin->GetWidget(win);
|
|
|
|
CloseTopLevelWindow(win);
|
|
|
|
}
|
|
|
|
//nsCOMPtr<nsIWebShellContainer> wsc(do_QueryInterface(winSupports));
|
|
|
|
//if (wsc) {
|
|
|
|
//
|
|
|
|
//}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-02-17 19:18:17 +03:00
|
|
|
#endif
|
1998-12-03 04:35:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new top level window and display the given URL within it...
|
1999-01-21 10:22:58 +03:00
|
|
|
*
|
1999-02-26 05:22:42 +03:00
|
|
|
* @param aParent - parent for the window to be created (generally null;
|
|
|
|
* included for compatibility with dialogs).
|
|
|
|
* (currently unused).
|
|
|
|
* @param aURL - location of XUL window contents description
|
|
|
|
* @param aControllerIID - currently provided as an argument. in the future,
|
|
|
|
* this will be specified by the XUL document itself.
|
|
|
|
* (currently unused, but please specify the same
|
|
|
|
* hardwired IID as others are using).
|
|
|
|
* @param anObserver - a stream observer to give to the new window
|
|
|
|
* @param aConstructionCallbacks - methods which will be called during
|
|
|
|
* window construction. can be null.
|
|
|
|
* @param aInitialWidth - width of window, in pixels (currently unused)
|
|
|
|
* @param aInitialHeight - height of window, in pixels (currently unused)
|
1998-12-03 04:35:53 +03:00
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
1999-02-26 05:22:42 +03:00
|
|
|
nsAppShellService::CreateTopLevelWindow(nsIWidget *aParent,
|
|
|
|
nsIURL* aUrl, nsString& aControllerIID,
|
1999-02-19 00:52:27 +03:00
|
|
|
nsIWidget*& aResult, nsIStreamObserver* anObserver,
|
1999-02-26 05:22:42 +03:00
|
|
|
nsIXULWindowCallbacks *aCallbacks,
|
1999-02-19 00:52:27 +03:00
|
|
|
PRInt32 aInitialWidth, PRInt32 aInitialHeight)
|
1998-12-03 04:35:53 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsWebShellWindow* window;
|
|
|
|
|
|
|
|
window = new nsWebShellWindow();
|
|
|
|
if (nsnull == window) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
} else {
|
1999-03-14 11:24:21 +03:00
|
|
|
// temporarily disabling parentage because non-Windows platforms
|
|
|
|
// seem to be interpreting it in unexpected ways.
|
|
|
|
rv = window->Initialize((nsIWidget *) nsnull, mAppShell, aUrl, aControllerIID,
|
1999-02-26 05:22:42 +03:00
|
|
|
anObserver, aCallbacks,
|
|
|
|
aInitialWidth, aInitialHeight);
|
1998-12-03 04:35:53 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aResult = window->GetWidget();
|
1999-02-15 08:38:15 +03:00
|
|
|
RegisterTopLevelWindow(aResult);
|
|
|
|
window->Show(PR_TRUE);
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::CloseTopLevelWindow(nsIWidget* aWindow)
|
|
|
|
{
|
1999-03-18 22:08:36 +03:00
|
|
|
nsresult closerv, unregrv;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
aWindow->GetClientData(data);
|
|
|
|
if (data == nsnull)
|
|
|
|
closerv = NS_ERROR_NULL_POINTER;
|
|
|
|
else {
|
|
|
|
nsWebShellWindow* window = (nsWebShellWindow *) data;
|
1999-03-18 22:19:52 +03:00
|
|
|
closerv = window->Close();
|
1999-03-18 22:08:36 +03:00
|
|
|
}
|
1999-02-15 08:38:15 +03:00
|
|
|
|
1999-03-18 22:08:36 +03:00
|
|
|
unregrv = UnregisterTopLevelWindow(aWindow);
|
|
|
|
if (0 == mWindowList->Count())
|
1999-02-15 08:38:15 +03:00
|
|
|
mAppShell->Exit();
|
|
|
|
|
1999-03-18 22:08:36 +03:00
|
|
|
return closerv == NS_OK ? unregrv : closerv;
|
1999-02-15 08:38:15 +03:00
|
|
|
}
|
|
|
|
|
1999-02-10 19:38:51 +03:00
|
|
|
/*
|
1999-02-26 05:22:42 +03:00
|
|
|
* Like CreateTopLevelWindow, but with dialog window borders. This
|
|
|
|
* method is necessary because of the current misfortune that the window
|
|
|
|
* is created before its XUL description has been parsed, so the description
|
|
|
|
* can't affect attributes like window type.
|
1999-02-10 19:38:51 +03:00
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::CreateDialogWindow(nsIWidget * aParent,
|
|
|
|
nsIURL* aUrl, nsString& aControllerIID,
|
1999-02-19 00:52:27 +03:00
|
|
|
nsIWidget*& aResult, nsIStreamObserver* anObserver,
|
1999-02-26 05:22:42 +03:00
|
|
|
nsIXULWindowCallbacks *aCallbacks,
|
1999-02-19 00:52:27 +03:00
|
|
|
PRInt32 aInitialWidth, PRInt32 aInitialHeight)
|
1999-02-10 19:38:51 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsWebShellWindow* window;
|
|
|
|
|
|
|
|
window = new nsWebShellWindow();
|
|
|
|
if (nsnull == window) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
} else {
|
1999-03-14 11:24:21 +03:00
|
|
|
// temporarily disabling parentage because non-Windows platforms
|
|
|
|
// seem to be interpreting it in unexpected ways.
|
|
|
|
rv = window->Initialize((nsIWidget *) nsnull, mAppShell, aUrl, aControllerIID,
|
1999-02-26 05:22:42 +03:00
|
|
|
anObserver, aCallbacks,
|
1999-02-19 00:52:27 +03:00
|
|
|
aInitialWidth, aInitialHeight);
|
1999-02-10 19:38:51 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
aResult = window->GetWidget();
|
1999-02-26 05:22:42 +03:00
|
|
|
RegisterTopLevelWindow(aResult);
|
|
|
|
window->Show(PR_TRUE);
|
1999-02-10 19:38:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
1998-12-03 04:35:53 +03:00
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register a new top level window (created elsewhere)
|
|
|
|
*/
|
|
|
|
static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID);
|
1998-12-03 04:35:53 +03:00
|
|
|
NS_IMETHODIMP
|
1999-02-15 08:38:15 +03:00
|
|
|
nsAppShellService::RegisterTopLevelWindow(nsIWidget* aWindow)
|
1998-12-03 04:35:53 +03:00
|
|
|
{
|
1999-02-15 08:38:15 +03:00
|
|
|
nsresult rv;
|
1998-12-03 04:35:53 +03:00
|
|
|
void* data;
|
|
|
|
|
|
|
|
aWindow->GetClientData(data);
|
1999-02-15 08:38:15 +03:00
|
|
|
if (data == nsnull)
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
else {
|
1999-02-17 19:49:43 +03:00
|
|
|
nsWebShellWindow* window = (nsWebShellWindow *) data;
|
|
|
|
nsIWebShellContainer* wsc;
|
1999-02-15 08:38:15 +03:00
|
|
|
rv = window->QueryInterface(kIWebShellContainerIID, (void **) &wsc);
|
1999-03-14 11:24:21 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-02-15 08:38:15 +03:00
|
|
|
mWindowList->AppendElement(wsc);
|
1999-03-14 11:24:21 +03:00
|
|
|
NS_RELEASE(wsc);
|
|
|
|
}
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
1999-02-15 08:38:15 +03:00
|
|
|
return rv;
|
|
|
|
}
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::UnregisterTopLevelWindow(nsIWidget* aWindow)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
void* data;
|
1998-12-03 04:35:53 +03:00
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
aWindow->GetClientData(data);
|
|
|
|
if (data == nsnull)
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
else {
|
|
|
|
nsWebShellWindow* window = (nsWebShellWindow *) data;
|
|
|
|
nsIWebShellContainer* wsc;
|
|
|
|
rv = window->QueryInterface(kIWebShellContainerIID, (void **) &wsc);
|
1999-03-14 11:24:21 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-02-15 08:38:15 +03:00
|
|
|
mWindowList->RemoveElement(wsc);
|
1999-03-14 11:24:21 +03:00
|
|
|
NS_RELEASE(wsc);
|
|
|
|
}
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
NS_EXPORT nsresult NS_NewAppShellService(nsIAppShellService** aResult)
|
|
|
|
{
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = new nsAppShellService();
|
|
|
|
if (nsnull == *aResult) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-01-21 10:22:58 +03:00
|
|
|
// Entry point to create nsAppShellService factory instances...
|
1999-03-08 12:44:16 +03:00
|
|
|
NS_DEF_FACTORY(AppShellService,nsAppShellService)
|
1998-12-03 04:35:53 +03:00
|
|
|
|
1999-01-21 10:22:58 +03:00
|
|
|
nsresult NS_NewAppShellServiceFactory(nsIFactory** aResult)
|
1998-12-03 04:35:53 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1999-03-08 12:44:16 +03:00
|
|
|
nsIFactory* inst = new nsAppShellServiceFactory;
|
1998-12-03 04:35:53 +03:00
|
|
|
if (nsnull == inst) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ADDREF(inst);
|
|
|
|
}
|
1999-01-21 10:22:58 +03:00
|
|
|
*aResult = inst;
|
1998-12-03 04:35:53 +03:00
|
|
|
return rv;
|
|
|
|
}
|