diff --git a/mozilla/gfx/thebes/public/gfxContext.h b/mozilla/gfx/thebes/public/gfxContext.h index 62dc8044f23..29f71b18ebc 100644 --- a/mozilla/gfx/thebes/public/gfxContext.h +++ b/mozilla/gfx/thebes/public/gfxContext.h @@ -581,4 +581,35 @@ private: PRInt32 mFlags; }; + +/** + * Sentry helper class for functions with multiple return points that need to + * call Save() on a gfxContext and have Restore() called automatically on the + * gfxContext before they return. + */ +class THEBES_API gfxContextAutoSaveRestore +{ +public: + gfxContextAutoSaveRestore() : mContext(nsnull) {} + + gfxContextAutoSaveRestore(gfxContext *aContext) : mContext(aContext) { + mContext->Save(); + } + + ~gfxContextAutoSaveRestore() { + if (mContext) { + mContext->Restore(); + } + } + + void SetContext(gfxContext *aContext) { + NS_ASSERTION(!mContext, "Not going to call Restore() on some context!!!"); + mContext = aContext; + mContext->Save(); + } + +private: + gfxContext *mContext; +}; + #endif /* GFX_CONTEXT_H */ diff --git a/mozilla/layout/svg/base/src/nsSVGInnerSVGFrame.cpp b/mozilla/layout/svg/base/src/nsSVGInnerSVGFrame.cpp index 0bc6b93c1d6..6a38a78477b 100644 --- a/mozilla/layout/svg/base/src/nsSVGInnerSVGFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGInnerSVGFrame.cpp @@ -158,37 +158,32 @@ nsSVGInnerSVGFrame::GetType() const NS_IMETHODIMP nsSVGInnerSVGFrame::PaintSVG(nsSVGRenderState *aContext, nsRect *aDirtyRect) { - nsresult rv = NS_OK; - - gfxContext *gfx = aContext->GetGfxContext(); - - gfx->Save(); + gfxContextAutoSaveRestore autoSR; if (GetStyleDisplay()->IsScrollableOverflow()) { + float x, y, width, height; + static_cast(mContent)-> + GetAnimatedLengthValues(&x, &y, &width, &height, nsnull); + + if (width <= 0 || height <= 0) { + return NS_OK; + } + nsCOMPtr clipTransform; if (!mPropagateTransform) { NS_NewSVGMatrix(getter_AddRefs(clipTransform)); } else { - nsSVGContainerFrame *parent = static_cast - (mParent); - clipTransform = parent->GetCanvasTM(); + clipTransform = static_cast(mParent)->GetCanvasTM(); } if (clipTransform) { - nsSVGSVGElement *svg = static_cast(mContent); - - float x, y, width, height; - svg->GetAnimatedLengthValues(&x, &y, &width, &height, nsnull); - + gfxContext *gfx = aContext->GetGfxContext(); + autoSR.SetContext(gfx); nsSVGUtils::SetClipRect(gfx, clipTransform, x, y, width, height); } } - rv = nsSVGInnerSVGFrameBase::PaintSVG(aContext, aDirtyRect); - - gfx->Restore(); - - return rv; + return nsSVGInnerSVGFrameBase::PaintSVG(aContext, aDirtyRect); } void