nsIFrame* groupFrame; groupBox->GetFrame(&groupFrame);
nsGroupBoxFrame::Paint(nsPresContext*      aPresContext,                        nsIRenderingContext& aRenderingContext,                        const nsRect&        aDirtyRect,                        nsFramePaintLayer    aWhichLayer,                        PRUint32             aFlags){  if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {    // Paint our background and border    if (GetStyleVisibility()->IsVisible() && mRect.width && mRect.height) {      PRIntn skipSides = 0;      const nsStyleBorder* borderStyleData = GetStyleBorder();      const nsStylePadding* paddingStyleData = GetStylePadding();               nsMargin border;        if (!borderStyleData->GetBorder(border)) {          NS_NOTYETIMPLEMENTED("percentage border");        }        nscoord yoff = 0;        nsRect groupRect;        nsIBox* groupBox = GetCaptionBox(aPresContext, groupRect);        if (groupBox) {                    nsIFrame* groupFrame;            groupBox->GetFrame(&groupFrame);            // if the border is smaller than the legend. Move the border down            // to be centered on the legend.             nsMargin groupMargin;            groupFrame->GetStyleMargin()->GetMargin(groupMargin);            groupRect.Inflate(groupMargin);                     if (border.top < groupRect.height)                yoff = (groupRect.height - border.top)/2 + groupRect.y;        }        nsRect rect(0, yoff, mRect.width, mRect.height - yoff);        nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,                                        aDirtyRect, rect, *borderStyleData,                                        *paddingStyleData, PR_FALSE);        if (groupBox) {          // we should probably use PaintBorderEdges to do this but for now just use clipping          // to achieve the same effect.          // draw left side          nsRect clipRect(rect);          clipRect.width = groupRect.x - rect.x;          clipRect.height = border.top;          aRenderingContext.PushState();          aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);          nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,                                      aDirtyRect, rect, *borderStyleData, mStyleContext, skipSides);            aRenderingContext.PopState();          // draw right side          clipRect = rect;          clipRect.x = groupRect.x + groupRect.width;          clipRect.width -= (groupRect.x + groupRect.width);          clipRect.height = border.top;          aRenderingContext.PushState();          aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);          nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,                                      aDirtyRect, rect, *borderStyleData, mStyleContext, skipSides);            aRenderingContext.PopState();                            // draw bottom          clipRect = rect;          clipRect.y += border.top;          clipRect.height = mRect.height - (yoff + border.top);                  aRenderingContext.PushState();          aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);          nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,                                      aDirtyRect, rect, *borderStyleData, mStyleContext, skipSides);            aRenderingContext.PopState();                  } 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()) {    if (HasView()) {      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;}