parser/html/nsHtml5ViewSourceUtils.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5
michael@0 6 #include "nsHtml5ViewSourceUtils.h"
michael@0 7 #include "nsHtml5AttributeName.h"
michael@0 8 #include "mozilla/Preferences.h"
michael@0 9
michael@0 10 // static
michael@0 11 nsHtml5HtmlAttributes*
michael@0 12 nsHtml5ViewSourceUtils::NewBodyAttributes()
michael@0 13 {
michael@0 14 nsHtml5HtmlAttributes* bodyAttrs = new nsHtml5HtmlAttributes(0);
michael@0 15 nsString* id = new nsString(NS_LITERAL_STRING("viewsource"));
michael@0 16 bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id);
michael@0 17
michael@0 18 if (mozilla::Preferences::GetBool("view_source.wrap_long_lines", true)) {
michael@0 19 nsString* klass = new nsString(NS_LITERAL_STRING("wrap"));
michael@0 20 bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_CLASS, klass);
michael@0 21 }
michael@0 22
michael@0 23 int32_t tabSize = mozilla::Preferences::GetInt("view_source.tab_size", 4);
michael@0 24 if (tabSize > 0) {
michael@0 25 nsString* style = new nsString(NS_LITERAL_STRING("-moz-tab-size: "));
michael@0 26 style->AppendInt(tabSize);
michael@0 27 bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_STYLE, style);
michael@0 28 }
michael@0 29
michael@0 30 return bodyAttrs;
michael@0 31 }
michael@0 32
michael@0 33 // static
michael@0 34 nsHtml5HtmlAttributes*
michael@0 35 nsHtml5ViewSourceUtils::NewLinkAttributes()
michael@0 36 {
michael@0 37 nsHtml5HtmlAttributes* linkAttrs = new nsHtml5HtmlAttributes(0);
michael@0 38 nsString* rel = new nsString(NS_LITERAL_STRING("stylesheet"));
michael@0 39 linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_REL, rel);
michael@0 40 nsString* type = new nsString(NS_LITERAL_STRING("text/css"));
michael@0 41 linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_TYPE, type);
michael@0 42 nsString* href = new nsString(
michael@0 43 NS_LITERAL_STRING("resource://gre-resources/viewsource.css"));
michael@0 44 linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href);
michael@0 45 return linkAttrs;
michael@0 46 }

mercurial