Bug 1565129 - Re-introduce plain_text.wrap_long_lines. r=bzbarsky
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 11 Jul 2019 18:49:50 +0000
changeset 482454 16bc2f5a8e199244beca4c28b93c0084e333d323
parent 482453 fa44f47160b2371069652b9ae763345d811bce32
child 482455 0b12da4fd972de938c80cd40712ceaee9dfd81c4
push id36282
push userdvarga@mozilla.com
push dateFri, 12 Jul 2019 09:56:21 +0000
treeherdermozilla-central@cb2d564879e3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1565129, 1514655, 1260720
milestone70.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 1565129 - Re-introduce plain_text.wrap_long_lines. r=bzbarsky Looks like some users use it, and it's not too much effort to support. This is somewhat simpler, and IMO better than what existed before bug 1514655 because: * It doesn't regress bidi rendering when the pref is disabled (before, the pref would prevent plaintext.css from applying altogether). * It's consistent with the way view-source docs work. * It doesn't use non-standard stylesheet APIs to toggle the stylesheet (bug 1260720). Differential Revision: https://phabricator.services.mozilla.com/D37742
layout/reftests/bugs/1565129.txt
layout/reftests/bugs/reftest.list
layout/style/res/plaintext.css
modules/libpref/init/StaticPrefList.h
parser/html/nsHtml5PlainTextUtils.cpp
parser/html/nsHtml5PlainTextUtils.h
parser/html/nsHtml5TreeBuilderCppSupplement.h
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/1565129.txt
@@ -0,0 +1,1 @@
+Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text. Some very very long text.
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -2109,8 +2109,9 @@ fuzzy-if(!webrender,0-6,0-34) fuzzy-if(g
 skip-if(!asyncPan) == 1544895.html 1544895-ref.html
 == 1548809.html 1548809-ref.html
 != 1552789-1.html 1552789-ref-1.html
 == 1558937-1.html 1558937-1-ref.html
 != 1563484.html 1563484-notref.html
 == 1563484.html 1563484-ref.html
 fuzzy-if(!webrender||!winWidget,254-255,464-1613) fuzzy-if(geckoview&&webrender,253-253,1397-1397) == 1562733-rotated-nastaliq-1.html 1562733-rotated-nastaliq-1-ref.html
 == 1562733-rotated-nastaliq-2.html 1562733-rotated-nastaliq-2-ref.html
+test-pref(plain_text.wrap_long_lines,false) != 1565129.txt 1565129.txt
--- a/layout/style/res/plaintext.css
+++ b/layout/style/res/plaintext.css
@@ -3,16 +3,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 pre {
   white-space: pre-wrap;
   word-wrap: break-word;
   -moz-control-character-visibility: visible;
 }
 
+.nowrap pre {
+  white-space: pre;
+}
+
 /* Make text go with the rules of dir=auto, but allow it to be overriden if 'Switch Text Direction' is triggered */
 html:not([dir]) pre { /* Not a UA sheet, so doesn't use :-moz-has-dir-attr */
   unicode-bidi: plaintext;
 }
 
 /* NOTE(emilio): For some reason some pages, mainly bing.com, load a bunch of
  * scripts in zero-size <object> elements, see bug 1548449.
  *
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -6974,16 +6974,28 @@ VARCACHE_PREF(
 VARCACHE_PREF(
   Live,
   "nglayout.debug.widget_update_flashing",
    nglayout_debug_widget_update_flashing,
   RelaxedAtomicBool, false
 )
 
 //---------------------------------------------------------------------------
+// Prefs starting with "plain_text."
+//---------------------------------------------------------------------------
+
+// When false, text in plaintext documents does not wrap long lines.
+VARCACHE_PREF(
+  Live,
+  "plain_text.wrap_long_lines",
+  plain_text_wrap_long_lines,
+  bool, true
+)
+
+//---------------------------------------------------------------------------
 // Prefs starting with "plugins."
 //---------------------------------------------------------------------------
 
 VARCACHE_PREF(
   Live,
   "plugins.flashBlock.enabled",
   plugins_flashBlock_enabled,
   bool, false
--- a/parser/html/nsHtml5PlainTextUtils.cpp
+++ b/parser/html/nsHtml5PlainTextUtils.cpp
@@ -1,22 +1,33 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsHtml5PlainTextUtils.h"
-#include "mozilla/Preferences.h"
+#include "mozilla/StaticPrefs.h"
 #include "nsHtml5AttributeName.h"
 #include "nsHtml5Portability.h"
 #include "nsHtml5String.h"
-#include "nsIServiceManager.h"
-#include "nsIStringBundle.h"
+#include "nsGkAtoms.h"
 
 // static
 nsHtml5HtmlAttributes* nsHtml5PlainTextUtils::NewLinkAttributes() {
   nsHtml5HtmlAttributes* linkAttrs = new nsHtml5HtmlAttributes(0);
   nsHtml5String rel = nsHtml5Portability::newStringFromLiteral("stylesheet");
   linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_REL, rel, -1);
   nsHtml5String href = nsHtml5Portability::newStringFromLiteral(
       "resource://content-accessible/plaintext.css");
   linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href, -1);
   return linkAttrs;
 }
+
+// static
+nsHtml5HtmlAttributes* nsHtml5PlainTextUtils::NewBodyAttributes() {
+  if (mozilla::StaticPrefs::plain_text_wrap_long_lines()) {
+    return nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES;
+  }
+  nsHtml5HtmlAttributes* bodyAttrs = new nsHtml5HtmlAttributes(0);
+  RefPtr<nsAtom> nowrap = nsGkAtoms::nowrap;
+  bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_CLASS,
+                          nsHtml5String::FromAtom(nowrap.forget()), -1);
+  return bodyAttrs;
+}
--- a/parser/html/nsHtml5PlainTextUtils.h
+++ b/parser/html/nsHtml5PlainTextUtils.h
@@ -5,11 +5,12 @@
 #ifndef nsHtml5PlainTextUtils_h
 #define nsHtml5PlainTextUtils_h
 
 #include "nsHtml5HtmlAttributes.h"
 
 class nsHtml5PlainTextUtils {
  public:
   static nsHtml5HtmlAttributes* NewLinkAttributes();
+  static nsHtml5HtmlAttributes* NewBodyAttributes();
 };
 
 #endif  // nsHtml5PlainTextUtils_h
--- a/parser/html/nsHtml5TreeBuilderCppSupplement.h
+++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h
@@ -1271,16 +1271,19 @@ void nsHtml5TreeBuilder::StartPlainTextV
   StartPlainTextBody();
 }
 
 void nsHtml5TreeBuilder::StartPlainText() {
   MOZ_ASSERT(!mBuilder, "Must not view source with builder.");
   startTag(nsHtml5ElementName::ELT_LINK,
            nsHtml5PlainTextUtils::NewLinkAttributes(), false);
 
+  startTag(nsHtml5ElementName::ELT_BODY,
+           nsHtml5PlainTextUtils::NewBodyAttributes(), false);
+
   StartPlainTextBody();
 }
 
 void nsHtml5TreeBuilder::StartPlainTextBody() {
   MOZ_ASSERT(!mBuilder, "Must not view source with builder.");
   startTag(nsHtml5ElementName::ELT_PRE, nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES,
            false);
   needToDropLF = false;