childItems);
childItems, aFixedItems);
HTMLStyleSheetImpl::ConstructFrameByDisplayType(nsIPresContext*       aPresContext,                                                const nsStyleDisplay* aDisplay,                                                nsIContent*           aContent,                                                nsIFrame*             aParentFrame,                                                nsIStyleContext*      aStyleContext,                                                nsAbsoluteItems&      aAbsoluteItems,                                                nsFrameItems&         aFrameItems){  PRBool    isAbsolutelyPositioned = PR_FALSE;  PRBool    isBlock = aDisplay->IsBlockLevel();  nsIFrame* newFrame = nsnull;  // the frame we construct  nsresult  rv = NS_OK;  // Get the position syle info  const nsStylePosition* position = (const nsStylePosition*)    aStyleContext->GetStyleData(eStyleStruct_Position);  // The frame is also a block if it's an inline frame that's floated or  // absolutely positioned  if ((NS_STYLE_DISPLAY_INLINE == aDisplay->mDisplay) &&      ((NS_STYLE_FLOAT_NONE != aDisplay->mFloats) ||       (NS_STYLE_POSITION_ABSOLUTE == position->mPosition))) {    isBlock = PR_TRUE;  }  // If the frame is a block-level frame and is scrollable, then wrap it  // in a scroll frame.  // XXX Applies to replaced elements, too, but how to tell if the element  // is replaced?  // XXX Ignore tables for the time being  if ((isBlock && (aDisplay->mDisplay != NS_STYLE_DISPLAY_TABLE)) &&      IsScrollable(aPresContext, aDisplay)) {    // See if it's absolutely positioned    isAbsolutelyPositioned = NS_STYLE_POSITION_ABSOLUTE == position->mPosition;    // Create a scroll frame    nsIFrame* scrollFrame;    NS_NewScrollFrame(scrollFrame);    // Initialize it    InitializeScrollFrame(scrollFrame, aPresContext, aContent, aParentFrame,  aStyleContext,                         aAbsoluteItems,  newFrame, isAbsolutelyPositioned, PR_FALSE);#if 0 // XXX The following "ifdef" could has been moved to the method "InitializeScrollFrame"    nsIFrame* geometricParent = isAbsolutelyPositioned ? aAbsoluteItems.containingBlock :                                                         aParentFrame;    scrollFrame->Init(*aPresContext, aContent, geometricParent, aStyleContext);    // The scroll frame gets the original style context, and the scrolled    // frame gets a SCROLLED-CONTENT pseudo element style context that    // inherits the background properties    nsIStyleContext*  scrolledPseudoStyle = aPresContext->ResolvePseudoStyleContextFor                        (aContent, nsHTMLAtoms::scrolledContentPseudo, aStyleContext);    // Create an area container for the frame    nsIFrame* scrolledFrame;    NS_NewAreaFrame(scrolledFrame, NS_BLOCK_SHRINK_WRAP);    // Initialize the frame and force it to have a view    scrolledFrame->Init(*aPresContext, aContent, scrollFrame, scrolledPseudoStyle);    nsHTMLContainerFrame::CreateViewForFrame(*aPresContext, scrolledFrame,                                             scrolledPseudoStyle, PR_TRUE);    NS_RELEASE(scrolledPseudoStyle);    // Process children    if (isAbsolutelyPositioned) {      // The area frame becomes a container for child frames that are      // absolutely positioned      nsAbsoluteItems  absoluteItems(scrolledFrame);      nsFrameItems     childItems;      ProcessChildren(aPresContext, aContent, scrolledFrame, absoluteItems,                      childItems);        // Set the initial child lists      scrolledFrame->SetInitialChildList(*aPresContext, nsnull, childItems.childList);      if (nsnull != absoluteItems.childList) {        scrolledFrame->SetInitialChildList(*aPresContext, nsLayoutAtoms::absoluteList,                                           absoluteItems.childList);      }    } else {      nsFrameItems childItems;      ProcessChildren(aPresContext, aContent, scrolledFrame, aAbsoluteItems,                      childItems);        // Set the initial child lists      scrolledFrame->SetInitialChildList(*aPresContext, nsnull, childItems.childList);    }    scrollFrame->SetInitialChildList(*aPresContext, nsnull, scrolledFrame);    aNewFrame = scrollFrame;#endif  // See if the frame is absolutely positioned  } else if ((NS_STYLE_POSITION_ABSOLUTE == position->mPosition) &&             ((NS_STYLE_DISPLAY_BLOCK == aDisplay->mDisplay) ||              (NS_STYLE_DISPLAY_INLINE == aDisplay->mDisplay) ||              (NS_STYLE_DISPLAY_LIST_ITEM == aDisplay->mDisplay))) {    isAbsolutelyPositioned = PR_TRUE;    // Create an area frame    NS_NewAreaFrame(newFrame, 0);    newFrame->Init(*aPresContext, aContent, aAbsoluteItems.containingBlock,                   aStyleContext);    // Create a view    nsHTMLContainerFrame::CreateViewForFrame(*aPresContext, newFrame,                                             aStyleContext, PR_FALSE);    // Process the child content. The area frame becomes a container for child    // frames that are absolutely positioned    nsAbsoluteItems  absoluteItems(newFrame);    nsFrameItems     childItems;    ProcessChildren(aPresContext, aContent, newFrame, absoluteItems, childItems);    // Set the frame's initial child list    newFrame->SetInitialChildList(*aPresContext, nsnull, childItems.childList);    if (nsnull != absoluteItems.childList) {      newFrame->SetInitialChildList(*aPresContext, nsLayoutAtoms::absoluteList,                                     absoluteItems.childList);    }  // See if the frame is floated, and it's a block or inline frame  } else if ((NS_STYLE_FLOAT_NONE != aDisplay->mFloats) &&             ((NS_STYLE_DISPLAY_BLOCK == aDisplay->mDisplay) ||              (NS_STYLE_DISPLAY_INLINE == aDisplay->mDisplay) ||              (NS_STYLE_DISPLAY_LIST_ITEM == aDisplay->mDisplay))) {    // Create an area frame    NS_NewAreaFrame(newFrame, NS_BLOCK_SHRINK_WRAP);    // Initialize the frame    newFrame->Init(*aPresContext, aContent, aParentFrame, aStyleContext);    // See if we need to create a view    nsHTMLContainerFrame::CreateViewForFrame(*aPresContext, newFrame,                                             aStyleContext, PR_FALSE);    // Process the child content    nsFrameItems childItems;    ProcessChildren(aPresContext, aContent, newFrame, aAbsoluteItems, childItems);    // Set the frame's initial child list    newFrame->SetInitialChildList(*aPresContext, nsnull, childItems.childList);  // See if it's a relatively positioned block  } else if ((NS_STYLE_POSITION_RELATIVE == position->mPosition) &&             ((NS_STYLE_DISPLAY_BLOCK == aDisplay->mDisplay))) {    // Create an area frame. No space manager, though    NS_NewAreaFrame(newFrame, NS_AREA_NO_SPACE_MGR);    newFrame->Init(*aPresContext, aContent, aParentFrame, aStyleContext);    // Create a view    nsHTMLContainerFrame::CreateViewForFrame(*aPresContext, newFrame,                                             aStyleContext, PR_FALSE);    // Process the child content. Relatively positioned frames becomes a    // container for child frames that are positioned    nsAbsoluteItems  absoluteItems(newFrame);    nsFrameItems     childItems;    ProcessChildren(aPresContext, aContent, newFrame, absoluteItems, childItems);    // Set the frame's initial child list    newFrame->SetInitialChildList(*aPresContext, nsnull, childItems.childList);    if (nsnull != absoluteItems.childList) {      newFrame->SetInitialChildList(*aPresContext, nsLayoutAtoms::absoluteList,                                    absoluteItems.childList);    }  } else {    PRBool  processChildren = PR_FALSE;  // whether we should process child content    // Use the 'display' property to chose a frame type    switch (aDisplay->mDisplay) {    case NS_STYLE_DISPLAY_BLOCK:    case NS_STYLE_DISPLAY_LIST_ITEM:    case NS_STYLE_DISPLAY_RUN_IN:    case NS_STYLE_DISPLAY_COMPACT:      rv = NS_NewBlockFrame(newFrame, 0);      processChildren = PR_TRUE;      break;      case NS_STYLE_DISPLAY_INLINE:      rv = NS_NewInlineFrame(newFrame);      processChildren = PR_TRUE;      break;      case NS_STYLE_DISPLAY_TABLE:    {      isAbsolutelyPositioned = NS_STYLE_POSITION_ABSOLUTE == position->mPosition;      nsIFrame* geometricParent = isAbsolutelyPositioned ? aAbsoluteItems.containingBlock :                                                           aParentFrame;      rv = ConstructTableFrame(aPresContext, aContent, geometricParent, aStyleContext,                               aAbsoluteItems, newFrame);      // Note: table construction function takes care of initializing the frame,      // processing children, and setting the initial child list      if (isAbsolutelyPositioned) {        nsIFrame* placeholderFrame;        CreatePlaceholderFrameFor(aPresContext, aContent, newFrame, aStyleContext,                                  aParentFrame, placeholderFrame);        // Add the absolutely positioned frame to its containing block's list        // of child frames        aAbsoluteItems.AddChild(newFrame);        // Add the placeholder frame to the flow        aFrameItems.AddChild(placeholderFrame);            } else {        // Add the table frame to the flow        aFrameItems.AddChild(newFrame);      }      return rv;    }      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      // XXX: see ConstructTableFrame for a prototype of how this should be done,      //      and propagate similar logic to other table elements      {        nsIFrame *parentFrame;        rv = GetAdjustedParentFrame(aParentFrame, aDisplay->mDisplay, parentFrame);        if (NS_SUCCEEDED(rv))        {          rv = NS_NewTableRowGroupFrame(newFrame);          processChildren = PR_TRUE;        }      }      break;      case NS_STYLE_DISPLAY_TABLE_COLUMN:      // XXX We should check for being inside of a table column group...      rv = NS_NewTableColFrame(newFrame);      processChildren = PR_TRUE;      break;      case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP:      // XXX We should check for being inside of a table...      {        nsIFrame *parentFrame;        rv = GetAdjustedParentFrame(aParentFrame, aDisplay->mDisplay, parentFrame);        if (NS_SUCCEEDED(rv))        {          rv = NS_NewTableColGroupFrame(newFrame);          processChildren = PR_TRUE;        }      }      break;      case NS_STYLE_DISPLAY_TABLE_ROW:      // XXX We should check for being inside of a table row group...      rv = NS_NewTableRowFrame(newFrame);      processChildren = PR_TRUE;      break;      case NS_STYLE_DISPLAY_TABLE_CELL:      // XXX We should check for being inside of a table row frame...      rv = ConstructTableCellFrame(aPresContext, aContent, aParentFrame,                                   aStyleContext, aAbsoluteItems, newFrame);      // Note: table construction function takes care of initializing the frame,      // processing children, and setting the initial child list      aFrameItems.AddChild(newFrame);      return rv;      case NS_STYLE_DISPLAY_TABLE_CAPTION:      // XXX We should check for being inside of a table row frame...      rv = NS_NewAreaFrame(newFrame, 0);      processChildren = PR_TRUE;      break;      default:      // Don't create any frame for content that's not displayed...      break;    }    // If we succeeded in creating a frame then initialize the frame and    // process children if requested    if (NS_SUCCEEDED(rv) && (nsnull != newFrame)) {      newFrame->Init(*aPresContext, aContent, aParentFrame, aStyleContext);      // See if we need to create a view, e.g. the frame is absolutely positioned      nsHTMLContainerFrame::CreateViewForFrame(*aPresContext, newFrame,                                               aStyleContext, PR_FALSE);      // Process the child content if requested      nsFrameItems childItems;      if (processChildren) {        rv = ProcessChildren(aPresContext, aContent, newFrame, aAbsoluteItems,                             childItems);      }      // Set the frame's initial child list      newFrame->SetInitialChildList(*aPresContext, nsnull, childItems.childList);    }  }  // If the frame is absolutely positioned then create a placeholder frame  if (isAbsolutelyPositioned) {    nsIFrame* placeholderFrame;    CreatePlaceholderFrameFor(aPresContext, aContent, newFrame, aStyleContext,                              aParentFrame, placeholderFrame);    // Add the absolutely positioned frame to its containing block's list    // of child frames    aAbsoluteItems.AddChild(newFrame);    // Add the placeholder frame to the flow    aFrameItems.AddChild(placeholderFrame);  } else if (nsnull != newFrame) {    // Add the frame we just created to the flowed list    aFrameItems.AddChild(newFrame);  }  return rv;}