if (titleBox) {
if (groupBox) {
nsGroupBoxFrame::Paint(nsIPresContext*      aPresContext,                        nsIRenderingContext& aRenderingContext,                        const nsRect&        aDirtyRect,                        nsFramePaintLayer    aWhichLayer,                        PRUint32             aFlags){  if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {    // Paint our background and border    const nsStyleVisibility* vis =       (const nsStyleVisibility*)mStyleContext->GetStyleData(eStyleStruct_Visibility);    if (vis->IsVisible() && mRect.width && mRect.height) {      PRIntn skipSides = GetSkipSides();      const nsStyleBackground* color =        (const nsStyleBackground*)mStyleContext->GetStyleData(eStyleStruct_Background);      const nsStyleBorder* borderStyleData =        (const nsStyleBorder*)mStyleContext->GetStyleData(eStyleStruct_Border);               nsMargin border;        if (!borderStyleData->GetBorder(border)) {          NS_NOTYETIMPLEMENTED("percentage border");        }        nscoord yoff = 0;        nsRect titleRect;        nsIBox* titleBox = GetTitleBox(aPresContext, titleRect);        if (titleBox) {                    nsIFrame* titleFrame;            titleBox->GetFrame(&titleFrame);            // if the border is smaller than the legend. Move the border down            // to be centered on the legend.             const nsStyleMargin* titleMarginData;            titleFrame->GetStyleData(eStyleStruct_Margin,                                    (const nsStyleStruct*&) titleMarginData);            nsMargin titleMargin;            titleMarginData->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, *borderStyleData, 0, 0);        if (titleBox) {          // 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, *borderStyleData, 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, *borderStyleData, 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, *borderStyleData, mStyleContext, skipSides);            aRenderingContext.PopState(clipState);                  } else {                    nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,                                      aDirtyRect, nsRect(0,0,mRect.width, mRect.height), *borderStyleData, 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;}