зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
3b4defe2d5
Коммит
28dedf278a
|
@ -45,7 +45,7 @@ function nsPrefWindow( frame_id )
|
||||||
|
|
||||||
this.contentFrame = frame_id
|
this.contentFrame = frame_id
|
||||||
this.wsm = new nsWidgetStateManager( 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.pref = null;
|
||||||
this.chromeRegistry = null;
|
this.chromeRegistry = null;
|
||||||
this.observerService= null;
|
this.observerService= null;
|
||||||
|
@ -215,7 +215,7 @@ nsPrefWindow.prototype =
|
||||||
if (!prefattribute) {
|
if (!prefattribute) {
|
||||||
if (elt == "radiogroup" || elt == "textbox" || elt == "menulist")
|
if (elt == "radiogroup" || elt == "textbox" || elt == "menulist")
|
||||||
prefattribute = "value";
|
prefattribute = "value";
|
||||||
else if (elt == "checkbox")
|
else if (elt == "checkbox" || elt == "listitem")
|
||||||
prefattribute = "checked";
|
prefattribute = "checked";
|
||||||
else if (elt == "button")
|
else if (elt == "button")
|
||||||
prefattribute = "disabled";
|
prefattribute = "disabled";
|
||||||
|
@ -226,7 +226,7 @@ nsPrefWindow.prototype =
|
||||||
if (!preftype) {
|
if (!preftype) {
|
||||||
if (elt == "textbox")
|
if (elt == "textbox")
|
||||||
preftype = "string";
|
preftype = "string";
|
||||||
else if (elt == "checkbox" || elt == "button")
|
else if (elt == "checkbox" || elt == "listitem" || elt == "button")
|
||||||
preftype = "bool";
|
preftype = "bool";
|
||||||
else if (elt == "radiogroup" || elt == "menulist")
|
else if (elt == "radiogroup" || elt == "menulist")
|
||||||
preftype = "int";
|
preftype = "int";
|
||||||
|
@ -238,6 +238,8 @@ nsPrefWindow.prototype =
|
||||||
value = true;
|
value = true;
|
||||||
else if( value == "false" && typeof(value) == "string" )
|
else if( value == "false" && typeof(value) == "string" )
|
||||||
value = false;
|
value = false;
|
||||||
|
if (itemObject.prefinverse == "true")
|
||||||
|
value = !value;
|
||||||
break;
|
break;
|
||||||
case "int":
|
case "int":
|
||||||
value = parseInt(value);
|
value = parseInt(value);
|
||||||
|
@ -340,7 +342,7 @@ nsPrefWindow.prototype =
|
||||||
if (!preftype) {
|
if (!preftype) {
|
||||||
if (elt == "textbox")
|
if (elt == "textbox")
|
||||||
preftype = "string";
|
preftype = "string";
|
||||||
else if (elt == "checkbox" || elt == "button")
|
else if (elt == "checkbox" || elt == "listitem" || elt == "button")
|
||||||
preftype = "bool";
|
preftype = "bool";
|
||||||
else if (elt == "radiogroup" || elt == "menulist")
|
else if (elt == "radiogroup" || elt == "menulist")
|
||||||
preftype = "int";
|
preftype = "int";
|
||||||
|
@ -350,27 +352,12 @@ nsPrefWindow.prototype =
|
||||||
if (!prefattribute) {
|
if (!prefattribute) {
|
||||||
if (elt == "radiogroup" || elt == "textbox" || elt == "menulist")
|
if (elt == "radiogroup" || elt == "textbox" || elt == "menulist")
|
||||||
prefattribute = "value";
|
prefattribute = "value";
|
||||||
else if (elt == "checkbox")
|
else if (elt == "checkbox" || elt == "listitem")
|
||||||
prefattribute = "checked";
|
prefattribute = "checked";
|
||||||
else if (elt == "button")
|
else if (elt == "button")
|
||||||
prefattribute = "disabled";
|
prefattribute = "disabled";
|
||||||
}
|
}
|
||||||
var prefvalue;
|
var prefvalue = this.getPref( preftype, prefstring );
|
||||||
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;
|
|
||||||
}
|
|
||||||
if( prefvalue == "!/!ERROR_UNDEFINED_PREF!/!" )
|
if( prefvalue == "!/!ERROR_UNDEFINED_PREF!/!" )
|
||||||
{
|
{
|
||||||
prefvalue = prefdefval;
|
prefvalue = prefdefval;
|
||||||
|
@ -381,6 +368,11 @@ nsPrefWindow.prototype =
|
||||||
if (isPrefLocked)
|
if (isPrefLocked)
|
||||||
root.disabled = "true";
|
root.disabled = "true";
|
||||||
root.localname = prefElements[i].localName;
|
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
|
this.wsm.setPageData( aPageTag ); // do not set extra elements, accept hard coded defaults
|
||||||
|
|
|
@ -35,11 +35,6 @@
|
||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** 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){
|
function changeDisabledState(state){
|
||||||
//Set the states of the groupbox children state based on the "javascript enabled" checkbox value
|
//Set the states of the groupbox children state based on the "javascript enabled" checkbox value
|
||||||
document.getElementById("allowScripts").disabled = state;
|
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(){
|
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
|
//If we don't have a checkbox under groupbox pluginPreferences, we should hide it
|
||||||
var pluginGroup = document.getElementById("pluginPreferences")
|
var pluginGroup = document.getElementById("pluginPreferences")
|
||||||
var children = pluginGroup.childNodes;
|
var children = pluginGroup.childNodes;
|
||||||
|
@ -110,57 +68,4 @@ function Startup(){
|
||||||
}
|
}
|
||||||
|
|
||||||
javascriptEnabledChange();
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,11 +68,16 @@
|
||||||
<label id="allowScripts" value="&allowScripts.label;"/>
|
<label id="allowScripts" value="&allowScripts.label;"/>
|
||||||
|
|
||||||
<listbox id="AllowList" flex="1">
|
<listbox id="AllowList" flex="1">
|
||||||
<listitem type="checkbox" id="allowWindowMoveResize" label="&allowWindowMoveResize.label;"/>
|
<listitem type="checkbox" id="allowWindowMoveResize" label="&allowWindowMoveResize.label;"
|
||||||
<listitem type="checkbox" id="allowWindowFlip" label="&allowWindowFlip.label;"/>
|
prefinverse="true" prefstring="dom.disable_window_move_resize"/>
|
||||||
<listitem type="checkbox" id="allowHideStatusBar" label="&allowHideStatusBar.label;"/>
|
<listitem type="checkbox" id="allowWindowFlip" label="&allowWindowFlip.label;"
|
||||||
<listitem type="checkbox" id="allowWindowStatusChange" label="&allowWindowStatusChange.label;"/>
|
prefinverse="true" prefstring="dom.disable_window_flip"/>
|
||||||
<listitem type="checkbox" id="allowImageSrcChange" label="&allowWindowImageSrcChange.label;"/>
|
<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>
|
</listbox>
|
||||||
</groupbox>
|
</groupbox>
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче