Bug 1690340 - Part 1: Hide all the panel tools in the developer tools menu. r=jdescottes
[gecko.git] / parser / html / nsHtml5ViewSourceUtils.cpp
blob2ea8f7e3eb2057d7b63e103f989104555b17f096
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"
11 // static
12 nsHtml5HtmlAttributes* nsHtml5ViewSourceUtils::NewBodyAttributes() {
13 nsHtml5HtmlAttributes* bodyAttrs = new nsHtml5HtmlAttributes(0);
14 nsHtml5String id = nsHtml5Portability::newStringFromLiteral("viewsource");
15 bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id, -1);
17 nsString klass;
18 if (StaticPrefs::view_source_wrap_long_lines()) {
19 klass.AppendLiteral(u"wrap ");
21 if (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 = StaticPrefs::view_source_tab_size();
30 if (tabSize > 0) {
31 nsString style;
32 style.AssignLiteral("-moz-tab-size: ");
33 style.AppendInt(tabSize);
34 bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_STYLE,
35 nsHtml5String::FromString(style), -1);
38 return bodyAttrs;
41 // static
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);
51 return linkAttrs;
54 // static
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);
62 return metaVpAttrs;