return result;
nsresult CElement::HandleStartToken(  nsCParserNode* aNode,                                      eHTMLTags aTag,                                      nsDTDContext* aContext,                                      nsIHTMLContentSink* aSink) {  CElement* theElement=gElementTable->mElements[aTag];  nsresult  result=WillHandleStartToken(theElement,aNode,aTag,aContext,aSink);#if 0  CElement* theDelegate=theElement->GetDelegate();  if(theDelegate) {    result=theDelegate->HandleStartToken(aNode,aTag,aContext,aSink);  }  else #endif  {    if(theElement) {      if(CanContain(theElement,aContext)) {            if(theElement->IsContainer()) {          if(theElement->IsSinkContainer()) {            result=theElement->OpenContainerInContext(aNode,aTag,aContext,aSink);          }          else {            result=theElement->OpenContext(aNode,aTag,aContext,aSink);          }        }        else {          result=aSink->AddLeaf(*aNode);         }      }      else if(theElement->IsBlockCloser()){        //Ok, so we have a start token that is misplaced. Before handing this off        //to a default container (parent), let's check the autoclose condition.        if(HasOptionalEndTag(mTag)) {          //aha! We have a case where this tag is autoclosed by anElement.          //Let's close this container, then try to open theElement.          PRInt32 theCount=aContext->GetCount();          PRInt32 theIndex=FindAutoCloseIndexForStartTag(theElement,theCount-2,aContext);          //continue ripping code out here...          if(kNotFound!=theIndex) {            eHTMLTags theParentTag=eHTMLTag_unknown;            CElement* theParent=0;            while(NS_SUCCEEDED(result) && (theCount>theIndex)) {              theParentTag=aContext->Last();              theParent=gElementTable->mElements[theParentTag];              nsCParserNode *theNode=aContext->PeekNode(); //this will get popped later...              if(theParent->IsSinkContainer()) {                CloseContainerInContext(theNode,theParentTag,aContext,aSink);              }              else CloseContext(theNode,theParentTag,aContext,aSink);              theCount--;            }            if(NS_SUCCEEDED(result)){              theParentTag=aContext->Last();              theParent=gElementTable->mElements[theParentTag];              result=theParent->HandleStartToken(aNode,aTag,aContext,aSink);            }          }          return result;        }        else {                    PRBool theElementCanOpen=PR_FALSE;            //the logic here is simple:            //  This operation can only succeed if the given tag is open, AND            //  all the tags below it have optional end tags.            //  If these conditions aren't met, we bail out, leaving the tag open.          if(mTag!=aTag) {            PRInt32 theLastPos=aContext->LastOf(aTag); //see if it's already open...            if(-1!=theLastPos) {              PRInt32 theCount=aContext->GetCount();              result=HandleEndToken(aNode,aTag,aContext,aSink);              theElementCanOpen=PRBool(aContext->GetCount()<theCount);            }          }          if(theElementCanOpen) {            if(NS_SUCCEEDED(result)){              eHTMLTags theParentTag=aContext->Last();              CElement* theParent=gElementTable->mElements[theParentTag];              return theParent->HandleStartToken(aNode,aTag,aContext,aSink);            }                      }        }          //ok, here's our last recourse -- let's let the parent handle it.        CElement* theContainer=GetDefaultContainerFor(theElement);        if(theContainer) {          result=theContainer->HandleMisplacedStartToken(aNode,aTag,aContext,aSink);        }      }    }  }  return result;}