Bug 253564 - Plain text (text/plain, text/javascript, text/css, etc) documents should word-wrap. r=bz
authorJared Wein <jwein@mozilla.com>
Wed, 06 Mar 2013 23:45:08 -0500
changeset 124027 ae59f51150c92523caff0531a400e52921db06c4
parent 124026 5361e3f3590d27c733696f31e13634aca0177fd5
child 124028 d37fdbac89f2e931d9189fc0ba7c6fc028fdbaf4
push id24202
push userjwein@mozilla.com
push dateThu, 07 Mar 2013 04:45:55 +0000
treeherdermozilla-inbound@ae59f51150c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs253564
milestone22.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 253564 - Plain text (text/plain, text/javascript, text/css, etc) documents should word-wrap. r=bz
browser/app/profile/firefox.js
layout/style/jar.mn
layout/style/plaintext.css
modules/libpref/src/init/all.js
parser/html/Makefile.in
parser/html/nsHtml5PlainTextUtils.cpp
parser/html/nsHtml5PlainTextUtils.h
parser/html/nsHtml5TreeBuilder.h
parser/html/nsHtml5TreeBuilderCppSupplement.h
parser/html/nsHtml5TreeBuilderHSupplement.h
toolkit/locales/en-US/chrome/global/browser.properties
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1214,8 +1214,11 @@ pref("social.directories", "https://addo
 // necessary. This does not affect whitelisted and directory installs.
 pref("social.remote-install.enabled", true);
 
 pref("social.sidebar.open", true);
 pref("social.sidebar.unload_timeout_ms", 10000);
 pref("social.toast-notifications.enabled", true);
 
 pref("dom.identity.enabled", false);
+
+// Override the Gecko-default value of false for Firefox.
+pref("plain_text.wrap_long_lines", true);
--- a/layout/style/jar.mn
+++ b/layout/style/jar.mn
@@ -2,14 +2,15 @@
 # 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/.
 
 toolkit.jar:
 *  res/ua.css    (ua.css)
    res/html.css    (html.css)
    res/quirk.css    (quirk.css)
    res/full-screen-override.css    (full-screen-override.css)
+   res/plaintext.css     (plaintext.css)
    res/viewsource.css    (viewsource.css)
 *  res/forms.css    (forms.css)
    res/arrow.gif    (arrow.gif)
    res/arrowd.gif   (arrowd.gif)
 
 % resource gre-resources %res/
new file mode 100644
--- /dev/null
+++ b/layout/style/plaintext.css
@@ -0,0 +1,8 @@
+/* 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/. */
+
+pre {
+  white-space: pre-wrap;
+  word-wrap: break-word;
+}
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -402,16 +402,19 @@ pref("devtools.debugger.force-local", tr
 pref("view_source.syntax_highlight", true);
 pref("view_source.wrap_long_lines", false);
 pref("view_source.editor.external", false);
 pref("view_source.editor.path", "");
 // allows to add further arguments to the editor; use the %LINE% placeholder
 // for jumping to a specific line (e.g. "/line:%LINE%" or "--goto %LINE%")
 pref("view_source.editor.args", "");
 
+// When true this will word-wrap plain text documents.
+pref("plain_text.wrap_long_lines", false);
+
 // dispatch left clicks only to content in browser (still allows clicks to chrome/xul)
 pref("nglayout.events.dispatchLeftClickOnly", true);
 
 // whether or not to draw images while dragging
 pref("nglayout.enable_drag_images", true);
 
 // enable/disable paint flashing --- useful for debugging
 pref("nglayout.debug.paint_flashing", false);
--- a/parser/html/Makefile.in
+++ b/parser/html/Makefile.in
@@ -43,16 +43,17 @@ EXPORTS		= \
 		nsHtml5TreeOperation.h \
 		nsHtml5TreeOpExecutor.h \
 		nsAHtml5TreeOpSink.h \
 		nsHtml5TreeOpStage.h \
 		nsHtml5UTF16Buffer.h \
 		nsHtml5UTF16BufferHSupplement.h \
 		nsHtml5DependentUTF16Buffer.h \
 		nsHtml5OwningUTF16Buffer.h \
+		nsHtml5PlainTextUtils.h \
 		nsHtml5ViewSourceUtils.h \
 		nsHtml5StringParser.h \
 		nsParserUtils.h \
 		$(NULL)
 
 CPPSRCS		= \
 		nsHtml5Atoms.cpp \
 		nsHtml5Atom.cpp \
@@ -78,16 +79,17 @@ CPPSRCS		= \
 		nsHtml5TreeOpStage.cpp \
 		nsHtml5StateSnapshot.cpp \
 		nsHtml5TreeOpExecutor.cpp \
 		nsHtml5StreamParser.cpp \
 		nsHtml5Speculation.cpp \
 		nsHtml5SpeculativeLoad.cpp \
 		nsHtml5SVGLoadDispatcher.cpp \
 		nsHtml5Highlighter.cpp \
+		nsHtml5PlainTextUtils.cpp \
 		nsHtml5ViewSourceUtils.cpp \
 		nsHtml5StringParser.cpp \
 		nsParserUtils.cpp \
 		$(NULL)
 
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/parser/html/nsHtml5PlainTextUtils.cpp
@@ -0,0 +1,39 @@
+/* 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 "nsHtml5AttributeName.h"
+#include "nsIServiceManager.h"
+#include "nsIStringBundle.h"
+
+// static
+nsHtml5HtmlAttributes*
+nsHtml5PlainTextUtils::NewLinkAttributes()
+{
+  nsHtml5HtmlAttributes* linkAttrs = new nsHtml5HtmlAttributes(0);
+  nsString* rel = new nsString(NS_LITERAL_STRING("stylesheet"));
+  linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_REL, rel);
+  nsString* type = new nsString(NS_LITERAL_STRING("text/css"));
+  linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_TYPE, type);
+  nsString* href = new nsString(
+      NS_LITERAL_STRING("resource://gre-resources/plaintext.css"));
+  linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href);
+
+  nsresult rv;
+  nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
+  NS_ASSERTION(NS_SUCCEEDED(rv) && bundleService, "The bundle service could not be loaded");
+  nsCOMPtr<nsIStringBundle> bundle;
+  rv = bundleService->CreateBundle("chrome://global/locale/browser.properties",
+                                   getter_AddRefs(bundle));
+  NS_ASSERTION(NS_SUCCEEDED(rv) && bundle, "chrome://global/locale/browser.properties could not be loaded");
+  nsXPIDLString title;
+  if (bundle) {
+    bundle->GetStringFromName(NS_LITERAL_STRING("plainText.wordWrap").get(), getter_Copies(title));
+  }
+
+  nsString* titleCopy = new nsString(title);
+  linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_TITLE, titleCopy);
+  return linkAttrs;
+}
new file mode 100644
--- /dev/null
+++ b/parser/html/nsHtml5PlainTextUtils.h
@@ -0,0 +1,16 @@
+/* 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/. */
+
+#ifndef nsHtml5PlainTextUtils_h_
+#define nsHtml5PlainTextUtils_h_
+
+#include "nsHtml5HtmlAttributes.h"
+
+class nsHtml5PlainTextUtils
+{
+  public:
+    static nsHtml5HtmlAttributes* NewLinkAttributes();
+};
+
+#endif // nsHtml5PlainTextUtils_h_
--- a/parser/html/nsHtml5TreeBuilder.h
+++ b/parser/html/nsHtml5TreeBuilder.h
@@ -46,16 +46,17 @@
 #include "nsHtml5TreeOperation.h"
 #include "nsHtml5PendingNotification.h"
 #include "nsHtml5StateSnapshot.h"
 #include "nsHtml5StackNode.h"
 #include "nsHtml5TreeOpExecutor.h"
 #include "nsHtml5StreamParser.h"
 #include "nsAHtml5TreeBuilderState.h"
 #include "nsHtml5Highlighter.h"
+#include "nsHtml5PlainTextUtils.h"
 #include "nsHtml5ViewSourceUtils.h"
 #include "mozilla/Likely.h"
 
 class nsHtml5StreamParser;
 
 class nsHtml5Tokenizer;
 class nsHtml5MetaScanner;
 class nsHtml5AttributeName;
--- a/parser/html/nsHtml5TreeBuilderCppSupplement.h
+++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h
@@ -7,16 +7,17 @@
 #include "nsError.h"
 #include "nsIPresShell.h"
 #include "nsEvent.h"
 #include "nsGUIEvent.h"
 #include "nsEventDispatcher.h"
 #include "nsNodeUtils.h"
 #include "nsIFrame.h"
 #include "mozilla/Likely.h"
+#include "mozilla/Preferences.h"
 
 class nsPresContext;
 
 nsHtml5TreeBuilder::nsHtml5TreeBuilder(nsAHtml5TreeOpSink* aOpSink,
                                        nsHtml5TreeOpStage* aStage)
   : scriptingEnabled(false)
   , fragment(false)
   , contextNode(nullptr)
@@ -717,22 +718,34 @@ nsHtml5TreeBuilder::StartPlainTextViewSo
   startTag(nsHtml5ElementName::ELT_LINK,
            nsHtml5ViewSourceUtils::NewLinkAttributes(),
            false);
 
   startTag(nsHtml5ElementName::ELT_BODY,
            nsHtml5ViewSourceUtils::NewBodyAttributes(),
            false);
 
-  StartPlainText();
+  StartPlainTextBody();
 }
 
 void
 nsHtml5TreeBuilder::StartPlainText()
 {
+  if (mozilla::Preferences::GetBool("plain_text.wrap_long_lines", true)) {
+    startTag(nsHtml5ElementName::ELT_LINK,
+             nsHtml5PlainTextUtils::NewLinkAttributes(),
+             false);
+  }
+
+  StartPlainTextBody();
+}
+
+void
+nsHtml5TreeBuilder::StartPlainTextBody()
+{
   startTag(nsHtml5ElementName::ELT_PRE,
            nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES,
            false);
   needToDropLF = false;
 }
 
 // DocumentModeHandler
 void
--- a/parser/html/nsHtml5TreeBuilderHSupplement.h
+++ b/parser/html/nsHtml5TreeBuilderHSupplement.h
@@ -62,16 +62,18 @@
                        nsHtml5TreeOpStage* aStage);
 
     ~nsHtml5TreeBuilder();
     
     void StartPlainTextViewSource(const nsAutoString& aTitle);
 
     void StartPlainText();
 
+    void StartPlainTextBody();
+
     bool HasScript();
     
     void SetOpSink(nsAHtml5TreeOpSink* aOpSink) {
       mOpSink = aOpSink;
     }
 
     void ClearOps() {
       mOpQueue.Clear();
--- a/toolkit/locales/en-US/chrome/global/browser.properties
+++ b/toolkit/locales/en-US/chrome/global/browser.properties
@@ -1,8 +1,10 @@
 # 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/.
 
 browsewithcaret.checkMsg=Do not show me this dialog box again.
 browsewithcaret.checkWindowTitle=Caret Browsing
 browsewithcaret.checkLabel=Pressing F7 turns Caret Browsing on or off. This feature places a moveable cursor in web pages, allowing you to select text with the keyboard. Do you want to turn Caret Browsing on?
 browsewithcaret.checkButtonLabel=Yes
+
+plainText.wordWrap=Wrap Long Lines