NS_RELEASE(htmlContent);
HTMLStyleSheetImpl::ConstructFrameByTag(nsIPresContext*  aPresContext,                                        nsIContent*      aContent,                                        nsIFrame*        aParentFrame,                                        nsIAtom*         aTag,                                        nsIStyleContext* aStyleContext,                                        nsAbsoluteItems& aAbsoluteItems,                                        nsIFrame*&       aNewFrame){  PRBool    processChildren = PR_FALSE;  // whether we should process child content  nsresult  rv = NS_OK;  PRBool    isAbsolutelyPositioned = PR_FALSE;  // Initialize OUT parameter  aNewFrame = nsnull;  if (nsnull == aTag) {    rv = NS_NewTextFrame(aNewFrame);  }  else {    nsIHTMLContent *htmlContent;    // Ignore the tag if it's not HTML content    if (NS_SUCCEEDED(aContent->QueryInterface(kIHTMLContentIID, (void **)&htmlContent))) {      // See if the element is absolutely positioned      const nsStylePosition* position = (const nsStylePosition*)        aStyleContext->GetStyleData(eStyleStruct_Position);      if (NS_STYLE_POSITION_ABSOLUTE == position->mPosition) {        isAbsolutelyPositioned = PR_TRUE;      }      // Create a frame based on the tag      if (nsHTMLAtoms::img == aTag) {        rv = NS_NewImageFrame(aNewFrame);      }      else if (nsHTMLAtoms::hr == aTag) {        rv = NS_NewHRFrame(aNewFrame);      }      else if (nsHTMLAtoms::br == aTag) {        rv = NS_NewBRFrame(aNewFrame);      }      else if (nsHTMLAtoms::wbr == aTag) {        rv = NS_NewWBRFrame(aNewFrame);      }      else if (nsHTMLAtoms::input == aTag) {        rv = CreateInputFrame(aContent, aNewFrame);      }      else if (nsHTMLAtoms::textarea == aTag) {        rv = NS_NewTextControlFrame(aNewFrame);      }      else if (nsHTMLAtoms::select == aTag) {        rv = NS_NewSelectControlFrame(aNewFrame);      }      else if (nsHTMLAtoms::applet == aTag) {        rv = NS_NewObjectFrame(aNewFrame);      }      else if (nsHTMLAtoms::embed == aTag) {        rv = NS_NewObjectFrame(aNewFrame);      }      else if (nsHTMLAtoms::fieldset == aTag) {        rv = NS_NewFieldSetFrame(aNewFrame);        processChildren = PR_TRUE;      }      else if (nsHTMLAtoms::legend == aTag) {        rv = NS_NewLegendFrame(aNewFrame);        processChildren = PR_TRUE;        isAbsolutelyPositioned = PR_FALSE;  // don't absolutely position      }      else if (nsHTMLAtoms::object == aTag) {        rv = NS_NewObjectFrame(aNewFrame);        //rv = NS_NewObjectFrame(aContent, aParentFrame, aNewFrame);        nsIFrame *blockFrame;        NS_NewBlockFrame(blockFrame, 0);        blockFrame->Init(*aPresContext, aContent, aNewFrame, aNewFrame,                         aStyleContext);        aNewFrame = blockFrame;        processChildren = PR_TRUE;      }      else if (nsHTMLAtoms::form == aTag) {        rv = NS_NewFormFrame(aNewFrame);      }      else if (nsHTMLAtoms::frameset == aTag) {        rv = NS_NewHTMLFramesetFrame(aNewFrame);        isAbsolutelyPositioned = PR_FALSE;  // don't absolutely position      }      else if (nsHTMLAtoms::iframe == aTag) {        rv = NS_NewHTMLFrameOuterFrame(aNewFrame);      }      else if (nsHTMLAtoms::spacer == aTag) {        rv = NS_NewSpacerFrame(aNewFrame);        isAbsolutelyPositioned = PR_FALSE;  // don't absolutely position      }      else if (nsHTMLAtoms::button == aTag) {        rv = NS_NewHTMLButtonControlFrame(aNewFrame);        processChildren = PR_TRUE;      }      else if (nsHTMLAtoms::label == aTag) {        rv = NS_NewLabelFrame(aNewFrame);        processChildren = PR_TRUE;      }      NS_RELEASE(htmlContent);    }  }  // If we succeeded in creating a frame then initialize it, process its  // children (if requested), and set the initial child list  if (NS_SUCCEEDED(rv) && (nsnull != aNewFrame)) {    nsIFrame* geometricParent = isAbsolutelyPositioned ? aAbsoluteItems.containingBlock :                                                         aParentFrame;    aNewFrame->Init(*aPresContext, aContent, geometricParent, aParentFrame,                    aStyleContext);    // See if we need to create a view, e.g. the frame is absolutely positioned    nsHTMLContainerFrame::CreateViewForFrame(*aPresContext, aNewFrame,                                             aStyleContext, PR_FALSE);    // Process the child content if requested    nsIFrame* childList = nsnull;    if (processChildren) {      rv = ProcessChildren(aPresContext, aContent, aNewFrame, aAbsoluteItems,                           childList);    }    // Set the frame's initial child list    aNewFrame->SetInitialChildList(*aPresContext, nsnull, childList);    // If the frame is absolutely positioned then create a placeholder frame    if (isAbsolutelyPositioned) {      nsIFrame* placeholderFrame;      CreatePlaceholderFrameFor(aPresContext, aContent, aNewFrame, aStyleContext,                                aParentFrame, placeholderFrame);      // Add the absolutely positioned frame to its containing block's list      // of child frames      aAbsoluteItems.AddAbsolutelyPositionedChild(aNewFrame);      // Add the placeholder frame to the flow      aNewFrame = placeholderFrame;    }  }  return rv;}