Bug 253564 - Plain text (text/plain, text/javascript, text/css, etc) documents should word-wrap. r=bz

This commit is contained in:
Jared Wein 2013-03-06 23:45:08 -05:00
Родитель ae87232f23
Коммит d1623e977a
11 изменённых файлов: 91 добавлений и 1 удалений

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

@ -1219,3 +1219,6 @@ 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);

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

@ -7,6 +7,7 @@ toolkit.jar:
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)

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

@ -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;
}

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

@ -407,6 +407,9 @@ pref("view_source.editor.path", "");
// 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);

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

@ -48,6 +48,7 @@ EXPORTS = \
nsHtml5UTF16BufferHSupplement.h \
nsHtml5DependentUTF16Buffer.h \
nsHtml5OwningUTF16Buffer.h \
nsHtml5PlainTextUtils.h \
nsHtml5ViewSourceUtils.h \
nsHtml5StringParser.h \
nsParserUtils.h \
@ -83,6 +84,7 @@ CPPSRCS = \
nsHtml5SpeculativeLoad.cpp \
nsHtml5SVGLoadDispatcher.cpp \
nsHtml5Highlighter.cpp \
nsHtml5PlainTextUtils.cpp \
nsHtml5ViewSourceUtils.cpp \
nsHtml5StringParser.cpp \
nsParserUtils.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;
}

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

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

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

@ -51,6 +51,7 @@
#include "nsHtml5StreamParser.h"
#include "nsAHtml5TreeBuilderState.h"
#include "nsHtml5Highlighter.h"
#include "nsHtml5PlainTextUtils.h"
#include "nsHtml5ViewSourceUtils.h"
#include "mozilla/Likely.h"

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

@ -12,6 +12,7 @@
#include "nsNodeUtils.h"
#include "nsIFrame.h"
#include "mozilla/Likely.h"
#include "mozilla/Preferences.h"
class nsPresContext;
@ -722,11 +723,23 @@ nsHtml5TreeBuilder::StartPlainTextViewSource(const nsAutoString& aTitle)
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,

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

@ -67,6 +67,8 @@
void StartPlainText();
void StartPlainTextBody();
bool HasScript();
void SetOpSink(nsAHtml5TreeOpSink* aOpSink) {

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

@ -6,3 +6,5 @@ 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