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) {
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 {
rv = OpenContainer(aNode);
NS_ENSURE_SUCCESS(rv, rv);

View File

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

View File

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

View File

@ -134,13 +134,14 @@ public:
nsIContent* aContent);
nsresult AddText(const nsAString& aString);
nsresult AddTextToContent(nsIContent* aContent,const nsString& aText);
nsresult AddTextToContent(nsIContent* aContent, const nsAString& aText);
nsresult FlushText();
void ProcessBaseTag(nsIContent* aContent);
void AddBaseTagInfo(nsIContent* aContent);
nsresult Init();
nsresult SetDocumentTitle(const nsAString& aString, const nsIParserNode* aNode);
PRPackedBool mAllContent;
PRPackedBool mProcessing;
@ -297,35 +298,7 @@ nsHTMLFragmentContentSink::EndContext(PRInt32 aID)
NS_IMETHODIMP
nsHTMLFragmentContentSink::SetTitle(const nsString& aValue)
{
NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_NOT_INITIALIZED);
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;
return SetDocumentTitle(aValue, nsnull);
}
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
nsHTMLFragmentContentSink::OpenContainer(const nsIParserNode& aNode)
{
@ -523,6 +526,19 @@ nsHTMLFragmentContentSink::AddHeadContent(const nsIParserNode& aNode)
NS_IMETHODIMP
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);
nsresult result = NS_OK;
@ -797,7 +813,7 @@ nsHTMLFragmentContentSink::AddText(const nsAString& aString)
}
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");
nsresult result=NS_OK;

View File

@ -3620,29 +3620,13 @@ nsresult CNavDTD::AddHeadLeaf(nsIParserNode *aNode){
}
if (mSink) {
if (eHTMLTag_title == theTag) {
nsAutoString title;
PRInt32 lineNo;
result = CollectSkippedContent(theTag, title, lineNo);
NS_ENSURE_SUCCESS(result, result);
STOP_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();
}
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;
}

View File

@ -247,7 +247,22 @@ nsLoggingSink::CloseContainer(const nsHTMLTag aTag) {
NS_IMETHODIMP
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;