result = NS_OK;  nsCOMPtr<nsIDOMNSHTMLTextAreaElement> textAreaElement = do_QueryInterface(mContent); nsCOMPtr<nsIDOMNSHTMLInputElement>    inputElement = do_QueryInterface(mContent); nsCOMPtr<nsIControllers> controllers; if (textAreaElement) result = textAreaElement->GetControllers(getter_AddRefs(controllers)); else if (inputElement) result = inputElement->GetControllers(getter_AddRefs(controllers)); else result = NS_ERROR_FAILURE; if (NS_SUCCEEDED(result)) { PRUint32 count; PRBool found = PR_FALSE; result = controllers->GetControllerCount(&count); NS_ASSERTION((NS_SUCCEEDED(result)), "bad result in gfx text control destructor"); for (PRUint32 i = 0; i < count; i ++) { nsCOMPtr<nsIController> controller; result = controllers->GetControllerAt(i, getter_AddRefs(controller)); if (NS_SUCCEEDED(result) && controller) { nsCOMPtr<nsIEditorController> editController = do_QueryInterface(controller); if (editController) { editController->SetEditor(nsnull); found = PR_TRUE; } } } }
nsGfxTextControlFrame::~nsGfxTextControlFrame(){  nsresult result;  if (mDisplayFrame) {    mFrameConstructor->RemoveMappingsForFrameSubtree(mFramePresContext,                                                     mDisplayFrame, nsnull);    mDisplayFrame->Destroy(mFramePresContext);  }  if (mTempObserver)  {    if (mWebShell) {      nsCOMPtr<nsIDocumentLoader> docLoader;      mWebShell->GetDocumentLoader(*getter_AddRefs(docLoader));      if (docLoader) {        docLoader->RemoveObserver(mTempObserver);      }    }    mTempObserver->SetFrame(nsnull);    NS_RELEASE(mTempObserver);  }  // remove the focus listener from the display content, if any  if (mDisplayContent && mFocusListenerForDisplayContent)  {    nsCOMPtr<nsIDOMEventReceiver> er;    result = mDisplayContent->QueryInterface(nsIDOMEventReceiver::GetIID(), getter_AddRefs(er));    if (NS_SUCCEEDED(result) && er)     {      er->RemoveEventListenerByIID(mFocusListenerForDisplayContent, nsIDOMFocusListener::GetIID());    }    mFocusListenerForDisplayContent->SetFrame(nsnull);    NS_RELEASE(mFocusListenerForDisplayContent);  }  // remove the drag listener from the frame's content node, if any  if (mContent && mListenerForContent)  {    // checking errors below does not good, I'm in a void method    // I only check the minimum required to be sure it all works right    nsCOMPtr<nsIDOMEventReceiver> contentER;    result = mContent->QueryInterface(nsIDOMEventReceiver::GetIID(), getter_AddRefs(contentER));    if (NS_SUCCEEDED(result) && contentER)     {      nsCOMPtr<nsIDOMDragListener> dragListenerForContent;      mListenerForContent->QueryInterface(nsIDOMDragListener::GetIID(), getter_AddRefs(dragListenerForContent));      if (dragListenerForContent)      {        contentER->RemoveEventListenerByIID(dragListenerForContent, nsIDOMDragListener::GetIID());      }    }    mListenerForContent->SetFrame(nsnull);    NS_RELEASE(mListenerForContent);  }    if (mEventListener)  {    if (mEditor)    {      // remove selection listener      nsCOMPtr<nsIDOMSelection>selection;      result = mEditor->GetSelection(getter_AddRefs(selection));      if (NS_SUCCEEDED(result) && selection)       {        nsCOMPtr<nsIDOMSelectionListener>selListener;        selListener = do_QueryInterface(mEventListener);        if (selListener) {          selection->RemoveSelectionListener(selListener);         }      }      // remove all other listeners from embedded document      nsCOMPtr<nsIDOMDocument>domDoc;      result = mEditor->GetDocument(getter_AddRefs(domDoc));      if (NS_SUCCEEDED(result) && domDoc)      {        nsCOMPtr<nsIDOMEventReceiver> er;        result = domDoc->QueryInterface(nsIDOMEventReceiver::GetIID(), getter_AddRefs(er));        if (NS_SUCCEEDED(result) && er)         {          // remove key listener          nsCOMPtr<nsIDOMKeyListener>keyListener;          keyListener = do_QueryInterface(mEventListener);          if (keyListener)            er->RemoveEventListenerByIID(keyListener, nsIDOMKeyListener::GetIID());          // remove mouse listener          nsCOMPtr<nsIDOMMouseListener>mouseListener;          mouseListener = do_QueryInterface(mEventListener);          if (mouseListener)            er->RemoveEventListenerByIID(mouseListener, nsIDOMMouseListener::GetIID());          // remove focus listener          nsCOMPtr<nsIDOMFocusListener>focusListener;          focusListener = do_QueryInterface(mEventListener);          if (focusListener)            er->RemoveEventListenerByIID(focusListener, nsIDOMFocusListener::GetIID());        }      }    }  }  mEditor = 0;  // editor must be destroyed before the webshell!   nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell));   if(webShellWin)      webShellWin->Destroy();   mWebShell = nsnull; // This is where it was released before.  Not sure if                        // there is ordering depending on it.  if (mDocObserver)  {    nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDoc);    if (doc)    {      doc->RemoveObserver(mDocObserver);    }    mDocObserver->SetFrame(nsnull);    NS_RELEASE(mDocObserver);  }  if (mCachedState) {    delete mCachedState;    mCachedState = nsnull;  }}