Bug 181973 Implement a system for inverting boolean prefs and apply it to the scripts listbox r=caillon sr=alecf

This commit is contained in:
neil%parkwaycc.co.uk 2003-11-12 10:13:10 +00:00
parent fada1ad2ce
commit f287978ed6
3 changed files with 23 additions and 121 deletions

View File

@ -45,7 +45,7 @@ function nsPrefWindow( frame_id )
this.contentFrame = frame_id
this.wsm = new nsWidgetStateManager( frame_id );
this.wsm.attributes = ["preftype", "prefstring", "prefattribute", "disabled"];
this.wsm.attributes = ["preftype", "prefstring", "prefattribute", "prefinverse", "disabled"];
this.pref = null;
this.chromeRegistry = null;
this.observerService= null;
@ -215,7 +215,7 @@ nsPrefWindow.prototype =
if (!prefattribute) {
if (elt == "radiogroup" || elt == "textbox" || elt == "menulist")
prefattribute = "value";
else if (elt == "checkbox")
else if (elt == "checkbox" || elt == "listitem")
prefattribute = "checked";
else if (elt == "button")
prefattribute = "disabled";
@ -226,7 +226,7 @@ nsPrefWindow.prototype =
if (!preftype) {
if (elt == "textbox")
preftype = "string";
else if (elt == "checkbox" || elt == "button")
else if (elt == "checkbox" || elt == "listitem" || elt == "button")
preftype = "bool";
else if (elt == "radiogroup" || elt == "menulist")
preftype = "int";
@ -238,6 +238,8 @@ nsPrefWindow.prototype =
value = true;
else if( value == "false" && typeof(value) == "string" )
value = false;
if (itemObject.prefinverse == "true")
value = !value;
break;
case "int":
value = parseInt(value);
@ -340,7 +342,7 @@ nsPrefWindow.prototype =
if (!preftype) {
if (elt == "textbox")
preftype = "string";
else if (elt == "checkbox" || elt == "button")
else if (elt == "checkbox" || elt == "listitem" || elt == "button")
preftype = "bool";
else if (elt == "radiogroup" || elt == "menulist")
preftype = "int";
@ -350,27 +352,12 @@ nsPrefWindow.prototype =
if (!prefattribute) {
if (elt == "radiogroup" || elt == "textbox" || elt == "menulist")
prefattribute = "value";
else if (elt == "checkbox")
else if (elt == "checkbox" || elt == "listitem")
prefattribute = "checked";
else if (elt == "button")
prefattribute = "disabled";
}
var prefvalue;
switch( preftype )
{
case "bool":
prefvalue = this.getPref( preftype, prefstring );
break;
case "int":
prefvalue = this.getPref( preftype, prefstring );
break;
case "string":
case "localizedstring":
case "color":
default:
prefvalue = this.getPref( preftype, prefstring );
break;
}
var prefvalue = this.getPref( preftype, prefstring );
if( prefvalue == "!/!ERROR_UNDEFINED_PREF!/!" )
{
prefvalue = prefdefval;
@ -381,6 +368,11 @@ nsPrefWindow.prototype =
if (isPrefLocked)
root.disabled = "true";
root.localname = prefElements[i].localName;
if (preftype == "bool") {
root.prefinverse = prefElements[i].getAttribute("prefinverse");
if (root.prefinverse == "true")
root[prefattribute] = !prefvalue;
}
}
}
this.wsm.setPageData( aPageTag ); // do not set extra elements, accept hard coded defaults

View File

@ -35,11 +35,6 @@
*
* ***** END LICENSE BLOCK ***** */
const pref = Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref);
// need it globally, but can only set it in startup()
var data;
function changeDisabledState(state){
//Set the states of the groupbox children state based on the "javascript enabled" checkbox value
document.getElementById("allowScripts").disabled = state;
@ -64,44 +59,7 @@ function javascriptEnabledChange(){
}
}
function getPrefValueForCheckbox(prefName){
var prefValue = false;
try {
prefValue = pref.GetBoolPref(prefName);
}
catch(e) {}
// the prefs are stored in terms of disabling,
// but we want our value in terms of enabling.
// so let's invert the prefValue.
return !prefValue;
}
function Startup(){
data = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-scripts.xul"];
//If scriptData does not exist, then it is the first time the panel was shown and we default to false
if (!("scriptData" in data)){
var changedList = ["allowWindowMoveResizeChanged",
"allowWindowStatusChangeChanged",
"allowWindowFlipChanged",
"allowImageSrcChangeChanged",
"allowHideStatusBarChanged"];
data.scriptData = [];
for(var run = 0; run < changedList.length; run++ ){
data.scriptData[ changedList[run] ] = [];
data.scriptData[ changedList[run] ].value = false;
}
document.getElementById("allowWindowMoveResize").checked = getPrefValueForCheckbox("dom.disable_window_move_resize");
document.getElementById("allowWindowFlip").checked = getPrefValueForCheckbox("dom.disable_window_flip");
document.getElementById("allowWindowStatusChange").checked = getPrefValueForCheckbox("dom.disable_window_status_change");
document.getElementById("allowImageSrcChange").checked = getPrefValueForCheckbox("dom.disable_image_src_set");
document.getElementById("allowHideStatusBar").checked = getPrefValueForCheckbox("dom.disable_window_open_feature.status");
//If we don't have a checkbox under groupbox pluginPreferences, we should hide it
var pluginGroup = document.getElementById("pluginPreferences")
var children = pluginGroup.childNodes;
@ -110,57 +68,4 @@ function Startup(){
}
javascriptEnabledChange();
document.getElementById("AllowList").addEventListener("CheckboxStateChange", onCheckboxCheck, false);
parent.hPrefWindow.registerOKCallbackFunc(doOnOk);
}
function doOnOk(){
//If a user makes a change to this panel, goes to another panel, and returns to this panel to
//make another change, then we cannot use data[elementName]. This is because data[elementName]
//contains the original xul change and we would loose the new change. Thus we track all changes
//by using getElementById.
//The nested functions are needed because doOnOk cannot access anything outside of its scope
//when it is called
function getCheckboxValue(name){
if ("onCheckboxCheck" in window)
return document.getElementById(name).checked;
return data[name].checked;
}
var data = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-scripts.xul"];
if (data.scriptData["allowWindowMoveResizeChanged"].value){
parent.hPrefWindow.setPref("bool", "dom.disable_window_move_resize",
!getCheckboxValue('allowWindowMoveResize'));
}
if (data.scriptData["allowWindowStatusChangeChanged"].value){
parent.hPrefWindow.setPref("bool", "dom.disable_window_status_change",
!getCheckboxValue("allowWindowStatusChange"));
}
if (data.scriptData["allowWindowFlipChanged"].value){
parent.hPrefWindow.setPref("bool", "dom.disable_window_flip",
!getCheckboxValue("allowWindowFlip"));
}
if (data.scriptData["allowImageSrcChangeChanged"].value){
parent.hPrefWindow.setPref("bool", "dom.disable_image_src_set",
!getCheckboxValue("allowImageSrcChange"));
}
if (data.scriptData["allowHideStatusBarChanged"].value) {
parent.hPrefWindow.setPref("bool", "dom.disable_window_open_feature.status",
!getCheckboxValue("allowHideStatusBar"));
}
}
function onCheckboxCheck(event)
{
data.scriptData[event.target.id+"Changed"].value = !data.scriptData[event.target.id+"Changed"].value;
}

View File

@ -68,11 +68,16 @@
<label id="allowScripts" value="&allowScripts.label;"/>
<listbox id="AllowList" flex="1">
<listitem type="checkbox" id="allowWindowMoveResize" label="&allowWindowMoveResize.label;"/>
<listitem type="checkbox" id="allowWindowFlip" label="&allowWindowFlip.label;"/>
<listitem type="checkbox" id="allowHideStatusBar" label="&allowHideStatusBar.label;"/>
<listitem type="checkbox" id="allowWindowStatusChange" label="&allowWindowStatusChange.label;"/>
<listitem type="checkbox" id="allowImageSrcChange" label="&allowWindowImageSrcChange.label;"/>
<listitem type="checkbox" id="allowWindowMoveResize" label="&allowWindowMoveResize.label;"
prefinverse="true" prefstring="dom.disable_window_move_resize"/>
<listitem type="checkbox" id="allowWindowFlip" label="&allowWindowFlip.label;"
prefinverse="true" prefstring="dom.disable_window_flip"/>
<listitem type="checkbox" id="allowHideStatusBar" label="&allowHideStatusBar.label;"
prefinverse="true" prefstring="dom.disable_window_open_feature.status"/>
<listitem type="checkbox" id="allowWindowStatusChange" label="&allowWindowStatusChange.label;"
prefinverse="true" prefstring="dom.disable_window_status_change"/>
<listitem type="checkbox" id="allowImageSrcChange" label="&allowWindowImageSrcChange.label;"
prefinverse="true" prefstring="dom.disable_image_src_set"/>
</listbox>
</groupbox>