Bug 1225864 - New flag OutputDisallowLineBreaking to disallow line breaking. r=masayuki.
authorJorg K <mozilla@jorgk.com>
Fri, 27 Nov 2015 15:27:00 +0100
changeset 309062 ca8916bb80cfab16fae905b624632d849ca4f094
parent 309061 0e3af3ef46f0d54bd937fb1c8b0627f16848a6b7
child 309063 f1c08ce11d245c054bd265b2faca3e83e6587772
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1225864
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1225864 - New flag OutputDisallowLineBreaking to disallow line breaking. r=masayuki.
dom/base/nsIDocumentEncoder.idl
dom/base/nsPlainTextSerializer.cpp
dom/base/nsPlainTextSerializer.h
dom/base/nsXMLContentSerializer.cpp
dom/base/nsXMLContentSerializer.h
--- a/dom/base/nsIDocumentEncoder.idl
+++ b/dom/base/nsIDocumentEncoder.idl
@@ -30,17 +30,17 @@ interface nsIDocumentEncoderNodeFixup : 
    * @param [OUT] aSerializeCloneKids True if the document encoder should
    * apply recursive serialization to the children of the fixed up node
    * instead of the children of the original node.
    * @return The resulting fixed up node.
    */
   nsIDOMNode fixupNode(in nsIDOMNode aNode, out boolean aSerializeCloneKids);
 };
 
-[scriptable, uuid(e5ec69d7-eaa7-4de7-986b-455e17c7f71a)]
+[scriptable, uuid(21f112df-d96f-47da-bfcb-5331273003d1)]
 interface nsIDocumentEncoder : nsISupports
 {
   // Output methods flag bits. There are a frightening number of these,
   // because everyone wants something a little bit different
    
 
   /** 
    * Output only the selection (as opposed to the whole document).
@@ -236,16 +236,23 @@ interface nsIDocumentEncoder : nsISuppor
 
   /**
    * Include ruby annotations and ruby parentheses in the output.
    * PlainText output only.
    */
   const unsigned long OutputRubyAnnotation = (1 << 26);
 
   /**
+   * Disallow breaking of long character strings. This is important
+   * for serializing e-mail which contains CJK strings. These must
+   * not be broken just as "normal" longs strings aren't broken.
+   */
+  const unsigned long OutputDisallowLineBreaking = (1 << 27);
+
+  /**
    * Initialize with a pointer to the document and the mime type.
    * @param aDocument Document to encode.
    * @param aMimeType MimeType to use. May also be set by SetMimeType.
    * @param aFlags Flags to use while encoding. May also be set by SetFlags.
    */
   void init(in nsIDOMDocument aDocument,
             in AString aMimeType,
             in unsigned long aFlags);
--- a/dom/base/nsPlainTextSerializer.cpp
+++ b/dom/base/nsPlainTextSerializer.cpp
@@ -139,17 +139,17 @@ nsPlainTextSerializer::Init(uint32_t aFl
                  "Can't do formatted and preformatted output at the same time!");
   }
 #endif
 
   mFlags = aFlags;
   mWrapColumn = aWrapColumn;
 
   // Only create a linebreaker if we will handle wrapping.
-  if (MayWrap()) {
+  if (MayWrap() && MayBreakLines()) {
     mLineBreaker = nsContentUtils::LineBreaker();
   }
 
   // Set the line break character:
   if ((mFlags & nsIDocumentEncoder::OutputCRLineBreak)
       && (mFlags & nsIDocumentEncoder::OutputLFLineBreak)) {
     // Windows
     mLineBreak.AssignLiteral("\r\n");
--- a/dom/base/nsPlainTextSerializer.h
+++ b/dom/base/nsPlainTextSerializer.h
@@ -96,16 +96,20 @@ private:
 
   // Inlined functions
   inline bool MayWrap()
   {
     return mWrapColumn &&
       ((mFlags & nsIDocumentEncoder::OutputFormatted) ||
        (mFlags & nsIDocumentEncoder::OutputWrap));
   }
+  inline bool MayBreakLines()
+  {
+    return !(mFlags & nsIDocumentEncoder::OutputDisallowLineBreaking);
+  }
 
   inline bool DoOutput()
   {
     return mHeadLevel == 0;
   }
 
   // Stack handling functions
   bool GetLastBool(const nsTArray<bool>& aStack);
--- a/dom/base/nsXMLContentSerializer.cpp
+++ b/dom/base/nsXMLContentSerializer.cpp
@@ -107,16 +107,18 @@ nsXMLContentSerializer::Init(uint32_t aF
   }
 
   mDoRaw = !!(mFlags & nsIDocumentEncoder::OutputRaw);
 
   mDoFormat = (mFlags & nsIDocumentEncoder::OutputFormatted && !mDoRaw);
 
   mDoWrap = (mFlags & nsIDocumentEncoder::OutputWrap && !mDoRaw);
 
+  mAllowLineBreaking = !(mFlags & nsIDocumentEncoder::OutputDisallowLineBreaking);
+
   if (!aWrapColumn) {
     mMaxColumn = 72;
   }
   else {
     mMaxColumn = aWrapColumn;
   }
 
   mPreLevel = 0;
@@ -1534,33 +1536,35 @@ nsXMLContentSerializer::AppendWrapped_No
         aPos = aSequenceStart;
         thisSequenceStartsAtBeginningOfLine = true;
         onceAgainBecauseWeAddedBreakInFront = true;
       }
       else {
         // we must wrap
         onceAgainBecauseWeAddedBreakInFront = false;
         bool foundWrapPosition = false;
-        int32_t wrapPosition;
-
-        nsILineBreaker *lineBreaker = nsContentUtils::LineBreaker();
+        int32_t wrapPosition = 0;
 
-        wrapPosition = lineBreaker->Prev(aSequenceStart,
-                                         (aEnd - aSequenceStart),
-                                         (aPos - aSequenceStart) + 1);
-        if (wrapPosition != NS_LINEBREAKER_NEED_MORE_TEXT) {
-          foundWrapPosition = true;
-        }
-        else {
-          wrapPosition = lineBreaker->Next(aSequenceStart,
+        if (mAllowLineBreaking) {
+          nsILineBreaker *lineBreaker = nsContentUtils::LineBreaker();
+
+          wrapPosition = lineBreaker->Prev(aSequenceStart,
                                            (aEnd - aSequenceStart),
-                                           (aPos - aSequenceStart));
+                                           (aPos - aSequenceStart) + 1);
           if (wrapPosition != NS_LINEBREAKER_NEED_MORE_TEXT) {
             foundWrapPosition = true;
           }
+          else {
+            wrapPosition = lineBreaker->Next(aSequenceStart,
+                                             (aEnd - aSequenceStart),
+                                             (aPos - aSequenceStart));
+            if (wrapPosition != NS_LINEBREAKER_NEED_MORE_TEXT) {
+              foundWrapPosition = true;
+            }
+          }
         }
 
         if (foundWrapPosition) {
           if (!mColPos && mDoFormat) {
             NS_ENSURE_TRUE(AppendIndentation(aOutputStr), false);
           }
           else if (mAddSpace) {
             bool result = aOutputStr.Append(char16_t(' '), mozilla::fallible);
--- a/dom/base/nsXMLContentSerializer.h
+++ b/dom/base/nsXMLContentSerializer.h
@@ -350,16 +350,19 @@ class nsXMLContentSerializer : public ns
 
   // true = no formatting,(OutputRaw flag)
   // no newline convertion and no rewrap long lines even if OutputWrap is set.
   bool mDoRaw;
 
   // true = wrapping should be done (OutputWrap flag)
   bool mDoWrap;
 
+  // true = we can break lines (OutputDisallowLineBreaking flag)
+  bool mAllowLineBreaking;
+
   // number of maximum column in a line, in the wrap mode
   uint32_t   mMaxColumn;
 
   // current indent value
   nsString   mIndent;
 
   // this is the indentation level after the indentation reached
   // the maximum length of indentation