Bug 626014 - Deal with the frame being destroyed as a result of the flush in AddRange. r=ehsan a=blocking2.0:final

This commit is contained in:
Mats Palmgren 2011-01-18 18:40:38 +01:00
parent b002155303
commit 479fbbed61

View File

@ -772,7 +772,11 @@ nsresult nsTextControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aV
// of select all which merely builds a range that selects
// all of the content and adds that to the selection.
SelectAllOrCollapseToEndOfText(PR_TRUE);
nsWeakFrame weakThis = this;
SelectAllOrCollapseToEndOfText(PR_TRUE); // NOTE: can destroy the world
if (!weakThis.IsAlive()) {
return NS_OK;
}
}
mIsProcessing = PR_FALSE;
}
@ -846,14 +850,19 @@ nsTextControlFrame::SetSelectionInternal(nsIDOMNode *aStartNode,
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
rv = selection->RemoveAllRanges();
rv = selection->RemoveAllRanges();
NS_ENSURE_SUCCESS(rv, rv);
rv = selection->AddRange(range);
rv = selection->AddRange(range); // NOTE: can destroy the world
NS_ENSURE_SUCCESS(rv, rv);
// Scroll the selection into view (see bug 231389)
// Fetch it again since it might have been destroyed (bug 626014).
selCon = txtCtrl->GetSelectionController();
if (!selCon) {
return NS_OK; // nothing to scroll, we're done
}
// Scroll the selection into view (see bug 231389).
return selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL,
nsISelectionController::SELECTION_FOCUS_REGION,
nsISelectionController::SCROLL_FIRST_ANCESTOR_ONLY);