diff --git a/gfx/src/nsFontMetrics.cpp b/gfx/src/nsFontMetrics.cpp index 6bbaa093b91..0f1adab4f9a 100644 --- a/gfx/src/nsFontMetrics.cpp +++ b/gfx/src/nsFontMetrics.cpp @@ -365,20 +365,20 @@ nsFontMetrics::DrawString(const PRUnichar* aString, PRUint32 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()); @@ -389,3 +389,19 @@ nsFontMetrics::GetBoundingMetrics(const PRUnichar *aString, PRUint32 aLength, } 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); +} + diff --git a/gfx/src/nsFontMetrics.h b/gfx/src/nsFontMetrics.h index d66d2cc2a69..e33fa7e8902 100644 --- a/gfx/src/nsFontMetrics.h +++ b/gfx/src/nsFontMetrics.h @@ -221,6 +221,12 @@ public: 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; } diff --git a/layout/xul/base/src/nsTextBoxFrame.cpp b/layout/xul/base/src/nsTextBoxFrame.cpp index d8115f50145..f2064355ee4 100644 --- a/layout/xul/base/src/nsTextBoxFrame.cpp +++ b/layout/xul/base/src/nsTextBoxFrame.cpp @@ -930,16 +930,32 @@ nsTextBoxFrame::DoLayout(nsBoxLayoutState& aBoxLayoutState) CalcDrawRect(*aBoxLayoutState.GetRenderingContext()); const nsStyleText* textStyle = GetStyleText(); + + nsRect bounds(nsPoint(0, 0), GetSize()); + nsRect textRect = mTextDrawRect; + + nsRefPtr 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; } @@ -947,8 +963,7 @@ nsTextBoxFrame::DoLayout(nsBoxLayoutState& aBoxLayoutState) nsRect nsTextBoxFrame::GetComponentAlphaBounds() { - return nsLayoutUtils::GetTextShadowRectsUnion(mTextDrawRect, this, - nsLayoutUtils::EXCLUDE_BLUR_SHADOWS); + return GetVisualOverflowRectRelativeToSelf(); } bool