frame->SetStyleContext(aPresContext, styleContext);
NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext*  aPresContext,                                                 nsIContent*      aContent,                                                 nsIFrame*        aParentFrame,                                                 nsIFrame*&       aFrameSubTree){  // Get the tag  nsIAtom*  tag;  aContent->GetTag(tag);  // Resolve the style context.  // XXX Cheesy hack for text  nsIStyleContext* styleContext;  if (nsnull == tag) {    styleContext = aPresContext->ResolvePseudoStyleContextFor(nsHTMLAtoms::text, aParentFrame);  } else {    styleContext = aPresContext->ResolveStyleContextFor(aContent, aParentFrame);  }  // Initialize OUT parameter  aFrameSubTree = nsnull;  // Create a frame.  nsIFrame* frame = nsnull;  nsIFrame* childList = nsnull;  if (nsnull == aParentFrame) {    // This should only be the case for the root content object.#ifdef NS_DEBUG    nsIDocument*  doc;    nsIContent*   rootContent;    // Verify it's the root content object    aContent->GetDocument(doc);    rootContent = doc->GetRootContent();    NS_ASSERTION(rootContent == aContent, "unexpected content");    NS_RELEASE(doc);    NS_RELEASE(rootContent);#endif    // Construct the root frame object    frame = ConstructRootFrame(aPresContext, aContent);    // Process the child content    ProcessChildren(aPresContext, frame, aContent, childList);  } else {    nsresult  rv = NS_OK;    // Handle specific frame types    if (nsnull == tag) {      rv = NS_NewTextFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::img == tag) {      rv = NS_NewImageFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::hr == tag) {      rv = NS_NewHRFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::br == tag) {      rv = NS_NewBRFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::wbr == tag) {      rv = NS_NewWBRFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::input == tag) {      rv = CreateInputFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::textarea == tag) {      rv = NS_NewInputTextFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::select == tag) {      rv = NS_NewHTMLSelectFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::applet == tag) {      rv = NS_NewObjectFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::embed == tag) {      rv = NS_NewObjectFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::object == tag) {      rv = NS_NewObjectFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::body == tag) {      rv = NS_NewBodyFrame(aContent, aParentFrame, frame);      // Process the child content      rv = ProcessChildren(aPresContext, frame, aContent, childList);    }    else if (nsHTMLAtoms::frameset == tag) {      rv = NS_NewHTMLFramesetFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::iframe == tag) {      rv = NS_NewHTMLFrameOuterFrame(aContent, aParentFrame, frame);    }    else if (nsHTMLAtoms::spacer == tag) {      rv = NS_NewSpacerFrame(aContent, aParentFrame, frame);    }    if (NS_OK != rv) {      NS_RELEASE(styleContext);      NS_IF_RELEASE(tag);      return rv;    }      // XXX add code in here to force the odd ones into the empty frame?    // AREA, HEAD, META, MAP, etc...      if (nsnull == frame) {      // When there is no explicit frame to create, assume it's a      // container and let style dictate the rest.      const nsStyleDisplay* styleDisplay = (const nsStyleDisplay*)        styleContext->GetStyleData(eStyleStruct_Display);        // Use style to choose what kind of frame to create      switch (styleDisplay->mDisplay) {      case NS_STYLE_DISPLAY_BLOCK:      case NS_STYLE_DISPLAY_LIST_ITEM:        rv = NS_NewBlockFrame(&frame, aContent, aParentFrame);        // Process the child content        ProcessChildren(aPresContext, frame, aContent, childList);        break;        case NS_STYLE_DISPLAY_INLINE:        rv = NS_NewInlineFrame(&frame, aContent, aParentFrame);        // Process the child content        ProcessChildren(aPresContext, frame, aContent, childList);        break;        case NS_STYLE_DISPLAY_TABLE:        frame = ConstructTableFrame(aPresContext, aContent, aParentFrame,                                    styleContext, childList);        break;      case NS_STYLE_DISPLAY_TABLE_ROW_GROUP:      case NS_STYLE_DISPLAY_TABLE_HEADER_GROUP:      case NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP:        // XXX We should check for being inside of a table. If there's a missing        // table then create an anonynmous table frame        rv = NS_NewTableRowGroupFrame(aContent, aParentFrame, frame);        // Process the child content        ProcessChildren(aPresContext, frame, aContent, childList);        break;        case NS_STYLE_DISPLAY_TABLE_COLUMN:        // XXX We should check for being inside of a table column group...        rv = NS_NewTableColFrame(aContent, aParentFrame, frame);        // Process the child content        ProcessChildren(aPresContext, frame, aContent, childList);        break;      case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP:        // XXX We should check for being inside of a table...        rv = NS_NewTableColGroupFrame(aContent, aParentFrame, frame);        // Process the child content        ProcessChildren(aPresContext, frame, aContent, childList);        break;      case NS_STYLE_DISPLAY_TABLE_ROW:        // XXX We should check for being inside of a table row group...        rv = NS_NewTableRowFrame(aContent, aParentFrame, frame);        // Process the child content        ProcessChildren(aPresContext, frame, aContent, childList);        break;      case NS_STYLE_DISPLAY_TABLE_CELL:        // XXX We should check for being inside of a table row frame...        rv = NS_NewTableCellFrame(aContent, aParentFrame, frame);        // Process the child content        ProcessChildren(aPresContext, frame, aContent, childList);        break;      default:        // Don't create any frame for content that's not displayed...        break;      }      if (NS_OK != rv) {        NS_RELEASE(styleContext);        NS_IF_RELEASE(tag);        return rv;      }    }  }    // If we created a frame then set its style context and initialize it  // passing it the child list  if (nsnull != frame) {    frame->SetStyleContext(aPresContext, styleContext);    frame->Init(*aPresContext, childList);  }  aFrameSubTree = frame;  NS_RELEASE(styleContext);  NS_IF_RELEASE(tag);  return NS_OK;}