1 # -*- Mode
: Java
; tab
-width
: 4; indent
-tabs
-mode
: nil
; c
-basic
-offset
: 4 -*-
2 # ***** BEGIN LICENSE BLOCK
*****
3 # Version
: MPL
1.1/GPL 2.0/LGPL
2.1
5 # The contents
of this file are subject to the Mozilla Public License Version
6 # 1.1 (the
"License"); you may not
use this file except
in compliance
with
7 # the License
. You may obtain a copy
of the License at
8 # http
://www.mozilla.org/MPL/
10 # Software distributed under the License is distributed on an
"AS IS" basis
,
11 # WITHOUT WARRANTY OF ANY KIND
, either express or implied
. See the License
12 # for the specific language governing rights and limitations under the
15 # The Original Code is the Firefox Preferences System
.
17 # The Initial Developer
of the Original Code is
19 # Portions created by the Initial Developer are
Copyright (C
) 2005
20 # the Initial Developer
. All Rights Reserved
.
23 # Ben Goodger
<ben
@mozilla
.org
>
24 # Asaf Romano
<mozilla
.mano
@sent
.com
>
26 # Alternatively
, the contents
of this file may be used under the terms
of
27 # either the GNU General Public License Version
2 or
later (the
"GPL"), or
28 # the GNU Lesser General Public License Version
2.1 or
later (the
"LGPL"),
29 # in which
case the provisions
of the GPL or the LGPL are applicable instead
30 # of those above
. If you wish to allow
use of your version
of this file only
31 # under the terms
of either the GPL or the LGPL
, and not to allow others to
32 # use your version
of this file under the terms
of the MPL
, indicate your
33 # decision by deleting the provisions above and replace them
with the notice
34 # and other provisions required by the GPL or the LGPL
. If you
do not
delete
35 # the provisions above
, a recipient may
use your version
of this file under
36 # the terms
of any one
of the MPL
, the GPL or the LGPL
.
38 # ***** END LICENSE BLOCK
*****
40 # browser
.display
.languageList LOCK ALL when LOCKED
42 const kDefaultFontType
= "font.default.%LANG%";
43 const kFontNameFmtSerif
= "font.name.serif.%LANG%";
44 const kFontNameFmtSansSerif
= "font.name.sans-serif.%LANG%";
45 const kFontNameFmtMonospace
= "font.name.monospace.%LANG%";
46 const kFontNameListFmtSerif
= "font.name-list.serif.%LANG%";
47 const kFontNameListFmtSansSerif
= "font.name-list.sans-serif.%LANG%";
48 const kFontNameListFmtMonospace
= "font.name-list.monospace.%LANG%";
49 const kFontSizeFmtVariable
= "font.size.variable.%LANG%";
50 const kFontSizeFmtFixed
= "font.size.fixed.%LANG%";
51 const kFontMinSizeFmt
= "font.minimum-size.%LANG%";
54 _selectLanguageGroup: function (aLanguageGroup
)
56 var prefs
= [{ format
: kDefaultFontType
, type
: "string", element
: "defaultFontType", fonttype
: null},
57 { format
: kFontNameFmtSerif
, type
: "fontname", element
: "serif", fonttype
: "serif" },
58 { format
: kFontNameFmtSansSerif
, type
: "fontname", element
: "sans-serif", fonttype
: "sans-serif" },
59 { format
: kFontNameFmtMonospace
, type
: "fontname", element
: "monospace", fonttype
: "monospace" },
60 { format
: kFontNameListFmtSerif
, type
: "unichar", element
: null, fonttype
: "serif" },
61 { format
: kFontNameListFmtSansSerif
, type
: "unichar", element
: null, fonttype
: "sans-serif" },
62 { format
: kFontNameListFmtMonospace
, type
: "unichar", element
: null, fonttype
: "monospace" },
63 { format
: kFontSizeFmtVariable
, type
: "int", element
: "sizeVar", fonttype
: null },
64 { format
: kFontSizeFmtFixed
, type
: "int", element
: "sizeMono", fonttype
: null },
65 { format
: kFontMinSizeFmt
, type
: "int", element
: "minSize", fonttype
: null }];
66 var preferences
= document
.getElementById("fontPreferences");
67 for (var i
= 0; i
< prefs
.length
; ++i
) {
68 var preference
= document
.getElementById(prefs
[i
].format
.replace(/%LANG%/, aLanguageGroup
));
70 preference
= document
.createElement("preference");
71 var name
= prefs
[i
].format
.replace(/%LANG%/, aLanguageGroup
);
73 preference
.setAttribute("name", name
);
74 preference
.setAttribute("type", prefs
[i
].type
);
75 preferences
.appendChild(preference
);
78 if (!prefs
[i
].element
)
81 var element
= document
.getElementById(prefs
[i
].element
);
83 element
.setAttribute("preference", preference
.id
);
85 if (prefs
[i
].fonttype
)
86 FontBuilder
.buildFontList(aLanguageGroup
, prefs
[i
].fonttype
, element
);
88 preference
.setElementValue(element
);
93 readFontLanguageGroup: function ()
95 var languagePref
= document
.getElementById("font.language.group");
96 this._selectLanguageGroup(languagePref
.value
);
100 readFontSelection: function (aElement
)
102 // Determine the appropriate value to select, for the following cases:
103 // - there is no setting
104 // - the font selected by the user is no longer present (e.g. deleted from
106 var preference
= document
.getElementById(aElement
.getAttribute("preference"));
107 if (preference
.value
) {
108 var fontItems
= aElement
.getElementsByAttribute("value", preference
.value
);
110 // There is a setting that actually is in the list. Respect it.
111 if (fontItems
.length
> 0)
115 var defaultValue
= aElement
.firstChild
.firstChild
.getAttribute("value");
116 var languagePref
= document
.getElementById("font.language.group");
117 preference
= document
.getElementById("font.name-list." + aElement
.id
+ "." + languagePref
.value
);
118 if (!preference
|| !preference
.hasUserValue
)
121 var fontNames
= preference
.value
.split(",");
122 var stripWhitespace
= /^\s*(.*)\s*$/;
124 for (var i
= 0; i
< fontNames
.length
; ++i
) {
125 var fontName
= fontNames
[i
].replace(stripWhitespace
, "$1");
126 fontItems
= aElement
.getElementsByAttribute("value", fontName
);
127 if (fontItems
.length
)
130 if (fontItems
.length
)
131 return fontItems
[0].getAttribute("value");
135 _charsetMenuInitialized
: false,
136 readDefaultCharset: function ()
138 if (!this._charsetMenuInitialized
) {
139 var os
= Components
.classes
["@mozilla.org/observer-service;1"]
140 .getService(Components
.interfaces
.nsIObserverService
);
141 os
.notifyObservers(null, "charsetmenu-selected", "other");
142 this._charsetMenuInitialized
= true;
147 readUseDocumentFonts: function ()
149 var preference
= document
.getElementById("browser.display.use_document_fonts");
150 return preference
.value
== 1;
153 writeUseDocumentFonts: function ()
155 var useDocumentFonts
= document
.getElementById("useDocumentFonts");
156 return useDocumentFonts
.checked
? 1 : 0;