1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsHtml5ViewSourceUtils.h"
6 #include "mozilla/Preferences.h"
7 #include "nsHtml5AttributeName.h"
8 #include "nsHtml5String.h"
9 #include "mozilla/StaticPrefs_view_source.h"
12 nsHtml5HtmlAttributes
* nsHtml5ViewSourceUtils::NewBodyAttributes() {
13 nsHtml5HtmlAttributes
* bodyAttrs
= new nsHtml5HtmlAttributes(0);
14 nsHtml5String id
= nsHtml5Portability::newStringFromLiteral("viewsource");
15 bodyAttrs
->addAttribute(nsHtml5AttributeName::ATTR_ID
, id
, -1);
18 if (mozilla::StaticPrefs::view_source_wrap_long_lines()) {
19 klass
.AppendLiteral(u
"wrap ");
21 if (mozilla::StaticPrefs::view_source_syntax_highlight()) {
22 klass
.AppendLiteral(u
"highlight");
24 if (!klass
.IsEmpty()) {
25 bodyAttrs
->addAttribute(nsHtml5AttributeName::ATTR_CLASS
,
26 nsHtml5String::FromString(klass
), -1);
29 int32_t tabSize
= mozilla::StaticPrefs::view_source_tab_size();
32 style
.AssignLiteral("tab-size: ");
33 style
.AppendInt(tabSize
);
34 bodyAttrs
->addAttribute(nsHtml5AttributeName::ATTR_STYLE
,
35 nsHtml5String::FromString(style
), -1);
42 nsHtml5HtmlAttributes
* nsHtml5ViewSourceUtils::NewLinkAttributes() {
43 nsHtml5HtmlAttributes
* linkAttrs
= new nsHtml5HtmlAttributes(0);
44 nsHtml5String rel
= nsHtml5Portability::newStringFromLiteral("stylesheet");
45 linkAttrs
->addAttribute(nsHtml5AttributeName::ATTR_REL
, rel
, -1);
46 nsHtml5String type
= nsHtml5Portability::newStringFromLiteral("text/css");
47 linkAttrs
->addAttribute(nsHtml5AttributeName::ATTR_TYPE
, type
, -1);
48 nsHtml5String href
= nsHtml5Portability::newStringFromLiteral(
49 "resource://content-accessible/viewsource.css");
50 linkAttrs
->addAttribute(nsHtml5AttributeName::ATTR_HREF
, href
, -1);
55 nsHtml5HtmlAttributes
* nsHtml5ViewSourceUtils::NewMetaViewportAttributes() {
56 nsHtml5HtmlAttributes
* metaVpAttrs
= new nsHtml5HtmlAttributes(0);
57 nsHtml5String name
= nsHtml5Portability::newStringFromLiteral("viewport");
58 metaVpAttrs
->addAttribute(nsHtml5AttributeName::ATTR_NAME
, name
, -1);
59 nsHtml5String content
=
60 nsHtml5Portability::newStringFromLiteral("width=device-width");
61 metaVpAttrs
->addAttribute(nsHtml5AttributeName::ATTR_CONTENT
, content
, -1);