Bug 746421 - Make nsTextBoxFrames overflow area include the LOOSE_INK_EXTENTS of the text. r=jfkthame
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 27 Apr 2012 12:24:54 +1200
changeset 92563 35dfe0d44d83ba99c977e43ebc4d10f8fae45513
parent 92562 3ca6df58d05d3ceab3fcca20643695aac5a97d7e
child 92564 e8bf76219f364346ef1b0e0b93636e819e1c9935
push id8753
push usermwoodrow@mozilla.com
push dateFri, 27 Apr 2012 00:25:03 +0000
treeherdermozilla-inbound@e8bf76219f36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs746421
milestone15.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 746421 - Make nsTextBoxFrames overflow area include the LOOSE_INK_EXTENTS of the text. r=jfkthame
gfx/src/nsFontMetrics.cpp
gfx/src/nsFontMetrics.h
layout/xul/base/src/nsTextBoxFrame.cpp
--- a/gfx/src/nsFontMetrics.cpp
+++ b/gfx/src/nsFontMetrics.cpp
@@ -360,32 +360,48 @@ nsFontMetrics::DrawString(const PRUnicha
     gfxPoint pt(aX, aY);
     if (mTextRunRTL) {
         pt.x += textRun->GetAdvanceWidth(0, aLength, &provider);
     }
     textRun->Draw(aContext->ThebesContext(), pt, gfxFont::GLYPH_FILL, 0, aLength,
                   &provider, nsnull, nsnull);
 }
 
-nsBoundingMetrics
-nsFontMetrics::GetBoundingMetrics(const PRUnichar *aString, PRUint32 aLength,
-                                  nsRenderingContext *aContext)
+static nsBoundingMetrics
+GetTextBoundingMetrics(nsFontMetrics* aMetrics, const PRUnichar *aString, PRUint32 aLength,
+                       nsRenderingContext *aContext, gfxFont::BoundingBoxType aType)
 {
     if (aLength == 0)
         return nsBoundingMetrics();
 
     StubPropertyProvider provider;
-    AutoTextRun textRun(this, aContext, aString, aLength);
+    AutoTextRun textRun(aMetrics, aContext, aString, aLength);
     nsBoundingMetrics m;
     if (textRun.get()) {
         gfxTextRun::Metrics theMetrics =
             textRun->MeasureText(0, aLength,
-                                 gfxFont::TIGHT_HINTED_OUTLINE_EXTENTS,
+                                 aType,
                                  aContext->ThebesContext(), &provider);
 
         m.leftBearing  = NSToCoordFloor( theMetrics.mBoundingBox.X());
         m.rightBearing = NSToCoordCeil(  theMetrics.mBoundingBox.XMost());
         m.ascent       = NSToCoordCeil( -theMetrics.mBoundingBox.Y());
         m.descent      = NSToCoordCeil(  theMetrics.mBoundingBox.YMost());
         m.width        = NSToCoordRound( theMetrics.mAdvanceWidth);
     }
     return m;
 }
+
+nsBoundingMetrics
+nsFontMetrics::GetBoundingMetrics(const PRUnichar *aString, PRUint32 aLength,
+                                  nsRenderingContext *aContext)
+{
+  return GetTextBoundingMetrics(this, aString, aLength, aContext, gfxFont::TIGHT_HINTED_OUTLINE_EXTENTS);
+  
+}
+
+nsBoundingMetrics
+nsFontMetrics::GetInkBoundsForVisualOverflow(const PRUnichar *aString, PRUint32 aLength,
+                                             nsRenderingContext *aContext)
+{
+  return GetTextBoundingMetrics(this, aString, aLength, aContext, gfxFont::LOOSE_INK_EXTENTS);
+}
+
--- a/gfx/src/nsFontMetrics.h
+++ b/gfx/src/nsFontMetrics.h
@@ -216,16 +216,22 @@ public:
                     nscoord aX, nscoord aY,
                     nsRenderingContext *aContext,
                     nsRenderingContext *aTextRunConstructionContext);
 
     nsBoundingMetrics GetBoundingMetrics(const PRUnichar *aString,
                                          PRUint32 aLength,
                                          nsRenderingContext *aContext);
 
+    // Returns the LOOSE_INK_EXTENTS bounds of the text for determing the
+    // overflow area of the string.
+    nsBoundingMetrics GetInkBoundsForVisualOverflow(const PRUnichar *aString,
+                                                    PRUint32 aLength,
+                                                    nsRenderingContext *aContext);
+
     void SetTextRunRTL(bool aIsRTL) { mTextRunRTL = aIsRTL; }
     bool GetTextRunRTL() { return mTextRunRTL; }
 
     gfxFontGroup* GetThebesFontGroup() { return mFontGroup; }
     gfxUserFontSet* GetUserFontSet() { return mFontGroup->GetUserFontSet(); }
 
     PRUint32 AppUnitsPerDevPixel() { return mP2A; }
 
--- a/layout/xul/base/src/nsTextBoxFrame.cpp
+++ b/layout/xul/base/src/nsTextBoxFrame.cpp
@@ -925,35 +925,50 @@ nsTextBoxFrame::DoLayout(nsBoxLayoutStat
         mNeedsReflowCallback = false;
     }
 
     nsresult rv = nsLeafBoxFrame::DoLayout(aBoxLayoutState);
 
     CalcDrawRect(*aBoxLayoutState.GetRenderingContext());
 
     const nsStyleText* textStyle = GetStyleText();
+    
+    nsRect bounds(nsPoint(0, 0), GetSize());
+    nsRect textRect = mTextDrawRect;
+    
+    nsRefPtr<nsFontMetrics> fontMet;
+    nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
+    nsBoundingMetrics metrics = 
+      fontMet->GetInkBoundsForVisualOverflow(mTitle.get(), mTitle.Length(),
+                                             aBoxLayoutState.GetRenderingContext());
+
+    textRect.x -= metrics.leftBearing;
+    textRect.width = metrics.width;
+    // In DrawText() we always draw with the baseline at MaxAscent() (relative to mTextDrawRect), 
+    textRect.y += fontMet->MaxAscent() - metrics.ascent;
+    textRect.height = metrics.ascent + metrics.descent;
+
+    bounds.UnionRect(bounds, textRect);
+    nsOverflowAreas overflow(bounds, bounds);
+
     if (textStyle->mTextShadow) {
-      nsRect bounds(nsPoint(0, 0), GetSize());
-      nsOverflowAreas overflow(bounds, bounds);
       // Our scrollable overflow is our bounds; our visual overflow may
       // extend beyond that.
-      nsPoint origin(0,0);
       nsRect &vis = overflow.VisualOverflow();
       vis.UnionRect(vis, nsLayoutUtils::GetTextShadowRectsUnion(mTextDrawRect, this));
-      FinishAndStoreOverflow(overflow, GetSize());
     }
+    FinishAndStoreOverflow(overflow, GetSize());
 
     return rv;
 }
 
 nsRect
 nsTextBoxFrame::GetComponentAlphaBounds()
 {
-  return nsLayoutUtils::GetTextShadowRectsUnion(mTextDrawRect, this,
-                                                nsLayoutUtils::EXCLUDE_BLUR_SHADOWS);
+  return GetVisualOverflowRectRelativeToSelf();
 }
 
 bool
 nsTextBoxFrame::ComputesOwnOverflowArea()
 {
     return true;
 }