PRUint32 cnt; nsresult rv = mSelectionListeners->Count(&cnt); if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIDOMDocument> domdoc; nsCOMPtr<nsIDocument> doc; nsCOMPtr<nsIPresShell> shell; rv = GetPresShell(getter_AddRefs(shell)); if (NS_SUCCEEDED(rv) && shell) { rv = shell->GetDocument(getter_AddRefs(doc)); if (NS_FAILED(rv)) doc = 0; domdoc = do_QueryInterface(doc); } for (PRUint32 i = 0; i < cnt;i++) { nsCOMPtr<nsISupports> isupports(dont_AddRef(mSelectionListeners->ElementAt(i))); nsCOMPtr<nsIDOMSelectionListener> thisListener = do_QueryInterface(isupports); if (thisListener) thisListener->NotifySelectionChanged(domdoc,this, (short) mFrameSelection->mMouseDownState); } return NS_OK;
return NS_ERROR_FAILURE;
nsDOMSelection::NotifySelectionListeners(){  if (!mSelectionListeners)    return NS_ERROR_FAILURE;   if (mFrameSelection->GetBatching()){    mFrameSelection->SetDirty();    return NS_OK;  }  PRUint32 cnt;  nsresult rv = mSelectionListeners->Count(&cnt);  if (NS_FAILED(rv)) return rv;    nsCOMPtr<nsIDOMDocument> domdoc;  nsCOMPtr<nsIDocument> doc;  nsCOMPtr<nsIPresShell> shell;  rv = GetPresShell(getter_AddRefs(shell));  if (NS_SUCCEEDED(rv) && shell)  {    rv = shell->GetDocument(getter_AddRefs(doc));    if (NS_FAILED(rv))      doc = 0;    domdoc = do_QueryInterface(doc);  }  for (PRUint32 i = 0; i < cnt;i++)  {    nsCOMPtr<nsISupports> isupports(dont_AddRef(mSelectionListeners->ElementAt(i)));    nsCOMPtr<nsIDOMSelectionListener> thisListener = do_QueryInterface(isupports);    if (thisListener)    	thisListener->NotifySelectionChanged(domdoc,this, (short) mFrameSelection->mMouseDownState);  }	return NS_OK;}