From f75dd725f54060ad3ccc4611392566f1fef7d761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 11 Jul 2019 16:32:08 +0000 Subject: [PATCH] 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 --HG-- extra : moz-landing-system : lando --- layout/reftests/bugs/1565129.txt | 1 + layout/reftests/bugs/reftest.list | 1 + layout/style/res/plaintext.css | 4 ++++ modules/libpref/init/StaticPrefList.h | 12 ++++++++++++ parser/html/nsHtml5PlainTextUtils.cpp | 16 +++++++++++++--- parser/html/nsHtml5PlainTextUtils.h | 1 + parser/html/nsHtml5TreeBuilderCppSupplement.h | 3 +++ 7 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 layout/reftests/bugs/1565129.txt diff --git a/layout/reftests/bugs/1565129.txt b/layout/reftests/bugs/1565129.txt new file mode 100644 index 000000000000..189370daa9ae --- /dev/null +++ b/layout/reftests/bugs/1565129.txt @@ -0,0 +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. diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list index 422406c58efa..3b021d42bea9 100644 --- a/layout/reftests/bugs/reftest.list +++ b/layout/reftests/bugs/reftest.list @@ -2114,3 +2114,4 @@ skip-if(!asyncPan) == 1544895.html 1544895-ref.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 diff --git a/layout/style/res/plaintext.css b/layout/style/res/plaintext.css index 02f97c093145..28d0462ed8b9 100644 --- a/layout/style/res/plaintext.css +++ b/layout/style/res/plaintext.css @@ -8,6 +8,10 @@ pre { -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; diff --git a/modules/libpref/init/StaticPrefList.h b/modules/libpref/init/StaticPrefList.h index 9089d4189c34..8c5e4f047051 100644 --- a/modules/libpref/init/StaticPrefList.h +++ b/modules/libpref/init/StaticPrefList.h @@ -6978,6 +6978,18 @@ VARCACHE_PREF( 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." //--------------------------------------------------------------------------- diff --git a/parser/html/nsHtml5PlainTextUtils.cpp b/parser/html/nsHtml5PlainTextUtils.cpp index dda17d25e4c9..0b240e4c3175 100644 --- a/parser/html/nsHtml5PlainTextUtils.cpp +++ b/parser/html/nsHtml5PlainTextUtils.cpp @@ -3,12 +3,11 @@ * 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() { @@ -20,3 +19,14 @@ nsHtml5HtmlAttributes* nsHtml5PlainTextUtils::NewLinkAttributes() { linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href, -1); return linkAttrs; } + +// static +nsHtml5HtmlAttributes* nsHtml5PlainTextUtils::NewBodyAttributes() { + nsHtml5HtmlAttributes* bodyAttrs = new nsHtml5HtmlAttributes(0); + if (!mozilla::StaticPrefs::plain_text_wrap_long_lines()) { + RefPtr nowrap = nsGkAtoms::nowrap; + bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_CLASS, + nsHtml5String::FromAtom(nowrap.forget()), -1); + } + return bodyAttrs; +} diff --git a/parser/html/nsHtml5PlainTextUtils.h b/parser/html/nsHtml5PlainTextUtils.h index e57f683a6250..a56a8fc81a86 100644 --- a/parser/html/nsHtml5PlainTextUtils.h +++ b/parser/html/nsHtml5PlainTextUtils.h @@ -10,6 +10,7 @@ class nsHtml5PlainTextUtils { public: static nsHtml5HtmlAttributes* NewLinkAttributes(); + static nsHtml5HtmlAttributes* NewBodyAttributes(); }; #endif // nsHtml5PlainTextUtils_h diff --git a/parser/html/nsHtml5TreeBuilderCppSupplement.h b/parser/html/nsHtml5TreeBuilderCppSupplement.h index 3e48d984e5d5..68ce4f8c8e95 100644 --- a/parser/html/nsHtml5TreeBuilderCppSupplement.h +++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h @@ -1276,6 +1276,9 @@ void nsHtml5TreeBuilder::StartPlainText() { startTag(nsHtml5ElementName::ELT_LINK, nsHtml5PlainTextUtils::NewLinkAttributes(), false); + startTag(nsHtml5ElementName::ELT_BODY, + nsHtml5PlainTextUtils::NewBodyAttributes(), false); + StartPlainTextBody(); }