Bug 266236 part 1: Preliminary API cleanup on nsIRenderingContext.
authorJan Küchler <jan@kuechler-wuppertal.de>
Thu, 07 Apr 2011 18:04:39 -0700
changeset 68364 faeb9fecfc94ed619fed6758b4dbea1b8ed1fee6
parent 68363 3afa19c50a85cd6056bfdb640277c636346dabe8
child 68365 1c1bfa98f6005c20776388a6814950aa531d5893
push id76
push userbzbarsky@mozilla.com
push dateTue, 05 Jul 2011 17:00:57 +0000
treeherdermozilla-beta@d3a2732c35f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs266236
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 266236 part 1: Preliminary API cleanup on nsIRenderingContext.
gfx/src/nsIRenderingContext.h
gfx/src/nsThebesRenderingContext.cpp
gfx/src/nsThebesRenderingContext.h
layout/base/nsBidiPresUtils.cpp
layout/base/nsCSSRendering.cpp
layout/base/nsDisplayList.h
layout/base/nsLayoutUtils.cpp
layout/base/nsPresShell.cpp
layout/forms/nsComboboxControlFrame.cpp
layout/generic/nsBRFrame.cpp
layout/generic/nsBlockFrame.cpp
layout/generic/nsFrameSetFrame.cpp
layout/generic/nsImageFrame.cpp
layout/generic/nsInlineFrame.cpp
layout/generic/nsLineLayout.cpp
layout/generic/nsObjectFrame.cpp
layout/generic/nsPageFrame.cpp
layout/generic/nsSimplePageSequence.cpp
layout/mathml/nsMathMLChar.cpp
layout/mathml/nsMathMLContainerFrame.cpp
layout/mathml/nsMathMLFrame.cpp
layout/mathml/nsMathMLmencloseFrame.cpp
layout/mathml/nsMathMLmfencedFrame.cpp
layout/mathml/nsMathMLmfracFrame.cpp
layout/mathml/nsMathMLmmultiscriptsFrame.cpp
layout/mathml/nsMathMLmoFrame.cpp
layout/mathml/nsMathMLmoverFrame.cpp
layout/mathml/nsMathMLmrootFrame.cpp
layout/mathml/nsMathMLmsubsupFrame.cpp
layout/mathml/nsMathMLmtableFrame.cpp
layout/mathml/nsMathMLmunderFrame.cpp
layout/mathml/nsMathMLmunderoverFrame.cpp
layout/svg/base/src/nsSVGIntegrationUtils.cpp
layout/svg/base/src/nsSVGOuterSVGFrame.cpp
layout/tables/nsTableCellFrame.cpp
layout/tables/nsTableFrame.cpp
layout/xul/base/src/nsTextBoxFrame.cpp
widget/src/cocoa/nsNativeThemeCocoa.mm
widget/src/gtk2/nsNativeThemeGTK.cpp
widget/src/qt/nsNativeThemeQt.h
widget/src/windows/nsNativeThemeWin.cpp
--- a/gfx/src/nsIRenderingContext.h
+++ b/gfx/src/nsIRenderingContext.h
@@ -37,16 +37,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsIRenderingContext_h___
 #define nsIRenderingContext_h___
 
 #include "nscore.h"
+#include "nsCOMPtr.h"
 #include "nsISupports.h"
 #include "nsColor.h"
 #include "nsCoord.h"
 #include "nsRect.h"
 #include "nsPoint.h"
 #include "nsSize.h"
 #include <stdio.h>
 
@@ -134,21 +135,20 @@ public:
    * @param aContext the device context to use for the drawing.
    * @param aThebesContext an existing thebes context to use for the drawing
    * @result The result of the initialization, NS_Ok if no errors
    */
   NS_IMETHOD Init(nsIDeviceContext* aContext, gfxContext* aThebesContext) = 0;
 
   /**
    * Get the DeviceContext that this RenderingContext was initialized
-   * with.  This function addrefs the device context.  Though it might
-   * be better if it just returned it directly, without addrefing.   
+   * with.
    * @result the device context
    */
-  NS_IMETHOD GetDeviceContext(nsIDeviceContext *& aDeviceContext) = 0;
+  virtual already_AddRefed<nsIDeviceContext> GetDeviceContext() = 0;
 
   /**
    * Save a graphical state onto a stack.
    */
   NS_IMETHOD PushState(void) = 0;
 
   /**
    * Get and and set RenderingContext to this graphical state
@@ -218,70 +218,76 @@ public:
    *        font to use in the RenderingContext
    */
   NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics) = 0;
 
   /**
    * Get the current fontmetrics for the RenderingContext
    * @return The current font of the RenderingContext
    */
-  NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics) = 0;
+  virtual already_AddRefed<nsIFontMetrics> GetFontMetrics() = 0;
 
   /**
-   *  Add in a translate to the RenderingContext's transformation matrix
-   * @param aX The horizontal translation
-   * @param aY The vertical translation
+   * Add in a translate to the RenderingContext's transformation matrix
+   * @param aPt The point to translate to
    */
-  NS_IMETHOD Translate(nscoord aX, nscoord aY) = 0;
-  
+  NS_IMETHOD Translate(const nsPoint& aPt) = 0;
+
   /**
    * Set the translation compoennt of the current transformation matrix.
    * Useful to set it to a known pixel value without incurring roundoff
    * errors.
    */
-  NS_IMETHOD SetTranslation(nscoord aX, nscoord aY) = 0;
+  NS_IMETHOD SetTranslation(const nsPoint& aPt) = 0;
 
   /**
    *  Add in a scale to the RenderingContext's transformation matrix
    * @param aX The horizontal scale
    * @param aY The vertical scale
    */
   NS_IMETHOD Scale(float aSx, float aSy) = 0;
 
   struct PushedTranslation {
     float mSavedX, mSavedY;
   };
 
   class AutoPushTranslation {
     nsIRenderingContext* mCtx;
     PushedTranslation mPushed;
   public:
-    AutoPushTranslation(nsIRenderingContext* aCtx, nscoord aX, nscoord aY)
+    AutoPushTranslation(nsIRenderingContext* aCtx, const nsPoint& aPt)
       : mCtx(aCtx) {
       mCtx->PushTranslation(&mPushed);
-      mCtx->Translate(aX, aY);
+      mCtx->Translate(aPt);
     }
     ~AutoPushTranslation() {
       mCtx->PopTranslation(&mPushed);
     }
   };
 
   NS_IMETHOD PushTranslation(PushedTranslation* aState) = 0;
 
   NS_IMETHOD PopTranslation(PushedTranslation* aState) = 0;
 
-  /** 
+  /**
    * Get the current transformation matrix for the RenderingContext
    * @return The transformation matrix for the RenderingContext
    */
-  NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform) = 0;
+  virtual nsTransform2D* GetCurrentTransform() = 0;
 
   /**
    * Draw a line
-   * @param aXO starting horiztonal coord in twips
+   * @param aStartPt starting point
+   * @param aEndPt ending point
+   */
+  NS_IMETHOD DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt) = 0;
+
+  /**
+   * Draw a line
+   * @param aX0 starting horizontal coord in twips
    * @param aY0 starting vertical coord in twips
    * @param aX1 end horiztonal coord in twips
    * @param aY1 end vertical coord in twips
    */
   NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1) = 0;
 
   /**
    * Draw a rectangle
--- a/gfx/src/nsThebesRenderingContext.cpp
+++ b/gfx/src/nsThebesRenderingContext.cpp
@@ -180,22 +180,21 @@ nsThebesRenderingContext::CommonInit(voi
 
     mThebes->SetLineWidth(1.0);
 
     mP2A = mDeviceContext->AppUnitsPerDevPixel();
 
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetDeviceContext(nsIDeviceContext *& aDeviceContext)
+already_AddRefed<nsIDeviceContext>
+nsThebesRenderingContext::GetDeviceContext()
 {
-    aDeviceContext = mDeviceContext;
-    NS_IF_ADDREF(aDeviceContext);
-    return NS_OK;
+    NS_IF_ADDREF(mDeviceContext);
+    return mDeviceContext.get();
 }
 
 NS_IMETHODIMP
 nsThebesRenderingContext::PushTranslation(PushedTranslation* aState)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PushTranslation\n", this));
 
     // XXX this is slow!
@@ -209,23 +208,23 @@ nsThebesRenderingContext::PopTranslation
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PopTranslation\n", this));
 
     // XXX this is slow!
     PopState();
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThebesRenderingContext::SetTranslation(nscoord aX, nscoord aY)
+nsThebesRenderingContext::SetTranslation(const nsPoint& aPt)
 {
-    PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetTranslation %d %d\n", this, aX, aY));
+    PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetTranslation %d %d\n", this, aPt.x, aPt.y));
 
     gfxMatrix newMat(mThebes->CurrentMatrix());
-    newMat.x0 = aX;
-    newMat.y0 = aY;
+    newMat.x0 = aPt.x;
+    newMat.y0 = aPt.y;
     mThebes->SetMatrix(newMat);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsThebesRenderingContext::PushState()
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::PushState\n", this));
@@ -352,20 +351,20 @@ nsThebesRenderingContext::SetColor(nscol
 NS_IMETHODIMP
 nsThebesRenderingContext::GetColor(nscolor &aColor) const
 {
     aColor = mColor;
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThebesRenderingContext::Translate(nscoord aX, nscoord aY)
+nsThebesRenderingContext::Translate(const nsPoint& aPt)
 {
-    PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Translate %d %d\n", this, aX, aY));
-    mThebes->Translate (gfxPoint(FROM_TWIPS(aX), FROM_TWIPS(aY)));
+    PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Translate %d %d\n", this, aPt.x, aPt.y));
+    mThebes->Translate (gfxPoint(FROM_TWIPS(aPt.x), FROM_TWIPS(aPt.y)));
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsThebesRenderingContext::Scale(float aSx, float aSy)
 {
     // as far as I can tell, noone actually calls this
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::Scale %f %f\n", this, aSx, aSy));
@@ -405,48 +404,57 @@ nsThebesRenderingContext::CurrentTransfo
  **** On other gfx implementations, the transform returned by this
  **** has a built in twips to pixels ratio.  That is, you pass in
  **** twips to any nsTransform2D TransformCoord method, and you
  **** get back pixels.  This makes no sense.  We don't do this.
  **** This in turn breaks SVG and <object>; those should just be
  **** fixed to not use this!
  ****/
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetCurrentTransform(nsTransform2D *&aTransform)
+nsTransform2D*
+nsThebesRenderingContext::GetCurrentTransform()
 {
-    PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::GetCurrentTransform\n", this));
+    PR_LOG(gThebesGFXLog, PR_LOG_DEBUG,
+           ("## %p nsTRC::GetCurrentTransform\n", this));
     UpdateTempTransformMatrix();
-    aTransform = &mTempTransform;
-    return NS_OK;
+    return &mTempTransform;
 }
 
 void
 nsThebesRenderingContext::TransformCoord (nscoord *aX, nscoord *aY)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::TransformCoord\n", this));
 
     gfxPoint pt(FROM_TWIPS(*aX), FROM_TWIPS(*aY));
 
     pt = mThebes->UserToDevice (pt);
 
     *aX = TO_TWIPS(pt.x);
     *aY = TO_TWIPS(pt.y);
 }
 
 NS_IMETHODIMP
-nsThebesRenderingContext::DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1)
+nsThebesRenderingContext::DrawLine(const nsPoint& aStartPt,
+                                   const nsPoint& aEndPt)
 {
-    PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::DrawLine %d %d %d %d\n", this, aX0, aY0, aX1, aY1));
+    return DrawLine(aStartPt.x, aStartPt.y, aEndPt.x, aEndPt.y);
+}
+
+NS_IMETHODIMP
+nsThebesRenderingContext::DrawLine(nscoord aX0, nscoord aY0,
+                                   nscoord aX1, nscoord aY1)
+{
+    PR_LOG(gThebesGFXLog, PR_LOG_DEBUG,
+           ("## %p nsTRC::DrawLine %d %d %d %d\n", this, aX0, aY0, aX1, aY1));
 
     gfxPoint p0 = gfxPoint(FROM_TWIPS(aX0), FROM_TWIPS(aY0));
     gfxPoint p1 = gfxPoint(FROM_TWIPS(aX1), FROM_TWIPS(aY1));
 
-    // we can't draw thick lines with gfx, so we always assume we want pixel-aligned
-    // lines if the rendering context is at 1.0 scale
+    // we can't draw thick lines with gfx, so we always assume we want
+    // pixel-aligned lines if the rendering context is at 1.0 scale
     gfxMatrix savedMatrix = mThebes->CurrentMatrix();
     if (!savedMatrix.HasNonTranslation()) {
         p0 = mThebes->UserToDevice(p0);
         p1 = mThebes->UserToDevice(p1);
 
         p0.Round();
         p1.Round();
 
@@ -821,22 +829,21 @@ NS_IMETHODIMP
 nsThebesRenderingContext::SetFont(nsIFontMetrics *aFontMetrics)
 {
     PR_LOG(gThebesGFXLog, PR_LOG_DEBUG, ("## %p nsTRC::SetFont[Metrics] %p\n", this, aFontMetrics));
 
     mFontMetrics = static_cast<nsIThebesFontMetrics*>(aFontMetrics);
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsThebesRenderingContext::GetFontMetrics(nsIFontMetrics *&aFontMetrics)
+already_AddRefed<nsIFontMetrics>
+nsThebesRenderingContext::GetFontMetrics()
 {
-    aFontMetrics = mFontMetrics;
-    NS_IF_ADDREF(aFontMetrics);
-    return NS_OK;
+    NS_IF_ADDREF(mFontMetrics);
+    return mFontMetrics.get();
 }
 
 PRInt32
 nsThebesRenderingContext::GetMaxStringLength()
 {
     if (!mFontMetrics)
         return 1;
     return mFontMetrics->GetMaxStringLength();
--- a/gfx/src/nsThebesRenderingContext.h
+++ b/gfx/src/nsThebesRenderingContext.h
@@ -127,37 +127,37 @@ public:
                           const nscoord* aSpacing = nsnull);
     NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength,
                           nscoord aX, nscoord aY,
                           PRInt32 aFontID = -1,
                           const nscoord* aSpacing = nsnull);
 
     NS_IMETHOD Init(nsIDeviceContext* aContext, gfxASurface* aThebesSurface);
     NS_IMETHOD Init(nsIDeviceContext* aContext, gfxContext* aThebesContext);
-
     NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWidget);
     NS_IMETHOD CommonInit(void);
-    NS_IMETHOD GetDeviceContext(nsIDeviceContext *& aDeviceContext);
+    virtual already_AddRefed<nsIDeviceContext> GetDeviceContext();
     NS_IMETHOD PushState(void);
     NS_IMETHOD PopState(void);
     NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
     NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
     NS_IMETHOD SetClipRegion(const nsIntRegion& aRegion, nsClipCombine aCombine);
     NS_IMETHOD SetColor(nscolor aColor);
     NS_IMETHOD GetColor(nscolor &aColor) const;
     NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLanguage,
                        gfxUserFontSet *aUserFontSet);
     NS_IMETHOD SetFont(const nsFont& aFont,
                        gfxUserFontSet *aUserFontSet);
     NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
-    NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
-    NS_IMETHOD Translate(nscoord aX, nscoord aY);
+    virtual already_AddRefed<nsIFontMetrics> GetFontMetrics();
+    NS_IMETHOD Translate(const nsPoint& aPt);
     NS_IMETHOD Scale(float aSx, float aSy);
-    NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
+    virtual nsTransform2D* GetCurrentTransform();
 
+    NS_IMETHOD DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt);
     NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
     NS_IMETHOD DrawRect(const nsRect& aRect);
     NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
     NS_IMETHOD FillRect(const nsRect& aRect);
     NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
     NS_IMETHOD InvertRect(const nsRect& aRect);
     NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
     NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
@@ -168,17 +168,17 @@ public:
 
     NS_IMETHOD PushFilter(const nsRect& aRect, PRBool aAreaIsOpaque, float aOpacity);
     NS_IMETHOD PopFilter();
 
     virtual void* GetNativeGraphicData(GraphicDataType aType);
 
     NS_IMETHOD PushTranslation(PushedTranslation* aState);
     NS_IMETHOD PopTranslation(PushedTranslation* aState);
-    NS_IMETHOD SetTranslation(nscoord aX, nscoord aY);
+    NS_IMETHOD SetTranslation(const nsPoint& aPoint);
 
     /**
      * Let the device context know whether we want text reordered with
      * right-to-left base direction
      */
     NS_IMETHOD SetRightToLeftText(PRBool aIsRTL);
     NS_IMETHOD GetRightToLeftText(PRBool* aIsRTL);
     virtual void SetTextRunRTL(PRBool aIsRTL);
--- a/layout/base/nsBidiPresUtils.cpp
+++ b/layout/base/nsBidiPresUtils.cpp
@@ -1782,18 +1782,17 @@ public:
     nscoord width;
     mTextRunConstructionContext->GetWidth(mText, mLength, width, nsnull);
     return width;
   }
 
   virtual void DrawText(nscoord aXOffset,
                         nscoord)
   {
-    nsCOMPtr<nsIFontMetrics> metrics;
-    mCtx->GetFontMetrics(*getter_AddRefs(metrics));
+    nsCOMPtr<nsIFontMetrics> metrics = mCtx->GetFontMetrics();
     nsIThebesFontMetrics* fm = static_cast<nsIThebesFontMetrics*>(metrics.get());
     fm->DrawString(mText, mLength, mPt.x + aXOffset, mPt.y,
                    mCtx, mTextRunConstructionContext);
   }
 
 private:
   nsIRenderingContext* mCtx;
   nsIRenderingContext* mTextRunConstructionContext;
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -1197,17 +1197,17 @@ nsCSSRendering::PaintBoxShadowOuter(nsPr
       // We assume that the native theme is going to paint over the shadow.
 
       // Draw the widget shape
       gfxContextMatrixAutoSaveRestore save(shadowContext);
       nsIDeviceContext* devCtx = aPresContext->DeviceContext();
       nsCOMPtr<nsIRenderingContext> wrapperCtx;
       devCtx->CreateRenderingContextInstance(*getter_AddRefs(wrapperCtx));
       wrapperCtx->Init(devCtx, shadowContext);
-      wrapperCtx->Translate(shadowItem->mXOffset, shadowItem->mYOffset);
+      wrapperCtx->Translate(nsPoint(shadowItem->mXOffset, shadowItem->mYOffset));
 
       nsRect nativeRect;
       nativeRect.IntersectRect(frameRect, aDirtyRect);
 
       aPresContext->GetTheme()->DrawWidgetBackground(wrapperCtx, aForFrame,
           styleDisplay->mAppearance, aFrameArea, nativeRect);
     } else {
       // Clip out the area of the actual frame so the shadow is not shown within
@@ -3085,23 +3085,23 @@ DrawSolidBorderSegment(nsIRenderingConte
                        nscoord              aEndBevelOffset = 0)
 {
 
   if ((aRect.width == aTwipsPerPixel) || (aRect.height == aTwipsPerPixel) ||
       ((0 == aStartBevelOffset) && (0 == aEndBevelOffset))) {
     // simple line or rectangle
     if ((NS_SIDE_TOP == aStartBevelSide) || (NS_SIDE_BOTTOM == aStartBevelSide)) {
       if (1 == aRect.height)
-        aContext.DrawLine(aRect.x, aRect.y, aRect.x, aRect.y + aRect.height);
+        aContext.DrawLine(aRect.TopLeft(), aRect.BottomLeft());
       else
         aContext.FillRect(aRect);
     }
     else {
       if (1 == aRect.width)
-        aContext.DrawLine(aRect.x, aRect.y, aRect.x + aRect.width, aRect.y);
+        aContext.DrawLine(aRect.TopLeft(), aRect.TopRight());
       else
         aContext.FillRect(aRect);
     }
   }
   else {
     // polygon with beveling
     nsPoint poly[5];
     SetPoly(aRect, poly);
--- a/layout/base/nsDisplayList.h
+++ b/layout/base/nsDisplayList.h
@@ -1323,17 +1323,17 @@ public:
 #ifdef NS_BUILD_REFCNT_LOGGING
   virtual ~nsDisplayReflowCount() {
     MOZ_COUNT_DTOR(nsDisplayReflowCount);
   }
 #endif
   
   virtual void Paint(nsDisplayListBuilder* aBuilder, nsIRenderingContext* aCtx) {
     nsPoint pt = ToReferenceFrame();
-    nsIRenderingContext::AutoPushTranslation translate(aCtx, pt.x, pt.y);
+    nsIRenderingContext::AutoPushTranslation translate(aCtx, pt);
     mFrame->PresContext()->PresShell()->PaintCount(mFrameName, aCtx,
                                                       mFrame->PresContext(),
                                                       mFrame, mColor);
   }
   NS_DISPLAY_DECL_NAME("nsDisplayReflowCount", TYPE_REFLOW_COUNT)
 protected:
   const char* mFrameName;
   nscolor mColor;
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -1491,17 +1491,17 @@ nsLayoutUtils::PaintFrame(nsIRenderingCo
       nsIScrollableFrame* rootScrollableFrame =
         presShell->GetRootScrollFrameAsScrollable();
       if (aFlags & PAINT_DOCUMENT_RELATIVE) {
         // Make visibleRegion and aRenderingContext relative to the
         // scrolled frame instead of the root frame.
         nsPoint pos = rootScrollableFrame->GetScrollPosition();
         visibleRegion.MoveBy(-pos);
         if (aRenderingContext) {
-          aRenderingContext->Translate(pos.x, pos.y);
+          aRenderingContext->Translate(pos);
         }
       }
       builder.SetIgnoreScrollFrame(rootScrollFrame);
 
       nsCanvasFrame* canvasFrame =
         do_QueryFrame(rootScrollableFrame->GetScrolledFrame());
       if (canvasFrame) {
         // Use UnionRect here to ensure that areas where the scrollbars
@@ -3262,18 +3262,17 @@ DrawImageInternal(nsIRenderingContext* a
                   GraphicsFilter       aGraphicsFilter,
                   const nsRect&        aDest,
                   const nsRect&        aFill,
                   const nsPoint&       aAnchor,
                   const nsRect&        aDirty,
                   const nsIntSize&     aImageSize,
                   PRUint32             aImageFlags)
 {
-  nsCOMPtr<nsIDeviceContext> dc;
-  aRenderingContext->GetDeviceContext(*getter_AddRefs(dc));
+  nsCOMPtr<nsIDeviceContext> dc = aRenderingContext->GetDeviceContext();
   PRInt32 appUnitsPerDevPixel = dc->AppUnitsPerDevPixel();
   gfxContext* ctx = aRenderingContext->ThebesContext();
 
   SnappedImageDrawingParameters drawingParams =
     ComputeSnappedImageDrawingParameters(ctx, appUnitsPerDevPixel, aDest, aFill,
                                          aAnchor, aDirty, aImageSize);
 
   if (!drawingParams.mShouldDraw)
@@ -3294,18 +3293,17 @@ DrawImageInternal(nsIRenderingContext* a
 nsLayoutUtils::DrawPixelSnapped(nsIRenderingContext* aRenderingContext,
                                 gfxDrawable*         aDrawable,
                                 GraphicsFilter       aFilter,
                                 const nsRect&        aDest,
                                 const nsRect&        aFill,
                                 const nsPoint&       aAnchor,
                                 const nsRect&        aDirty)
 {
-  nsCOMPtr<nsIDeviceContext> dc;
-  aRenderingContext->GetDeviceContext(*getter_AddRefs(dc));
+  nsCOMPtr<nsIDeviceContext> dc = aRenderingContext->GetDeviceContext();
   PRInt32 appUnitsPerDevPixel = dc->AppUnitsPerDevPixel();
   gfxContext* ctx = aRenderingContext->ThebesContext();
   gfxIntSize drawableSize = aDrawable->Size();
   nsIntSize imageSize(drawableSize.width, drawableSize.height);
 
   SnappedImageDrawingParameters drawingParams =
     ComputeSnappedImageDrawingParameters(ctx, appUnitsPerDevPixel, aDest, aFill,
                                          aAnchor, aDirty, imageSize);
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -5617,17 +5617,17 @@ PresShell::PaintRangePaintInfo(nsTArray<
         .ToOutsidePixels(pc->AppUnitsPerDevPixel());
     rc->SetClipRegion(region, nsClipCombine_kReplace);
   }
 
   if (resize)
     rc->Scale(scale, scale);
 
   // translate so that points are relative to the surface area
-  rc->Translate(-aArea.x, -aArea.y);
+  rc->Translate(-aArea.TopLeft());
 
   // temporarily hide the selection so that text is drawn normally. If a
   // selection is being rendered, use that, otherwise use the presshell's
   // selection.
   nsCOMPtr<nsFrameSelection> frameSelection;
   if (aSelection) {
     nsCOMPtr<nsISelectionPrivate> selpriv = do_QueryInterface(aSelection);
     selpriv->GetFrameSelection(getter_AddRefs(frameSelection));
@@ -5640,17 +5640,17 @@ PresShell::PaintRangePaintInfo(nsTArray<
 
   // next, paint each range in the selection
   PRInt32 count = aItems->Length();
   for (PRInt32 i = 0; i < count; i++) {
     RangePaintInfo* rangeInfo = (*aItems)[i];
     // the display lists paint relative to the offset from the reference
     // frame, so translate the rendering context
     nsIRenderingContext::AutoPushTranslation
-      translate(rc, rangeInfo->mRootOffset.x, rangeInfo->mRootOffset.y);
+      translate(rc, rangeInfo->mRootOffset);
 
     aArea.MoveBy(-rangeInfo->mRootOffset.x, -rangeInfo->mRootOffset.y);
     nsRegion visible(aArea);
     rangeInfo->mList.ComputeVisibilityForRoot(&rangeInfo->mBuilder, &visible);
     rangeInfo->mList.PaintRoot(&rangeInfo->mBuilder, rc, nsDisplayList::PAINT_DEFAULT);
     aArea.MoveBy(rangeInfo->mRootOffset.x, rangeInfo->mRootOffset.y);
   }
 
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -1423,26 +1423,20 @@ void nsComboboxControlFrame::PaintFocus(
   aRenderingContext.SetLineStyle(nsLineStyle_kDotted);
   aRenderingContext.SetColor(GetStyleColor()->mColor);
 
   //aRenderingContext.DrawRect(clipRect);
 
   nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
   clipRect.width -= onePixel;
   clipRect.height -= onePixel;
-  aRenderingContext.DrawLine(clipRect.x, clipRect.y, 
-                             clipRect.x+clipRect.width, clipRect.y);
-  aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y, 
-                             clipRect.x+clipRect.width, clipRect.y+clipRect.height);
-  aRenderingContext.DrawLine(clipRect.x+clipRect.width, clipRect.y+clipRect.height, 
-                             clipRect.x, clipRect.y+clipRect.height);
-  aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, 
-                             clipRect.x, clipRect.y);
-  aRenderingContext.DrawLine(clipRect.x, clipRect.y+clipRect.height, 
-                             clipRect.x, clipRect.y);
+  aRenderingContext.DrawLine(clipRect.TopLeft(), clipRect.TopRight());
+  aRenderingContext.DrawLine(clipRect.TopRight(), clipRect.BottomRight());
+  aRenderingContext.DrawLine(clipRect.BottomRight(), clipRect.BottomLeft());
+  aRenderingContext.DrawLine(clipRect.BottomLeft(), clipRect.TopLeft());
 
   aRenderingContext.PopState();
 }
 
 //---------------------------------------------------------
 // gets the content (an option) by index and then set it as
 // being selected or not selected
 //---------------------------------------------------------
--- a/layout/generic/nsBRFrame.cpp
+++ b/layout/generic/nsBRFrame.cpp
@@ -147,18 +147,17 @@ BRFrame::Reflow(nsPresContext* aPresCont
       // quirks-mode fix that doesn't apply the block's min
       // line-height makes this necessary to make BR cause a line
       // of the full line-height
 
       // We also do this in strict mode because BR should act like a
       // normal inline frame.  That line-height is used is important
       // here for cases where the line-height is less than 1.
       nsLayoutUtils::SetFontFromStyle(aReflowState.rendContext, mStyleContext);
-      nsCOMPtr<nsIFontMetrics> fm;
-      aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
+      nsCOMPtr<nsIFontMetrics> fm = aReflowState.rendContext->GetFontMetrics();
       if (fm) {
         nscoord logicalHeight = aReflowState.CalcLineHeight();
         aMetrics.height = logicalHeight;
         aMetrics.ascent =
           nsLayoutUtils::GetCenteredFontBaseline(fm, logicalHeight);
         AddStateBits(BR_USING_CENTERED_FONT_BASELINE);
       }
       else {
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -2365,18 +2365,17 @@ nsBlockFrame::ReflowDirtyLines(nsBlockRe
 
       if (metrics.ascent == nsHTMLReflowMetrics::ASK_FOR_BASELINE &&
           !nsLayoutUtils::GetFirstLineBaseline(mBullet, &metrics.ascent)) {
         metrics.ascent = metrics.height;
       }
 
       nsIRenderingContext *rc = aState.mReflowState.rendContext;
       nsLayoutUtils::SetFontFromStyle(rc, GetStyleContext());
-      nsCOMPtr<nsIFontMetrics> fm;
-      rc->GetFontMetrics(*getter_AddRefs(fm));
+      nsCOMPtr<nsIFontMetrics> fm = rc->GetFontMetrics();
 
       nscoord minAscent =
         nsLayoutUtils::GetCenteredFontBaseline(fm, aState.mMinLineHeight);
       nscoord minDescent = aState.mMinLineHeight - minAscent;
 
       aState.mY += NS_MAX(minAscent, metrics.ascent) +
                    NS_MAX(minDescent, metrics.height - metrics.ascent);
 
--- a/layout/generic/nsFrameSetFrame.cpp
+++ b/layout/generic/nsFrameSetFrame.cpp
@@ -1685,17 +1685,17 @@ void nsHTMLFramesetBorderFrame::PaintBor
 {
   nscolor WHITE    = NS_RGB(255, 255, 255);
   nscolor bgColor  = NS_RGB(200,200,200);
   nscolor fgColor  = NS_RGB(0,0,0);
   nscolor hltColor = NS_RGB(255,255,255);
   nscolor sdwColor = NS_RGB(128,128,128);
 
   nsIRenderingContext::AutoPushTranslation
-    translate(&aRenderingContext, aPt.x, aPt.y);
+    translate(&aRenderingContext, aPt);
 
   {
     nsCOMPtr<nsILookAndFeel> lookAndFeel = do_GetService(kLookAndFeelCID);
     if (lookAndFeel) {
       lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground,  bgColor);
       lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground,  fgColor);
       lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow,    sdwColor);
       lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor);
@@ -1703,66 +1703,64 @@ void nsHTMLFramesetBorderFrame::PaintBor
   }
 
   nscoord widthInPixels = nsPresContext::AppUnitsToIntCSSPixels(mWidth);
   nscoord pixelWidth    = nsPresContext::CSSPixelsToAppUnits(1);
 
   if (widthInPixels <= 0)
     return;
 
-  nscoord x0 = 0;
-  nscoord y0 = 0;
-  nscoord x1 = (mVertical) ? 0 : mRect.width;
-  nscoord y1 = (mVertical) ? mRect.height : 0;
+  nsPoint start(0,0);
+  nsPoint end((mVertical) ? 0 : mRect.width, (mVertical) ? mRect.height : 0);
 
   nscolor color = WHITE;
   if (mVisibility || mVisibilityOverride) {
     color = (NO_COLOR == mColor) ? bgColor : mColor;
   }
   aRenderingContext.SetColor(color);
   // draw grey or white first
   for (int i = 0; i < widthInPixels; i++) {
-    aRenderingContext.DrawLine (x0, y0, x1, y1);
+    aRenderingContext.DrawLine (start, end);
     if (mVertical) {
-      x0 += pixelWidth;
-      x1 =  x0;
+      start.x += pixelWidth;
+      end.x =  start.x;
     } else {
-      y0 += pixelWidth;
-      y1 =  y0;
+      start.y += pixelWidth;
+      end.y =  start.y;
     }
   }
 
   if (!mVisibility && !mVisibilityOverride)
     return;
 
   if (widthInPixels >= 5) {
     aRenderingContext.SetColor(hltColor);
-    x0 = (mVertical) ? pixelWidth : 0;
-    y0 = (mVertical) ? 0 : pixelWidth;
-    x1 = (mVertical) ? x0 : mRect.width;
-    y1 = (mVertical) ? mRect.height : y0;
-    aRenderingContext.DrawLine(x0, y0, x1, y1);
+    start.x = (mVertical) ? pixelWidth : 0;
+    start.y = (mVertical) ? 0 : pixelWidth;
+    end.x   = (mVertical) ? start.x : mRect.width;
+    end.y   = (mVertical) ? mRect.height : start.y;
+    aRenderingContext.DrawLine(start, end);
   }
 
   if (widthInPixels >= 2) {
     aRenderingContext.SetColor(sdwColor);
-    x0 = (mVertical) ? mRect.width - (2 * pixelWidth) : 0;
-    y0 = (mVertical) ? 0 : mRect.height - (2 * pixelWidth);
-    x1 = (mVertical) ? x0 : mRect.width;
-    y1 = (mVertical) ? mRect.height : y0;
-    aRenderingContext.DrawLine(x0, y0, x1, y1);
+    start.x = (mVertical) ? mRect.width - (2 * pixelWidth) : 0;
+    start.y = (mVertical) ? 0 : mRect.height - (2 * pixelWidth);
+    end.x   = (mVertical) ? start.x : mRect.width;
+    end.y   = (mVertical) ? mRect.height : start.y;
+    aRenderingContext.DrawLine(start, end);
   }
 
   if (widthInPixels >= 1) {
     aRenderingContext.SetColor(fgColor);
-    x0 = (mVertical) ? mRect.width - pixelWidth : 0;
-    y0 = (mVertical) ? 0 : mRect.height - pixelWidth;
-    x1 = (mVertical) ? x0 : mRect.width;
-    y1 = (mVertical) ? mRect.height : y0;
-    aRenderingContext.DrawLine(x0, y0, x1, y1);
+    start.x = (mVertical) ? mRect.width - pixelWidth : 0;
+    start.y = (mVertical) ? 0 : mRect.height - pixelWidth;
+    end.x   = (mVertical) ? start.x : mRect.width;
+    end.y   = (mVertical) ? mRect.height : start.y;
+    aRenderingContext.DrawLine(start, end);
   }
 }
 
 
 NS_IMETHODIMP
 nsHTMLFramesetBorderFrame::HandleEvent(nsPresContext* aPresContext, 
                                        nsGUIEvent*     aEvent,
                                        nsEventStatus*  aEventStatus)
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -971,18 +971,17 @@ nsImageFrame::DisplayAltText(nsPresConte
                              const nsString&      aAltText,
                              const nsRect&        aRect)
 {
   // Set font and color
   aRenderingContext.SetColor(GetStyleColor()->mColor);
   nsLayoutUtils::SetFontFromStyle(&aRenderingContext, mStyleContext);
 
   // Format the text to display within the formatting rect
-  nsIFontMetrics* fm;
-  aRenderingContext.GetFontMetrics(fm);
+  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
 
   nscoord maxAscent, maxDescent, height;
   fm->GetMaxAscent(maxAscent);
   fm->GetMaxDescent(maxDescent);
   fm->GetHeight(height);
 
   // XXX It would be nice if there was a way to have the font metrics tell
   // use where to break the text given a maximum width. At a minimum we need
@@ -1023,18 +1022,16 @@ nsImageFrame::DisplayAltText(nsPresConte
       aRenderingContext.DrawString(str, maxFit, aRect.x, y + maxAscent);
 
     // Move to the next line
     str += maxFit;
     strLen -= maxFit;
     y += height;
     firstLine = PR_FALSE;
   }
-
-  NS_RELEASE(fm);
 }
 
 struct nsRecessedBorder : public nsStyleBorder {
   nsRecessedBorder(nscoord aBorderWidth, nsPresContext* aPresContext)
     : nsStyleBorder(aPresContext)
   {
     NS_FOR_CSS_SIDES(side) {
       // Note: use SetBorderColor here because we want to make sure
@@ -1179,17 +1176,17 @@ static void PaintAltFeedback(nsIFrame* a
 static void PaintDebugImageMap(nsIFrame* aFrame, nsIRenderingContext* aCtx,
      const nsRect& aDirtyRect, nsPoint aPt) {
   nsImageFrame* f = static_cast<nsImageFrame*>(aFrame);
   nsRect inner = f->GetInnerArea() + aPt;
   nsPresContext* pc = f->PresContext();
 
   aCtx->SetColor(NS_RGB(0, 0, 0));
   aCtx->PushState();
-  aCtx->Translate(inner.x, inner.y);
+  aCtx->Translate(inner.TopLeft());
   f->GetImageMap(pc)->Draw(aFrame, *aCtx);
   aCtx->PopState();
 }
 #endif
 
 void
 nsDisplayImage::Paint(nsDisplayListBuilder* aBuilder,
                       nsIRenderingContext* aCtx) {
@@ -1290,17 +1287,17 @@ nsImageFrame::PaintImage(nsIRenderingCon
     aFlags);
 
   nsPresContext* presContext = PresContext();
   nsImageMap* map = GetImageMap(presContext);
   if (nsnull != map) {
     aRenderingContext.PushState();
     aRenderingContext.SetColor(NS_RGB(0, 0, 0));
     aRenderingContext.SetLineStyle(nsLineStyle_kDotted);
-    aRenderingContext.Translate(inner.x, inner.y);
+    aRenderingContext.Translate(inner.TopLeft());
     map->Draw(this, aRenderingContext);
     aRenderingContext.PopState();
   }
 }
 
 NS_IMETHODIMP
 nsImageFrame::BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                                const nsRect&           aDirtyRect,
--- a/layout/generic/nsInlineFrame.cpp
+++ b/layout/generic/nsInlineFrame.cpp
@@ -639,18 +639,17 @@ nsInlineFrame::ReflowFrames(nsPresContex
   if (NS_FRAME_IS_COMPLETE(aStatus) &&
       !GetLastInFlow()->GetNextContinuation() &&
       !nsLayoutUtils::FrameIsNonLastInIBSplit(this)) {
     aMetrics.width += ltr ? aReflowState.mComputedBorderPadding.right
                           : aReflowState.mComputedBorderPadding.left;
   }
 
   nsLayoutUtils::SetFontFromStyle(aReflowState.rendContext, mStyleContext);
-  nsCOMPtr<nsIFontMetrics> fm;
-  aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aReflowState.rendContext->GetFontMetrics();
 
   if (fm) {
     // Compute final height of the frame.
     //
     // Do things the standard css2 way -- though it's hard to find it
     // in the css2 spec! It's actually found in the css1 spec section
     // 4.4 (you will have to read between the lines to really see
     // it).
--- a/layout/generic/nsLineLayout.cpp
+++ b/layout/generic/nsLineLayout.cpp
@@ -1558,18 +1558,17 @@ nsLineLayout::VerticalAlignFrames(PerSpa
   // Get parent frame info
   PerFrameData* spanFramePFD = psd->mFrame;
   nsIFrame* spanFrame = spanFramePFD->mFrame;
 
   // Get the parent frame's font for all of the frames in this span
   nsStyleContext* styleContext = spanFrame->GetStyleContext();
   nsIRenderingContext* rc = mBlockReflowState->rendContext;
   nsLayoutUtils::SetFontFromStyle(mBlockReflowState->rendContext, styleContext);
-  nsCOMPtr<nsIFontMetrics> fm;
-  rc->GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = rc->GetFontMetrics();
 
   PRBool preMode = mStyleText->WhiteSpaceIsSignificant();
 
   // See if the span is an empty continuation. It's an empty continuation iff:
   // - it has a prev-in-flow
   // - it has no next in flow
   // - it's zero sized
   PRBool emptyContinuation = psd != mRootSpan &&
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -1318,17 +1318,17 @@ nsObjectFrame::DidReflow(nsPresContext* 
   return rv;
 }
 
 /* static */ void
 nsObjectFrame::PaintPrintPlugin(nsIFrame* aFrame, nsIRenderingContext* aCtx,
                                 const nsRect& aDirtyRect, nsPoint aPt)
 {
   nsPoint pt = aPt + aFrame->GetUsedBorderAndPadding().TopLeft();
-  nsIRenderingContext::AutoPushTranslation translate(aCtx, pt.x, pt.y);
+  nsIRenderingContext::AutoPushTranslation translate(aCtx, pt);
   // FIXME - Bug 385435: Doesn't aDirtyRect need translating too?
   static_cast<nsObjectFrame*>(aFrame)->PrintPlugin(*aCtx, aDirtyRect);
 }
 
 class nsDisplayPluginReadback : public nsDisplayItem {
 public:
   nsDisplayPluginReadback(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
     : nsDisplayItem(aBuilder, aFrame)
@@ -2279,17 +2279,17 @@ nsObjectFrame::PaintPlugin(nsDisplayList
         mInstanceOwner->Paint(nativeClipRect - offset, cgContext);
       }
       mInstanceOwner->EndCGPaint();
 
       nativeDrawing.EndNativeDrawing();
     } else {
       // FIXME - Bug 385435: Doesn't aDirtyRect need translating too?
       nsIRenderingContext::AutoPushTranslation
-        translate(&aRenderingContext, aPluginRect.x, aPluginRect.y);
+        translate(&aRenderingContext, aPluginRect.TopLeft());
 
       // this rect is used only in the CoreGraphics drawing model
       gfxRect tmpRect(0, 0, 0, 0);
       mInstanceOwner->Paint(tmpRect, NULL);
     }
   }
 #elif defined(MOZ_X11)
   if (mInstanceOwner) {
@@ -2419,17 +2419,17 @@ nsObjectFrame::PaintPlugin(nsDisplayList
   if (inst) {
     // Look if it's windowless
     NPWindow *window;
     mInstanceOwner->GetWindow(window);
 
     if (window->type == NPWindowTypeDrawable) {
       // FIXME - Bug 385435: Doesn't aDirtyRect need translating too?
       nsIRenderingContext::AutoPushTranslation
-        translate(&aRenderingContext, aPluginRect.x, aPluginRect.y);
+        translate(&aRenderingContext, aPluginRect.TopLeft());
 
       // check if we need to call SetWindow with updated parameters
       PRBool doupdatewindow = PR_FALSE;
       // the offset of the DC
       nsIntPoint origin;
 
       /*
        * Layout now has an optimized way of painting. Now we always get
--- a/layout/generic/nsPageFrame.cpp
+++ b/layout/generic/nsPageFrame.cpp
@@ -548,17 +548,17 @@ void
 nsPageFrame::PaintPageContent(nsIRenderingContext& aRenderingContext,
                               const nsRect&        aDirtyRect,
                               nsPoint              aPt) {
   nsIFrame* pageContentFrame  = mFrames.FirstChild();
   nsRect rect = aDirtyRect;
   float scale = PresContext()->GetPageScale();
   aRenderingContext.PushState();
   nsPoint framePos = aPt + pageContentFrame->GetOffsetTo(this);
-  aRenderingContext.Translate(framePos.x, framePos.y);
+  aRenderingContext.Translate(framePos);
   // aPt translates to coords relative to this, then margins translate to
   // pageContentFrame's coords
   rect -= framePos;
   aRenderingContext.Scale(scale, scale);
   rect.ScaleRoundOut(1.0f / scale);
   // Make sure we don't draw where we aren't supposed to draw, especially
   // when printing selection
   nsRect clipRect(nsPoint(0, 0), pageContentFrame->GetSize());
--- a/layout/generic/nsSimplePageSequence.cpp
+++ b/layout/generic/nsSimplePageSequence.cpp
@@ -675,29 +675,29 @@ static void PaintPageSequence(nsIFrame* 
 void
 nsSimplePageSequenceFrame::PaintPageSequence(nsIRenderingContext& aRenderingContext,
                                              const nsRect&        aDirtyRect,
                                              nsPoint              aPt) {
   nsRect rect = aDirtyRect;
   float scale = PresContext()->GetPrintPreviewScale();
   aRenderingContext.PushState();
   nsPoint framePos = aPt;
-  aRenderingContext.Translate(framePos.x, framePos.y);
+  aRenderingContext.Translate(framePos);
   rect -= framePos;
   aRenderingContext.Scale(scale, scale);
   rect.ScaleRoundOut(1.0f / scale);
 
   // Now the rect and the rendering coordinates are are relative to this frame.
   // Loop over the pages and paint them.
   nsIFrame* child = GetFirstChild(nsnull);
   while (child) {
     nsPoint pt = child->GetPosition();
     // The rendering context has to be translated before each call to PaintFrame
     aRenderingContext.PushState();
-    aRenderingContext.Translate(pt.x, pt.y);
+    aRenderingContext.Translate(pt);
     nsLayoutUtils::PaintFrame(&aRenderingContext, child,
                               nsRegion(rect - pt), NS_RGBA(0,0,0,0),
                               nsLayoutUtils::PAINT_SYNC_DECODE_IMAGES);
     aRenderingContext.PopState();
     child = child->GetNextSibling();
   }
 
   aRenderingContext.PopState();
--- a/layout/mathml/nsMathMLChar.cpp
+++ b/layout/mathml/nsMathMLChar.cpp
@@ -2127,17 +2127,17 @@ nsMathMLChar::Display(nsDisplayListBuild
         nsDisplayMathMLCharForeground(aBuilder, aForFrame, this,
                                       aSelectedRect && !aSelectedRect->IsEmpty()));
 }
 
 void
 nsMathMLChar::ApplyTransforms(nsIRenderingContext& aRenderingContext, nsRect &r)
 {
   // apply the transforms
-  aRenderingContext.Translate(r.x, r.y);
+  aRenderingContext.Translate(r.TopLeft());
   aRenderingContext.Scale(mScaleX, mScaleY);
 
   // update the bounding rectangle.
   r.x = r.y = 0;
   r.width /= mScaleX;
   r.height /= mScaleY;
 }
 
--- a/layout/mathml/nsMathMLContainerFrame.cpp
+++ b/layout/mathml/nsMathMLContainerFrame.cpp
@@ -104,18 +104,17 @@ nsMathMLContainerFrame::ReflowError(nsIR
   if (NS_FAILED(rv)) {
     NS_WARNING("GetBoundingMetrics failed");
     aDesiredSize.width = aDesiredSize.height = 0;
     aDesiredSize.ascent = 0;
     return NS_OK;
   }
 
   // reflow metrics
-  nsCOMPtr<nsIFontMetrics> fm;
-  aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
   fm->GetMaxAscent(aDesiredSize.ascent);
   nscoord descent;
   fm->GetMaxDescent(descent);
   aDesiredSize.height = aDesiredSize.ascent + descent;
   aDesiredSize.width = mBoundingMetrics.width;
 
   // Also return our bounding metrics
   aDesiredSize.mBoundingMetrics = mBoundingMetrics;
@@ -147,18 +146,17 @@ void nsDisplayMathMLError::Paint(nsDispl
   nsLayoutUtils::SetFontFromStyle(aCtx, mFrame->GetStyleContext());
 
   nsPoint pt = ToReferenceFrame();
   aCtx->SetColor(NS_RGB(255,0,0));
   aCtx->FillRect(nsRect(pt, mFrame->GetSize()));
   aCtx->SetColor(NS_RGB(255,255,255));
 
   nscoord ascent;
-  nsCOMPtr<nsIFontMetrics> fm;
-  aCtx->GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aCtx->GetFontMetrics();
   fm->GetMaxAscent(ascent);
 
   nsAutoString errorMsg; errorMsg.AssignLiteral("invalid-markup");
   aCtx->DrawString(errorMsg.get(), PRUint32(errorMsg.Length()), pt.x, pt.y+ascent);
 }
 
 /* /////////////
  * nsIMathMLFrame - support methods for stretchy elements
--- a/layout/mathml/nsMathMLFrame.cpp
+++ b/layout/mathml/nsMathMLFrame.cpp
@@ -277,18 +277,17 @@ nsMathMLFrame::GetAttribute(nsIContent* 
 /* static */ void
 nsMathMLFrame::GetRuleThickness(nsIRenderingContext& aRenderingContext,
                                 nsIFontMetrics*      aFontMetrics,
                                 nscoord&             aRuleThickness)
 {
   // get the bounding metrics of the overbar char, the rendering context
   // is assumed to have been set with the font of the current style context
 #ifdef NS_DEBUG
-  nsCOMPtr<nsIFontMetrics> currFontMetrics;
-  aRenderingContext.GetFontMetrics(*getter_AddRefs(currFontMetrics));
+  nsCOMPtr<nsIFontMetrics> currFontMetrics = aRenderingContext.GetFontMetrics();
   NS_ASSERTION(currFontMetrics->Font().Equals(aFontMetrics->Font()),
       "unexpected state");
 #endif
   nscoord xHeight;
   aFontMetrics->GetXHeight(xHeight);
   PRUnichar overBar = 0x00AF;
   nsBoundingMetrics bm;
   nsresult rv = aRenderingContext.GetBoundingMetrics(&overBar, PRUint32(1), bm);
@@ -316,18 +315,17 @@ nsMathMLFrame::GetRuleThickness(nsIRende
 /* static */ void
 nsMathMLFrame::GetAxisHeight(nsIRenderingContext& aRenderingContext,
                              nsIFontMetrics*      aFontMetrics,
                              nscoord&             aAxisHeight)
 {
   // get the bounding metrics of the minus sign, the rendering context
   // is assumed to have been set with the font of the current style context
 #ifdef NS_DEBUG
-  nsCOMPtr<nsIFontMetrics> currFontMetrics;
-  aRenderingContext.GetFontMetrics(*getter_AddRefs(currFontMetrics));
+  nsCOMPtr<nsIFontMetrics> currFontMetrics = aRenderingContext.GetFontMetrics();
   NS_ASSERTION(currFontMetrics->Font().Equals(aFontMetrics->Font()),
 	"unexpected state");
 #endif
   nscoord xHeight;
   aFontMetrics->GetXHeight(xHeight);
   PRUnichar minus = 0x2212; // not '-', but official Unicode minus sign
   nsBoundingMetrics bm;
   nsresult rv = aRenderingContext.GetBoundingMetrics(&minus, PRUint32(1), bm);
--- a/layout/mathml/nsMathMLmencloseFrame.cpp
+++ b/layout/mathml/nsMathMLmencloseFrame.cpp
@@ -369,21 +369,21 @@ nsMathMLmencloseFrame::PlaceInternal(nsI
   nsBoundingMetrics bmLongdivChar, bmRadicalChar;
   nscoord radicalAscent = 0, radicalDescent = 0;
   nscoord longdivAscent = 0, longdivDescent = 0;
   nscoord psi = 0;
 
   ///////////////
   // Thickness of bars and font metrics
   nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
-  nsCOMPtr<nsIFontMetrics> fm;
+
   nscoord mEmHeight;
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             PresContext()->GetUserFontSet());
-  aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
   GetRuleThickness(aRenderingContext, fm, mRuleThickness);
   GetEmHeight(fm, mEmHeight);
 
   nsBoundingMetrics bmOne;
   aRenderingContext.GetBoundingMetrics(NS_LITERAL_STRING("1").get(), 1, bmOne);
 
   ///////////////
   // General rules: the menclose element takes the size of the enclosed content.
--- a/layout/mathml/nsMathMLmfencedFrame.cpp
+++ b/layout/mathml/nsMathMLmfencedFrame.cpp
@@ -237,21 +237,20 @@ nsMathMLmfencedFrame::Reflow(nsPresConte
                              nsReflowStatus&          aStatus)
 {
   nsresult rv;
   aDesiredSize.width = aDesiredSize.height = 0;
   aDesiredSize.ascent = 0;
   aDesiredSize.mBoundingMetrics.Clear();
 
   PRInt32 i;
-  nsCOMPtr<nsIFontMetrics> fm;
   const nsStyleFont* font = GetStyleFont();
   aReflowState.rendContext->SetFont(font->mFont,
                                     aPresContext->GetUserFontSet());
-  aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aReflowState.rendContext->GetFontMetrics();
   nscoord axisHeight, em;
   GetAxisHeight(*aReflowState.rendContext, fm, axisHeight);
   GetEmHeight(fm, em);
   // leading to be left at the top and the bottom of stretched chars
   nscoord leading = NSToCoordRound(0.2f * em); 
 
   /////////////
   // Reflow children
--- a/layout/mathml/nsMathMLmfracFrame.cpp
+++ b/layout/mathml/nsMathMLmfracFrame.cpp
@@ -265,18 +265,17 @@ nsMathMLmfracFrame::PlaceInternal(nsIRen
   GetReflowAndBoundingMetricsFor(frameNum, sizeNum, bmNum);
   GetReflowAndBoundingMetricsFor(frameDen, sizeDen, bmDen);
 
   nsPresContext* presContext = PresContext();
   nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
 
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             presContext->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm;
-  aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
 
   nscoord defaultRuleThickness, axisHeight;
   GetRuleThickness(aRenderingContext, fm, defaultRuleThickness);
   GetAxisHeight(aRenderingContext, fm, axisHeight);
 
   nsEmbellishData coreData;
   GetEmbellishDataFrom(mEmbellishData.coreFrame, coreData);
 
--- a/layout/mathml/nsMathMLmmultiscriptsFrame.cpp
+++ b/layout/mathml/nsMathMLmmultiscriptsFrame.cpp
@@ -158,18 +158,17 @@ nsMathMLmmultiscriptsFrame::Place(nsIRen
   ////////////////////////////////////////
 
   ProcessAttributes();
 
   // get x-height (an ex)
   const nsStyleFont* font = GetStyleFont();
   aRenderingContext.SetFont(font->mFont,
                             PresContext()->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm;
-  aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
 
   nscoord xHeight;
   fm->GetXHeight (xHeight);
 
   nscoord ruleSize;
   GetRuleThickness (aRenderingContext, fm, ruleSize);
 
   // scriptspace from TeX for extra spacing after sup/subscript (0.5pt in plain TeX)
--- a/layout/mathml/nsMathMLmoFrame.cpp
+++ b/layout/mathml/nsMathMLmoFrame.cpp
@@ -633,20 +633,19 @@ nsMathMLmoFrame::Stretch(nsIRenderingCon
     NS_WARNING("it is wrong to fire stretch more than once on a frame");
     return NS_OK;
   }
   mPresentationData.flags |= NS_MATHML_STRETCH_DONE;
 
   nsIFrame* firstChild = mFrames.FirstChild();
 
   // get the axis height;
-  nsCOMPtr<nsIFontMetrics> fm;
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             PresContext()->GetUserFontSet());
-  aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
   nscoord axisHeight, height;
   GetAxisHeight(aRenderingContext, fm, axisHeight);
 
   // get the leading to be left at the top and the bottom of the stretched char
   // this seems more reliable than using fm->GetLeading() on suspicious fonts               
   nscoord em;
   GetEmHeight(fm, em);
   nscoord leading = NSToCoordRound(0.2f * em);
--- a/layout/mathml/nsMathMLmoverFrame.cpp
+++ b/layout/mathml/nsMathMLmoverFrame.cpp
@@ -279,18 +279,17 @@ nsMathMLmoverFrame::Place(nsIRenderingCo
 
   nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
 
   ////////////////////
   // Place Children
 
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             PresContext()->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm;
-  aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
 
   nscoord xHeight = 0;
   fm->GetXHeight (xHeight);
 
   nscoord ruleThickness;
   GetRuleThickness (aRenderingContext, fm, ruleThickness);
 
   // there are 2 different types of placement depending on 
--- a/layout/mathml/nsMathMLmrootFrame.cpp
+++ b/layout/mathml/nsMathMLmrootFrame.cpp
@@ -256,18 +256,17 @@ nsMathMLmrootFrame::Reflow(nsPresContext
     return rv;
   }
 
   ////////////
   // Prepare the radical symbol and the overline bar
 
   renderingContext.SetFont(GetStyleFont()->mFont,
                            aPresContext->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm;
-  renderingContext.GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = renderingContext.GetFontMetrics();
 
   // For radical glyphs from TeX fonts and some of the radical glyphs from
   // Mathematica fonts, the thickness of the overline can be obtained from the
   // ascent of the glyph.  Most fonts however have radical glyphs above the
   // baseline so no assumption can be made about the meaning of the ascent.
   nscoord ruleThickness, leading, em;
   GetRuleThickness(renderingContext, fm, ruleThickness);
 
@@ -409,18 +408,17 @@ nsMathMLmrootFrame::GetIntrinsicWidth(ns
   nscoord baseWidth =
     nsLayoutUtils::IntrinsicForContainer(aRenderingContext, baseFrame,
                                          nsLayoutUtils::PREF_WIDTH);
   nscoord indexWidth =
     nsLayoutUtils::IntrinsicForContainer(aRenderingContext, indexFrame,
                                          nsLayoutUtils::PREF_WIDTH);
   nscoord sqrWidth = mSqrChar.GetMaxWidth(PresContext(), *aRenderingContext);
 
-  nsCOMPtr<nsIFontMetrics> fm;
-  aRenderingContext->GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext->GetFontMetrics();
   nscoord dxSqr;
   GetRadicalXOffsets(indexWidth, sqrWidth, fm, nsnull, &dxSqr);
 
   return dxSqr + sqrWidth + baseWidth;
 }
 
 // ----------------------
 // the Style System will use these to pass the proper style context to our MathMLChar
--- a/layout/mathml/nsMathMLmsubsupFrame.cpp
+++ b/layout/mathml/nsMathMLmsubsupFrame.cpp
@@ -191,18 +191,17 @@ nsMathMLmsubsupFrame::PlaceSubSupScript(
   // subScriptShift{1,2}
   // = minimum amount to shift the subscript down
   // = sub{1,2} in TeXbook
   // subScriptShift1 = subscriptshift attribute * x-height
   nscoord subScriptShift1, subScriptShift2;
 
   aRenderingContext.SetFont(baseFrame->GetStyleFont()->mFont,
                             aPresContext->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm;
-  aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
 
   // get x-height (an ex)
   nscoord xHeight;
   fm->GetXHeight (xHeight);
 
   nscoord ruleSize;
   GetRuleThickness (aRenderingContext, fm, ruleSize);
 
--- a/layout/mathml/nsMathMLmtableFrame.cpp
+++ b/layout/mathml/nsMathMLmtableFrame.cpp
@@ -634,18 +634,17 @@ nsMathMLmtableOuterFrame::Reflow(nsPresC
       // in other situations, fallback to center
       aDesiredSize.ascent = dy + height/2;
       break;
     case eAlign_axis:
     default: {
       // XXX should instead use style data from the row of reference here ?
       aReflowState.rendContext->SetFont(GetStyleFont()->mFont,
                                         aPresContext->GetUserFontSet());
-      nsCOMPtr<nsIFontMetrics> fm;
-      aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
+      nsCOMPtr<nsIFontMetrics> fm = aReflowState.rendContext->GetFontMetrics();
       nscoord axisHeight;
       GetAxisHeight(*aReflowState.rendContext, fm, axisHeight);
       if (rowFrame) {
         // anchor the table on the axis of the row of reference
         // XXX fallback to baseline because it is a hard problem
         // XXX need to fetch the axis of the row; would need rowalign=axis to work better
         nscoord rowAscent = ((nsTableRowFrame*)rowFrame)->GetMaxCellAscent();
         if (rowAscent) { // the row has at least one cell with 'vertical-align: baseline'
--- a/layout/mathml/nsMathMLmunderFrame.cpp
+++ b/layout/mathml/nsMathMLmunderFrame.cpp
@@ -276,18 +276,17 @@ nsMathMLmunderFrame::Place(nsIRenderingC
 
   nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
 
   ////////////////////
   // Place Children
 
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             PresContext()->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm;
-  aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
 
   nscoord xHeight = 0;
   fm->GetXHeight (xHeight);
 
   nscoord ruleThickness;
   GetRuleThickness (aRenderingContext, fm, ruleThickness);
 
   // there are 2 different types of placement depending on 
--- a/layout/mathml/nsMathMLmunderoverFrame.cpp
+++ b/layout/mathml/nsMathMLmunderoverFrame.cpp
@@ -318,18 +318,17 @@ nsMathMLmunderoverFrame::Place(nsIRender
 
   nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
 
   ////////////////////
   // Place Children
 
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             PresContext()->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm;
-  aRenderingContext.GetFontMetrics(*getter_AddRefs(fm));
+  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
 
   nscoord xHeight = 0;
   fm->GetXHeight (xHeight);
 
   nscoord ruleThickness;
   GetRuleThickness (aRenderingContext, fm, ruleThickness);
 
   nscoord correction = 0;
--- a/layout/svg/base/src/nsSVGIntegrationUtils.cpp
+++ b/layout/svg/base/src/nsSVGIntegrationUtils.cpp
@@ -214,17 +214,17 @@ public:
                             const nsPoint& aOffset)
     : mBuilder(aBuilder), mInnerList(aInnerList), mFrame(aFrame),
       mOffset(aOffset) {}
 
   virtual void Paint(nsSVGRenderState *aContext, nsIFrame *aTarget,
                      const nsIntRect* aDirtyRect)
   {
     nsIRenderingContext* ctx = aContext->GetRenderingContext(aTarget);
-    nsIRenderingContext::AutoPushTranslation push(ctx, -mOffset.x, -mOffset.y);
+    nsIRenderingContext::AutoPushTranslation push(ctx, -mOffset);
     mInnerList->PaintForFrame(mBuilder, ctx, mFrame, nsDisplayList::PAINT_DEFAULT);
   }
 
 private:
   nsDisplayListBuilder* mBuilder;
   nsDisplayList* mInnerList;
   nsIFrame* mFrame;
   nsPoint mOffset;
@@ -281,17 +281,17 @@ nsSVGIntegrationUtils::PaintFramesWithEf
 
   gfxContext* gfx = aCtx->ThebesContext();
   gfxMatrix savedCTM = gfx->CurrentMatrix();
   nsSVGRenderState svgContext(aCtx);
 
   nsRect userSpaceRect = GetNonSVGUserSpace(firstFrame) + aBuilder->ToReferenceFrame(firstFrame);
   PRInt32 appUnitsPerDevPixel = aEffectsFrame->PresContext()->AppUnitsPerDevPixel();
   userSpaceRect = userSpaceRect.ToNearestPixels(appUnitsPerDevPixel).ToAppUnits(appUnitsPerDevPixel);
-  aCtx->Translate(userSpaceRect.x, userSpaceRect.y);
+  aCtx->Translate(userSpaceRect.TopLeft());
 
   gfxMatrix matrix = GetInitialMatrix(aEffectsFrame);
 
   PRBool complexEffects = PR_FALSE;
   /* Check if we need to do additional operations on this child's
    * rendering, which necessitates rendering into another surface. */
   if (opacity != 1.0f || maskFrame || (clipPathFrame && !isTrivialClip)) {
     complexEffects = PR_TRUE;
@@ -314,17 +314,17 @@ nsSVGIntegrationUtils::PaintFramesWithEf
     RegularFramePaintCallback paint(aBuilder, aInnerList, aEffectsFrame,
                                     userSpaceRect.TopLeft());
     nsIntRect r = (aDirtyRect - userSpaceRect.TopLeft()).ToOutsidePixels(appUnitsPerDevPixel);
     filterFrame->FilterPaint(&svgContext, aEffectsFrame, &paint, &r);
   } else {
     gfx->SetMatrix(savedCTM);
     aInnerList->PaintForFrame(aBuilder, aCtx, aEffectsFrame,
                               nsDisplayList::PAINT_DEFAULT);
-    aCtx->Translate(userSpaceRect.x, userSpaceRect.y);
+    aCtx->Translate(userSpaceRect.TopLeft());
   }
 
   if (clipPathFrame && isTrivialClip) {
     gfx->Restore();
   }
 
   /* No more effects, we're done. */
   if (!complexEffects) {
--- a/layout/svg/base/src/nsSVGOuterSVGFrame.cpp
+++ b/layout/svg/base/src/nsSVGOuterSVGFrame.cpp
@@ -548,17 +548,17 @@ nsSVGOuterSVGFrame::Paint(const nsDispla
 
   nsRect viewportRect = GetContentRect();
   nsPoint viewportOffset = aPt + viewportRect.TopLeft() - GetPosition();
   viewportRect.MoveTo(viewportOffset);
 
   nsRect clipRect;
   clipRect.IntersectRect(aDirtyRect, viewportRect);
   aRenderingContext.SetClipRect(clipRect, nsClipCombine_kIntersect);
-  aRenderingContext.Translate(viewportRect.x, viewportRect.y);
+  aRenderingContext.Translate(viewportRect.TopLeft());
   nsRect dirtyRect = clipRect - viewportOffset;
 
 #if defined(DEBUG) && defined(SVG_DEBUG_PAINT_TIMING)
   PRTime start = PR_Now();
 #endif
 
   nsIntRect dirtyPxRect = dirtyRect.ToOutsidePixels(PresContext()->AppUnitsPerDevPixel());
 
--- a/layout/tables/nsTableCellFrame.cpp
+++ b/layout/tables/nsTableCellFrame.cpp
@@ -334,17 +334,17 @@ nsTableCellFrame::DecorateForSelection(n
       }
       nscoord threePx = nsPresContext::CSSPixelsToAppUnits(3);
       if ((mRect.width > threePx) && (mRect.height > threePx))
       {
         //compare bordercolor to ((nsStyleColor *)myColor)->mBackgroundColor)
         bordercolor = EnsureDifferentColors(bordercolor,
                                             GetStyleBackground()->mBackgroundColor);
         nsIRenderingContext::AutoPushTranslation
-            translate(&aRenderingContext, aPt.x, aPt.y);
+            translate(&aRenderingContext, aPt);
         nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
 
         aRenderingContext.SetColor(bordercolor);
         aRenderingContext.DrawLine(onePixel, 0, mRect.width, 0);
         aRenderingContext.DrawLine(0, onePixel, 0, mRect.height);
         aRenderingContext.DrawLine(onePixel, mRect.height, mRect.width, mRect.height);
         aRenderingContext.DrawLine(mRect.width, onePixel, mRect.width, mRect.height);
         //middle
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -1364,17 +1364,17 @@ nsTableFrame::PaintTableBorderBackground
       PRIntn skipSides = GetSkipSides();
       nsRect rect(aPt, mRect.Size());
       nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
                                   aDirtyRect, rect, mStyleContext, skipSides);
     }
     else {
       // XXX we should probably get rid of this translation at some stage
       // But that would mean modifying PaintBCBorders, ugh
-      nsIRenderingContext::AutoPushTranslation translate(&aRenderingContext, aPt.x, aPt.y);
+      nsIRenderingContext::AutoPushTranslation translate(&aRenderingContext, aPt);
       PaintBCBorders(aRenderingContext, aDirtyRect - aPt);
     }
   }
 }
 
 PRIntn
 nsTableFrame::GetSkipSides() const
 {
--- a/layout/xul/base/src/nsTextBoxFrame.cpp
+++ b/layout/xul/base/src/nsTextBoxFrame.cpp
@@ -650,21 +650,20 @@ nsTextBoxFrame::CalculateUnderline(nsIRe
          // Calculate all fields of mAccessKeyInfo which
          // are the same for both BiDi and non-BiDi frames.
          const PRUnichar *titleString = mCroppedTitle.get();
          aRenderingContext.SetTextRunRTL(PR_FALSE);
          aRenderingContext.GetWidth(titleString[mAccessKeyInfo->mAccesskeyIndex],
                                     mAccessKeyInfo->mAccessWidth);
 
          nscoord offset, baseline;
-         nsIFontMetrics *metrics;
-         aRenderingContext.GetFontMetrics(metrics);
+         nsCOMPtr<nsIFontMetrics> metrics
+             = aRenderingContext.GetFontMetrics();
          metrics->GetUnderline(offset, mAccessKeyInfo->mAccessUnderlineSize);
          metrics->GetMaxAscent(baseline);
-         NS_RELEASE(metrics);
          mAccessKeyInfo->mAccessOffset = baseline - offset;
     }
 }
 
 nscoord
 nsTextBoxFrame::CalculateTitleForWidth(nsPresContext*      aPresContext,
                                        nsIRenderingContext& aRenderingContext,
                                        nscoord              aWidth)
--- a/widget/src/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/src/cocoa/nsNativeThemeCocoa.mm
@@ -1496,18 +1496,17 @@ nsNativeThemeCocoa::DrawResizer(CGContex
 NS_IMETHODIMP
 nsNativeThemeCocoa::DrawWidgetBackground(nsIRenderingContext* aContext, nsIFrame* aFrame,
                                          PRUint8 aWidgetType, const nsRect& aRect,
                                          const nsRect& aDirtyRect)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
   // setup to draw into the correct port
-  nsCOMPtr<nsIDeviceContext> dctx;
-  aContext->GetDeviceContext(*getter_AddRefs(dctx));
+  nsCOMPtr<nsIDeviceContext> dctx = aContext->GetDeviceContext();
   PRInt32 p2a = dctx->AppUnitsPerDevPixel();
 
   gfxRect nativeDirtyRect(aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height);
   gfxRect nativeWidgetRect(aRect.x, aRect.y, aRect.width, aRect.height);
   nativeWidgetRect.ScaleInverse(gfxFloat(p2a));
   nativeDirtyRect.ScaleInverse(gfxFloat(p2a));
   nativeWidgetRect.Round();
   if (nativeWidgetRect.IsEmpty())
--- a/widget/src/gtk2/nsNativeThemeGTK.cpp
+++ b/widget/src/gtk2/nsNativeThemeGTK.cpp
@@ -1131,18 +1131,17 @@ nsNativeThemeGTK::GetMinimumWidgetSize(n
   case NS_THEME_RADIO_LABEL:
   case NS_THEME_BUTTON:
   case NS_THEME_DROPDOWN:
   case NS_THEME_TOOLBAR_BUTTON:
   case NS_THEME_TREEVIEW_HEADER_CELL:
     {
       // Just include our border, and let the box code augment the size.
 
-      nsCOMPtr<nsIDeviceContext> dc;
-      aContext->GetDeviceContext(*getter_AddRefs(dc));
+      nsCOMPtr<nsIDeviceContext> dc = aContext->GetDeviceContext();
 
       nsIntMargin border;
       nsNativeThemeGTK::GetWidgetBorder(dc, aFrame, aWidgetType, &border);
       aResult->width = border.left + border.right;
       aResult->height = border.top + border.bottom;
     }
     break;
   case NS_THEME_TOOLBAR_SEPARATOR:
--- a/widget/src/qt/nsNativeThemeQt.h
+++ b/widget/src/qt/nsNativeThemeQt.h
@@ -107,18 +107,17 @@ private:
   inline nsresult DrawWidgetBackground(QPainter *qPainter,
                                        nsIRenderingContext* aContext,
                                        nsIFrame* aFrame,
                                        PRUint8 aWidgetType,
                                        const nsRect& aRect,
                                        const nsRect& aClipRect);
 
   inline PRInt32 GetAppUnitsPerDevPixel(nsIRenderingContext* aContext){
-    nsCOMPtr<nsIDeviceContext> dctx = nsnull;
-    aContext->GetDeviceContext(*getter_AddRefs(dctx));
+    nsCOMPtr<nsIDeviceContext> dctx = aContext->GetDeviceContext();
     return dctx->AppUnitsPerDevPixel();
   }
 
   void InitButtonStyle(PRUint8 widgetType,
                        nsIFrame* aFrame,
                        QRect rect,
                        QStyleOptionButton &opt);
 
--- a/widget/src/windows/nsNativeThemeWin.cpp
+++ b/widget/src/windows/nsNativeThemeWin.cpp
@@ -1241,18 +1241,17 @@ nsNativeThemeWin::DrawWidgetBackground(n
   }
 #endif // MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_LONGHORN
 
   PRInt32 part, state;
   nsresult rv = GetThemePartAndState(aFrame, aWidgetType, part, state);
   if (NS_FAILED(rv))
     return rv;
 
-  nsCOMPtr<nsIDeviceContext> dc;
-  aContext->GetDeviceContext(*getter_AddRefs(dc));
+  nsCOMPtr<nsIDeviceContext> dc = aContext->GetDeviceContext();
   gfxFloat p2a = gfxFloat(dc->AppUnitsPerDevPixel());
   RECT widgetRect;
   RECT clipRect;
   gfxRect tr(aRect.x, aRect.y, aRect.width, aRect.height),
           dr(aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height);
 
   tr.ScaleInverse(p2a);
   dr.ScaleInverse(p2a);
@@ -3110,18 +3109,17 @@ nsresult nsNativeThemeWin::ClassicDrawWi
 {
   PRInt32 part, state;
   PRBool focused;
   nsresult rv;
   rv = ClassicGetThemePartAndState(aFrame, aWidgetType, part, state, focused);
   if (NS_FAILED(rv))
     return rv;
 
-  nsCOMPtr<nsIDeviceContext> dc;
-  aContext->GetDeviceContext(*getter_AddRefs(dc));
+  nsCOMPtr<nsIDeviceContext> dc = aContext->GetDeviceContext();
   gfxFloat p2a = gfxFloat(dc->AppUnitsPerDevPixel());
   RECT widgetRect;
   gfxRect tr(aRect.x, aRect.y, aRect.width, aRect.height),
           dr(aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height);
 
   tr.ScaleInverse(p2a);
   dr.ScaleInverse(p2a);