Backout 032a3ba018db, It breaks <select> form element interactions (bug 961489, bug 961662)

This commit is contained in:
Mark Finkle 2014-01-20 16:40:28 -05:00
parent 5fce2fe5f7
commit e78859a28f
2 changed files with 23 additions and 23 deletions

View File

@ -170,25 +170,18 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
/* Adds to a result value from the lists that can be shown in dialogs. /* Adds to a result value from the lists that can be shown in dialogs.
* Will set the selected value(s) to the button attribute of the * Will set the selected value(s) to the button attribute of the
* object that's passed in. If this is a multi-select dialog, sets a * object that's passed in. If this is a multi-select dialog, can set
* selected attribute to an array of booleans. * the button attribute to an array.
*/ */
private void addListResult(final JSONObject result, int which) { private void addListResult(final JSONObject result, int which) {
try { try {
if (mSelected != null) { if (mSelected != null) {
JSONArray selected = new JSONArray(); JSONArray selected = new JSONArray();
for (int i = 0; i < mSelected.length; i++) { for (int i = 0; i < mSelected.length; i++) {
if (mSelected[i]) { selected.put(mSelected[i]);
selected.put(i);
}
} }
result.put("list", selected); result.put("button", selected);
} else { } else {
// Mirror the selected array from multi choice for consistency.
JSONArray selected = new JSONArray();
selected.put(which);
result.put("list", selected);
// Make the button be the index of the select item.
result.put("button", which); result.put("button", which);
} }
} catch(JSONException ex) { } } catch(JSONException ex) { }
@ -229,12 +222,12 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
JSONObject ret = new JSONObject(); JSONObject ret = new JSONObject();
try { try {
ListView list = mDialog.getListView(); ListView list = mDialog.getListView();
addButtonResult(ret, which);
addInputValues(ret);
if (list != null || mSelected != null) { if (list != null || mSelected != null) {
addListResult(ret, which); addListResult(ret, which);
} else {
addButtonResult(ret, which);
} }
addInputValues(ret);
} catch(Exception ex) { } catch(Exception ex) {
Log.i(LOGTAG, "Error building return: " + ex); Log.i(LOGTAG, "Error building return: " + ex);
} }

View File

@ -37,25 +37,32 @@ var SelectHelper = {
} }
p.show((function(data) { p.show((function(data) {
let selected = data.list; let selected = data.button;
if (selected == -1)
return;
if (aElement instanceof Ci.nsIDOMXULMenuListElement) { if (aElement instanceof Ci.nsIDOMXULMenuListElement) {
if (aElement.selectedIndex != selected[0]) { if (aElement.selectedIndex != selected) {
aElement.selectedIndex = selected[0]; aElement.selectedIndex = selected;
this.fireOnCommand(aElement); this.fireOnCommand(aElement);
} }
} else if (aElement instanceof HTMLSelectElement) { } else if (aElement instanceof HTMLSelectElement) {
let changed = false; let changed = false;
if (!Array.isArray(selected)) {
let temp = [];
for (let i = 0; i <= list.length; i++) {
temp[i] = (i == selected);
}
selected = temp;
}
let i = 0; let i = 0;
this.forOptions(aElement, function(aNode) { this.forOptions(aElement, function(aNode) {
if (aNode.selected == (selected.indexOf(i) == -1)) { if (aNode.selected != selected[i]) {
changed = true; changed = true;
aNode.selected = false; aNode.selected = selected[i];
} else if (!aNode.selected == (selected.indexOf(i) != -1)) {
changed = true;
aNode.selected = true;
} }
i++; i++
}); });
if (changed) if (changed)