From 1c6d65819c757147982aa491c5549b48eb355d38 Mon Sep 17 00:00:00 2001 From: "sharparrow1%yahoo.com" Date: Fri, 14 Apr 2006 00:28:22 +0000 Subject: [PATCH] Bug 328395: deal with an nsTypedSelection existing after its presentation is destroyed so it doesn't crash. r=bzbarsky, sr=roc git-svn-id: svn://10.0.0.236/trunk@194369 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/generic/nsSelection.cpp | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index 20cbd39fb46..19c8a246b3d 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -257,6 +257,8 @@ public: nsresult NotifySelectionListeners(); + void DetachFromPresentation(); + private: friend class nsSelectionIterator; friend struct nsScrollSelectionIntoViewEvent; @@ -952,7 +954,10 @@ nsSelection::~nsSelection() { PRInt32 i; for (i = 0;iDetachFromPresentation(); + NS_RELEASE(mDomSelections[i]); + } } } @@ -1601,6 +1606,8 @@ nsTypedSelection::ToStringWithFormat(const char * aFormatType, PRUint32 aFlags, NS_IMETHODIMP nsTypedSelection::SetInterlinePosition(PRBool aHintRight) { + if (!mFrameSelection) + return NS_ERROR_NOT_INITIALIZED; // Can't do selection nsIFrameSelection::HINT hint; if (aHintRight) hint = nsIFrameSelection::HINTRIGHT; @@ -1612,6 +1619,8 @@ nsTypedSelection::SetInterlinePosition(PRBool aHintRight) NS_IMETHODIMP nsTypedSelection::GetInterlinePosition(PRBool *aHintRight) { + if (!mFrameSelection) + return NS_ERROR_NOT_INITIALIZED; // Can't do selection nsIFrameSelection::HINT hint; nsresult rv = mFrameSelection->GetHint(&hint); if (hint == nsIFrameSelection::HINTRIGHT) @@ -4270,6 +4279,10 @@ nsTypedSelection::nsTypedSelection() nsTypedSelection::~nsTypedSelection() { + DetachFromPresentation(); +} + +void nsTypedSelection::DetachFromPresentation() { setAnchorFocusRange(-1); if (mAutoScrollTimer) { @@ -4282,7 +4295,12 @@ nsTypedSelection::~nsTypedSelection() mScrollEventPosted = PR_FALSE; } - delete mCachedOffsetForFrame; + if (mCachedOffsetForFrame) { + delete mCachedOffsetForFrame; + mCachedOffsetForFrame = nsnull; + } + + mFrameSelection = nsnull; } @@ -5535,6 +5553,8 @@ nsTypedSelection::Collapse(nsIDOMNode* aParentNode, PRInt32 aOffset) { if (!aParentNode) return NS_ERROR_INVALID_ARG; + if (!mFrameSelection) + return NS_ERROR_NOT_INITIALIZED; // Can't do selection mFrameSelection->InvalidateDesiredX(); if (!IsValidSelectionPoint(mFrameSelection, aParentNode)) return NS_ERROR_FAILURE; @@ -6052,6 +6072,9 @@ nsTypedSelection::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset) if (!mAnchorFocusRange) return NS_ERROR_NOT_INITIALIZED; + if (!mFrameSelection) + return NS_ERROR_NOT_INITIALIZED; // Can't do selection + nsresult res; if (!IsValidSelectionPoint(mFrameSelection, aParentNode)) return NS_ERROR_FAILURE; @@ -7283,6 +7306,8 @@ nsTypedSelection::DeleteFromDocument() NS_IMETHODIMP nsTypedSelection::SelectionLanguageChange(PRBool aLangRTL) { + if (!mFrameSelection) + return NS_ERROR_NOT_INITIALIZED; // Can't do selection nsresult result; nsCOMPtr focusNode; nsCOMPtr focusContent;