Bug 669845: Make nsTypeFindAhead clear out all of its references to content nodes when reset. r=gavin

This commit is contained in:
Kyle Huey 2012-02-17 15:17:05 -08:00
parent b4c45712be
commit 19137795c6
2 changed files with 34 additions and 10 deletions

View File

@ -109,7 +109,8 @@ nsTypeAheadFind::nsTypeAheadFind():
mStartLinksOnlyPref(false),
mCaretBrowsingOn(false),
mLastFindLength(0),
mIsSoundInitialized(false)
mIsSoundInitialized(false),
mCaseSensitive(false)
{
}
@ -129,8 +130,7 @@ nsTypeAheadFind::Init(nsIDocShell* aDocShell)
mSearchRange = new nsRange();
mStartPointRange = new nsRange();
mEndPointRange = new nsRange();
mFind = do_CreateInstance(NS_FIND_CONTRACTID);
if (!prefInternal || !mFind)
if (!prefInternal || !EnsureFind())
return NS_ERROR_FAILURE;
SetDocShell(aDocShell);
@ -142,10 +142,6 @@ nsTypeAheadFind::Init(nsIDocShell* aDocShell)
// ----------- Get initial preferences ----------
PrefsReset();
// ----------- Set search options ---------------
mFind->SetCaseSensitive(false);
mFind->SetWordBreaker(nsnull);
return rv;
}
@ -176,14 +172,20 @@ nsTypeAheadFind::PrefsReset()
NS_IMETHODIMP
nsTypeAheadFind::SetCaseSensitive(bool isCaseSensitive)
{
mFind->SetCaseSensitive(isCaseSensitive);
mCaseSensitive = isCaseSensitive;
if (mFind) {
mFind->SetCaseSensitive(mCaseSensitive);
}
return NS_OK;
}
NS_IMETHODIMP
nsTypeAheadFind::GetCaseSensitive(bool* isCaseSensitive)
{
mFind->GetCaseSensitive(isCaseSensitive);
*isCaseSensitive = mCaseSensitive;
return NS_OK;
}
@ -202,6 +204,7 @@ nsTypeAheadFind::SetDocShell(nsIDocShell* aDocShell)
mStartFindRange = nsnull;
mStartPointRange = new nsRange();
mSearchRange = new nsRange();
mEndPointRange = new nsRange();
mFoundLink = nsnull;
mFoundEditable = nsnull;
@ -209,6 +212,8 @@ nsTypeAheadFind::SetDocShell(nsIDocShell* aDocShell)
mSelectionController = nsnull;
mFind = nsnull;
return NS_OK;
}
@ -393,7 +398,7 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell, bool aIsLinksOnly,
// No need to wrap find in doc if starting at beginning
bool hasWrapped = (rangeCompareResult < 0);
if (mTypeAheadBuffer.IsEmpty())
if (mTypeAheadBuffer.IsEmpty() || !EnsureFind())
return NS_ERROR_FAILURE;
mFind->SetFindBackwards(aFindPrev);

View File

@ -128,6 +128,25 @@ protected:
// Cached useful interfaces
nsCOMPtr<nsIFind> mFind;
bool mCaseSensitive;
bool EnsureFind() {
if (mFind) {
return true;
}
mFind = do_CreateInstance("@mozilla.org/embedcomp/rangefind;1");
if (!mFind) {
return false;
}
mFind->SetCaseSensitive(mCaseSensitive);
mFind->SetWordBreaker(nsnull);
return true;
}
nsCOMPtr<nsIWebBrowserFind> mWebBrowserFind;
// The focused content window that we're listening to and its cached objects