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