Bug 292607 Dragging preformatted text collapses whitespace r+sr=bz a=pavlov

This commit is contained in:
neil@parkwaycc.co.uk 2007-09-28 03:28:28 -07:00
parent 8df40619da
commit 6c63075bbf

View File

@ -98,6 +98,9 @@
#include "nsISelectionController.h"
#include "nsFrameSelection.h"
#include "nsIDOMEventTarget.h"
#include "nsWidgetsCID.h"
static NS_DEFINE_CID(kHTMLConverterCID, NS_HTMLFORMATCONVERTER_CID);
// private clipboard data flavors for html copy, used by editor when pasting
#define kHTMLContext "text/_moz_htmlcontext"
@ -137,11 +140,8 @@ private:
static void GetSelectedLink(nsISelection* inSelection,
nsIDOMNode **outLinkNode);
enum serializationMode {serializeAsText, serializeAsHTML};
// if inNode is null, use the selection from the window
static nsresult SerializeNodeOrSelection(serializationMode inMode,
PRUint32 inFlags,
nsIDOMWindow* inWindow,
static nsresult SerializeNodeOrSelection(nsIDOMWindow* inWindow,
nsIDOMNode* inNode,
nsAString& outResultString,
nsAString& outHTMLContext,
@ -1338,16 +1338,24 @@ nsTransferableFactory::Produce(PRBool* aDragSelection,
nodeToSerialize = nsnull;
}
SerializeNodeOrSelection(serializeAsHTML,
nsIDocumentEncoder::OutputAbsoluteLinks |
nsIDocumentEncoder::OutputEncodeW3CEntities,
window, nodeToSerialize,
SerializeNodeOrSelection(window, nodeToSerialize,
mHtmlString, mContextString, mInfoString);
nsAutoString dummy1, dummy2;
SerializeNodeOrSelection(serializeAsText, 0,
window, nodeToSerialize,
mTitleString, dummy1, dummy2);
nsCOMPtr<nsIFormatConverter> htmlConverter =
do_CreateInstance(kHTMLConverterCID);
NS_ENSURE_TRUE(htmlConverter, NS_ERROR_FAILURE);
nsCOMPtr<nsISupportsString> html =
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
NS_ENSURE_TRUE(html, NS_ERROR_FAILURE);
html->SetData(mHtmlString);
nsCOMPtr<nsISupportsString> text;
PRUint32 textLen;
htmlConverter->Convert(kHTMLMime, html, mHtmlString.Length() * 2,
kUnicodeMime, getter_AddRefs(text), &textLen);
NS_ENSURE_TRUE(text, NS_ERROR_FAILURE);
text->GetData(mTitleString);
#ifdef CHANGE_SELECTION_ON_DRAG
// We used to change the selection to wrap the dragged node (mainly
@ -1688,9 +1696,7 @@ void nsTransferableFactory::GetSelectedLink(nsISelection* inSelection,
// static
nsresult
nsTransferableFactory::SerializeNodeOrSelection(serializationMode inMode,
PRUint32 inFlags,
nsIDOMWindow* inWindow,
nsTransferableFactory::SerializeNodeOrSelection(nsIDOMWindow* inWindow,
nsIDOMNode* inNode,
nsAString& outResultString,
nsAString& outContext,
@ -1699,22 +1705,16 @@ nsTransferableFactory::SerializeNodeOrSelection(serializationMode inMode,
NS_ENSURE_ARG_POINTER(inWindow);
nsresult rv;
nsCOMPtr<nsIDocumentEncoder> encoder;
static const char *textplain = "text/plain";
if (inMode == serializeAsText) {
nsCAutoString formatType(NS_DOC_ENCODER_CONTRACTID_BASE);
formatType.Append(textplain);
encoder = do_CreateInstance(formatType.get(), &rv);
} else {
encoder = do_CreateInstance(NS_HTMLCOPY_ENCODER_CONTRACTID, &rv);
}
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocumentEncoder> encoder =
do_CreateInstance(NS_HTMLCOPY_ENCODER_CONTRACTID);
NS_ENSURE_TRUE(encoder, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMDocument> domDoc;
inWindow->GetDocument(getter_AddRefs(domDoc));
NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE);
PRUint32 flags = nsIDocumentEncoder::OutputAbsoluteLinks |
nsIDocumentEncoder::OutputEncodeW3CEntities;
nsCOMPtr<nsIDOMRange> range;
nsCOMPtr<nsISelection> selection;
if (inNode) {
@ -1725,14 +1725,10 @@ nsTransferableFactory::SerializeNodeOrSelection(serializationMode inMode,
NS_ENSURE_SUCCESS(rv, rv);
} else {
inWindow->GetSelection(getter_AddRefs(selection));
inFlags |= nsIDocumentEncoder::OutputSelectionOnly;
flags |= nsIDocumentEncoder::OutputSelectionOnly;
}
if (inMode == serializeAsText) {
rv = encoder->Init(domDoc, NS_ConvertASCIItoUTF16(textplain), inFlags);
} else {
rv = encoder->Init(domDoc, NS_LITERAL_STRING(kHTMLMime), inFlags);
}
rv = encoder->Init(domDoc, NS_LITERAL_STRING(kHTMLMime), flags);
NS_ENSURE_SUCCESS(rv, rv);
if (range) {
@ -1741,12 +1737,6 @@ nsTransferableFactory::SerializeNodeOrSelection(serializationMode inMode,
encoder->SetSelection(selection);
}
if (inMode == serializeAsText) {
outContext.Truncate();
outInfo.Truncate();
return encoder->EncodeToString(outResultString);
}
return encoder->EncodeToStringWithContext(outContext, outInfo,
outResultString);
}