Bug #223909 --> Land the aviary 1.0 changes for supporting copy and paste of windows clipboard images into HTML mail

compose onto the 1.8 branch. Changes were re-reviewed for 1.8 by various folks including module owners: stuart, biesi, glazman

a=asa


git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@179004 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
scott%scott-macgregor.org
2005-08-25 22:35:49 +00:00
parent 964be8bea4
commit 2ee2592948
14 changed files with 935 additions and 23 deletions

View File

@@ -130,6 +130,10 @@
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIContentFilter.h"
#include "imgIEncoder.h"
#include "nsIExternalHelperAppService.h"
#include "nsCExternalHandlerService.h"
const PRUnichar nbsp = 160;
@@ -1143,7 +1147,11 @@ NS_IMETHODIMP nsHTMLEditor::PrepareHTMLTransferable(nsITransferable **aTransfera
}
(*aTransferable)->AddDataFlavor(kHTMLMime);
(*aTransferable)->AddDataFlavor(kFileMime);
//(*aTransferable)->AddDataFlavor(kJPEGImageMime);
#ifdef XP_WIN32
// we only support copy and paste of clipboard images on Windows
(*aTransferable)->AddDataFlavor(kJPEGImageMime);
(*aTransferable)->AddDataFlavor(kNativeImageMime);
#endif
}
(*aTransferable)->AddDataFlavor(kUnicodeMime);
}
@@ -1407,14 +1415,58 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
}
}
}
else if (flavor.Equals(NS_LITERAL_STRING(kNativeImageMime)))
{
nsXPIDLString htmlstr;
nsAutoEditBatch beginBatching(this);
rv = InsertHTMLWithContext(htmlstr, EmptyString(), EmptyString(), flavor, aSourceDoc, aDestinationNode, aDestOffset, aDoDeleteSelection);
}
else if (0 == nsCRT::strcmp(bestFlavor, kJPEGImageMime))
{
// need to provide a hook from here
// 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
// Insert Image code
nsCOMPtr<nsIClipboardImage> clipboardImage (do_QueryInterface(genericDataObj));
if (clipboardImage)
{
// invoke image encoder
nsCOMPtr<imgIEncoder> imgEncoder (do_CreateInstance("@mozilla.org/image/encoder;2?type=image/jpeg"));
if (imgEncoder)
{
nsCOMPtr<nsIFile> clipboardImageFile;
rv = imgEncoder->EncodeClipboardImage(clipboardImage, getter_AddRefs(clipboardImageFile));
if (NS_FAILED(rv) || !clipboardImageFile)
return rv;
nsCOMPtr<nsIURI> uri;
rv = NS_NewFileURI(getter_AddRefs(uri), clipboardImageFile);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIURL> fileURL(do_QueryInterface(uri));
if (fileURL)
{
nsCAutoString urltext;
rv = fileURL->GetSpec(urltext);
if (NS_SUCCEEDED(rv) && !urltext.IsEmpty())
{
stuffToPaste.AssignLiteral("<IMG src=\"");
AppendUTF8toUTF16(urltext, stuffToPaste);
stuffToPaste.AppendLiteral("\" alt=\"\" >");
nsAutoEditBatch beginBatching(this);
rv = InsertHTMLWithContext(stuffToPaste,
nsString(), nsString(), NS_LITERAL_STRING(kFileMime),
aSourceDoc,
aDestinationNode, aDestOffset,
aDoDeleteSelection);
}
}
nsCOMPtr<nsPIExternalAppLauncher> tempFileManager (do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID));
if (tempFileManager)
tempFileManager->DeleteTemporaryFileOnExit(clipboardImageFile);
}
else
rv = NS_ERROR_NOT_IMPLEMENTED; // for now give error code, we don't know how to handle the image format from the clipboard
}
}
}
nsCRT::free(bestFlavor);
@@ -1927,7 +1979,7 @@ NS_IMETHODIMP nsHTMLEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste)
// the flavors that we can deal with
const char* const textEditorFlavors[] = { kUnicodeMime, nsnull };
const char* const htmlEditorFlavors[] = { kHTMLMime, kJPEGImageMime, nsnull };
const char* const htmlEditorFlavors[] = { kHTMLMime, kJPEGImageMime, kNativeImageMime, nsnull };
nsCOMPtr<nsISupportsArray> flavorsList =
do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);