Added XULCommand back in fixed commands

This commit is contained in:
rods%netscape.com 1999-02-11 15:14:34 +00:00
Родитель 7c6549cd3f
Коммит 1291cb1b5f
23 изменённых файлов: 1193 добавлений и 560 удалений

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

@ -11,9 +11,12 @@ interface BrowserAppCore : BaseAppCore
void setToolbarWindow(in Window win);
void setContentWindow(in Window win);
void setWebShellWindow(in Window win);
void disableCallback(in wstring script);
void enableCallback(in wstring script);
void showPasswordDialog(in Window win);
void setDisableCallback(in wstring script);
void setEnableCallback(in wstring script);
};

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

@ -1,14 +0,0 @@
interface ToolbarCore : BaseAppCore
{
/* IID: { 0xbf4ae23e, 0xba9b, 0x11d2, \
{0x96, 0xc4, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56}} */
void ToolbarCore();
void SetWindow(in Window win);
void SetWebShellWindow(in Window win);
void SetStatus(in wstring msg);
};

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

@ -45,9 +45,11 @@ public:
NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin)=0;
NS_IMETHOD DisableCallback(const nsString& aScript)=0;
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin)=0;
NS_IMETHOD EnableCallback(const nsString& aScript)=0;
NS_IMETHOD SetDisableCallback(const nsString& aScript)=0;
NS_IMETHOD SetEnableCallback(const nsString& aScript)=0;
};
@ -57,8 +59,9 @@ public:
NS_IMETHOD LoadUrl(const nsString& aUrl); \
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin); \
NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin); \
NS_IMETHOD DisableCallback(const nsString& aScript); \
NS_IMETHOD EnableCallback(const nsString& aScript); \
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin); \
NS_IMETHOD SetDisableCallback(const nsString& aScript); \
NS_IMETHOD SetEnableCallback(const nsString& aScript); \
@ -68,8 +71,9 @@ public:
NS_IMETHOD LoadUrl(const nsString& aUrl) { return _to##LoadUrl(aUrl); } \
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin) { return _to##SetToolbarWindow(aWin); } \
NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin) { return _to##SetContentWindow(aWin); } \
NS_IMETHOD DisableCallback(const nsString& aScript) { return _to##DisableCallback(aScript); } \
NS_IMETHOD EnableCallback(const nsString& aScript) { return _to##EnableCallback(aScript); } \
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin) { return _to##SetWebShellWindow(aWin); } \
NS_IMETHOD SetDisableCallback(const nsString& aScript) { return _to##SetDisableCallback(aScript); } \
NS_IMETHOD SetEnableCallback(const nsString& aScript) { return _to##SetEnableCallback(aScript); } \
extern nsresult NS_InitBrowserAppCoreClass(nsIScriptContext *aContext, void **aPrototype);

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

@ -37,22 +37,18 @@ public:
NS_IMETHOD SetWindow(nsIDOMWindow* aWin)=0;
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin)=0;
NS_IMETHOD SetStatus(const nsString& aMsg)=0;
};
#define NS_DECL_IDOMTOOLBARCORE \
NS_IMETHOD SetWindow(nsIDOMWindow* aWin); \
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin); \
NS_IMETHOD SetStatus(const nsString& aMsg); \
#define NS_FORWARD_IDOMTOOLBARCORE(_to) \
NS_IMETHOD SetWindow(nsIDOMWindow* aWin) { return _to##SetWindow(aWin); } \
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin) { return _to##SetWebShellWindow(aWin); } \
NS_IMETHOD SetStatus(const nsString& aMsg) { return _to##SetStatus(aMsg); } \

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

@ -29,19 +29,43 @@
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIURL.h"
#include "nsIWidget.h"
#include "plevent.h"
#include "nsIAppShell.h"
#include "nsIAppShellService.h"
#include "nsAppShellCIDs.h"
/* Define Class IDs */
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
static NS_DEFINE_IID(kBrowserAppCoreCID, NS_BROWSERAPPCORE_CID);
/* Define Interface IDs */
static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID);
// Globals
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIBrowserAppCoreIID, NS_IDOMBROWSERAPPCORE_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, nsIDOMDocument::IID());
static NS_DEFINE_IID(kIDocumentIID, nsIDocument::IID());
static NS_DEFINE_IID(kBrowserAppCoreCID, NS_BROWSERAPPCORE_CID);
static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID);
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
static NS_DEFINE_IID(kIWebShellWindowIID, NS_IWEBSHELL_WINDOW_IID);
/////////////////////////////////////////////////////////////////////////
@ -57,6 +81,7 @@ nsBrowserAppCore::nsBrowserAppCore()
mToolbarScriptContext = nsnull;
mContentWindow = nsnull;
mContentScriptContext = nsnull;
mWebShellWin = nsnull;
IncInstanceCount();
NS_INIT_REFCNT();
@ -68,6 +93,7 @@ nsBrowserAppCore::~nsBrowserAppCore()
NS_IF_RELEASE(mToolbarScriptContext);
NS_IF_RELEASE(mContentWindow);
NS_IF_RELEASE(mContentScriptContext);
NS_IF_RELEASE(mWebShellWin);
DecInstanceCount();
}
@ -91,7 +117,18 @@ nsBrowserAppCore::QueryInterface(REFNSIID aIID,void** aInstancePtr)
AddRef();
return NS_OK;
}
if (aIID.Equals(kINetSupportIID)) {
*aInstancePtr = (void*) ((nsINetSupport*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIStreamObserverIID)) {
*aInstancePtr = (void*) ((nsIStreamObserver*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return nsBaseAppCore::QueryInterface(aIID, aInstancePtr);
}
@ -129,9 +166,9 @@ nsBrowserAppCore::Init(const nsString& aId)
NS_IMETHODIMP
nsBrowserAppCore::Back()
{
ExecuteScript(mToolbarScriptContext, mDisableScript);
ExecuteScript(mContentScriptContext, "window.back()");
ExecuteScript(mToolbarScriptContext, mEnableScript);
//ExecuteScript(mToolbarScriptContext, mDisableScript);
ExecuteScript(mContentScriptContext, "window.back();");
//ExecuteScript(mToolbarScriptContext, mEnableScript);
return NS_OK;
}
@ -145,14 +182,14 @@ nsBrowserAppCore::Forward()
}
NS_IMETHODIMP
nsBrowserAppCore::DisableCallback(const nsString& aScript)
nsBrowserAppCore::SetDisableCallback(const nsString& aScript)
{
mDisableScript = aScript;
return NS_OK;
}
NS_IMETHODIMP
nsBrowserAppCore::EnableCallback(const nsString& aScript)
nsBrowserAppCore::SetEnableCallback(const nsString& aScript)
{
mEnableScript = aScript;
return NS_OK;
@ -180,8 +217,56 @@ nsBrowserAppCore::SetContentWindow(nsIDOMWindow* aWin)
mContentWindow = aWin;
NS_ADDREF(aWin);
mContentScriptContext = GetScriptContext(aWin);
nsCOMPtr<nsIScriptGlobalObject> globalObj( mContentWindow );
if (!globalObj) {
return NS_ERROR_FAILURE;
}
return NS_OK;
nsIWebShell * webShell;
globalObj->GetWebShell(&webShell);
if (nsnull != webShell) {
webShell->SetObserver(this);
PRUnichar * name;
webShell->GetName( &name);
nsAutoString str(name);
printf("Attaching to Content WebShell [%s]\n", str.ToNewCString());
NS_RELEASE(webShell);
}
return NS_OK;
}
NS_IMETHODIMP
nsBrowserAppCore::SetWebShellWindow(nsIDOMWindow* aWin)
{
if (!mContentWindow) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIScriptGlobalObject> globalObj( aWin );
if (!globalObj) {
return NS_ERROR_FAILURE;
}
nsIWebShell * webShell;
globalObj->GetWebShell(&webShell);
if (nsnull != webShell) {
PRUnichar * name;
webShell->GetName( &name);
nsAutoString str(name);
printf("Attaching to WebShellWindow[%s]\n", str.ToNewCString());
nsIWebShellContainer * webShellContainer;
webShell->GetContainer(webShellContainer);
if (nsnull != webShellContainer) {
if (NS_OK == webShellContainer->QueryInterface(kIWebShellWindowIID, (void**) &mWebShellWin)) {
}
NS_RELEASE(webShellContainer);
}
NS_RELEASE(webShell);
}
return NS_OK;
}
@ -192,6 +277,7 @@ nsBrowserAppCore::ExecuteScript(nsIScriptContext * aContext, const nsString& aSc
const char* url = "";
PRBool isUndefined = PR_FALSE;
nsString rVal;
printf("Executing [%s]\n", aScript.ToNewCString());
aContext->EvaluateString(aScript, url, 0, rVal, &isUndefined);
}
return NS_OK;
@ -200,3 +286,183 @@ nsBrowserAppCore::ExecuteScript(nsIScriptContext * aContext, const nsString& aSc
NS_IMETHODIMP
nsBrowserAppCore::DoDialog()
{
nsresult rv;
nsString controllerCID;
char * urlstr=nsnull;
char * progname = nsnull;
char * width=nsnull, *height=nsnull;
char * iconic_state=nsnull;
nsIAppShellService* appShell = nsnull;
urlstr = "resource:/res/samples/Password.html";
/*
* Create the Application Shell instance...
*/
rv = nsServiceManager::GetService(kAppShellServiceCID,
kIAppShellServiceIID,
(nsISupports**)&appShell);
if (!NS_SUCCEEDED(rv)) {
goto done;
}
/*
* Initialize the Shell...
*/
rv = appShell->Initialize();
if (!NS_SUCCEEDED(rv)) {
goto done;
}
/*
* Post an event to the shell instance to load the AppShell
* initialization routines...
*
* This allows the application to enter its event loop before having to
* deal with GUI initialization...
*/
///write me...
nsIURL* url;
nsIWidget* newWindow;
rv = NS_NewURL(&url, urlstr);
if (NS_FAILED(rv)) {
goto done;
}
nsIWidget * parent;
mWebShellWin->GetWidget(parent);
/*
* XXX: Currently, the CID for the "controller" is passed in as an argument
* to CreateTopLevelWindow(...). Once XUL supports "controller"
* components this will be specified in the XUL description...
*/
controllerCID = "43147b80-8a39-11d2-9938-0080c7cb1081";
appShell->CreateDialogWindow(parent, url, controllerCID, newWindow, (nsIStreamObserver *)this);
newWindow->Resize(300, 200, PR_TRUE);
NS_RELEASE(url);
NS_RELEASE(parent);
/*
* Start up the main event loop...
*/
//rv = appShell->Run();
rv = NS_OK;
while (rv == NS_OK) {
void * data;
PRBool inWin;
PRBool isMouseEvent;
rv = appShell->GetNativeEvent(data, newWindow, inWin, isMouseEvent);
if (rv == NS_OK) {
printf("In win %d is mouse %d\n", inWin, isMouseEvent);
} else {
rv = NS_OK;
}
if (rv == NS_OK && (inWin || (!inWin && !isMouseEvent))) {
appShell->DispatchNativeEvent(data);
}
}
/*
* Shut down the Shell instance... This is done even if the Run(...)
* method returned an error.
*/
(void) appShell->Shutdown();
done:
/* Release the shell... */
if (nsnull != appShell) {
nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
}
return NS_OK;
}
NS_IMETHODIMP
nsBrowserAppCore::OnStartBinding(nsIURL* aURL, const char *aContentType)
{
nsresult rv = NS_OK;
printf("OnStartBinding\n");
return rv;
}
NS_IMETHODIMP
nsBrowserAppCore::OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax)
{
nsresult rv = NS_OK;
printf("OnStartBinding\n");
return rv;
}
NS_IMETHODIMP
nsBrowserAppCore::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
{
nsresult rv = NS_OK;
printf("OnStartBinding\n");
return rv;
}
NS_IMETHODIMP
nsBrowserAppCore::OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg)
{
nsresult rv = NS_OK;
printf("OnStartBinding\n");
return rv;
}
//----------------------------------------------------------------------
NS_IMETHODIMP_(void)
nsBrowserAppCore::Alert(const nsString &aText)
{
printf("Alert\n");
}
NS_IMETHODIMP_(PRBool)
nsBrowserAppCore::Confirm(const nsString &aText)
{
PRBool bResult = PR_FALSE;
printf("Confirm\n");
return bResult;
}
NS_IMETHODIMP_(PRBool)
nsBrowserAppCore::Prompt(const nsString &aText,
const nsString &aDefault,
nsString &aResult)
{
PRBool bResult = PR_FALSE;
printf("Prompt\n");
return bResult;
}
NS_IMETHODIMP_(PRBool)
nsBrowserAppCore::PromptUserAndPassword(const nsString &aText,
nsString &aUser,
nsString &aPassword)
{
PRBool bResult = PR_FALSE;
printf("PromptUserAndPassword\n");
DoDialog();
return bResult;
}
NS_IMETHODIMP_(PRBool)
nsBrowserAppCore::PromptPassword(const nsString &aText,
nsString &aPassword)
{
PRBool bResult = PR_FALSE;
printf("PromptPassword\n");
return bResult;
}

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

@ -26,18 +26,24 @@
#include "nsIDOMBrowserAppCore.h"
#include "nsBaseAppCore.h"
#include "nsINetSupport.h"
#include "nsIStreamObserver.h"
class nsIBrowserWindow;
class nsIWebShell;
class nsIScriptContext;
class nsIDOMWindow;
class nsIURL;
class nsIWebShellWindow;
////////////////////////////////////////////////////////////////////////////////
// nsBrowserAppCore:
////////////////////////////////////////////////////////////////////////////////
class nsBrowserAppCore : public nsBaseAppCore,
public nsIDOMBrowserAppCore
public nsIDOMBrowserAppCore,
public nsINetSupport,
public nsIStreamObserver
{
public:
@ -55,10 +61,34 @@ class nsBrowserAppCore : public nsBaseAppCore,
NS_IMETHOD LoadUrl(const nsString& aUrl);
NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin);
NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin);
NS_IMETHOD DisableCallback(const nsString& aScript);
NS_IMETHOD EnableCallback(const nsString& aScript);
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin);
NS_IMETHOD SetDisableCallback(const nsString& aScript);
NS_IMETHOD SetEnableCallback(const nsString& aScript);
// nsIStreamObserver
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
// nsINetSupport
NS_IMETHOD_(void) Alert(const nsString &aText);
NS_IMETHOD_(PRBool) Confirm(const nsString &aText);
NS_IMETHOD_(PRBool) Prompt(const nsString &aText,
const nsString &aDefault,
nsString &aResult);
NS_IMETHOD_(PRBool) PromptUserAndPassword(const nsString &aText,
nsString &aUser,
nsString &aPassword);
NS_IMETHOD_(PRBool) PromptPassword(const nsString &aText,
nsString &aPassword);
protected:
NS_IMETHOD DoDialog();
NS_IMETHOD ExecuteScript(nsIScriptContext * aContext, const nsString& aScript);
nsString mEnableScript;
@ -69,6 +99,8 @@ class nsBrowserAppCore : public nsBaseAppCore,
nsIDOMWindow *mToolbarWindow;
nsIDOMWindow *mContentWindow;
nsIWebShellWindow *mWebShellWin;
};
#endif // nsBrowserAppCore_h___

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

@ -317,14 +317,14 @@ BrowserAppCoreSetContentWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *
//
// Native method DisableCallback
// Native method SetWebShellWindow
//
PR_STATIC_CALLBACK(JSBool)
BrowserAppCoreDisableCallback(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
BrowserAppCoreSetWebShellWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMBrowserAppCore *nativeThis = (nsIDOMBrowserAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
nsIDOMWindowPtr b0;
*rval = JSVAL_NULL;
@ -335,16 +335,22 @@ BrowserAppCoreDisableCallback(JSContext *cx, JSObject *obj, uintN argc, jsval *a
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kIWindowIID,
"Window",
cx,
argv[0])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->DisableCallback(b0)) {
if (NS_OK != nativeThis->SetWebShellWindow(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function disableCallback requires 1 parameters");
JS_ReportError(cx, "Function setWebShellWindow requires 1 parameters");
return JS_FALSE;
}
@ -353,10 +359,10 @@ BrowserAppCoreDisableCallback(JSContext *cx, JSObject *obj, uintN argc, jsval *a
//
// Native method EnableCallback
// Native method SetDisableCallback
//
PR_STATIC_CALLBACK(JSBool)
BrowserAppCoreEnableCallback(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
BrowserAppCoreSetDisableCallback(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMBrowserAppCore *nativeThis = (nsIDOMBrowserAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
@ -373,14 +379,50 @@ BrowserAppCoreEnableCallback(JSContext *cx, JSObject *obj, uintN argc, jsval *ar
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (NS_OK != nativeThis->EnableCallback(b0)) {
if (NS_OK != nativeThis->SetDisableCallback(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function enableCallback requires 1 parameters");
JS_ReportError(cx, "Function setDisableCallback requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method SetEnableCallback
//
PR_STATIC_CALLBACK(JSBool)
BrowserAppCoreSetEnableCallback(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMBrowserAppCore *nativeThis = (nsIDOMBrowserAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (NS_OK != nativeThis->SetEnableCallback(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function setEnableCallback requires 1 parameters");
return JS_FALSE;
}
@ -425,8 +467,9 @@ static JSFunctionSpec BrowserAppCoreMethods[] =
{"loadUrl", BrowserAppCoreLoadUrl, 1},
{"setToolbarWindow", BrowserAppCoreSetToolbarWindow, 1},
{"setContentWindow", BrowserAppCoreSetContentWindow, 1},
{"disableCallback", BrowserAppCoreDisableCallback, 1},
{"enableCallback", BrowserAppCoreEnableCallback, 1},
{"setWebShellWindow", BrowserAppCoreSetWebShellWindow, 1},
{"setDisableCallback", BrowserAppCoreSetDisableCallback, 1},
{"setEnableCallback", BrowserAppCoreSetEnableCallback, 1},
{0}
};

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

@ -172,48 +172,6 @@ ToolbarCoreSetWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva
}
//
// Native method SetWebShellWindow
//
PR_STATIC_CALLBACK(JSBool)
ToolbarCoreSetWebShellWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMToolbarCore *nativeThis = (nsIDOMToolbarCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMWindowPtr b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kIWindowIID,
"Window",
cx,
argv[0])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->SetWebShellWindow(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function SetWebShellWindow requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method SetStatus
//
@ -283,7 +241,6 @@ static JSPropertySpec ToolbarCoreProperties[] =
static JSFunctionSpec ToolbarCoreMethods[] =
{
{"SetWindow", ToolbarCoreSetWindow, 1},
{"SetWebShellWindow", ToolbarCoreSetWebShellWindow, 1},
{"SetStatus", ToolbarCoreSetStatus, 1},
{0}
};

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

@ -26,6 +26,7 @@
#include "nsAppCoresManager.h"
#include "nsCOMPtr.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
#include "nsIScriptContext.h"
#include "nsIDOMDocument.h"
@ -34,9 +35,6 @@
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDOMCharacterData.h"
#include "nsIScriptGlobalObject.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
// Globals
@ -49,12 +47,6 @@ static NS_DEFINE_IID(kIDOMCharacterDataIID, nsIDOMCharacterData::IID());
static NS_DEFINE_IID(kToolbarCoreCID, NS_TOOLBARCORE_CID);
static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID);
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
static NS_DEFINE_IID(kIWebShellWindowIID, NS_IWEBSHELL_WINDOW_IID);
/////////////////////////////////////////////////////////////////////////
// nsToolbarCore
/////////////////////////////////////////////////////////////////////////
@ -65,7 +57,6 @@ nsToolbarCore::nsToolbarCore()
mWindow = nsnull;
mStatusText = nsnull;
mWebShellWin = nsnull;
IncInstanceCount();
NS_INIT_REFCNT();
@ -74,7 +65,6 @@ nsToolbarCore::nsToolbarCore()
nsToolbarCore::~nsToolbarCore()
{
NS_IF_RELEASE(mWindow);
NS_IF_RELEASE(mWebShellWin);
NS_IF_RELEASE(mStatusText);
DecInstanceCount();
}
@ -99,17 +89,6 @@ nsToolbarCore::QueryInterface(REFNSIID aIID,void** aInstancePtr)
AddRef();
return NS_OK;
}
if (aIID.Equals(kINetSupportIID)) {
*aInstancePtr = (void*) ((nsINetSupport*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIStreamObserverIID)) {
*aInstancePtr = (void*) ((nsIStreamObserver*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return nsBaseAppCore::QueryInterface(aIID, aInstancePtr);
}
@ -177,7 +156,6 @@ nsToolbarCore::SetStatus(const nsString& aMsg)
}
mStatusText->SetData(aMsg); */
DoDialog();
return NS_OK;
}
@ -187,31 +165,6 @@ nsToolbarCore::SetWebShellWindow(nsIDOMWindow* aWin)
{
mWindow = aWin;
NS_ADDREF(aWin);
nsCOMPtr<nsIScriptGlobalObject> globalObj( mWindow );
if (!globalObj) {
return NS_ERROR_FAILURE;
}
nsIWebShell * webShell;
globalObj->GetWebShell(&webShell);
if (nsnull != webShell) {
webShell->SetObserver(this);
PRUnichar * name;
webShell->GetName( &name);
nsAutoString str(name);
printf("attaching to [%s]\n", str.ToNewCString());
nsIWebShellContainer * webShellContainer;
webShell->GetContainer(webShellContainer);
if (nsnull != webShellContainer) {
if (NS_OK == webShellContainer->QueryInterface(kIWebShellWindowIID, (void**) &mWebShellWin)) {
}
NS_RELEASE(webShellContainer);
}
NS_RELEASE(webShell);
}
return NS_OK;
}
@ -220,245 +173,6 @@ nsToolbarCore::SetWindow(nsIDOMWindow* aWin)
{
mWindow = aWin;
NS_ADDREF(aWin);
nsCOMPtr<nsIScriptGlobalObject> globalObj( mWindow );
if (!globalObj) {
return NS_ERROR_FAILURE;
}
nsIWebShell * webShell;
globalObj->GetWebShell(&webShell);
if (nsnull != webShell) {
webShell->SetObserver(this);
PRUnichar * name;
webShell->GetName( &name);
nsAutoString str(name);
printf("attaching to [%s]\n", str.ToNewCString());
NS_RELEASE(webShell);
}
/* nsCOMPtr<nsIDOMNode> oldNode( node );
oldNode->GetNextSibling(getter_AddRefs(node));
nsCOMPtr<nsIDOMDocument> domDoc; // result == nsnull;
// first get the toolbar child WebShell
nsCOMPtr<nsIWebShell> childWebShell;
mWebShell->FindChildWithName(aWebShellName, *getter_AddRefs(childWebShell));
if (!childWebShell)
return domDoc;
nsCOMPtr<nsIContentViewer> cv;
childWebShell->GetContentViewer(getter_AddRefs(cv));
if (!cv)
return domDoc;
nsCOMPtr<nsIDocumentViewer> docv(cv);
if (!docv)
return domDoc;
nsCOMPtr<nsIDocument> doc;
docv->GetDocument(*getter_AddRefs(doc));
if (doc)
return nsCOMPtr<nsIDOMDocument>(doc);
return domDoc;*/
return NS_OK;
}
#include "nsIServiceManager.h"
#include "nsIURL.h"
#include "nsIWidget.h"
#include "plevent.h"
#include "nsIAppShell.h"
#include "nsIAppShellService.h"
#include "nsAppShellCIDs.h"
/* Define Class IDs */
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
/* Define Interface IDs */
static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID);
NS_IMETHODIMP
nsToolbarCore::DoDialog()
{
nsresult rv;
nsString controllerCID;
char * urlstr=nsnull;
char * progname = nsnull;
char * width=nsnull, *height=nsnull;
char * iconic_state=nsnull;
nsIAppShellService* appShell = nsnull;
urlstr = "resource:/res/samples/Password.html";
/*
* Create the Application Shell instance...
*/
rv = nsServiceManager::GetService(kAppShellServiceCID,
kIAppShellServiceIID,
(nsISupports**)&appShell);
if (!NS_SUCCEEDED(rv)) {
goto done;
}
/*
* Initialize the Shell...
*/
rv = appShell->Initialize();
if (!NS_SUCCEEDED(rv)) {
goto done;
}
/*
* Post an event to the shell instance to load the AppShell
* initialization routines...
*
* This allows the application to enter its event loop before having to
* deal with GUI initialization...
*/
///write me...
nsIURL* url;
nsIWidget* newWindow;
rv = NS_NewURL(&url, urlstr);
if (NS_FAILED(rv)) {
goto done;
}
nsIWidget * parent;
mWebShellWin->GetWidget(parent);
/*
* XXX: Currently, the CID for the "controller" is passed in as an argument
* to CreateTopLevelWindow(...). Once XUL supports "controller"
* components this will be specified in the XUL description...
*/
controllerCID = "43147b80-8a39-11d2-9938-0080c7cb1081";
appShell->CreateDialogWindow(parent, url, controllerCID, newWindow, (nsIStreamObserver *)this);
NS_RELEASE(url);
NS_RELEASE(parent);
/*
* Start up the main event loop...
*/
//rv = appShell->Run();
rv = NS_OK;
while (rv == NS_OK) {
void * data;
PRBool inWin;
PRBool isMouseEvent;
rv = appShell->GetNativeEvent(data, newWindow, inWin, isMouseEvent);
if (rv == NS_OK) {
printf("In win %d is mouse %d\n", inWin, isMouseEvent);
} else {
rv = NS_OK;
}
if (rv == NS_OK && (inWin || (!inWin && !isMouseEvent))) {
appShell->DispatchNativeEvent(data);
}
}
/*
* Shut down the Shell instance... This is done even if the Run(...)
* method returned an error.
*/
(void) appShell->Shutdown();
done:
/* Release the shell... */
if (nsnull != appShell) {
nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
}
return NS_OK;
}
NS_IMETHODIMP
nsToolbarCore::OnStartBinding(nsIURL* aURL, const char *aContentType)
{
nsresult rv = NS_OK;
printf("OnStartBinding\n");
return rv;
}
NS_IMETHODIMP
nsToolbarCore::OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax)
{
nsresult rv = NS_OK;
printf("OnStartBinding\n");
return rv;
}
NS_IMETHODIMP
nsToolbarCore::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
{
nsresult rv = NS_OK;
printf("OnStartBinding\n");
return rv;
}
NS_IMETHODIMP
nsToolbarCore::OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg)
{
nsresult rv = NS_OK;
printf("OnStartBinding\n");
return rv;
}
//----------------------------------------------------------------------
NS_IMETHODIMP_(void)
nsToolbarCore::Alert(const nsString &aText)
{
printf("Alert\n");
}
NS_IMETHODIMP_(PRBool)
nsToolbarCore::Confirm(const nsString &aText)
{
PRBool bResult = PR_FALSE;
printf("Confirm\n");
return bResult;
}
NS_IMETHODIMP_(PRBool)
nsToolbarCore::Prompt(const nsString &aText,
const nsString &aDefault,
nsString &aResult)
{
PRBool bResult = PR_FALSE;
printf("Prompt\n");
return bResult;
}
NS_IMETHODIMP_(PRBool)
nsToolbarCore::PromptUserAndPassword(const nsString &aText,
nsString &aUser,
nsString &aPassword)
{
PRBool bResult = PR_FALSE;
printf("PromptUserAndPassword\n");
DoDialog();
return bResult;
}
NS_IMETHODIMP_(PRBool)
nsToolbarCore::PromptPassword(const nsString &aText,
nsString &aPassword)
{
PRBool bResult = PR_FALSE;
printf("PromptPassword\n");
return bResult;
}

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

@ -27,8 +27,6 @@
#include "nsIDOMToolbarCore.h"
#include "nsBaseAppCore.h"
#include "nsINetSupport.h"
#include "nsIStreamObserver.h"
class nsIBrowserWindow;
class nsIWebShell;
@ -36,16 +34,13 @@ class nsIScriptContext;
class nsIDOMWindow;
class nsIDOMDocument;
class nsIDOMCharacterData;
class nsIWebShellWindow;
////////////////////////////////////////////////////////////////////////////////
// nsToolbarCore:
////////////////////////////////////////////////////////////////////////////////
class nsToolbarCore : public nsBaseAppCore,
public nsIDOMToolbarCore,
public nsINetSupport,
public nsIStreamObserver
public nsIDOMToolbarCore
{
public:
@ -62,33 +57,9 @@ class nsToolbarCore : public nsBaseAppCore,
NS_IMETHOD SetWebShellWindow(nsIDOMWindow* aWin);
NS_IMETHOD SetStatus(const nsString& aMsg);
// nsIStreamObserver
NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
// nsINetSupport
NS_IMETHOD_(void) Alert(const nsString &aText);
NS_IMETHOD_(PRBool) Confirm(const nsString &aText);
NS_IMETHOD_(PRBool) Prompt(const nsString &aText,
const nsString &aDefault,
nsString &aResult);
NS_IMETHOD_(PRBool) PromptUserAndPassword(const nsString &aText,
nsString &aUser,
nsString &aPassword);
NS_IMETHOD_(PRBool) PromptPassword(const nsString &aText,
nsString &aPassword);
private:
NS_IMETHOD DoDialog();
nsIDOMWindow *mWindow;
nsIWebShellWindow *mWebShellWin;
nsIDOMCharacterData *mStatusText;
};

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

@ -1,138 +0,0 @@
<html>
<head>
<script LANGUAGE="JavaScript">
<!--
function SendMailMessage()
{
var appCore = AppCoresManager.Find("MailCore");
if (appCore==null) {
appCore = new MailCore();
if (appCore != null) {
appCore.Init("MailCore");
appCore.MailCompleteCallback("MailSent()");
appCore.SetWindow(window);
appCore.SendMail(document.forms[0].elements[1].value, document.forms[0].elements[2].value, document.forms[0].elements[4].value);
}
} else {
appCore.SendMail(document.forms[0].elements[1].value, document.forms[0].elements[2].value, document.forms[0].elements[4].value);
}
appCore = AppCoresManager.Find("ToolbarCore");
if (appCore==null) {
appCore = new ToolbarCore();
if (appCore != null) {
appCore.Init("ToolbarCore");
appCore.SetWindow(window.parent.frames[2]);
appCore.SetStatus("Mail was Sent!");
} else {
}
} else {
appCore.SetStatus("Mail was Sent!");
}
}
function MailSent()
{
// Clear Them
document.forms[0].elements[1].value = "";
document.forms[0].elements[2].value = "";
document.forms[0].elements[4].value = "";
/*dump("top name: "+top.name+"\n");
if (window.parent.frames[2] != null) {
dump("frame[2] name: "+window.parent.frames[2].name+"\n");
var parent = window.parent.frames[0].parent;
dump("parent name: "+parent.name+"\n");
var doc = window.parent.frames[2].document;
var win = window.parent.frames[2];
if (doc != null) {
//dump("Doc name: "+doc.name);
doc.elements[8].value = "xxxxxx";
} else {
dump("doc was null\n");
}
} else {
dump("parent is null\n");
}*/
}
// End -->
</script>
<style type="text/css">
/* This style sheet should be in a seperate file */
FIELDSET {
background-color: rgb(192, 192, 192);
border: 2px groove rgb(192, 192, 192);
display: inline;
margin-left: 10px;
padding: 2px;
}
LEGEND {
background-color:rgb(192, 192, 192);
border: none ;
padding: 2px;
}
BODY,TD {
font-family: Sans-Serif;
background-color: #C0C0C0;
}
LABEL {
background-color: #C0C0C0;
margin: 0px 0px 0px 0px;
padding-left: 0px;
padding-right: 0px;
}
BODY,TD,INPUT {
font-size: 9pt;
}
BODY {
margin: 0px 0px 0px 0px;
}
</style>
</head>
<body>
<center>
<p><form ENCTYPE="text/plain" onSubmit="return submitForms()"></center>
<TABLE bgcolor="#C0C0C0">
<TR>
<TD>
<fieldset width="100%" height="100%" >
<legend align=left>&nbsp;Info&nbsp;</legend>
<TABLE width="100%" height="100%">
<TR>
<TD>Address:</TD>
<TD width="100%"><input type="text" name="addrTo" ></TD>
</TR>
<TR>
<TD>Subject:</TD>
<TD><input type="text" name="subject" id="subject"></TD>
</TR>
</TABLE>
</fieldset>
</TD>
</TR>
<TR>
<TD>
<fieldset width="100%" height="100%" >
<legend align=left>&nbsp;Message&nbsp;</legend>
<TEXTAREA cols=40 rows=20 name="mailbody"></TEXTAREA>
</fieldset>
</TD>
</TR></TABLE>
</form>
</center>
</body>
</html>

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

@ -4,6 +4,54 @@
<?xml-stylesheet href="xul.css" type="text/css"?>
<!DOCTYPE window>
<script LANGUAGE="JavaScript">
function SendMailMessage()
{
var appCore = AppCoresManager.Find("MailCore");
if (appCore==null) {
appCore = new MailCore();
if (appCore != null) {
appCore.Init("MailCore");
appCore.MailCompleteCallback("MailSent()");
appCore.SetWindow(window);
appCore.SendMail(document.forms[0].elements[1].value, document.forms[0].elements[2].value, document.forms[0].elements[4].value);
}
} else {
appCore.SendMail(document.forms[0].elements[1].value, document.forms[0].elements[2].value, document.forms[0].elements[4].value);
}
}
function MailSent()
{
// Clear Them
document.forms[0].elements[1].value = "";
document.forms[0].elements[2].value = "";
document.forms[0].elements[4].value = "";
/*dump("top name: "+top.name+"\n");
if (window.parent.frames[2] != null) {
dump("frame[2] name: "+window.parent.frames[2].name+"\n");
var parent = window.parent.frames[0].parent;
dump("parent name: "+parent.name+"\n");
var doc = window.parent.frames[2].document;
var win = window.parent.frames[2];
if (doc != null) {
//dump("Doc name: "+doc.name);
doc.elements[8].value = "xxxxxx";
} else {
dump("doc was null\n");
}
} else {
dump("parent is null\n");
}*/
}
</script>
<window>
<xul:commands>
<xul:command name="nsCmd:MailSendMsg" onCommand="SendMailMessage()"/>

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

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

@ -6,4 +6,5 @@ nsAppShellCIDs.h
nsIAppShellService.h
nsICmdLineService.h
nsIWebShellWindow.h
nsIXULCommand.h
nsIWidgetController.h

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

@ -24,10 +24,11 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
EXPORTS = \
nsIXULCommand.h \
nsIWebShellWindow.h \
nsAppShellCIDs.h \
nsIAppShellService.h \
nsICmdLineService.h \
nsICmdLineService.h \
nsIWidgetController.h \
$(NULL)

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

@ -23,6 +23,7 @@ MODULE=raptor
EXPORTS = \
nsIWebShellWindow.h \
nsIXULCommand.h \
nsAppShellCIDs.h \
nsIAppShellService.h \
nsICmdLineService.h \

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

@ -0,0 +1,150 @@
/* -*- 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.
*/
#ifndef nsIXULCommand_h___
#define nsIXULCommand_h___
#include "nsString.h"
#include "nsIDOMElement.h"
#include "nsIWebShell.h"
class nsIDOMNode;
class nsIFactory;
// Interface ID for nsIXULCommand
#define NS_IXULCOMMAND_IID \
{ 0xabf645a1, 0xb3d0, 0x11d2, { 0x9a, 0x42, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74}}
// Class ID for an implementation of nsIXULCommand
#define NS_XULCOMMAND_CID \
{ 0xabf645a1, 0xb3d0, 0x11d2, { 0x9a, 0x42, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74}}
//----------------------------------------------------------------------
class nsIXULCommand : public nsISupports {
public:
/**
* Adds a source widget/DOMNode to the command
* @param aNode the DOM node to be added
* @return NS_OK if there was an node was added otherwise NS_ERROR_FAILURE
*/
NS_IMETHOD AddUINode(nsIDOMNode * aNode) = 0;
/**
* Removes a source widget/DOMNode from the command
* @param aNode the DOM node to be remove
* @return NS_OK if there was an node was remove otherwise NS_ERROR_FAILURE
*/
NS_IMETHOD RemoveUINode(nsIDOMNode * aCmd) = 0;
/**
* Sets the name of the command
* @param aName the name of the command
* @return NS_OK
*/
NS_IMETHOD SetName(const nsString &aName) = 0;
/**
* Gets the name of the command
* @param aName the name of the command
* @return NS_OK
*/
NS_IMETHOD GetName(nsString &aName) const = 0;
/**
* Sets the command to be enabled/disabled, this then sets all the Source DOMNodes
* and the corresponding widgets/controls to enabled/disabled
* @param aIsEnabled the new enabled/disabled state
* @return NS_OK
*/
NS_IMETHOD SetEnabled(PRBool aIsEnabled) = 0;
/**
* Returns whether the command is enabled or not
* @param aIsEnabled the out parameter with the new enabled/disabled state
* @return NS_OK
*/
NS_IMETHOD GetEnabled(PRBool & aIsEnabled) = 0;
/**
* Sets the JavaScript Command to be invoked when a "gui" event occurs on a source widget
* @param aStrCmd the JS command to be cached for later execution
* @return NS_OK
*/
NS_IMETHOD SetCommand(const nsString & aStrCmd) = 0;
/**
* Executes the "cached" JavaScript Command
* @return NS_OK if the command was executed properly, otherwise an error code
*/
NS_IMETHOD DoCommand() = 0;
/**
* Sets the Tooltip of the command
* @param aTip the Tooltip of the command
* @return NS_OK
*/
NS_IMETHOD SetTooltip(const nsString &aTip) = 0;
/**
* Gets the Tooltip of the command
* @param aTip the Tooltip of the command
* @return NS_OK
*/
NS_IMETHOD GetTooltip(nsString &aTip) const = 0;
/**
* Sets the description of the command
* @param aDescription the description of the command
* @return NS_OK
*/
NS_IMETHOD SetDescription(const nsString &aDescription) = 0;
/**
* Gets the description of the command
* @param aDescription the description of the command
* @return NS_OK
*/
NS_IMETHOD GetDescription(nsString &aDescription) const = 0;
// Some of the originally specific methods
/*
NS_IMETHOD Create();
NS_IMETHOD Destroy();
NS_IMETHOD AddOriginatingWidget(const nsIFrame *aWidget);
NS_IMETHOD RemoveOriginatingWidget(nsIFrame *aWidget);
NS_IMETHOD SetSelected(PRBool aSelected);
NS_IMETHOD GetSelected(PRBool *aSelected) const;
*/
/* DO NOT CALL THESE METHODS
* These are here as a temporary hack - cps
*/
NS_IMETHOD SetDOMElement(nsIDOMElement * aDOMNode) = 0;
NS_IMETHOD SetWebShell(nsIWebShell * aWebShell) = 0;
};
extern "C" nsresult
NS_NewXULCommandFactory(nsIFactory** aFactory);
#endif /* nsIXULCommand_h___ */

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

@ -28,6 +28,7 @@ LIBRARY_NAME = nsappshell
MODULE=raptor
CPPSRCS= \
nsXULCommand.cpp \
nsAppShellService.cpp \
nsWebShellWindow.cpp \
nsAppShellFactory.cpp \

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

@ -22,6 +22,7 @@ DEFINES=-D_IMPL_NS_APPSHELL -DWIN32_LEAN_AND_MEAN
MODULE=raptor
CPPSRCS= \
nsXULCommand.cpp \
nsAppShellService.cpp \
nsWebShellWindow.cpp \
nsAppShellFactory.cpp \
@ -29,6 +30,7 @@ CPPSRCS= \
$(NULL)
CPP_OBJS= \
.\$(OBJDIR)\nsXULCommand.obj \
.\$(OBJDIR)\nsAppShellService.obj \
.\$(OBJDIR)\nsWebShellWindow.obj \
.\$(OBJDIR)\nsAppShellFactory.obj \

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

@ -34,7 +34,7 @@
#include "nsAppShellCIDs.h"
#include "nsIXULCommand.h"
//#include "nsXULCommand.h"
#include "nsXULCommand.h"
#include "nsIDOMCharacterData.h"
#include "nsIMenuBar.h"
@ -453,7 +453,7 @@ void nsWebShellWindow::LoadCommands(nsIWebShell * aWebShell, nsIDOMDocument * aD
element->GetAttribute(nsAutoString("name"), name);
element->GetAttribute(nsAutoString("onCommand"), value);
nsIXULCommand * xulCmdInterface = nsnull;
/*nsIXULCommand * xulCmdInterface = nsnull;
rv = nsRepository::CreateInstance(kXULCommandCID, nsnull, kIXULCommandIID,
(void**)&xulCmdInterface);
if (NS_OK == rv) {
@ -462,9 +462,9 @@ void nsWebShellWindow::LoadCommands(nsIWebShell * aWebShell, nsIDOMDocument * aD
xulCmdInterface->SetWebShell(aWebShell);// Added to nsIXULCommand
xulCmdInterface->SetDOMElement(element);// Added to nsIXULCommand
mCommands.AppendElement(xulCmdInterface);
}
}*/
/*
nsXULCommand * xulCmd = new nsXULCommand();
xulCmd->SetName(name);//nsIXULCommand
xulCmd->SetCommand(value);//nsIXULCommand
@ -474,7 +474,7 @@ void nsWebShellWindow::LoadCommands(nsIWebShell * aWebShell, nsIDOMDocument * aD
if (NS_OK == xulCmd->QueryInterface(kIXULCommandIID, (void**) &icmd)) {
mCommands.AppendElement(icmd);
}
*/
//printf("Commands[%s] value[%s]\n", nsAutoCString(name), nsAutoCString(value));
}
}
@ -502,7 +502,7 @@ void nsWebShellWindow::LoadCommands(nsIWebShell * aWebShell, nsIDOMDocument * aD
if (name.Equals(nsAutoString("BUTTON")))
ConnectCommandToOneGUINode(node, element, name);
else if (name.Equals(nsAutoString("INPUT"))) {
nsIXULCommand * xulCmdInterface = nsnull;
/*nsIXULCommand * xulCmdInterface = nsnull;
rv = nsRepository::CreateInstance(kXULCommandCID, nsnull, kIXULCommandIID,
(void**)&xulCmdInterface);
if (NS_OK == rv) {
@ -514,8 +514,8 @@ void nsWebShellWindow::LoadCommands(nsIWebShell * aWebShell, nsIDOMDocument * aD
mCommands.AppendElement(xulCmdInterface);
xulCmdInterface->AddUINode(node);
}
/*
}*/
nsXULCommand * xulCmd = new nsXULCommand();
xulCmd->SetName(name);
xulCmd->SetCommand(value);
@ -526,7 +526,7 @@ void nsWebShellWindow::LoadCommands(nsIWebShell * aWebShell, nsIDOMDocument * aD
mCommands.AppendElement(icmd);
}
xulCmd->AddUINode(node);
*/
//printf("Linking cmd to button [%s]\n", nsAutoCString(cmdName));
}
}
@ -543,10 +543,14 @@ void nsWebShellWindow::LoadCommands(nsIWebShell * aWebShell, nsIDOMDocument * aD
// Enable All Command
PRInt32 i, n = mCommands.Count();
for (i = 0; i < n; i++) {
nsIXULCommand* cmd = (nsIXULCommand*) mCommands.ElementAt(i);
nsXULCommand* cmd = (nsXULCommand*) mCommands.ElementAt(i);
cmd->SetEnabled(PR_TRUE);
}
//SetCommandEnabled(nsAutoString("nsCmd:BrowserStop"), PR_FALSE);
nsCOMPtr<nsIXULCommand> cmd(FindCommandByName(nsAutoString("nsCmd:StartUp")));
if (cmd) {
cmd->DoCommand();
}
UpdateButtonStatus(PR_FALSE);
}
@ -851,8 +855,8 @@ NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete()
nsCOMPtr<nsIDOMNode> parent(GetParentNodeFromDOMDoc(toolbarDOMDoc));
if (!parent)
return NS_ERROR_FAILURE;
LoadCommands(contentWebShell, toolbarDOMDoc);
//LoadCommands(toolbarWebShell, toolbarDOMDoc);
//LoadCommands(contentWebShell, toolbarDOMDoc);
LoadCommands(toolbarWebShell, toolbarDOMDoc);
PRInt32 count = 0;
nsCOMPtr<nsIDOMNode> imgNode(FindNamedDOMNode(nsAutoString("IMG"), parent, count, 7));

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

@ -0,0 +1,480 @@
/* -*- 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 "nsIDOMNode.h"
#include "nsIDOMEvent.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLButtonElement.h"
// FOr JS Execution
#include "nsIScriptContextOwner.h"
#include "nsRepository.h"
#include "nsXULCommand.h"
#define DEBUGCMDS 0
//----------------------------------------------------------------------
// Class IID's
static NS_DEFINE_IID(kXULCommandCID, NS_XULCOMMAND_CID);
// IID's
static NS_DEFINE_IID(kIXULCommandIID, NS_IXULCOMMAND_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLButtonElement, NS_IDOMHTMLBUTTONELEMENT_IID);
static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID);
//----------------------------------------------------------------------
nsXULCommand::nsXULCommand()
{
NS_INIT_REFCNT();
mIsEnabled = PR_FALSE;
}
//----------------------------------------------------------------------
nsXULCommand::~nsXULCommand()
{
while (mSrcWidgets.Count() > 0) {
nsCOMPtr<nsIDOMNode> node = dont_AddRef(NS_STATIC_CAST(nsIDOMNode*,mSrcWidgets.ElementAt(0)));
mSrcWidgets.RemoveElementAt(0);
}
}
NS_IMPL_ADDREF(nsXULCommand)
NS_IMPL_RELEASE(nsXULCommand)
//----------------------------------------------------------------------
nsresult
nsXULCommand::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
nsresult rv = NS_NOINTERFACE;
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIXULCommandIID)) {
*aInstancePtr = (void*)(nsIXULCommand*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMMouseListenerIID)) {
NS_ADDREF_THIS(); // Increase reference count for caller
*aInstancePtr = (void *)((nsIDOMMouseListener*)this);
return NS_OK;
}
if (aIID.Equals(kIDOMKeyListenerIID)) {
NS_ADDREF_THIS(); // Increase reference count for caller
*aInstancePtr = (void *)((nsIDOMKeyListener*)this);
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*)(nsISupports*)(nsIXULCommand*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return rv;
}
// XUL UI Objects
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::SetName(const nsString &aName)
{
mName = aName;
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::GetName(nsString &aName) const
{
aName = mName;
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::AddUINode(nsIDOMNode * aNode)
{
NS_PRECONDITION(nsnull != aNode, "adding event listener to null node");
nsCOMPtr<nsIDOMEventReceiver> receiver ( aNode );
if ( receiver ) {
receiver->AddEventListener((nsIDOMMouseListener*)this, kIDOMMouseListenerIID);
receiver->AddEventListener((nsIDOMKeyListener*)this, kIDOMKeyListenerIID);
mSrcWidgets.AppendElement(aNode);
NS_ADDREF(aNode);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::RemoveUINode(nsIDOMNode * aCmd)
{
PRInt32 index = mSrcWidgets.IndexOf(aCmd);
if (index > 0) {
mSrcWidgets.RemoveElementAt(index);
}
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::SetEnabled(PRBool aIsEnabled)
{
mIsEnabled = aIsEnabled;
PRInt32 i, n = mSrcWidgets.Count();
for (i = 0; i < n; i++) {
nsCOMPtr<nsIDOMNode> node = dont_AddRef(NS_STATIC_CAST(nsIDOMNode*,mSrcWidgets.ElementAt(i)));
nsCOMPtr<nsIDOMHTMLInputElement> input ( node );
//*** rewrite this part to set an attribute on a nsIDOMElement
if ( input ) {
input->SetDisabled(aIsEnabled);
} else {
nsCOMPtr<nsIDOMHTMLButtonElement> btn ( node );
if ( btn )
btn->SetDisabled(!aIsEnabled);
}
//***
}
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::GetEnabled(PRBool & aIsEnabled)
{
//*** rewrite this part to get an attribute on a nsIDOMElement
aIsEnabled = mIsEnabled;
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::SetCommand(const nsString & aStrCmd)
{
mCommandStr = aStrCmd;
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::DoCommand()
{
PRUnichar * name;
mWebShell->GetName( &name);
nsAutoString str(name);
if (DEBUGCMDS) printf("DoCommand - mWebShell is [%s] 0x%x\n", str.ToNewCString(), mWebShell);
return ExecuteJavaScriptString(mWebShell, mCommandStr);
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::SetWebShell(nsIWebShell * aWebShell)
{
mWebShell = aWebShell;
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::SetDOMElement(nsIDOMElement * aDOMElement)
{
mDOMElement = aDOMElement;
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::ExecuteJavaScriptString(nsIWebShell* aWebShell, nsString& aJavaScript)
{
if (0 == aJavaScript.Length()) {
return NS_ERROR_FAILURE;
}
nsresult status;
NS_ASSERTION(nsnull != aWebShell, "null webshell passed to EvaluateJavaScriptString");
// Get nsIScriptContextOwner
nsCOMPtr<nsIScriptContextOwner> scriptContextOwner ( aWebShell );
if ( scriptContextOwner ) {
const char* url = "";
// Get nsIScriptContext
nsCOMPtr<nsIScriptContext> scriptContext;
status = scriptContextOwner->GetScriptContext(getter_AddRefs(scriptContext));
if (NS_OK == status) {
// Ask the script context to evalute the javascript string
PRBool isUndefined = PR_FALSE;
nsString rVal("xxx");
scriptContext->EvaluateString(aJavaScript, url, 0, rVal, &isUndefined);
if (DEBUGCMDS) printf("EvaluateString - %d [%s]\n", isUndefined, rVal.ToNewCString());
}
}
return status;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::SetTooltip(const nsString &aTip)
{
mTooltip = aTip;
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::GetTooltip(nsString &aTip) const
{
aTip = mTooltip;
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::SetDescription(const nsString &aDescription)
{
mDescription = aDescription;
return NS_OK;
}
//----------------------------------------------------------------------
NS_IMETHODIMP nsXULCommand::GetDescription(nsString &aDescription) const
{
aDescription = mDescription;
return NS_OK;
}
//-----------------------------------------------------------------
//-- nsIDOMMouseListener
//-----------------------------------------------------------------
//-----------------------------------------------------------------
nsresult nsXULCommand::ProcessEvent(nsIDOMEvent* aEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXULCommand::MouseUp(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXULCommand::MouseDown(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXULCommand::MouseClick(nsIDOMEvent* aMouseEvent)
{
if (DEBUGCMDS) printf("Executing [%s]\n", mCommandStr.ToNewCString());
if (mIsEnabled) {
DoCommand();
}
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXULCommand::MouseDblClick(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXULCommand::MouseOver(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXULCommand::MouseOut(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
//-----------------------------------------------------------------
//-----------------------------------------------------------------
// nsIDOMKeyListener
//-----------------------------------------------------------------
nsresult nsXULCommand::KeyDown(nsIDOMEvent* aKeyEvent)
{
PRUint32 type;
aKeyEvent->GetKeyCode(&type);
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXULCommand::KeyUp(nsIDOMEvent* aKeyEvent)
{
PRUint32 type;
aKeyEvent->GetKeyCode(&type);
if (nsIDOMEvent::VK_RETURN != type) {
return NS_OK;
}
nsCOMPtr<nsIDOMHTMLInputElement> input ( mDOMElement );
if ( input ) {
nsAutoString value;
input->GetValue(value);
//printf("Value [%s]\n", value.ToNewCString());
mWebShell->LoadURL(value);
}
return NS_OK;
}
//-----------------------------------------------------------------
nsresult nsXULCommand::KeyPress(nsIDOMEvent* aKeyEvent)
{
return NS_OK;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------
// Factory code for creating nsXULCommand's
class nsXULCommandFactory : public nsIFactory
{
public:
nsXULCommandFactory();
virtual ~nsXULCommandFactory();
// nsISupports methods
NS_IMETHOD QueryInterface(const nsIID &aIID, void **aResult);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
private:
nsrefcnt mRefCnt;
};
nsXULCommandFactory::nsXULCommandFactory()
{
mRefCnt = 0;
}
nsXULCommandFactory::~nsXULCommandFactory()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
nsresult
nsXULCommandFactory::QueryInterface(const nsIID &aIID, void **aResult)
{
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aResult = NULL;
if (aIID.Equals(kISupportsIID)) {
*aResult = (void *)(nsISupports*)this;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = (void *)(nsIFactory*)this;
}
if (*aResult == NULL) {
return NS_NOINTERFACE;
}
NS_ADDREF_THIS(); // Increase reference count for caller
return NS_OK;
}
nsrefcnt
nsXULCommandFactory::AddRef()
{
return ++mRefCnt;
}
nsrefcnt
nsXULCommandFactory::Release()
{
if (--mRefCnt == 0) {
delete this;
return 0; // Don't access mRefCnt after deleting!
}
return mRefCnt;
}
nsresult
nsXULCommandFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
nsresult rv;
nsXULCommand *inst;
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
if (nsnull != aOuter) {
rv = NS_ERROR_NO_AGGREGATION;
goto done;
}
NS_NEWXPCOM(inst, nsXULCommand);
if (inst == NULL) {
rv = NS_ERROR_OUT_OF_MEMORY;
goto done;
}
NS_ADDREF(inst);
rv = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
done:
return rv;
}
nsresult
nsXULCommandFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
extern "C" nsresult
NS_NewXULCommandFactory(nsIFactory** aFactory)
{
nsresult rv = NS_OK;
nsIFactory* inst = new nsXULCommandFactory();
if (nsnull == inst) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
NS_ADDREF(inst);
}
*aFactory = inst;
return rv;
}

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

@ -0,0 +1,109 @@
/* -*- 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.
*/
#ifndef nsXULCommand_h__
#define nsXULCommand_h__
#include "nsIXULCommand.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsVoidArray.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsIDOMElement.h" // for some older c++ compilers.
#include "nsIWebShell.h" // for some older c++ compilers.
#include "nsCOMPtr.h"
// Forward Declarations
class nsIDOMNode;
class nsIDOMEvent;
//----------------------------------------------------------------------
class nsXULCommand : public nsIXULCommand,
public nsIDOMMouseListener,
public nsIDOMKeyListener
{
public:
nsXULCommand();
virtual ~nsXULCommand();
// nsISupports
NS_DECL_ISUPPORTS
// XUL UI Objects
NS_IMETHOD SetName(const nsString &aName);
NS_IMETHOD GetName(nsString &aName) const;
NS_IMETHOD AddUINode(nsIDOMNode * aNode);
NS_IMETHOD RemoveUINode(nsIDOMNode * aCmd);
NS_IMETHOD SetEnabled(PRBool aIsEnabled);
NS_IMETHOD GetEnabled(PRBool & aIsEnabled);
NS_IMETHOD SetTooltip(const nsString &aTip);
NS_IMETHOD GetTooltip(nsString &aTip) const;
NS_IMETHOD SetDescription(const nsString &aDescription);
NS_IMETHOD GetDescription(nsString &aDescription) const;
NS_IMETHOD DoCommand();
// Non-Interface Methods
NS_IMETHOD SetDOMElement(nsIDOMElement * aDOMNode);
NS_IMETHOD SetWebShell(nsIWebShell * aWebShell);
NS_IMETHOD SetCommand(const nsString & aStrCmd);
// nsIDOMEventListener
virtual nsresult ProcessEvent(nsIDOMEvent* aEvent);
// nsIDOMMouseListener (is derived from nsIDOMEventListener)
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent);
// nsIDOMKeyListener
virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent);
virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent);
virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent);
protected:
NS_IMETHOD ExecuteJavaScriptString(nsIWebShell* aWebShell, nsString& aJavaScript);
nsString mName;
nsString mCommandStr;
nsString mTooltip;
nsString mDescription;
PRBool mIsEnabled;
nsVoidArray mSrcWidgets;
nsCOMPtr<nsIWebShell> mWebShell;
nsCOMPtr<nsIDOMElement> mDOMElement;
};
#endif /* nsXULCommand_h__ */

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

@ -4,6 +4,8 @@
<?xml-stylesheet href="xul.css" type="text/css"?>
<!DOCTYPE window>
<window>
<xul:commands>
<xul:command name="nsCmd:BrowserBack" onCommand="window.back();"/>