b=406458; code cleanup: add new ThebesContext() call as opposed to NATIVE_THEBES_CONTEXT hackery, r=stuart
authorvladimir@pobox.com
Tue, 18 Dec 2007 15:01:15 -0800
changeset 9438 9d27f01afee9569154535ac7313b7d3e5ee34d9c
parent 9437 0b1cead41b8380ab6b15f0e544a013ff1da96ebb
child 9439 84f209a802d43ce86aa79ef8a479c7aafc68e95a
push idunknown
push userunknown
push dateunknown
reviewersstuart
bugs406458
milestone1.9b3pre
b=406458; code cleanup: add new ThebesContext() call as opposed to NATIVE_THEBES_CONTEXT hackery, r=stuart
gfx/public/nsIRenderingContext.h
gfx/src/nsRenderingContextImpl.h
gfx/src/thebes/nsThebesFontMetrics.cpp
gfx/src/thebes/nsThebesFontMetrics.h
gfx/src/thebes/nsThebesImage.cpp
gfx/src/thebes/nsThebesRenderingContext.h
layout/base/nsCSSRendering.cpp
layout/base/nsDisplayList.cpp
layout/base/nsLayoutUtils.cpp
layout/generic/nsBlockFrame.cpp
layout/generic/nsFrame.cpp
layout/generic/nsHTMLCanvasFrame.cpp
layout/generic/nsHTMLContainerFrame.cpp
layout/generic/nsObjectFrame.cpp
layout/generic/nsTextFrameThebes.cpp
layout/mathml/base/src/nsMathMLContainerFrame.cpp
layout/svg/base/src/nsSVGUtils.cpp
layout/xul/base/src/nsTextBoxFrame.cpp
view/src/nsViewManager.cpp
widget/src/beos/nsWindow.cpp
widget/src/cocoa/nsNativeThemeCocoa.mm
widget/src/gtk2/nsNativeThemeGTK.cpp
widget/src/gtk2/nsWindow.cpp
widget/src/windows/nsNativeThemeWin.cpp
--- a/gfx/public/nsIRenderingContext.h
+++ b/gfx/public/nsIRenderingContext.h
@@ -691,16 +691,21 @@ public:
    *
    * @param aRect  Rectangle in which to render the EPSF.
    * @param aDataFile - plugin data stored in a file
    * @return NS_OK for success, or a suitable error value.
    *         NS_ERROR_NOT_IMPLEMENTED is returned if the rendering context
    *         doesn't support rendering EPSF, 
    */
   NS_IMETHOD RenderEPS(const nsRect& aRect, FILE *aDataFile) = 0;
+
+  /**
+   * Return the Thebes gfxContext associated with this nsIRenderingContext.
+   */
+  virtual gfxContext *ThebesContext() = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIRenderingContext, NS_IRENDERING_CONTEXT_IID)
 
 // Bit values for GetHints
 
 /**
  * This bit, when set, indicates that the underlying rendering system
--- a/gfx/src/nsRenderingContextImpl.h
+++ b/gfx/src/nsRenderingContextImpl.h
@@ -188,14 +188,16 @@ public:
                                 const nscoord* aSpacing = nsnull)
   { return NS_ERROR_NOT_IMPLEMENTED; }
   NS_IMETHOD DrawStringInternal(const PRUnichar *aString, PRUint32 aLength,
                                 nscoord aX, nscoord aY,
                                 PRInt32 aFontID = -1,
                                 const nscoord* aSpacing = nsnull)
   { return NS_ERROR_NOT_IMPLEMENTED; }
 
+  gfxContext *ThebesContext() { return nsnull; }
+
 protected:
   virtual ~nsRenderingContextImpl();
 
 };
 
 #endif /* nsRenderingContextImpl */
--- a/gfx/src/thebes/nsThebesFontMetrics.cpp
+++ b/gfx/src/thebes/nsThebesFontMetrics.cpp
@@ -383,17 +383,17 @@ nsThebesFontMetrics::DrawString(const ch
     StubPropertyProvider provider;
     AutoTextRun textRun(this, aContext, aString, aLength);
     if (!textRun.get())
         return NS_ERROR_FAILURE;
     gfxPoint pt(aX, aY);
     if (mTextRunRTL) {
         pt.x += textRun->GetAdvanceWidth(0, aLength, &provider);
     }
-    textRun->Draw(aContext->Thebes(), pt, 0, aLength,
+    textRun->Draw(aContext->ThebesContext(), pt, 0, aLength,
                   nsnull, &provider, nsnull);
     return NS_OK;
 }
 
 nsresult
 nsThebesFontMetrics::DrawString(const PRUnichar* aString, PRUint32 aLength,
                                 nscoord aX, nscoord aY,
                                 PRInt32 aFontID,
@@ -407,31 +407,31 @@ nsThebesFontMetrics::DrawString(const PR
     StubPropertyProvider provider;
     AutoTextRun textRun(this, aContext, aString, aLength);
     if (!textRun.get())
         return NS_ERROR_FAILURE;
     gfxPoint pt(aX, aY);
     if (mTextRunRTL) {
         pt.x += textRun->GetAdvanceWidth(0, aLength, &provider);
     }
-    textRun->Draw(aContext->Thebes(), pt, 0, aLength,
+    textRun->Draw(aContext->ThebesContext(), pt, 0, aLength,
                   nsnull, &provider, nsnull);
     return NS_OK;
 }
 
 #ifdef MOZ_MATHML
 
 static void
 GetTextRunBoundingMetrics(gfxTextRun *aTextRun, PRUint32 aStart, PRUint32 aLength,
                           nsThebesRenderingContext *aContext,
                           nsBoundingMetrics &aBoundingMetrics)
 {
     StubPropertyProvider provider;
     gfxTextRun::Metrics theMetrics =
-        aTextRun->MeasureText(aStart, aLength, PR_TRUE, aContext->Thebes(), &provider);
+        aTextRun->MeasureText(aStart, aLength, PR_TRUE, aContext->ThebesContext(), &provider);
 
     aBoundingMetrics.leftBearing = NSToCoordFloor(theMetrics.mBoundingBox.X());
     aBoundingMetrics.rightBearing = NSToCoordCeil(theMetrics.mBoundingBox.XMost());
     aBoundingMetrics.width = NSToCoordRound(theMetrics.mAdvanceWidth);
     aBoundingMetrics.ascent = NSToCoordCeil(- theMetrics.mBoundingBox.Y());
     aBoundingMetrics.descent = NSToCoordCeil(theMetrics.mBoundingBox.YMost());
 }
 
--- a/gfx/src/thebes/nsThebesFontMetrics.h
+++ b/gfx/src/thebes/nsThebesFontMetrics.h
@@ -152,26 +152,25 @@ protected:
     const gfxFont::Metrics& GetMetrics() const;
 
     class AutoTextRun {
     public:
         AutoTextRun(nsThebesFontMetrics* aMetrics, nsIRenderingContext* aRC,
                     const char* aString, PRInt32 aLength) {
             mTextRun = gfxTextRunCache::MakeTextRun(
                 reinterpret_cast<const PRUint8*>(aString), aLength,
-                aMetrics->mFontGroup,
-                static_cast<gfxContext*>(aRC->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT)),
+                aMetrics->mFontGroup, aRC->ThebesContext(),
                 aMetrics->mP2A,
                 ComputeFlags(aMetrics));
         }
         AutoTextRun(nsThebesFontMetrics* aMetrics, nsIRenderingContext* aRC,
                     const PRUnichar* aString, PRInt32 aLength) {
             mTextRun = gfxTextRunCache::MakeTextRun(
                 aString, aLength, aMetrics->mFontGroup,
-                static_cast<gfxContext*>(aRC->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT)),
+                aRC->ThebesContext(),
                 aMetrics->mP2A,
                 ComputeFlags(aMetrics));
         }
         gfxTextRun* operator->() { return mTextRun.get(); }
         gfxTextRun* get() { return mTextRun.get(); }
 
     private:
         gfxTextRunCache::AutoTextRun mTextRun;
--- a/gfx/src/thebes/nsThebesImage.cpp
+++ b/gfx/src/thebes/nsThebesImage.cpp
@@ -378,17 +378,17 @@ nsThebesImage::Draw(nsIRenderingContext 
                     const gfxRect &aDestRect)
 {
     if (NS_UNLIKELY(aDestRect.IsEmpty())) {
         NS_ERROR("nsThebesImage::Draw zero dest size - please fix caller.");
         return NS_OK;
     }
 
     nsThebesRenderingContext *thebesRC = static_cast<nsThebesRenderingContext*>(&aContext);
-    gfxContext *ctx = thebesRC->Thebes();
+    gfxContext *ctx = thebesRC->ThebesContext();
 
 #if 0
     fprintf (stderr, "nsThebesImage::Draw src [%f %f %f %f] dest [%f %f %f %f] trans: [%f %f] dec: [%f %f]\n",
              aSourceRect.pos.x, aSourceRect.pos.y, aSourceRect.size.width, aSourceRect.size.height,
              aDestRect.pos.x, aDestRect.pos.y, aDestRect.size.width, aDestRect.size.height,
              ctx->CurrentMatrix().GetTranslation().x, ctx->CurrentMatrix().GetTranslation().y,
              mDecoded.x, mDecoded.y, mDecoded.width, mDecoded.height);
 #endif
--- a/gfx/src/thebes/nsThebesRenderingContext.h
+++ b/gfx/src/thebes/nsThebesRenderingContext.h
@@ -206,17 +206,17 @@ public:
                              PRUint32 aStart,
                              PRUint32 aEnd,
                              PRUint32 &aWidth);
 
     NS_IMETHOD RenderEPS(const nsRect& aRect, FILE *aDataFile);
 
     // Thebes specific stuff
 
-    gfxContext *Thebes() { return mThebes; }
+    gfxContext *ThebesContext() { return mThebes; }
 
     nsTransform2D& CurrentTransform();
 
     void TransformCoord (nscoord *aX, nscoord *aY);
 
 protected:
     nsCOMPtr<nsIDeviceContext> mDeviceContext;
     // cached pixels2twips, twips2pixels values
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -2736,18 +2736,17 @@ nsCSSRendering::PaintBorder(nsPresContex
       borderColors[i] = 0x0;
     else if (foreground)
       borderColors[i] = ourColor->mColor;
   }
 
   SF(" borderStyles: %d %d %d %d\n", borderStyles[0], borderStyles[1], borderStyles[2], borderStyles[3]);
 
   // start drawing
-  nsRefPtr<gfxContext> ctx = (gfxContext*)
-    aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
 
   ctx->Save();
 
 #if 0
   // this will draw a transparent red backround underneath the area between iRect and oRect
   ctx->Save();
   ctx->Rectangle(iRect);
   ctx->Clip();
@@ -2895,18 +2894,17 @@ nsCSSRendering::PaintOutline(nsPresConte
 
   // convert the border widths
   gfxFloat outlineWidths[4] = { width / twipsPerPixel,
                                 width / twipsPerPixel,
                                 width / twipsPerPixel,
                                 width / twipsPerPixel };
 
   // start drawing
-  nsRefPtr<gfxContext> ctx = (gfxContext*)
-    aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
 
   ctx->Save();
 
   DrawBorders(ctx,
               oRect,
               iRect,
               outlineStyles,
               outlineWidths,
@@ -3637,18 +3635,17 @@ nsCSSRendering::PaintBackgroundWithSC(ns
       ComputeBackgroundAnchorPoint(aColor, bgOriginArea, bgClipArea, tileWidth, tileHeight, anchor);
     }
 
     // For scrolling attachment, the anchor is within the 'background-clip'
     anchor.x += bgClipArea.x - aBorderArea.x;
     anchor.y += bgClipArea.y - aBorderArea.y;
   }
 
-  nsRefPtr<gfxContext> ctx = (gfxContext*)
-    aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
   ctx->Save();
 
   nscoord appUnitsPerPixel = aPresContext->DevPixelsToAppUnits(1);
 
   ctx->NewPath();
   ctx->Rectangle(RectToGfxRect(dirtyRect, appUnitsPerPixel), PR_TRUE);
   ctx->Clip();
 
@@ -3934,18 +3931,17 @@ nsCSSRendering::PaintRoundedBackground(n
                                        nsIRenderingContext& aRenderingContext,
                                        nsIFrame* aForFrame,
                                        const nsRect& aBgClipArea,
                                        const nsStyleBackground& aColor,
                                        const nsStyleBorder& aBorder,
                                        nscoord aTheRadius[4],
                                        PRBool aCanPaintNonWhite)
 {
-  nsRefPtr<gfxContext> ctx = (gfxContext*)
-    aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
 
   // needed for our border thickness
   nscoord appUnitsPerPixel = aPresContext->AppUnitsPerDevPixel();
 
   nscolor color = aColor.mBackgroundColor;
   if (!aCanPaintNonWhite) {
     color = NS_RGB(255, 255, 255);
   }
@@ -4178,17 +4174,17 @@ nsCSSRendering::DrawTableBorderSegment(n
   if ((twipsPerPixel >= aBorder.width) || (twipsPerPixel >= aBorder.height) ||
       (NS_STYLE_BORDER_STYLE_DASHED == aBorderStyle) || (NS_STYLE_BORDER_STYLE_DOTTED == aBorderStyle)) {
     // no beveling for 1 pixel border, dash or dot
     aStartBevelOffset = 0;
     aEndBevelOffset = 0;
   }
 
 #ifdef MOZ_CAIRO_GFX
-  gfxContext *ctx = (gfxContext*) aContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  gfxContext *ctx = aContext.ThebesContext();
   gfxContext::AntialiasMode oldMode = ctx->CurrentAntialiasMode();
   ctx->SetAntialiasMode(gfxContext::MODE_ALIASED);
 #endif
 
   switch (aBorderStyle) {
   case NS_STYLE_BORDER_STYLE_NONE:
   case NS_STYLE_BORDER_STYLE_HIDDEN:
     //NS_ASSERTION(PR_FALSE, "style of none or hidden");
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -778,17 +778,17 @@ void nsDisplayOpacity::Paint(nsDisplayLi
 
   nsRect bounds;
   bounds.IntersectRect(GetBounds(aBuilder), aDirtyRect);
 
   nsCOMPtr<nsIDeviceContext> devCtx;
   aCtx->GetDeviceContext(*getter_AddRefs(devCtx));
   float a2p = 1.0f / devCtx->AppUnitsPerDevPixel();
 
-  nsRefPtr<gfxContext> ctx = (gfxContext*)aCtx->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  nsRefPtr<gfxContext> ctx = aCtx->ThebesContext();
 
   ctx->Save();
 
   ctx->NewPath();
   ctx->Rectangle(gfxRect(bounds.x * a2p,
                          bounds.y * a2p,
                          bounds.width * a2p,
                          bounds.height * a2p),
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -2234,19 +2234,17 @@ nsLayoutUtils::DrawImage(nsIRenderingCon
     aImage->GetHeight(&h);
     pxSrc.size.width = gfxFloat(w);
     pxSrc.size.height = gfxFloat(h);
   }
 
   nsCOMPtr<nsIDeviceContext> dc;
   aRenderingContext->GetDeviceContext(*getter_AddRefs(dc));
 
-  nsRefPtr<gfxContext> ctx = static_cast<gfxContext*>
-                                        (aRenderingContext->GetNativeGraphicData(
-      nsIRenderingContext::NATIVE_THEBES_CONTEXT));
+  nsRefPtr<gfxContext> ctx = aRenderingContext->ThebesContext();
 
   // the dest rect is affected by the current transform; that'll be
   // handled by Image::Draw(), when we actually set up the rectangle.
   
   // Snap the edges of where layout wants the image to the nearest
   // pixel, but then convert back to gfxFloats for the rest of the math.
   gfxRect pxDest;
   {
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -5869,18 +5869,17 @@ nsBlockFrame::PaintTextDecorationLine(ns
     start += indent;
     width -= indent;
   }
       
   // Only paint if we have a positive width
   if (width > 0) {
     const nsStyleVisibility* visibility = GetStyleVisibility();
     PRBool isRTL = visibility->mDirection == NS_STYLE_DIRECTION_RTL;
-    nsRefPtr<gfxContext> ctx = (gfxContext*)
-      aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+    nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
     gfxPoint pt(PresContext()->AppUnitsToGfxUnits(start + aPt.x),
                 PresContext()->AppUnitsToGfxUnits(aLine->mBounds.y + aPt.y));
     gfxSize size(PresContext()->AppUnitsToGfxUnits(width),
                  PresContext()->AppUnitsToGfxUnits(aSize));
     nsCSSRendering::PaintDecorationLine(
       ctx, aColor, pt, size,
       PresContext()->AppUnitsToGfxUnits(aLine->GetAscent()),
       PresContext()->AppUnitsToGfxUnits(aOffset),
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -773,17 +773,17 @@ void nsDisplaySelectionOverlay::Paint(ns
   nsCOMPtr<nsILookAndFeel> look;
   look = do_GetService(kLookAndFeelCID, &result);
   if (NS_SUCCEEDED(result) && look)
     look->GetColor(colorID, color);
 
   gfxRGBA c(color);
   c.a = .5;
 
-  nsRefPtr<gfxContext> ctx = (gfxContext*)aCtx->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  nsRefPtr<gfxContext> ctx = aCtx->ThebesContext();
   ctx->SetColor(c);
 
   nsRect rect(aBuilder->ToReferenceFrame(mFrame), mFrame->GetSize());
   rect.IntersectRect(rect, aDirtyRect);
   rect.ScaleRoundOut(1.0f / mFrame->PresContext()->AppUnitsPerDevPixel());
   ctx->NewPath();
   ctx->Rectangle(gfxRect(rect.x, rect.y, rect.width, rect.height), PR_TRUE);
   ctx->Fill();
--- a/layout/generic/nsHTMLCanvasFrame.cpp
+++ b/layout/generic/nsHTMLCanvasFrame.cpp
@@ -207,26 +207,26 @@ nsHTMLCanvasFrame::PaintCanvas(nsIRender
   {
     float sx = inner.width / (float) sizeAppUnits.width;
     float sy = inner.height / (float) sizeAppUnits.height;
 
     aRenderingContext.PushState();
     aRenderingContext.Translate(inner.x, inner.y);
     aRenderingContext.Scale(sx, sy);
 
-    canvas->RenderContexts((gfxContext*) aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));
+    canvas->RenderContexts(aRenderingContext.ThebesContext());
 
     aRenderingContext.PopState();
   } else {
     //nsIRenderingContext::AutoPushTranslation(&aRenderingContext, px, py);
 
     aRenderingContext.PushState();
     aRenderingContext.Translate(inner.x, inner.y);
 
-    canvas->RenderContexts((gfxContext*) aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));
+    canvas->RenderContexts(aRenderingContext.ThebesContext());
 
     aRenderingContext.PopState();
   }
 }
 
 static void PaintCanvas(nsIFrame* aFrame, nsIRenderingContext* aCtx,
                         const nsRect& aDirtyRect, nsPoint aPt)
 {
--- a/layout/generic/nsHTMLContainerFrame.cpp
+++ b/layout/generic/nsHTMLContainerFrame.cpp
@@ -207,18 +207,17 @@ nsHTMLContainerFrame::PaintTextDecoratio
   NS_FOR_CSS_SIDES(side) {
     if (skip & (1 << side)) {
       bp.side(side) = 0;
     }
   }
   const nsStyleVisibility* visibility = GetStyleVisibility();
   PRBool isRTL = visibility->mDirection == NS_STYLE_DIRECTION_RTL;
   nscoord innerWidth = mRect.width - bp.left - bp.right;
-  nsRefPtr<gfxContext> ctx = (gfxContext*)
-    aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
   gfxPoint pt(PresContext()->AppUnitsToGfxUnits(bp.left + aPt.x),
               PresContext()->AppUnitsToGfxUnits(bp.top + aPt.y));
   gfxSize size(PresContext()->AppUnitsToGfxUnits(innerWidth),
                PresContext()->AppUnitsToGfxUnits(aSize));
   nsCSSRendering::PaintDecorationLine(
     ctx, aColor, pt, size, PresContext()->AppUnitsToGfxUnits(aAscent),
     PresContext()->AppUnitsToGfxUnits(aOffset),
     PresContext()->AppUnitsToGfxUnits(aSize),
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -1234,17 +1234,17 @@ nsObjectFrame::PaintPlugin(nsIRenderingC
       /*
        * Layout now has an optimized way of painting. Now we always get
        * a new drawing surface, sized to be just what's needed. Windowless
        * plugins need a transform applied to their origin so they paint
        * in the right place. Since |SetWindow| is no longer being used
        * to tell the plugin where it is, we dispatch a NPWindow through
        * |HandleEvent| to tell the plugin when its window moved
        */
-      nsRefPtr<gfxContext> ctx = (gfxContext*)aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+      nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
       gfxMatrix ctxMatrix = ctx->CurrentMatrix();
       if (ctxMatrix.HasNonTranslation()) {
         // soo; in the future, we should be able to render
         // the object content to an offscreen DC, and then
         // composite it in with the right transforms.
 
         // But, we don't bother doing that, because we don't
         // have the event handling story figured out yet.
--- a/layout/generic/nsTextFrameThebes.cpp
+++ b/layout/generic/nsTextFrameThebes.cpp
@@ -1288,18 +1288,17 @@ GetReferenceRenderingContext(nsTextFrame
   nsCOMPtr<nsIRenderingContext> tmp = aRC;
   if (!tmp) {
     nsresult rv = aTextFrame->PresContext()->PresShell()->
       CreateRenderingContext(aTextFrame, getter_AddRefs(tmp));
     if (NS_FAILED(rv))
       return nsnull;
   }
 
-  gfxContext* ctx = static_cast<gfxContext*>
-          (tmp->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));
+  gfxContext* ctx = tmp->ThebesContext();
   NS_ADDREF(ctx);
   return ctx;
 }
 
 /**
  * The returned textrun must be released via gfxTextRunCache::ReleaseTextRun
  * or gfxTextRunCache::AutoTextRun.
  */
@@ -4098,18 +4097,17 @@ nsTextFrame::PaintText(nsIRenderingConte
   if (!mTextRun)
     return;
 
   nsTextPaintStyle textPaintStyle(this);
   PropertyProvider provider(this, iter);
   // Trim trailing whitespace
   provider.InitializeForDisplay(PR_TRUE);
 
-  gfxContext* ctx = static_cast<gfxContext*>
-                               (aRenderingContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));
+  gfxContext* ctx = aRenderingContext->ThebesContext();
 
   gfxPoint framePt(aPt.x, aPt.y);
   gfxPoint textBaselinePt(
       mTextRun->IsRightToLeft() ? gfxFloat(aPt.x + GetSize().width) : framePt.x,
       GetSnappedBaselineY(ctx, aPt.y));
 
   gfxRect dirtyRect(aDirtyRect.x, aDirtyRect.y,
                     aDirtyRect.width, aDirtyRect.height);
@@ -4865,18 +4863,17 @@ void nsTextFrame::MarkIntrinsicWidthsDir
 
 // XXX this doesn't handle characters shaped by line endings. We need to
 // temporarily override the "current line ending" settings.
 void
 nsTextFrame::AddInlineMinWidthForFlow(nsIRenderingContext *aRenderingContext,
                                       nsIFrame::InlineMinWidthData *aData)
 {
   PRUint32 flowEndInTextRun;
-  gfxContext* ctx = static_cast<gfxContext*>
-    (aRenderingContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));
+  gfxContext* ctx = aRenderingContext->ThebesContext();
   gfxSkipCharsIterator iter =
     EnsureTextRun(ctx, nsnull, aData->line, &flowEndInTextRun);
   if (!mTextRun)
     return;
 
   // Pass null for the line container. This will disable tab spacing, but that's
   // OK since we can't really handle tabs for intrinsic sizing anyway.
   const nsTextFragment* frag = mContent->GetText();
@@ -4968,18 +4965,17 @@ nsTextFrame::AddInlineMinWidth(nsIRender
 
 // XXX this doesn't handle characters shaped by line endings. We need to
 // temporarily override the "current line ending" settings.
 void
 nsTextFrame::AddInlinePrefWidthForFlow(nsIRenderingContext *aRenderingContext,
                                        nsIFrame::InlinePrefWidthData *aData)
 {
   PRUint32 flowEndInTextRun;
-  gfxContext* ctx = static_cast<gfxContext*>
-    (aRenderingContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));
+  gfxContext* ctx = aRenderingContext->ThebesContext();
   gfxSkipCharsIterator iter =
     EnsureTextRun(ctx, nsnull, aData->line, &flowEndInTextRun);
   if (!mTextRun)
     return;
 
   // Pass null for the line container. This will disable tab spacing, but that's
   // OK since we can't really handle tabs for intrinsic sizing anyway.
   PropertyProvider provider(mTextRun, GetStyleText(), mContent->GetText(), this,
@@ -5274,18 +5270,17 @@ nsTextFrame::Reflow(nsPresContext*      
       PRInt32 whitespaceCount = GetTrimmableWhitespaceCount(frag, offset, length, 1);
       offset += whitespaceCount;
       length -= whitespaceCount;
     }
   }
 
   PRUint32 flowEndInTextRun;
   nsIFrame* lineContainer = lineLayout.GetLineContainerFrame();
-  gfxContext* ctx = static_cast<gfxContext*>
-    (aReflowState.rendContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));
+  gfxContext* ctx = aReflowState.rendContext->ThebesContext();
   gfxSkipCharsIterator iter =
     EnsureTextRun(ctx, lineContainer, lineLayout.GetLine(), &flowEndInTextRun);
 
   PRInt32 skippedRunLength;
   if (mTextRun && mTextRun->GetLength() == iter.GetSkippedOffset() &&
       length > 0 &&
       (!iter.IsOriginalCharSkipped(&skippedRunLength) || skippedRunLength < length)) {
     // The textrun does not map enough text for this frame. This can happen
@@ -5573,18 +5568,17 @@ nsTextFrame::TrimTrailingWhiteSpace(nsIR
   result.mDeltaWidth = 0;
 
   AddStateBits(TEXT_END_OF_LINE);
 
   PRInt32 contentLength = GetContentLength();
   if (!contentLength)
     return result;
 
-  gfxContext* ctx = static_cast<gfxContext*>
-    (aRC->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));
+  gfxContext* ctx = aRC->ThebesContext();
   gfxSkipCharsIterator start = EnsureTextRun(ctx);
   NS_ENSURE_TRUE(mTextRun, result);
 
   PRUint32 trimmedStart = start.GetSkippedOffset();
 
   const nsTextFragment* frag = mContent->GetText();
   TrimmedOffsets trimmed = GetTrimmedOffsets(frag, PR_TRUE);
   gfxSkipCharsIterator trimmedEndIter = start;
--- a/layout/mathml/base/src/nsMathMLContainerFrame.cpp
+++ b/layout/mathml/base/src/nsMathMLContainerFrame.cpp
@@ -1013,19 +1013,17 @@ nsMathMLContainerFrame::ReflowChild(nsIF
       // the baseline instead of going through DidReflow() and
       // GetBaseline().  This is what nsFrame::GetBaseline() will do anyway.
       aDesiredSize.ascent = aDesiredSize.height;
     }
   }
   if (IsForeignChild(aChildFrame) &&
       (aDesiredSize.mFlags | NS_REFLOW_CALC_BOUNDING_METRICS)) {
     // use ComputeTightBounds API as aDesiredSize.mBoundingMetrics is not set.
-    gfxContext* ctx = static_cast<gfxContext*>
-      (aReflowState.rendContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));  
-    nsRect r = aChildFrame->ComputeTightBounds(ctx);
+    nsRect r = aChildFrame->ComputeTightBounds(aReflowState.rendContext->ThebesContext());
     aDesiredSize.mBoundingMetrics.leftBearing = r.x;
     aDesiredSize.mBoundingMetrics.rightBearing = r.XMost();
     aDesiredSize.mBoundingMetrics.ascent = aDesiredSize.ascent - r.y;
     aDesiredSize.mBoundingMetrics.descent = r.YMost() - aDesiredSize.ascent;
     aDesiredSize.mBoundingMetrics.width = aDesiredSize.width;
   }
   return rv;
 }
--- a/layout/svg/base/src/nsSVGUtils.cpp
+++ b/layout/svg/base/src/nsSVGUtils.cpp
@@ -1542,16 +1542,15 @@ nsSVGUtils::WritePPM(const char *fname, 
 }
 #endif
 
 // ----------------------------------------------------------------------
 
 nsSVGRenderState::nsSVGRenderState(nsIRenderingContext *aContext) :
   mRenderMode(NORMAL), mRenderingContext(aContext)
 {
-  mGfxContext = static_cast<gfxContext*>
-                           (aContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));
+  mGfxContext = aContext->ThebesContext();
 }
 
 nsSVGRenderState::nsSVGRenderState(gfxContext *aContext) :
   mRenderMode(NORMAL), mRenderingContext(nsnull), mGfxContext(aContext)
 {
 }
--- a/layout/xul/base/src/nsTextBoxFrame.cpp
+++ b/layout/xul/base/src/nsTextBoxFrame.cpp
@@ -446,18 +446,17 @@ nsTextBoxFrame::PaintTitle(nsIRenderingC
     nscoord offset;
     nscoord size;
     nscoord ascent;
     fontMet->GetMaxAscent(ascent);
     PRBool isRTL = vis->mDirection == NS_STYLE_DIRECTION_RTL;
 
     nscoord baseline =
       presContext->RoundAppUnitsToNearestDevPixels(textRect.y + ascent);
-    nsRefPtr<gfxContext> ctx = (gfxContext*)
-      aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+    nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
     gfxPoint pt(presContext->AppUnitsToGfxUnits(textRect.x),
                 presContext->AppUnitsToGfxUnits(textRect.y));
     gfxFloat width = presContext->AppUnitsToGfxUnits(textRect.width);
     gfxFloat ascentPixel = presContext->AppUnitsToGfxUnits(ascent);
     if (decorations & (NS_FONT_DECORATION_OVERLINE | NS_FONT_DECORATION_UNDERLINE)) {
       fontMet->GetUnderline(offset, size);
       gfxFloat offsetPixel = presContext->AppUnitsToGfxUnits(offset);
       gfxFloat sizePixel = presContext->AppUnitsToGfxUnits(size);
--- a/view/src/nsViewManager.cpp
+++ b/view/src/nsViewManager.cpp
@@ -469,18 +469,17 @@ void nsViewManager::Refresh(nsView *aVie
       }
     } else {
       // plain assignment grabs another reference.
       localcx = aContext;
     }
 
   PRInt32 p2a = mContext->AppUnitsPerDevPixel();
 
-  nsRefPtr<gfxContext> ctx =
-    (gfxContext*) localcx->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  nsRefPtr<gfxContext> ctx = localcx->ThebesContext();
 
   ctx->Save();
 
   nsPoint vtowoffset = aView->ViewToWidgetOffset();
   ctx->Translate(gfxPoint(gfxFloat(vtowoffset.x) / p2a,
                           gfxFloat(vtowoffset.y) / p2a));
 
   ctx->Translate(gfxPoint(-gfxFloat(viewRect.x) / p2a,
--- a/widget/src/beos/nsWindow.cpp
+++ b/widget/src/beos/nsWindow.cpp
@@ -2548,18 +2548,17 @@ nsresult nsWindow::OnPaint(BRegion *breg
 
 	nsIRenderingContext* rc = GetRenderingContext();
 	if (NS_UNLIKELY(!rc)) {
 		return NS_ERROR_FAILURE;
 	}
 
 	// Double buffering for cairo builds is done here
 #ifdef MOZ_CAIRO_GFX
-	nsRefPtr<gfxContext> ctx =
-		(gfxContext*)rc->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+	nsRefPtr<gfxContext> ctx = rc->ThebesContext();
 	ctx->Save();
 
 	// Clip
 	ctx->NewPath();
 	for (int i = 0; i< numrects; i++)
 	{
 		BRect br = breg->RectAt(i);
 		ctx->Rectangle(gfxRect(int(br.left), int(br.top), 
--- a/widget/src/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/src/cocoa/nsNativeThemeCocoa.mm
@@ -579,18 +579,17 @@ nsNativeThemeCocoa::DrawWidgetBackground
                                          PRUint8 aWidgetType, const nsRect& aRect,
                                          const nsRect& aClipRect)
 {
   // setup to draw into the correct port
   nsCOMPtr<nsIDeviceContext> dctx;
   aContext->GetDeviceContext(*getter_AddRefs(dctx));
   PRInt32 p2a = dctx->AppUnitsPerDevPixel();
 
-  nsRefPtr<gfxContext> thebesCtx = (gfxContext*)
-    aContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  nsRefPtr<gfxContext> thebesCtx = aContext->ThebesContext();
   if (!thebesCtx)
     return NS_ERROR_FAILURE;
 
   thebesCtx->UpdateSurfaceClip();
 
   double offsetX = 0.0, offsetY = 0.0;
   nsRefPtr<gfxASurface> thebesSurface = thebesCtx->CurrentSurface(&offsetX, &offsetY);
   if (thebesSurface->CairoStatus() != 0) {
--- a/widget/src/gtk2/nsNativeThemeGTK.cpp
+++ b/widget/src/gtk2/nsNativeThemeGTK.cpp
@@ -701,18 +701,17 @@ nsNativeThemeGTK::DrawWidgetBackground(n
 
   PRBool safeState = IsWidgetStateSafe(mSafeWidgetStates, aWidgetType, &state);
   XErrorHandler oldHandler = nsnull;
   if (!safeState) {
     gLastXError = 0;
     oldHandler = XSetErrorHandler(NativeThemeErrorHandler);
   }
 
-  gfxContext* ctx =
-    (gfxContext*)aContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  gfxContext* ctx = aContext->ThebesContext();
   gfxMatrix current = ctx->CurrentMatrix();
 
   // We require the use of the default display and visual
   // because I'm afraid that otherwise the GTK theme may explode.
   // Some themes (e.g. Clearlooks) just don't clip properly to any
   // clip rect we provide, so we cannot advertise support for clipping within the
   // widget bounds. The gdk_clip is just advisory here, meanining "you don't
   // need to draw outside this rect if you don't feel like it!"
--- a/widget/src/gtk2/nsWindow.cpp
+++ b/widget/src/gtk2/nsWindow.cpp
@@ -1667,18 +1667,17 @@ nsWindow::OnExposeEvent(GtkWidget *aWidg
     nsIntRect boundsRect;
     GdkPixmap* bufferPixmap = nsnull;
     nsRefPtr<gfxXlibSurface> bufferPixmapSurface;
 
     updateRegion->GetBoundingBox(&boundsRect.x, &boundsRect.y,
                                  &boundsRect.width, &boundsRect.height);
 
     // do double-buffering and clipping here
-    nsRefPtr<gfxContext> ctx
-        = (gfxContext*)rc->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+    nsRefPtr<gfxContext> ctx = rc->ThebesContext();
     ctx->Save();
     ctx->NewPath();
     if (translucent) {
         // Collapse update area to the bounding box. This is so we only have to
         // call UpdateTranslucentWindowAlpha once. After we have dropped
         // support for non-Thebes graphics, UpdateTranslucentWindowAlpha will be
         // our private interface so we can rework things to avoid this.
         ctx->Rectangle(gfxRect(boundsRect.x, boundsRect.y,
--- a/widget/src/windows/nsNativeThemeWin.cpp
+++ b/widget/src/windows/nsNativeThemeWin.cpp
@@ -1122,17 +1122,17 @@ nsNativeThemeWin::DrawWidgetBackground(n
   RECT widgetRect;
   RECT clipRect;
   gfxRect tr(aRect.x, aRect.y, aRect.width, aRect.height),
           cr(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height);
 
   tr.ScaleInverse(p2a);
   cr.ScaleInverse(p2a);
 
-  nsRefPtr<gfxContext> ctx = (gfxContext*)aContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  nsRefPtr<gfxContext> ctx = aContext->ThebesContext();
 
   gfxWindowsNativeDrawing nativeDrawing(ctx, cr, GetWidgetNativeDrawingFlags(aWidgetType));
 
 RENDER_AGAIN:
 
   HDC hdc = nativeDrawing.BeginNativeDrawing();
   if (!hdc)
     return NS_ERROR_FAILURE;
@@ -2457,17 +2457,17 @@ nsresult nsNativeThemeWin::ClassicDrawWi
   gfxFloat p2a = gfxFloat(dc->AppUnitsPerDevPixel());
   RECT widgetRect;
   gfxRect tr(aRect.x, aRect.y, aRect.width, aRect.height),
           cr(aClipRect.x, aClipRect.y, aClipRect.width, aClipRect.height);
 
   tr.ScaleInverse(p2a);
   cr.ScaleInverse(p2a);
 
-  nsRefPtr<gfxContext> ctx = (gfxContext*)aContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
+  nsRefPtr<gfxContext> ctx = aContext->ThebesContext();
 
   gfxWindowsNativeDrawing nativeDrawing(ctx, cr, GetWidgetNativeDrawingFlags(aWidgetType));
 
 RENDER_AGAIN:
 
   HDC hdc = nativeDrawing.BeginNativeDrawing();
   if (!hdc)
     return NS_ERROR_FAILURE;