1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/parser/html/nsHtml5ViewSourceUtils.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 + 1.9 +#include "nsHtml5ViewSourceUtils.h" 1.10 +#include "nsHtml5AttributeName.h" 1.11 +#include "mozilla/Preferences.h" 1.12 + 1.13 +// static 1.14 +nsHtml5HtmlAttributes* 1.15 +nsHtml5ViewSourceUtils::NewBodyAttributes() 1.16 +{ 1.17 + nsHtml5HtmlAttributes* bodyAttrs = new nsHtml5HtmlAttributes(0); 1.18 + nsString* id = new nsString(NS_LITERAL_STRING("viewsource")); 1.19 + bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id); 1.20 + 1.21 + if (mozilla::Preferences::GetBool("view_source.wrap_long_lines", true)) { 1.22 + nsString* klass = new nsString(NS_LITERAL_STRING("wrap")); 1.23 + bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_CLASS, klass); 1.24 + } 1.25 + 1.26 + int32_t tabSize = mozilla::Preferences::GetInt("view_source.tab_size", 4); 1.27 + if (tabSize > 0) { 1.28 + nsString* style = new nsString(NS_LITERAL_STRING("-moz-tab-size: ")); 1.29 + style->AppendInt(tabSize); 1.30 + bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_STYLE, style); 1.31 + } 1.32 + 1.33 + return bodyAttrs; 1.34 +} 1.35 + 1.36 +// static 1.37 +nsHtml5HtmlAttributes* 1.38 +nsHtml5ViewSourceUtils::NewLinkAttributes() 1.39 +{ 1.40 + nsHtml5HtmlAttributes* linkAttrs = new nsHtml5HtmlAttributes(0); 1.41 + nsString* rel = new nsString(NS_LITERAL_STRING("stylesheet")); 1.42 + linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_REL, rel); 1.43 + nsString* type = new nsString(NS_LITERAL_STRING("text/css")); 1.44 + linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_TYPE, type); 1.45 + nsString* href = new nsString( 1.46 + NS_LITERAL_STRING("resource://gre-resources/viewsource.css")); 1.47 + linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href); 1.48 + return linkAttrs; 1.49 +}