From 2ec53e1f90df2ed4558808c3f72c2008ace1937c Mon Sep 17 00:00:00 2001 From: "jfrancis%netscape.com" Date: Mon, 19 Jul 1999 22:49:21 +0000 Subject: [PATCH] assorted work to expose nav html dtd to the editor --- editor/base/nsEditor.cpp | 28 +++++++++ editor/base/nsEditor.h | 5 ++ editor/base/nsHTMLEditRules.cpp | 14 ++++- editor/base/nsHTMLEditor.cpp | 72 +++++----------------- editor/base/nsHTMLEditor.h | 6 +- editor/libeditor/base/nsEditor.cpp | 28 +++++++++ editor/libeditor/base/nsEditor.h | 5 ++ editor/libeditor/html/nsHTMLEditRules.cpp | 14 ++++- editor/libeditor/html/nsHTMLEditor.cpp | 72 +++++----------------- editor/libeditor/html/nsHTMLEditor.h | 6 +- htmlparser/src/CNavDTD.cpp | 10 +++ htmlparser/src/CNavDTD.h | 6 ++ htmlparser/src/COtherDTD.cpp | 9 +++ htmlparser/src/COtherDTD.h | 6 ++ htmlparser/src/CRtfDTD.cpp | 9 +++ htmlparser/src/CRtfDTD.h | 7 +++ htmlparser/src/nsIDTD.h | 8 +++ htmlparser/src/nsParserCIID.h | 3 + htmlparser/src/nsParserFactory.cpp | 8 +++ htmlparser/src/nsValidDTD.cpp | 10 +++ htmlparser/src/nsValidDTD.h | 7 +++ htmlparser/src/nsViewSourceHTML.cpp | 9 +++ htmlparser/src/nsViewSourceHTML.h | 6 ++ htmlparser/src/nsWellFormedDTD.cpp | 9 +++ parser/htmlparser/src/CNavDTD.cpp | 10 +++ parser/htmlparser/src/CNavDTD.h | 6 ++ parser/htmlparser/src/COtherDTD.cpp | 9 +++ parser/htmlparser/src/COtherDTD.h | 6 ++ parser/htmlparser/src/CRtfDTD.cpp | 9 +++ parser/htmlparser/src/CRtfDTD.h | 7 +++ parser/htmlparser/src/nsIDTD.h | 8 +++ parser/htmlparser/src/nsParserCIID.h | 3 + parser/htmlparser/src/nsParserFactory.cpp | 8 +++ parser/htmlparser/src/nsValidDTD.cpp | 10 +++ parser/htmlparser/src/nsValidDTD.h | 7 +++ parser/htmlparser/src/nsViewSourceHTML.cpp | 9 +++ parser/htmlparser/src/nsViewSourceHTML.h | 6 ++ parser/htmlparser/src/nsWellFormedDTD.cpp | 9 +++ 38 files changed, 336 insertions(+), 128 deletions(-) diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index 48c22b8bafc6..7f384ce203f5 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -499,6 +499,11 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell) mPresShell->GetPresContext(getter_AddRefs(context)); context->SetLinkHandler(0); + // Set up the DTD + // XXX - in the long run we want to get this from the document, but there + // is no way to do that right now. So we leave it null here and set + // up a nav html dtd in nsHTMLEditor::Init + // Init mEditProperty nsresult result = NS_NewEditProperty(getter_AddRefs(mEditProperty)); if (NS_FAILED(result)) { return result; } @@ -3302,6 +3307,29 @@ nsEditor::NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag) return PR_FALSE; } +PRBool +nsEditor::CanContainTag(nsIDOMNode* aParent, const nsString &aTag) +{ + // if we don't have a dtd then assume we can insert whatever want + if (!mDTD) return PR_TRUE; + + PRInt32 childTagEnum, parentTagEnum; + nsString parentStringTag; + nsString non_const_aTag(aTag); + nsresult res = mDTD->StringTagToIntTag(non_const_aTag,&childTagEnum); + if (NS_FAILED(res)) return PR_FALSE; + + nsCOMPtr parentElement = do_QueryInterface(aParent); + if (!parentElement) return PR_FALSE; + + parentElement->GetTagName(parentStringTag); + res = mDTD->StringTagToIntTag(parentStringTag,&parentTagEnum); + if (NS_FAILED(res)) return PR_FALSE; + + return mDTD->CanContain(parentTagEnum, childTagEnum); +} + + PRBool nsEditor::IsEditable(nsIDOMNode *aNode) { diff --git a/editor/base/nsEditor.h b/editor/base/nsEditor.h index 8a298fac1ac5..9446c5ff8d23 100644 --- a/editor/base/nsEditor.h +++ b/editor/base/nsEditor.h @@ -37,6 +37,7 @@ #include "nsIFileSpec.h" #include "nsIDOMCharacterData.h" #include "nsICSSStyleSheet.h" +#include "nsIDTD.h" class nsIEditActionListener; class nsIDOMCharacterData; @@ -100,6 +101,7 @@ private: nsCOMPtr mStringBundle; protected: nsIDOMDocument * mDoc; + nsCOMPtr mDTD; // Services are not nsCOMPtr friendly nsIPref* mPrefs; @@ -559,6 +561,9 @@ public: /** returns PR_TRUE if aNode is of the type implied by aTag */ static PRBool NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag); + /** returns PR_TRUE if aParent can contain a child of type aTag */ + PRBool CanContainTag(nsIDOMNode* aParent, const nsString &aTag); + /** returns PR_TRUE if aNode is an editable node */ PRBool IsEditable(nsIDOMNode *aNode); diff --git a/editor/base/nsHTMLEditRules.cpp b/editor/base/nsHTMLEditRules.cpp index 5a7d6faf590e..76009a6076e1 100644 --- a/editor/base/nsHTMLEditRules.cpp +++ b/editor/base/nsHTMLEditRules.cpp @@ -18,6 +18,7 @@ #include "nsHTMLEditRules.h" #include "nsEditor.h" +#include "nsHTMLEditor.h" #include "nsTextEditor.h" #include "PlaceholderTxn.h" #include "InsertTextTxn.h" @@ -747,9 +748,16 @@ nsHTMLEditRules::WillIndent(nsIDOMSelection *aSelection, PRBool *aCancel) if (!curQuote || transitionList[i]) { nsAutoString quoteType("blockquote"); - res = mEditor->CreateNode(quoteType, curParent, offset, getter_AddRefs(curQuote)); - if (NS_FAILED(res)) return res; - // curQuote is now the correct thing to put curNode in + if (mEditor->CanContainTag(curParent,quoteType)) + { + res = mEditor->CreateNode(quoteType, curParent, offset, getter_AddRefs(curQuote)); + if (NS_FAILED(res)) return res; + // curQuote is now the correct thing to put curNode in + } + else + { + printf("trying to put a blockquote in a bad place\n"); + } } // tuck the node into the end of the active blockquote diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index 7c2791781ffd..840a7cddf07f 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -63,6 +63,12 @@ const unsigned char nbsp = 160; #include "nsJSEditorLog.h" #endif // ENABLE_JS_EDITOR_LOG +// HACK - CID for NavDTD until we can get at dtd via the document +// {a6cf9107-15b3-11d2-932e-00805f8add32} +#define NS_CNAVDTD_CID \ +{ 0xa6cf9107, 0x15b3, 0x11d2, { 0x93, 0x2e, 0x0, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } +static NS_DEFINE_CID(kCNavDTDCID, NS_CNAVDTD_CID); + static NS_DEFINE_CID(kEditorCID, NS_EDITOR_CID); static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID); static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID); @@ -129,7 +135,16 @@ NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsresult res=NS_ERROR_NULL_POINTER; if ((nsnull!=aDoc) && (nsnull!=aPresShell)) { - return nsTextEditor::Init(aDoc, aPresShell); + res = nsTextEditor::Init(aDoc, aPresShell); + if (NS_SUCCEEDED(res)) + { + // Set up a DTD XXX XXX + // HACK: This should have happened in a document specific way + // in nsEditor::Init(), but we dont' have a way to do that yet + res = nsComponentManager::CreateInstance(kCNavDTDCID, nsnull, + nsIDTD::GetIID(), getter_AddRefs(mDTD)); + if (!mDTD) res = NS_ERROR_FAILURE; + } } return res; } @@ -2233,12 +2248,6 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* return res; } -NS_IMETHODIMP -nsHTMLEditor::CanContainElement(nsIDOMNode* aParent, nsIDOMElement* aElement) -{ - return NS_OK; -} - NS_IMETHODIMP nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) { @@ -2752,55 +2761,6 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList) #endif } -PRBool -nsHTMLEditor::CanContainTag(nsIDOMNode* aParent, const nsString &aTag) -{ - if (!aParent) return PR_FALSE; - - static nsAutoString ulTag = "ul"; - static nsAutoString olTag = "ol"; - static nsAutoString liTag = "li"; - static nsAutoString bodyTag = "body"; - static nsAutoString tdTag = "td"; - static nsAutoString thTag = "th"; - static nsAutoString bqTag = "blockquote"; - - nsCOMPtr pTagAtom = GetTag(aParent); - nsAutoString pTag; - pTagAtom->ToString(pTag); - - // flesh this out... - // for now, only lists and blockquotes are using this funct - - if (aTag.EqualsIgnoreCase(ulTag) || - aTag.EqualsIgnoreCase(olTag) ) - { - if (pTag.EqualsIgnoreCase(bodyTag) || - pTag.EqualsIgnoreCase(tdTag) || - pTag.EqualsIgnoreCase(thTag) || - pTag.EqualsIgnoreCase(ulTag) || - pTag.EqualsIgnoreCase(olTag) || - pTag.EqualsIgnoreCase(liTag) || - pTag.EqualsIgnoreCase(bqTag) ) - { - return PR_TRUE; - } - } - else if (aTag.EqualsIgnoreCase(bqTag) ) - { - if (pTag.EqualsIgnoreCase(bodyTag) || - pTag.EqualsIgnoreCase(tdTag) || - pTag.EqualsIgnoreCase(thTag) || - pTag.EqualsIgnoreCase(liTag) || - pTag.EqualsIgnoreCase(bqTag) ) - { - return PR_TRUE; - } - } - return PR_FALSE; -} - - NS_IMETHODIMP nsHTMLEditor::IsRootTag(nsString &aTag, PRBool &aIsTag) { diff --git a/editor/base/nsHTMLEditor.h b/editor/base/nsHTMLEditor.h index 9557bf36c250..be1f87922315 100644 --- a/editor/base/nsHTMLEditor.h +++ b/editor/base/nsHTMLEditor.h @@ -155,7 +155,6 @@ public: // This should replace InsertLink and InsertImage once it is working NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn); NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn); - NS_IMETHOD CanContainElement(nsIDOMNode* aParent, nsIDOMElement* aElement); NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection); NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement); NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); @@ -185,10 +184,9 @@ public: NS_IMETHOD DeleteTableRow(PRInt32 aNumber); NS_IMETHOD JoinTableCells(PRBool aCellToRight); -// Data members protected: - + // rules initialization virtual void InitRules(); @@ -216,8 +214,6 @@ protected: NS_IMETHOD RemoveParentFromBlockContent(const nsString &aParentTag, nsIDOMRange *aRange); - PRBool CanContainTag(nsIDOMNode* aParent, const nsString &aTag); - NS_IMETHOD IsRootTag(nsString &aTag, PRBool &aIsTag); NS_IMETHOD IsSubordinateBlock(nsString &aTag, PRBool &aIsTag); diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 48c22b8bafc6..7f384ce203f5 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -499,6 +499,11 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell) mPresShell->GetPresContext(getter_AddRefs(context)); context->SetLinkHandler(0); + // Set up the DTD + // XXX - in the long run we want to get this from the document, but there + // is no way to do that right now. So we leave it null here and set + // up a nav html dtd in nsHTMLEditor::Init + // Init mEditProperty nsresult result = NS_NewEditProperty(getter_AddRefs(mEditProperty)); if (NS_FAILED(result)) { return result; } @@ -3302,6 +3307,29 @@ nsEditor::NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag) return PR_FALSE; } +PRBool +nsEditor::CanContainTag(nsIDOMNode* aParent, const nsString &aTag) +{ + // if we don't have a dtd then assume we can insert whatever want + if (!mDTD) return PR_TRUE; + + PRInt32 childTagEnum, parentTagEnum; + nsString parentStringTag; + nsString non_const_aTag(aTag); + nsresult res = mDTD->StringTagToIntTag(non_const_aTag,&childTagEnum); + if (NS_FAILED(res)) return PR_FALSE; + + nsCOMPtr parentElement = do_QueryInterface(aParent); + if (!parentElement) return PR_FALSE; + + parentElement->GetTagName(parentStringTag); + res = mDTD->StringTagToIntTag(parentStringTag,&parentTagEnum); + if (NS_FAILED(res)) return PR_FALSE; + + return mDTD->CanContain(parentTagEnum, childTagEnum); +} + + PRBool nsEditor::IsEditable(nsIDOMNode *aNode) { diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index 8a298fac1ac5..9446c5ff8d23 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -37,6 +37,7 @@ #include "nsIFileSpec.h" #include "nsIDOMCharacterData.h" #include "nsICSSStyleSheet.h" +#include "nsIDTD.h" class nsIEditActionListener; class nsIDOMCharacterData; @@ -100,6 +101,7 @@ private: nsCOMPtr mStringBundle; protected: nsIDOMDocument * mDoc; + nsCOMPtr mDTD; // Services are not nsCOMPtr friendly nsIPref* mPrefs; @@ -559,6 +561,9 @@ public: /** returns PR_TRUE if aNode is of the type implied by aTag */ static PRBool NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag); + /** returns PR_TRUE if aParent can contain a child of type aTag */ + PRBool CanContainTag(nsIDOMNode* aParent, const nsString &aTag); + /** returns PR_TRUE if aNode is an editable node */ PRBool IsEditable(nsIDOMNode *aNode); diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index 5a7d6faf590e..76009a6076e1 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -18,6 +18,7 @@ #include "nsHTMLEditRules.h" #include "nsEditor.h" +#include "nsHTMLEditor.h" #include "nsTextEditor.h" #include "PlaceholderTxn.h" #include "InsertTextTxn.h" @@ -747,9 +748,16 @@ nsHTMLEditRules::WillIndent(nsIDOMSelection *aSelection, PRBool *aCancel) if (!curQuote || transitionList[i]) { nsAutoString quoteType("blockquote"); - res = mEditor->CreateNode(quoteType, curParent, offset, getter_AddRefs(curQuote)); - if (NS_FAILED(res)) return res; - // curQuote is now the correct thing to put curNode in + if (mEditor->CanContainTag(curParent,quoteType)) + { + res = mEditor->CreateNode(quoteType, curParent, offset, getter_AddRefs(curQuote)); + if (NS_FAILED(res)) return res; + // curQuote is now the correct thing to put curNode in + } + else + { + printf("trying to put a blockquote in a bad place\n"); + } } // tuck the node into the end of the active blockquote diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 7c2791781ffd..840a7cddf07f 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -63,6 +63,12 @@ const unsigned char nbsp = 160; #include "nsJSEditorLog.h" #endif // ENABLE_JS_EDITOR_LOG +// HACK - CID for NavDTD until we can get at dtd via the document +// {a6cf9107-15b3-11d2-932e-00805f8add32} +#define NS_CNAVDTD_CID \ +{ 0xa6cf9107, 0x15b3, 0x11d2, { 0x93, 0x2e, 0x0, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } +static NS_DEFINE_CID(kCNavDTDCID, NS_CNAVDTD_CID); + static NS_DEFINE_CID(kEditorCID, NS_EDITOR_CID); static NS_DEFINE_CID(kTextEditorCID, NS_TEXTEDITOR_CID); static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID); @@ -129,7 +135,16 @@ NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsresult res=NS_ERROR_NULL_POINTER; if ((nsnull!=aDoc) && (nsnull!=aPresShell)) { - return nsTextEditor::Init(aDoc, aPresShell); + res = nsTextEditor::Init(aDoc, aPresShell); + if (NS_SUCCEEDED(res)) + { + // Set up a DTD XXX XXX + // HACK: This should have happened in a document specific way + // in nsEditor::Init(), but we dont' have a way to do that yet + res = nsComponentManager::CreateInstance(kCNavDTDCID, nsnull, + nsIDTD::GetIID(), getter_AddRefs(mDTD)); + if (!mDTD) res = NS_ERROR_FAILURE; + } } return res; } @@ -2233,12 +2248,6 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* return res; } -NS_IMETHODIMP -nsHTMLEditor::CanContainElement(nsIDOMNode* aParent, nsIDOMElement* aElement) -{ - return NS_OK; -} - NS_IMETHODIMP nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) { @@ -2752,55 +2761,6 @@ nsHTMLEditor::GetEmbeddedObjects(nsISupportsArray** aNodeList) #endif } -PRBool -nsHTMLEditor::CanContainTag(nsIDOMNode* aParent, const nsString &aTag) -{ - if (!aParent) return PR_FALSE; - - static nsAutoString ulTag = "ul"; - static nsAutoString olTag = "ol"; - static nsAutoString liTag = "li"; - static nsAutoString bodyTag = "body"; - static nsAutoString tdTag = "td"; - static nsAutoString thTag = "th"; - static nsAutoString bqTag = "blockquote"; - - nsCOMPtr pTagAtom = GetTag(aParent); - nsAutoString pTag; - pTagAtom->ToString(pTag); - - // flesh this out... - // for now, only lists and blockquotes are using this funct - - if (aTag.EqualsIgnoreCase(ulTag) || - aTag.EqualsIgnoreCase(olTag) ) - { - if (pTag.EqualsIgnoreCase(bodyTag) || - pTag.EqualsIgnoreCase(tdTag) || - pTag.EqualsIgnoreCase(thTag) || - pTag.EqualsIgnoreCase(ulTag) || - pTag.EqualsIgnoreCase(olTag) || - pTag.EqualsIgnoreCase(liTag) || - pTag.EqualsIgnoreCase(bqTag) ) - { - return PR_TRUE; - } - } - else if (aTag.EqualsIgnoreCase(bqTag) ) - { - if (pTag.EqualsIgnoreCase(bodyTag) || - pTag.EqualsIgnoreCase(tdTag) || - pTag.EqualsIgnoreCase(thTag) || - pTag.EqualsIgnoreCase(liTag) || - pTag.EqualsIgnoreCase(bqTag) ) - { - return PR_TRUE; - } - } - return PR_FALSE; -} - - NS_IMETHODIMP nsHTMLEditor::IsRootTag(nsString &aTag, PRBool &aIsTag) { diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index 9557bf36c250..be1f87922315 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -155,7 +155,6 @@ public: // This should replace InsertLink and InsertImage once it is working NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn); NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn); - NS_IMETHOD CanContainElement(nsIDOMNode* aParent, nsIDOMElement* aElement); NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection); NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement); NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); @@ -185,10 +184,9 @@ public: NS_IMETHOD DeleteTableRow(PRInt32 aNumber); NS_IMETHOD JoinTableCells(PRBool aCellToRight); -// Data members protected: - + // rules initialization virtual void InitRules(); @@ -216,8 +214,6 @@ protected: NS_IMETHOD RemoveParentFromBlockContent(const nsString &aParentTag, nsIDOMRange *aRange); - PRBool CanContainTag(nsIDOMNode* aParent, const nsString &aTag); - NS_IMETHOD IsRootTag(nsString &aTag, PRBool &aIsTag); NS_IMETHOD IsSubordinateBlock(nsString &aTag, PRBool &aIsTag); diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index 654ec02e0cd6..13022348f39c 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -1778,6 +1778,16 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const { return gHTMLElements[aParent].CanContain((eHTMLTags)aChild); } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP CNavDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + *aIntTag = nsHTMLTags::LookupTag(aTag); + return NS_OK; +} + /** * This method is called to determine whether or not * the necessary intermediate tags should be propagated diff --git a/htmlparser/src/CNavDTD.h b/htmlparser/src/CNavDTD.h index 1bf371184ecd..3e4d1cf352ae 100644 --- a/htmlparser/src/CNavDTD.h +++ b/htmlparser/src/CNavDTD.h @@ -369,6 +369,12 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { */ virtual PRInt32 GetTopmostIndexOf(eHTMLTags aTagSet[],PRInt32 aCount) const; + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const; + /** * The following methods are use to create and manage diff --git a/htmlparser/src/COtherDTD.cpp b/htmlparser/src/COtherDTD.cpp index 5bb426bcd50b..b67f93c33ac8 100644 --- a/htmlparser/src/COtherDTD.cpp +++ b/htmlparser/src/COtherDTD.cpp @@ -306,6 +306,15 @@ PRBool COtherDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const { } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP COtherDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + return CNavDTD::StringTagToIntTag(aTag, aIntTag); +} + /** * This method gets called to determine whether a given * tag can contain newlines. Most do not. diff --git a/htmlparser/src/COtherDTD.h b/htmlparser/src/COtherDTD.h index 6e63a61fa598..3a418bab43f7 100644 --- a/htmlparser/src/COtherDTD.h +++ b/htmlparser/src/COtherDTD.h @@ -121,6 +121,12 @@ class COtherDTD : public CNavDTD { */ virtual PRBool CanOmit(eHTMLTags aParent,eHTMLTags aChild)const; + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag)const; + /** * This method gets called when a start token has been consumed and needs * to be handled (possibly added to content model via sink). diff --git a/htmlparser/src/CRtfDTD.cpp b/htmlparser/src/CRtfDTD.cpp index 70711243df7f..cbe44c925765 100644 --- a/htmlparser/src/CRtfDTD.cpp +++ b/htmlparser/src/CRtfDTD.cpp @@ -370,6 +370,15 @@ PRBool CRtfDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const{ return result; } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP CRtfDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + /** * * @update gess 3/25/98 diff --git a/htmlparser/src/CRtfDTD.h b/htmlparser/src/CRtfDTD.h index 5d7153d73ecf..eb0696245ab4 100644 --- a/htmlparser/src/CRtfDTD.h +++ b/htmlparser/src/CRtfDTD.h @@ -337,6 +337,13 @@ class CRtfDTD : public nsIDTD { * @return ptr to recycler (or null) */ virtual nsITokenRecycler* GetTokenRecycler(void); + + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const; + protected: diff --git a/htmlparser/src/nsIDTD.h b/htmlparser/src/nsIDTD.h index 5d5d4147d804..6bca3fe8b10d 100644 --- a/htmlparser/src/nsIDTD.h +++ b/htmlparser/src/nsIDTD.h @@ -199,6 +199,14 @@ class nsIDTD : public nsISupports { * @return */ virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser)=0; + +/* XXX Temporary measure, pending further work by RickG */ + + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const =0; }; diff --git a/htmlparser/src/nsParserCIID.h b/htmlparser/src/nsParserCIID.h index b2c7a4a1abef..4e2035cd79ea 100644 --- a/htmlparser/src/nsParserCIID.h +++ b/htmlparser/src/nsParserCIID.h @@ -37,5 +37,8 @@ #define NS_WELLFORMEDDTD_CID \ { 0xe6fd9941, 0x899d, 0x11d2, { 0x8e, 0xae, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } } +// {a6cf9107-15b3-11d2-932e-00805f8add32} +#define NS_CNAVDTD_CID \ +{ 0xa6cf9107, 0x15b3, 0x11d2, { 0x93, 0x2e, 0x0, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } #endif diff --git a/htmlparser/src/nsParserFactory.cpp b/htmlparser/src/nsParserFactory.cpp index 0f727ca98665..3d4cc495f685 100644 --- a/htmlparser/src/nsParserFactory.cpp +++ b/htmlparser/src/nsParserFactory.cpp @@ -25,6 +25,7 @@ #include "nsParser.h" #include "nsParserNode.h" #include "nsWellFormedDTD.h" +#include "CNavDTD.h" #include "nsHTMLTags.h" #include "nsHTMLEntities.h" @@ -36,6 +37,7 @@ static NS_DEFINE_IID(kCParser, NS_PARSER_IID); static NS_DEFINE_IID(kCParserNode, NS_PARSER_NODE_IID); static NS_DEFINE_IID(kLoggingSinkCID, NS_LOGGING_SINK_IID); static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID); +static NS_DEFINE_CID(kCNavDTDCID, NS_CNAVDTD_CID); class nsParserFactory : public nsIFactory { @@ -151,6 +153,12 @@ nsresult nsParserFactory::CreateInstance(nsISupports *aOuter, return rv; } } + else if (mClassID.Equals(kCNavDTDCID)) { + nsresult rv = NS_NewNavHTMLDTD((nsIDTD**) &inst); + if (NS_FAILED(rv)) { + return rv; + } + } if (inst == NULL) { return NS_ERROR_OUT_OF_MEMORY; diff --git a/htmlparser/src/nsValidDTD.cpp b/htmlparser/src/nsValidDTD.cpp index 256b7800f8c7..6f108046421c 100644 --- a/htmlparser/src/nsValidDTD.cpp +++ b/htmlparser/src/nsValidDTD.cpp @@ -296,6 +296,16 @@ PRBool CValidDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const{ return result; } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP CValidDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + /** * This method gets called to determine whether a given * tag is itself a container diff --git a/htmlparser/src/nsValidDTD.h b/htmlparser/src/nsValidDTD.h index 728ac54238a4..073cd1167bbb 100644 --- a/htmlparser/src/nsValidDTD.h +++ b/htmlparser/src/nsValidDTD.h @@ -230,6 +230,13 @@ class CValidDTD : public nsIDTD { * @return ptr to recycler (or null) */ virtual nsITokenRecycler* GetTokenRecycler(void); + + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const; + protected: diff --git a/htmlparser/src/nsViewSourceHTML.cpp b/htmlparser/src/nsViewSourceHTML.cpp index 6ecd072c9c4c..60df387d4cb3 100644 --- a/htmlparser/src/nsViewSourceHTML.cpp +++ b/htmlparser/src/nsViewSourceHTML.cpp @@ -544,6 +544,15 @@ PRBool CViewSourceHTML::CanContain(PRInt32 aParent,PRInt32 aChild) const{ return result; } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP CViewSourceHTML::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + /** * This method gets called to determine whether a given * tag is itself a container diff --git a/htmlparser/src/nsViewSourceHTML.h b/htmlparser/src/nsViewSourceHTML.h index 8d8f31843899..3f492cd941a1 100644 --- a/htmlparser/src/nsViewSourceHTML.h +++ b/htmlparser/src/nsViewSourceHTML.h @@ -214,6 +214,12 @@ class CViewSourceHTML: public nsIDTD { */ virtual PRBool CanContain(PRInt32 aParent,PRInt32 aChild) const; + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const; + /** * This method gets called to determine whether a given * tag is itself a container diff --git a/htmlparser/src/nsWellFormedDTD.cpp b/htmlparser/src/nsWellFormedDTD.cpp index 82e26146297b..94528f6d2ede 100644 --- a/htmlparser/src/nsWellFormedDTD.cpp +++ b/htmlparser/src/nsWellFormedDTD.cpp @@ -397,6 +397,15 @@ PRBool CWellFormedDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const{ return result; } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP CWellFormedDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + /** * This method gets called to determine whether a given * tag is itself a container diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index 654ec02e0cd6..13022348f39c 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -1778,6 +1778,16 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const { return gHTMLElements[aParent].CanContain((eHTMLTags)aChild); } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP CNavDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + *aIntTag = nsHTMLTags::LookupTag(aTag); + return NS_OK; +} + /** * This method is called to determine whether or not * the necessary intermediate tags should be propagated diff --git a/parser/htmlparser/src/CNavDTD.h b/parser/htmlparser/src/CNavDTD.h index 1bf371184ecd..3e4d1cf352ae 100644 --- a/parser/htmlparser/src/CNavDTD.h +++ b/parser/htmlparser/src/CNavDTD.h @@ -369,6 +369,12 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { */ virtual PRInt32 GetTopmostIndexOf(eHTMLTags aTagSet[],PRInt32 aCount) const; + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const; + /** * The following methods are use to create and manage diff --git a/parser/htmlparser/src/COtherDTD.cpp b/parser/htmlparser/src/COtherDTD.cpp index 5bb426bcd50b..b67f93c33ac8 100644 --- a/parser/htmlparser/src/COtherDTD.cpp +++ b/parser/htmlparser/src/COtherDTD.cpp @@ -306,6 +306,15 @@ PRBool COtherDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const { } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP COtherDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + return CNavDTD::StringTagToIntTag(aTag, aIntTag); +} + /** * This method gets called to determine whether a given * tag can contain newlines. Most do not. diff --git a/parser/htmlparser/src/COtherDTD.h b/parser/htmlparser/src/COtherDTD.h index 6e63a61fa598..3a418bab43f7 100644 --- a/parser/htmlparser/src/COtherDTD.h +++ b/parser/htmlparser/src/COtherDTD.h @@ -121,6 +121,12 @@ class COtherDTD : public CNavDTD { */ virtual PRBool CanOmit(eHTMLTags aParent,eHTMLTags aChild)const; + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag)const; + /** * This method gets called when a start token has been consumed and needs * to be handled (possibly added to content model via sink). diff --git a/parser/htmlparser/src/CRtfDTD.cpp b/parser/htmlparser/src/CRtfDTD.cpp index 70711243df7f..cbe44c925765 100644 --- a/parser/htmlparser/src/CRtfDTD.cpp +++ b/parser/htmlparser/src/CRtfDTD.cpp @@ -370,6 +370,15 @@ PRBool CRtfDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const{ return result; } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP CRtfDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + /** * * @update gess 3/25/98 diff --git a/parser/htmlparser/src/CRtfDTD.h b/parser/htmlparser/src/CRtfDTD.h index 5d7153d73ecf..eb0696245ab4 100644 --- a/parser/htmlparser/src/CRtfDTD.h +++ b/parser/htmlparser/src/CRtfDTD.h @@ -337,6 +337,13 @@ class CRtfDTD : public nsIDTD { * @return ptr to recycler (or null) */ virtual nsITokenRecycler* GetTokenRecycler(void); + + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const; + protected: diff --git a/parser/htmlparser/src/nsIDTD.h b/parser/htmlparser/src/nsIDTD.h index 5d5d4147d804..6bca3fe8b10d 100644 --- a/parser/htmlparser/src/nsIDTD.h +++ b/parser/htmlparser/src/nsIDTD.h @@ -199,6 +199,14 @@ class nsIDTD : public nsISupports { * @return */ virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser)=0; + +/* XXX Temporary measure, pending further work by RickG */ + + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const =0; }; diff --git a/parser/htmlparser/src/nsParserCIID.h b/parser/htmlparser/src/nsParserCIID.h index b2c7a4a1abef..4e2035cd79ea 100644 --- a/parser/htmlparser/src/nsParserCIID.h +++ b/parser/htmlparser/src/nsParserCIID.h @@ -37,5 +37,8 @@ #define NS_WELLFORMEDDTD_CID \ { 0xe6fd9941, 0x899d, 0x11d2, { 0x8e, 0xae, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } } +// {a6cf9107-15b3-11d2-932e-00805f8add32} +#define NS_CNAVDTD_CID \ +{ 0xa6cf9107, 0x15b3, 0x11d2, { 0x93, 0x2e, 0x0, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } #endif diff --git a/parser/htmlparser/src/nsParserFactory.cpp b/parser/htmlparser/src/nsParserFactory.cpp index 0f727ca98665..3d4cc495f685 100644 --- a/parser/htmlparser/src/nsParserFactory.cpp +++ b/parser/htmlparser/src/nsParserFactory.cpp @@ -25,6 +25,7 @@ #include "nsParser.h" #include "nsParserNode.h" #include "nsWellFormedDTD.h" +#include "CNavDTD.h" #include "nsHTMLTags.h" #include "nsHTMLEntities.h" @@ -36,6 +37,7 @@ static NS_DEFINE_IID(kCParser, NS_PARSER_IID); static NS_DEFINE_IID(kCParserNode, NS_PARSER_NODE_IID); static NS_DEFINE_IID(kLoggingSinkCID, NS_LOGGING_SINK_IID); static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID); +static NS_DEFINE_CID(kCNavDTDCID, NS_CNAVDTD_CID); class nsParserFactory : public nsIFactory { @@ -151,6 +153,12 @@ nsresult nsParserFactory::CreateInstance(nsISupports *aOuter, return rv; } } + else if (mClassID.Equals(kCNavDTDCID)) { + nsresult rv = NS_NewNavHTMLDTD((nsIDTD**) &inst); + if (NS_FAILED(rv)) { + return rv; + } + } if (inst == NULL) { return NS_ERROR_OUT_OF_MEMORY; diff --git a/parser/htmlparser/src/nsValidDTD.cpp b/parser/htmlparser/src/nsValidDTD.cpp index 256b7800f8c7..6f108046421c 100644 --- a/parser/htmlparser/src/nsValidDTD.cpp +++ b/parser/htmlparser/src/nsValidDTD.cpp @@ -296,6 +296,16 @@ PRBool CValidDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const{ return result; } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP CValidDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + /** * This method gets called to determine whether a given * tag is itself a container diff --git a/parser/htmlparser/src/nsValidDTD.h b/parser/htmlparser/src/nsValidDTD.h index 728ac54238a4..073cd1167bbb 100644 --- a/parser/htmlparser/src/nsValidDTD.h +++ b/parser/htmlparser/src/nsValidDTD.h @@ -230,6 +230,13 @@ class CValidDTD : public nsIDTD { * @return ptr to recycler (or null) */ virtual nsITokenRecycler* GetTokenRecycler(void); + + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const; + protected: diff --git a/parser/htmlparser/src/nsViewSourceHTML.cpp b/parser/htmlparser/src/nsViewSourceHTML.cpp index 6ecd072c9c4c..60df387d4cb3 100644 --- a/parser/htmlparser/src/nsViewSourceHTML.cpp +++ b/parser/htmlparser/src/nsViewSourceHTML.cpp @@ -544,6 +544,15 @@ PRBool CViewSourceHTML::CanContain(PRInt32 aParent,PRInt32 aChild) const{ return result; } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP CViewSourceHTML::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + /** * This method gets called to determine whether a given * tag is itself a container diff --git a/parser/htmlparser/src/nsViewSourceHTML.h b/parser/htmlparser/src/nsViewSourceHTML.h index 8d8f31843899..3f492cd941a1 100644 --- a/parser/htmlparser/src/nsViewSourceHTML.h +++ b/parser/htmlparser/src/nsViewSourceHTML.h @@ -214,6 +214,12 @@ class CViewSourceHTML: public nsIDTD { */ virtual PRBool CanContain(PRInt32 aParent,PRInt32 aChild) const; + /** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ + NS_IMETHOD StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const; + /** * This method gets called to determine whether a given * tag is itself a container diff --git a/parser/htmlparser/src/nsWellFormedDTD.cpp b/parser/htmlparser/src/nsWellFormedDTD.cpp index 82e26146297b..94528f6d2ede 100644 --- a/parser/htmlparser/src/nsWellFormedDTD.cpp +++ b/parser/htmlparser/src/nsWellFormedDTD.cpp @@ -397,6 +397,15 @@ PRBool CWellFormedDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const{ return result; } +/** + * Give rest of world access to our tag enums, so that CanContain(), etc, + * become useful. + */ +NS_IMETHODIMP CWellFormedDTD::StringTagToIntTag(nsString &aTag, PRInt32* aIntTag) const +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + /** * This method gets called to determine whether a given * tag is itself a container