added beginnings of toolkit dialog factory

This commit is contained in:
danm%netscape.com 1999-02-15 05:38:15 +00:00
Родитель afa4cbe051
Коммит 207aac9356
22 изменённых файлов: 763 добавлений и 56 удалений

Просмотреть файл

@ -0,0 +1,8 @@
interface ToolkitCore : BaseAppCore
{
/* IID: { 0x1cab9340, 0xc122, 0x11d2, \
{0x81, 0xb2, 0x00, 0x60, 0x08, 0x3a, 0x0b, 0xcf}} *\
void ToolkitCore();
void ShowWindow(in wstring url, in Window parent);
};

Двоичные данные
xpfe/AppCores/macbuild/AppCores.mcp

Двоичный файл не отображается.

Просмотреть файл

@ -28,9 +28,10 @@ EXPORTS = \
nsIDOMBaseAppCore.h \
nsIDOMMailCore.h \
nsIDOMToolbarCore.h \
nsIDOMBrowserAppCore.h \
nsAppCoresCIDs.h \
$(NULL)
nsIDOMToolkitCore.h \
nsIDOMBrowserAppCore.h \
nsAppCoresCIDs.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

Просмотреть файл

@ -26,6 +26,7 @@ EXPORTS= \
nsIDOMBaseAppCore.h \
nsIDOMMailCore.h \
nsIDOMToolbarCore.h \
nsIDOMToolkitCore.h \
nsIDOMBrowserAppCore.h \
nsAppCoresCIDs.h

Просмотреть файл

@ -45,6 +45,17 @@
{0x96, 0xc4, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56} \
}
#define NS_TOOLKITCORE_CID \
{ /* 1cab9340-c122-11d2-81b2-0060083a0bcf */ \
0x1cab9340, 0xc122, 0x11d2, \
{0x81, 0xb2, 0x00, 0x60, 0x08, 0x3a, 0x0b, 0xcf} \
}
#define NS_TOOLKITCORE_FACTORY_CID \
{ /* 1cab9341-c122-11d2-81b2-0060083a0bcf */ \
0x1cab9341, 0xc122, 0x11d2, \
{0x81, 0xb2, 0x00, 0x60, 0x08, 0x3a, 0x0b, 0xcf} \
}
#define NS_THROBBERGLUE_FACTORY_CID \
{ /* 771C3121-BC44-11d2-8A3F-00805F8A6608 */ \

Просмотреть файл

@ -0,0 +1,55 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMToolkitCore_h__
#define nsIDOMToolkitCore_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsIDOMBaseAppCore.h"
class nsIDOMWindow;
#define NS_IDOMTOOLKITCORE_IID \
{ 0x1cab9340, 0xc122, 0x11d2, \
{0x81, 0xb2, 0x00, 0x60, 0x08, 0x3a, 0x0b, 0xcf}}
class nsIDOMToolkitCore : public nsIDOMBaseAppCore {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMTOOLKITCORE_IID; return iid; }
NS_IMETHOD ShowWindow(const nsString& aUrl, nsIDOMWindow* aParent)=0;
};
#define NS_DECL_IDOMTOOLKITCORE \
NS_IMETHOD ShowWindow(const nsString& aUrl, nsIDOMWindow* aParent); \
#define NS_FORWARD_IDOMTOOLKITCORE(_to) \
NS_IMETHOD ShowWindow(const nsString& aUrl, nsIDOMWindow* aParent) { return _to##ShowWindow(aUrl, aParent); } \
extern nsresult NS_InitToolkitCoreClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptToolkitCore(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMToolkitCore_h__

Просмотреть файл

@ -32,10 +32,12 @@ CPPSRCS= \
nsMailCore.cpp \
nsAppCoresNameSet.cpp \
nsToolbarCore.cpp \
nsToolkitCore.cpp \
nsBrowserAppCore.cpp \
nsThrobberGlue.cpp \
nsMailCoreFactory.cpp \
nsToolbarCoreFactory.cpp \
nsToolkitCoreFactory.cpp \
nsBrowserAppCoreFactory.cpp \
nsAppCoresManager.cpp \
nsAppCoresManagerFactory.cpp \
@ -43,6 +45,7 @@ CPPSRCS= \
nsJSAppCores.cpp \
nsJSMailCore.cpp \
nsJSToolbarCore.cpp \
nsJSToolkitCore.cpp \
nsJSBrowserAppCore.cpp \
nsAppCores.cpp \
$(NULL)

Просмотреть файл

@ -62,6 +62,8 @@ OBJS = \
.\$(OBJDIR)\nsMailCore.obj \
.\$(OBJDIR)\nsAppCoresNameSet.obj \
.\$(OBJDIR)\nsToolbarCore.obj \
.\$(OBJDIR)\nsToolkitCore.obj \
.\$(OBJDIR)\nsToolkitCoreFactory.obj \
.\$(OBJDIR)\nsBrowserAppCore.obj \
.\$(OBJDIR)\nsMailCoreFactory.obj \
.\$(OBJDIR)\nsToolbarCoreFactory.obj \
@ -73,6 +75,7 @@ OBJS = \
.\$(OBJDIR)\nsJSAppCores.obj \
.\$(OBJDIR)\nsJSMailCore.obj \
.\$(OBJDIR)\nsJSToolbarCore.obj \
.\$(OBJDIR)\nsJSToolkitCore.obj \
.\$(OBJDIR)\nsJSBrowserAppCore.obj \
.\$(OBJDIR)\nsAppCores.obj \
$(NULL)

Просмотреть файл

@ -22,6 +22,7 @@
#include "nsMailCoreFactory.h"
#include "nsToolbarCoreFactory.h"
#include "nsBrowserAppCoreFactory.h"
#include "nsToolkitCoreFactory.h"
#include "nsIFactory.h"
#include "nsRepository.h"
@ -33,6 +34,7 @@ static PRInt32 gInstanceCnt = 0;
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kMailCoreCID, NS_MailCore_CID);
static NS_DEFINE_IID(kToolbarCoreCID, NS_TOOLBARCORE_CID);
static NS_DEFINE_IID(kToolkitCoreCID, NS_TOOLKITCORE_CID);
static NS_DEFINE_IID(kBrowserAppCoreCID, NS_BROWSERAPPCORE_CID);
static NS_DEFINE_IID(kAppCoresCID, NS_AppCores_CID);
@ -54,6 +56,7 @@ NSRegisterSelf(const char *path)
nsRepository::RegisterFactory(kAppCoresCID, path, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kMailCoreCID, path, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kToolbarCoreCID, path, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kToolkitCoreCID, path, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kBrowserAppCoreCID, path, PR_TRUE, PR_TRUE);
return NS_OK;
}
@ -66,6 +69,7 @@ NSUnregisterSelf(const char *path)
nsRepository::UnregisterFactory(kAppCoresCID, path);
nsRepository::UnregisterFactory(kMailCoreCID, path);
nsRepository::UnregisterFactory(kToolbarCoreCID, path);
nsRepository::UnregisterFactory(kToolkitCoreCID, path);
nsRepository::UnregisterFactory(kBrowserAppCoreCID, path);
return NS_OK;
@ -85,7 +89,6 @@ NSGetFactory(const nsCID &aClass, nsISupports* serviceMgr, nsIFactory **aFactory
*aFactory = NULL;
nsISupports *inst;
if ( aClass.Equals(kAppCoresCID) )
{
inst = new nsAppCoresManagerFactory();
@ -98,6 +101,10 @@ NSGetFactory(const nsCID &aClass, nsISupports* serviceMgr, nsIFactory **aFactory
{
inst = new nsToolbarCoreFactory();
}
else if ( aClass.Equals(kToolkitCoreCID) )
{
inst = new nsToolkitCoreFactory();
}
else if ( aClass.Equals(kBrowserAppCoreCID) )
{
inst = new nsBrowserAppCoreFactory();

Просмотреть файл

@ -25,6 +25,7 @@
#include "nsIScriptContext.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIDOMAppCores.h"
#include "nsIDOMToolkitCore.h"
#include "nsIDOMMailCore.h"
#include "nsIDOMToolbarCore.h"
#include "nsIDOMBrowserAppCore.h"
@ -33,6 +34,7 @@
static NS_DEFINE_IID(kIScriptExternalNameSetIID, NS_ISCRIPTEXTERNALNAMESET_IID);
static NS_DEFINE_IID(kAppCoresCID, NS_AppCores_CID);
static NS_DEFINE_IID(kToolkitCoreCID, NS_TOOLKITCORE_CID);
static NS_DEFINE_IID(kMailCoreCID, NS_MailCore_CID);
static NS_DEFINE_IID(kToolbarCoreCID, NS_TOOLBARCORE_CID);
static NS_DEFINE_IID(kBrowserAppCoreCID, NS_BROWSERAPPCORE_CID);
@ -62,6 +64,7 @@ nsAppCoresNameSet::InitializeClasses(nsIScriptContext* aScriptContext)
result = NS_InitMailCoreClass(aScriptContext, nsnull);
result = NS_InitToolbarCoreClass(aScriptContext, nsnull);
result = NS_InitBrowserAppCoreClass(aScriptContext, nsnull);
result = NS_InitToolkitCoreClass(aScriptContext, nsnull);
return result;
}
@ -90,6 +93,12 @@ nsAppCoresNameSet::AddNameSet(nsIScriptContext* aScriptContext)
if (NS_OK != result) return result;
result = manager->RegisterGlobalName("ToolkitCore",
kToolkitCoreCID,
PR_TRUE);
if (NS_OK != result) return result;
result = manager->RegisterGlobalName("BrowserAppCore",
kBrowserAppCoreCID,
PR_TRUE);
@ -100,7 +109,6 @@ nsAppCoresNameSet::AddNameSet(nsIScriptContext* aScriptContext)
kAppCoresCID,
PR_FALSE);
NS_RELEASE(manager);
}
return result;

Просмотреть файл

Просмотреть файл

@ -0,0 +1,154 @@
/* -*- 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 "nsAppCoresManager.h"
#include "nsAppShellCIDs.h"
#include "nsIAppShellService.h"
#include "nsIDOMBaseAppCore.h"
#include "nsIServiceManager.h"
#include "nsISupports.h"
#include "nsIURL.h"
#include "nsIWidget.h"
#include "nsToolkitCore.h"
class nsIScriptContext;
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID);
static NS_DEFINE_IID(kIDOMBaseAppCoreIID, NS_IDOMBASEAPPCORE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIToolkitCoreIID, NS_IDOMTOOLKITCORE_IID);
/////////////////////////////////////////////////////////////////////////
// nsToolkitCore
/////////////////////////////////////////////////////////////////////////
nsToolkitCore::nsToolkitCore() {
printf("Created nsToolkitCore\n");
IncInstanceCount();
NS_INIT_REFCNT();
}
nsToolkitCore::~nsToolkitCore() {
DecInstanceCount();
}
NS_IMPL_ADDREF(nsToolkitCore)
NS_IMPL_RELEASE(nsToolkitCore)
NS_IMETHODIMP
nsToolkitCore::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
if (aInstancePtr == NULL)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = NULL;
if (aIID.Equals(kIToolkitCoreIID)) {
*aInstancePtr = (void*) ((nsIDOMToolkitCore*) this);
AddRef();
return NS_OK;
}
return nsBaseAppCore::QueryInterface(aIID, aInstancePtr);
}
NS_IMETHODIMP
nsToolkitCore::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) {
nsresult rv = NS_OK;
NS_PRECONDITION(aScriptObject != nsnull, "null arg");
if (mScriptObject == nsnull) {
nsISupports *core;
rv = QueryInterface(kISupportsIID, (void **)&core);
if (NS_SUCCEEDED(rv)) {
rv = NS_NewScriptToolkitCore(aContext,
(nsISupports *) core,
nsnull,
&mScriptObject);
NS_RELEASE(core);
}
}
*aScriptObject = mScriptObject;
return rv;
}
NS_IMETHODIMP
nsToolkitCore::Init(const nsString& aId) {
nsresult rv;
nsBaseAppCore::Init(aId);
nsIDOMBaseAppCore *core;
rv = QueryInterface(kIDOMBaseAppCoreIID, (void **)&core);
if (NS_SUCCEEDED(rv)) {
nsAppCoresManager* sdm = new nsAppCoresManager();
if (sdm) {
sdm->Add(core);
delete sdm;
return NS_OK;
} else
rv = NS_ERROR_OUT_OF_MEMORY;
NS_RELEASE(core);
}
return rv;
}
NS_IMETHODIMP
nsToolkitCore::ShowWindow(const nsString& aUrl, nsIDOMWindow* aParent) {
nsresult rv;
nsString controllerCID;
nsIAppShellService *appShell;
nsIURL *url;
nsIWidget *window;
printf("in toolkitcore::ShowWindow\n");
window = nsnull;
rv = NS_NewURL(&url, aUrl);
if (NS_FAILED(rv))
return rv;
rv = nsServiceManager::GetService(kAppShellServiceCID, kIAppShellServiceIID,
(nsISupports**) &appShell);
if (NS_SUCCEEDED(rv)) {
// hardwired temporary hack. See nsAppRunner.cpp at main()
controllerCID = "43147b80-8a39-11d2-9938-0080c7cb1081";
appShell->CreateTopLevelWindow(url, controllerCID, window, nsnull);
nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
}
if (window != nsnull) {
window->Show(PR_TRUE);
}
return rv;
}

Просмотреть файл

@ -0,0 +1,53 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsToolkitCorePrivate_h___
#define nsToolkitCorePrivate_h___
//#include "nsAppCores.h"
#include "nscore.h"
#include "nsString.h"
#include "nsISupports.h"
#include "nsIDOMToolkitCore.h"
#include "nsBaseAppCore.h"
class nsIScriptContext;
////////////////////////////////////////////////////////////////////////////////
// nsToolbarCore:
////////////////////////////////////////////////////////////////////////////////
class nsToolkitCore : public nsBaseAppCore,
public nsIDOMToolkitCore {
public:
nsToolkitCore();
virtual ~nsToolkitCore();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD Init(const nsString& aId);
NS_IMETHOD GetId(nsString& aId) { return nsBaseAppCore::GetId(aId); }
NS_DECL_IDOMTOOLKITCORE
};
#endif // nsToolkitCorePrivate_h___

Просмотреть файл

@ -0,0 +1,114 @@
/* -*- 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 "nsToolkitCore.h"
#include "nsToolkitCoreFactory.h"
//#include "pratom.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
/////////////////////////////////////////////////////////////////////////
// nsToolkitCoreFactory
/////////////////////////////////////////////////////////////////////////
nsToolkitCoreFactory::nsToolkitCoreFactory(void) {
mRefCnt = 0;
IncInstanceCount();
}
nsToolkitCoreFactory::~nsToolkitCoreFactory(void) {
DecInstanceCount();
}
NS_IMETHODIMP
nsToolkitCoreFactory::QueryInterface(REFNSIID aIID, void** aInstancePtr) {
if (aInstancePtr == NULL)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = NULL;
if (aIID.Equals(kISupportsIID))
*aInstancePtr = (void*) this;
else if (aIID.Equals(kIFactoryIID))
*aInstancePtr = (void*) this;
if (*aInstancePtr == NULL)
return NS_ERROR_NO_INTERFACE;
AddRef();
return NS_OK;
}
NS_IMETHODIMP
nsToolkitCoreFactory::AddRef(void) {
return ++mRefCnt;
}
NS_IMETHODIMP
nsToolkitCoreFactory::Release(void) {
if (--mRefCnt == 0) {
delete this;
return 0;
}
return mRefCnt;
}
NS_IMETHODIMP
nsToolkitCoreFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) {
if (aResult == NULL)
return NS_ERROR_NULL_POINTER;
*aResult = NULL;
nsToolkitCore *inst = new nsToolkitCore();
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
nsresult result = inst->QueryInterface(aIID, aResult);
if (result != NS_OK)
delete inst;
return result;
}
NS_IMETHODIMP
nsToolkitCoreFactory::LockFactory(PRBool aLock) {
if (aLock)
IncLockCount();
else
DecLockCount();
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,46 @@
/* -*- 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 "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsToolkitCoreFactory_h___
#define nsToolkitCoreFactory_h___
#include "nsIFactory.h"
#include "nsISupports.h"
////////////////////////////////////////////////////////////////////////////////
// nsToolkitCoreFactory:
////////////////////////////////////////////////////////////////////////////////
class nsToolkitCoreFactory : public nsIFactory {
public:
nsToolkitCoreFactory();
virtual ~nsToolkitCoreFactory();
// PRBool CanUnload(void);
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif // nsToolkitCoreFactory_h___

Просмотреть файл

@ -56,6 +56,8 @@ public:
nsString& aControllerIID,
nsIWidget*& aResult, nsIStreamObserver* anObserver) = 0;
NS_IMETHOD CloseTopLevelWindow(nsIWidget* aWindow) = 0;
NS_IMETHOD RegisterTopLevelWindow(nsIWidget* aWindow) = 0;
NS_IMETHOD UnregisterTopLevelWindow(nsIWidget* aWindow) = 0;
};
#endif /* nsIAppShellService_h__ */

Просмотреть файл

@ -31,6 +31,7 @@ class nsIWebShellWindow : public nsISupports
{
public:
NS_IMETHOD Show(PRBool aShow) = 0;
NS_IMETHOD GetWebShell(nsIWebShell *& aWebShell) = 0;
NS_IMETHOD GetWidget(nsIWidget *& aWidget) = 0;
@ -40,4 +41,4 @@ public:
#define NS_IWEBSHELL_WINDOW_IID \
{ 0x28dce479, 0xbf73, 0x11d2, { 0x96, 0xc8, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56}}
#endif /* nsIWebShellWindow_h__ */
#endif /* nsIWebShellWindow_h__ */

Просмотреть файл

@ -41,6 +41,8 @@ class nsIFactory;
class nsIXULCommand : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IXULCOMMAND_IID; return iid; }
/**
* Adds a source widget/DOMNode to the command
* @param aNode the DOM node to be added

Просмотреть файл

@ -70,6 +70,8 @@ public:
nsString& aControllerIID,
nsIWidget*& aResult, nsIStreamObserver* anObserver);
NS_IMETHOD CloseTopLevelWindow(nsIWidget* aWindow);
NS_IMETHOD RegisterTopLevelWindow(nsIWidget* aWindow);
NS_IMETHOD UnregisterTopLevelWindow(nsIWidget* aWindow);
protected:
@ -184,14 +186,29 @@ nsAppShellService::CreateTopLevelWindow(nsIURL* aUrl, nsString& aControllerIID,
} else {
rv = window->Initialize(mAppShell, aUrl, aControllerIID, anObserver);
if (NS_SUCCEEDED(rv)) {
mWindowList->AppendElement((nsIWebShellContainer*)window);
aResult = window->GetWidget();
RegisterTopLevelWindow(aResult);
window->Show(PR_TRUE);
}
}
return rv;
}
NS_IMETHODIMP
nsAppShellService::CloseTopLevelWindow(nsIWidget* aWindow)
{
nsresult rv;
rv = UnregisterTopLevelWindow(aWindow);
if (0 == mWindowList->Count()) {
mAppShell->Exit();
}
return rv;
}
/*
* Create a new top level window and display the given URL within it...
*
@ -222,34 +239,53 @@ nsAppShellService::CreateDialogWindow(nsIWidget * aParent,
return rv;
}
NS_IMETHODIMP
nsAppShellService::CloseTopLevelWindow(nsIWidget* aWindow)
{
nsresult rv = NS_OK;
nsWebShellWindow* window;
/*
* Register a new top level window (created elsewhere)
*/
static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID);
NS_IMETHODIMP
nsAppShellService::RegisterTopLevelWindow(nsIWidget* aWindow)
{
nsresult rv;
void* data;
// Get the nsWebShellWindow from the nsIWidget...
aWindow->GetClientData(data);
if (nsnull != data) {
window = (nsWebShellWindow*)data;
if (data == nsnull)
rv = NS_ERROR_NULL_POINTER;
else {
nsWebShellWindow* window = (nsWebShellWindow *) data;
// nsCOMPtr<nsIWebShellContainer> wsc(window); DRaM
nsIWebShellContainer* wsc;
rv = window->QueryInterface(kIWebShellContainerIID, (void **) &wsc);
if (NS_SUCCEEDED(rv))
mWindowList->AppendElement(wsc);
}
if (nsnull != data) {
PRBool bFound;
bFound = mWindowList->RemoveElement((nsIWebShellContainer*)window);
}
if (0 == mWindowList->Count()) {
mAppShell->Exit();
}
return rv;
}
NS_IMETHODIMP
nsAppShellService::UnregisterTopLevelWindow(nsIWidget* aWindow)
{
nsresult rv;
void* data;
aWindow->GetClientData(data);
if (data == nsnull)
rv = NS_ERROR_NULL_POINTER;
else {
nsWebShellWindow* window = (nsWebShellWindow *) data;
// nsCOMPtr<nsIWebShellContainer> wsc(window); DRaM
nsIWebShellContainer* wsc;
rv = window->QueryInterface(kIWebShellContainerIID, (void **) &wsc);
if (NS_SUCCEEDED(rv))
mWindowList->RemoveElement(wsc);
}
return rv;
}
NS_EXPORT nsresult NS_NewAppShellService(nsIAppShellService** aResult)
{
if (nsnull == aResult) {

Просмотреть файл

@ -36,6 +36,7 @@
#include "nsIXULCommand.h"
#include "nsXULCommand.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMNodeList.h"
#include "nsIMenuBar.h"
#include "nsIMenu.h"
@ -240,9 +241,6 @@ nsresult nsWebShellWindow::Initialize(nsIWidget* aParent,
if (nsnull != aUrl) {
mWebShell->LoadURL(urlString);
}
mWebShell->Show();
mWindow->Show(PR_TRUE);
// Create the IWidgetController for the document...
mController = nsnull;
@ -408,6 +406,7 @@ nsCOMPtr<nsIDOMNode> nsWebShellWindow::FindNamedParentFromDoc(nsIDOMDocument * a
return node;
}
#if 0
//----------------------------------------
void nsWebShellWindow::LoadCommands(nsIWebShell * aWebShell, nsIDOMDocument * aDOMDoc)
{
@ -529,28 +528,37 @@ void nsWebShellWindow::LoadCommands(nsIWebShell * aWebShell, nsIDOMDocument * aD
}
}
#endif
//----------------------------------------
void nsWebShellWindow::ConnectCommandToOneGUINode(
nsIDOMNode* aNode,
nsIDOMElement * theNodeAsElement,
const nsString& theGuiNodeType)
void nsWebShellWindow::ConnectCommandToOneGUINode(nsIDOMNode* aGUINode)
{
nsCOMPtr<nsIDOMElement> domElement(aGUINode);
if (!domElement)
return;
nsAutoString cmdAtom("cmd");
nsString nodeCmdName;
theNodeAsElement->GetAttribute(cmdAtom, nodeCmdName);
nsCOMPtr<nsIXULCommand> cmd(FindCommandByName(nodeCmdName));
nsString cmdName;
domElement->GetAttribute(cmdAtom, cmdName);
nsCOMPtr<nsIXULCommand> cmd(FindCommandByName(cmdName));
if (cmd) {
nsString guiDisplayName; // ok, this doesn't work. How do I get the button text? jrm
theNodeAsElement->GetAttribute(nsAutoString("name"), guiDisplayName);
cmd->AddUINode(aGUINode);
#ifdef DEBUGCMDS
nsString nodeName, nodeType;
char *cmdNameString, *nodeNameString, *nodeTypeString;
if (DEBUGCMDS) printf("Linking cmd [%s] to %s [%s]\n",
nodeCmdName.ToNewCString(),
theGuiNodeType.ToNewCString(),
guiDisplayName.ToNewCString()
);
cmd->AddUINode(aNode);
cmdNameString = cmdName.ToNewCString();
domElement->GetNodeName(nodeType);
nodeTypeString = nodeType.ToNewCString();
domElement->GetAttribute(nsAutoString("name"), nodeName);
nodeNameString = nodeName.ToNewCString();
printf("Linkind cmd [%s] to %s [%s]\n",
cmdNameString, nodeTypeString, nodeNameString);
delete [] nodeNameString;
delete [] nodeTypeString;
delete [] cmdNameString;
#endif
}
} // nsWebShellWindow::ConnectCommandToOneGUINode
@ -630,7 +638,7 @@ void nsWebShellWindow::LoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWi
pnsMenuItem->SetLabel(menuitemName);
// Make nsMenuItem a child of nsMenu
//pnsMenu->AddMenuItem(pnsMenuItem); // XXX adds an additional item
ConnectCommandToOneGUINode(menuitemNode, menuitemElement, "menuitem");
ConnectCommandToOneGUINode(menuitemNode);
}
}
@ -703,6 +711,14 @@ nsWebShellWindow::FocusAvailable(nsIWebShell* aFocusedWebShell)
//----------------------------------------
// nsIWebShellWindow methods...
//----------------------------------------
NS_IMETHODIMP
nsWebShellWindow::Show(PRBool aShow)
{
mWebShell->Show(); // crimminy -- it doesn't take a parameter!
mWindow->Show(aShow);
return NS_OK;
}
NS_IMETHODIMP
nsWebShellWindow::GetWebShell(nsIWebShell *& aWebShell)
{
@ -838,6 +854,10 @@ PRInt32 nsWebShellWindow::GetDocHeight(nsIDocument * aDoc)
NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete()
{
if (DEBUGCMDS) printf("OnConnectionsComplete\n");
LoadCommandsInWebShell(mWebShell);
ConnectCommandsToWidgetsByType(mWebShell, nsAutoString("button"));
nsCOMPtr<nsIWebShell> contentWebShell;
mWebShell->FindChildWithName(nsAutoString("browser.webwindow"), *getter_AddRefs(contentWebShell));
@ -853,8 +873,10 @@ NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete()
nsCOMPtr<nsIDOMNode> parent(GetParentNodeFromDOMDoc(toolbarDOMDoc));
if (!parent)
return NS_ERROR_FAILURE;
LoadCommands(toolbarWebShell, toolbarDOMDoc);
LoadCommandsInWebShell(toolbarWebShell);
ConnectCommandsToWidgetsByType(toolbarWebShell, nsAutoString("button"));
PRInt32 count = 0;
nsCOMPtr<nsIDOMNode> imgNode(FindNamedDOMNode(nsAutoString("img"), parent, count, 7));
if (!imgNode)
@ -868,7 +890,7 @@ NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete()
nsCOMPtr<nsIDOMNode> node(FindNamedDOMNode(nsAutoString("input"), parent, count, 1));
if (node) {
if (NS_OK == node->QueryInterface(kIDOMHTMLInputElementIID, (void**) &mURLBarText)) {
PRUnichar * urlStr = nsnull;
const PRUnichar * urlStr = nsnull;
contentWebShell->GetURL(0, &urlStr);
if (nsnull != urlStr) {
nsString url(urlStr);
@ -885,6 +907,11 @@ NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete()
LoadMenus(menubarDOMDoc, mWindow);
}
// look for a special startup command and execute it -- hackery or permanent feature?
nsCOMPtr<nsIXULCommand> startupCmd(FindCommandByName(nsAutoString("nsCmd:StartUp")));
if (startupCmd)
startupCmd->DoCommand();
///////////////////////////////
// Find the Status Text DOM Node. EVIL ASSUMPTION THAT ALL SUCH WINDOWS HAVE ONE.
///////////////////////////////
@ -948,3 +975,172 @@ NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete()
} // nsWebShellWindow::OnConnectionsComplete
/**
* Get nsIDOMElement corresponding to a given webshell
* @param aShell the given webshell
* @return the corresponding DOM element, null if for some reason there is none
*/
nsCOMPtr<nsIDOMNode>
nsWebShellWindow::GetDOMNodeFromWebShell(nsIWebShell *aShell)
{
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIContentViewer> cv;
aShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
nsCOMPtr<nsIDocumentViewer> docv(cv);
if (docv) {
nsCOMPtr<nsIDocument> doc;
docv->GetDocument(*getter_AddRefs(doc));
if (doc) {
nsCOMPtr<nsIDOMDocument> domdoc(doc);
if (domdoc) {
nsCOMPtr<nsIDOMElement> element;
domdoc->GetDocumentElement(getter_AddRefs(element));
if (element)
node = element;
}
}
}
}
return node;
}
/**
* Wire up any commands found in the given DOM element. This is hackery
* to be replaced by the new command structure when available, but it's
* a more general hackery than LoadCommands().
* @param aNode the DOM node inside which we suspect commands
*/
void nsWebShellWindow::LoadCommandsInWebShell(nsIWebShell *aShell)
{
// NS_PRECONDITION(aNode, "null argument to LoadCommandsInElement");
nsCOMPtr<nsIDOMNode> webshellNode = GetDOMNodeFromWebShell(aShell);
if (!webshellNode)
return;
nsCOMPtr<nsIDOMElement> webshellElement(webshellNode);
if (!webshellElement)
return;
// process all child <commands...> nodes
nsCOMPtr<nsIDOMNodeList> commandRootList;
webshellElement->GetElementsByTagName(nsAutoString("commands"), getter_AddRefs(commandRootList));
if (commandRootList) {
PRUint32 rootCtr, rootCount;
commandRootList->GetLength(&rootCount);
for (rootCtr = 0; rootCtr < rootCount; rootCtr++) {
nsCOMPtr<nsIDOMNode> commandRoot;
if (NS_FAILED(commandRootList->Item(rootCtr, getter_AddRefs(commandRoot))))
break;
nsCOMPtr<nsIDOMElement> commandRootElement(commandRoot);
if (!commandRootElement)
break;
// process all child <command...> nodes of each <commands...> node
nsCOMPtr<nsIDOMNodeList> commandList;
commandRootElement->GetElementsByTagName(nsAutoString("command"), getter_AddRefs(commandList));
if (commandList) {
PRUint32 cmdCtr, cmdCount;
commandList->GetLength(&cmdCount);
for (cmdCtr = 0; cmdCtr < cmdCount; cmdCtr++) {
nsCOMPtr<nsIDOMNode> command;
if (NS_SUCCEEDED(commandList->Item(cmdCtr, getter_AddRefs(command))))
MakeOneCommand(aShell, command);
}
}
}
}
// XXX hack until Command DOM is available
// Enable All Command
PRInt32 i, n = mCommands.Count();
for (i = 0; i < n; i++) {
nsXULCommand* cmd = (nsXULCommand*) mCommands.ElementAt(i);
cmd->SetEnabled(PR_TRUE);
}
}
/**
* Create an nsXULCommand, add it to our list of commands.
* @param aShell the webshell to which the command belongs, in which it is found in the XUL
* @param aCommand the DOM command node describing the command
*/
void
nsWebShellWindow::MakeOneCommand(nsIWebShell *aShell, nsCOMPtr<nsIDOMNode> aCommand)
{
nsCOMPtr<nsIDOMElement> cmdElement(aCommand);
if (!cmdElement)
return;
nsString name,
value;
cmdElement->GetAttribute(nsAutoString("name"), name);
cmdElement->GetAttribute(nsAutoString("onCommand"), value);
// create command object and add it to the webshell's list
if (DEBUGCMDS) printf("Creating cmd [%s]\n",name.ToNewCString());
nsXULCommand * xulCmd = new nsXULCommand();
xulCmd->SetName(name);
xulCmd->SetCommand(value);
xulCmd->SetWebShell(aShell);
xulCmd->SetDOMElement(cmdElement);
nsIXULCommand *iCmd;
if (NS_SUCCEEDED(xulCmd->QueryInterface(nsIXULCommand::IID(), (void**) &iCmd)))
mCommands.AppendElement(iCmd);
}
/**
* Search for widgets with the given type. Wire them to the command list in mCommands.
* Assumes mCommands has already been built.
* @param aShell the webshell in which to search for widgets
* @param aType all widgets of this type (XML element tag) will be considered
*/
void
nsWebShellWindow::ConnectCommandsToWidgetsByType(nsIWebShell *aShell, nsString &aType)
{
// hook it up to any toolbars you may find in the webshell
nsCOMPtr<nsIDOMNode> webshellNode = GetDOMNodeFromWebShell(aShell);
if (!webshellNode)
return;
nsCOMPtr<nsIDOMElement> webshellElement(webshellNode);
if (!webshellElement)
return;
nsCOMPtr<nsIDOMNodeList> widgetList;
webshellElement->GetElementsByTagName(aType, getter_AddRefs(widgetList));
if (widgetList)
ConnectWidgetCommands(widgetList);
}
/**
* Look for the "cmd" attribute in a list of widgets, and hook up the corresponding
* commands. Assumes the list of commands in mCommands has already been built.
* @param aNodes a list of DOM nodes, presumably widgets, which may contain commands
*/
void
nsWebShellWindow::ConnectWidgetCommands(nsIDOMNodeList *aNodes)
{
PRUint32 listCount, listCtr;
if (!aNodes)
return;
aNodes->GetLength(&listCount);
for (listCtr = 0; listCtr < listCount; listCtr++) {
nsCOMPtr<nsIDOMNode> domNode;
if (NS_SUCCEEDED(aNodes->Item(listCtr, getter_AddRefs(domNode))))
ConnectCommandToOneGUINode(domNode);
}
}

Просмотреть файл

@ -84,6 +84,7 @@ public:
// nsIWebShellWindow methods...
NS_IMETHOD Show(PRBool aShow);
NS_IMETHOD GetWebShell(nsIWebShell *& aWebShell);
NS_IMETHOD GetWidget(nsIWidget *& aWidget);
@ -99,11 +100,7 @@ public:
protected:
PRInt32 GetDocHeight(nsIDocument * aDoc);
void SetCommandEnabled(const nsString & aCmdName, PRBool aState);
void LoadCommands(nsIWebShell * aWebShell, nsIDOMDocument * aDOMDoc);
void ConnectCommandToOneGUINode(
nsIDOMNode* aNode,
nsIDOMElement* theNodeAsElementElement,
const nsString& aGuiNodeType);
void ConnectCommandToOneGUINode(nsIDOMNode* aGUINode);
void LoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWindow);
nsCOMPtr<nsIXULCommand> FindCommandByName(const nsString & aCmdName);
@ -112,11 +109,18 @@ protected:
nsCOMPtr<nsIDOMDocument> GetNamedDOMDoc(const nsString & aWebShellName);
nsCOMPtr<nsIDOMNode> GetParentNodeFromDOMDoc(nsIDOMDocument * aDOMDoc);
nsCOMPtr<nsIDOMNode> GetDOMNodeFromWebShell(nsIWebShell *aShell);
void LoadCommandsInWebShell(nsIWebShell *aShell);
void MakeOneCommand(nsIWebShell *aShell, nsCOMPtr<nsIDOMNode> aCommand);
void ConnectCommandsToWidgetsByType(nsIWebShell *aShell, nsString &aType);
void ConnectWidgetCommands(nsIDOMNodeList *aNodes);
virtual ~nsWebShellWindow();
static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent);
nsIWidget* mWindow;
nsIWidget* mWindow;
nsIWebShell* mWebShell;
nsIWidgetController* mController;
nsIDOMCharacterData* mStatusText;

Просмотреть файл

@ -31,6 +31,7 @@
static nsIDOMAppCores *gAppCores = NULL;
static NS_DEFINE_IID(kIAppCoresIID, NS_IDOMAPPCORES_IID);
static NS_DEFINE_IID(kAppCoresCID, NS_AppCores_CID);
static NS_DEFINE_IID(kToolkitCoreCID, NS_TOOLKITCORE_CID);
static NS_DEFINE_IID(kMailCoreCID, NS_MailCore_CID);
static NS_DEFINE_IID(kToolbarCoreCID, NS_TOOLBARCORE_CID);
static NS_DEFINE_IID(kBrowserAppCoreCID, NS_BROWSERAPPCORE_CID);
@ -91,6 +92,7 @@ NS_SetupRegistry_1()
//#if defined(XP_PC) || defined(XP_MAC)
nsRepository::RegisterFactory(kAppCoresCID, APPCORES_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kToolkitCoreCID, APPCORES_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kMailCoreCID, APPCORES_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kToolbarCoreCID, APPCORES_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kBrowserAppCoreCID, APPCORES_DLL, PR_FALSE, PR_FALSE);