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
This commit is contained in:
Emilio Cobos Álvarez 2019-07-11 16:32:08 +00:00
Родитель 12a1dd4faf
Коммит f75dd725f5
7 изменённых файлов: 35 добавлений и 3 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -2114,3 +2114,4 @@ skip-if(!asyncPan) == 1544895.html 1544895-ref.html
== 1563484.html 1563484-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 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 == 1562733-rotated-nastaliq-2.html 1562733-rotated-nastaliq-2-ref.html
test-pref(plain_text.wrap_long_lines,false) != 1565129.txt 1565129.txt

Просмотреть файл

@ -8,6 +8,10 @@ pre {
-moz-control-character-visibility: visible; -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 */ /* 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 */ html:not([dir]) pre { /* Not a UA sheet, so doesn't use :-moz-has-dir-attr */
unicode-bidi: plaintext; unicode-bidi: plaintext;

Просмотреть файл

@ -6978,6 +6978,18 @@ VARCACHE_PREF(
RelaxedAtomicBool, false 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." // Prefs starting with "plugins."
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

Просмотреть файл

@ -3,12 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsHtml5PlainTextUtils.h" #include "nsHtml5PlainTextUtils.h"
#include "mozilla/Preferences.h" #include "mozilla/StaticPrefs.h"
#include "nsHtml5AttributeName.h" #include "nsHtml5AttributeName.h"
#include "nsHtml5Portability.h" #include "nsHtml5Portability.h"
#include "nsHtml5String.h" #include "nsHtml5String.h"
#include "nsIServiceManager.h" #include "nsGkAtoms.h"
#include "nsIStringBundle.h"
// static // static
nsHtml5HtmlAttributes* nsHtml5PlainTextUtils::NewLinkAttributes() { nsHtml5HtmlAttributes* nsHtml5PlainTextUtils::NewLinkAttributes() {
@ -20,3 +19,14 @@ nsHtml5HtmlAttributes* nsHtml5PlainTextUtils::NewLinkAttributes() {
linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href, -1); linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href, -1);
return linkAttrs; return linkAttrs;
} }
// static
nsHtml5HtmlAttributes* nsHtml5PlainTextUtils::NewBodyAttributes() {
nsHtml5HtmlAttributes* bodyAttrs = new nsHtml5HtmlAttributes(0);
if (!mozilla::StaticPrefs::plain_text_wrap_long_lines()) {
RefPtr<nsAtom> nowrap = nsGkAtoms::nowrap;
bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_CLASS,
nsHtml5String::FromAtom(nowrap.forget()), -1);
}
return bodyAttrs;
}

Просмотреть файл

@ -10,6 +10,7 @@
class nsHtml5PlainTextUtils { class nsHtml5PlainTextUtils {
public: public:
static nsHtml5HtmlAttributes* NewLinkAttributes(); static nsHtml5HtmlAttributes* NewLinkAttributes();
static nsHtml5HtmlAttributes* NewBodyAttributes();
}; };
#endif // nsHtml5PlainTextUtils_h #endif // nsHtml5PlainTextUtils_h

Просмотреть файл

@ -1276,6 +1276,9 @@ void nsHtml5TreeBuilder::StartPlainText() {
startTag(nsHtml5ElementName::ELT_LINK, startTag(nsHtml5ElementName::ELT_LINK,
nsHtml5PlainTextUtils::NewLinkAttributes(), false); nsHtml5PlainTextUtils::NewLinkAttributes(), false);
startTag(nsHtml5ElementName::ELT_BODY,
nsHtml5PlainTextUtils::NewBodyAttributes(), false);
StartPlainTextBody(); StartPlainTextBody();
} }