diff --git a/mozilla/content/base/src/nsCommentNode.cpp b/mozilla/content/base/src/nsCommentNode.cpp index ab23cf6d1b5..872aa025f56 100644 --- a/mozilla/content/base/src/nsCommentNode.cpp +++ b/mozilla/content/base/src/nsCommentNode.cpp @@ -22,6 +22,7 @@ #include "nsIDOMEventReceiver.h" #include "nsIContent.h" #include "nsFrame.h" +#include "nsLayoutAtoms.h" static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID); @@ -100,6 +101,14 @@ nsCommentNode::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_NOINTERFACE; } +NS_IMETHODIMP +nsCommentNode::GetTag(nsIAtom*& aResult) const +{ + aResult = nsLayoutAtoms::commentTagName; + NS_ADDREF(aResult); + return NS_OK; +} + NS_IMETHODIMP nsCommentNode::GetNodeName(nsString& aNodeName) { @@ -141,7 +150,7 @@ nsCommentNode::List(FILE* out, PRInt32 aIndent) const PRInt32 index; for (index = aIndent; --index >= 0; ) fputs(" ", out); - fprintf(out, " refcount=%d<", mRefCnt); + fprintf(out, "Comment refcount=%d<", mRefCnt); nsAutoString tmp; mInner.ToCString(tmp, 0, mInner.mText.GetLength()); diff --git a/mozilla/content/base/src/nsContentList.cpp b/mozilla/content/base/src/nsContentList.cpp index 5529283d2ff..ec1a83ba16d 100644 --- a/mozilla/content/base/src/nsContentList.cpp +++ b/mozilla/content/base/src/nsContentList.cpp @@ -25,6 +25,7 @@ #include "nsIDOMScriptObjectFactory.h" #include "nsGenericElement.h" +#include "nsLayoutAtoms.h" #include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms nsIAtom* nsContentList::gWildCardAtom = nsnull; @@ -320,7 +321,8 @@ nsContentList::Match(nsIContent *aContent, PRBool *aMatch) // If we have to match all, only do those that have // a tagName i.e. only the elements. - if (mMatchAll && (nsnull != name)) { + if (mMatchAll && (nsLayoutAtoms::textTagName != name) && + (nsLayoutAtoms::commentTagName != name)) { *aMatch = PR_TRUE; } // XXX We don't yet match on namespace. Maybe we should?? diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.h b/mozilla/content/base/src/nsGenericDOMDataNode.h index 4be7305e5b5..b315ab945d4 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.h +++ b/mozilla/content/base/src/nsGenericDOMDataNode.h @@ -125,10 +125,6 @@ struct nsGenericDOMDataNode { aID = kNameSpaceID_None; return NS_OK; } - nsresult GetTag(nsIAtom*& aResult) const { - aResult = nsnull; - return NS_OK; - } nsresult ParseAttributeString(const nsString& aStr, nsIAtom*& aName, PRInt32& aNameSpaceID) { @@ -393,9 +389,7 @@ struct nsGenericDOMDataNode { NS_IMETHOD GetNameSpaceID(PRInt32& aID) const { \ return _g.GetNameSpaceID(aID); \ } \ - NS_IMETHOD GetTag(nsIAtom*& aResult) const { \ - return _g.GetTag(aResult); \ - } \ + NS_IMETHOD GetTag(nsIAtom*& aResult) const; \ NS_IMETHOD ParseAttributeString(const nsString& aStr, \ nsIAtom*& aName, \ PRInt32& aNameSpaceID) { \ diff --git a/mozilla/content/base/src/nsTextNode.cpp b/mozilla/content/base/src/nsTextNode.cpp index 5940363026d..83e6990e4a8 100644 --- a/mozilla/content/base/src/nsTextNode.cpp +++ b/mozilla/content/base/src/nsTextNode.cpp @@ -25,6 +25,7 @@ #include "nsFrame.h" #include "nsIDocument.h" #include "nsCRT.h" +#include "nsLayoutAtoms.h" static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID); @@ -124,6 +125,14 @@ nsTextNode::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_NOINTERFACE; } +NS_IMETHODIMP +nsTextNode::GetTag(nsIAtom*& aResult) const +{ + aResult = nsLayoutAtoms::textTagName; + NS_ADDREF(aResult); + return NS_OK; +} + NS_IMETHODIMP nsTextNode::GetNodeName(nsString& aNodeName) { diff --git a/mozilla/content/html/content/src/nsHTMLAtoms.cpp b/mozilla/content/html/content/src/nsHTMLAtoms.cpp index 26b844ad27d..46227164efa 100644 --- a/mozilla/content/html/content/src/nsHTMLAtoms.cpp +++ b/mozilla/content/html/content/src/nsHTMLAtoms.cpp @@ -71,6 +71,7 @@ nsIAtom* nsHTMLAtoms::colgroup; nsIAtom* nsHTMLAtoms::cols; nsIAtom* nsHTMLAtoms::colspan; nsIAtom* nsHTMLAtoms::columnPseudo; +nsIAtom* nsHTMLAtoms::commentPseudo; nsIAtom* nsHTMLAtoms::compact; nsIAtom* nsHTMLAtoms::content; nsIAtom* nsHTMLAtoms::coords; @@ -314,6 +315,7 @@ void nsHTMLAtoms::AddrefAtoms() cols = NS_NewAtom("COLS"); colspan = NS_NewAtom("COLSPAN"); columnPseudo = NS_NewAtom(":BODY-COLUMN"); + commentPseudo = NS_NewAtom(":MOZ-COMMENT"); compact = NS_NewAtom("COMPACT"); content = NS_NewAtom("CONTENT"); coords = NS_NewAtom("COORDS"); @@ -473,7 +475,7 @@ void nsHTMLAtoms::AddrefAtoms() thead = NS_NewAtom("THEAD"); text = NS_NewAtom("TEXT"); textarea = NS_NewAtom("TEXTAREA"); - textPseudo = NS_NewAtom(":TEXT"); + textPseudo = NS_NewAtom(":MOZ-TEXT"); th = NS_NewAtom("TH"); title = NS_NewAtom("TITLE"); top = NS_NewAtom("TOP"); @@ -553,6 +555,7 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(cols); NS_RELEASE(colspan); NS_RELEASE(columnPseudo); + NS_RELEASE(commentPseudo); NS_RELEASE(compact); NS_RELEASE(content); NS_RELEASE(coords); diff --git a/mozilla/content/html/content/src/nsHTMLAtoms.h b/mozilla/content/html/content/src/nsHTMLAtoms.h index e518c960719..5958fca304a 100644 --- a/mozilla/content/html/content/src/nsHTMLAtoms.h +++ b/mozilla/content/html/content/src/nsHTMLAtoms.h @@ -93,6 +93,7 @@ public: static nsIAtom* cols; static nsIAtom* colspan; static nsIAtom* columnPseudo; + static nsIAtom* commentPseudo; static nsIAtom* compact; static nsIAtom* content; static nsIAtom* coords; diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index 9a54439d62b..2a1089e7dde 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -37,6 +37,7 @@ #include "nsITextContent.h" #include "nsIDOMText.h" +#include "nsIDOMComment.h" #include "nsIDOMHTMLFormElement.h" #include "nsIDOMHTMLTextAreaElement.h" @@ -72,6 +73,7 @@ static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); static NS_DEFINE_IID(kIHTMLContentIID, NS_IHTMLCONTENT_IID); static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); +static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID); static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); static NS_DEFINE_IID(kIDOMHTMLMapElementIID, NS_IDOMHTMLMAPELEMENT_IID); static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID); @@ -262,6 +264,7 @@ public: nsresult CloseContainer(const nsIParserNode& aNode); nsresult AddLeaf(const nsIParserNode& aNode); nsresult AddLeaf(nsIHTMLContent* aContent); + nsresult AddComment(const nsIParserNode& aNode); nsresult End(); nsresult GrowStack(); @@ -1108,6 +1111,43 @@ SinkContext::AddLeaf(nsIHTMLContent* aContent) return NS_OK; } +nsresult +SinkContext::AddComment(const nsIParserNode& aNode) +{ + nsIContent *comment; + nsIDOMComment *domComment; + nsresult result = NS_OK; + + FlushText(); + + result = NS_NewCommentNode(&comment); + if (NS_OK == result) { + result = comment->QueryInterface(kIDOMCommentIID, + (void **)&domComment); + if (NS_OK == result) { + domComment->AppendData(aNode.GetText()); + NS_RELEASE(domComment); + + comment->SetDocument(mSink->mDocument, PR_FALSE); + + nsIHTMLContent* parent; + if ((nsnull == mSink->mBody) && (nsnull != mSink->mHead)) { + parent = mSink->mHead; + } + else { + parent = mStack[mStackPos - 1].mContent; + } + parent->AppendChildTo(comment, PR_FALSE); + + // Mark sink dirty if it can safely reflow something + MaybeMarkSinkDirty(); + } + NS_RELEASE(comment); + } + + return result; +} + nsresult SinkContext::End() { @@ -1877,8 +1917,7 @@ HTMLContentSink::AddLeaf(const nsIParserNode& aNode) * @return error code */ nsresult HTMLContentSink::AddComment(const nsIParserNode& aNode) { - nsresult result= NS_OK; - return result; + return mCurrentContext->AddComment(aNode); } /** diff --git a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp index 1a18a44dcc8..b2e0ea0b137 100644 --- a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp @@ -1825,7 +1825,7 @@ HTMLStyleSheetImpl::ConstructFrameByTag(nsIPresContext* aPresContext, // Initialize OUT parameter aNewFrame = nsnull; - if (nsnull == aTag) { + if (nsLayoutAtoms::textTagName == aTag) { rv = NS_NewTextFrame(aNewFrame); } else { @@ -2778,7 +2778,7 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, nsIStyleContext* parentStyleContext; aParentFrame->GetStyleContext(parentStyleContext); - if (nsnull == tag) { + if (nsLayoutAtoms::textTagName == tag) { // Use a special pseudo element style context for text nsIContent* parentContent = nsnull; if (nsnull != aParentFrame) { @@ -2789,6 +2789,18 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, parentStyleContext); rv = (nsnull == styleContext) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; NS_IF_RELEASE(parentContent); + } else if (nsLayoutAtoms::commentTagName == tag) { + // Use a special pseudo element style context for comments + nsIContent* parentContent = nsnull; + if (nsnull != aParentFrame) { + aParentFrame->GetContent(parentContent); + } + styleContext = aPresContext->ResolvePseudoStyleContextFor(parentContent, + nsHTMLAtoms::commentPseudo, + parentStyleContext); + rv = (nsnull == styleContext) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; + NS_IF_RELEASE(parentContent); + } else { styleContext = aPresContext->ResolveStyleContextFor(aContent, parentStyleContext); rv = (nsnull == styleContext) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; diff --git a/mozilla/content/shared/public/nsHTMLAtoms.h b/mozilla/content/shared/public/nsHTMLAtoms.h index e518c960719..5958fca304a 100644 --- a/mozilla/content/shared/public/nsHTMLAtoms.h +++ b/mozilla/content/shared/public/nsHTMLAtoms.h @@ -93,6 +93,7 @@ public: static nsIAtom* cols; static nsIAtom* colspan; static nsIAtom* columnPseudo; + static nsIAtom* commentPseudo; static nsIAtom* compact; static nsIAtom* content; static nsIAtom* coords; diff --git a/mozilla/content/shared/public/nsLayoutAtoms.h b/mozilla/content/shared/public/nsLayoutAtoms.h index 83837f58bd7..ea4f1585b88 100644 --- a/mozilla/content/shared/public/nsLayoutAtoms.h +++ b/mozilla/content/shared/public/nsLayoutAtoms.h @@ -55,6 +55,10 @@ public: static nsIAtom* bulletList; static nsIAtom* colGroupList; static nsIAtom* floaterList; + + // Alphabetical list of pseudo tag names for non-element content + static nsIAtom* textTagName; + static nsIAtom* commentTagName; }; #endif /* nsLayoutAtoms_h___ */ diff --git a/mozilla/content/shared/src/nsHTMLAtoms.cpp b/mozilla/content/shared/src/nsHTMLAtoms.cpp index 26b844ad27d..46227164efa 100644 --- a/mozilla/content/shared/src/nsHTMLAtoms.cpp +++ b/mozilla/content/shared/src/nsHTMLAtoms.cpp @@ -71,6 +71,7 @@ nsIAtom* nsHTMLAtoms::colgroup; nsIAtom* nsHTMLAtoms::cols; nsIAtom* nsHTMLAtoms::colspan; nsIAtom* nsHTMLAtoms::columnPseudo; +nsIAtom* nsHTMLAtoms::commentPseudo; nsIAtom* nsHTMLAtoms::compact; nsIAtom* nsHTMLAtoms::content; nsIAtom* nsHTMLAtoms::coords; @@ -314,6 +315,7 @@ void nsHTMLAtoms::AddrefAtoms() cols = NS_NewAtom("COLS"); colspan = NS_NewAtom("COLSPAN"); columnPseudo = NS_NewAtom(":BODY-COLUMN"); + commentPseudo = NS_NewAtom(":MOZ-COMMENT"); compact = NS_NewAtom("COMPACT"); content = NS_NewAtom("CONTENT"); coords = NS_NewAtom("COORDS"); @@ -473,7 +475,7 @@ void nsHTMLAtoms::AddrefAtoms() thead = NS_NewAtom("THEAD"); text = NS_NewAtom("TEXT"); textarea = NS_NewAtom("TEXTAREA"); - textPseudo = NS_NewAtom(":TEXT"); + textPseudo = NS_NewAtom(":MOZ-TEXT"); th = NS_NewAtom("TH"); title = NS_NewAtom("TITLE"); top = NS_NewAtom("TOP"); @@ -553,6 +555,7 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(cols); NS_RELEASE(colspan); NS_RELEASE(columnPseudo); + NS_RELEASE(commentPseudo); NS_RELEASE(compact); NS_RELEASE(content); NS_RELEASE(coords); diff --git a/mozilla/content/shared/src/nsLayoutAtoms.cpp b/mozilla/content/shared/src/nsLayoutAtoms.cpp index bf7865f6234..7fc641db25d 100644 --- a/mozilla/content/shared/src/nsLayoutAtoms.cpp +++ b/mozilla/content/shared/src/nsLayoutAtoms.cpp @@ -42,6 +42,8 @@ nsIAtom* nsLayoutAtoms::bulletList; nsIAtom* nsLayoutAtoms::colGroupList; nsIAtom* nsLayoutAtoms::floaterList; +nsIAtom* nsLayoutAtoms::textTagName; +nsIAtom* nsLayoutAtoms::commentTagName; static nsrefcnt gRefCnt; @@ -67,6 +69,9 @@ void nsLayoutAtoms::AddrefAtoms() bulletList = NS_NewAtom("Bullet-list"); colGroupList = NS_NewAtom("ColGroup-list"); floaterList = NS_NewAtom("Floater-list"); + + textTagName = NS_NewAtom("__moz_text"); + commentTagName = NS_NewAtom("__moz_comment"); } ++gRefCnt; } @@ -94,6 +99,9 @@ void nsLayoutAtoms::ReleaseAtoms() NS_RELEASE(bulletList); NS_RELEASE(colGroupList); NS_RELEASE(floaterList); + + NS_RELEASE(textTagName); + NS_RELEASE(commentTagName); } } diff --git a/mozilla/layout/base/nsLayoutAtoms.cpp b/mozilla/layout/base/nsLayoutAtoms.cpp index bf7865f6234..7fc641db25d 100644 --- a/mozilla/layout/base/nsLayoutAtoms.cpp +++ b/mozilla/layout/base/nsLayoutAtoms.cpp @@ -42,6 +42,8 @@ nsIAtom* nsLayoutAtoms::bulletList; nsIAtom* nsLayoutAtoms::colGroupList; nsIAtom* nsLayoutAtoms::floaterList; +nsIAtom* nsLayoutAtoms::textTagName; +nsIAtom* nsLayoutAtoms::commentTagName; static nsrefcnt gRefCnt; @@ -67,6 +69,9 @@ void nsLayoutAtoms::AddrefAtoms() bulletList = NS_NewAtom("Bullet-list"); colGroupList = NS_NewAtom("ColGroup-list"); floaterList = NS_NewAtom("Floater-list"); + + textTagName = NS_NewAtom("__moz_text"); + commentTagName = NS_NewAtom("__moz_comment"); } ++gRefCnt; } @@ -94,6 +99,9 @@ void nsLayoutAtoms::ReleaseAtoms() NS_RELEASE(bulletList); NS_RELEASE(colGroupList); NS_RELEASE(floaterList); + + NS_RELEASE(textTagName); + NS_RELEASE(commentTagName); } } diff --git a/mozilla/layout/base/nsLayoutAtoms.h b/mozilla/layout/base/nsLayoutAtoms.h index 83837f58bd7..ea4f1585b88 100644 --- a/mozilla/layout/base/nsLayoutAtoms.h +++ b/mozilla/layout/base/nsLayoutAtoms.h @@ -55,6 +55,10 @@ public: static nsIAtom* bulletList; static nsIAtom* colGroupList; static nsIAtom* floaterList; + + // Alphabetical list of pseudo tag names for non-element content + static nsIAtom* textTagName; + static nsIAtom* commentTagName; }; #endif /* nsLayoutAtoms_h___ */ diff --git a/mozilla/layout/base/public/nsLayoutAtoms.h b/mozilla/layout/base/public/nsLayoutAtoms.h index 83837f58bd7..ea4f1585b88 100644 --- a/mozilla/layout/base/public/nsLayoutAtoms.h +++ b/mozilla/layout/base/public/nsLayoutAtoms.h @@ -55,6 +55,10 @@ public: static nsIAtom* bulletList; static nsIAtom* colGroupList; static nsIAtom* floaterList; + + // Alphabetical list of pseudo tag names for non-element content + static nsIAtom* textTagName; + static nsIAtom* commentTagName; }; #endif /* nsLayoutAtoms_h___ */ diff --git a/mozilla/layout/base/src/nsCommentNode.cpp b/mozilla/layout/base/src/nsCommentNode.cpp index ab23cf6d1b5..872aa025f56 100644 --- a/mozilla/layout/base/src/nsCommentNode.cpp +++ b/mozilla/layout/base/src/nsCommentNode.cpp @@ -22,6 +22,7 @@ #include "nsIDOMEventReceiver.h" #include "nsIContent.h" #include "nsFrame.h" +#include "nsLayoutAtoms.h" static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID); @@ -100,6 +101,14 @@ nsCommentNode::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_NOINTERFACE; } +NS_IMETHODIMP +nsCommentNode::GetTag(nsIAtom*& aResult) const +{ + aResult = nsLayoutAtoms::commentTagName; + NS_ADDREF(aResult); + return NS_OK; +} + NS_IMETHODIMP nsCommentNode::GetNodeName(nsString& aNodeName) { @@ -141,7 +150,7 @@ nsCommentNode::List(FILE* out, PRInt32 aIndent) const PRInt32 index; for (index = aIndent; --index >= 0; ) fputs(" ", out); - fprintf(out, " refcount=%d<", mRefCnt); + fprintf(out, "Comment refcount=%d<", mRefCnt); nsAutoString tmp; mInner.ToCString(tmp, 0, mInner.mText.GetLength()); diff --git a/mozilla/layout/base/src/nsContentList.cpp b/mozilla/layout/base/src/nsContentList.cpp index 5529283d2ff..ec1a83ba16d 100644 --- a/mozilla/layout/base/src/nsContentList.cpp +++ b/mozilla/layout/base/src/nsContentList.cpp @@ -25,6 +25,7 @@ #include "nsIDOMScriptObjectFactory.h" #include "nsGenericElement.h" +#include "nsLayoutAtoms.h" #include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms nsIAtom* nsContentList::gWildCardAtom = nsnull; @@ -320,7 +321,8 @@ nsContentList::Match(nsIContent *aContent, PRBool *aMatch) // If we have to match all, only do those that have // a tagName i.e. only the elements. - if (mMatchAll && (nsnull != name)) { + if (mMatchAll && (nsLayoutAtoms::textTagName != name) && + (nsLayoutAtoms::commentTagName != name)) { *aMatch = PR_TRUE; } // XXX We don't yet match on namespace. Maybe we should?? diff --git a/mozilla/layout/base/src/nsGenericDOMDataNode.h b/mozilla/layout/base/src/nsGenericDOMDataNode.h index 4be7305e5b5..b315ab945d4 100644 --- a/mozilla/layout/base/src/nsGenericDOMDataNode.h +++ b/mozilla/layout/base/src/nsGenericDOMDataNode.h @@ -125,10 +125,6 @@ struct nsGenericDOMDataNode { aID = kNameSpaceID_None; return NS_OK; } - nsresult GetTag(nsIAtom*& aResult) const { - aResult = nsnull; - return NS_OK; - } nsresult ParseAttributeString(const nsString& aStr, nsIAtom*& aName, PRInt32& aNameSpaceID) { @@ -393,9 +389,7 @@ struct nsGenericDOMDataNode { NS_IMETHOD GetNameSpaceID(PRInt32& aID) const { \ return _g.GetNameSpaceID(aID); \ } \ - NS_IMETHOD GetTag(nsIAtom*& aResult) const { \ - return _g.GetTag(aResult); \ - } \ + NS_IMETHOD GetTag(nsIAtom*& aResult) const; \ NS_IMETHOD ParseAttributeString(const nsString& aStr, \ nsIAtom*& aName, \ PRInt32& aNameSpaceID) { \ diff --git a/mozilla/layout/base/src/nsLayoutAtoms.cpp b/mozilla/layout/base/src/nsLayoutAtoms.cpp index bf7865f6234..7fc641db25d 100644 --- a/mozilla/layout/base/src/nsLayoutAtoms.cpp +++ b/mozilla/layout/base/src/nsLayoutAtoms.cpp @@ -42,6 +42,8 @@ nsIAtom* nsLayoutAtoms::bulletList; nsIAtom* nsLayoutAtoms::colGroupList; nsIAtom* nsLayoutAtoms::floaterList; +nsIAtom* nsLayoutAtoms::textTagName; +nsIAtom* nsLayoutAtoms::commentTagName; static nsrefcnt gRefCnt; @@ -67,6 +69,9 @@ void nsLayoutAtoms::AddrefAtoms() bulletList = NS_NewAtom("Bullet-list"); colGroupList = NS_NewAtom("ColGroup-list"); floaterList = NS_NewAtom("Floater-list"); + + textTagName = NS_NewAtom("__moz_text"); + commentTagName = NS_NewAtom("__moz_comment"); } ++gRefCnt; } @@ -94,6 +99,9 @@ void nsLayoutAtoms::ReleaseAtoms() NS_RELEASE(bulletList); NS_RELEASE(colGroupList); NS_RELEASE(floaterList); + + NS_RELEASE(textTagName); + NS_RELEASE(commentTagName); } } diff --git a/mozilla/layout/base/src/nsTextNode.cpp b/mozilla/layout/base/src/nsTextNode.cpp index 5940363026d..83e6990e4a8 100644 --- a/mozilla/layout/base/src/nsTextNode.cpp +++ b/mozilla/layout/base/src/nsTextNode.cpp @@ -25,6 +25,7 @@ #include "nsFrame.h" #include "nsIDocument.h" #include "nsCRT.h" +#include "nsLayoutAtoms.h" static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID); @@ -124,6 +125,14 @@ nsTextNode::QueryInterface(REFNSIID aIID, void** aInstancePtr) return NS_NOINTERFACE; } +NS_IMETHODIMP +nsTextNode::GetTag(nsIAtom*& aResult) const +{ + aResult = nsLayoutAtoms::textTagName; + NS_ADDREF(aResult); + return NS_OK; +} + NS_IMETHODIMP nsTextNode::GetNodeName(nsString& aNodeName) { diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index 08dcae1c139..c7174a7e819 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -43,6 +43,7 @@ #include "nsIEventStateManager.h" #include "nsIFocusTracker.h" #include "nsHTMLParts.h" +#include "nsLayoutAtoms.h" // Some Misc #defines #define SELECTION_DEBUG 0 @@ -1609,7 +1610,7 @@ nsFrame::MakeFrameName(const char* aType, nsString& aResult) const if (nsnull != mContent) { nsIAtom* tag; mContent->GetTag(tag); - if (tag != nsnull) { + if ((tag != nsnull) && (tag != nsLayoutAtoms::textTagName)) { aResult.Append("("); nsAutoString buf; tag->ToString(buf); diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index 08dcae1c139..c7174a7e819 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -43,6 +43,7 @@ #include "nsIEventStateManager.h" #include "nsIFocusTracker.h" #include "nsHTMLParts.h" +#include "nsLayoutAtoms.h" // Some Misc #defines #define SELECTION_DEBUG 0 @@ -1609,7 +1610,7 @@ nsFrame::MakeFrameName(const char* aType, nsString& aResult) const if (nsnull != mContent) { nsIAtom* tag; mContent->GetTag(tag); - if (tag != nsnull) { + if ((tag != nsnull) && (tag != nsLayoutAtoms::textTagName)) { aResult.Append("("); nsAutoString buf; tag->ToString(buf); diff --git a/mozilla/layout/html/base/src/nsHTMLAtoms.cpp b/mozilla/layout/html/base/src/nsHTMLAtoms.cpp index 26b844ad27d..46227164efa 100644 --- a/mozilla/layout/html/base/src/nsHTMLAtoms.cpp +++ b/mozilla/layout/html/base/src/nsHTMLAtoms.cpp @@ -71,6 +71,7 @@ nsIAtom* nsHTMLAtoms::colgroup; nsIAtom* nsHTMLAtoms::cols; nsIAtom* nsHTMLAtoms::colspan; nsIAtom* nsHTMLAtoms::columnPseudo; +nsIAtom* nsHTMLAtoms::commentPseudo; nsIAtom* nsHTMLAtoms::compact; nsIAtom* nsHTMLAtoms::content; nsIAtom* nsHTMLAtoms::coords; @@ -314,6 +315,7 @@ void nsHTMLAtoms::AddrefAtoms() cols = NS_NewAtom("COLS"); colspan = NS_NewAtom("COLSPAN"); columnPseudo = NS_NewAtom(":BODY-COLUMN"); + commentPseudo = NS_NewAtom(":MOZ-COMMENT"); compact = NS_NewAtom("COMPACT"); content = NS_NewAtom("CONTENT"); coords = NS_NewAtom("COORDS"); @@ -473,7 +475,7 @@ void nsHTMLAtoms::AddrefAtoms() thead = NS_NewAtom("THEAD"); text = NS_NewAtom("TEXT"); textarea = NS_NewAtom("TEXTAREA"); - textPseudo = NS_NewAtom(":TEXT"); + textPseudo = NS_NewAtom(":MOZ-TEXT"); th = NS_NewAtom("TH"); title = NS_NewAtom("TITLE"); top = NS_NewAtom("TOP"); @@ -553,6 +555,7 @@ void nsHTMLAtoms::ReleaseAtoms() NS_RELEASE(cols); NS_RELEASE(colspan); NS_RELEASE(columnPseudo); + NS_RELEASE(commentPseudo); NS_RELEASE(compact); NS_RELEASE(content); NS_RELEASE(coords); diff --git a/mozilla/layout/html/base/src/nsHTMLAtoms.h b/mozilla/layout/html/base/src/nsHTMLAtoms.h index e518c960719..5958fca304a 100644 --- a/mozilla/layout/html/base/src/nsHTMLAtoms.h +++ b/mozilla/layout/html/base/src/nsHTMLAtoms.h @@ -93,6 +93,7 @@ public: static nsIAtom* cols; static nsIAtom* colspan; static nsIAtom* columnPseudo; + static nsIAtom* commentPseudo; static nsIAtom* compact; static nsIAtom* content; static nsIAtom* coords; diff --git a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp index 9a54439d62b..2a1089e7dde 100644 --- a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp @@ -37,6 +37,7 @@ #include "nsITextContent.h" #include "nsIDOMText.h" +#include "nsIDOMComment.h" #include "nsIDOMHTMLFormElement.h" #include "nsIDOMHTMLTextAreaElement.h" @@ -72,6 +73,7 @@ static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); static NS_DEFINE_IID(kIHTMLContentIID, NS_IHTMLCONTENT_IID); static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); +static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID); static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); static NS_DEFINE_IID(kIDOMHTMLMapElementIID, NS_IDOMHTMLMAPELEMENT_IID); static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID); @@ -262,6 +264,7 @@ public: nsresult CloseContainer(const nsIParserNode& aNode); nsresult AddLeaf(const nsIParserNode& aNode); nsresult AddLeaf(nsIHTMLContent* aContent); + nsresult AddComment(const nsIParserNode& aNode); nsresult End(); nsresult GrowStack(); @@ -1108,6 +1111,43 @@ SinkContext::AddLeaf(nsIHTMLContent* aContent) return NS_OK; } +nsresult +SinkContext::AddComment(const nsIParserNode& aNode) +{ + nsIContent *comment; + nsIDOMComment *domComment; + nsresult result = NS_OK; + + FlushText(); + + result = NS_NewCommentNode(&comment); + if (NS_OK == result) { + result = comment->QueryInterface(kIDOMCommentIID, + (void **)&domComment); + if (NS_OK == result) { + domComment->AppendData(aNode.GetText()); + NS_RELEASE(domComment); + + comment->SetDocument(mSink->mDocument, PR_FALSE); + + nsIHTMLContent* parent; + if ((nsnull == mSink->mBody) && (nsnull != mSink->mHead)) { + parent = mSink->mHead; + } + else { + parent = mStack[mStackPos - 1].mContent; + } + parent->AppendChildTo(comment, PR_FALSE); + + // Mark sink dirty if it can safely reflow something + MaybeMarkSinkDirty(); + } + NS_RELEASE(comment); + } + + return result; +} + nsresult SinkContext::End() { @@ -1877,8 +1917,7 @@ HTMLContentSink::AddLeaf(const nsIParserNode& aNode) * @return error code */ nsresult HTMLContentSink::AddComment(const nsIParserNode& aNode) { - nsresult result= NS_OK; - return result; + return mCurrentContext->AddComment(aNode); } /** diff --git a/mozilla/layout/html/document/src/ua.css b/mozilla/layout/html/document/src/ua.css index 425dc719157..39d3b7896c2 100644 --- a/mozilla/layout/html/document/src/ua.css +++ b/mozilla/layout/html/document/src/ua.css @@ -581,4 +581,6 @@ NOFRAMES { display: block; } - +:MOZ-COMMENT { + display: none; +} \ No newline at end of file diff --git a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp index 1a18a44dcc8..b2e0ea0b137 100644 --- a/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/html/style/src/nsHTMLStyleSheet.cpp @@ -1825,7 +1825,7 @@ HTMLStyleSheetImpl::ConstructFrameByTag(nsIPresContext* aPresContext, // Initialize OUT parameter aNewFrame = nsnull; - if (nsnull == aTag) { + if (nsLayoutAtoms::textTagName == aTag) { rv = NS_NewTextFrame(aNewFrame); } else { @@ -2778,7 +2778,7 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, nsIStyleContext* parentStyleContext; aParentFrame->GetStyleContext(parentStyleContext); - if (nsnull == tag) { + if (nsLayoutAtoms::textTagName == tag) { // Use a special pseudo element style context for text nsIContent* parentContent = nsnull; if (nsnull != aParentFrame) { @@ -2789,6 +2789,18 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, parentStyleContext); rv = (nsnull == styleContext) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; NS_IF_RELEASE(parentContent); + } else if (nsLayoutAtoms::commentTagName == tag) { + // Use a special pseudo element style context for comments + nsIContent* parentContent = nsnull; + if (nsnull != aParentFrame) { + aParentFrame->GetContent(parentContent); + } + styleContext = aPresContext->ResolvePseudoStyleContextFor(parentContent, + nsHTMLAtoms::commentPseudo, + parentStyleContext); + rv = (nsnull == styleContext) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; + NS_IF_RELEASE(parentContent); + } else { styleContext = aPresContext->ResolveStyleContextFor(aContent, parentStyleContext); rv = (nsnull == styleContext) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; diff --git a/mozilla/layout/style/nsHTMLStyleSheet.cpp b/mozilla/layout/style/nsHTMLStyleSheet.cpp index 1a18a44dcc8..b2e0ea0b137 100644 --- a/mozilla/layout/style/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/style/nsHTMLStyleSheet.cpp @@ -1825,7 +1825,7 @@ HTMLStyleSheetImpl::ConstructFrameByTag(nsIPresContext* aPresContext, // Initialize OUT parameter aNewFrame = nsnull; - if (nsnull == aTag) { + if (nsLayoutAtoms::textTagName == aTag) { rv = NS_NewTextFrame(aNewFrame); } else { @@ -2778,7 +2778,7 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, nsIStyleContext* parentStyleContext; aParentFrame->GetStyleContext(parentStyleContext); - if (nsnull == tag) { + if (nsLayoutAtoms::textTagName == tag) { // Use a special pseudo element style context for text nsIContent* parentContent = nsnull; if (nsnull != aParentFrame) { @@ -2789,6 +2789,18 @@ HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext, parentStyleContext); rv = (nsnull == styleContext) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; NS_IF_RELEASE(parentContent); + } else if (nsLayoutAtoms::commentTagName == tag) { + // Use a special pseudo element style context for comments + nsIContent* parentContent = nsnull; + if (nsnull != aParentFrame) { + aParentFrame->GetContent(parentContent); + } + styleContext = aPresContext->ResolvePseudoStyleContextFor(parentContent, + nsHTMLAtoms::commentPseudo, + parentStyleContext); + rv = (nsnull == styleContext) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; + NS_IF_RELEASE(parentContent); + } else { styleContext = aPresContext->ResolveStyleContextFor(aContent, parentStyleContext); rv = (nsnull == styleContext) ? NS_ERROR_OUT_OF_MEMORY : NS_OK; diff --git a/mozilla/layout/style/ua.css b/mozilla/layout/style/ua.css index 425dc719157..39d3b7896c2 100644 --- a/mozilla/layout/style/ua.css +++ b/mozilla/layout/style/ua.css @@ -581,4 +581,6 @@ NOFRAMES { display: block; } - +:MOZ-COMMENT { + display: none; +} \ No newline at end of file