Bug 266236 part 6: Change out-parameters to return values and remove a bunch of default parameters that were never called with non-default values.
authorZack Weinberg <zackw@panix.com>
Thu, 07 Apr 2011 18:04:40 -0700
changeset 68126 cf8bfa6a407376d42c802f1e966e368ab61c8a63
parent 68125 793e5d7b26c5818d7cb5bef267cf938b8ed233c2
child 68127 5fb27ef09b9b4b4bc416ad36f9226e9f96f3d656
push idunknown
push userunknown
push dateunknown
bugs266236
milestone6.0a1
Bug 266236 part 6: Change out-parameters to return values and remove a bunch of default parameters that were never called with non-default values.
gfx/src/nsRenderingContext.cpp
gfx/src/nsRenderingContext.h
layout/base/nsBidiPresUtils.cpp
layout/base/nsLayoutUtils.cpp
layout/generic/nsImageFrame.cpp
layout/mathml/nsMathMLChar.cpp
layout/mathml/nsMathMLContainerFrame.cpp
layout/mathml/nsMathMLFrame.cpp
layout/mathml/nsMathMLmencloseFrame.cpp
layout/mathml/nsMathMLmfencedFrame.cpp
layout/mathml/nsMathMLmrootFrame.cpp
layout/xul/base/src/nsTextBoxFrame.cpp
layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
--- a/gfx/src/nsRenderingContext.cpp
+++ b/gfx/src/nsRenderingContext.cpp
@@ -503,260 +503,172 @@ nsRenderingContext::GetFontMetrics()
 PRInt32
 nsRenderingContext::GetMaxChunkLength()
 {
     if (!mFontMetrics)
         return 1;
     return PR_MIN(mFontMetrics->GetMaxStringLength(), MAX_GFX_TEXT_BUF_SIZE);
 }
 
-nsresult
-nsRenderingContext::GetWidth(char aC, nscoord &aWidth)
+nscoord
+nsRenderingContext::GetWidth(char aC)
 {
-    if (aC == ' ' && mFontMetrics)
-        return mFontMetrics->GetSpaceWidth(aWidth);
+    if (aC == ' ' && mFontMetrics) {
+        nscoord width;
+        mFontMetrics->GetSpaceWidth(width);
+        return width;
+    }
 
-    return GetWidth(&aC, 1, aWidth);
+    return GetWidth(&aC, 1);
 }
 
-nsresult
-nsRenderingContext::GetWidth(PRUnichar aC, nscoord &aWidth, PRInt32 *aFontID)
+nscoord
+nsRenderingContext::GetWidth(PRUnichar aC)
 {
-    return GetWidth(&aC, 1, aWidth, aFontID);
+    return GetWidth(&aC, 1);
 }
 
-nsresult
-nsRenderingContext::GetWidth(const nsString& aString, nscoord &aWidth,
-                                   PRInt32 *aFontID)
+nscoord
+nsRenderingContext::GetWidth(const nsString& aString)
 {
-    return GetWidth(aString.get(), aString.Length(), aWidth, aFontID);
-}
-
-nsresult
-nsRenderingContext::GetWidth(const char* aString, nscoord& aWidth)
-{
-    return GetWidth(aString, strlen(aString), aWidth);
+    return GetWidth(aString.get(), aString.Length());
 }
 
-nsresult
-nsRenderingContext::GetWidth(const char* aString,
-                             PRUint32 aLength,
-                             nscoord& aWidth)
+nscoord
+nsRenderingContext::GetWidth(const char* aString)
+{
+    return GetWidth(aString, strlen(aString));
+}
+
+nscoord
+nsRenderingContext::GetWidth(const char* aString, PRUint32 aLength)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength();
-    aWidth = 0;
+    nscoord width = 0;
     while (aLength > 0) {
         PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength);
-        nscoord width;
-        nsresult rv = GetWidthInternal(aString, len, width);
-        if (NS_FAILED(rv))
-            return rv;
-        aWidth += width;
+        width += GetWidthInternal(aString, len);
         aLength -= len;
         aString += len;
     }
-    return NS_OK;
+    return width;
 }
 
-nsresult
-nsRenderingContext::GetWidth(const PRUnichar *aString,
-                             PRUint32 aLength,
-                             nscoord &aWidth,
-                             PRInt32 *aFontID)
+nscoord
+nsRenderingContext::GetWidth(const PRUnichar *aString, PRUint32 aLength)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength();
-    aWidth = 0;
-
-    if (aFontID) {
-        *aFontID = 0;
-    }
-
+    nscoord width = 0;
     while (aLength > 0) {
         PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength);
-        nscoord width;
-        nsresult rv = GetWidthInternal(aString, len, width);
-        if (NS_FAILED(rv))
-            return rv;
-        aWidth += width;
+        width += GetWidthInternal(aString, len);
         aLength -= len;
         aString += len;
     }
-    return NS_OK;
+    return width;
 }
 
 #ifdef MOZ_MATHML
-nsresult
-nsRenderingContext::GetBoundingMetrics(const PRUnichar*   aString,
-                                       PRUint32           aLength,
-                                       nsBoundingMetrics& aBoundingMetrics,
-                                       PRInt32*           aFontID)
+nsBoundingMetrics
+nsRenderingContext::GetBoundingMetrics(const PRUnichar* aString,
+                                       PRUint32 aLength)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength();
-    if (aLength <= maxChunkLength)
-        return GetBoundingMetricsInternal(aString, aLength, aBoundingMetrics,
-                                          aFontID);
+    PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength);
+    // Assign directly in the first iteration. This ensures that
+    // negative ascent/descent can be returned and the left bearing
+    // is properly initialized.
+    nsBoundingMetrics totalMetrics;
+    mFontMetrics->GetBoundingMetrics(aString, len, this, totalMetrics);
+    aLength -= len;
+    aString += len;
 
-    if (aFontID) {
-        *aFontID = 0;
-    }
-
-    PRBool firstIteration = PR_TRUE;
     while (aLength > 0) {
-        PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength);
+        len = FindSafeLength(aString, aLength, maxChunkLength);
         nsBoundingMetrics metrics;
-        nsresult rv = GetBoundingMetricsInternal(aString, len, metrics);
-        if (NS_FAILED(rv))
-            return rv;
-        if (firstIteration) {
-            // Instead of combining with a Clear()ed nsBoundingMetrics, we
-            // assign directly in the first iteration. This ensures that
-            // negative ascent/ descent can be returned and the left bearing
-            // is properly initialized.
-            aBoundingMetrics = metrics;
-        } else {
-            aBoundingMetrics += metrics;
-        }
+        mFontMetrics->GetBoundingMetrics(aString, len, this, metrics);
+        totalMetrics += metrics;
         aLength -= len;
         aString += len;
-        firstIteration = PR_FALSE;
     }
-    return NS_OK;
+    return totalMetrics;
 }
 #endif
 
 void
-nsRenderingContext::DrawString(const nsString& aString, nscoord aX, nscoord aY,
-                               PRInt32 aFontID, const nscoord* aSpacing)
-{
-    DrawString(aString.get(), aString.Length(), aX, aY, aFontID, aSpacing);
-}
-
-void
 nsRenderingContext::DrawString(const char *aString, PRUint32 aLength,
-                               nscoord aX, nscoord aY,
-                               const nscoord* aSpacing)
+                               nscoord aX, nscoord aY)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength();
     while (aLength > 0) {
         PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength);
-        DrawStringInternal(aString, len, aX, aY);
+        mFontMetrics->DrawString(aString, len, aX, aY, nsnull, this);
         aLength -= len;
 
         if (aLength > 0) {
-            nscoord width;
-            nsresult rv = GetWidthInternal(aString, len, width);
-            if (NS_FAILED(rv))
-                return;
+            nscoord width = GetWidthInternal(aString, len);
             aX += width;
             aString += len;
         }
     }
 }
 
 void
+nsRenderingContext::DrawString(const nsString& aString, nscoord aX, nscoord aY)
+{
+    DrawString(aString.get(), aString.Length(), aX, aY);
+}
+
+void
 nsRenderingContext::DrawString(const PRUnichar *aString, PRUint32 aLength,
-                               nscoord aX, nscoord aY,
-                               PRInt32 aFontID,
-                               const nscoord* aSpacing)
+                               nscoord aX, nscoord aY)
 {
     PRUint32 maxChunkLength = GetMaxChunkLength();
     if (aLength <= maxChunkLength) {
-        DrawStringInternal(aString, aLength, aX, aY, aFontID, aSpacing);
+        mFontMetrics->DrawString(aString, aLength, aX, aY, this, this);
         return;
     }
 
     PRBool isRTL = mFontMetrics->GetRightToLeftText();
 
+    // If we're drawing right to left, we must start at the end.
     if (isRTL) {
-        nscoord totalWidth = 0;
-        if (aSpacing) {
-            for (PRUint32 i = 0; i < aLength; ++i) {
-                totalWidth += aSpacing[i];
-            }
-        } else {
-            nsresult rv = GetWidth(aString, aLength, totalWidth);
-            if (NS_FAILED(rv))
-                return;
-        }
-        aX += totalWidth;
+        aX += GetWidth(aString, aLength);
     }
 
     while (aLength > 0) {
         PRInt32 len = FindSafeLength(aString, aLength, maxChunkLength);
-        nscoord width = 0;
-        if (aSpacing) {
-            for (PRInt32 i = 0; i < len; ++i) {
-                width += aSpacing[i];
-            }
-        } else {
-            nsresult rv = GetWidthInternal(aString, len, width);
-            if (NS_FAILED(rv))
-                return;
-        }
-
+        nscoord width = GetWidthInternal(aString, len);
         if (isRTL) {
             aX -= width;
         }
-        DrawStringInternal(aString, len, aX, aY, aFontID, aSpacing);
-        aLength -= len;
+        mFontMetrics->DrawString(aString, len, aX, aY, this, this);
         if (!isRTL) {
             aX += width;
         }
+        aLength -= len;
         aString += len;
-        if (aSpacing) {
-            aSpacing += len;
-        }
     }
 }
 
-nsresult
-nsRenderingContext::GetWidthInternal(const char* aString, PRUint32 aLength,
-                                     nscoord& aWidth)
+nscoord
+nsRenderingContext::GetWidthInternal(const char* aString, PRUint32 aLength)
 {
     if (aLength == 0) {
-        aWidth = 0;
-        return NS_OK;
+        return 0;
     }
 
-    return mFontMetrics->GetWidth(aString, aLength, aWidth, this);
-}
-
-nsresult
-nsRenderingContext::GetWidthInternal(const PRUnichar *aString, PRUint32 aLength,
-                                     nscoord &aWidth, PRInt32 *aFontID)
-{
-    if (aLength == 0) {
-        aWidth = 0;
-        return NS_OK;
-    }
-
-    return mFontMetrics->GetWidth(aString, aLength, aWidth, aFontID, this);
+    nscoord width;
+    mFontMetrics->GetWidth(aString, aLength, width, this);
+    return width;
 }
 
-#ifdef MOZ_MATHML
-nsresult
-nsRenderingContext::GetBoundingMetricsInternal(const PRUnichar*   aString,
-                                               PRUint32           aLength,
-                                               nsBoundingMetrics& aBoundingMetrics,
-                                               PRInt32*           aFontID)
+nscoord
+nsRenderingContext::GetWidthInternal(const PRUnichar *aString, PRUint32 aLength)
 {
-    return mFontMetrics->GetBoundingMetrics(aString, aLength, this,
-                                            aBoundingMetrics);
-}
-#endif // MOZ_MATHML
+    if (aLength == 0) {
+        return 0;
+    }
 
-void
-nsRenderingContext::DrawStringInternal(const char *aString, PRUint32 aLength,
-                                       nscoord aX, nscoord aY,
-                                       const nscoord* aSpacing)
-{
-    mFontMetrics->DrawString(aString, aLength, aX, aY, aSpacing, this);
+    nscoord width;
+    mFontMetrics->GetWidth(aString, aLength, width, nsnull, this);
+    return width;
 }
-
-void
-nsRenderingContext::DrawStringInternal(const PRUnichar *aString,
-                                       PRUint32 aLength,
-                                       nscoord aX, nscoord aY,
-                                       PRInt32 aFontID,
-                                       const nscoord* aSpacing)
-{
-    mFontMetrics->DrawString(aString, aLength, aX, aY, aFontID, aSpacing, this);
-}
--- a/gfx/src/nsRenderingContext.h
+++ b/gfx/src/nsRenderingContext.h
@@ -201,69 +201,38 @@ public:
                  gfxUserFontSet *aUserFontSet);
     void SetFont(const nsFont& aFont, gfxUserFontSet *aUserFontSet);
     void SetFont(nsIFontMetrics *aFontMetrics);
     already_AddRefed<nsIFontMetrics> GetFontMetrics();
 
     void SetRightToLeftText(PRBool aIsRTL);
     void SetTextRunRTL(PRBool aIsRTL);
 
-    nsresult GetWidth(const nsString& aString, nscoord &aWidth,
-                      PRInt32 *aFontID = nsnull);
-    nsresult GetWidth(const char* aString, nscoord& aWidth);
-    nsresult GetWidth(const char* aString, PRUint32 aLength,
-                      nscoord& aWidth);
-    nsresult GetWidth(const PRUnichar *aString, PRUint32 aLength,
-                      nscoord &aWidth, PRInt32 *aFontID = nsnull);
-    nsresult GetWidth(char aC, nscoord &aWidth);
-    nsresult GetWidth(PRUnichar aC, nscoord &aWidth, PRInt32 *aFontID = nsnull);
+    nscoord GetWidth(char aC);
+    nscoord GetWidth(PRUnichar aC);
+    nscoord GetWidth(const nsString& aString);
+    nscoord GetWidth(const char* aString);
+    nscoord GetWidth(const char* aString, PRUint32 aLength);
+    nscoord GetWidth(const PRUnichar *aString, PRUint32 aLength);
 
 #ifdef MOZ_MATHML
-    nsresult GetBoundingMetrics(const PRUnichar*   aString,
-                                PRUint32           aLength,
-                                nsBoundingMetrics& aBoundingMetrics,
-                                PRInt32*           aFontID = nsnull);
+    nsBoundingMetrics GetBoundingMetrics(const PRUnichar *aString,
+                                         PRUint32 aLength);
 #endif
 
-    void DrawString(const nsString& aString, nscoord aX, nscoord aY,
-                    PRInt32 aFontID = -1,
-                    const nscoord* aSpacing = nsnull);
+    void DrawString(const nsString& aString, nscoord aX, nscoord aY);
     void DrawString(const char *aString, PRUint32 aLength,
-                    nscoord aX, nscoord aY,
-                    const nscoord* aSpacing = nsnull);
+                    nscoord aX, nscoord aY);
     void DrawString(const PRUnichar *aString, PRUint32 aLength,
-                    nscoord aX, nscoord aY,
-                    PRInt32 aFontID = -1,
-                    const nscoord* aSpacing = nsnull);
+                    nscoord aX, nscoord aY);
 
 protected:
     PRInt32 GetMaxChunkLength();
-
-    nsresult GetWidthInternal(const char *aString, PRUint32 aLength,
-                              nscoord &aWidth);
-    nsresult GetWidthInternal(const PRUnichar *aString, PRUint32 aLength,
-                              nscoord &aWidth, PRInt32 *aFontID = nsnull);
-
-    void DrawStringInternal(const char *aString, PRUint32 aLength,
-                            nscoord aX, nscoord aY,
-                            const nscoord* aSpacing = nsnull);
-    void DrawStringInternal(const PRUnichar *aString, PRUint32 aLength,
-                            nscoord aX, nscoord aY,
-                            PRInt32 aFontID = -1,
-                            const nscoord* aSpacing = nsnull);
-
-#ifdef MOZ_MATHML
-    /**
-     * Returns metrics (in app units) of a Unicode character string
-     */
-    nsresult GetBoundingMetricsInternal(const PRUnichar*   aString,
-                                        PRUint32           aLength,
-                                        nsBoundingMetrics& aBoundingMetrics,
-                                        PRInt32*           aFontID = nsnull);
-#endif /* MOZ_MATHML */
+    nscoord GetWidthInternal(const char *aString, PRUint32 aLength);
+    nscoord GetWidthInternal(const PRUnichar *aString, PRUint32 aLength);
 
     nsRefPtr<gfxContext> mThebes;
     nsCOMPtr<nsIDeviceContext> mDeviceContext;
     nsCOMPtr<nsIThebesFontMetrics> mFontMetrics;
 
     double mP2A; // cached app units per device pixel value
 };
 
--- a/layout/base/nsBidiPresUtils.cpp
+++ b/layout/base/nsBidiPresUtils.cpp
@@ -1774,19 +1774,17 @@ public:
   {
     mTextRunConstructionContext->SetTextRunRTL(aDirection==NSBIDI_RTL);
     mText = aText;
     mLength = aLength;
   }
 
   virtual nscoord GetWidth()
   {
-    nscoord width;
-    mTextRunConstructionContext->GetWidth(mText, mLength, width, nsnull);
-    return width;
+    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,
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -1700,28 +1700,27 @@ nsLayoutUtils::BinarySearchForPosition(n
                         PRInt32    aEndInx,
                         PRInt32    aCursorPos,
                         PRInt32&   aIndex,
                         PRInt32&   aTextWidth)
 {
   PRInt32 range = aEndInx - aStartInx;
   if ((range == 1) || (range == 2 && NS_IS_HIGH_SURROGATE(aText[aStartInx]))) {
     aIndex   = aStartInx + aBaseInx;
-    aRendContext->GetWidth(aText, aIndex, aTextWidth);
+    aTextWidth = aRendContext->GetWidth(aText, aIndex);
     return PR_TRUE;
   }
 
   PRInt32 inx = aStartInx + (range / 2);
 
   // Make sure we don't leave a dangling low surrogate
   if (NS_IS_HIGH_SURROGATE(aText[inx-1]))
     inx++;
 
-  PRInt32 textWidth = 0;
-  aRendContext->GetWidth(aText, inx, textWidth);
+  PRInt32 textWidth = aRendContext->GetWidth(aText, inx);
 
   PRInt32 fullWidth = aBaseWidth + textWidth;
   if (fullWidth == aCursorPos) {
     aTextWidth = textWidth;
     aIndex = inx;
     return PR_TRUE;
   } else if (aCursorPos < fullWidth) {
     aTextWidth = aBaseWidth;
@@ -2835,19 +2834,17 @@ nsLayoutUtils::GetStringWidth(const nsIF
     nsBidiDirection direction =
       (NS_STYLE_DIRECTION_RTL == vis->mDirection) ?
       NSBIDI_RTL : NSBIDI_LTR;
     return nsBidiPresUtils::MeasureTextWidth(aString, aLength,
                                              direction, presContext, *aContext);
   }
 #endif // IBMBIDI
   aContext->SetTextRunRTL(PR_FALSE);
-  nscoord width;
-  aContext->GetWidth(aString, aLength, width);
-  return width;
+  return aContext->GetWidth(aString, aLength);
 }
 
 /* static */ nscoord
 nsLayoutUtils::GetCenteredFontBaseline(nsIFontMetrics* aFontMetrics,
                                        nscoord         aLineHeight)
 {
   nscoord fontAscent, fontHeight;
   aFontMetrics->GetMaxAscent(fontAscent);
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -905,19 +905,18 @@ nsImageFrame::Reflow(nsPresContext*     
 nscoord
 nsImageFrame::MeasureString(const PRUnichar*     aString,
                             PRInt32              aLength,
                             nscoord              aMaxWidth,
                             PRUint32&            aMaxFit,
                             nsRenderingContext& aContext)
 {
   nscoord totalWidth = 0;
-  nscoord spaceWidth;
   aContext.SetTextRunRTL(PR_FALSE);
-  aContext.GetWidth(' ', spaceWidth);
+  nscoord spaceWidth = aContext.GetWidth(' ');
 
   aMaxFit = 0;
   while (aLength > 0) {
     // Find the next place we can line break
     PRUint32  len = aLength;
     PRBool    trailingSpace = PR_FALSE;
     for (PRInt32 i = 0; i < aLength; i++) {
       if (XP_IS_SPACE(aString[i]) && (i > 0)) {
--- a/layout/mathml/nsMathMLChar.cpp
+++ b/layout/mathml/nsMathMLChar.cpp
@@ -1239,57 +1239,54 @@ nsMathMLChar::StretchEnumContext::TryVar
 
     SetFontFamily(mChar->mStyleContext->PresContext(), mRenderingContext,
                   font, aGlyphTable, ch, aFamily);
 
     NS_ASSERTION(maxWidth || ch.code != mChar->mGlyph.code ||
                  !font.name.Equals(mChar->mFamily),
                  "glyph table incorrectly set -- duplicate found");
 
-    nsBoundingMetrics bm;
-    nsresult rv = mRenderingContext.GetBoundingMetrics(&ch.code, 1, bm);
-    if (NS_SUCCEEDED(rv)) {
-      nscoord charSize =
-        isVertical ? bm.ascent + bm.descent
-                   : bm.rightBearing - bm.leftBearing;
+    nsBoundingMetrics bm = mRenderingContext.GetBoundingMetrics(&ch.code, 1);
+    nscoord charSize =
+      isVertical ? bm.ascent + bm.descent
+      : bm.rightBearing - bm.leftBearing;
 
-      if (largeopOnly ||
-          IsSizeBetter(charSize, bestSize, mTargetSize, mStretchHint)) {
-        mGlyphFound = PR_TRUE;
-        if (maxWidth) {
-          // IsSizeBetter() checked that charSize < maxsize;
-          // Leave ascent, descent, and bestsize as these contain maxsize.
-          if (mBoundingMetrics.width < bm.width)
-            mBoundingMetrics.width = bm.width;
-          if (mBoundingMetrics.leftBearing > bm.leftBearing)
-            mBoundingMetrics.leftBearing = bm.leftBearing;
-          if (mBoundingMetrics.rightBearing < bm.rightBearing)
-            mBoundingMetrics.rightBearing = bm.rightBearing;
-          // Continue to check other sizes unless largeopOnly
-          haveBetter = largeopOnly;
-        }
-        else {
-          mBoundingMetrics = bm;
-          haveBetter = PR_TRUE;
-          bestSize = charSize;
-          mChar->mGlyphTable = aGlyphTable;
-          mChar->mGlyph = ch;
-          mChar->mFamily = font.name;
-        }
-#ifdef NOISY_SEARCH
-        printf("    size:%d Current best\n", size);
-#endif
+    if (largeopOnly ||
+        IsSizeBetter(charSize, bestSize, mTargetSize, mStretchHint)) {
+      mGlyphFound = PR_TRUE;
+      if (maxWidth) {
+        // IsSizeBetter() checked that charSize < maxsize;
+        // Leave ascent, descent, and bestsize as these contain maxsize.
+        if (mBoundingMetrics.width < bm.width)
+          mBoundingMetrics.width = bm.width;
+        if (mBoundingMetrics.leftBearing > bm.leftBearing)
+          mBoundingMetrics.leftBearing = bm.leftBearing;
+        if (mBoundingMetrics.rightBearing < bm.rightBearing)
+          mBoundingMetrics.rightBearing = bm.rightBearing;
+        // Continue to check other sizes unless largeopOnly
+        haveBetter = largeopOnly;
       }
       else {
+        mBoundingMetrics = bm;
+        haveBetter = PR_TRUE;
+        bestSize = charSize;
+        mChar->mGlyphTable = aGlyphTable;
+        mChar->mGlyph = ch;
+        mChar->mFamily = font.name;
+      }
 #ifdef NOISY_SEARCH
-        printf("    size:%d Rejected!\n", size);
+      printf("    size:%d Current best\n", size);
 #endif
-        if (haveBetter)
-          break; // Not making an futher progress, stop searching
-      }
+    }
+    else {
+#ifdef NOISY_SEARCH
+      printf("    size:%d Rejected!\n", size);
+#endif
+      if (haveBetter)
+        break; // Not making an futher progress, stop searching
     }
 
     // if largeopOnly is set, break now
     if (largeopOnly) break;
     ++size;
   }
 
   return haveBetter &&
@@ -1351,32 +1348,26 @@ nsMathMLChar::StretchEnumContext::TryPar
     switch (i) {
     case 0: ch = aGlyphTable->TopOf(mPresContext, mChar);    break;
     case 1: ch = aGlyphTable->MiddleOf(mPresContext, mChar); break;
     case 2: ch = aGlyphTable->BottomOf(mPresContext, mChar); break;
     case 3: ch = glue;                                       break;
     }
     // empty slots are filled with the glue if it is not null
     if (!ch.Exists()) ch = glue;
-    nsBoundingMetrics bm;
     chdata[i] = ch;
     if (!ch.Exists()) {
       // Null glue indicates that a rule will be drawn, which can stretch to
       // fill any space.  Leave bounding metrics at 0.
       sizedata[i] = mTargetSize;
     }
     else {
       SetFontFamily(mChar->mStyleContext->PresContext(), mRenderingContext,
                     font, aGlyphTable, ch, aFamily);
-      nsresult rv = mRenderingContext.GetBoundingMetrics(&ch.code, 1, bm);
-      if (NS_FAILED(rv)) {
-        // stop if we failed to compute the bounding metrics of a part.
-        NS_WARNING("GetBoundingMetrics failed");
-        return PR_FALSE; // to next table
-      }
+      nsBoundingMetrics bm = mRenderingContext.GetBoundingMetrics(&ch.code, 1);
 
       // TODO: For the generic Unicode table, ideally we should check that the
       // glyphs are actually found and that they each come from the same
       // font.
       bmdata[i] = bm;
       sizedata[i] = isVertical ? bm.ascent + bm.descent
                                : bm.rightBearing - bm.leftBearing;
     }
@@ -1556,24 +1547,18 @@ nsMathMLChar::StretchInternal(nsPresCont
   PRBool maxWidth = (NS_STRETCH_MAXWIDTH & aStretchHint) != 0;
   if (!maxWidth) {
     // Record the families in case there is no stretch.  But don't bother
     // storing families when they are just those from the StyleContext.
     mFamily = families;
   }
 
   aRenderingContext.SetFont(font, aPresContext->GetUserFontSet());
-  nsresult rv =
-    aRenderingContext.GetBoundingMetrics(mData.get(), PRUint32(mData.Length()),
-                                         aDesiredStretchSize);
-  if (NS_FAILED(rv)) {
-    NS_WARNING("GetBoundingMetrics failed");
-    mDirection = NS_STRETCH_DIRECTION_UNSUPPORTED;
-    return rv;
-  }
+  aDesiredStretchSize =
+    aRenderingContext.GetBoundingMetrics(mData.get(), PRUint32(mData.Length()));
 
   if (!maxWidth) {
     mUnscaledAscent = aDesiredStretchSize.ascent;
   }
 
   ////////////////////////////////////////////////////////////////////////////////////
   // 1. Check the common situations where stretching is not actually needed
   ////////////////////////////////////////////////////////////////////////////////////
@@ -2275,21 +2260,17 @@ nsMathMLChar::PaintVertically(nsPresCont
         break;
     }
     // empty slots are filled with the glue if it is not null
     if (!ch.Exists()) ch = chGlue;
     // if (!ch.Exists()) glue is null, leave bounding metrics at 0
     if (ch.Exists()) {
       SetFontFamily(aPresContext, aRenderingContext,
                     aFont, aGlyphTable, ch, mFamily);
-      rv = aRenderingContext.GetBoundingMetrics(&ch.code, 1, bmdata[i]);
-      if (NS_FAILED(rv)) {
-        NS_WARNING("GetBoundingMetrics failed");
-        return rv;
-      }
+      bmdata[i] = aRenderingContext.GetBoundingMetrics(&ch.code, 1);
     }
     chdata[i] = ch;
     ++i;
   }
   nscoord dx = aRect.x;
   nscoord offset[3], start[3], end[3];
   nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
   for (i = 0; i <= bottom; ++i) {
@@ -2508,21 +2489,17 @@ nsMathMLChar::PaintHorizontally(nsPresCo
         break;
     }
     // empty slots are filled with the glue if it is not null
     if (!ch.Exists()) ch = chGlue;
     // if (!ch.Exists()) glue is null, leave bounding metrics at 0.
     if (ch.Exists()) {
       SetFontFamily(aPresContext, aRenderingContext,
                     aFont, aGlyphTable, ch, mFamily);
-      rv = aRenderingContext.GetBoundingMetrics(&ch.code, 1, bmdata[i]);
-      if (NS_FAILED(rv)) {
-        NS_WARNING("GetBoundingMetrics failed");
-        return rv;
-      }
+      bmdata[i] = aRenderingContext.GetBoundingMetrics(&ch.code, 1);
     }
     chdata[i] = ch;
     ++i;
   }
   nscoord dy = aRect.y + mBoundingMetrics.ascent;
   nscoord offset[3], start[3], end[3];
   nsRefPtr<gfxContext> ctx = aRenderingContext.ThebesContext();
   for (i = 0; i <= right; ++i) {
--- a/layout/mathml/nsMathMLContainerFrame.cpp
+++ b/layout/mathml/nsMathMLContainerFrame.cpp
@@ -93,25 +93,18 @@ nsMathMLContainerFrame::ReflowError(nsRe
   mPresentationData.flags = NS_MATHML_ERROR;
 
   ///////////////
   // Set font
   nsLayoutUtils::SetFontFromStyle(&aRenderingContext, GetStyleContext());
 
   // bounding metrics
   nsAutoString errorMsg; errorMsg.AssignLiteral("invalid-markup");
-  rv = aRenderingContext.GetBoundingMetrics(errorMsg.get(),
-                                            PRUint32(errorMsg.Length()),
-                                            mBoundingMetrics);
-  if (NS_FAILED(rv)) {
-    NS_WARNING("GetBoundingMetrics failed");
-    aDesiredSize.width = aDesiredSize.height = 0;
-    aDesiredSize.ascent = 0;
-    return NS_OK;
-  }
+  mBoundingMetrics =
+    aRenderingContext.GetBoundingMetrics(errorMsg.get(), errorMsg.Length());
 
   // reflow metrics
   nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
   fm->GetMaxAscent(aDesiredSize.ascent);
   nscoord descent;
   fm->GetMaxDescent(descent);
   aDesiredSize.height = aDesiredSize.ascent + descent;
   aDesiredSize.width = mBoundingMetrics.width;
--- a/layout/mathml/nsMathMLFrame.cpp
+++ b/layout/mathml/nsMathMLFrame.cpp
@@ -284,37 +284,22 @@ nsMathMLFrame::GetRuleThickness(nsRender
 #ifdef NS_DEBUG
   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);
-  if (NS_SUCCEEDED(rv)) {
-    aRuleThickness = bm.ascent + bm.descent;
-  }
-  if (NS_FAILED(rv) || aRuleThickness <= 0 || aRuleThickness >= xHeight) {
+  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);
   }
-
-#if 0
-  nscoord oldRuleThickness;
-  GetRuleThickness(aFontMetrics, oldRuleThickness);
-
-  PRUnichar sqrt = 0xE063; // a sqrt glyph from TeX's CMEX font
-  rv = aRenderingContext.GetBoundingMetrics(&sqrt, PRUint32(1), bm);
-  nscoord sqrtrule = bm.ascent; // according to TeX, the ascent should be the rule
-
-  printf("xheight:%4d rule:%4d oldrule:%4d  sqrtrule:%4d\n",
-          xHeight, aRuleThickness, oldRuleThickness, sqrtrule);
-#endif
 }
 
 /* static */ void
 nsMathMLFrame::GetAxisHeight(nsRenderingContext& aRenderingContext,
                              nsIFontMetrics*      aFontMetrics,
                              nscoord&             aAxisHeight)
 {
   // get the bounding metrics of the minus sign, the rendering context
@@ -322,22 +307,19 @@ nsMathMLFrame::GetAxisHeight(nsRendering
 #ifdef NS_DEBUG
   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);
-  if (NS_SUCCEEDED(rv)) {
-    aAxisHeight = bm.ascent - (bm.ascent + bm.descent)/2;
-  }
-  if (NS_FAILED(rv) || aAxisHeight <= 0 || aAxisHeight >= xHeight) {
+  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);
   }
 }
 
 /* static */ nscoord
 nsMathMLFrame::CalcLength(nsPresContext*   aPresContext,
                           nsStyleContext*   aStyleContext,
--- a/layout/mathml/nsMathMLmencloseFrame.cpp
+++ b/layout/mathml/nsMathMLmencloseFrame.cpp
@@ -377,18 +377,18 @@ nsMathMLmencloseFrame::PlaceInternal(nsR
 
   nscoord mEmHeight;
   aRenderingContext.SetFont(GetStyleFont()->mFont,
                             PresContext()->GetUserFontSet());
   nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
   GetRuleThickness(aRenderingContext, fm, mRuleThickness);
   GetEmHeight(fm, mEmHeight);
 
-  nsBoundingMetrics bmOne;
-  aRenderingContext.GetBoundingMetrics(NS_LITERAL_STRING("1").get(), 1, bmOne);
+  PRUnichar one = '1';
+  nsBoundingMetrics bmOne = aRenderingContext.GetBoundingMetrics(&one, 1);
 
   ///////////////
   // General rules: the menclose element takes the size of the enclosed content.
   // We add a padding when needed.
 
   // determine padding & psi
   nscoord padding = 3 * mRuleThickness;
   nscoord delta = padding % onePixel;
--- a/layout/mathml/nsMathMLmfencedFrame.cpp
+++ b/layout/mathml/nsMathMLmfencedFrame.cpp
@@ -497,18 +497,18 @@ nsMathMLmfencedFrame::ReflowChar(nsPresC
     }
     else {
       // either it hasn't changed or stretching the char failed (i.e.,
       // GetBoundingMetrics failed)
       leading = 0;
       if (NS_FAILED(res)) {
         nsAutoString data;
         aMathMLChar->GetData(data);
-        nsBoundingMetrics metrics;
-        aRenderingContext.GetBoundingMetrics(data.get(), data.Length(), metrics);
+        nsBoundingMetrics metrics =
+          aRenderingContext.GetBoundingMetrics(data.get(), data.Length());
         charSize.ascent = metrics.ascent;
         charSize.descent = metrics.descent;
         charSize.width = metrics.width;
         // Set this as the bounding metrics of the MathMLChar to leave
         // the necessary room to paint the char.
         aMathMLChar->SetBoundingMetrics(charSize);
       }
     }
--- a/layout/mathml/nsMathMLmrootFrame.cpp
+++ b/layout/mathml/nsMathMLmrootFrame.cpp
@@ -265,18 +265,18 @@ nsMathMLmrootFrame::Reflow(nsPresContext
 
   // 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);
 
-  nsBoundingMetrics bmOne;
-  renderingContext.GetBoundingMetrics(NS_LITERAL_STRING("1").get(), 1, bmOne);
+  PRUnichar one = '1';
+  nsBoundingMetrics bmOne = renderingContext.GetBoundingMetrics(&one, 1);
 
   // get the leading to be left at the top of the resulting frame
   // this seems more reliable than using fm->GetLeading() on suspicious fonts
   GetEmHeight(fm, em);
   leading = nscoord(0.2f * em); 
 
   // Rule 11, App. G, TeXbook
   // psi = clearance between rule and content
--- a/layout/xul/base/src/nsTextBoxFrame.cpp
+++ b/layout/xul/base/src/nsTextBoxFrame.cpp
@@ -562,18 +562,19 @@ nsTextBoxFrame::DrawText(nsRenderingCont
     {
        aRenderingContext.SetTextRunRTL(PR_FALSE);
 
        if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {
            // In the simple (non-BiDi) case, we calculate the mnemonic's
            // underline position by getting the text metric.
            // XXX are attribute values always two byte?
            if (mAccessKeyInfo->mAccesskeyIndex > 0)
-               refContext->GetWidth(mCroppedTitle.get(), mAccessKeyInfo->mAccesskeyIndex,
-                                    mAccessKeyInfo->mBeforeWidth);
+               mAccessKeyInfo->mBeforeWidth =
+                   refContext->GetWidth(mCroppedTitle.get(),
+                                        mAccessKeyInfo->mAccesskeyIndex);
            else
                mAccessKeyInfo->mBeforeWidth = 0;
        }
 
        nsIThebesFontMetrics* fm = static_cast<nsIThebesFontMetrics*>(fontMet.get());
        fm->DrawString(mCroppedTitle.get(), mCroppedTitle.Length(),
                       aTextRect.x, baseline, &aRenderingContext, refContext.get());
     }
@@ -646,18 +647,19 @@ void nsTextBoxFrame::PaintOneShadow(gfxC
 void
 nsTextBoxFrame::CalculateUnderline(nsRenderingContext& aRenderingContext)
 {
     if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {
          // 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);
+         mAccessKeyInfo->mAccessWidth =
+             aRenderingContext.GetWidth(titleString[mAccessKeyInfo->
+                                                    mAccesskeyIndex]);
 
          nscoord offset, baseline;
          nsCOMPtr<nsIFontMetrics> metrics
              = aRenderingContext.GetFontMetrics();
          metrics->GetUnderline(offset, mAccessKeyInfo->mAccessUnderlineSize);
          metrics->GetMaxAscent(baseline);
          mAccessKeyInfo->mAccessOffset = baseline - offset;
     }
@@ -689,17 +691,17 @@ nsTextBoxFrame::CalculateTitleForWidth(n
 
     const nsDependentString& kEllipsis = nsContentUtils::GetLocalizedEllipsis();
     // start with an ellipsis
     mCroppedTitle.Assign(kEllipsis);
 
     // see if the width is even smaller than the ellipsis
     // if so, clear the text (XXX set as many '.' as we can?).
     aRenderingContext.SetTextRunRTL(PR_FALSE);
-    aRenderingContext.GetWidth(kEllipsis, titleWidth);
+    titleWidth = aRenderingContext.GetWidth(kEllipsis);
 
     if (titleWidth > aWidth) {
         mCroppedTitle.SetLength(0);
         return 0;
     }
 
     // if the ellipsis fits perfectly, no use in trying to insert
     if (titleWidth == aWidth)
@@ -717,17 +719,17 @@ nsTextBoxFrame::CalculateTitleForWidth(n
         {
             nscoord cwidth;
             nscoord twidth = 0;
             int length = mTitle.Length();
             int i;
             for (i = 0; i < length; ++i) {
                 PRUnichar ch = mTitle.CharAt(i);
                 // still in LTR mode
-                aRenderingContext.GetWidth(ch,cwidth);
+                cwidth = aRenderingContext.GetWidth(ch);
                 if (twidth + cwidth > aWidth)
                     break;
 
                 twidth += cwidth;
 #ifdef IBMBIDI
                 if (UCS2_CHAR_IS_BIDI(ch) ) {
                   mState |= NS_FRAME_IS_BIDI;
                 }
@@ -747,17 +749,17 @@ nsTextBoxFrame::CalculateTitleForWidth(n
         case CropLeft:
         {
             nscoord cwidth;
             nscoord twidth = 0;
             int length = mTitle.Length();
             int i;
             for (i=length-1; i >= 0; --i) {
                 PRUnichar ch = mTitle.CharAt(i);
-                aRenderingContext.GetWidth(ch,cwidth);
+                cwidth = aRenderingContext.GetWidth(ch);
                 if (twidth + cwidth > aWidth)
                     break;
 
                 twidth += cwidth;
 #ifdef IBMBIDI
                 if (UCS2_CHAR_IS_BIDI(ch) ) {
                   mState |= NS_FRAME_IS_BIDI;
                 }
@@ -791,33 +793,33 @@ nsTextBoxFrame::CalculateTitleForWidth(n
             int leftPos, rightPos;
             nsAutoString leftString, rightString;
 
             rightPos = mTitle.Length() - 1;
             aRenderingContext.SetTextRunRTL(PR_FALSE);
             for (leftPos = 0; leftPos <= rightPos;) {
                 // look at the next character on the left end
                 ch = mTitle.CharAt(leftPos);
-                aRenderingContext.GetWidth(ch, charWidth);
+                charWidth = aRenderingContext.GetWidth(ch);
                 totalWidth += charWidth;
                 if (totalWidth > aWidth)
                     // greater than the allowable width
                     break;
                 leftString.Insert(ch, leftString.Length());
 
 #ifdef IBMBIDI
                 if (UCS2_CHAR_IS_BIDI(ch))
                     mState |= NS_FRAME_IS_BIDI;
 #endif
 
                 // look at the next character on the right end
                 if (rightPos > leftPos) {
                     // haven't looked at this character yet
                     ch = mTitle.CharAt(rightPos);
-                    aRenderingContext.GetWidth(ch, charWidth);
+                    charWidth = aRenderingContext.GetWidth(ch);
                     totalWidth += charWidth;
                     if (totalWidth > aWidth)
                         // greater than the allowable width
                         break;
                     rightString.Insert(ch, 0);
 
 #ifdef IBMBIDI
                     if (UCS2_CHAR_IS_BIDI(ch))
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
@@ -1379,19 +1379,18 @@ nsTreeBodyFrame::AdjustForCellText(nsAut
       }
     }
   }
 
   if (width > maxWidth) {
     // See if the width is even smaller than the ellipsis
     // If so, clear the text completely.
     const nsDependentString& kEllipsis = nsContentUtils::GetLocalizedEllipsis();
-    nscoord ellipsisWidth;
     aRenderingContext.SetTextRunRTL(PR_FALSE);
-    aRenderingContext.GetWidth(kEllipsis, ellipsisWidth);
+    nscoord ellipsisWidth = aRenderingContext.GetWidth(kEllipsis);
 
     width = maxWidth;
     if (ellipsisWidth > width)
       aText.SetLength(0);
     else if (ellipsisWidth == width)
       aText.Assign(kEllipsis);
     else {
       // We will be drawing an ellipsis, thank you very much.
@@ -1406,17 +1405,17 @@ nsTreeBodyFrame::AdjustForCellText(nsAut
           // Crop right.
           nscoord cwidth;
           nscoord twidth = 0;
           int length = aText.Length();
           int i;
           for (i = 0; i < length; ++i) {
             PRUnichar ch = aText[i];
             // XXX this is horrible and doesn't handle clusters
-            aRenderingContext.GetWidth(ch,cwidth);
+            cwidth = aRenderingContext.GetWidth(ch);
             if (twidth + cwidth > width)
               break;
             twidth += cwidth;
           }
           aText.Truncate(i);
           aText.Append(kEllipsis);
         }
         break;
@@ -1424,17 +1423,17 @@ nsTreeBodyFrame::AdjustForCellText(nsAut
         case 2: {
           // Crop left.
           nscoord cwidth;
           nscoord twidth = 0;
           int length = aText.Length();
           int i;
           for (i=length-1; i >= 0; --i) {
             PRUnichar ch = aText[i];
-            aRenderingContext.GetWidth(ch,cwidth);
+            cwidth = aRenderingContext.GetWidth(ch);
             if (twidth + cwidth > width)
               break;
             twidth += cwidth;
           }
 
           nsAutoString copy;
           aText.Right(copy, length-1-i);
           aText.Assign(kEllipsis);
@@ -1446,24 +1445,24 @@ nsTreeBodyFrame::AdjustForCellText(nsAut
         {
           // Crop center.
           nsAutoString leftStr, rightStr;
           nscoord cwidth, twidth = 0;
           int length = aText.Length();
           int rightPos = length - 1;
           for (int leftPos = 0; leftPos < rightPos; ++leftPos) {
             PRUnichar ch = aText[leftPos];
-            aRenderingContext.GetWidth(ch, cwidth);
+            cwidth = aRenderingContext.GetWidth(ch);
             twidth += cwidth;
             if (twidth > width)
               break;
             leftStr.Append(ch);
 
             ch = aText[rightPos];
-            aRenderingContext.GetWidth(ch, cwidth);
+            cwidth = aRenderingContext.GetWidth(ch);
             twidth += cwidth;
             if (twidth > width)
               break;
             rightStr.Insert(ch, 0);
             --rightPos;
           }
           aText = leftStr;
           aText.Append(kEllipsis);