nsHtml5ViewSourceUtils.cpp (2127B)
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 "nsHtml5AttributeName.h" 7 #include "nsHtml5String.h" 8 #include "mozilla/StaticPrefs_view_source.h" 9 10 // static 11 nsHtml5HtmlAttributes* nsHtml5ViewSourceUtils::NewBodyAttributes() { 12 nsHtml5HtmlAttributes* bodyAttrs = new nsHtml5HtmlAttributes(0); 13 nsHtml5String id = nsHtml5Portability::newStringFromLiteral("viewsource"); 14 bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id, -1); 15 16 int32_t tabSize = mozilla::StaticPrefs::view_source_tab_size(); 17 if (tabSize > 0) { 18 nsString style; 19 style.AssignLiteral("tab-size: "); 20 style.AppendInt(tabSize); 21 bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_STYLE, 22 nsHtml5String::FromString(style), -1); 23 } 24 25 return bodyAttrs; 26 } 27 28 // static 29 nsHtml5HtmlAttributes* nsHtml5ViewSourceUtils::NewLinkAttributes() { 30 nsHtml5HtmlAttributes* linkAttrs = new nsHtml5HtmlAttributes(0); 31 nsHtml5String rel = nsHtml5Portability::newStringFromLiteral("stylesheet"); 32 linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_REL, rel, -1); 33 nsHtml5String type = nsHtml5Portability::newStringFromLiteral("text/css"); 34 linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_TYPE, type, -1); 35 nsHtml5String href = nsHtml5Portability::newStringFromLiteral( 36 "resource://content-accessible/viewsource.css"); 37 linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href, -1); 38 return linkAttrs; 39 } 40 41 // static 42 nsHtml5HtmlAttributes* nsHtml5ViewSourceUtils::NewMetaViewportAttributes() { 43 nsHtml5HtmlAttributes* metaVpAttrs = new nsHtml5HtmlAttributes(0); 44 nsHtml5String name = nsHtml5Portability::newStringFromLiteral("viewport"); 45 metaVpAttrs->addAttribute(nsHtml5AttributeName::ATTR_NAME, name, -1); 46 nsHtml5String content = 47 nsHtml5Portability::newStringFromLiteral("width=device-width"); 48 metaVpAttrs->addAttribute(nsHtml5AttributeName::ATTR_CONTENT, content, -1); 49 return metaVpAttrs; 50 }