diff --git a/mozilla/content/base/src/nsPlainTextSerializer.cpp b/mozilla/content/base/src/nsPlainTextSerializer.cpp index be972b3c7f7..80e9908bb63 100644 --- a/mozilla/content/base/src/nsPlainTextSerializer.cpp +++ b/mozilla/content/base/src/nsPlainTextSerializer.cpp @@ -89,6 +89,8 @@ nsPlainTextSerializer::nsPlainTextSerializer() mCiteQuoteLevel = 0; mStructs = PR_TRUE; // will be read from prefs later mHeaderStrategy = 1 /*indent increasingly*/; // ditto + mQuotesPreformatted = PR_FALSE; // ditto + mSpanLevel = 0; for (PRInt32 i = 0; i <= 6; i++) { mHeaderCounter[i] = 0; } @@ -178,6 +180,8 @@ nsPlainTextSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn, if (NS_SUCCEEDED(rv) && prefs) { prefs->GetBoolPref(PREF_STRUCTS, &mStructs); prefs->GetIntPref(PREF_HEADER_STRATEGY, &mHeaderStrategy); + // The quotesPreformatted pref is a temporary measure. See bug 69638. + prefs->GetBoolPref("editor.quotesPreformatted", &mQuotesPreformatted); } } @@ -594,6 +598,9 @@ nsPlainTextSerializer::DoOpenContainer(PRInt32 aTag) else if (type == eHTMLTag_dd) { mIndent += kIndentSizeDD; } + else if (type == eHTMLTag_span) { + ++mSpanLevel; + } // Else make sure we'll separate block level tags, // even if we're about to leave, before doing any other formatting. @@ -742,6 +749,10 @@ nsPlainTextSerializer::DoCloseContainer(PRInt32 aTag) else if (type == eHTMLTag_dd) { mIndent -= kIndentSizeDD; } + else if (type == eHTMLTag_span) { + --mSpanLevel; + } + else if (IsBlockLevel(aTag) && type != eHTMLTag_blockquote && type != eHTMLTag_script @@ -1356,9 +1367,8 @@ void nsPlainTextSerializer::Write(const nsAReadableString& aString) { #ifdef DEBUG_wrapping - char* foo = ToNewCString(aString); - printf("Write(%s): wrap col = %d\n", foo, mWrapColumn); - nsMemory::Free(foo); + printf("Write(%s): wrap col = %d\n", + NS_ConvertUCS2toUTF8(aString).get(), mWrapColumn); #endif PRInt32 bol = 0; @@ -1366,10 +1376,16 @@ nsPlainTextSerializer::Write(const nsAReadableString& aString) PRInt32 totLen = aString.Length(); + // If the string is empty, do nothing: + if (totLen <= 0) return; + // We have two major codepaths here. One that does preformatted text and one // that does normal formatted text. The one for preformatted text calls // Output directly while the other code path goes through AddToLine. - if ((mPreFormatted && !mWrapColumn) || IsInPre()) { + if ((mPreFormatted && !mWrapColumn) || IsInPre() + || (!mQuotesPreformatted && mSpanLevel > 0 + //&& Substring(aString, 0, 1) == NS_LITERAL_STRING(">"))) { + && aString.First() == PRUnichar('>'))) { // No intelligent wrapping. // This mustn't be mixed with intelligent wrapping without clearing diff --git a/mozilla/content/base/src/nsPlainTextSerializer.h b/mozilla/content/base/src/nsPlainTextSerializer.h index abb26122935..476f40de5a7 100644 --- a/mozilla/content/base/src/nsPlainTextSerializer.h +++ b/mozilla/content/base/src/nsPlainTextSerializer.h @@ -164,6 +164,11 @@ protected: // The width of the line as it will appear on the screen (approx.) PRUint32 mCurrentLineWidth; + // Treat quoted text as though it's preformatted -- don't wrap it. + // Having it on a pref is a temporary measure, See bug 69638. + PRInt32 mSpanLevel; + PRBool mQuotesPreformatted; + PRBool mDoFragment; PRInt32 mEmptyLines; // Will be the number of empty lines before // the current. 0 if we are starting a new diff --git a/mozilla/editor/base/nsHTMLDataTransfer.cpp b/mozilla/editor/base/nsHTMLDataTransfer.cpp index ad5c9bb98d4..7110973ec1f 100644 --- a/mozilla/editor/base/nsHTMLDataTransfer.cpp +++ b/mozilla/editor/base/nsHTMLDataTransfer.cpp @@ -237,6 +237,10 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAReadableString & res = CreateListOfNodesToPaste(fragmentAsNode, address_of(nodeList), rangeStartHint, rangeEndHint); NS_ENSURE_SUCCESS(res, res); + PRUint32 cc; + + nodeList->Count(&cc); + // are there any table elements in the list? // node and offset for insertion nsCOMPtr parentNode; @@ -370,6 +374,9 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAReadableString & nsCOMPtr isupports = dont_AddRef(nodeList->ElementAt(j)); nsCOMPtr curNode( do_QueryInterface(isupports) ); + nsString namestr; + curNode->GetNodeName(namestr); + NS_ENSURE_TRUE(curNode, NS_ERROR_FAILURE); NS_ENSURE_TRUE(curNode != fragmentAsNode, NS_ERROR_FAILURE); NS_ENSURE_TRUE(!nsTextEditUtils::IsBody(curNode), NS_ERROR_FAILURE); @@ -583,6 +590,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable PRUnichar* text = nsnull; textDataObj->ToString ( &text ); + nsAutoString debugDump (text); stuffToPaste.Assign ( text, len / 2 ); nsAutoEditBatch beginBatching(this); rv = InsertHTMLWithContext(stuffToPaste, aContextStr, aInfoStr); @@ -1306,6 +1314,14 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAReadableString & aQuotedText, nsIDOMNode **aNodeInserted) { nsresult rv; + + // The quotesPreformatted pref is a temporary measure. See bug 69638. + // Eventually we'll pick one way or the other. + PRBool quotesInPre; + nsCOMPtr prefs = do_GetService(kPrefServiceCID, &rv); + if (NS_SUCCEEDED(rv) && prefs) + rv = prefs->GetBoolPref("editor.quotesPreformatted", "esInPre); + nsCOMPtr preNode; // get selection nsCOMPtr selection; @@ -1326,7 +1342,12 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAReadableString & aQuotedText, if (!handled) { // Wrap the inserted quote in a
 so it won't be wrapped:
-      nsAutoString tag; tag.AssignWithConversion("pre");
+      nsAutoString tag;
+      if (quotesInPre)
+        tag.Assign(NS_LITERAL_STRING("pre"));
+      else
+        tag.Assign(NS_LITERAL_STRING("span"));
+
       rv = DeleteSelectionAndCreateNode(tag, getter_AddRefs(preNode));
       
       // If this succeeded, then set selection inside the pre
@@ -1566,6 +1587,11 @@ nsresult nsHTMLEditor::CreateListOfNodesToPaste(nsIDOMNode  *aFragmentAsNode,
   res = docFragRange->SetEnd(endParent, endOffset);
   NS_ENSURE_SUCCESS(res, res);
 
+  nsAutoString str;
+  docFragRange->ToString(str);
+  nsCOMPtr root = do_QueryInterface(aFragmentAsNode);
+  if (root)  root->List(stdout);
+
   // now use a subtree iterator over the range to create a list of nodes
   nsTrivialFunctor functor;
   nsDOMSubtreeIterator iter;
diff --git a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp
index ad5c9bb98d4..7110973ec1f 100644
--- a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -237,6 +237,10 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAReadableString &
   res = CreateListOfNodesToPaste(fragmentAsNode, address_of(nodeList), rangeStartHint, rangeEndHint);
   NS_ENSURE_SUCCESS(res, res);
   
+  PRUint32 cc;
+
+  nodeList->Count(&cc);
+  
   // are there any table elements in the list?  
   // node and offset for insertion
   nsCOMPtr parentNode;
@@ -370,6 +374,9 @@ nsresult nsHTMLEditor::InsertHTMLWithCharsetAndContext(const nsAReadableString &
       nsCOMPtr isupports = dont_AddRef(nodeList->ElementAt(j));
       nsCOMPtr curNode( do_QueryInterface(isupports) );
 
+      nsString namestr;
+      curNode->GetNodeName(namestr);
+
       NS_ENSURE_TRUE(curNode, NS_ERROR_FAILURE);
       NS_ENSURE_TRUE(curNode != fragmentAsNode, NS_ERROR_FAILURE);
       NS_ENSURE_TRUE(!nsTextEditUtils::IsBody(curNode), NS_ERROR_FAILURE);
@@ -583,6 +590,7 @@ NS_IMETHODIMP nsHTMLEditor::InsertFromTransferable(nsITransferable *transferable
         PRUnichar* text = nsnull;
 
         textDataObj->ToString ( &text );
+        nsAutoString debugDump (text);
         stuffToPaste.Assign ( text, len / 2 );
         nsAutoEditBatch beginBatching(this);
         rv = InsertHTMLWithContext(stuffToPaste, aContextStr, aInfoStr);
@@ -1306,6 +1314,14 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAReadableString & aQuotedText,
                                          nsIDOMNode **aNodeInserted)
 {
   nsresult rv;
+
+  // The quotesPreformatted pref is a temporary measure. See bug 69638.
+  // Eventually we'll pick one way or the other.
+  PRBool quotesInPre;
+  nsCOMPtr prefs = do_GetService(kPrefServiceCID, &rv);
+  if (NS_SUCCEEDED(rv) && prefs)
+    rv = prefs->GetBoolPref("editor.quotesPreformatted", "esInPre);
+
   nsCOMPtr preNode;
   // get selection
   nsCOMPtr selection;
@@ -1326,7 +1342,12 @@ nsHTMLEditor::InsertAsPlaintextQuotation(const nsAReadableString & aQuotedText,
     if (!handled)
     {
       // Wrap the inserted quote in a 
 so it won't be wrapped:
-      nsAutoString tag; tag.AssignWithConversion("pre");
+      nsAutoString tag;
+      if (quotesInPre)
+        tag.Assign(NS_LITERAL_STRING("pre"));
+      else
+        tag.Assign(NS_LITERAL_STRING("span"));
+
       rv = DeleteSelectionAndCreateNode(tag, getter_AddRefs(preNode));
       
       // If this succeeded, then set selection inside the pre
@@ -1566,6 +1587,11 @@ nsresult nsHTMLEditor::CreateListOfNodesToPaste(nsIDOMNode  *aFragmentAsNode,
   res = docFragRange->SetEnd(endParent, endOffset);
   NS_ENSURE_SUCCESS(res, res);
 
+  nsAutoString str;
+  docFragRange->ToString(str);
+  nsCOMPtr root = do_QueryInterface(aFragmentAsNode);
+  if (root)  root->List(stdout);
+
   // now use a subtree iterator over the range to create a list of nodes
   nsTrivialFunctor functor;
   nsDOMSubtreeIterator iter;
diff --git a/mozilla/editor/ui/composer.js b/mozilla/editor/ui/composer.js
index 7e025533f36..4d7c5c54a92 100644
--- a/mozilla/editor/ui/composer.js
+++ b/mozilla/editor/ui/composer.js
@@ -57,3 +57,5 @@ pref("editor.image_editor",                 "");
 pref("editor.singleLine.pasteNewlines",     1);
 
 pref("editor.history.url_maximum", 10);
+
+pref("editor.quotesPreformatted",            false);
diff --git a/mozilla/modules/libpref/src/init/editor.js b/mozilla/modules/libpref/src/init/editor.js
index 7e025533f36..4d7c5c54a92 100644
--- a/mozilla/modules/libpref/src/init/editor.js
+++ b/mozilla/modules/libpref/src/init/editor.js
@@ -57,3 +57,5 @@ pref("editor.image_editor",                 "");
 pref("editor.singleLine.pasteNewlines",     1);
 
 pref("editor.history.url_maximum", 10);
+
+pref("editor.quotesPreformatted",            false);