зеркало из https://github.com/mozilla/pjs.git
Fix typeahead find when fastback is turned on by checking that the pres shell is attached to a window before using it. Clean up some warnings as well. Bug 298622, r+sr=dbaron, a=chase.
This commit is contained in:
Родитель
6163cf8997
Коммит
adae76e381
|
@ -501,7 +501,7 @@ nsTypeAheadFind::UseInWindow(nsIDOMWindow *aDOMWin)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPresShell> oldPresShell(do_QueryReferent(mFocusedWeakShell));
|
||||
nsCOMPtr<nsIPresShell> oldPresShell(GetPresShell());
|
||||
|
||||
if (!oldPresShell || oldPresShell != presShell) {
|
||||
CancelFind();
|
||||
|
@ -556,7 +556,7 @@ nsTypeAheadFind::HandleEvent(nsIDOMEvent* aEvent)
|
|||
nsCOMPtr<nsIDOMEventTarget> eventTarget;
|
||||
event->GetOriginalTarget(getter_AddRefs(eventTarget));
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(eventTarget));
|
||||
nsCOMPtr<nsIPresShell> focusedShell(do_QueryReferent(mFocusedWeakShell));
|
||||
nsCOMPtr<nsIPresShell> focusedShell(GetPresShell());
|
||||
if (!focusedShell || !doc) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -933,7 +933,7 @@ nsTypeAheadFind::HandleChar(PRUnichar aChar)
|
|||
// If not, make sure the selection is in sync with the focus, so we can
|
||||
// start our search from there.
|
||||
nsCOMPtr<nsIContent> focusedContent;
|
||||
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mFocusedWeakShell));
|
||||
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
|
||||
NS_ENSURE_TRUE(presShell, NS_OK);
|
||||
nsPresContext *presContext = presShell->GetPresContext();
|
||||
NS_ENSURE_TRUE(presContext, NS_OK);
|
||||
|
@ -1224,8 +1224,7 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell,
|
|||
PRBool aIsFirstVisiblePreferred)
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> presShell(aPresShell);
|
||||
nsCOMPtr<nsIPresShell> startingPresShell =
|
||||
do_QueryReferent(mFocusedWeakShell);
|
||||
nsCOMPtr<nsIPresShell> startingPresShell = GetPresShell();
|
||||
|
||||
if (!presShell) {
|
||||
presShell = startingPresShell; // this is the current document
|
||||
|
@ -1525,8 +1524,7 @@ nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer,
|
|||
// Consider current selection as null if
|
||||
// it's not in the currently focused document
|
||||
nsCOMPtr<nsIDOMRange> currentSelectionRange;
|
||||
nsCOMPtr<nsIPresShell> selectionPresShell =
|
||||
do_QueryReferent(mFocusedWeakShell);
|
||||
nsCOMPtr<nsIPresShell> selectionPresShell = GetPresShell();
|
||||
|
||||
if (aCanUseDocSelection && selectionPresShell == presShell && mFocusedDocSelection) {
|
||||
mFocusedDocSelection->GetRangeAt(0, getter_AddRefs(currentSelectionRange));
|
||||
|
@ -1707,7 +1705,7 @@ nsTypeAheadFind::NotifySelectionChanged(nsIDOMDocument *aDoc,
|
|||
if (mRepeatingMode != eRepeatingNone) {
|
||||
// Selection had changed color for Type Ahead Find's version of Accel+G
|
||||
// We change it back when the selection changes from someone else
|
||||
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mFocusedWeakShell));
|
||||
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
|
||||
SetSelectionLook(presShell, PR_FALSE, PR_FALSE);
|
||||
}
|
||||
CancelFind();
|
||||
|
@ -1736,7 +1734,7 @@ nsTypeAheadFind::FindNext(PRBool aFindBackwards, nsISupportsInterfacePointer *aC
|
|||
// with the top level content pres shell window where find next is happening
|
||||
// If they're different, exit so that webbrowswerfind can handle FindNext()
|
||||
|
||||
nsCOMPtr<nsIPresShell> typeAheadPresShell(do_QueryReferent(mFocusedWeakShell));
|
||||
nsCOMPtr<nsIPresShell> typeAheadPresShell(GetPresShell());
|
||||
NS_ENSURE_TRUE(typeAheadPresShell, NS_OK);
|
||||
|
||||
nsPresContext *presContext = typeAheadPresShell->GetPresContext();
|
||||
|
@ -1869,7 +1867,7 @@ nsTypeAheadFind::StartNewFind(nsIDOMWindow *aWindow, PRBool aLinksOnly)
|
|||
mIsFindingText = PR_TRUE; // Turn off side effects from selection listener
|
||||
mFocusedDocSelection->CollapseToStart();
|
||||
mIsFindingText = PR_FALSE;
|
||||
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mFocusedWeakShell));
|
||||
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
|
||||
SetSelectionLook(presShell, PR_TRUE, PR_TRUE);
|
||||
}
|
||||
DisplayStatus(PR_TRUE, nsnull, PR_FALSE);
|
||||
|
@ -2033,7 +2031,7 @@ nsTypeAheadFind::CancelFind()
|
|||
if (mIsTypeAheadOn || mRepeatingMode != eRepeatingNone) {
|
||||
mTypeAheadBuffer.Truncate();
|
||||
DisplayStatus(PR_FALSE, nsnull, PR_TRUE); // Clear status
|
||||
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mFocusedWeakShell));
|
||||
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
|
||||
SetSelectionLook(presShell, PR_FALSE, PR_FALSE);
|
||||
}
|
||||
|
||||
|
@ -2214,7 +2212,7 @@ nsTypeAheadFind::SetSelectionLook(nsIPresShell *aPresShell,
|
|||
void
|
||||
nsTypeAheadFind::RemoveDocListeners()
|
||||
{
|
||||
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mFocusedWeakShell));
|
||||
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
|
||||
nsIViewManager* vm = nsnull;
|
||||
|
||||
if (presShell) {
|
||||
|
@ -2490,7 +2488,7 @@ nsTypeAheadFind::GetTargetIfTypeAheadOkay(nsIDOMEvent *aEvent,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPresShell> lastShell(do_QueryReferent(mFocusedWeakShell));
|
||||
nsCOMPtr<nsIPresShell> lastShell(GetPresShell());
|
||||
|
||||
if (lastShell != presShell || topContentWin != mFocusedWindow) {
|
||||
GetAutoStart(topContentWin, &mIsFindAllowedInWindow);
|
||||
|
@ -2723,7 +2721,7 @@ nsTypeAheadFind::DisplayStatus(PRBool aSuccess, nsIContent *aFocusedContent,
|
|||
// pres shell -> pres context -> container -> tree item ->
|
||||
// tree owner -> browser chrome
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mFocusedWeakShell));
|
||||
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
|
||||
if (!presShell) {
|
||||
return;
|
||||
}
|
||||
|
@ -3012,3 +3010,21 @@ nsTypeAheadController::EnsureContentWindow(nsIDOMWindowInternal *aFocusedWin,
|
|||
NS_IF_ADDREF(*aStartContentWin);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIPresShell>
|
||||
nsTypeAheadFind::GetPresShell()
|
||||
{
|
||||
if (!mFocusedWeakShell)
|
||||
return nsnull;
|
||||
|
||||
nsIPresShell *shell = nsnull;
|
||||
CallQueryReferent(mFocusedWeakShell.get(), &shell);
|
||||
if (shell) {
|
||||
nsPresContext *pc = shell->GetPresContext();
|
||||
if (!pc || !nsCOMPtr<nsISupports>(pc->GetContainer())) {
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
}
|
||||
|
||||
return shell;
|
||||
}
|
||||
|
|
|
@ -183,6 +183,10 @@ protected:
|
|||
PRBool aClearStatus, const PRUnichar *aText = nsnull);
|
||||
nsresult GetTranslatedString(const nsAString& aKey, nsAString& aStringOut);
|
||||
|
||||
// Get the pres shell from mFocusedWeakShell and return it only if it is
|
||||
// still attached to the DOM window.
|
||||
NS_HIDDEN_(already_AddRefed<nsIPresShell>) GetPresShell();
|
||||
|
||||
// Used by GetInstance and ReleaseInstance
|
||||
static nsTypeAheadFind *sInstance;
|
||||
|
||||
|
|
|
@ -118,11 +118,10 @@ static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID);
|
|||
nsTypeAheadFind::nsTypeAheadFind():
|
||||
mLinksOnlyPref(PR_FALSE), mStartLinksOnlyPref(PR_FALSE),
|
||||
mLinksOnly(PR_FALSE), mCaretBrowsingOn(PR_FALSE),
|
||||
mLiteralTextSearchOnly(PR_FALSE), mDontTryExactMatch(PR_FALSE),
|
||||
mAllTheSameChar(PR_TRUE),
|
||||
mFocusLinks(PR_FALSE), mLiteralTextSearchOnly(PR_FALSE),
|
||||
mDontTryExactMatch(PR_FALSE), mAllTheSameChar(PR_TRUE),
|
||||
mRepeatingMode(eRepeatingNone), mLastFindLength(0),
|
||||
mFocusLinks(PR_FALSE),
|
||||
mSoundInterface(nsnull), mIsSoundInitialized(PR_FALSE)
|
||||
mIsSoundInitialized(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -281,7 +280,7 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell,
|
|||
mFoundLink = nsnull;
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
nsCOMPtr<nsISelectionController> selectionController;
|
||||
nsCOMPtr<nsIPresShell> startingPresShell (do_QueryReferent(mPresShell));
|
||||
nsCOMPtr<nsIPresShell> startingPresShell (GetPresShell());
|
||||
if (!startingPresShell) {
|
||||
nsCOMPtr<nsIDocShell> ds = do_QueryReferent(mDocShell);
|
||||
NS_ENSURE_TRUE(ds, NS_ERROR_FAILURE);
|
||||
|
@ -442,7 +441,10 @@ nsTypeAheadFind::FindItNow(nsIPresShell *aPresShell,
|
|||
}
|
||||
}
|
||||
|
||||
*aResult = hasWrapped ? FIND_WRAPPED : FIND_FOUND;
|
||||
if (hasWrapped)
|
||||
*aResult = FIND_WRAPPED;
|
||||
else
|
||||
*aResult = FIND_FOUND;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -603,7 +605,7 @@ nsTypeAheadFind::GetSearchContainers(nsISupports *aContainer,
|
|||
// Consider current selection as null if
|
||||
// it's not in the currently focused document
|
||||
nsCOMPtr<nsIDOMRange> currentSelectionRange;
|
||||
nsCOMPtr<nsIPresShell> selectionPresShell (do_QueryReferent(mPresShell));
|
||||
nsCOMPtr<nsIPresShell> selectionPresShell (GetPresShell());
|
||||
if (aCanUseDocSelection && selectionPresShell && selectionPresShell == presShell) {
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
nsCOMPtr<nsISelectionController> selectionController;
|
||||
|
@ -819,7 +821,7 @@ nsTypeAheadFind::Find(const nsAString& aSearchString, PRBool aLinksOnly, PRUint1
|
|||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
nsCOMPtr<nsISelectionController> selectionController;
|
||||
nsCOMPtr<nsIPresShell> presShell (do_QueryReferent(mPresShell));
|
||||
nsCOMPtr<nsIPresShell> presShell (GetPresShell());
|
||||
if (!presShell) {
|
||||
nsCOMPtr<nsIDocShell> ds (do_QueryReferent(mDocShell));
|
||||
NS_ENSURE_TRUE(ds, NS_ERROR_FAILURE);
|
||||
|
@ -1136,3 +1138,21 @@ nsTypeAheadFind::IsRangeVisible(nsIPresShell *aPresShell,
|
|||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIPresShell>
|
||||
nsTypeAheadFind::GetPresShell()
|
||||
{
|
||||
if (!mPresShell)
|
||||
return nsnull;
|
||||
|
||||
nsIPresShell *shell = nsnull;
|
||||
CallQueryReferent(mPresShell.get(), &shell);
|
||||
if (shell) {
|
||||
nsPresContext *pc = shell->GetPresContext();
|
||||
if (!pc || !nsCOMPtr<nsISupports>(pc->GetContainer())) {
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
}
|
||||
|
||||
return shell;
|
||||
}
|
||||
|
|
|
@ -107,7 +107,11 @@ protected:
|
|||
nsPresContext **aPresContext);
|
||||
|
||||
nsresult Cancel();
|
||||
|
||||
|
||||
// Get the pres shell from mPresShell and return it only if it is still
|
||||
// attached to the DOM window.
|
||||
NS_HIDDEN_(already_AddRefed<nsIPresShell>) GetPresShell();
|
||||
|
||||
// Current find state
|
||||
nsString mTypeAheadBuffer;
|
||||
nsCString mNotFoundSoundURL;
|
||||
|
|
Загрузка…
Ссылка в новой задаче