Fix to get default namespaces to work. Cleanup of DOM handling of character data.

This commit is contained in:
vidur%netscape.com 1999-01-21 19:33:03 +00:00
Родитель 02a60fb54d
Коммит b9e4d31fab
16 изменённых файлов: 183 добавлений и 65 удалений

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

@ -624,6 +624,7 @@ NS_IMETHODIMP
nsDocument::GetBaseURL(nsIURL*& aURL) const
{
aURL = mDocumentURL;
NS_IF_ADDREF(mDocumentURL);
return NS_OK;
}

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

@ -18,9 +18,12 @@
*/
#include "nsGenericDOMDataNode.h"
#include "nsGenericElement.h"
#include "nsIDocument.h"
#include "nsIEventListenerManager.h"
#include "nsIDocument.h"
#include "nsIDOMRange.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentFragment.h"
#include "nsXIFConverter.h"
#include "nsSelectionRange.h"
#include "nsRange.h"
@ -38,7 +41,7 @@
NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID);
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
//----------------------------------------------------------------------
@ -56,7 +59,6 @@ nsGenericDOMDataNode::nsGenericDOMDataNode()
nsGenericDOMDataNode::~nsGenericDOMDataNode()
{
NS_IF_RELEASE(mListenerManager);
// XXX what about mScriptObject? its now safe to GC it...
delete mRangeList;
}
@ -71,21 +73,13 @@ nsGenericDOMDataNode::Init(nsIContent* aOuterContentObject)
nsresult
nsGenericDOMDataNode::GetNodeValue(nsString& aNodeValue)
{
aNodeValue.Truncate();
mText.AppendTo(aNodeValue);
return NS_OK;
return GetData(aNodeValue);
}
nsresult
nsGenericDOMDataNode::SetNodeValue(const nsString& aNodeValue)
{
mText = aNodeValue;
// Trigger a reflow
if (nsnull != mDocument) {
mDocument->ContentChanged(mContent, nsnull);
}
return NS_OK;
return SetData(aNodeValue);
}
nsresult
@ -96,8 +90,36 @@ nsGenericDOMDataNode::GetParentNode(nsIDOMNode** aParentNode)
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
return res;
}
else if (nsnull == mDocument) {
// A standalone node (i.e. one without a parent or a document)
// implicitly has a document fragment as its parent according to
// the DOM.
nsIDOMDocumentFragment* docFrag;
nsIDOMNode *node, *ret;
// XXX If we don't have a document, how do we give the document
// fragment an owner document?
nsresult res = NS_NewDocumentFragment(&docFrag, nsnull);
if (NS_OK != res) {
return res;
}
res = mContent->QueryInterface(kIDOMNodeIID, (void**)&node);
if (NS_OK != res) {
return res;
}
res = docFrag->AppendChild(node, &ret);
NS_RELEASE(node);
if (NS_OK != res) {
return res;
}
NS_RELEASE(ret);
res = docFrag->QueryInterface(kIDOMNodeIID, (void**)aParentNode);
NS_RELEASE(docFrag);
return res;
}
else {
*aParentNode = nsnull;
// If we don't have a parent, but we're in the document, we must
// be at the top level. The DOM says that the root is the document.
return mDocument->QueryInterface(kIDOMNodeIID, (void**)aParentNode);
}
return NS_OK;
}
@ -119,6 +141,8 @@ nsGenericDOMDataNode::GetPreviousSibling(nsIDOMNode** aNode)
}
}
}
// XXX Nodes that are just below the document (their parent is the
// document) need to go to the document to find their previous sibling.
*aNode = nsnull;
return NS_OK;
}
@ -140,6 +164,8 @@ nsGenericDOMDataNode::GetNextSibling(nsIDOMNode** aNextSibling)
}
}
}
// XXX Nodes that are just below the document (their parent is the
// document) need to go to the document to find their next sibling.
*aNextSibling = nsnull;
return NS_OK;
}
@ -331,14 +357,30 @@ nsGenericDOMDataNode::GetScriptObject(nsIScriptContext* aContext,
return res;
}
res = factory->NewScriptCharacterData(nsIDOMNode::TEXT_NODE,
nsIDOMNode* node;
PRUint16 nodeType;
res = mContent->QueryInterface(kIDOMNodeIID, (void**)&node);
if (NS_OK != res) {
return res;
}
node->GetNodeType(&nodeType);
res = factory->NewScriptCharacterData(nodeType,
aContext, mContent,
mParent, (void**)&mScriptObject);
if (nsnull != mDocument) {
nsAutoString nodeName;
char nameBuf[128];
node->GetNodeName(nodeName);
nodeName.ToCString(nameBuf, sizeof(nameBuf));
aContext->AddNamedReference((void *)&mScriptObject,
mScriptObject,
"Text");
nameBuf);
}
NS_RELEASE(node);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;

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

@ -300,6 +300,8 @@ nsGenericElement::GetPreviousSibling(nsIDOMNode** aNode)
}
}
}
// XXX Nodes that are just below the document (their parent is the
// document) need to go to the document to find their previous sibling.
*aNode = nsnull;
return NS_OK;
}
@ -321,6 +323,8 @@ nsGenericElement::GetNextSibling(nsIDOMNode** aNextSibling)
}
}
}
// XXX Nodes that are just below the document (their parent is the
// document) need to go to the document to find their next sibling.
*aNextSibling = nsnull;
return NS_OK;
}

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

@ -185,7 +185,12 @@ NameSpaceImpl::FindNameSpaceID(nsIAtom* aPrefix, PRInt32& aNameSpaceID) const
nameSpace = nameSpace->mParent;
}
while (nsnull != nameSpace);
aNameSpaceID = kNameSpaceID_Unknown;
if (nsnull == aPrefix) {
aNameSpaceID = kNameSpaceID_None;
}
else {
aNameSpaceID = kNameSpaceID_Unknown;
}
return NS_ERROR_ILLEGAL_VALUE;
}

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

@ -484,13 +484,19 @@ nsXMLContentSink::PushNameSpacesFrom(const nsIParserNode& aNode)
// Look for "xmlns" at the start of the attribute name
offset = k.Find(kNameSpaceDef);
if (0 == offset) {
PRUnichar next = k.CharAt(sizeof(kNameSpaceDef)-1);
// If the next character is a :, there is a namespace prefix
if (':' == next) {
k.Right(prefix, k.Length()-sizeof(kNameSpaceDef));
if (k.Length() == (sizeof(kNameSpaceDef)-1)) {
// If there's nothing left, this is a default namespace
prefix.Truncate();
}
else {
prefix.Truncate();
PRUnichar next = k.CharAt(sizeof(kNameSpaceDef)-1);
// If the next character is a :, there is a namespace prefix
if (':' == next) {
k.Right(prefix, k.Length()-sizeof(kNameSpaceDef));
}
else {
continue;
}
}
// Get the attribute value (the URI for the namespace)
@ -1243,10 +1249,7 @@ nsXMLContentSink::AddEntityReference(const nsIParserNode& aNode)
PRInt32
nsXMLContentSink::GetNameSpaceId(nsIAtom* aPrefix)
{
if (nsnull == aPrefix) {
return kNameSpaceID_None;
}
PRInt32 id = kNameSpaceID_Unknown;
PRInt32 id = (nsnull == aPrefix) ? kNameSpaceID_None : kNameSpaceID_Unknown;
if ((nsnull != mNameSpaceStack) && (0 < mNameSpaceStack->Count())) {
PRInt32 index = mNameSpaceStack->Count() - 1;
nsINameSpace* nameSpace = (nsINameSpace*)mNameSpaceStack->ElementAt(index);
@ -1409,19 +1412,19 @@ nsXMLContentSink::EvaluateScript(nsString& aScript, PRUint32 aLineNo)
return rv;
}
nsIURL* mDocURL = mDocument->GetDocumentURL();
const char* mURL;
if (mDocURL) {
(void)mDocURL->GetSpec(&mURL);
nsIURL* docURL = mDocument->GetDocumentURL();
const char* url;
if (docURL) {
(void)docURL->GetSpec(&url);
}
nsAutoString val;
PRBool isUndefined;
PRBool result = context->EvaluateString(aScript, mURL, aLineNo,
PRBool result = context->EvaluateString(aScript, url, aLineNo,
val, &isUndefined);
NS_IF_RELEASE(mDocURL);
NS_IF_RELEASE(docURL);
NS_RELEASE(context);
NS_RELEASE(owner);

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

@ -3,6 +3,10 @@
<!DOCTYPE Book SYSTEM "docbook.dtd">
<Book> <Title>SoftQuad
Inc.</Title>
<p xmlns="http://www.w3.org/TR/REC-html40" xmlns:h="http://www.w3.org/TR/REC-html40">
<h:img src="flamer.gif"/>
<img src="flamer.gif"/>
</p>
<BookInfo> <BookBiblio> <Title>Demo Product Documentation</Title>
<AuthorGroup><CorpAuthor>SoftQuad Inc.</CorpAuthor></AuthorGroup>
</BookBiblio> </BookInfo> <Preface> <Title><Anchor

Двоичные данные
content/xml/tests/flamer.gif Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 11 KiB

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

@ -61,7 +61,7 @@ public:
nsISupports *aParent,
void** aReturn)=0;
NS_IMETHOD NewScriptCharacterData(const int aNodeType,
NS_IMETHOD NewScriptCharacterData(PRUint16 aNodeType,
nsIScriptContext *aContext,
nsISupports *aData,
nsISupports *aParent,

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

@ -227,7 +227,7 @@ public:
nsISupports *aParent,
void** aReturn);
NS_IMETHOD NewScriptCharacterData(const int aNodeType,
NS_IMETHOD NewScriptCharacterData(PRUint16 aNodeType,
nsIScriptContext *aContext,
nsISupports *aData,
nsISupports *aParent,
@ -334,7 +334,7 @@ nsDOMScriptObjectFactory::NewScriptDOMImplementation(nsIScriptContext *aContext,
}
NS_IMETHODIMP
nsDOMScriptObjectFactory::NewScriptCharacterData(const int aNodeType,
nsDOMScriptObjectFactory::NewScriptCharacterData(PRUint16 aNodeType,
nsIScriptContext *aContext,
nsISupports *aData,
nsISupports *aParent,

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

@ -624,6 +624,7 @@ NS_IMETHODIMP
nsDocument::GetBaseURL(nsIURL*& aURL) const
{
aURL = mDocumentURL;
NS_IF_ADDREF(mDocumentURL);
return NS_OK;
}

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

@ -18,9 +18,12 @@
*/
#include "nsGenericDOMDataNode.h"
#include "nsGenericElement.h"
#include "nsIDocument.h"
#include "nsIEventListenerManager.h"
#include "nsIDocument.h"
#include "nsIDOMRange.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentFragment.h"
#include "nsXIFConverter.h"
#include "nsSelectionRange.h"
#include "nsRange.h"
@ -38,7 +41,7 @@
NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID);
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
//----------------------------------------------------------------------
@ -56,7 +59,6 @@ nsGenericDOMDataNode::nsGenericDOMDataNode()
nsGenericDOMDataNode::~nsGenericDOMDataNode()
{
NS_IF_RELEASE(mListenerManager);
// XXX what about mScriptObject? its now safe to GC it...
delete mRangeList;
}
@ -71,21 +73,13 @@ nsGenericDOMDataNode::Init(nsIContent* aOuterContentObject)
nsresult
nsGenericDOMDataNode::GetNodeValue(nsString& aNodeValue)
{
aNodeValue.Truncate();
mText.AppendTo(aNodeValue);
return NS_OK;
return GetData(aNodeValue);
}
nsresult
nsGenericDOMDataNode::SetNodeValue(const nsString& aNodeValue)
{
mText = aNodeValue;
// Trigger a reflow
if (nsnull != mDocument) {
mDocument->ContentChanged(mContent, nsnull);
}
return NS_OK;
return SetData(aNodeValue);
}
nsresult
@ -96,8 +90,36 @@ nsGenericDOMDataNode::GetParentNode(nsIDOMNode** aParentNode)
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
return res;
}
else if (nsnull == mDocument) {
// A standalone node (i.e. one without a parent or a document)
// implicitly has a document fragment as its parent according to
// the DOM.
nsIDOMDocumentFragment* docFrag;
nsIDOMNode *node, *ret;
// XXX If we don't have a document, how do we give the document
// fragment an owner document?
nsresult res = NS_NewDocumentFragment(&docFrag, nsnull);
if (NS_OK != res) {
return res;
}
res = mContent->QueryInterface(kIDOMNodeIID, (void**)&node);
if (NS_OK != res) {
return res;
}
res = docFrag->AppendChild(node, &ret);
NS_RELEASE(node);
if (NS_OK != res) {
return res;
}
NS_RELEASE(ret);
res = docFrag->QueryInterface(kIDOMNodeIID, (void**)aParentNode);
NS_RELEASE(docFrag);
return res;
}
else {
*aParentNode = nsnull;
// If we don't have a parent, but we're in the document, we must
// be at the top level. The DOM says that the root is the document.
return mDocument->QueryInterface(kIDOMNodeIID, (void**)aParentNode);
}
return NS_OK;
}
@ -119,6 +141,8 @@ nsGenericDOMDataNode::GetPreviousSibling(nsIDOMNode** aNode)
}
}
}
// XXX Nodes that are just below the document (their parent is the
// document) need to go to the document to find their previous sibling.
*aNode = nsnull;
return NS_OK;
}
@ -140,6 +164,8 @@ nsGenericDOMDataNode::GetNextSibling(nsIDOMNode** aNextSibling)
}
}
}
// XXX Nodes that are just below the document (their parent is the
// document) need to go to the document to find their next sibling.
*aNextSibling = nsnull;
return NS_OK;
}
@ -331,14 +357,30 @@ nsGenericDOMDataNode::GetScriptObject(nsIScriptContext* aContext,
return res;
}
res = factory->NewScriptCharacterData(nsIDOMNode::TEXT_NODE,
nsIDOMNode* node;
PRUint16 nodeType;
res = mContent->QueryInterface(kIDOMNodeIID, (void**)&node);
if (NS_OK != res) {
return res;
}
node->GetNodeType(&nodeType);
res = factory->NewScriptCharacterData(nodeType,
aContext, mContent,
mParent, (void**)&mScriptObject);
if (nsnull != mDocument) {
nsAutoString nodeName;
char nameBuf[128];
node->GetNodeName(nodeName);
nodeName.ToCString(nameBuf, sizeof(nameBuf));
aContext->AddNamedReference((void *)&mScriptObject,
mScriptObject,
"Text");
nameBuf);
}
NS_RELEASE(node);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;

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

@ -300,6 +300,8 @@ nsGenericElement::GetPreviousSibling(nsIDOMNode** aNode)
}
}
}
// XXX Nodes that are just below the document (their parent is the
// document) need to go to the document to find their previous sibling.
*aNode = nsnull;
return NS_OK;
}
@ -321,6 +323,8 @@ nsGenericElement::GetNextSibling(nsIDOMNode** aNextSibling)
}
}
}
// XXX Nodes that are just below the document (their parent is the
// document) need to go to the document to find their next sibling.
*aNextSibling = nsnull;
return NS_OK;
}

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

@ -185,7 +185,12 @@ NameSpaceImpl::FindNameSpaceID(nsIAtom* aPrefix, PRInt32& aNameSpaceID) const
nameSpace = nameSpace->mParent;
}
while (nsnull != nameSpace);
aNameSpaceID = kNameSpaceID_Unknown;
if (nsnull == aPrefix) {
aNameSpaceID = kNameSpaceID_None;
}
else {
aNameSpaceID = kNameSpaceID_Unknown;
}
return NS_ERROR_ILLEGAL_VALUE;
}

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

@ -484,13 +484,19 @@ nsXMLContentSink::PushNameSpacesFrom(const nsIParserNode& aNode)
// Look for "xmlns" at the start of the attribute name
offset = k.Find(kNameSpaceDef);
if (0 == offset) {
PRUnichar next = k.CharAt(sizeof(kNameSpaceDef)-1);
// If the next character is a :, there is a namespace prefix
if (':' == next) {
k.Right(prefix, k.Length()-sizeof(kNameSpaceDef));
if (k.Length() == (sizeof(kNameSpaceDef)-1)) {
// If there's nothing left, this is a default namespace
prefix.Truncate();
}
else {
prefix.Truncate();
PRUnichar next = k.CharAt(sizeof(kNameSpaceDef)-1);
// If the next character is a :, there is a namespace prefix
if (':' == next) {
k.Right(prefix, k.Length()-sizeof(kNameSpaceDef));
}
else {
continue;
}
}
// Get the attribute value (the URI for the namespace)
@ -1243,10 +1249,7 @@ nsXMLContentSink::AddEntityReference(const nsIParserNode& aNode)
PRInt32
nsXMLContentSink::GetNameSpaceId(nsIAtom* aPrefix)
{
if (nsnull == aPrefix) {
return kNameSpaceID_None;
}
PRInt32 id = kNameSpaceID_Unknown;
PRInt32 id = (nsnull == aPrefix) ? kNameSpaceID_None : kNameSpaceID_Unknown;
if ((nsnull != mNameSpaceStack) && (0 < mNameSpaceStack->Count())) {
PRInt32 index = mNameSpaceStack->Count() - 1;
nsINameSpace* nameSpace = (nsINameSpace*)mNameSpaceStack->ElementAt(index);
@ -1409,19 +1412,19 @@ nsXMLContentSink::EvaluateScript(nsString& aScript, PRUint32 aLineNo)
return rv;
}
nsIURL* mDocURL = mDocument->GetDocumentURL();
const char* mURL;
if (mDocURL) {
(void)mDocURL->GetSpec(&mURL);
nsIURL* docURL = mDocument->GetDocumentURL();
const char* url;
if (docURL) {
(void)docURL->GetSpec(&url);
}
nsAutoString val;
PRBool isUndefined;
PRBool result = context->EvaluateString(aScript, mURL, aLineNo,
PRBool result = context->EvaluateString(aScript, url, aLineNo,
val, &isUndefined);
NS_IF_RELEASE(mDocURL);
NS_IF_RELEASE(docURL);
NS_RELEASE(context);
NS_RELEASE(owner);

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

@ -3,6 +3,10 @@
<!DOCTYPE Book SYSTEM "docbook.dtd">
<Book> <Title>SoftQuad
Inc.</Title>
<p xmlns="http://www.w3.org/TR/REC-html40" xmlns:h="http://www.w3.org/TR/REC-html40">
<h:img src="flamer.gif"/>
<img src="flamer.gif"/>
</p>
<BookInfo> <BookBiblio> <Title>Demo Product Documentation</Title>
<AuthorGroup><CorpAuthor>SoftQuad Inc.</CorpAuthor></AuthorGroup>
</BookBiblio> </BookInfo> <Preface> <Title><Anchor

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