Bug 266236 part 8: Change nsRenderingContext::GetDeviceContext and ::GetFontMetrics to return bare pointers.
authorZack Weinberg <zackw@panix.com>
Thu, 07 Apr 2011 18:04:40 -0700
changeset 68371 3eba1138ea6dd509f46605d408ce18da8bc72df1
parent 68370 5fb27ef09b9b4b4bc416ad36f9226e9f96f3d656
child 68372 3a3109b0d39d91fe13098852c38e5c52031dec9b
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 8: Change nsRenderingContext::GetDeviceContext and ::GetFontMetrics to return bare pointers.
gfx/src/nsRenderingContext.cpp
gfx/src/nsRenderingContext.h
layout/base/nsBidiPresUtils.cpp
layout/base/nsLayoutUtils.cpp
layout/generic/nsBRFrame.cpp
layout/generic/nsBlockFrame.cpp
layout/generic/nsImageFrame.cpp
layout/generic/nsInlineFrame.cpp
layout/generic/nsLineLayout.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/xul/base/src/nsTextBoxFrame.cpp
widget/src/cocoa/nsNativeThemeCocoa.mm
widget/src/gtk2/nsNativeThemeGTK.cpp
widget/src/qt/nsNativeThemeQt.cpp
widget/src/qt/nsNativeThemeQt.h
widget/src/windows/nsNativeThemeWin.cpp
--- a/gfx/src/nsRenderingContext.cpp
+++ b/gfx/src/nsRenderingContext.cpp
@@ -95,39 +95,32 @@ nsRenderingContext::Init(nsIDeviceContex
 {
     mDeviceContext = aContext;
     mThebes = aThebesContext;
 
     mThebes->SetLineWidth(1.0);
     mP2A = mDeviceContext->AppUnitsPerDevPixel();
 }
 
-already_AddRefed<nsIDeviceContext>
-nsRenderingContext::GetDeviceContext()
-{
-    NS_IF_ADDREF(mDeviceContext);
-    return mDeviceContext.get();
-}
+//
+// graphics state
+//
 
 void
 nsRenderingContext::PushState()
 {
     mThebes->Save();
 }
 
 void
 nsRenderingContext::PopState()
 {
     mThebes->Restore();
 }
 
-//
-// clipping
-//
-
 void
 nsRenderingContext::IntersectClip(const nsRect& aRect)
 {
     mThebes->NewPath();
     gfxRect clipRect(GFX_RECT_FROM_TWIPS_RECT(aRect));
     if (mThebes->UserToDevicePixelSnapped(clipRect, PR_TRUE)) {
         gfxMatrix mat(mThebes->CurrentMatrix());
         mThebes->IdentityMatrix();
@@ -203,16 +196,20 @@ nsRenderingContext::Translate(const nsPo
 }
 
 void
 nsRenderingContext::Scale(float aSx, float aSy)
 {
     mThebes->Scale(aSx, aSy);
 }
 
+//
+// shapes
+//
+
 void
 nsRenderingContext::DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt)
 {
     DrawLine(aStartPt.x, aStartPt.y, aEndPt.x, aEndPt.y);
 }
 
 void
 nsRenderingContext::DrawLine(nscoord aX0, nscoord aY0,
@@ -440,17 +437,19 @@ nsRenderingContext::FillPolygon(const ns
         pxPoints[i].y = FROM_TWIPS(twPoints[i].y);
     }
 
     mThebes->NewPath();
     mThebes->Polygon(pxPoints, aNumPoints);
     mThebes->Fill();
 }
 
+//
 // text
+//
 
 void
 nsRenderingContext::SetRightToLeftText(PRBool aIsRTL)
 {
     mFontMetrics->SetRightToLeftText(aIsRTL);
 }
 
 void
@@ -480,23 +479,16 @@ nsRenderingContext::SetFont(const nsFont
 }
 
 void
 nsRenderingContext::SetFont(nsIFontMetrics *aFontMetrics)
 {
     mFontMetrics = static_cast<nsIThebesFontMetrics*>(aFontMetrics);
 }
 
-already_AddRefed<nsIFontMetrics>
-nsRenderingContext::GetFontMetrics()
-{
-    NS_IF_ADDREF(mFontMetrics);
-    return mFontMetrics.get();
-}
-
 PRInt32
 nsRenderingContext::GetMaxChunkLength()
 {
     if (!mFontMetrics)
         return 1;
     return PR_MIN(mFontMetrics->GetMaxStringLength(), MAX_GFX_TEXT_BUF_SIZE);
 }
 
--- a/gfx/src/nsRenderingContext.h
+++ b/gfx/src/nsRenderingContext.h
@@ -137,18 +137,20 @@ public:
     nsRenderingContext() : mP2A(0.) {}
     // ~nsRenderingContext() {}
 
     NS_INLINE_DECL_REFCOUNTING(nsRenderingContext)
 
     void Init(nsIDeviceContext* aContext, gfxASurface* aThebesSurface);
     void Init(nsIDeviceContext* aContext, gfxContext* aThebesContext);
 
-    already_AddRefed<nsIDeviceContext> GetDeviceContext();
+    // These accessors will never return null.
     gfxContext *ThebesContext() { return mThebes; }
+    nsIDeviceContext *DeviceContext() { return mDeviceContext; }
+    PRInt32 AppUnitsPerDevPixel() { return mP2A; }
 
     // Graphics state
 
     void PushState(void);
     void PopState(void);
     void IntersectClip(const nsRect& aRect);
     void SetClip(const nsIntRegion& aRegion);
     void SetLineStyle(nsLineStyle aLineStyle);
@@ -189,17 +191,17 @@ public:
     void InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
 
     // Text
 
     void SetFont(const nsFont& aFont, nsIAtom* aLanguage,
                  gfxUserFontSet *aUserFontSet);
     void SetFont(const nsFont& aFont, gfxUserFontSet *aUserFontSet);
     void SetFont(nsIFontMetrics *aFontMetrics);
-    already_AddRefed<nsIFontMetrics> GetFontMetrics();
+    nsIThebesFontMetrics *FontMetrics() { return mFontMetrics; } // may be null
 
     void SetRightToLeftText(PRBool aIsRTL);
     void SetTextRunRTL(PRBool aIsRTL);
 
     nscoord GetWidth(char aC);
     nscoord GetWidth(PRUnichar aC);
     nscoord GetWidth(const nsString& aString);
     nscoord GetWidth(const char* aString);
--- a/layout/base/nsBidiPresUtils.cpp
+++ b/layout/base/nsBidiPresUtils.cpp
@@ -1780,20 +1780,18 @@ public:
   virtual nscoord GetWidth()
   {
     return mTextRunConstructionContext->GetWidth(mText, mLength);
   }
 
   virtual void DrawText(nscoord aXOffset,
                         nscoord)
   {
-    nsCOMPtr<nsIFontMetrics> metrics = mCtx->GetFontMetrics();
-    nsIThebesFontMetrics* fm = static_cast<nsIThebesFontMetrics*>(metrics.get());
-    fm->DrawString(mText, mLength, mPt.x + aXOffset, mPt.y,
-                   mCtx, mTextRunConstructionContext);
+    mCtx->FontMetrics()->DrawString(mText, mLength, mPt.x + aXOffset, mPt.y,
+                                    mCtx, mTextRunConstructionContext);
   }
 
 private:
   nsRenderingContext* mCtx;
   nsRenderingContext* mTextRunConstructionContext;
   nsPoint mPt;
   const PRUnichar* mText;
   PRInt32 mLength;
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -3259,18 +3259,17 @@ DrawImageInternal(nsRenderingContext* aR
                   GraphicsFilter       aGraphicsFilter,
                   const nsRect&        aDest,
                   const nsRect&        aFill,
                   const nsPoint&       aAnchor,
                   const nsRect&        aDirty,
                   const nsIntSize&     aImageSize,
                   PRUint32             aImageFlags)
 {
-  nsCOMPtr<nsIDeviceContext> dc = aRenderingContext->GetDeviceContext();
-  PRInt32 appUnitsPerDevPixel = dc->AppUnitsPerDevPixel();
+  PRInt32 appUnitsPerDevPixel = aRenderingContext->AppUnitsPerDevPixel();
   gfxContext* ctx = aRenderingContext->ThebesContext();
 
   SnappedImageDrawingParameters drawingParams =
     ComputeSnappedImageDrawingParameters(ctx, appUnitsPerDevPixel, aDest, aFill,
                                          aAnchor, aDirty, aImageSize);
 
   if (!drawingParams.mShouldDraw)
     return NS_OK;
@@ -3290,18 +3289,17 @@ DrawImageInternal(nsRenderingContext* aR
 nsLayoutUtils::DrawPixelSnapped(nsRenderingContext* aRenderingContext,
                                 gfxDrawable*         aDrawable,
                                 GraphicsFilter       aFilter,
                                 const nsRect&        aDest,
                                 const nsRect&        aFill,
                                 const nsPoint&       aAnchor,
                                 const nsRect&        aDirty)
 {
-  nsCOMPtr<nsIDeviceContext> dc = aRenderingContext->GetDeviceContext();
-  PRInt32 appUnitsPerDevPixel = dc->AppUnitsPerDevPixel();
+  PRInt32 appUnitsPerDevPixel = aRenderingContext->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/generic/nsBRFrame.cpp
+++ b/layout/generic/nsBRFrame.cpp
@@ -147,17 +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();
+      nsIFontMetrics *fm = aReflowState.rendContext->FontMetrics();
       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,20 +2365,20 @@ nsBlockFrame::ReflowDirtyLines(nsBlockRe
 
       if (metrics.ascent == nsHTMLReflowMetrics::ASK_FOR_BASELINE &&
           !nsLayoutUtils::GetFirstLineBaseline(mBullet, &metrics.ascent)) {
         metrics.ascent = metrics.height;
       }
 
       nsRenderingContext *rc = aState.mReflowState.rendContext;
       nsLayoutUtils::SetFontFromStyle(rc, GetStyleContext());
-      nsCOMPtr<nsIFontMetrics> fm = rc->GetFontMetrics();
 
       nscoord minAscent =
-        nsLayoutUtils::GetCenteredFontBaseline(fm, aState.mMinLineHeight);
+        nsLayoutUtils::GetCenteredFontBaseline(rc->FontMetrics(),
+                                               aState.mMinLineHeight);
       nscoord minDescent = aState.mMinLineHeight - minAscent;
 
       aState.mY += NS_MAX(minAscent, metrics.ascent) +
                    NS_MAX(minDescent, metrics.height - metrics.ascent);
 
       nscoord offset = minAscent - metrics.ascent;
       if (offset > 0) {
         mBullet->SetRect(mBullet->GetRect() + nsPoint(0, offset));
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -970,17 +970,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
-  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
+  nsIFontMetrics* fm = aRenderingContext.FontMetrics();
 
   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
--- a/layout/generic/nsInlineFrame.cpp
+++ b/layout/generic/nsInlineFrame.cpp
@@ -639,17 +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();
+  nsIFontMetrics* fm = aReflowState.rendContext->FontMetrics();
 
   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,17 +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();
   nsRenderingContext* rc = mBlockReflowState->rendContext;
   nsLayoutUtils::SetFontFromStyle(mBlockReflowState->rendContext, styleContext);
-  nsCOMPtr<nsIFontMetrics> fm = rc->GetFontMetrics();
+  nsIFontMetrics* fm = rc->FontMetrics();
 
   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/mathml/nsMathMLContainerFrame.cpp
+++ b/layout/mathml/nsMathMLContainerFrame.cpp
@@ -97,17 +97,17 @@ nsMathMLContainerFrame::ReflowError(nsRe
   nsLayoutUtils::SetFontFromStyle(&aRenderingContext, GetStyleContext());
 
   // bounding metrics
   nsAutoString errorMsg; errorMsg.AssignLiteral("invalid-markup");
   mBoundingMetrics =
     aRenderingContext.GetBoundingMetrics(errorMsg.get(), errorMsg.Length());
 
   // reflow metrics
-  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
+  nsIFontMetrics* fm = aRenderingContext.FontMetrics();
   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;
@@ -139,18 +139,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();
-  fm->GetMaxAscent(ascent);
+  aCtx->FontMetrics()->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
@@ -276,21 +276,20 @@ nsMathMLFrame::GetAttribute(nsIContent* 
 
 /* static */ void
 nsMathMLFrame::GetRuleThickness(nsRenderingContext& 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();
-  NS_ASSERTION(currFontMetrics->Font().Equals(aFontMetrics->Font()),
-      "unexpected state");
-#endif
+  NS_ASSERTION(aRenderingContext.FontMetrics()->Font().
+               Equals(aFontMetrics->Font()),
+               "unexpected state");
+
   nscoord xHeight;
   aFontMetrics->GetXHeight(xHeight);
   PRUnichar overBar = 0x00AF;
   nsBoundingMetrics bm = aRenderingContext.GetBoundingMetrics(&overBar, 1);
   aRuleThickness = bm.ascent + bm.descent;
   if (aRuleThickness <= 0 || aRuleThickness >= xHeight) {
     // fall-back to the other version
     GetRuleThickness(aFontMetrics, aRuleThickness);
@@ -299,21 +298,20 @@ nsMathMLFrame::GetRuleThickness(nsRender
 
 /* static */ void
 nsMathMLFrame::GetAxisHeight(nsRenderingContext& 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();
-  NS_ASSERTION(currFontMetrics->Font().Equals(aFontMetrics->Font()),
-	"unexpected state");
-#endif
+  NS_ASSERTION(aRenderingContext.FontMetrics()->Font().
+               Equals(aFontMetrics->Font()),
+               "unexpected state");
+
   nscoord xHeight;
   aFontMetrics->GetXHeight(xHeight);
   PRUnichar minus = 0x2212; // not '-', but official Unicode minus sign
   nsBoundingMetrics bm = aRenderingContext.GetBoundingMetrics(&minus, 1);
   aAxisHeight = bm.ascent - (bm.ascent + bm.descent)/2;
   if (aAxisHeight <= 0 || aAxisHeight >= xHeight) {
     // fall-back to the other version
     GetAxisHeight(aFontMetrics, aAxisHeight);
--- a/layout/mathml/nsMathMLmencloseFrame.cpp
+++ b/layout/mathml/nsMathMLmencloseFrame.cpp
@@ -373,17 +373,17 @@ nsMathMLmencloseFrame::PlaceInternal(nsR
 
   ///////////////
   // Thickness of bars and font metrics
   nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
 
   nscoord mEmHeight;
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             PresContext()->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
+  nsIFontMetrics* fm = aRenderingContext.FontMetrics();
   GetRuleThickness(aRenderingContext, fm, mRuleThickness);
   GetEmHeight(fm, mEmHeight);
 
   PRUnichar one = '1';
   nsBoundingMetrics bmOne = aRenderingContext.GetBoundingMetrics(&one, 1);
 
   ///////////////
   // General rules: the menclose element takes the size of the enclosed content.
--- a/layout/mathml/nsMathMLmfencedFrame.cpp
+++ b/layout/mathml/nsMathMLmfencedFrame.cpp
@@ -240,17 +240,17 @@ nsMathMLmfencedFrame::Reflow(nsPresConte
   aDesiredSize.width = aDesiredSize.height = 0;
   aDesiredSize.ascent = 0;
   aDesiredSize.mBoundingMetrics = nsBoundingMetrics();
 
   PRInt32 i;
   const nsStyleFont* font = GetStyleFont();
   aReflowState.rendContext->SetFont(font->mFont,
                                     aPresContext->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm = aReflowState.rendContext->GetFontMetrics();
+  nsIFontMetrics* fm = aReflowState.rendContext->FontMetrics();
   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,17 +265,17 @@ nsMathMLmfracFrame::PlaceInternal(nsRend
   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();
+  nsIFontMetrics* fm = aRenderingContext.FontMetrics();
 
   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,17 +158,17 @@ nsMathMLmmultiscriptsFrame::Place(nsRend
   ////////////////////////////////////////
 
   ProcessAttributes();
 
   // get x-height (an ex)
   const nsStyleFont* font = GetStyleFont();
   aRenderingContext.SetFont(font->mFont,
                             PresContext()->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
+  nsIFontMetrics* fm = aRenderingContext.FontMetrics();
 
   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
@@ -635,22 +635,22 @@ nsMathMLmoFrame::Stretch(nsRenderingCont
   }
   mPresentationData.flags |= NS_MATHML_STRETCH_DONE;
 
   nsIFrame* firstChild = mFrames.FirstChild();
 
   // get the axis height;
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             PresContext()->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
+  nsIFontMetrics* fm = aRenderingContext.FontMetrics();
   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               
+  // this seems more reliable than using fm->GetLeading() on suspicious fonts
   nscoord em;
   GetEmHeight(fm, em);
   nscoord leading = NSToCoordRound(0.2f * em);
 
   // Operators that are stretchy, or those that are to be centered
   // to cater for fonts that are not math-aware, are handled by the MathMLChar
   // ('form' is reset if stretch fails -- i.e., we don't bother to stretch next time)
   PRBool useMathMLChar = UseMathMLChar();
--- a/layout/mathml/nsMathMLmoverFrame.cpp
+++ b/layout/mathml/nsMathMLmoverFrame.cpp
@@ -279,17 +279,17 @@ nsMathMLmoverFrame::Place(nsRenderingCon
 
   nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
 
   ////////////////////
   // Place Children
 
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             PresContext()->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
+  nsIFontMetrics* fm = aRenderingContext.FontMetrics();
 
   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,17 +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();
+  nsIFontMetrics* fm = renderingContext.FontMetrics();
 
   // 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);
 
@@ -408,19 +408,19 @@ 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();
   nscoord dxSqr;
-  GetRadicalXOffsets(indexWidth, sqrWidth, fm, nsnull, &dxSqr);
+  GetRadicalXOffsets(indexWidth, sqrWidth, aRenderingContext->FontMetrics(),
+                     nsnull, &dxSqr);
 
   return dxSqr + sqrWidth + baseWidth;
 }
 
 // ----------------------
 // the Style System will use these to pass the proper style context to our MathMLChar
 nsStyleContext*
 nsMathMLmrootFrame::GetAdditionalStyleContext(PRInt32 aIndex) const
--- a/layout/mathml/nsMathMLmsubsupFrame.cpp
+++ b/layout/mathml/nsMathMLmsubsupFrame.cpp
@@ -191,17 +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();
+  nsIFontMetrics* fm = aRenderingContext.FontMetrics();
 
   // 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,19 +634,20 @@ 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();
       nscoord axisHeight;
-      GetAxisHeight(*aReflowState.rendContext, fm, axisHeight);
+      GetAxisHeight(*aReflowState.rendContext,
+                    aReflowState.rendContext->FontMetrics(),
+                    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'
           aDesiredSize.ascent = dy + rowAscent;
           break;
--- a/layout/mathml/nsMathMLmunderFrame.cpp
+++ b/layout/mathml/nsMathMLmunderFrame.cpp
@@ -276,17 +276,17 @@ nsMathMLmunderFrame::Place(nsRenderingCo
 
   nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
 
   ////////////////////
   // Place Children
 
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             PresContext()->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
+  nsIFontMetrics* fm = aRenderingContext.FontMetrics();
 
   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,17 +318,17 @@ nsMathMLmunderoverFrame::Place(nsRenderi
 
   nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
 
   ////////////////////
   // Place Children
 
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             PresContext()->GetUserFontSet());
-  nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
+  nsIFontMetrics* fm = aRenderingContext.FontMetrics();
 
   nscoord xHeight = 0;
   fm->GetXHeight (xHeight);
 
   nscoord ruleThickness;
   GetRuleThickness (aRenderingContext, fm, ruleThickness);
 
   nscoord correction = 0;
--- a/layout/xul/base/src/nsTextBoxFrame.cpp
+++ b/layout/xul/base/src/nsTextBoxFrame.cpp
@@ -652,18 +652,17 @@ nsTextBoxFrame::CalculateUnderline(nsRen
          // are the same for both BiDi and non-BiDi frames.
          const PRUnichar *titleString = mCroppedTitle.get();
          aRenderingContext.SetTextRunRTL(PR_FALSE);
          mAccessKeyInfo->mAccessWidth =
              aRenderingContext.GetWidth(titleString[mAccessKeyInfo->
                                                     mAccesskeyIndex]);
 
          nscoord offset, baseline;
-         nsCOMPtr<nsIFontMetrics> metrics
-             = aRenderingContext.GetFontMetrics();
+         nsIFontMetrics* metrics = aRenderingContext.FontMetrics();
          metrics->GetUnderline(offset, mAccessKeyInfo->mAccessUnderlineSize);
          metrics->GetMaxAscent(baseline);
          mAccessKeyInfo->mAccessOffset = baseline - offset;
     }
 }
 
 nscoord
 nsTextBoxFrame::CalculateTitleForWidth(nsPresContext*      aPresContext,
--- a/widget/src/cocoa/nsNativeThemeCocoa.mm
+++ b/widget/src/cocoa/nsNativeThemeCocoa.mm
@@ -1489,35 +1489,37 @@ nsNativeThemeCocoa::DrawResizer(CGContex
 
   RenderTransformedHIThemeControl(cgContext, aRect, RenderResizer, &drawInfo,
                                   IsFrameRTL(aFrame));
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 NS_IMETHODIMP
-nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext, nsIFrame* aFrame,
-                                         PRUint8 aWidgetType, const nsRect& aRect,
+nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* 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();
-  PRInt32 p2a = dctx->AppUnitsPerDevPixel();
+  PRInt32 p2a = aContext->AppUnitsPerDevPixel();
 
-  gfxRect nativeDirtyRect(aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height);
+  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())
     return NS_OK; // Don't attempt to draw invisible widgets.
 
-  nsRefPtr<gfxContext> thebesCtx = aContext->ThebesContext();
+  gfxContext* thebesCtx = aContext->ThebesContext();
   if (!thebesCtx)
     return NS_ERROR_FAILURE;
 
   gfxQuartzNativeDrawing nativeDrawing(thebesCtx, nativeDirtyRect);
 
   CGContextRef cgContext = nativeDrawing.BeginNativeDrawing();
   if (cgContext == nsnull) {
     // The Quartz surface handles 0x0 surfaces by internally
--- a/widget/src/gtk2/nsNativeThemeGTK.cpp
+++ b/widget/src/gtk2/nsNativeThemeGTK.cpp
@@ -1130,21 +1130,19 @@ nsNativeThemeGTK::GetMinimumWidgetSize(n
   case NS_THEME_CHECKBOX_LABEL:
   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();
-
       nsIntMargin border;
-      nsNativeThemeGTK::GetWidgetBorder(dc, aFrame, aWidgetType, &border);
+      nsNativeThemeGTK::GetWidgetBorder(aContext->DeviceContext(),
+                                        aFrame, aWidgetType, &border);
       aResult->width = border.left + border.right;
       aResult->height = border.top + border.bottom;
     }
     break;
   case NS_THEME_TOOLBAR_SEPARATOR:
     {
       gint separator_width;
     
--- a/widget/src/qt/nsNativeThemeQt.cpp
+++ b/widget/src/qt/nsNativeThemeQt.cpp
@@ -195,17 +195,17 @@ nsNativeThemeQt::DrawWidgetBackground(QP
     if (!ctm.HasNonTranslation()) {
         ctm.x0 = NSToCoordRound(ctm.x0);
         ctm.y0 = NSToCoordRound(ctm.y0);
     }
 
     QMatrix qctm(ctm.xx, ctm.yx, ctm.xy, ctm.yy, ctm.x0, ctm.y0);
     qPainter->setWorldMatrix(qctm, true);
 
-    PRInt32 p2a = GetAppUnitsPerDevPixel(aContext);
+    PRInt32 p2a = aContext->AppUnitsPerDevPixel();
 
     QRect r = qRectInPixels(aRect, p2a);
     QRect cr = qRectInPixels(aClipRect, p2a);
 
     QStyle::State extraFlags = QStyle::State_None;
 
     switch (aWidgetType) {
     case NS_THEME_RADIO:
@@ -390,17 +390,17 @@ nsNativeThemeQt::GetMinimumWidgetSize(ns
                                       PRUint8 aWidgetType,
                                       nsIntSize* aResult, PRBool* aIsOverridable)
 {
     (*aResult).width = (*aResult).height = 0;
     *aIsOverridable = PR_TRUE;
 
     QStyle *s = qApp->style();
 
-    PRInt32 p2a = GetAppUnitsPerDevPixel(aContext);
+    PRInt32 p2a = aContext->AppUnitsPerDevPixel();
 
     switch (aWidgetType) {
     case NS_THEME_RADIO:
     case NS_THEME_CHECKBOX: {
         nsRect frameRect = aFrame->GetRect();
 
         QRect qRect = qRectInPixels(frameRect, p2a);
 
--- a/widget/src/qt/nsNativeThemeQt.h
+++ b/widget/src/qt/nsNativeThemeQt.h
@@ -106,21 +106,16 @@ private:
 
   inline nsresult DrawWidgetBackground(QPainter *qPainter,
                                        nsRenderingContext* aContext,
                                        nsIFrame* aFrame,
                                        PRUint8 aWidgetType,
                                        const nsRect& aRect,
                                        const nsRect& aClipRect);
 
-  inline PRInt32 GetAppUnitsPerDevPixel(nsRenderingContext* aContext){
-    nsCOMPtr<nsIDeviceContext> dctx = aContext->GetDeviceContext();
-    return dctx->AppUnitsPerDevPixel();
-  }
-
   void InitButtonStyle(PRUint8 widgetType,
                        nsIFrame* aFrame,
                        QRect rect,
                        QStyleOptionButton &opt);
 
   void InitPlainStyle(PRUint8 aWidgetType,
                       nsIFrame* aFrame,
                       QRect rect,
--- 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();
-  gfxFloat p2a = gfxFloat(dc->AppUnitsPerDevPixel());
+  gfxFloat p2a = gfxFloat(aContext->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);
 
@@ -3109,18 +3108,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();
-  gfxFloat p2a = gfxFloat(dc->AppUnitsPerDevPixel());
+  gfxFloat p2a = gfxFloat(aContext->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);
 
   nsRefPtr<gfxContext> ctx = aContext->ThebesContext();