NS_IMETHODIMP HTMLEditor::HideResizers() { NS_ENSURE_TRUE(mResizedObject, NS_OK); // get the presshell's document observer interface. nsCOMPtr<nsIPresShell> ps = GetPresShell(); // We allow the pres shell to be null; when it is, we presume there // are no document observers to notify, but we still want to // UnbindFromTree. NS_NAMED_LITERAL_STRING(mousedown, "mousedown"); RemoveListenerAndDeleteRef(mousedown, mEventListener, true, Move(mTopLeftHandle), ps); RemoveListenerAndDeleteRef(mousedown, mEventListener, true, Move(mTopHandle), ps); RemoveListenerAndDeleteRef(mousedown, mEventListener, true, Move(mTopRightHandle), ps); RemoveListenerAndDeleteRef(mousedown, mEventListener, true, Move(mLeftHandle), ps); RemoveListenerAndDeleteRef(mousedown, mEventListener, true, Move(mRightHandle), ps); RemoveListenerAndDeleteRef(mousedown, mEventListener, true, Move(mBottomLeftHandle), ps); RemoveListenerAndDeleteRef(mousedown, mEventListener, true, Move(mBottomHandle), ps); RemoveListenerAndDeleteRef(mousedown, mEventListener, true, Move(mBottomRightHandle), ps); RemoveListenerAndDeleteRef(mousedown, mEventListener, true, Move(mResizingShadow), ps); RemoveListenerAndDeleteRef(mousedown, mEventListener, true, Move(mResizingInfo), ps); if (mActivatedHandle) { mActivatedHandle->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_activated, true); mActivatedHandle = nullptr; } // don't forget to remove the listeners ! nsCOMPtr<nsIDOMEventTarget> target = GetDOMEventTarget(); if (target && mMouseMotionListenerP) { DebugOnly<nsresult> rv = target->RemoveEventListener(NS_LITERAL_STRING("mousemove"), mMouseMotionListenerP, true); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove mouse motion listener"); } mMouseMotionListenerP = nullptr; nsCOMPtr<nsIDocument> doc = GetDocument(); if (!doc) { return NS_ERROR_NULL_POINTER; } target = do_QueryInterface(doc->GetWindow()); if (!target) { return NS_ERROR_NULL_POINTER; } if (mResizeEventListenerP) { DebugOnly<nsresult> rv = target->RemoveEventListener(NS_LITERAL_STRING("resize"), mResizeEventListenerP, false); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove resize event listener"); } mResizeEventListenerP = nullptr; mResizedObject->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_resizing, true); mResizedObject = nullptr; return NS_OK; }
NS_IMETHODIMP nsHTMLEditor::HideResizers(void) { if (!mResizedObject) return NS_OK; // get the presshell's document observer interface. nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; nsresult res; nsCOMPtr<nsIDOMNode> parentNode; nsCOMPtr<nsIContent> parentContent; if (mTopLeftHandle) { res = mTopLeftHandle->GetParentNode(getter_AddRefs(parentNode)); NS_ENSURE_SUCCESS(res, res); parentContent = do_QueryInterface(parentNode); } NS_NAMED_LITERAL_STRING(mousedown, "mousedown"); RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mTopLeftHandle, parentContent, ps); mTopLeftHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mTopHandle, parentContent, ps); mTopHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mTopRightHandle, parentContent, ps); mTopRightHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mLeftHandle, parentContent, ps); mLeftHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mRightHandle, parentContent, ps); mRightHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mBottomLeftHandle, parentContent, ps); mBottomLeftHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mBottomHandle, parentContent, ps); mBottomHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mBottomRightHandle, parentContent, ps); mBottomRightHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mResizingShadow, parentContent, ps); mResizingShadow = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mResizingInfo, parentContent, ps); mResizingInfo = nsnull; if (mActivatedHandle) { mActivatedHandle->RemoveAttribute(NS_LITERAL_STRING("_moz_activated")); mActivatedHandle = nsnull; } // don't forget to remove the listeners ! nsCOMPtr<nsPIDOMEventTarget> piTarget = GetPIDOMEventTarget(); nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(piTarget); if (target && mMouseMotionListenerP) { res = target->RemoveEventListener(NS_LITERAL_STRING("mousemove"), mMouseMotionListenerP, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(res), "failed to remove mouse motion listener"); } mMouseMotionListenerP = nsnull; nsCOMPtr<nsIDOMDocument> domDoc; GetDocument(getter_AddRefs(domDoc)); nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); if (!doc) { return NS_ERROR_NULL_POINTER; } target = do_QueryInterface(doc->GetWindow()); if (!target) { return NS_ERROR_NULL_POINTER; } if (mResizeEventListenerP) { res = target->RemoveEventListener(NS_LITERAL_STRING("resize"), mResizeEventListenerP, PR_FALSE); NS_ASSERTION(NS_SUCCEEDED(res), "failed to remove resize event listener"); } mResizeEventListenerP = nsnull; mResizedObject->RemoveAttribute(NS_LITERAL_STRING("_moz_resizing")); mResizedObject = nsnull; return NS_OK; }
NS_IMETHODIMP nsHTMLEditor::HideResizers(void) { if (!mResizedObject) return NS_OK; // get the presshell's document observer interface. nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; // get the root content node. nsIDOMElement *bodyElement = GetRoot(); nsCOMPtr<nsIContent> bodyContent( do_QueryInterface(bodyElement) ); if (!bodyContent) return NS_ERROR_FAILURE; NS_NAMED_LITERAL_STRING(mousedown, "mousedown"); RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mTopLeftHandle, bodyContent, ps); mTopLeftHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mTopHandle, bodyContent, ps); mTopHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mTopRightHandle, bodyContent, ps); mTopRightHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mLeftHandle, bodyContent, ps); mLeftHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mRightHandle, bodyContent, ps); mRightHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mBottomLeftHandle, bodyContent, ps); mBottomLeftHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mBottomHandle, bodyContent, ps); mBottomHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mBottomRightHandle, bodyContent, ps); mBottomRightHandle = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mResizingShadow, bodyContent, ps); mResizingShadow = nsnull; RemoveListenerAndDeleteRef(mousedown, mMouseListenerP, PR_TRUE, mResizingInfo, bodyContent, ps); mResizingInfo = nsnull; // don't forget to remove the listeners ! nsCOMPtr<nsIDOMEventReceiver> erP = GetDOMEventReceiver(); nsresult res; if (erP && mMouseMotionListenerP) { res = erP->RemoveEventListener(NS_LITERAL_STRING("mousemove"), mMouseMotionListenerP, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(res), "failed to remove mouse motion listener"); } mMouseMotionListenerP = nsnull; nsCOMPtr<nsIDOMDocument> domDoc; GetDocument(getter_AddRefs(domDoc)); nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); if (!doc) { return NS_ERROR_NULL_POINTER; } nsIScriptGlobalObject *global = doc->GetScriptGlobalObject(); if (!global) { return NS_ERROR_NULL_POINTER; } nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(global); if (target && mResizeEventListenerP) { res = target->RemoveEventListener(NS_LITERAL_STRING("resize"), mResizeEventListenerP, PR_FALSE); NS_ASSERTION(NS_SUCCEEDED(res), "failed to remove resize event listener"); } mResizeEventListenerP = nsnull; mResizedObject->RemoveAttribute(NS_LITERAL_STRING("_moz_resizing")); mResizedObject = nsnull; return NS_OK; }