зеркало из https://github.com/mozilla/gecko-dev.git
Needed for bug 40457: Add API for range methods to tell
whether a node or point intersects the range. r=vidur, a=beppe.
This commit is contained in:
Родитель
e76bf3f5ee
Коммит
5530c009d8
|
@ -47,4 +47,24 @@ interface NSRange {
|
|||
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */
|
||||
DocumentFragment createContextualFragment(in DOMString fragment);
|
||||
boolean isValidFragment(in DOMString fragment);
|
||||
|
||||
// Is the point contained in the range?
|
||||
boolean isPointInRange(in Node parent, in long offset);
|
||||
|
||||
// comparePoint returns
|
||||
// -1 if point is before range,
|
||||
// 0 if point is in range,
|
||||
// 1 if point is after range
|
||||
// Sort of a strcmp for ranges.
|
||||
short comparePoint(in Node parent, in long offset);
|
||||
|
||||
// Does the node intersect the range?
|
||||
boolean intersectsNode(in Node n);
|
||||
|
||||
// HOW does the node intersect the range? Four possible values:
|
||||
const unsigned short NODE_BEFORE = 0;
|
||||
const unsigned short NODE_AFTER = 1;
|
||||
const unsigned short NODE_BEFORE_AND_AFTER = 2;
|
||||
const unsigned short NODE_INSIDE = 3;
|
||||
unsigned short compareNode(in Node n);
|
||||
};
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
#ifndef nsDOMPropEnums_h__
|
||||
#define nsDOMPropEnums_h__
|
||||
|
||||
// Use genPropNames.pl to keep this list in sync with nsDOMPropNames.h
|
||||
// Use genPropNames.pl after modifying,
|
||||
// to keep nsDOMPropNames.h in sync with this file.
|
||||
|
||||
enum nsDOMProp {
|
||||
NS_DOM_PROP_ABSTRACTVIEW_DOCUMENT,
|
||||
|
@ -808,7 +809,11 @@ enum nsDOMProp {
|
|||
NS_DOM_PROP_NSHTMLTEXTAREAELEMENT_CONTROLLERS,
|
||||
NS_DOM_PROP_NSLOCATION_RELOAD,
|
||||
NS_DOM_PROP_NSLOCATION_REPLACE,
|
||||
NS_DOM_PROP_NSRANGE_COMPARENODE,
|
||||
NS_DOM_PROP_NSRANGE_COMPAREPOINT,
|
||||
NS_DOM_PROP_NSRANGE_CREATECONTEXTUALFRAGMENT,
|
||||
NS_DOM_PROP_NSRANGE_INTERSECTSNODE,
|
||||
NS_DOM_PROP_NSRANGE_ISPOINTINRANGE,
|
||||
NS_DOM_PROP_NSRANGE_ISVALIDFRAGMENT,
|
||||
NS_DOM_PROP_NSUIEVENT_CANCELBUBBLE,
|
||||
NS_DOM_PROP_NSUIEVENT_GETPREVENTDEFAULT,
|
||||
|
|
|
@ -807,7 +807,11 @@
|
|||
"nshtmltextareaelement.controllers", \
|
||||
"nslocation.reload", \
|
||||
"nslocation.replace", \
|
||||
"nsrange.comparenode", \
|
||||
"nsrange.comparepoint", \
|
||||
"nsrange.createcontextualfragment", \
|
||||
"nsrange.intersectsnode", \
|
||||
"nsrange.ispointinrange", \
|
||||
"nsrange.isvalidfragment", \
|
||||
"nsuievent.cancelbubble", \
|
||||
"nsuievent.getpreventdefault", \
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "nsString.h"
|
||||
#include "nsIScriptContext.h"
|
||||
|
||||
class nsIDOMNode;
|
||||
class nsIDOMDocumentFragment;
|
||||
|
||||
#define NS_IDOMNSRANGE_IID \
|
||||
|
@ -37,22 +38,44 @@ class nsIDOMDocumentFragment;
|
|||
class nsIDOMNSRange : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOMNSRANGE_IID; return iid; }
|
||||
enum {
|
||||
NODE_BEFORE = 0,
|
||||
NODE_AFTER = 1,
|
||||
NODE_BEFORE_AND_AFTER = 2,
|
||||
NODE_INSIDE = 3
|
||||
};
|
||||
|
||||
NS_IMETHOD CreateContextualFragment(const nsString& aFragment, nsIDOMDocumentFragment** aReturn)=0;
|
||||
|
||||
NS_IMETHOD IsValidFragment(const nsString& aFragment, PRBool* aReturn)=0;
|
||||
|
||||
NS_IMETHOD IsPointInRange(nsIDOMNode* aParent, PRInt32 aOffset, PRBool* aReturn)=0;
|
||||
|
||||
NS_IMETHOD ComparePoint(nsIDOMNode* aParent, PRInt32 aOffset, PRInt16* aReturn)=0;
|
||||
|
||||
NS_IMETHOD IntersectsNode(nsIDOMNode* aN, PRBool* aReturn)=0;
|
||||
|
||||
NS_IMETHOD CompareNode(nsIDOMNode* aN, PRInt16* aReturn)=0;
|
||||
};
|
||||
|
||||
|
||||
#define NS_DECL_IDOMNSRANGE \
|
||||
NS_IMETHOD CreateContextualFragment(const nsString& aFragment, nsIDOMDocumentFragment** aReturn); \
|
||||
NS_IMETHOD IsValidFragment(const nsString& aFragment, PRBool* aReturn); \
|
||||
NS_IMETHOD IsPointInRange(nsIDOMNode* aParent, PRInt32 aOffset, PRBool* aReturn); \
|
||||
NS_IMETHOD ComparePoint(nsIDOMNode* aParent, PRInt32 aOffset, PRInt16* aReturn); \
|
||||
NS_IMETHOD IntersectsNode(nsIDOMNode* aN, PRBool* aReturn); \
|
||||
NS_IMETHOD CompareNode(nsIDOMNode* aN, PRInt16* aReturn); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMNSRANGE(_to) \
|
||||
NS_IMETHOD CreateContextualFragment(const nsString& aFragment, nsIDOMDocumentFragment** aReturn) { return _to CreateContextualFragment(aFragment, aReturn); } \
|
||||
NS_IMETHOD IsValidFragment(const nsString& aFragment, PRBool* aReturn) { return _to IsValidFragment(aFragment, aReturn); } \
|
||||
NS_IMETHOD IsPointInRange(nsIDOMNode* aParent, PRInt32 aOffset, PRBool* aReturn) { return _to IsPointInRange(aParent, aOffset, aReturn); } \
|
||||
NS_IMETHOD ComparePoint(nsIDOMNode* aParent, PRInt32 aOffset, PRInt16* aReturn) { return _to ComparePoint(aParent, aOffset, aReturn); } \
|
||||
NS_IMETHOD IntersectsNode(nsIDOMNode* aN, PRBool* aReturn) { return _to IntersectsNode(aN, aReturn); } \
|
||||
NS_IMETHOD CompareNode(nsIDOMNode* aN, PRInt16* aReturn) { return _to CompareNode(aN, aReturn); } \
|
||||
|
||||
|
||||
#endif // nsIDOMNSRange_h__
|
||||
|
|
|
@ -1079,6 +1079,226 @@ NSRangeIsValidFragment(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js
|
|||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method IsPointInRange
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
NSRangeIsPointInRange(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMRange *privateThis = (nsIDOMRange*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
nsCOMPtr<nsIDOMNSRange> nativeThis;
|
||||
nsresult result = NS_OK;
|
||||
if (NS_OK != privateThis->QueryInterface(kINSRangeIID, getter_AddRefs(nativeThis))) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR);
|
||||
}
|
||||
|
||||
PRBool nativeRet;
|
||||
nsCOMPtr<nsIDOMNode> b0;
|
||||
PRInt32 b1;
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (!nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
{
|
||||
*rval = JSVAL_NULL;
|
||||
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
|
||||
if (!secMan)
|
||||
return PR_FALSE;
|
||||
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSRANGE_ISPOINTINRANGE, PR_FALSE);
|
||||
if (NS_FAILED(result)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
if (argc < 2) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
|
||||
}
|
||||
|
||||
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0),
|
||||
kINodeIID,
|
||||
NS_ConvertASCIItoUCS2("Node"),
|
||||
cx,
|
||||
argv[0])) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR);
|
||||
}
|
||||
if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_NUMBER_ERR);
|
||||
}
|
||||
|
||||
result = nativeThis->IsPointInRange(b0, b1, &nativeRet);
|
||||
if (NS_FAILED(result)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
|
||||
*rval = BOOLEAN_TO_JSVAL(nativeRet);
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method ComparePoint
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
NSRangeComparePoint(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMRange *privateThis = (nsIDOMRange*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
nsCOMPtr<nsIDOMNSRange> nativeThis;
|
||||
nsresult result = NS_OK;
|
||||
if (NS_OK != privateThis->QueryInterface(kINSRangeIID, getter_AddRefs(nativeThis))) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR);
|
||||
}
|
||||
|
||||
PRInt16 nativeRet;
|
||||
nsCOMPtr<nsIDOMNode> b0;
|
||||
PRInt32 b1;
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (!nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
{
|
||||
*rval = JSVAL_NULL;
|
||||
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
|
||||
if (!secMan)
|
||||
return PR_FALSE;
|
||||
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSRANGE_COMPAREPOINT, PR_FALSE);
|
||||
if (NS_FAILED(result)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
if (argc < 2) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
|
||||
}
|
||||
|
||||
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0),
|
||||
kINodeIID,
|
||||
NS_ConvertASCIItoUCS2("Node"),
|
||||
cx,
|
||||
argv[0])) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR);
|
||||
}
|
||||
if (!JS_ValueToInt32(cx, argv[1], (int32 *)&b1)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_NUMBER_ERR);
|
||||
}
|
||||
|
||||
result = nativeThis->ComparePoint(b0, b1, &nativeRet);
|
||||
if (NS_FAILED(result)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
|
||||
*rval = INT_TO_JSVAL(nativeRet);
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method IntersectsNode
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
NSRangeIntersectsNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMRange *privateThis = (nsIDOMRange*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
nsCOMPtr<nsIDOMNSRange> nativeThis;
|
||||
nsresult result = NS_OK;
|
||||
if (NS_OK != privateThis->QueryInterface(kINSRangeIID, getter_AddRefs(nativeThis))) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR);
|
||||
}
|
||||
|
||||
PRBool nativeRet;
|
||||
nsCOMPtr<nsIDOMNode> b0;
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (!nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
{
|
||||
*rval = JSVAL_NULL;
|
||||
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
|
||||
if (!secMan)
|
||||
return PR_FALSE;
|
||||
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSRANGE_INTERSECTSNODE, PR_FALSE);
|
||||
if (NS_FAILED(result)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
if (argc < 1) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
|
||||
}
|
||||
|
||||
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0),
|
||||
kINodeIID,
|
||||
NS_ConvertASCIItoUCS2("Node"),
|
||||
cx,
|
||||
argv[0])) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR);
|
||||
}
|
||||
|
||||
result = nativeThis->IntersectsNode(b0, &nativeRet);
|
||||
if (NS_FAILED(result)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
|
||||
*rval = BOOLEAN_TO_JSVAL(nativeRet);
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method CompareNode
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
NSRangeCompareNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMRange *privateThis = (nsIDOMRange*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
nsCOMPtr<nsIDOMNSRange> nativeThis;
|
||||
nsresult result = NS_OK;
|
||||
if (NS_OK != privateThis->QueryInterface(kINSRangeIID, getter_AddRefs(nativeThis))) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR);
|
||||
}
|
||||
|
||||
PRInt16 nativeRet;
|
||||
nsCOMPtr<nsIDOMNode> b0;
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (!nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
{
|
||||
*rval = JSVAL_NULL;
|
||||
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
|
||||
if (!secMan)
|
||||
return PR_FALSE;
|
||||
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSRANGE_COMPARENODE, PR_FALSE);
|
||||
if (NS_FAILED(result)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
if (argc < 1) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
|
||||
}
|
||||
|
||||
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0),
|
||||
kINodeIID,
|
||||
NS_ConvertASCIItoUCS2("Node"),
|
||||
cx,
|
||||
argv[0])) {
|
||||
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR);
|
||||
}
|
||||
|
||||
result = nativeThis->CompareNode(b0, &nativeRet);
|
||||
if (NS_FAILED(result)) {
|
||||
return nsJSUtils::nsReportError(cx, obj, result);
|
||||
}
|
||||
|
||||
*rval = INT_TO_JSVAL(nativeRet);
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// class for Range
|
||||
|
@ -1138,6 +1358,10 @@ static JSFunctionSpec RangeMethods[] =
|
|||
{"toString", RangeToString, 0},
|
||||
{"createContextualFragment", NSRangeCreateContextualFragment, 1},
|
||||
{"isValidFragment", NSRangeIsValidFragment, 1},
|
||||
{"isPointInRange", NSRangeIsPointInRange, 2},
|
||||
{"comparePoint", NSRangeComparePoint, 2},
|
||||
{"intersectsNode", NSRangeIntersectsNode, 1},
|
||||
{"compareNode", NSRangeCompareNode, 1},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче