diff --git a/mozilla/editor/libeditor/html/Makefile.in b/mozilla/editor/libeditor/html/Makefile.in index b245ac3f441..b8c159d71d4 100644 --- a/mozilla/editor/libeditor/html/Makefile.in +++ b/mozilla/editor/libeditor/html/Makefile.in @@ -41,8 +41,10 @@ REQUIRES = xpcom \ necko \ pref \ gfx \ + imglib2 \ widget \ view \ + exthandler \ $(NULL) # Building the full blown HTML Editor so add its source files and objects: diff --git a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp index 5b6f9c7b178..a344ed6abe8 100644 --- a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp @@ -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; @@ -280,7 +284,22 @@ nsHTMLEditor::InsertHTMLWithContext(const nsAString & aInputString, // create a dom document fragment that represents the structure to paste nsCOMPtr fragmentAsNode; PRInt32 rangeStartHint, rangeEndHint; - res = CreateDOMFragmentFromPaste(aInputString, aContextStr, aInfoStr, + + nsAutoString contextStr; + contextStr.Assign(aContextStr); + +#ifdef MOZ_THUNDERBIRD + // See Bug #228920 --> editor / parser has trouble inserting single cell data from Excel. + // The details are in the bug. Until we figure out why the parser is not building the right + // document structure for the single cell paste case, we can explicitly check for just such + // a condition and work around it. By setting the contextStr to an empty string we end up + // pasting just the cell text which is what we want anyway. + // A paste from an excel cell always starts with a new line, two spaces and then the td tag + if (StringBeginsWith(aInputString, NS_LITERAL_STRING("\n AddDataFlavor(kHTMLMime); (*aTransferable)->AddDataFlavor(kFileMime); - //(*aTransferable)->AddDataFlavor(kJPEGImageMime); + (*aTransferable)->AddDataFlavor(kJPEGImageMime); + (*aTransferable)->AddDataFlavor(kNativeImageMime); + } (*aTransferable)->AddDataFlavor(kUnicodeMime); } @@ -1393,14 +1414,62 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable } } } + else if (flavor.Equals(NS_LITERAL_STRING(kNativeImageMime))) + { + nsXPIDLString htmlstr; + nsAutoEditBatch beginBatching(this); + rv = InsertHTMLWithContext(htmlstr, nsString(), nsString(), 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 + + nsCOMPtr clipboardImage (do_QueryInterface(genericDataObj)); + if (clipboardImage) + { + // invoke image encoder + nsCOMPtr imgEncoder (do_CreateInstance("@mozilla.org/image/encoder;2?type=image/jpeg")); + if (imgEncoder) + { + nsCOMPtr clipboardImageFile; + rv = imgEncoder->EncodeClipboardImage(clipboardImage, getter_AddRefs(clipboardImageFile)); + + if (NS_FAILED(rv) || !clipboardImageFile) + return rv; + + nsCOMPtr uri; + rv = NS_NewFileURI(getter_AddRefs(uri), clipboardImageFile); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr fileURL(do_QueryInterface(uri)); + if (fileURL) + { + nsCAutoString urltext; + rv = fileURL->GetSpec(urltext); + if (NS_SUCCEEDED(rv) && !urltext.IsEmpty()) + { + stuffToPaste.Assign(NS_LITERAL_STRING("\"\"")); + nsAutoEditBatch beginBatching(this); + rv = InsertHTMLWithContext(stuffToPaste, + nsString(), nsString(), NS_LITERAL_STRING(kFileMime), + aSourceDoc, + aDestinationNode, aDestOffset, + aDoDeleteSelection); + } + } + + // XXX: For mail, it should be safe to move this temporary file onto the list of files to delete at shutdown. + // But that is not true for editor documents. Maybe we should leave the document around if pasting into an editor document? + + nsCOMPtr tempFileManager (do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID)); + if (tempFileManager) + tempFileManager->DeleteTemporaryFileOnExit(clipboardImageFile); + } + } } } nsCRT::free(bestFlavor); @@ -1913,7 +1982,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 flavorsList = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv); diff --git a/mozilla/editor/ui/dialogs/content/EdSpellCheck.js b/mozilla/editor/ui/dialogs/content/EdSpellCheck.js index 3c0bef8f482..6c3acd08a10 100644 --- a/mozilla/editor/ui/dialogs/content/EdSpellCheck.js +++ b/mozilla/editor/ui/dialogs/content/EdSpellCheck.js @@ -365,9 +365,11 @@ function IgnoreAll() NextWord(); } -function Replace() +function Replace(newWord) { - var newWord = gDialog.ReplaceWordInput.value; + if (!newWord) + return; + if (gMisspelledWord && gMisspelledWord != newWord) { var editor = GetCurrentEditor(); diff --git a/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul b/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul index 9f26ac7d80d..1e1576cb499 100644 --- a/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul +++ b/mozilla/editor/ui/dialogs/content/EdSpellCheck.xul @@ -76,13 +76,15 @@ - + -