From 505d44861f5037eb7563d7ad6078b7c9db633b25 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Fri, 7 May 1999 22:27:26 +0000 Subject: [PATCH] Added insertLinkAroundSelection method to appcore --- xpfe/AppCores/idl/EditorAppCore.idl | 5 +- xpfe/AppCores/public/nsIDOMEditorAppCore.h | 4 ++ xpfe/AppCores/src/nsEditorAppCore.cpp | 19 ++++++++ xpfe/AppCores/src/nsEditorAppCore.h | 1 + xpfe/AppCores/src/nsJSEditorAppCore.cpp | 57 +++++++++++++++++++++- 5 files changed, 83 insertions(+), 3 deletions(-) diff --git a/xpfe/AppCores/idl/EditorAppCore.idl b/xpfe/AppCores/idl/EditorAppCore.idl index 08e28e59a5c..41542661ffc 100755 --- a/xpfe/AppCores/idl/EditorAppCore.idl +++ b/xpfe/AppCores/idl/EditorAppCore.idl @@ -43,13 +43,14 @@ interface EditorAppCore : BaseAppCore void insertText(in DOMString textToInsert); - void insertLink(); + void insertLink(); void insertImage(); Element getSelectedElement(in DOMString tagName); Element createElementWithDefaults(in DOMString tagName); Element insertElement(in Element element, in boolean deleteSelection); - + void insertLinkAroundSelection(in Element anchorElement); + void exit(); void setToolbarWindow(in Window win); diff --git a/xpfe/AppCores/public/nsIDOMEditorAppCore.h b/xpfe/AppCores/public/nsIDOMEditorAppCore.h index 751f85e5f90..42deb6d8d41 100755 --- a/xpfe/AppCores/public/nsIDOMEditorAppCore.h +++ b/xpfe/AppCores/public/nsIDOMEditorAppCore.h @@ -96,6 +96,8 @@ public: NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn)=0; + NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement)=0; + NS_IMETHOD Exit()=0; NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin)=0; @@ -136,6 +138,7 @@ public: NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn); \ NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn); \ NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn); \ + NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); \ NS_IMETHOD Exit(); \ NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin); \ NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin); \ @@ -173,6 +176,7 @@ public: NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn) { return _to GetSelectedElement(aTagName, aReturn); } \ NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn) { return _to CreateElementWithDefaults(aTagName, aReturn); } \ NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn) { return _to InsertElement(aElement, aDeleteSelection, aReturn); } \ + NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { return _to InsertLinkAroundSelection(aAnchorElement); } \ NS_IMETHOD Exit() { return _to Exit(); } \ NS_IMETHOD SetToolbarWindow(nsIDOMWindow* aWin) { return _to SetToolbarWindow(aWin); } \ NS_IMETHOD SetContentWindow(nsIDOMWindow* aWin) { return _to SetContentWindow(aWin); } \ diff --git a/xpfe/AppCores/src/nsEditorAppCore.cpp b/xpfe/AppCores/src/nsEditorAppCore.cpp index 5be9ff6bd6c..2b3b9b84482 100755 --- a/xpfe/AppCores/src/nsEditorAppCore.cpp +++ b/xpfe/AppCores/src/nsEditorAppCore.cpp @@ -1274,6 +1274,25 @@ nsEditorAppCore::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, return err; } +NS_IMETHODIMP +nsEditorAppCore::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) +{ + nsresult err = NS_NOINTERFACE; + switch (mEditorType) + { + case eHTMLTextEditorType: + { + nsCOMPtr htmlEditor = do_QueryInterface(mEditor); + if (htmlEditor) + return htmlEditor->InsertLinkAroundSelection(aAnchorElement); + } + break; + default: + err = NS_ERROR_NOT_IMPLEMENTED; + } + return err; +} + NS_IMETHODIMP nsEditorAppCore::BeginBatchChanges() { diff --git a/xpfe/AppCores/src/nsEditorAppCore.h b/xpfe/AppCores/src/nsEditorAppCore.h index 32e2166b957..b6bf5c0f48c 100755 --- a/xpfe/AppCores/src/nsEditorAppCore.h +++ b/xpfe/AppCores/src/nsEditorAppCore.h @@ -65,6 +65,7 @@ class nsEditorAppCore : public nsBaseAppCore, NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn); NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn); NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, nsIDOMElement** aReturn); + NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); NS_IMETHOD SetEditorType(const nsString& aEditorType); NS_IMETHOD SetTextProperty(const nsString& aProp, const nsString& aAttr, diff --git a/xpfe/AppCores/src/nsJSEditorAppCore.cpp b/xpfe/AppCores/src/nsJSEditorAppCore.cpp index 8531c80e851..a451ecd6c16 100755 --- a/xpfe/AppCores/src/nsJSEditorAppCore.cpp +++ b/xpfe/AppCores/src/nsJSEditorAppCore.cpp @@ -33,6 +33,7 @@ #include "nsIDOMWindow.h" #include "nsIScriptNameSpaceManager.h" #include "nsIComponentManager.h" +#include "nsIJSNativeInitializer.h" #include "nsDOMCID.h" @@ -1075,6 +1076,48 @@ EditorAppCoreInsertElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv } +// +// Native method InsertLinkAroundSelection +// +PR_STATIC_CALLBACK(JSBool) +EditorAppCoreInsertLinkAroundSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMEditorAppCore *nativeThis = (nsIDOMEditorAppCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMElementPtr 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, + kIElementIID, + "Element", + cx, + argv[0])) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->InsertLinkAroundSelection(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function insertLinkAroundSelection requires 1 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + // // Native method Exit // @@ -1295,6 +1338,7 @@ static JSFunctionSpec EditorAppCoreMethods[] = {"getSelectedElement", EditorAppCoreGetSelectedElement, 1}, {"createElementWithDefaults", EditorAppCoreCreateElementWithDefaults, 1}, {"insertElement", EditorAppCoreInsertElement, 2}, + {"insertLinkAroundSelection", EditorAppCoreInsertLinkAroundSelection, 1}, {"exit", EditorAppCoreExit, 0}, {"setToolbarWindow", EditorAppCoreSetToolbarWindow, 1}, {"setContentWindow", EditorAppCoreSetContentWindow, 1}, @@ -1315,8 +1359,10 @@ EditorAppCore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval nsIScriptNameSpaceManager* manager; nsIDOMEditorAppCore *nativeThis; nsIScriptObjectOwner *owner = nsnull; + nsIJSNativeInitializer* initializer = nsnull; static NS_DEFINE_IID(kIDOMEditorAppCoreIID, NS_IDOMEDITORAPPCORE_IID); + static NS_DEFINE_IID(kIJSNativeInitializerIID, NS_IJSNATIVEINITIALIZER_IID); result = context->GetNameSpaceManager(&manager); if (NS_OK != result) { @@ -1337,7 +1383,16 @@ EditorAppCore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval return JS_FALSE; } - // XXX We should be calling Init() on the instance + result = nativeThis->QueryInterface(kIJSNativeInitializerIID, (void **)&initializer); + if (NS_OK == result) { + result = initializer->Initialize(cx, argc, argv); + NS_RELEASE(initializer); + + if (NS_OK != result) { + NS_RELEASE(nativeThis); + return JS_FALSE; + } + } result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner); if (NS_OK != result) {