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.

     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/. */
     6 #include "nsHtml5ViewSourceUtils.h"
     7 #include "nsHtml5AttributeName.h"
     8 #include "mozilla/Preferences.h"
    10 // static
    11 nsHtml5HtmlAttributes*
    12 nsHtml5ViewSourceUtils::NewBodyAttributes()
    13 {
    14   nsHtml5HtmlAttributes* bodyAttrs = new nsHtml5HtmlAttributes(0);
    15   nsString* id = new nsString(NS_LITERAL_STRING("viewsource"));
    16   bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_ID, id);
    18   if (mozilla::Preferences::GetBool("view_source.wrap_long_lines", true)) {
    19     nsString* klass = new nsString(NS_LITERAL_STRING("wrap"));
    20     bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_CLASS, klass);
    21   }
    23   int32_t tabSize = mozilla::Preferences::GetInt("view_source.tab_size", 4);
    24   if (tabSize > 0) {
    25     nsString* style = new nsString(NS_LITERAL_STRING("-moz-tab-size: "));
    26     style->AppendInt(tabSize);
    27     bodyAttrs->addAttribute(nsHtml5AttributeName::ATTR_STYLE, style);
    28   }
    30   return bodyAttrs;
    31 }
    33 // static
    34 nsHtml5HtmlAttributes*
    35 nsHtml5ViewSourceUtils::NewLinkAttributes()
    36 {
    37   nsHtml5HtmlAttributes* linkAttrs = new nsHtml5HtmlAttributes(0);
    38   nsString* rel = new nsString(NS_LITERAL_STRING("stylesheet"));
    39   linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_REL, rel);
    40   nsString* type = new nsString(NS_LITERAL_STRING("text/css"));
    41   linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_TYPE, type);
    42   nsString* href = new nsString(
    43       NS_LITERAL_STRING("resource://gre-resources/viewsource.css"));
    44   linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href);
    45   return linkAttrs;
    46 }

mercurial