Implemented DOM document's createTextNode() function, and changed insertBefore()

handler to allow refChild to be null


git-svn-id: svn://10.0.0.236/trunk@1103 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
troy
1998-05-04 20:34:37 +00:00
parent ea789f09b3
commit c94f8a9104
11 changed files with 91 additions and 52 deletions

View File

@@ -583,20 +583,6 @@ nsresult nsDocument::CreateDocumentContext(nsIDOMDocumentContext **aDocContext)
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement)
{
//XXX TBI (currently there's a cheesy implementation in nsHTMLDocument)
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateTextNode(nsString &aData, nsIDOMText** aTextNode)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateComment(nsString &aData, nsIDOMComment **aComment)
{
//XXX TBI

View File

@@ -161,8 +161,8 @@ public:
virtual nsresult CreateDocumentContext(nsIDOMDocumentContext **aDocContext);
virtual nsresult CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement);
virtual nsresult CreateTextNode(nsString &aData, nsIDOMText** aTextNode);
nsIDOMElement **aElement) = 0;
virtual nsresult CreateTextNode(nsString &aData, nsIDOMText** aTextNode) = 0;
virtual nsresult CreateComment(nsString &aData, nsIDOMComment **aComment);
virtual nsresult CreatePI(nsString &aName, nsString &aData, nsIDOMPI **aPI);
virtual nsresult CreateAttribute(nsString &aName,

View File

@@ -28,9 +28,11 @@
#include "nsIImageMap.h"
#include "nsIHTMLContent.h"
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IHTMLDOCUMENT_IID);
NS_LAYOUT nsresult
@@ -208,6 +210,18 @@ nsresult nsHTMLDocument::CreateElement(nsString &aTagName,
return rv;
}
nsresult nsHTMLDocument::CreateTextNode(nsString &aData, nsIDOMText** aTextNode)
{
nsIHTMLContent* text = nsnull;
nsresult rv = NS_NewHTMLText(&text, aData, aData.Length());
if (NS_OK == rv) {
rv = text->QueryInterface(kIDOMTextIID, (void**)aTextNode);
}
return rv;
}
//----------------------------------------------------------------------
// Aggregation class to give nsHTMLDocument the nsIHTMLDocument interface

View File

@@ -42,9 +42,10 @@ public:
return offsetof(nsHTMLDocument,mIHTMLDocument);
}
virtual nsresult CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement);
virtual nsresult CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement);
virtual nsresult CreateTextNode(nsString &aData, nsIDOMText** aTextNode);
protected:
virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet);

View File

@@ -23,6 +23,7 @@
#include "nsIDOMDocument.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
#include "nsString.h"
static NS_DEFINE_IID(kIScriptObjectIID, NS_ISCRIPTOBJECT_IID);
@@ -195,7 +196,29 @@ CreateElement(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
PR_STATIC_CALLBACK(JSBool)
CreateTextNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
//XXX TBI
nsIDOMDocument *document = (nsIDOMDocument*)JS_GetPrivate(cx, obj);
if (nsnull != document) {
NS_ASSERTION(1 == argc, "unexpected argument count");
JSString* jsstring1 = JSVAL_TO_STRING(argv[0]);
nsString data(JS_GetStringChars(jsstring1));
nsIDOMText* textNode;
if (NS_OK == document->CreateTextNode(data, &textNode)) {
// get the js object
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == textNode->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
JSObject *object = nsnull;
if (NS_OK == owner->GetScriptObject(cx, (void**)&object)) {
// set the return value
*rval = OBJECT_TO_JSVAL(object);
}
NS_RELEASE(owner);
}
NS_RELEASE(textNode);
}
}
return JS_TRUE;
}

View File

@@ -42,7 +42,7 @@ PR_STATIC_CALLBACK(JSBool)
GetTextProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMText *text = (nsIDOMText*)JS_GetPrivate(cx, obj);
NS_ASSERTION(nsnull != text, "null pointer");
// NS_ASSERTION(nsnull != text, "null pointer");
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {

View File

@@ -583,20 +583,6 @@ nsresult nsDocument::CreateDocumentContext(nsIDOMDocumentContext **aDocContext)
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement)
{
//XXX TBI (currently there's a cheesy implementation in nsHTMLDocument)
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateTextNode(nsString &aData, nsIDOMText** aTextNode)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsDocument::CreateComment(nsString &aData, nsIDOMComment **aComment)
{
//XXX TBI

View File

@@ -161,8 +161,8 @@ public:
virtual nsresult CreateDocumentContext(nsIDOMDocumentContext **aDocContext);
virtual nsresult CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement);
virtual nsresult CreateTextNode(nsString &aData, nsIDOMText** aTextNode);
nsIDOMElement **aElement) = 0;
virtual nsresult CreateTextNode(nsString &aData, nsIDOMText** aTextNode) = 0;
virtual nsresult CreateComment(nsString &aData, nsIDOMComment **aComment);
virtual nsresult CreatePI(nsString &aName, nsString &aData, nsIDOMPI **aPI);
virtual nsresult CreateAttribute(nsString &aName,

View File

@@ -783,23 +783,37 @@ nsresult nsHTMLContainer::GetFirstChild(nsIDOMNode **aNode)
nsresult nsHTMLContainer::InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild)
{
nsIContent* content = nsnull;
nsresult res = refChild->QueryInterface(kIContentIID, (void**)&content);
NS_ASSERTION(NS_OK == res, "Must be an nsIContent");
NS_PRECONDITION(nsnull != newChild, "Null new child");
// Get the nsIContent interface for the new content
nsIContent* newContent = nsnull;
nsresult res = newChild->QueryInterface(kIContentIID, (void**)&newContent);
NS_ASSERTION(NS_OK == res, "New child must be an nsIContent");
if (NS_OK == res) {
PRInt32 pos = IndexOf(content);
if (pos >= 0) {
nsIContent* newContent = nsnull;
res = newChild->QueryInterface(kIContentIID, (void**)&newContent);
NS_ASSERTION(NS_OK == res, "Must be an nsIContent");
if (nsnull == refChild) {
// Append the new child to the end
if (PR_FALSE == AppendChild(newContent)) {
res == NS_ERROR_FAILURE;
}
} else {
nsIContent* content = nsnull;
// Get the index of where to insert the new child
res = refChild->QueryInterface(kIContentIID, (void**)&content);
NS_ASSERTION(NS_OK == res, "Ref child must be an nsIContent");
if (NS_OK == res) {
if (PR_FALSE == InsertChildAt(newContent, pos)) {
res = NS_ERROR_FAILURE;
PRInt32 pos = IndexOf(content);
if (pos >= 0) {
if (PR_FALSE == InsertChildAt(newContent, pos)) {
res = NS_ERROR_FAILURE;
}
}
NS_RELEASE(newContent);
NS_RELEASE(content);
}
}
NS_RELEASE(content);
NS_RELEASE(newContent);
}
return res;

View File

@@ -28,9 +28,11 @@
#include "nsIImageMap.h"
#include "nsIHTMLContent.h"
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IHTMLDOCUMENT_IID);
NS_LAYOUT nsresult
@@ -208,6 +210,18 @@ nsresult nsHTMLDocument::CreateElement(nsString &aTagName,
return rv;
}
nsresult nsHTMLDocument::CreateTextNode(nsString &aData, nsIDOMText** aTextNode)
{
nsIHTMLContent* text = nsnull;
nsresult rv = NS_NewHTMLText(&text, aData, aData.Length());
if (NS_OK == rv) {
rv = text->QueryInterface(kIDOMTextIID, (void**)aTextNode);
}
return rv;
}
//----------------------------------------------------------------------
// Aggregation class to give nsHTMLDocument the nsIHTMLDocument interface

View File

@@ -42,9 +42,10 @@ public:
return offsetof(nsHTMLDocument,mIHTMLDocument);
}
virtual nsresult CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement);
virtual nsresult CreateElement(nsString &aTagName,
nsIDOMAttributeList *aAttributes,
nsIDOMElement **aElement);
virtual nsresult CreateTextNode(nsString &aData, nsIDOMText** aTextNode);
protected:
virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet);