/src/mozilla-central/parser/html/nsHtml5ViewSourceUtils.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
4 | | |
5 | | #include "nsHtml5ViewSourceUtils.h" |
6 | | #include "mozilla/Preferences.h" |
7 | | #include "nsHtml5AttributeName.h" |
8 | | #include "nsHtml5String.h" |
9 | | |
10 | | // static |
11 | | nsHtml5HtmlAttributes* |
12 | | nsHtml5ViewSourceUtils::NewBodyAttributes() |
13 | 0 | { |
14 | 0 | nsHtml5HtmlAttributes* bodyAttrs = new nsHtml5HtmlAttributes(0); |
15 | 0 | nsHtml5String id = nsHtml5Portability::newStringFromLiteral("viewsource"); |
16 | 0 | bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id, -1); |
17 | 0 |
|
18 | 0 | nsString klass; |
19 | 0 | if (mozilla::Preferences::GetBool("view_source.wrap_long_lines", true)) { |
20 | 0 | klass.AppendLiteral(u"wrap "); |
21 | 0 | } |
22 | 0 | if (mozilla::Preferences::GetBool("view_source.syntax_highlight", true)) { |
23 | 0 | klass.AppendLiteral(u"highlight"); |
24 | 0 | } |
25 | 0 | if (!klass.IsEmpty()) { |
26 | 0 | bodyAttrs->addAttribute( |
27 | 0 | nsHtml5AttributeName::ATTR_CLASS, nsHtml5String::FromString(klass), -1); |
28 | 0 | } |
29 | 0 |
|
30 | 0 | int32_t tabSize = mozilla::Preferences::GetInt("view_source.tab_size", 4); |
31 | 0 | if (tabSize > 0) { |
32 | 0 | nsString style; |
33 | 0 | style.AssignLiteral("-moz-tab-size: "); |
34 | 0 | style.AppendInt(tabSize); |
35 | 0 | bodyAttrs->addAttribute( |
36 | 0 | nsHtml5AttributeName::ATTR_STYLE, nsHtml5String::FromString(style), -1); |
37 | 0 | } |
38 | 0 |
|
39 | 0 | return bodyAttrs; |
40 | 0 | } |
41 | | |
42 | | // static |
43 | | nsHtml5HtmlAttributes* |
44 | | nsHtml5ViewSourceUtils::NewLinkAttributes() |
45 | 0 | { |
46 | 0 | nsHtml5HtmlAttributes* linkAttrs = new nsHtml5HtmlAttributes(0); |
47 | 0 | nsHtml5String rel = nsHtml5Portability::newStringFromLiteral("stylesheet"); |
48 | 0 | linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_REL, rel, -1); |
49 | 0 | nsHtml5String type = nsHtml5Portability::newStringFromLiteral("text/css"); |
50 | 0 | linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_TYPE, type, -1); |
51 | 0 | nsHtml5String href = nsHtml5Portability::newStringFromLiteral( |
52 | 0 | "resource://content-accessible/viewsource.css"); |
53 | 0 | linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href, -1); |
54 | 0 | return linkAttrs; |
55 | 0 | } |
56 | | |
57 | | // static |
58 | | nsHtml5HtmlAttributes* |
59 | | nsHtml5ViewSourceUtils::NewMetaViewportAttributes() |
60 | 0 | { |
61 | 0 | nsHtml5HtmlAttributes* metaVpAttrs = new nsHtml5HtmlAttributes(0); |
62 | 0 | nsHtml5String name = nsHtml5Portability::newStringFromLiteral("viewport"); |
63 | 0 | metaVpAttrs->addAttribute(nsHtml5AttributeName::ATTR_NAME, name, -1); |
64 | 0 | nsHtml5String content = |
65 | 0 | nsHtml5Portability::newStringFromLiteral("width=device-width"); |
66 | 0 | metaVpAttrs->addAttribute(nsHtml5AttributeName::ATTR_CONTENT, content, -1); |
67 | 0 | return metaVpAttrs; |
68 | 0 | } |