browser/components/preferences/content.js

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

     1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 var gContentPane = {
     8   /**
     9    * Initializes the fonts dropdowns displayed in this pane.
    10    */
    11   init: function ()
    12   {
    13     this._rebuildFonts();
    14     var menulist = document.getElementById("defaultFont");
    15     if (menulist.selectedIndex == -1) {
    16       menulist.insertItemAt(0, "", "", "");
    17       menulist.selectedIndex = 0;
    18     }
    19   },
    21   // UTILITY FUNCTIONS
    23   /**
    24    * Utility function to enable/disable the button specified by aButtonID based
    25    * on the value of the Boolean preference specified by aPreferenceID.
    26    */
    27   updateButtons: function (aButtonID, aPreferenceID)
    28   {
    29     var button = document.getElementById(aButtonID);
    30     var preference = document.getElementById(aPreferenceID);
    31     button.disabled = preference.value != true;
    32     return undefined;
    33   },
    35   // BEGIN UI CODE
    37   /*
    38    * Preferences:
    39    *
    40    * dom.disable_open_during_load
    41    * - true if popups are blocked by default, false otherwise
    42    */
    44   // POP-UPS
    46   /**
    47    * Displays the popup exceptions dialog where specific site popup preferences
    48    * can be set.
    49    */
    50   showPopupExceptions: function ()
    51   {
    52     var bundlePreferences = document.getElementById("bundlePreferences");
    53     var params = { blockVisible: false, sessionVisible: false, allowVisible: true, prefilledHost: "", permissionType: "popup" };
    54     params.windowTitle = bundlePreferences.getString("popuppermissionstitle");
    55     params.introText = bundlePreferences.getString("popuppermissionstext");
    56     document.documentElement.openWindow("Browser:Permissions",
    57                                         "chrome://browser/content/preferences/permissions.xul",
    58                                         "", params);
    59   },
    62   // FONTS
    64   /**
    65    * Populates the default font list in UI.
    66    */
    67   _rebuildFonts: function ()
    68   {
    69     var langGroupPref = document.getElementById("font.language.group");
    70     this._selectDefaultLanguageGroup(langGroupPref.value,
    71                                      this._readDefaultFontTypeForLanguage(langGroupPref.value) == "serif");
    72   },
    74   /**
    75    * 
    76    */
    77   _selectDefaultLanguageGroup: function (aLanguageGroup, aIsSerif)
    78   {
    79     const kFontNameFmtSerif         = "font.name.serif.%LANG%";
    80     const kFontNameFmtSansSerif     = "font.name.sans-serif.%LANG%";
    81     const kFontNameListFmtSerif     = "font.name-list.serif.%LANG%";
    82     const kFontNameListFmtSansSerif = "font.name-list.sans-serif.%LANG%";
    83     const kFontSizeFmtVariable      = "font.size.variable.%LANG%";
    85     var prefs = [{ format   : aIsSerif ? kFontNameFmtSerif : kFontNameFmtSansSerif,
    86                    type     : "fontname",
    87                    element  : "defaultFont",
    88                    fonttype : aIsSerif ? "serif" : "sans-serif" },
    89                  { format   : aIsSerif ? kFontNameListFmtSerif : kFontNameListFmtSansSerif,
    90                    type     : "unichar",
    91                    element  : null,
    92                    fonttype : aIsSerif ? "serif" : "sans-serif" },
    93                  { format   : kFontSizeFmtVariable,
    94                    type     : "int",
    95                    element  : "defaultFontSize",
    96                    fonttype : null }];
    97     var preferences = document.getElementById("contentPreferences");
    98     for (var i = 0; i < prefs.length; ++i) {
    99       var preference = document.getElementById(prefs[i].format.replace(/%LANG%/, aLanguageGroup));
   100       if (!preference) {
   101         preference = document.createElement("preference");
   102         var name = prefs[i].format.replace(/%LANG%/, aLanguageGroup);
   103         preference.id = name;
   104         preference.setAttribute("name", name);
   105         preference.setAttribute("type", prefs[i].type);
   106         preferences.appendChild(preference);
   107       }
   109       if (!prefs[i].element)
   110         continue;
   112       var element = document.getElementById(prefs[i].element);
   113       if (element) {
   114         element.setAttribute("preference", preference.id);
   116         if (prefs[i].fonttype)
   117           FontBuilder.buildFontList(aLanguageGroup, prefs[i].fonttype, element);
   119         preference.setElementValue(element);
   120       }
   121     }
   122   },
   124   /**
   125    * Returns the type of the current default font for the language denoted by
   126    * aLanguageGroup.
   127    */
   128   _readDefaultFontTypeForLanguage: function (aLanguageGroup)
   129   {
   130     const kDefaultFontType = "font.default.%LANG%";
   131     var defaultFontTypePref = kDefaultFontType.replace(/%LANG%/, aLanguageGroup);
   132     var preference = document.getElementById(defaultFontTypePref);
   133     if (!preference) {
   134       preference = document.createElement("preference");
   135       preference.id = defaultFontTypePref;
   136       preference.setAttribute("name", defaultFontTypePref);
   137       preference.setAttribute("type", "string");
   138       preference.setAttribute("onchange", "gContentPane._rebuildFonts();");
   139       document.getElementById("contentPreferences").appendChild(preference);
   140     }
   141     return preference.value;
   142   },
   144   /**
   145    * Displays the fonts dialog, where web page font names and sizes can be
   146    * configured.
   147    */  
   148   configureFonts: function ()
   149   {
   150     document.documentElement.openSubDialog("chrome://browser/content/preferences/fonts.xul",
   151                                            "", null);
   152   },
   154   /**
   155    * Displays the colors dialog, where default web page/link/etc. colors can be
   156    * configured.
   157    */
   158   configureColors: function ()
   159   {
   160     document.documentElement.openSubDialog("chrome://browser/content/preferences/colors.xul",
   161                                            "", null);  
   162   },
   164   // LANGUAGES
   166   /**
   167    * Shows a dialog in which the preferred language for web content may be set.
   168    */
   169   showLanguages: function ()
   170   {
   171     document.documentElement.openSubDialog("chrome://browser/content/preferences/languages.xul",
   172                                            "", null);
   173   }
   174 };

mercurial