toolkit/mozapps/preferences/fontbuilder.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 var FontBuilder = {
michael@0 8 _enumerator: null,
michael@0 9 get enumerator ()
michael@0 10 {
michael@0 11 if (!this._enumerator) {
michael@0 12 this._enumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
michael@0 13 .createInstance(Components.interfaces.nsIFontEnumerator);
michael@0 14 }
michael@0 15 return this._enumerator;
michael@0 16 },
michael@0 17
michael@0 18 _allFonts: null,
michael@0 19 buildFontList: function (aLanguage, aFontType, aMenuList)
michael@0 20 {
michael@0 21 // Reset the list
michael@0 22 while (aMenuList.hasChildNodes())
michael@0 23 aMenuList.removeChild(aMenuList.firstChild);
michael@0 24
michael@0 25 var defaultFont = null;
michael@0 26 // Load Font Lists
michael@0 27 var fonts = this.enumerator.EnumerateFonts(aLanguage, aFontType, { } );
michael@0 28 if (fonts.length > 0)
michael@0 29 defaultFont = this.enumerator.getDefaultFont(aLanguage, aFontType);
michael@0 30 else {
michael@0 31 fonts = this.enumerator.EnumerateFonts(aLanguage, "", { });
michael@0 32 if (fonts.length > 0)
michael@0 33 defaultFont = this.enumerator.getDefaultFont(aLanguage, "");
michael@0 34 }
michael@0 35
michael@0 36 if (!this._allFonts)
michael@0 37 this._allFonts = this.enumerator.EnumerateAllFonts({});
michael@0 38
michael@0 39 // Build the UI for the Default Font and Fonts for this CSS type.
michael@0 40 var popup = document.createElement("menupopup");
michael@0 41 var separator;
michael@0 42 if (fonts.length > 0) {
michael@0 43 if (defaultFont) {
michael@0 44 var bundlePreferences = document.getElementById("bundlePreferences");
michael@0 45 var label = bundlePreferences.getFormattedString("labelDefaultFont", [defaultFont]);
michael@0 46 var menuitem = document.createElement("menuitem");
michael@0 47 menuitem.setAttribute("label", label);
michael@0 48 menuitem.setAttribute("value", ""); // Default Font has a blank value
michael@0 49 popup.appendChild(menuitem);
michael@0 50
michael@0 51 separator = document.createElement("menuseparator");
michael@0 52 popup.appendChild(separator);
michael@0 53 }
michael@0 54
michael@0 55 for (var i = 0; i < fonts.length; ++i) {
michael@0 56 menuitem = document.createElement("menuitem");
michael@0 57 menuitem.setAttribute("value", fonts[i]);
michael@0 58 menuitem.setAttribute("label", fonts[i]);
michael@0 59 popup.appendChild(menuitem);
michael@0 60 }
michael@0 61 }
michael@0 62
michael@0 63 // Build the UI for the remaining fonts.
michael@0 64 if (this._allFonts.length > fonts.length) {
michael@0 65 // Both lists are sorted, and the Fonts-By-Type list is a subset of the
michael@0 66 // All-Fonts list, so walk both lists side-by-side, skipping values we've
michael@0 67 // already created menu items for.
michael@0 68 var builtItem = separator ? separator.nextSibling : popup.firstChild;
michael@0 69 var builtItemValue = builtItem ? builtItem.getAttribute("value") : null;
michael@0 70
michael@0 71 separator = document.createElement("menuseparator");
michael@0 72 popup.appendChild(separator);
michael@0 73
michael@0 74 for (i = 0; i < this._allFonts.length; ++i) {
michael@0 75 if (this._allFonts[i] != builtItemValue) {
michael@0 76 menuitem = document.createElement("menuitem");
michael@0 77 menuitem.setAttribute("value", this._allFonts[i]);
michael@0 78 menuitem.setAttribute("label", this._allFonts[i]);
michael@0 79 popup.appendChild(menuitem);
michael@0 80 }
michael@0 81 else {
michael@0 82 builtItem = builtItem.nextSibling;
michael@0 83 builtItemValue = builtItem ? builtItem.getAttribute("value") : null;
michael@0 84 }
michael@0 85 }
michael@0 86 }
michael@0 87 aMenuList.appendChild(popup);
michael@0 88 }
michael@0 89 };

mercurial