1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/preferences/in-content/content.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,173 @@ 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 file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +var gContentPane = { 1.9 + 1.10 + /** 1.11 + * Initializes the fonts dropdowns displayed in this pane. 1.12 + */ 1.13 + init: function () 1.14 + { 1.15 + this._rebuildFonts(); 1.16 + var menulist = document.getElementById("defaultFont"); 1.17 + if (menulist.selectedIndex == -1) { 1.18 + menulist.insertItemAt(0, "", "", ""); 1.19 + menulist.selectedIndex = 0; 1.20 + } 1.21 + }, 1.22 + 1.23 + // UTILITY FUNCTIONS 1.24 + 1.25 + /** 1.26 + * Utility function to enable/disable the button specified by aButtonID based 1.27 + * on the value of the Boolean preference specified by aPreferenceID. 1.28 + */ 1.29 + updateButtons: function (aButtonID, aPreferenceID) 1.30 + { 1.31 + var button = document.getElementById(aButtonID); 1.32 + var preference = document.getElementById(aPreferenceID); 1.33 + button.disabled = preference.value != true; 1.34 + return undefined; 1.35 + }, 1.36 + 1.37 + // BEGIN UI CODE 1.38 + 1.39 + /* 1.40 + * Preferences: 1.41 + * 1.42 + * dom.disable_open_during_load 1.43 + * - true if popups are blocked by default, false otherwise 1.44 + */ 1.45 + 1.46 + // POP-UPS 1.47 + 1.48 + /** 1.49 + * Displays the popup exceptions dialog where specific site popup preferences 1.50 + * can be set. 1.51 + */ 1.52 + showPopupExceptions: function () 1.53 + { 1.54 + var bundlePreferences = document.getElementById("bundlePreferences"); 1.55 + var params = { blockVisible: false, sessionVisible: false, allowVisible: true, 1.56 + prefilledHost: "", permissionType: "popup" } 1.57 + params.windowTitle = bundlePreferences.getString("popuppermissionstitle"); 1.58 + params.introText = bundlePreferences.getString("popuppermissionstext"); 1.59 + 1.60 + openDialog("chrome://browser/content/preferences/permissions.xul", 1.61 + "Browser:Permissions", "resizable=yes", params); 1.62 + }, 1.63 + 1.64 + // FONTS 1.65 + 1.66 + /** 1.67 + * Populates the default font list in UI. 1.68 + */ 1.69 + _rebuildFonts: function () 1.70 + { 1.71 + var langGroupPref = document.getElementById("font.language.group"); 1.72 + this._selectDefaultLanguageGroup(langGroupPref.value, 1.73 + this._readDefaultFontTypeForLanguage(langGroupPref.value) == "serif"); 1.74 + }, 1.75 + 1.76 + /** 1.77 + * 1.78 + */ 1.79 + _selectDefaultLanguageGroup: function (aLanguageGroup, aIsSerif) 1.80 + { 1.81 + const kFontNameFmtSerif = "font.name.serif.%LANG%"; 1.82 + const kFontNameFmtSansSerif = "font.name.sans-serif.%LANG%"; 1.83 + const kFontNameListFmtSerif = "font.name-list.serif.%LANG%"; 1.84 + const kFontNameListFmtSansSerif = "font.name-list.sans-serif.%LANG%"; 1.85 + const kFontSizeFmtVariable = "font.size.variable.%LANG%"; 1.86 + 1.87 + var prefs = [{ format : aIsSerif ? kFontNameFmtSerif : kFontNameFmtSansSerif, 1.88 + type : "fontname", 1.89 + element : "defaultFont", 1.90 + fonttype : aIsSerif ? "serif" : "sans-serif" }, 1.91 + { format : aIsSerif ? kFontNameListFmtSerif : kFontNameListFmtSansSerif, 1.92 + type : "unichar", 1.93 + element : null, 1.94 + fonttype : aIsSerif ? "serif" : "sans-serif" }, 1.95 + { format : kFontSizeFmtVariable, 1.96 + type : "int", 1.97 + element : "defaultFontSize", 1.98 + fonttype : null }]; 1.99 + var preferences = document.getElementById("contentPreferences"); 1.100 + for (var i = 0; i < prefs.length; ++i) { 1.101 + var preference = document.getElementById(prefs[i].format.replace(/%LANG%/, aLanguageGroup)); 1.102 + if (!preference) { 1.103 + preference = document.createElement("preference"); 1.104 + var name = prefs[i].format.replace(/%LANG%/, aLanguageGroup); 1.105 + preference.id = name; 1.106 + preference.setAttribute("name", name); 1.107 + preference.setAttribute("type", prefs[i].type); 1.108 + preferences.appendChild(preference); 1.109 + } 1.110 + 1.111 + if (!prefs[i].element) 1.112 + continue; 1.113 + 1.114 + var element = document.getElementById(prefs[i].element); 1.115 + if (element) { 1.116 + element.setAttribute("preference", preference.id); 1.117 + 1.118 + if (prefs[i].fonttype) 1.119 + FontBuilder.buildFontList(aLanguageGroup, prefs[i].fonttype, element); 1.120 + 1.121 + preference.setElementValue(element); 1.122 + } 1.123 + } 1.124 + }, 1.125 + 1.126 + /** 1.127 + * Returns the type of the current default font for the language denoted by 1.128 + * aLanguageGroup. 1.129 + */ 1.130 + _readDefaultFontTypeForLanguage: function (aLanguageGroup) 1.131 + { 1.132 + const kDefaultFontType = "font.default.%LANG%"; 1.133 + var defaultFontTypePref = kDefaultFontType.replace(/%LANG%/, aLanguageGroup); 1.134 + var preference = document.getElementById(defaultFontTypePref); 1.135 + if (!preference) { 1.136 + preference = document.createElement("preference"); 1.137 + preference.id = defaultFontTypePref; 1.138 + preference.setAttribute("name", defaultFontTypePref); 1.139 + preference.setAttribute("type", "string"); 1.140 + preference.setAttribute("onchange", "gContentPane._rebuildFonts();"); 1.141 + document.getElementById("contentPreferences").appendChild(preference); 1.142 + } 1.143 + return preference.value; 1.144 + }, 1.145 + 1.146 + /** 1.147 + * Displays the fonts dialog, where web page font names and sizes can be 1.148 + * configured. 1.149 + */ 1.150 + configureFonts: function () 1.151 + { 1.152 + openDialog("chrome://browser/content/preferences/fonts.xul", 1.153 + "Browser:FontPreferences", null); 1.154 + }, 1.155 + 1.156 + /** 1.157 + * Displays the colors dialog, where default web page/link/etc. colors can be 1.158 + * configured. 1.159 + */ 1.160 + configureColors: function () 1.161 + { 1.162 + openDialog("chrome://browser/content/preferences/colors.xul", 1.163 + "Browser:ColorPreferences", null); 1.164 + }, 1.165 + 1.166 + // LANGUAGES 1.167 + 1.168 + /** 1.169 + * Shows a dialog in which the preferred language for web content may be set. 1.170 + */ 1.171 + showLanguages: function () 1.172 + { 1.173 + openDialog("chrome://browser/content/preferences/languages.xul", 1.174 + "Browser:LanguagePreferences", null); 1.175 + } 1.176 +};