From 68e11bba0d06d5f683d7728b855d0e2a800f10be Mon Sep 17 00:00:00 2001 From: "roc+%cs.cmu.edu" Date: Tue, 15 May 2007 05:23:19 +0000 Subject: [PATCH] NPOTB, new-text-frame. Fix mouse events targeting after the end of a textframe. git-svn-id: svn://10.0.0.236/trunk@226421 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/generic/nsTextFrameThebes.cpp | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mozilla/layout/generic/nsTextFrameThebes.cpp b/mozilla/layout/generic/nsTextFrameThebes.cpp index 927eb37d393..72e882a9831 100644 --- a/mozilla/layout/generic/nsTextFrameThebes.cpp +++ b/mozilla/layout/generic/nsTextFrameThebes.cpp @@ -3868,27 +3868,30 @@ nsTextFrame::IsVisibleInSelection(nsISelection* aSelection) return found; } +/** + * Compute the longest prefix of text whose width is <= aWidth. Return + * the length of the prefix. Also returns the width of the prefix in aFitWidth. + */ static PRUint32 CountCharsFit(gfxTextRun* aTextRun, PRUint32 aStart, PRUint32 aLength, gfxFloat aWidth, PropertyProvider* aProvider, gfxFloat* aFitWidth) { PRUint32 last = 0; - gfxFloat totalWidth = 0; + gfxFloat width = 0; PRUint32 i; for (i = 1; i <= aLength; ++i) { if (i == aLength || aTextRun->IsClusterStart(aStart + i)) { - gfxFloat lastWidth = totalWidth; - totalWidth += aTextRun->GetAdvanceWidth(aStart + last, i - last, aProvider); - if (totalWidth > aWidth) { - *aFitWidth = lastWidth; - return last; - } + gfxFloat nextWidth = width + + aTextRun->GetAdvanceWidth(aStart + last, i - last, aProvider); + if (nextWidth > aWidth) + break; last = i; + width = nextWidth; } } - *aFitWidth = 0; - return 0; + *aFitWidth = width; + return last; } nsIFrame::ContentOffsets