From d9d7267141aa963eec1b4060a01373c2af9405d6 Mon Sep 17 00:00:00 2001 From: Timothy Nikkel Date: Wed, 24 Nov 2010 19:35:01 -0600 Subject: [PATCH] Bug 607857. If caret is in a frame that needs reflow we can wrongly position the caret rect. r=roc a=blocking-final --- layout/base/nsCaret.cpp | 15 ++++++++++++--- layout/base/nsCaret.h | 8 ++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/layout/base/nsCaret.cpp b/layout/base/nsCaret.cpp index 775c365451a..062aa044957 100644 --- a/layout/base/nsCaret.cpp +++ b/layout/base/nsCaret.cpp @@ -357,14 +357,17 @@ void nsCaret::SetCaretReadOnly(PRBool inMakeReadonly) mReadOnly = inMakeReadonly; } -void +nsresult nsCaret::GetGeometryForFrame(nsIFrame* aFrame, PRInt32 aFrameOffset, nsRect* aRect, nscoord* aBidiIndicatorSize) { nsPoint framePos(0, 0); - aFrame->GetPointFromOffset(aFrameOffset, &framePos); + nsresult rv = aFrame->GetPointFromOffset(aFrameOffset, &framePos); + if (NS_FAILED(rv)) + return rv; + nsIFrame *frame = aFrame->GetContentInsertionFrame(); NS_ASSERTION(frame, "We should not be in the middle of reflow"); nscoord baseline = frame->GetCaretBaseline(); @@ -401,6 +404,8 @@ nsCaret::GetGeometryForFrame(nsIFrame* aFrame, if (aBidiIndicatorSize) *aBidiIndicatorSize = caretMetrics.mBidiIndicatorSize; + + return NS_OK; } nsIFrame* nsCaret::GetGeometry(nsISelection* aSelection, nsRect* aRect, @@ -1089,7 +1094,11 @@ nsCaret::UpdateCaretRects(nsIFrame* aFrame, PRInt32 aFrameOffset) NS_ASSERTION(aFrame, "Should have a frame here"); nscoord bidiIndicatorSize; - GetGeometryForFrame(aFrame, aFrameOffset, &mCaretRect, &bidiIndicatorSize); + nsresult rv = + GetGeometryForFrame(aFrame, aFrameOffset, &mCaretRect, &bidiIndicatorSize); + if (NS_FAILED(rv)) { + return PR_FALSE; + } // on RTL frames the right edge of mCaretRect must be equal to framePos const nsStyleVisibility* vis = aFrame->GetStyleVisibility(); diff --git a/layout/base/nsCaret.h b/layout/base/nsCaret.h index 74346d81986..4ae582c8a52 100644 --- a/layout/base/nsCaret.h +++ b/layout/base/nsCaret.h @@ -217,10 +217,10 @@ protected: nscoord mCaretWidth; // full caret width including bidi indicator }; Metrics ComputeMetrics(nsIFrame* aFrame, PRInt32 aOffset, nscoord aCaretHeight); - void GetGeometryForFrame(nsIFrame* aFrame, - PRInt32 aFrameOffset, - nsRect* aRect, - nscoord* aBidiIndicatorSize); + nsresult GetGeometryForFrame(nsIFrame* aFrame, + PRInt32 aFrameOffset, + nsRect* aRect, + nscoord* aBidiIndicatorSize); // Returns true if the caret should be drawn. When |mDrawn| is true, // this returns true, so that we erase the drawn caret. If |aIgnoreDrawnState|