Replace internal HTML Doctype API with the DOM DocumentType API, HTML documents now get a DOM DocumentType if the file contains one and the DOM DocumentType is ouput if/when the document is saved. This fixes bug #25020.

This commit is contained in:
jst@netscape.com
2000-03-28 23:25:26 +00:00
parent 3e75aeaee2
commit 79bb02c6d8
10 changed files with 364 additions and 244 deletions

View File

@@ -198,7 +198,6 @@ nsHTMLDocument::nsHTMLDocument()
mParser = nsnull;
mDTDMode = eDTDMode_Nav;
mCSSLoader = nsnull;
mDocTypeStr=nsnull;
// Find/Search Init
mSearchStr = nsnull;
@@ -260,10 +259,6 @@ nsHTMLDocument::~nsHTMLDocument()
mCSSLoader->DropDocumentReference(); // release weak ref
NS_RELEASE(mCSSLoader);
}
if (nsnull != mDocTypeStr) {
delete mDocTypeStr;
mDocTypeStr = nsnull;
}
// These will be converted to a nsDeque
delete[] mParentStack;
@@ -1055,106 +1050,6 @@ nsHTMLDocument::SetDTDMode(nsDTDMode aMode)
return NS_OK;
}
NS_IMETHODIMP
nsHTMLDocument::GetDocTypeStr(nsString& aDocTypeString)
{
if(mDocTypeStr) aDocTypeString = *mDocTypeStr;
return NS_OK;
}
NS_IMETHODIMP
nsHTMLDocument::AddDocTypeDecl(const nsString& aDocTypeString, nsDTDMode aMode)
{
nsresult result=NS_OK;
result=SetDTDMode(aMode);
if(result==NS_OK) {
if (mDocTypeStr == nsnull) {
if(aDocTypeString.Length()>0) {
mDocTypeStr = new nsString(aDocTypeString);
if (mDocTypeStr==nsnull) result=NS_ERROR_OUT_OF_MEMORY;
}
}
else {
mDocTypeStr->SetLength(0);
mDocTypeStr->Append(aDocTypeString);
}
}
PRInt32 pos = aDocTypeString.Find("public", PR_TRUE);
nsAutoString publicId;
if (pos >= 0) {
aDocTypeString.Mid(publicId, pos + 6, aDocTypeString.Length() - pos);
publicId.CompressWhitespace();
PRUnichar ch = publicId.First();
if (ch == '"' || ch == '\'') {
publicId.Cut(0, 1);
pos = publicId.FindChar(ch);
if (pos >= 0) {
publicId.Truncate(pos);
} else {
publicId.Truncate();
}
}
}
if (publicId.Length()) {
nsCOMPtr<nsIDOMDocumentType> oldDocType;
nsCOMPtr<nsIDOMDocumentType> docType;
GetDoctype(getter_AddRefs(oldDocType));
nsCOMPtr<nsIDOMDOMImplementation> domImpl;
result = GetImplementation(getter_AddRefs(domImpl));
if (NS_FAILED(result) || !domImpl) {
return result;
}
result = domImpl->CreateDocumentType(nsAutoString("html"), publicId,
nsAutoString(""),
getter_AddRefs(docType));
if (NS_FAILED(result) || !docType) {
return result;
}
nsCOMPtr<nsIDOMNode> tmpNode;
if (oldDocType) {
/*
* If we already have a doctype we replace the old one.
*/
result = ReplaceChild(oldDocType, docType, getter_AddRefs(tmpNode));
} else {
/*
* If we don't already have one we insert it as the first child,
* this might not be 100% correct but since this is called from
* the content sink we assume that this is what we want.
*/
nsCOMPtr<nsIDOMNode> firstChild;
GetFirstChild(getter_AddRefs(firstChild));
/*
* If the above fails it must be because we don't have any child
* nodes, then firstChild will be 0 and InsertBefore() will append
*/
result = InsertBefore(docType, firstChild, getter_AddRefs(tmpNode));
}
}
return result;
}
NS_IMETHODIMP
nsHTMLDocument::SetHeaderData(nsIAtom* aHeaderField, const nsString& aData)
{