Added IsValidFragment to nsIDOMNSRange interface and CreateRange to nsIDOMNSDocument.

This commit is contained in:
vidur%netscape.com 1999-05-11 20:20:40 +00:00
Родитель d47c6526f6
Коммит 5dbbb06562
6 изменённых файлов: 100 добавлений и 2 удалений

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

@ -26,6 +26,7 @@
class nsIDOMElement;
class nsIDOMStyleSheetCollection;
class nsIDOMRange;
#define NS_IDOMNSDOCUMENT_IID \
{ 0xa6cf90cd, 0x15b3, 0x11d2, \
@ -38,18 +39,22 @@ public:
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)=0;
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName, const nsString& aNameSpace, nsIDOMElement** aReturn)=0;
NS_IMETHOD CreateRange(nsIDOMRange** aReturn)=0;
};
#define NS_DECL_IDOMNSDOCUMENT \
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets); \
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName, const nsString& aNameSpace, nsIDOMElement** aReturn); \
NS_IMETHOD CreateRange(nsIDOMRange** aReturn); \
#define NS_FORWARD_IDOMNSDOCUMENT(_to) \
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets) { return _to GetStyleSheets(aStyleSheets); } \
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName, const nsString& aNameSpace, nsIDOMElement** aReturn) { return _to CreateElementWithNameSpace(aTagName, aNameSpace, aReturn); } \
NS_IMETHOD CreateRange(nsIDOMRange** aReturn) { return _to CreateRange(aReturn); } \
#endif // nsIDOMNSDocument_h__

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

@ -29,7 +29,7 @@
readonly attribute StyleSheetCollection styleSheets;
Element createElementWithNameSpace(in DOMString tagName,
in DOMString nameSpace)
raises(DOMException);
raises(DOMException); Range createRange();
};
interface EventCapturer : EventReceiver {

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

@ -46,4 +46,5 @@ interface NSRange {
/* IID: { 0xa6cf90f2, 0x15b3, 0x11d2, \
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */
void insertFragment(in DOMString fragment);
boolean isValidFragment(in DOMString fragment);
};

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

@ -34,16 +34,20 @@ public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOMNSRANGE_IID; return iid; }
NS_IMETHOD InsertFragment(const nsString& aFragment)=0;
NS_IMETHOD IsValidFragment(const nsString& aFragment, PRBool* aReturn)=0;
};
#define NS_DECL_IDOMNSRANGE \
NS_IMETHOD InsertFragment(const nsString& aFragment); \
NS_IMETHOD IsValidFragment(const nsString& aFragment, PRBool* aReturn); \
#define NS_FORWARD_IDOMNSRANGE(_to) \
NS_IMETHOD InsertFragment(const nsString& aFragment) { return _to InsertFragment(aFragment); } \
NS_IMETHOD IsValidFragment(const nsString& aFragment, PRBool* aReturn) { return _to IsValidFragment(aFragment, aReturn); } \
#endif // nsIDOMNSRange_h__

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

@ -39,6 +39,7 @@
#include "nsIDOMNSDocument.h"
#include "nsIDOMComment.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIDOMRange.h"
#include "nsIDOMEventCapturer.h"
#include "nsIDOMNodeList.h"
@ -59,6 +60,7 @@ static NS_DEFINE_IID(kIEntityReferenceIID, NS_IDOMENTITYREFERENCE_IID);
static NS_DEFINE_IID(kINSDocumentIID, NS_IDOMNSDOCUMENT_IID);
static NS_DEFINE_IID(kICommentIID, NS_IDOMCOMMENT_IID);
static NS_DEFINE_IID(kIDocumentFragmentIID, NS_IDOMDOCUMENTFRAGMENT_IID);
static NS_DEFINE_IID(kIRangeIID, NS_IDOMRANGE_IID);
static NS_DEFINE_IID(kIEventCapturerIID, NS_IDOMEVENTCAPTURER_IID);
static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
@ -75,6 +77,7 @@ NS_DEF_PTR(nsIDOMEntityReference);
NS_DEF_PTR(nsIDOMNSDocument);
NS_DEF_PTR(nsIDOMComment);
NS_DEF_PTR(nsIDOMDocumentFragment);
NS_DEF_PTR(nsIDOMRange);
NS_DEF_PTR(nsIDOMEventCapturer);
NS_DEF_PTR(nsIDOMNodeList);
@ -610,6 +613,46 @@ NSDocumentCreateElementWithNameSpace(JSContext *cx, JSObject *obj, uintN argc, j
}
//
// Native method CreateRange
//
PR_STATIC_CALLBACK(JSBool)
NSDocumentCreateRange(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMDocument *privateThis = (nsIDOMDocument*)JS_GetPrivate(cx, obj);
nsIDOMNSDocument *nativeThis = nsnull;
if (NS_OK != privateThis->QueryInterface(kINSDocumentIID, (void **)&nativeThis)) {
JS_ReportError(cx, "Object must be of type NSDocument");
return JS_FALSE;
}
JSBool rBool = JS_FALSE;
nsIDOMRange* nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->CreateRange(&nativeRet)) {
return JS_FALSE;
}
nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, rval);
}
else {
JS_ReportError(cx, "Function createRange requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method CaptureEvent
//
@ -740,6 +783,7 @@ static JSFunctionSpec DocumentMethods[] =
{"createEntityReference", DocumentCreateEntityReference, 1},
{"getElementsByTagName", DocumentGetElementsByTagName, 1},
{"createElementWithNameSpace", NSDocumentCreateElementWithNameSpace, 2},
{"createRange", NSDocumentCreateRange, 0},
{"captureEvent", EventCapturerCaptureEvent, 1},
{"releaseEvent", EventCapturerReleaseEvent, 1},
{0}

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

@ -942,6 +942,49 @@ NSRangeInsertFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
}
//
// Native method IsValidFragment
//
PR_STATIC_CALLBACK(JSBool)
NSRangeIsValidFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMRange *privateThis = (nsIDOMRange*)JS_GetPrivate(cx, obj);
nsIDOMNSRange *nativeThis = nsnull;
if (NS_OK != privateThis->QueryInterface(kINSRangeIID, (void **)&nativeThis)) {
JS_ReportError(cx, "Object must be of type NSRange");
return JS_FALSE;
}
JSBool rBool = JS_FALSE;
PRBool nativeRet;
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->IsValidFragment(b0, &nativeRet)) {
return JS_FALSE;
}
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function isValidFragment requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for Range
@ -998,6 +1041,7 @@ static JSFunctionSpec RangeMethods[] =
{"clone", RangeClone, 0},
{"toString", RangeToString, 0},
{"insertFragment", NSRangeInsertFragment, 1},
{"isValidFragment", NSRangeIsValidFragment, 1},
{0}
};
@ -1079,7 +1123,7 @@ extern "C" NS_DOM nsresult NS_InitRangeClass(nsIScriptContext *aContext, void **
//
// Method for creating a new Range JavaScript object
//
NS_DOM nsresult NS_NewScriptRange(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
extern "C" NS_DOM nsresult NS_NewScriptRange(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptRange");
JSObject *proto;