ForceCompositionEnd(); nsAutoString stuffToPaste;   nsresult rv; NS_WITH_SERVICE ( nsIClipboard, clipboard, kCClipboardCID, &rv ); if ( NS_FAILED(rv) ) return rv;   nsCOMPtr<nsITransferable> trans; rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, NS_GET_IID(nsITransferable), (void**) getter_AddRefs(trans)); if (NS_SUCCEEDED(rv)) {  if (trans) {   if ((mFlags & eEditorPlaintextMask) == 0) { trans->AddDataFlavor(kJPEGImageMime); trans->AddDataFlavor(kHTMLMime); } trans->AddDataFlavor(kUnicodeMime);   if (NS_SUCCEEDED(clipboard->GetData(trans))) { char* bestFlavor = nsnull; nsCOMPtr<nsISupports> genericDataObj; PRUint32 len = 0; if ( NS_SUCCEEDED(trans->GetAnyTransferData(&bestFlavor, getter_AddRefs(genericDataObj), &len)) ) { nsAutoString flavor ( bestFlavor ); #ifdef DEBUG_akkana printf("Got flavor [%s]\n", bestFlavor); #endif if (flavor.Equals(kHTMLMime)) { nsCOMPtr<nsISupportsWString> textDataObj ( do_QueryInterface(genericDataObj) ); if (textDataObj && len > 0) { PRUnichar* text = nsnull; textDataObj->ToString ( &text ); stuffToPaste.SetString ( text, len / 2 ); nsAutoEditBatch beginBatching(this); rv = InsertHTML(stuffToPaste); } } else if (flavor.Equals(kUnicodeMime)) { nsCOMPtr<nsISupportsWString> textDataObj ( do_QueryInterface(genericDataObj) ); if (textDataObj && len > 0) { PRUnichar* text = nsnull; textDataObj->ToString ( &text ); stuffToPaste.SetString ( text, len / 2 ); nsAutoEditBatch beginBatching(this); rv = InsertText(stuffToPaste); } } else if (flavor.Equals(kJPEGImageMime)) {  printf("Don't know how to insert an image yet!\n");   rv = NS_ERROR_NOT_IMPLEMENTED; } } nsCRT::free(bestFlavor); } } }  return rv;
return nsTextEditor::Paste();
NS_IMETHODIMP nsHTMLEditor::Paste(){  ForceCompositionEnd();  nsAutoString stuffToPaste;  // Get Clipboard Service  nsresult rv;  NS_WITH_SERVICE ( nsIClipboard, clipboard, kCClipboardCID, &rv );  if ( NS_FAILED(rv) )    return rv;      // Create generic Transferable for getting the data  nsCOMPtr<nsITransferable> trans;  rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,                                           NS_GET_IID(nsITransferable),                                           (void**) getter_AddRefs(trans));  if (NS_SUCCEEDED(rv))  {    // Get the nsITransferable interface for getting the data from the clipboard    if (trans)    {      // Create the desired DataFlavor for the type of data      // we want to get out of the transferable      if ((mFlags & eEditorPlaintextMask) == 0)  // This should only happen in html editors, not plaintext      {        trans->AddDataFlavor(kJPEGImageMime);        trans->AddDataFlavor(kHTMLMime);      }      trans->AddDataFlavor(kUnicodeMime);      // Get the Data from the clipboard      if (NS_SUCCEEDED(clipboard->GetData(trans)))      {        char* bestFlavor = nsnull;        nsCOMPtr<nsISupports> genericDataObj;        PRUint32 len = 0;        if ( NS_SUCCEEDED(trans->GetAnyTransferData(&bestFlavor, getter_AddRefs(genericDataObj), &len)) )        {          nsAutoString flavor ( bestFlavor );   // just so we can use flavor.Equals()#ifdef DEBUG_akkana          printf("Got flavor [%s]\n", bestFlavor);#endif          if (flavor.Equals(kHTMLMime))          {            nsCOMPtr<nsISupportsWString> textDataObj ( do_QueryInterface(genericDataObj) );            if (textDataObj && len > 0)            {              PRUnichar* text = nsnull;              textDataObj->ToString ( &text );              stuffToPaste.SetString ( text, len / 2 );              nsAutoEditBatch beginBatching(this);              rv = InsertHTML(stuffToPaste);            }          }          else if (flavor.Equals(kUnicodeMime))          {            nsCOMPtr<nsISupportsWString> textDataObj ( do_QueryInterface(genericDataObj) );            if (textDataObj && len > 0)            {              PRUnichar* text = nsnull;              textDataObj->ToString ( &text );              stuffToPaste.SetString ( text, len / 2 );              nsAutoEditBatch beginBatching(this);              rv = InsertText(stuffToPaste);            }          }          else if (flavor.Equals(kJPEGImageMime))          {            // Insert Image code here            printf("Don't know how to insert an image yet!\n");            //nsIImage* image = (nsIImage *)data;            //NS_RELEASE(image);            rv = NS_ERROR_NOT_IMPLEMENTED; // for now give error code          }        }        nsCRT::free(bestFlavor);      }    }  }  return rv;}