From 2cf50fdc88f23c97cdd4e53290abaaccf31365d8 Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Mon, 15 Feb 1999 05:38:15 +0000 Subject: [PATCH] added beginnings of toolkit dialog factory git-svn-id: svn://10.0.0.236/trunk@20723 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpfe/AppCores/idl/ToolkitCore.idl | 8 + mozilla/xpfe/AppCores/macbuild/AppCores.mcp | Bin 43417 -> 50041 bytes mozilla/xpfe/AppCores/public/Makefile.in | 7 +- mozilla/xpfe/AppCores/public/makefile.win | 1 + mozilla/xpfe/AppCores/public/nsAppCoresCIDs.h | 11 + .../xpfe/AppCores/public/nsIDOMToolkitCore.h | 55 +++ mozilla/xpfe/AppCores/src/Makefile.in | 3 + mozilla/xpfe/AppCores/src/makefile.win | 3 + mozilla/xpfe/AppCores/src/nsAppCores.cpp | 9 +- .../xpfe/AppCores/src/nsAppCoresNameSet.cpp | 10 +- mozilla/xpfe/AppCores/src/nsJSToolkitcore.cpp | 362 ++++++++++++++++++ mozilla/xpfe/AppCores/src/nsToolkitCore.cpp | 154 ++++++++ mozilla/xpfe/AppCores/src/nsToolkitCore.h | 53 +++ .../AppCores/src/nsToolkitCoreFactory.cpp | 114 ++++++ .../xpfe/AppCores/src/nsToolkitCoreFactory.h | 46 +++ .../xpfe/appshell/public/nsIAppShellService.h | 2 + .../xpfe/appshell/public/nsIWebShellWindow.h | 3 +- mozilla/xpfe/appshell/public/nsIXULCommand.h | 2 + .../xpfe/appshell/src/nsAppShellService.cpp | 78 +++- .../xpfe/appshell/src/nsWebShellWindow.cpp | 242 ++++++++++-- mozilla/xpfe/appshell/src/nsWebShellWindow.h | 16 +- mozilla/xpfe/bootstrap/nsSetupRegistry.cpp | 2 + 22 files changed, 1125 insertions(+), 56 deletions(-) create mode 100644 mozilla/xpfe/AppCores/idl/ToolkitCore.idl create mode 100644 mozilla/xpfe/AppCores/public/nsIDOMToolkitCore.h create mode 100644 mozilla/xpfe/AppCores/src/nsJSToolkitcore.cpp create mode 100644 mozilla/xpfe/AppCores/src/nsToolkitCore.cpp create mode 100644 mozilla/xpfe/AppCores/src/nsToolkitCore.h create mode 100644 mozilla/xpfe/AppCores/src/nsToolkitCoreFactory.cpp create mode 100644 mozilla/xpfe/AppCores/src/nsToolkitCoreFactory.h diff --git a/mozilla/xpfe/AppCores/idl/ToolkitCore.idl b/mozilla/xpfe/AppCores/idl/ToolkitCore.idl new file mode 100644 index 00000000000..6e58ad64597 --- /dev/null +++ b/mozilla/xpfe/AppCores/idl/ToolkitCore.idl @@ -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); +}; diff --git a/mozilla/xpfe/AppCores/macbuild/AppCores.mcp b/mozilla/xpfe/AppCores/macbuild/AppCores.mcp index 138eb577caf35eab44b75279a0a7985f1793097a..a819ddd4b685421285d9efb764d6195c22951eb7 100644 GIT binary patch delta 2214 zcmchZdu&rx9LLYO>)pDwgH1{qTZQs4jKXf`fHFZI-HU+?8`eEQrfj3z*wzPaaTW@wl;)`u8C;_?rfe9uM(GVXYL{URB0fPzZW`qbqCF=LwTV(MM{xR{F{QCRe z&w1?pe&^hCx91D#x95{=jlp0$V=Rd=p3B&YJ&b*DiZS^(*n;ov(t*AQEEZO%Y!Qy-k1#A!y#m%Ng0r#NLVU=`&WJ0?wpvUB{vouVtei!t*I#>7b0 zMi-qqnL-KU9NplYZW$xgVlz`m>INHF9$ZOGp-m~FH+;5gNbBabbbLb^%hnKQwwOET zfoeRgMK)U*GeWXzmb(4NN?+8yZrw^>leA;BcvKggjhu$F$EAzR9)qufw^C}(qV#5{ zW$f>p=dos?q^X({YCZ!lx2 z1@Kv7$@I?Lk77l3wRVX)nF7i!%1p~4HQPeNCZjrRE0PxmBFieh*qyfZ(c)m(r!GD#s7m4Upo9CwTX@i4$A<*y?MH(p%%QCMVjMI}{S7iztzn_J(;Q zyP-TEO6uat7M?6I!-`;lwki|U?G=a845Ax#@5_pLWZC5Qc$UZ9#aPOytkZgR3-ZTxqng2W5is3 z@j=>BkexF0Qy6c-4_MG2oL-x4)q#J$2Gpr*tXw^|?Sxfz)eYJI_qEc=c?R{Sn{$*( z=GwNYw~9>?9d^moy`~>{HRq{Vt0Y-U%9eXaSNNjgV23Z<7O{&$#@zXtO9N3~IN*!g zOP>n0V>`m=ev_*m`I0zUc$@y~JY3=ujdDy=>uL)PM)8)3O`y%IrpU9Psx&nlYQ%B3 z$b~`FoyvP>6r|(zmY6>h4WQ2mvt1GQ1~_&o>FV8v(dE?Ft4LF?(D~lR(oOzoJEjtM z+Z{7!LFHl~Zj_M&r(;5Crau(<7q1zn&3)teafO@ zMqYPp%o(UI@Cf1vp86}EGr+}7HiBD_AlpQ%`W>#iIgD9PhQhuk*7Ha@@Dey|>;PlQ zW}VNO0w9KnfYe5r>HU6(l>aDw-|rlM33Qa!F&@7ST>*!gi1H3N`Oj2$KFk@(E8#H3k2+=P{2Os!R%)0P)F2KdcrkS1PPJ`;R&;)K5IS+c7W{?$^wq|%iFt&> zZ13VHJJc!Ci(j~o2Qe`$as&L5KGDu+0cthOcAftx?f6%3fQh>ww)?V3Tkn5blw!4p z*&GuRNYVL=JHW*E0`~SW7G%_U>n=0M8jUmOa}*y?I$ihSu|aF^@rrNP6MD1lV?>M2 zC*?!0P4EkdX*y3|0bQ?iR}?X^u44zF8+2a%3}T|-ySG9&>bw_uqu_c$KFz>% delta 1426 zcmZvc3uv2F6vxl^<@M#&Ei7r92U@X(u1%8|SoT1>wZpAU?84S9nXcHicHKtPgr&%Q zK&PUDL*e6?>IR}>nPm{{ygG{5CW_A$akSu*;gCW%++ga^O(yui`MO%g1LxjzfA@Un z-gEA~-;HNY$LG{gUp6~PL?$Aok?2i7(O4UiB@MRzbm%9Gs7bddTs~vwsO=n^v@oyL zhV`V&9fC)lf(9Dq3tF&Y0E44M&LWWuCJj)g<*Iq6<*IVqrJLrt5aQ1_@^vlG$6Rhc zV$XTuv=iEc1>1=s6v=Xc(WTpbtRzLc5{6p$|g$@SuC6 zWgDyxG3kC;(UW#DA8NPog8rMROV27ikudY7y=IYG@r_B}dP2imKunOu;+B*wg>}SJ_m^kB6^`x~D<65fPw%|po z!7qd-?NKp6Z64i$!3{-BBuWYrw8OnaBx9N?h9b2Jr{m)?d46K|Sp#fIozk}*64&Cj zs;D~YRQay=>x|vL%44oUG469)tty#1vqStwp+-;Igtbs~hz}>1vJ$`NFW2eG$3)SO zWvWiPRFUW|SO3pfHX?Ti4xK-rYK{l4$V1BHhlh~jG6{iek{?F)7yp^4zrqdE5p{Kj zcTM-*o68IjW-*D9-4eTWZp4QN|NUWXI~EFOa{2%8_~ZQ7bd7S3eWfkd#M_8f=6$86 z&h#2wGs+C-@G=(qHEDa41V!E>|K%) zwf&6zjNKM~k#VF#oQx)r8xtWBfh1y3tztmu&09Q zI8M|tYxsXGOCet%#D5A2*bIK`c>wtmA?x6;Y6d^_qWqW0=L&Ha+4oUor1d%2y_NaV zuG?WhBqy<_(`dW~zas{_2MTc_L2?+}-3fc2r11X)&0^y3z6HBiQli#NXci0p(vz@p zY*IFgO2Jc=f_&Ks@^FRIrWy1`#Yba*!tOVCRQ8J%e?@M3zri>Eu~hL C>rqJn diff --git a/mozilla/xpfe/AppCores/public/Makefile.in b/mozilla/xpfe/AppCores/public/Makefile.in index f5b361ddbbc..249b4fcc8cd 100644 --- a/mozilla/xpfe/AppCores/public/Makefile.in +++ b/mozilla/xpfe/AppCores/public/Makefile.in @@ -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)) diff --git a/mozilla/xpfe/AppCores/public/makefile.win b/mozilla/xpfe/AppCores/public/makefile.win index 07ebce6dce2..cdbc9f6ff5d 100644 --- a/mozilla/xpfe/AppCores/public/makefile.win +++ b/mozilla/xpfe/AppCores/public/makefile.win @@ -26,6 +26,7 @@ EXPORTS= \ nsIDOMBaseAppCore.h \ nsIDOMMailCore.h \ nsIDOMToolbarCore.h \ + nsIDOMToolkitCore.h \ nsIDOMBrowserAppCore.h \ nsAppCoresCIDs.h diff --git a/mozilla/xpfe/AppCores/public/nsAppCoresCIDs.h b/mozilla/xpfe/AppCores/public/nsAppCoresCIDs.h index 7b6c96f1e4c..3a252bd5c30 100644 --- a/mozilla/xpfe/AppCores/public/nsAppCoresCIDs.h +++ b/mozilla/xpfe/AppCores/public/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 */ \ diff --git a/mozilla/xpfe/AppCores/public/nsIDOMToolkitCore.h b/mozilla/xpfe/AppCores/public/nsIDOMToolkitCore.h new file mode 100644 index 00000000000..9b8af4a3f1b --- /dev/null +++ b/mozilla/xpfe/AppCores/public/nsIDOMToolkitCore.h @@ -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__ diff --git a/mozilla/xpfe/AppCores/src/Makefile.in b/mozilla/xpfe/AppCores/src/Makefile.in index 889d23d966b..50262243692 100644 --- a/mozilla/xpfe/AppCores/src/Makefile.in +++ b/mozilla/xpfe/AppCores/src/Makefile.in @@ -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) diff --git a/mozilla/xpfe/AppCores/src/makefile.win b/mozilla/xpfe/AppCores/src/makefile.win index dc2c2fad3d8..0c8321c9870 100644 --- a/mozilla/xpfe/AppCores/src/makefile.win +++ b/mozilla/xpfe/AppCores/src/makefile.win @@ -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) diff --git a/mozilla/xpfe/AppCores/src/nsAppCores.cpp b/mozilla/xpfe/AppCores/src/nsAppCores.cpp index e92cd3dba6c..6e8cab574a9 100644 --- a/mozilla/xpfe/AppCores/src/nsAppCores.cpp +++ b/mozilla/xpfe/AppCores/src/nsAppCores.cpp @@ -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(); diff --git a/mozilla/xpfe/AppCores/src/nsAppCoresNameSet.cpp b/mozilla/xpfe/AppCores/src/nsAppCoresNameSet.cpp index e6f7a04e685..33ecac1cdaf 100644 --- a/mozilla/xpfe/AppCores/src/nsAppCoresNameSet.cpp +++ b/mozilla/xpfe/AppCores/src/nsAppCoresNameSet.cpp @@ -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; diff --git a/mozilla/xpfe/AppCores/src/nsJSToolkitcore.cpp b/mozilla/xpfe/AppCores/src/nsJSToolkitcore.cpp new file mode 100644 index 00000000000..1d4c6ffccf6 --- /dev/null +++ b/mozilla/xpfe/AppCores/src/nsJSToolkitcore.cpp @@ -0,0 +1,362 @@ +/* -*- 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!!! */ + +#include "jsapi.h" +#include "nsJSUtils.h" +#include "nscore.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" +#include "nsString.h" +#include "nsIDOMToolkitCore.h" +#include "nsIDOMWindow.h" +#include "nsIScriptNameSpaceManager.h" +#include "nsRepository.h" +#include "nsDOMCID.h" + + +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kIToolkitCoreIID, NS_IDOMTOOLKITCORE_IID); +static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID); + +NS_DEF_PTR(nsIDOMToolkitCore); +NS_DEF_PTR(nsIDOMWindow); + + +/***********************************************************************/ +// +// ToolkitCore Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetToolkitCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMToolkitCore *a = (nsIDOMToolkitCore*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case 0: + default: + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); + } + + return PR_TRUE; +} + +/***********************************************************************/ +// +// ToolkitCore Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetToolkitCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMToolkitCore *a = (nsIDOMToolkitCore*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case 0: + default: + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); + } + + return PR_TRUE; +} + + +// +// ToolkitCore finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeToolkitCore(JSContext *cx, JSObject *obj) +{ + nsJSUtils::nsGenericFinalize(cx, obj); +} + + +// +// ToolkitCore enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateToolkitCore(JSContext *cx, JSObject *obj) +{ + return nsJSUtils::nsGenericEnumerate(cx, obj); +} + + +// +// ToolkitCore resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveToolkitCore(JSContext *cx, JSObject *obj, jsval id) +{ + return nsJSUtils::nsGenericResolve(cx, obj, id); +} + + +// +// Native method ShowWindow +// +PR_STATIC_CALLBACK(JSBool) +ToolkitCoreShowWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMToolkitCore *nativeThis = (nsIDOMToolkitCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString b0; + nsIDOMWindowPtr b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 2) { + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1, + kIWindowIID, + "Window", + cx, + argv[1])) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->ShowWindow(b0, b1)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function ShowWindow requires 2 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for ToolkitCore +// +JSClass ToolkitCoreClass = { + "ToolkitCore", + JSCLASS_HAS_PRIVATE, + JS_PropertyStub, + JS_PropertyStub, + GetToolkitCoreProperty, + SetToolkitCoreProperty, + EnumerateToolkitCore, + ResolveToolkitCore, + JS_ConvertStub, + FinalizeToolkitCore +}; + + +// +// ToolkitCore class properties +// +static JSPropertySpec ToolkitCoreProperties[] = +{ + {0} +}; + + +// +// ToolkitCore class methods +// +static JSFunctionSpec ToolkitCoreMethods[] = +{ + {"ShowWindow", ToolkitCoreShowWindow, 2}, + {0} +}; + + +// +// ToolkitCore constructor +// +PR_STATIC_CALLBACK(JSBool) +ToolkitCore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsresult result; + nsIID classID; + nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx); + nsIScriptNameSpaceManager* manager; + nsIDOMToolkitCore *nativeThis; + nsIScriptObjectOwner *owner = nsnull; + + static NS_DEFINE_IID(kIDOMToolkitCoreIID, NS_IDOMTOOLKITCORE_IID); + + result = context->GetNameSpaceManager(&manager); + if (NS_OK != result) { + return JS_FALSE; + } + + result = manager->LookupName("ToolkitCore", PR_TRUE, classID); + NS_RELEASE(manager); + if (NS_OK != result) { + return JS_FALSE; + } + + result = nsRepository::CreateInstance(classID, + nsnull, + kIDOMToolkitCoreIID, + (void **)&nativeThis); + if (NS_OK != result) { + return JS_FALSE; + } + + // XXX We should be calling Init() on the instance + + result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner); + if (NS_OK != result) { + NS_RELEASE(nativeThis); + return JS_FALSE; + } + + owner->SetScriptObject((void *)obj); + JS_SetPrivate(cx, obj, nativeThis); + + NS_RELEASE(owner); + return JS_TRUE; +} + +// +// ToolkitCore class initialization +// +nsresult NS_InitToolkitCoreClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "ToolkitCore", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + if (NS_OK != NS_InitBaseAppCoreClass(aContext, (void **)&parent_proto)) { + return NS_ERROR_FAILURE; + } + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &ToolkitCoreClass, // JSClass + ToolkitCore, // JSNative ctor + 0, // ctor args + ToolkitCoreProperties, // proto props + ToolkitCoreMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new ToolkitCore JavaScript object +// +extern "C" NS_DOM nsresult NS_NewScriptToolkitCore(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptToolkitCore"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + nsresult result = NS_OK; + nsIDOMToolkitCore *aToolkitCore; + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitToolkitCoreClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + result = aSupports->QueryInterface(kIToolkitCoreIID, (void **)&aToolkitCore); + if (NS_OK != result) { + return result; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &ToolkitCoreClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aToolkitCore); + } + else { + NS_RELEASE(aToolkitCore); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/mozilla/xpfe/AppCores/src/nsToolkitCore.cpp b/mozilla/xpfe/AppCores/src/nsToolkitCore.cpp new file mode 100644 index 00000000000..4f3243a5dfb --- /dev/null +++ b/mozilla/xpfe/AppCores/src/nsToolkitCore.cpp @@ -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; +} diff --git a/mozilla/xpfe/AppCores/src/nsToolkitCore.h b/mozilla/xpfe/AppCores/src/nsToolkitCore.h new file mode 100644 index 00000000000..1ad8ee02620 --- /dev/null +++ b/mozilla/xpfe/AppCores/src/nsToolkitCore.h @@ -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___ diff --git a/mozilla/xpfe/AppCores/src/nsToolkitCoreFactory.cpp b/mozilla/xpfe/AppCores/src/nsToolkitCoreFactory.cpp new file mode 100644 index 00000000000..dab2e6570f0 --- /dev/null +++ b/mozilla/xpfe/AppCores/src/nsToolkitCoreFactory.cpp @@ -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; +} diff --git a/mozilla/xpfe/AppCores/src/nsToolkitCoreFactory.h b/mozilla/xpfe/AppCores/src/nsToolkitCoreFactory.h new file mode 100644 index 00000000000..51309d82aa9 --- /dev/null +++ b/mozilla/xpfe/AppCores/src/nsToolkitCoreFactory.h @@ -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___ diff --git a/mozilla/xpfe/appshell/public/nsIAppShellService.h b/mozilla/xpfe/appshell/public/nsIAppShellService.h index e79ecedcc12..89075b9e9eb 100644 --- a/mozilla/xpfe/appshell/public/nsIAppShellService.h +++ b/mozilla/xpfe/appshell/public/nsIAppShellService.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__ */ diff --git a/mozilla/xpfe/appshell/public/nsIWebShellWindow.h b/mozilla/xpfe/appshell/public/nsIWebShellWindow.h index fd6ff6723f7..974e60008f9 100644 --- a/mozilla/xpfe/appshell/public/nsIWebShellWindow.h +++ b/mozilla/xpfe/appshell/public/nsIWebShellWindow.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__ */ \ No newline at end of file +#endif /* nsIWebShellWindow_h__ */ diff --git a/mozilla/xpfe/appshell/public/nsIXULCommand.h b/mozilla/xpfe/appshell/public/nsIXULCommand.h index dd2a6d9da85..63633777fdd 100644 --- a/mozilla/xpfe/appshell/public/nsIXULCommand.h +++ b/mozilla/xpfe/appshell/public/nsIXULCommand.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 diff --git a/mozilla/xpfe/appshell/src/nsAppShellService.cpp b/mozilla/xpfe/appshell/src/nsAppShellService.cpp index 9338ef0692b..6a035fc5311 100644 --- a/mozilla/xpfe/appshell/src/nsAppShellService.cpp +++ b/mozilla/xpfe/appshell/src/nsAppShellService.cpp @@ -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 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 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) { diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index 1f1d42d13e1..4b17930361c 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -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 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 domElement(aGUINode); + if (!domElement) + return; + nsAutoString cmdAtom("cmd"); - nsString nodeCmdName; - theNodeAsElement->GetAttribute(cmdAtom, nodeCmdName); - nsCOMPtr cmd(FindCommandByName(nodeCmdName)); + nsString cmdName; + + domElement->GetAttribute(cmdAtom, cmdName); + nsCOMPtr 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 contentWebShell; mWebShell->FindChildWithName(nsAutoString("browser.webwindow"), *getter_AddRefs(contentWebShell)); @@ -853,8 +873,10 @@ NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete() nsCOMPtr parent(GetParentNodeFromDOMDoc(toolbarDOMDoc)); if (!parent) return NS_ERROR_FAILURE; - LoadCommands(toolbarWebShell, toolbarDOMDoc); - + + LoadCommandsInWebShell(toolbarWebShell); + ConnectCommandsToWidgetsByType(toolbarWebShell, nsAutoString("button")); + PRInt32 count = 0; nsCOMPtr imgNode(FindNamedDOMNode(nsAutoString("img"), parent, count, 7)); if (!imgNode) @@ -868,7 +890,7 @@ NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete() nsCOMPtr 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 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 +nsWebShellWindow::GetDOMNodeFromWebShell(nsIWebShell *aShell) +{ + nsCOMPtr node; + + nsCOMPtr cv; + aShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) { + nsCOMPtr docv(cv); + if (docv) { + nsCOMPtr doc; + docv->GetDocument(*getter_AddRefs(doc)); + if (doc) { + nsCOMPtr domdoc(doc); + if (domdoc) { + nsCOMPtr 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 webshellNode = GetDOMNodeFromWebShell(aShell); + if (!webshellNode) + return; + nsCOMPtr webshellElement(webshellNode); + if (!webshellElement) + return; + + // process all child nodes + nsCOMPtr commandRootList; + webshellElement->GetElementsByTagName(nsAutoString("commands"), getter_AddRefs(commandRootList)); + if (commandRootList) { + PRUint32 rootCtr, rootCount; + commandRootList->GetLength(&rootCount); + for (rootCtr = 0; rootCtr < rootCount; rootCtr++) { + nsCOMPtr commandRoot; + if (NS_FAILED(commandRootList->Item(rootCtr, getter_AddRefs(commandRoot)))) + break; + nsCOMPtr commandRootElement(commandRoot); + if (!commandRootElement) + break; + + // process all child nodes of each node + nsCOMPtr commandList; + commandRootElement->GetElementsByTagName(nsAutoString("command"), getter_AddRefs(commandList)); + if (commandList) { + PRUint32 cmdCtr, cmdCount; + commandList->GetLength(&cmdCount); + for (cmdCtr = 0; cmdCtr < cmdCount; cmdCtr++) { + + nsCOMPtr 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 aCommand) +{ + nsCOMPtr 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 webshellNode = GetDOMNodeFromWebShell(aShell); + if (!webshellNode) + return; + nsCOMPtr webshellElement(webshellNode); + if (!webshellElement) + return; + + nsCOMPtr 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 domNode; + if (NS_SUCCEEDED(aNodes->Item(listCtr, getter_AddRefs(domNode)))) + ConnectCommandToOneGUINode(domNode); + } +} diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.h b/mozilla/xpfe/appshell/src/nsWebShellWindow.h index 2050a0f1380..9ead42962df 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.h +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.h @@ -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 FindCommandByName(const nsString & aCmdName); @@ -112,11 +109,18 @@ protected: nsCOMPtr GetNamedDOMDoc(const nsString & aWebShellName); nsCOMPtr GetParentNodeFromDOMDoc(nsIDOMDocument * aDOMDoc); + nsCOMPtr GetDOMNodeFromWebShell(nsIWebShell *aShell); + void LoadCommandsInWebShell(nsIWebShell *aShell); + void MakeOneCommand(nsIWebShell *aShell, nsCOMPtr 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; diff --git a/mozilla/xpfe/bootstrap/nsSetupRegistry.cpp b/mozilla/xpfe/bootstrap/nsSetupRegistry.cpp index 493d7caa422..7998e1416ca 100644 --- a/mozilla/xpfe/bootstrap/nsSetupRegistry.cpp +++ b/mozilla/xpfe/bootstrap/nsSetupRegistry.cpp @@ -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);