michael@0: /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // browser.display.languageList LOCK ALL when LOCKED michael@0: michael@0: const kDefaultFontType = "font.default.%LANG%"; michael@0: const kFontNameFmtSerif = "font.name.serif.%LANG%"; michael@0: const kFontNameFmtSansSerif = "font.name.sans-serif.%LANG%"; michael@0: const kFontNameFmtMonospace = "font.name.monospace.%LANG%"; michael@0: const kFontNameListFmtSerif = "font.name-list.serif.%LANG%"; michael@0: const kFontNameListFmtSansSerif = "font.name-list.sans-serif.%LANG%"; michael@0: const kFontNameListFmtMonospace = "font.name-list.monospace.%LANG%"; michael@0: const kFontSizeFmtVariable = "font.size.variable.%LANG%"; michael@0: const kFontSizeFmtFixed = "font.size.fixed.%LANG%"; michael@0: const kFontMinSizeFmt = "font.minimum-size.%LANG%"; michael@0: michael@0: var gFontsDialog = { michael@0: _selectLanguageGroup: function (aLanguageGroup) michael@0: { michael@0: var prefs = [{ format: kDefaultFontType, type: "string", element: "defaultFontType", fonttype: null}, michael@0: { format: kFontNameFmtSerif, type: "fontname", element: "serif", fonttype: "serif" }, michael@0: { format: kFontNameFmtSansSerif, type: "fontname", element: "sans-serif", fonttype: "sans-serif" }, michael@0: { format: kFontNameFmtMonospace, type: "fontname", element: "monospace", fonttype: "monospace" }, michael@0: { format: kFontNameListFmtSerif, type: "unichar", element: null, fonttype: "serif" }, michael@0: { format: kFontNameListFmtSansSerif, type: "unichar", element: null, fonttype: "sans-serif" }, michael@0: { format: kFontNameListFmtMonospace, type: "unichar", element: null, fonttype: "monospace" }, michael@0: { format: kFontSizeFmtVariable, type: "int", element: "sizeVar", fonttype: null }, michael@0: { format: kFontSizeFmtFixed, type: "int", element: "sizeMono", fonttype: null }, michael@0: { format: kFontMinSizeFmt, type: "int", element: "minSize", fonttype: null }]; michael@0: var preferences = document.getElementById("fontPreferences"); 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: readFontLanguageGroup: function () michael@0: { michael@0: var languagePref = document.getElementById("font.language.group"); michael@0: this._selectLanguageGroup(languagePref.value); michael@0: return undefined; michael@0: }, michael@0: michael@0: readFontSelection: function (aElement) michael@0: { michael@0: // Determine the appropriate value to select, for the following cases: michael@0: // - there is no setting michael@0: // - the font selected by the user is no longer present (e.g. deleted from michael@0: // fonts folder) michael@0: var preference = document.getElementById(aElement.getAttribute("preference")); michael@0: if (preference.value) { michael@0: var fontItems = aElement.getElementsByAttribute("value", preference.value); michael@0: michael@0: // There is a setting that actually is in the list. Respect it. michael@0: if (fontItems.length > 0) michael@0: return undefined; michael@0: } michael@0: michael@0: var defaultValue = aElement.firstChild.firstChild.getAttribute("value"); michael@0: var languagePref = document.getElementById("font.language.group"); michael@0: preference = document.getElementById("font.name-list." + aElement.id + "." + languagePref.value); michael@0: if (!preference || !preference.hasUserValue) michael@0: return defaultValue; michael@0: michael@0: var fontNames = preference.value.split(","); michael@0: var stripWhitespace = /^\s*(.*)\s*$/; michael@0: michael@0: for (var i = 0; i < fontNames.length; ++i) { michael@0: var fontName = fontNames[i].replace(stripWhitespace, "$1"); michael@0: fontItems = aElement.getElementsByAttribute("value", fontName); michael@0: if (fontItems.length) michael@0: break; michael@0: } michael@0: if (fontItems.length) michael@0: return fontItems[0].getAttribute("value"); michael@0: return defaultValue; michael@0: }, michael@0: michael@0: readUseDocumentFonts: function () michael@0: { michael@0: var preference = document.getElementById("browser.display.use_document_fonts"); michael@0: return preference.value == 1; michael@0: }, michael@0: michael@0: writeUseDocumentFonts: function () michael@0: { michael@0: var useDocumentFonts = document.getElementById("useDocumentFonts"); michael@0: return useDocumentFonts.checked ? 1 : 0; michael@0: } michael@0: }; michael@0: