зеркало из https://github.com/mozilla/pjs.git
Added insertLinkAroundSelection method to appcore
This commit is contained in:
Родитель
9bb944b33f
Коммит
505d44861f
|
@ -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);
|
||||
|
|
|
@ -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); } \
|
||||
|
|
|
@ -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<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||
if (htmlEditor)
|
||||
return htmlEditor->InsertLinkAroundSelection(aAnchorElement);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
err = NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorAppCore::BeginBatchChanges()
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче