nsIFrame* titleFrame = GetGroupTitle(aPresContext, titleRect);
nsIFrame* titleFrame = GetTitleFrame(aPresContext, titleRect);
nsTitledBoxFrame::Paint(nsIPresContext* aPresContext,                       nsIRenderingContext& aRenderingContext,                       const nsRect& aDirtyRect,                       nsFramePaintLayer aWhichLayer){  if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {    // Paint our background and border    const nsStyleDisplay* disp =      (const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display);    if (disp->mVisible == NS_STYLE_VISIBILITY_VISIBLE && mRect.width && mRect.height) {      PRIntn skipSides = GetSkipSides();      const nsStyleColor* color =        (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);      const nsStyleSpacing* spacing =        (const nsStyleSpacing*)mStyleContext->GetStyleData(eStyleStruct_Spacing);               nsMargin border;        if (!spacing->GetBorder(border)) {          NS_NOTYETIMPLEMENTED("percentage border");        }        nscoord yoff = 0;        nsRect titleRect;        nsIFrame* titleFrame = GetGroupTitle(aPresContext, titleRect);        if (titleFrame) {                    // if the border is smaller than the legend. Move the border down            // to be centered on the legend.             const nsStyleSpacing* titleSpacing;            titleFrame->GetStyleData(eStyleStruct_Spacing,                                    (const nsStyleStruct*&) titleSpacing);            nsMargin titleMargin;            titleSpacing->GetMargin(titleMargin);            titleRect.Inflate(titleMargin);                     if (border.top < titleRect.height)                yoff = (titleRect.height - border.top)/2 + titleRect.y;        }        nsRect rect(0, yoff, mRect.width, mRect.height - yoff);        nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,                                        aDirtyRect, rect, *color, *spacing, 0, 0);        if (titleFrame) {          // we should probably use PaintBorderEdges to do this but for now just use clipping          // to achieve the same effect.          PRBool clipState;          // draw left side          nsRect clipRect(rect);          clipRect.width = titleRect.x - rect.x;          clipRect.height = border.top;          aRenderingContext.PushState();          aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect, clipState);          nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,                                      aDirtyRect, rect, *spacing, mStyleContext, skipSides);            aRenderingContext.PopState(clipState);          // draw right side          clipRect = rect;          clipRect.x = titleRect.x + titleRect.width;          clipRect.width -= (titleRect.x + titleRect.width);          clipRect.height = border.top;          aRenderingContext.PushState();          aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect, clipState);          nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,                                      aDirtyRect, rect, *spacing, mStyleContext, skipSides);            aRenderingContext.PopState(clipState);                            // draw bottom          clipRect = rect;          clipRect.y += border.top;          clipRect.height = mRect.height - (yoff + border.top);                  aRenderingContext.PushState();          aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect, clipState);          nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,                                      aDirtyRect, rect, *spacing, mStyleContext, skipSides);            aRenderingContext.PopState(clipState);                  } else {                    nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,                                      aDirtyRect, nsRect(0,0,mRect.width, mRect.height), *spacing, mStyleContext, skipSides);        }    }  }  PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);#ifdef DEBUG  if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) {    nsIView* view;    GetView(aPresContext, &view);    if (nsnull != view) {      aRenderingContext.SetColor(NS_RGB(0,0,255));    }    else {      aRenderingContext.SetColor(NS_RGB(255,0,0));    }    aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height);  }#endif  return NS_OK;}