зеркало из https://github.com/mozilla/gecko-dev.git
XForms bug 299273 - xforms-select/xforms-deselect events not firing for select/select1. r=smaug,aaronr
This commit is contained in:
Родитель
5d565d2f7f
Коммит
768864929c
|
@ -105,7 +105,7 @@
|
|||
<getter>
|
||||
if (!this._uiElement) {
|
||||
this._uiElement =
|
||||
document.getAnonymousElementByAttribute(this, "anonid", "select");
|
||||
document.getAnonymousElementByAttribute(this, "anonid", "select");;
|
||||
}
|
||||
|
||||
return this._uiElement;
|
||||
|
@ -297,7 +297,7 @@
|
|||
|
||||
// add to the control array
|
||||
this._controlArray[this._controlArraySize] =
|
||||
{control: aControl, option: option, type: "item"}
|
||||
{control: aControl, option: option, type: "item", wasSelected: false}
|
||||
this._controlArraySize++;
|
||||
|
||||
return option;
|
||||
|
@ -344,7 +344,7 @@
|
|||
|
||||
// add to the control array
|
||||
this._controlArray[this._controlArraySize] =
|
||||
{control: child, option: option, type: "item"}
|
||||
{control: child, option: option, type: "item", wasSelected: false}
|
||||
this._controlArraySize++;
|
||||
|
||||
// check if we should pre-select this option
|
||||
|
@ -372,7 +372,7 @@
|
|||
|
||||
// add to the control array
|
||||
this._controlArray[this._controlArraySize] =
|
||||
{control: aItemElement, option: option, type: "item"}
|
||||
{control: aItemElement, option: option, type: "item", wasSelected: false}
|
||||
this._controlArraySize++;
|
||||
|
||||
this.uiElement.appendChild(option);
|
||||
|
@ -389,6 +389,10 @@
|
|||
// if incremental, change instance data and send the value-changed event
|
||||
if (this.incremental) {
|
||||
this._setBoundValue();
|
||||
} else {
|
||||
// per the spec, if not incremental, we still need to send the
|
||||
// deselect/select events. which _getSelectedValues() does for us
|
||||
this._getSelectedValues();
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
|
@ -406,6 +410,7 @@
|
|||
<body>
|
||||
<![CDATA[
|
||||
var selectedValues = "";
|
||||
var newSelectedControls = new Array();
|
||||
|
||||
// select if found, unselect if not
|
||||
var options = this._controlArray;
|
||||
|
@ -422,9 +427,28 @@
|
|||
|
||||
selectedValues +=
|
||||
options[i].control.QueryInterface(Components.interfaces.nsIXFormsSelectChild).value;
|
||||
|
||||
// if it wasn't selected before add to the list of newly selected items
|
||||
if (!options[i].wasSelected) {
|
||||
newSelectedControls.push(options[i].control);
|
||||
}
|
||||
|
||||
options[i].wasSelected = true;
|
||||
} else {
|
||||
// it was selected before, but now unselected
|
||||
if (options[i].wasSelected) {
|
||||
this.dispatchSelectEvent(options[i].control, "xforms-deselect");
|
||||
}
|
||||
|
||||
options[i].wasSelected = false;
|
||||
}
|
||||
}
|
||||
|
||||
// we send xforms-select after all deselect events are thrown
|
||||
for (var i = 0; i < newSelectedControls.length; i++) {
|
||||
this.dispatchSelectEvent(newSelectedControls[i], "xforms-select");
|
||||
}
|
||||
|
||||
return selectedValues;
|
||||
]]>
|
||||
</body>
|
||||
|
@ -508,11 +532,33 @@
|
|||
var control = this._controlArray[this._controlArraySize - 1]
|
||||
this._setItemSelection(control, true);
|
||||
|
||||
// tell the control it was selected
|
||||
control.wasSelected = true;
|
||||
|
||||
this._defaultHash[aValue].hits++;
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="dispatchSelectEvent">
|
||||
<parameter name="aElement"/>
|
||||
<parameter name="aName"/>
|
||||
<body>
|
||||
var ev = document.createEvent("Events");
|
||||
ev.initEvent(aName, true, false);
|
||||
|
||||
var elm = aElement;
|
||||
|
||||
// per http://www.w3.org/TR/2005/PER-xforms-20051006/index-all.html#evt-select
|
||||
// we send the event to the itemset if it is a parent.
|
||||
if (elm.parentNode.localName == "itemset")
|
||||
elm = elm.parentNode;
|
||||
|
||||
elm.dispatchEvent(ev);
|
||||
return true;
|
||||
</body>
|
||||
</method>
|
||||
</implementation>
|
||||
</binding>
|
||||
|
||||
|
@ -603,7 +649,7 @@
|
|||
|
||||
// add to the control array
|
||||
this._controlArray[this._controlArraySize] =
|
||||
{control: aControl, checkbox: item.firstChild, type: "item"}
|
||||
{control: aControl, checkbox: item.firstChild, type: "item", wasSelected: false}
|
||||
this._controlArraySize++;
|
||||
]]>
|
||||
</body>
|
||||
|
@ -655,7 +701,7 @@
|
|||
|
||||
// add to the control array
|
||||
this._controlArray[this._controlArraySize] =
|
||||
{control: child, checkbox: item.firstChild, type: "item"}
|
||||
{control: child, checkbox: item.firstChild, type: "item", wasSelected: false}
|
||||
this._controlArraySize++;
|
||||
|
||||
// check if we should pre-select this option
|
||||
|
@ -684,7 +730,7 @@
|
|||
|
||||
// add to the control array
|
||||
this._controlArray[this._controlArraySize] =
|
||||
{control: aItemElement, checkbox: item.firstChild, type: "item"}
|
||||
{control: aItemElement, checkbox: item.firstChild, type: "item", wasSelected: false}
|
||||
this._controlArraySize++;
|
||||
|
||||
this.uiElement.appendChild(item);
|
||||
|
|
|
@ -87,6 +87,7 @@
|
|||
<!-- This is either an nsIXFormsItemElement or null. -->
|
||||
<field name="_selected">null</field>
|
||||
<field name="_tmpSelected">null</field>
|
||||
<field name="_lastSelectedItem">null</field>
|
||||
<field name="popupOpen">false</field>
|
||||
<field name="shouldHandleBlur">true</field>
|
||||
|
||||
|
@ -183,7 +184,7 @@
|
|||
el.scrollIntoView(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!this.popupOpen && this.getAttribute("incremental") != "false") {
|
||||
if (this._selected) {
|
||||
this.updateInputField();
|
||||
|
@ -323,7 +324,7 @@
|
|||
<body>
|
||||
<![CDATA[
|
||||
var label = null;
|
||||
var next = null;
|
||||
var next = null, nextItem = null;
|
||||
var node = this.firstChild;
|
||||
while (node) {
|
||||
if (node.namespaceURI == this.XFORMS_NS &&
|
||||
|
@ -345,12 +346,16 @@
|
|||
next = this.findNextSelectable(node, aDown);
|
||||
if (next) {
|
||||
if (this._selected) {
|
||||
this.dispatchSelectEvent(this._selected, "xforms-deselect");
|
||||
this._selected.setActive(false);
|
||||
this._selected = null;
|
||||
}
|
||||
|
||||
this._selected = next.QueryInterface(Components.interfaces.nsIXFormsItemElement);
|
||||
if (this._selected) {
|
||||
nextItem = next.QueryInterface(Components.interfaces.nsIXFormsItemElement);
|
||||
if (nextItem) {
|
||||
this.dispatchSelectEvent(nextItem, "xforms-select");
|
||||
this._selected = nextItem;
|
||||
this._lastSelectedItem = nextItem;
|
||||
this._selected.setActive(true);
|
||||
this.updateInputField();
|
||||
}
|
||||
|
@ -390,6 +395,14 @@
|
|||
this.hidePopup();
|
||||
|
||||
if (this._selected) {
|
||||
if (this._lastSelectedItem != this._selected) {
|
||||
if (this._lastSelectedItem)
|
||||
this.dispatchSelectEvent(this._lastSelectedItem, "xforms-deselect");
|
||||
|
||||
this.dispatchSelectEvent(this._selected, "xforms-select");
|
||||
this._lastSelectedItem = this._selected;
|
||||
}
|
||||
|
||||
this.updateInputField();
|
||||
this.delegate.value =
|
||||
this._selected.value;
|
||||
|
@ -560,12 +573,14 @@
|
|||
}
|
||||
this._selected.setActive(false);
|
||||
this._selected = null;
|
||||
this._lastSelectedItem = null;
|
||||
}
|
||||
|
||||
this.selectItemByValue(newValue);
|
||||
|
||||
|
||||
if (this._selected) {
|
||||
this.updateInputField();
|
||||
this._lastSelectedItem = this._selected;
|
||||
} else if (this.selectionOpen) {
|
||||
this.inputField.value = newValue;
|
||||
} else {
|
||||
|
@ -650,6 +665,25 @@
|
|||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="dispatchSelectEvent">
|
||||
<parameter name="aElement"/>
|
||||
<parameter name="aName"/>
|
||||
<body>
|
||||
var ev = document.createEvent("Events");
|
||||
ev.initEvent(aName, true, false);
|
||||
|
||||
var elm = aElement;
|
||||
|
||||
// per http://www.w3.org/TR/2005/PER-xforms-20051006/index-all.html#evt-select
|
||||
// we send the event to the itemset if it is a parent.
|
||||
if (elm.parentNode.localName == "itemset")
|
||||
elm = elm.parentNode;
|
||||
|
||||
elm.dispatchEvent(ev);
|
||||
return true;
|
||||
</body>
|
||||
</method>
|
||||
</implementation>
|
||||
</binding>
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче