diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index f007a0f59be..abfcf904a73 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -555,121 +555,166 @@ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsIToke return result; } +/** + * @param aTarget - Tag that was neglected in the document. + * @param aType - Specifies the type of the target. Ex. start, end, text, etc. + * @param aParser - Parser to drive this process + * @param aSink - HTML Content sink + */ +nsresult +CNavDTD::BuildNeglectedTarget(eHTMLTags aTarget, + eHTMLTokenTypes aType, + nsIParser* aParser, + nsIContentSink* aSink) +{ + NS_ASSERTION(mTokenizer, "tokenizer is null! unable to build target."); + NS_ASSERTION(mTokenAllocator, "unable to create tokens without an allocator."); + if (!mTokenizer || !mTokenAllocator) + return NS_OK; + if (eHTMLTag_unknown != mSkipTarget && eHTMLTag_title == aTarget) { + PRInt32 size = mSkippedContent.GetSize(); + // Note: The first location of the skipped content + // deque contains the opened-skip-target. Do not include + // that when guessing title contents. The term "guessing" + // is used because the document did not contain an end title + // and hence it's almost impossible to know what markup + // should belong in the title. The assumption used here is that + // if the markup is anything other than "text", or "entity" or, + // "whitespace" then it's least likely to belong in the title. + PRInt32 index; + for (index = 1; index < size; index++) { + CHTMLToken* token = + NS_REINTERPRET_CAST(CHTMLToken*, mSkippedContent.ObjectAt(index)); + NS_ASSERTION(token, "there is a null token in the skipped content list!"); + eHTMLTokenTypes type = eHTMLTokenTypes(token->GetTokenType()); + if (eToken_whitespace != type && + eToken_newline != type && + eToken_text != type && + eToken_entity != type && + eToken_attribute != type) { + // Now pop the tokens that do not belong ( just a guess work ) + // in the title and push them into the tokens queue. + while (size != index++) { + token = NS_REINTERPRET_CAST(CHTMLToken*, mSkippedContent.Pop()); + mTokenizer->PushTokenFront(token); + } + break; + } + } + } + CHTMLToken* target = + NS_STATIC_CAST(CHTMLToken*, mTokenAllocator->CreateTokenOfType(aType, aTarget)); + mTokenizer->PushTokenFront(target); + return BuildModel(aParser, mTokenizer, 0, aSink); +} + /** * * @update gess5/18/98 * @param * @return */ -nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParser* aParser,nsIContentSink* aSink){ - nsresult result=NS_OK; - - if(aSink) { - - if((NS_OK==anErrorCode) && !(mFlags & (NS_DTD_FLAG_HAD_BODY | NS_DTD_FLAG_HAD_FRAMESET))) { - - mSkipTarget=eHTMLTag_unknown; //clear this in case we were searching earlier. - - if (mTokenAllocator) { - CStartToken *theToken = NS_STATIC_CAST(CStartToken*, mTokenAllocator->CreateTokenOfType(eToken_start,eHTMLTag_body,NS_LITERAL_STRING("body"))); - mTokenizer->PushTokenFront(theToken); //this token should get pushed on the context stack, don't recycle it - result = BuildModel(aParser,mTokenizer, 0, aSink); +nsresult CNavDTD::DidBuildModel(nsresult anErrorCode, + PRBool aNotifySink, + nsIParser* aParser, + nsIContentSink* aSink) +{ + if (!aSink) + return NS_OK; + nsresult result = NS_OK; + if (aParser && aNotifySink) { + if (NS_OK == anErrorCode) { + if (eHTMLTag_unknown != mSkipTarget) { + // Looks like there is an open target ( ex.