diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index 9855068f620..c9e27fdeeb7 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -473,13 +473,6 @@ nsEditor::RemoveEventListeners() NS_GET_IID(nsIDOMDragListener)); } } - - mKeyListenerP = nsnull; - mMouseListenerP = nsnull; - mFocusListenerP = nsnull; - mTextListenerP = nsnull; - mCompositionListenerP = nsnull; - mDragListenerP = nsnull; } NS_IMETHODIMP diff --git a/mozilla/editor/libeditor/html/nsHTMLAbsPosition.cpp b/mozilla/editor/libeditor/html/nsHTMLAbsPosition.cpp index 0f6ec4020ae..d3912f6fdd1 100644 --- a/mozilla/editor/libeditor/html/nsHTMLAbsPosition.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLAbsPosition.cpp @@ -316,9 +316,6 @@ nsHTMLEditor::HideGrabber() nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr docObserver(do_QueryInterface(ps)); - if (!docObserver) return NS_ERROR_FAILURE; - // get the root content node. nsIDOMElement *rootElement = GetRoot(); @@ -326,9 +323,9 @@ nsHTMLEditor::HideGrabber() nsCOMPtr rootContent = do_QueryInterface(rootElement); if (!rootContent) return NS_ERROR_NULL_POINTER; - DeleteRefToAnonymousNode(mGrabber, rootContent, docObserver); + DeleteRefToAnonymousNode(mGrabber, rootContent, ps); mGrabber = nsnull; - DeleteRefToAnonymousNode(mPositioningShadow, rootContent, docObserver); + DeleteRefToAnonymousNode(mPositioningShadow, rootContent, ps); mPositioningShadow = nsnull; return NS_OK; @@ -425,9 +422,6 @@ nsHTMLEditor::EndMoving() nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr docObserver(do_QueryInterface(ps)); - if (!docObserver) return NS_ERROR_FAILURE; - // get the root content node. nsIDOMElement *rootElement = GetRoot(); @@ -435,7 +429,7 @@ nsHTMLEditor::EndMoving() nsCOMPtr rootContent( do_QueryInterface(rootElement) ); if (!rootContent) return NS_ERROR_FAILURE; - DeleteRefToAnonymousNode(mPositioningShadow, rootContent, docObserver); + DeleteRefToAnonymousNode(mPositioningShadow, rootContent, ps); mPositioningShadow = nsnull; } nsCOMPtr erP = GetDOMEventReceiver(); diff --git a/mozilla/editor/libeditor/html/nsHTMLAnonymousUtils.cpp b/mozilla/editor/libeditor/html/nsHTMLAnonymousUtils.cpp index c8f26a814fd..e6894c7b417 100644 --- a/mozilla/editor/libeditor/html/nsHTMLAnonymousUtils.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLAnonymousUtils.cpp @@ -41,6 +41,7 @@ #include "nsIDocument.h" #include "nsIEditor.h" #include "nsIPresShell.h" +#include "nsPresContext.h" #include "nsISelection.h" @@ -51,6 +52,7 @@ #include "nsIDOMHTMLElement.h" #include "nsIDOMNSHTMLElement.h" +#include "nsIDOMEventTarget.h" #include "nsIDOMCSSValue.h" #include "nsIDOMCSSPrimitiveValue.h" @@ -167,11 +169,27 @@ nsHTMLEditor::CreateAnonymousElement(const nsAString & aTag, nsIDOMNode * aPare return NS_OK; } +// Removes event listener and calls DeleteRefToAnonymousNode. +void +nsHTMLEditor::RemoveListenerAndDeleteRef(const nsAString& aEvent, + nsIDOMEventListener* aListener, + PRBool aUseCapture, + nsIDOMElement* aElement, + nsIContent * aParentContent, + nsIPresShell* aShell) +{ + nsCOMPtr evtTarget(do_QueryInterface(aElement)); + if (evtTarget) { + evtTarget->RemoveEventListener(aEvent, aListener, aUseCapture); + } + DeleteRefToAnonymousNode(aElement, aParentContent, aShell); +} + // Deletes all references to an anonymous element void nsHTMLEditor::DeleteRefToAnonymousNode(nsIDOMElement* aElement, - nsIContent * aParentContent, - nsIDocumentObserver * aDocObserver) + nsIContent* aParentContent, + nsIPresShell* aShell) { // call ContentRemoved() for the anonymous content // node so its references get removed from the frame manager's @@ -180,8 +198,17 @@ nsHTMLEditor::DeleteRefToAnonymousNode(nsIDOMElement* aElement, if (aElement) { nsCOMPtr content = do_QueryInterface(aElement); if (content) { - aDocObserver->ContentRemoved(content->GetCurrentDoc(), - aParentContent, content, -1); + // Need to check whether aShell has been destroyed (but not yet deleted). + // In that case presContext->GetPresShell() returns nsnull. + // See bug 338129. + if (aShell && aShell->GetPresContext() && + aShell->GetPresContext()->GetPresShell() == aShell) { + nsCOMPtr docObserver = do_QueryInterface(aShell); + if (docObserver) { + docObserver->ContentRemoved(content->GetCurrentDoc(), + aParentContent, content, -1); + } + } content->UnbindFromTree(); } } diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h index e75ed9c2369..d7c883f007a 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h @@ -786,9 +786,15 @@ public: protected: /* ANONYMOUS UTILS */ + void RemoveListenerAndDeleteRef(const nsAString& aEvent, + nsIDOMEventListener* aListener, + PRBool aUseCapture, + nsIDOMElement* aElement, + nsIContent* aParentContent, + nsIPresShell* aShell); void DeleteRefToAnonymousNode(nsIDOMElement* aElement, nsIContent * aParentContent, - nsIDocumentObserver * aDocObserver); + nsIPresShell* aShell); nsresult GetElementOrigin(nsIDOMElement * aElement, PRInt32 & aX, PRInt32 & aY); nsresult GetPositionAndDimensions(nsIDOMElement * aElement, PRInt32 & aX, PRInt32 & aY, diff --git a/mozilla/editor/libeditor/html/nsHTMLInlineTableEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLInlineTableEditor.cpp index c0934d52b59..452ed45b438 100644 --- a/mozilla/editor/libeditor/html/nsHTMLInlineTableEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLInlineTableEditor.cpp @@ -122,9 +122,6 @@ nsHTMLEditor::HideInlineTableEditingUI() nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr docObserver(do_QueryInterface(ps)); - if (!docObserver) return NS_ERROR_FAILURE; - // get the root content node. nsIDOMElement *bodyElement = GetRoot(); @@ -132,17 +129,17 @@ nsHTMLEditor::HideInlineTableEditingUI() nsCOMPtr bodyContent( do_QueryInterface(bodyElement) ); if (!bodyContent) return NS_ERROR_FAILURE; - DeleteRefToAnonymousNode(mAddColumnBeforeButton, bodyContent, docObserver); + DeleteRefToAnonymousNode(mAddColumnBeforeButton, bodyContent, ps); mAddColumnBeforeButton = nsnull; - DeleteRefToAnonymousNode(mRemoveColumnButton, bodyContent, docObserver); + DeleteRefToAnonymousNode(mRemoveColumnButton, bodyContent, ps); mRemoveColumnButton = nsnull; - DeleteRefToAnonymousNode(mAddColumnAfterButton, bodyContent, docObserver); + DeleteRefToAnonymousNode(mAddColumnAfterButton, bodyContent, ps); mAddColumnAfterButton = nsnull; - DeleteRefToAnonymousNode(mAddRowBeforeButton, bodyContent, docObserver); + DeleteRefToAnonymousNode(mAddRowBeforeButton, bodyContent, ps); mAddRowBeforeButton = nsnull; - DeleteRefToAnonymousNode(mRemoveRowButton, bodyContent, docObserver); + DeleteRefToAnonymousNode(mRemoveRowButton, bodyContent, ps); mRemoveRowButton = nsnull; - DeleteRefToAnonymousNode(mAddRowAfterButton, bodyContent, docObserver); + DeleteRefToAnonymousNode(mAddRowAfterButton, bodyContent, ps); mAddRowAfterButton = nsnull; return NS_OK; diff --git a/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp b/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp index f8b8c9f6df5..e229de989dc 100644 --- a/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp @@ -426,9 +426,6 @@ nsHTMLEditor::HideResizers(void) nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr docObserver(do_QueryInterface(ps)); - if (!docObserver) return NS_ERROR_FAILURE; - // get the root content node. nsIDOMElement *bodyElement = GetRoot(); @@ -436,25 +433,46 @@ nsHTMLEditor::HideResizers(void) nsCOMPtr bodyContent( do_QueryInterface(bodyElement) ); if (!bodyContent) return NS_ERROR_FAILURE; - DeleteRefToAnonymousNode(mTopLeftHandle, bodyContent, docObserver); + NS_NAMED_LITERAL_STRING(mousedown, "mousedown"); + + RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, + mTopLeftHandle, bodyContent, ps); mTopLeftHandle = nsnull; - DeleteRefToAnonymousNode(mTopHandle, bodyContent, docObserver); + + RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, + mTopHandle, bodyContent, ps); mTopHandle = nsnull; - DeleteRefToAnonymousNode(mTopRightHandle, bodyContent, docObserver); + + RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, + mTopRightHandle, bodyContent, ps); mTopRightHandle = nsnull; - DeleteRefToAnonymousNode(mLeftHandle, bodyContent, docObserver); + + RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, + mLeftHandle, bodyContent, ps); mLeftHandle = nsnull; - DeleteRefToAnonymousNode(mRightHandle, bodyContent, docObserver); + + RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, + mRightHandle, bodyContent, ps); mRightHandle = nsnull; - DeleteRefToAnonymousNode(mBottomLeftHandle, bodyContent, docObserver); + + RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, + mBottomLeftHandle, bodyContent, ps); mBottomLeftHandle = nsnull; - DeleteRefToAnonymousNode(mBottomHandle, bodyContent, docObserver); + + RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, + mBottomHandle, bodyContent, ps); mBottomHandle = nsnull; - DeleteRefToAnonymousNode(mBottomRightHandle, bodyContent, docObserver); + + RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, + mBottomRightHandle, bodyContent, ps); mBottomRightHandle = nsnull; - DeleteRefToAnonymousNode(mResizingShadow, bodyContent, docObserver); + + RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, + mResizingShadow, bodyContent, ps); mResizingShadow = nsnull; - DeleteRefToAnonymousNode(mResizingInfo, bodyContent, docObserver); + + RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, + mResizingInfo, bodyContent, ps); mResizingInfo = nsnull; // don't forget to remove the listeners !