michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var gContentPane = { michael@0: michael@0: /** michael@0: * Initializes the fonts dropdowns displayed in this pane. michael@0: */ michael@0: init: function () michael@0: { michael@0: this._rebuildFonts(); michael@0: var menulist = document.getElementById("defaultFont"); michael@0: if (menulist.selectedIndex == -1) { michael@0: menulist.insertItemAt(0, "", "", ""); michael@0: menulist.selectedIndex = 0; michael@0: } michael@0: }, michael@0: michael@0: // UTILITY FUNCTIONS michael@0: michael@0: /** michael@0: * Utility function to enable/disable the button specified by aButtonID based michael@0: * on the value of the Boolean preference specified by aPreferenceID. michael@0: */ michael@0: updateButtons: function (aButtonID, aPreferenceID) michael@0: { michael@0: var button = document.getElementById(aButtonID); michael@0: var preference = document.getElementById(aPreferenceID); michael@0: button.disabled = preference.value != true; michael@0: return undefined; michael@0: }, michael@0: michael@0: // BEGIN UI CODE michael@0: michael@0: /* michael@0: * Preferences: michael@0: * michael@0: * dom.disable_open_during_load michael@0: * - true if popups are blocked by default, false otherwise michael@0: */ michael@0: michael@0: // POP-UPS michael@0: michael@0: /** michael@0: * Displays the popup exceptions dialog where specific site popup preferences michael@0: * can be set. michael@0: */ michael@0: showPopupExceptions: function () michael@0: { michael@0: var bundlePreferences = document.getElementById("bundlePreferences"); michael@0: var params = { blockVisible: false, sessionVisible: false, allowVisible: true, michael@0: prefilledHost: "", permissionType: "popup" } michael@0: params.windowTitle = bundlePreferences.getString("popuppermissionstitle"); michael@0: params.introText = bundlePreferences.getString("popuppermissionstext"); michael@0: michael@0: openDialog("chrome://browser/content/preferences/permissions.xul", michael@0: "Browser:Permissions", "resizable=yes", params); michael@0: }, michael@0: michael@0: // FONTS michael@0: michael@0: /** michael@0: * Populates the default font list in UI. michael@0: */ michael@0: _rebuildFonts: function () michael@0: { michael@0: var langGroupPref = document.getElementById("font.language.group"); michael@0: this._selectDefaultLanguageGroup(langGroupPref.value, michael@0: this._readDefaultFontTypeForLanguage(langGroupPref.value) == "serif"); michael@0: }, michael@0: michael@0: /** michael@0: * michael@0: */ michael@0: _selectDefaultLanguageGroup: function (aLanguageGroup, aIsSerif) michael@0: { michael@0: const kFontNameFmtSerif = "font.name.serif.%LANG%"; michael@0: const kFontNameFmtSansSerif = "font.name.sans-serif.%LANG%"; michael@0: const kFontNameListFmtSerif = "font.name-list.serif.%LANG%"; michael@0: const kFontNameListFmtSansSerif = "font.name-list.sans-serif.%LANG%"; michael@0: const kFontSizeFmtVariable = "font.size.variable.%LANG%"; michael@0: michael@0: var prefs = [{ format : aIsSerif ? kFontNameFmtSerif : kFontNameFmtSansSerif, michael@0: type : "fontname", michael@0: element : "defaultFont", michael@0: fonttype : aIsSerif ? "serif" : "sans-serif" }, michael@0: { format : aIsSerif ? kFontNameListFmtSerif : kFontNameListFmtSansSerif, michael@0: type : "unichar", michael@0: element : null, michael@0: fonttype : aIsSerif ? "serif" : "sans-serif" }, michael@0: { format : kFontSizeFmtVariable, michael@0: type : "int", michael@0: element : "defaultFontSize", michael@0: fonttype : null }]; michael@0: var preferences = document.getElementById("contentPreferences"); michael@0: for (var i = 0; i < prefs.length; ++i) { michael@0: var preference = document.getElementById(prefs[i].format.replace(/%LANG%/, aLanguageGroup)); michael@0: if (!preference) { michael@0: preference = document.createElement("preference"); michael@0: var name = prefs[i].format.replace(/%LANG%/, aLanguageGroup); michael@0: preference.id = name; michael@0: preference.setAttribute("name", name); michael@0: preference.setAttribute("type", prefs[i].type); michael@0: preferences.appendChild(preference); michael@0: } michael@0: michael@0: if (!prefs[i].element) michael@0: continue; michael@0: michael@0: var element = document.getElementById(prefs[i].element); michael@0: if (element) { michael@0: element.setAttribute("preference", preference.id); michael@0: michael@0: if (prefs[i].fonttype) michael@0: FontBuilder.buildFontList(aLanguageGroup, prefs[i].fonttype, element); michael@0: michael@0: preference.setElementValue(element); michael@0: } michael@0: } michael@0: }, michael@0: michael@0: /** michael@0: * Returns the type of the current default font for the language denoted by michael@0: * aLanguageGroup. michael@0: */ michael@0: _readDefaultFontTypeForLanguage: function (aLanguageGroup) michael@0: { michael@0: const kDefaultFontType = "font.default.%LANG%"; michael@0: var defaultFontTypePref = kDefaultFontType.replace(/%LANG%/, aLanguageGroup); michael@0: var preference = document.getElementById(defaultFontTypePref); michael@0: if (!preference) { michael@0: preference = document.createElement("preference"); michael@0: preference.id = defaultFontTypePref; michael@0: preference.setAttribute("name", defaultFontTypePref); michael@0: preference.setAttribute("type", "string"); michael@0: preference.setAttribute("onchange", "gContentPane._rebuildFonts();"); michael@0: document.getElementById("contentPreferences").appendChild(preference); michael@0: } michael@0: return preference.value; michael@0: }, michael@0: michael@0: /** michael@0: * Displays the fonts dialog, where web page font names and sizes can be michael@0: * configured. michael@0: */ michael@0: configureFonts: function () michael@0: { michael@0: openDialog("chrome://browser/content/preferences/fonts.xul", michael@0: "Browser:FontPreferences", null); michael@0: }, michael@0: michael@0: /** michael@0: * Displays the colors dialog, where default web page/link/etc. colors can be michael@0: * configured. michael@0: */ michael@0: configureColors: function () michael@0: { michael@0: openDialog("chrome://browser/content/preferences/colors.xul", michael@0: "Browser:ColorPreferences", null); michael@0: }, michael@0: michael@0: // LANGUAGES michael@0: michael@0: /** michael@0: * Shows a dialog in which the preferred language for web content may be set. michael@0: */ michael@0: showLanguages: function () michael@0: { michael@0: openDialog("chrome://browser/content/preferences/languages.xul", michael@0: "Browser:LanguagePreferences", null); michael@0: } michael@0: };