Fix for bug 199490: A crash occurs after clicking in (HTML tags )document - Trunk [@

nsHTMLEditor::SetFinalSize]

  - A one line fix in HideResizers() which prevents the
    reported crash by setting mIsResizing to false. I assume
    we can't be resizing if the resize handles are being hidden.
    The assertion and null check in SetFinalSize() are just because
    I'm paranoid, but they should never be triggered if HideResizers()
    is called first.

  - The changes in StartResizing() makes it so that we don't create
    a new mouse motion listener if we already have one. We were
    creating a new listener each time we clicked on the handles, and
    never unregistering the old one ... this meant that the old
    listeners could be triggered if the editor were ever destroyed
    and the document left in tact ... allowing us to crash because the
    listeners keep an un-addref'd pointer to the HTMLEditor. Note that
    this crash is not likely to be hit in Mozilla since we always
    destroy the document and editor in Composer and MailCompose, but
    it can happen in an embedding context.

r=glazman@netscape.com  sr=sfraser@netscape.com
This commit is contained in:
kin%netscape.com 2003-04-09 21:10:58 +00:00
parent 1663cf6ca7
commit 117932d74b

View File

@ -549,6 +549,7 @@ nsHTMLEditor::HideResizers(void)
mIsShowingResizeHandles = PR_FALSE; mIsShowingResizeHandles = PR_FALSE;
mResizedObject = nsnull; mResizedObject = nsnull;
mIsResizing = PR_FALSE;
return NS_OK; return NS_OK;
} }
@ -604,12 +605,16 @@ nsHTMLEditor::StartResizing(nsIDOMElement *aHandle)
h + NS_LITERAL_STRING("px"), h + NS_LITERAL_STRING("px"),
PR_TRUE); PR_TRUE);
nsresult result = NS_OK;
if (!mMouseMotionListenerP)
{
// add a mouse move listener to the editor // add a mouse move listener to the editor
mMouseMotionListenerP = new ResizerMouseMotionListener(this); mMouseMotionListenerP = new ResizerMouseMotionListener(this);
if (!mMouseMotionListenerP) {return NS_ERROR_NULL_POINTER;} if (!mMouseMotionListenerP) {return NS_ERROR_NULL_POINTER;}
nsCOMPtr<nsIDOMEventReceiver> erP; nsCOMPtr<nsIDOMEventReceiver> erP;
nsresult result = GetDOMEventReceiver(getter_AddRefs(erP)); result = GetDOMEventReceiver(getter_AddRefs(erP));
if (NS_SUCCEEDED(result) && erP) if (NS_SUCCEEDED(result) && erP)
{ {
result = erP->AddEventListener(NS_LITERAL_STRING("mousemove"), mMouseMotionListenerP, PR_TRUE); result = erP->AddEventListener(NS_LITERAL_STRING("mousemove"), mMouseMotionListenerP, PR_TRUE);
@ -617,6 +622,8 @@ nsHTMLEditor::StartResizing(nsIDOMElement *aHandle)
} }
else else
HandleEventListenerError(); HandleEventListenerError();
}
return result; return result;
} }
@ -879,6 +886,9 @@ nsHTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent)
void void
nsHTMLEditor::SetFinalSize(PRInt32 aX, PRInt32 aY) nsHTMLEditor::SetFinalSize(PRInt32 aX, PRInt32 aY)
{ {
NS_ASSERTION(mResizedObject, "SetFinalSize() called with null mResizedObject ptr!");
if (!mResizedObject) return;
// we have now to set the new width and height of the resized object // we have now to set the new width and height of the resized object
// we don't set the x and y position because we don't control that in // we don't set the x and y position because we don't control that in
// a normal HTML layout // a normal HTML layout