Bug 1214377 - Hack to solve Thunderbird's need to detect style pre-wrap. r=roc a=rkent THUNDERBIRD_38_VERBRANCH
authorJorg K <mozilla@jorgk.com>
Fri, 06 Nov 2015 11:42:29 -0800
branchTHUNDERBIRD_38_VERBRANCH
changeset 261029 a0390f2afafd142ad6ebf85e4d5f1aed17cff57d
parent 261028 02840486a7a9e3580819ce0028efe0945967c258
child 261030 8cc8fa60f0f6c3fc8cdb31af8575e53069c90fe5
push id321
push userkent@caspia.com
push dateFri, 29 Apr 2016 21:03:17 +0000
treeherdermozilla-esr38@8cc8fa60f0f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, rkent
bugs1214377
milestone38.8.0esrpre
Bug 1214377 - Hack to solve Thunderbird's need to detect style pre-wrap. r=roc a=rkent
dom/base/nsDocumentEncoder.cpp
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -45,16 +45,17 @@
 #include "nsTArray.h"
 #include "nsIFrame.h"
 #include "nsStringBuffer.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/ShadowRoot.h"
 #include "mozilla/dom/EncodingUtils.h"
 #include "nsContainerFrame.h"
 #include "nsBlockFrame.h"
+#include "nsComputedDOMStyle.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 nsresult NS_NewDomSelection(nsISelection **aDomSelection);
 
 enum nsRangeIterationDirection {
   kDirectionOut = -1,
@@ -1425,42 +1426,51 @@ nsHTMLCopyEncoder::SetSelection(nsISelec
   // here that multi-range selections are table cell selections, in which case
   // the common parent is somewhere in the table and we don't really care where.
   nsresult rv = aSelection->GetRangeAt(0, getter_AddRefs(range));
   NS_ENSURE_SUCCESS(rv, rv);
   if (!range)
     return NS_ERROR_NULL_POINTER;
   range->GetCommonAncestorContainer(getter_AddRefs(commonParent));
 
-  // Thunderbird's msg compose code abuses the HTML copy encoder and gets
-  // confused if mIsTextWidget ends up becoming true, so for now we skip
-  // this logic in Thunderbird.
-#ifndef MOZ_THUNDERBIRD
   for (nsCOMPtr<nsIContent> selContent(do_QueryInterface(commonParent));
        selContent;
        selContent = selContent->GetParent())
   {
     // checking for selection inside a plaintext form widget
     nsIAtom *atom = selContent->Tag();
     if (atom == nsGkAtoms::input ||
         atom == nsGkAtoms::textarea)
     {
       mIsTextWidget = true;
       break;
     }
+#ifdef MOZ_THUNDERBIRD
+    else if (selContent->IsElement()) {
+      RefPtr<nsStyleContext> styleContext =
+        nsComputedDOMStyle::GetStyleContextForElementNoFlush(
+          selContent->AsElement(), nullptr, nullptr);
+      if (styleContext) {
+        const nsStyleText* textStyle = styleContext->StyleText();
+        if (textStyle->mWhiteSpace == NS_STYLE_WHITESPACE_PRE_WRAP) {
+          mIsTextWidget = true;
+        }
+      }
+    }
+    break;
+#endif
   }
 
   // normalize selection if we are not in a widget
   if (mIsTextWidget) 
   {
     mSelection = aSelection;
     mMimeType.AssignLiteral("text/plain");
     return NS_OK;
   }
-#endif
 
   // also consider ourselves in a text widget if we can't find an html document
   nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
   if (!(htmlDoc && mDocument->IsHTML())) {
     mIsTextWidget = true;
     mSelection = aSelection;
     // mMimeType is set to text/plain when encoding starts.
     return NS_OK;