NS_ASSERTION(mStackPos > 0, "bad parser");
NS_IMETHODIMP HTMLContentSink::AddLeaf(const nsIParserNode& aNode){  SINK_TRACE_NODE(SINK_TRACE_CALLS,                  "HTMLContentSink::AddLeaf", aNode);  // Check for nodes that require special handling  switch (aNode.GetNodeType()) {  case eHTMLTag_style:    FlushText();    ProcessSTYLETag(aNode);    return NS_OK;  case eHTMLTag_script:    // XXX SCRIPT tag evaluation is currently turned off till we    // get more scripts working.    FlushText();    ProcessSCRIPTTag(aNode);    return NS_OK;  case eHTMLTag_area:    FlushText();    ProcessAREATag(aNode);    return NS_OK;  case eHTMLTag_meta:    // Add meta objects to the head object    FlushText();    ProcessMETATag(aNode);    return NS_OK;  case eHTMLTag_base:    ProcessBASETag(aNode);    return NS_OK;  }  eHTMLTags parentType;  nsIHTMLContent* parent = GetCurrentContainer(&parentType);  switch (parentType) {  /*case eHTMLTag_table:  case eHTMLTag_tr:  case eHTMLTag_tbody:  case eHTMLTag_thead:  case eHTMLTag_tfoot:    // XXX Discard leaf content (those annoying \n's really) in    // table's or table rows    return PR_TRUE;  */  case eHTMLTag_option:    FlushText();    ProcessOPTIONTagContent(aNode);    return NS_OK;  case eHTMLTag_select:    // Discard content in a select that's not an option    if (eHTMLTag_option != aNode.GetNodeType()) {      return NS_OK;    }    break;  }  PRBool sleazyTextHackXXX = PR_FALSE;  nsresult rv = NS_OK;  nsIHTMLContent* leaf = nsnull;  switch (aNode.GetTokenType()) {  case eToken_start:    switch (aNode.GetNodeType()) {    case eHTMLTag_br:      FlushText();      rv = ProcessBRTag(&leaf, aNode);      break;    case eHTMLTag_frame:      FlushText();      rv = ProcessFrameTag(&leaf, aNode);      break;    case eHTMLTag_hr:      FlushText();      rv = ProcessHRTag(&leaf, aNode);      break;    case eHTMLTag_input:      FlushText();      rv = ProcessINPUTTag(&leaf, aNode);      break;    case eHTMLTag_img:      FlushText();      rv = ProcessIMGTag(&leaf, aNode);      break;    case eHTMLTag_spacer:      FlushText();      rv = ProcessSPACERTag(&leaf, aNode);      break;    case eHTMLTag_textarea:      FlushText();      ProcessTEXTAREATag(&leaf, aNode);      break;    case eHTMLTag_embed:      rv = ProcessEMBEDTag(&leaf, aNode);      break;    }    break;  case eToken_text:  case eToken_whitespace:  case eToken_newline:    rv = AddText(aNode.GetText(), &leaf);    sleazyTextHackXXX = PR_TRUE;    break;  case eToken_entity:    {      nsAutoString tmp;      PRInt32 unicode = aNode.TranslateToUnicodeStr(tmp);      if (unicode < 0) {        rv = AddText(aNode.GetText(), &leaf);      }      else {        rv = AddText(tmp, &leaf);      }      sleazyTextHackXXX = PR_TRUE;    }    break;  case eToken_skippedcontent:    break;  }  if (NS_OK == rv) {    if (nsnull != leaf) {      if (nsnull != parent) {        AppendToCorrectParent(parentType, parent,                              (nsHTMLTag) aNode.GetNodeType(), leaf,                              PR_FALSE);        if (sleazyTextHackXXX) {          // XXX Prevent incremental reflows on the text as it pours in          leaf->SetDocument(nsnull);        }      } else {        // XXX drop stuff on the floor that doesn't have a container!        // Bad parser!      }    }  }  NS_IF_RELEASE(leaf);  return rv;}