mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 10:44:56 +00:00
Bug 581585 - Cache the frame for caret; r=roc approval2.0=dbaron
--HG-- extra : rebase_source : 3043705ce2689532c40d6e0f1b023b55174e8a88
This commit is contained in:
parent
5105968c9e
commit
9b8f299714
@ -178,6 +178,7 @@ nsCaret::nsCaret()
|
||||
#endif
|
||||
, mLastContentOffset(0)
|
||||
, mLastHint(nsFrameSelection::HINTLEFT)
|
||||
, mLastFrameOffset(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -300,6 +301,7 @@ void nsCaret::Terminate()
|
||||
mPresShell = nsnull;
|
||||
|
||||
mLastContent = nsnull;
|
||||
mLastFrame = nsnull;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -503,8 +505,8 @@ nsIFrame * nsCaret::GetCaretFrame(PRInt32 *aOffset)
|
||||
if (!mDrawn)
|
||||
return nsnull;
|
||||
|
||||
// Recompute the frame that we're supposed to draw in to guarantee that
|
||||
// we're not going to try to draw into a stale (dead) frame.
|
||||
// Recompute the frame that we're supposed to draw in if the cached frame
|
||||
// is stale (dead).
|
||||
PRInt32 offset;
|
||||
nsIFrame *frame = nsnull;
|
||||
nsresult rv = GetCaretFrameForNodeOffset(mLastContent, mLastContentOffset,
|
||||
@ -740,6 +742,16 @@ nsCaret::GetCaretFrameForNodeOffset(nsIContent* aContentNode,
|
||||
nsIFrame** aReturnFrame,
|
||||
PRInt32* aReturnOffset)
|
||||
{
|
||||
// Try to see if we can use our cached frame
|
||||
if (mLastFrame.IsAlive() &&
|
||||
mLastContent == aContentNode &&
|
||||
mLastContentOffset == aOffset &&
|
||||
mLastHint == aFrameHint &&
|
||||
mLastBidiLevel == aBidiLevel) {
|
||||
*aReturnFrame = mLastFrame;
|
||||
*aReturnOffset = mLastFrameOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//get frame selection and find out what frame to use...
|
||||
nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
|
||||
@ -900,6 +912,8 @@ nsCaret::GetCaretFrameForNodeOffset(nsIContent* aContentNode,
|
||||
}
|
||||
*aReturnFrame = theFrame;
|
||||
*aReturnOffset = theFrameOffset;
|
||||
mLastFrame = theFrame;
|
||||
mLastFrameOffset = theFrameOffset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -293,8 +293,11 @@ protected:
|
||||
// actually drawn (anon <BR> in text control)
|
||||
PRInt32 mLastContentOffset; // the offset for the last request
|
||||
|
||||
nsFrameSelection::HINT mLastHint; // the hint associated with the last request, see also
|
||||
// mLastBidiLevel below
|
||||
nsFrameSelection::HINT mLastHint; // the hint associated with the last request, see also
|
||||
// mLastBidiLevel above
|
||||
|
||||
nsWeakFrame mLastFrame; // the last frame on which the caret has been drawn.
|
||||
PRInt32 mLastFrameOffset; // the frame offset for the last caret position
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user