bug 280044: Pass a title node to the content sinks so that attributes on title don't get lost. r=sicking sr=peterv

This commit is contained in:
mrbkap%gmail.com 2005-03-23 07:09:24 +00:00
parent 513516a9bc
commit 85d6f098e9
6 changed files with 95 additions and 59 deletions

View File

@ -323,6 +323,19 @@ mozSanitizingHTMLSerializer::AddHeadContent(const nsIParserNode& aNode)
eHTMLTag_entity == type) { eHTMLTag_entity == type) {
rv = AddLeaf(aNode); rv = AddLeaf(aNode);
} }
else if (eHTMLTag_title == type) {
NS_ASSERTION(mParser, "Only CNavDTD treats title this way.");
nsString skippedContent;
PRInt32 lineNo;
nsCOMPtr<nsIDTD> dtd;
mParser->GetDTD(getter_AddRefs(dtd));
NS_ENSURE_TRUE(dtd, NS_ERROR_UNEXPECTED);
dtd->CollectSkippedContent(type, skippedContent, lineNo);
SetTitle(skippedContent);
}
else { else {
rv = OpenContainer(aNode); rv = OpenContainer(aNode);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

View File

@ -479,6 +479,10 @@ nsPlainTextSerializer::CloseContainer(const nsHTMLTag aTag)
NS_IMETHODIMP NS_IMETHODIMP
nsPlainTextSerializer::AddHeadContent(const nsIParserNode& aNode) nsPlainTextSerializer::AddHeadContent(const nsIParserNode& aNode)
{ {
if (eHTMLTag_title == aNode.GetNodeType()) {
// XXX collect the skipped content
return NS_OK;
}
OpenHead(aNode); OpenHead(aNode);
nsresult rv = AddLeaf(aNode); nsresult rv = AddLeaf(aNode);
CloseHead(); CloseHead();

View File

@ -279,7 +279,7 @@ public:
protected: protected:
PRBool IsTimeToNotify(); PRBool IsTimeToNotify();
nsresult SetDocumentTitle(const nsAString& aTitle); nsresult SetDocumentTitle(const nsAString& aTitle, const nsIParserNode* aNode);
// If aCheckIfPresent is true, will only set an attribute in cases // If aCheckIfPresent is true, will only set an attribute in cases
// when it's not already set. // when it's not already set.
nsresult AddAttributes(const nsIParserNode& aNode, nsIContent* aContent, nsresult AddAttributes(const nsIParserNode& aNode, nsIContent* aContent,
@ -2600,7 +2600,7 @@ HTMLContentSink::SetTitle(const nsString& aValue)
nsresult rv = OpenHeadContext(); nsresult rv = OpenHeadContext();
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = SetDocumentTitle(aValue); rv = SetDocumentTitle(aValue, nsnull);
} }
CloseHeadContext(); CloseHeadContext();
@ -3072,7 +3072,7 @@ HTMLContentSink::AddHeadContent(const nsIParserNode& aNode)
nsAutoString title; nsAutoString title;
PRInt32 lineNo = 0; PRInt32 lineNo = 0;
dtd->CollectSkippedContent(eHTMLTag_title, title, lineNo); dtd->CollectSkippedContent(eHTMLTag_title, title, lineNo);
rv = SetDocumentTitle(title); rv = SetDocumentTitle(title, &aNode);
} }
} }
else { else {
@ -3139,7 +3139,7 @@ HTMLContentSink::AddLeaf(const nsIParserNode& aNode)
} }
nsresult nsresult
HTMLContentSink::SetDocumentTitle(const nsAString& aTitle) HTMLContentSink::SetDocumentTitle(const nsAString& aTitle, const nsIParserNode* aNode)
{ {
MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::SetDocumentTitle()\n")); MOZ_TIMER_DEBUGLOG(("Start: nsHTMLContentSink::SetDocumentTitle()\n"));
MOZ_TIMER_START(mWatch); MOZ_TIMER_START(mWatch);
@ -3171,6 +3171,10 @@ HTMLContentSink::SetDocumentTitle(const nsAString& aTitle)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
} }
if (aNode) {
AddAttributes(*aNode, it);
}
nsCOMPtr<nsITextContent> text; nsCOMPtr<nsITextContent> text;
rv = NS_NewTextNode(getter_AddRefs(text)); rv = NS_NewTextNode(getter_AddRefs(text));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

View File

@ -134,13 +134,14 @@ public:
nsIContent* aContent); nsIContent* aContent);
nsresult AddText(const nsAString& aString); nsresult AddText(const nsAString& aString);
nsresult AddTextToContent(nsIContent* aContent,const nsString& aText); nsresult AddTextToContent(nsIContent* aContent, const nsAString& aText);
nsresult FlushText(); nsresult FlushText();
void ProcessBaseTag(nsIContent* aContent); void ProcessBaseTag(nsIContent* aContent);
void AddBaseTagInfo(nsIContent* aContent); void AddBaseTagInfo(nsIContent* aContent);
nsresult Init(); nsresult Init();
nsresult SetDocumentTitle(const nsAString& aString, const nsIParserNode* aNode);
PRPackedBool mAllContent; PRPackedBool mAllContent;
PRPackedBool mProcessing; PRPackedBool mProcessing;
@ -297,35 +298,7 @@ nsHTMLFragmentContentSink::EndContext(PRInt32 aID)
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLFragmentContentSink::SetTitle(const nsString& aValue) nsHTMLFragmentContentSink::SetTitle(const nsString& aValue)
{ {
NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_NOT_INITIALIZED); return SetDocumentTitle(aValue, nsnull);
nsresult result=NS_OK;
nsCOMPtr<nsINodeInfo> nodeInfo;
result = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::title, nsnull,
kNameSpaceID_None,
getter_AddRefs(nodeInfo));
if(NS_SUCCEEDED(result)) {
nsRefPtr<nsGenericHTMLElement> content = NS_NewHTMLTitleElement(nodeInfo);
if (!content) {
result = NS_ERROR_OUT_OF_MEMORY;
} else {
nsIContent *parent = GetCurrentContent();
if (nsnull == parent) {
parent = mRoot;
}
result=parent->AppendChildTo(content, PR_FALSE, PR_FALSE);
if (NS_SUCCEEDED(result)) {
result=AddTextToContent(content,aValue);
}
}
}
return result;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -433,6 +406,36 @@ nsHTMLFragmentContentSink::AddBaseTagInfo(nsIContent* aContent)
} }
} }
nsresult
nsHTMLFragmentContentSink::SetDocumentTitle(const nsAString& aString, const nsIParserNode* aNode)
{
NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsINodeInfo> nodeInfo;
nsresult rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::title, nsnull,
kNameSpaceID_None,
getter_AddRefs(nodeInfo));
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<nsGenericHTMLElement> content = NS_NewHTMLTitleElement(nodeInfo);
NS_ENSURE_TRUE(content, NS_ERROR_OUT_OF_MEMORY);
nsIContent *parent = GetCurrentContent();
if (!parent) {
parent = mRoot;
}
if (aNode) {
AddAttributes(*aNode, content);
}
rv = parent->AppendChildTo(content, PR_FALSE, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
return AddTextToContent(content, aString);
}
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLFragmentContentSink::OpenContainer(const nsIParserNode& aNode) nsHTMLFragmentContentSink::OpenContainer(const nsIParserNode& aNode)
{ {
@ -523,6 +526,19 @@ nsHTMLFragmentContentSink::AddHeadContent(const nsIParserNode& aNode)
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLFragmentContentSink::AddLeaf(const nsIParserNode& aNode) nsHTMLFragmentContentSink::AddLeaf(const nsIParserNode& aNode)
{ {
if (eHTMLTag_title == aNode.GetNodeType()) {
nsCOMPtr<nsIDTD> dtd;
mParser->GetDTD(getter_AddRefs(dtd));
NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE);
nsAutoString skippedContent;
PRInt32 lineNo = 0;
dtd->CollectSkippedContent(eHTMLTag_title, skippedContent, lineNo);
return SetDocumentTitle(skippedContent, &aNode);
}
NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_NOT_INITIALIZED);
nsresult result = NS_OK; nsresult result = NS_OK;
@ -797,7 +813,7 @@ nsHTMLFragmentContentSink::AddText(const nsAString& aString)
} }
nsresult nsresult
nsHTMLFragmentContentSink::AddTextToContent(nsIContent* aContent,const nsString& aText) { nsHTMLFragmentContentSink::AddTextToContent(nsIContent* aContent, const nsAString& aText) {
NS_ASSERTION(aContent !=nsnull, "can't add text w/o a content"); NS_ASSERTION(aContent !=nsnull, "can't add text w/o a content");
nsresult result=NS_OK; nsresult result=NS_OK;

View File

@ -3620,29 +3620,13 @@ nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){
} }
if (mSink) { if (mSink) {
if (eHTMLTag_title == theTag) { STOP_TIMER();
nsAutoString title; MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
PRInt32 lineNo;
result = CollectSkippedContent(theTag, title, lineNo); result = mSink->AddHeadContent(*aNode);
NS_ENSURE_SUCCESS(result, result);
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
STOP_TIMER(); START_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
result = mSink->SetTitle(title);
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
START_TIMER();
}
else {
STOP_TIMER();
MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
result = mSink->AddHeadContent(*aNode);
MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::AddHeadLeaf(), this=%p\n", this));
START_TIMER();
}
} }
return result; return result;
} }

View File

@ -247,7 +247,22 @@ nsLoggingSink::CloseContainer(const nsHTMLTag aTag) {
NS_IMETHODIMP NS_IMETHODIMP
nsLoggingSink::AddHeadContent(const nsIParserNode& aNode) { nsLoggingSink::AddHeadContent(const nsIParserNode& aNode) {
LeafNode(aNode); eHTMLTags type = (eHTMLTags)aNode.GetNodeType();
if (type == eHTMLTag_title) {
nsCOMPtr<nsIDTD> dtd;
mParser->GetDTD(getter_AddRefs(dtd));
NS_ENSURE_TRUE(dtd, NS_ERROR_FAILURE);
nsString theString;
PRInt32 lineNo = 0;
dtd->CollectSkippedContent(type, theString, lineNo);
SetTitle(theString);
}
else {
LeafNode(aNode);
}
nsresult theResult=NS_OK; nsresult theResult=NS_OK;