In the XUL autocomplete widget, make user-initiated autocomplete dispatch an oninput event, just as if the user had typed the text. Also fixing a bug where it was not possible to create an oninput event from script. Bug 287996, r=mconnor sr=jst.

This commit is contained in:
bryner%brianryner.com 2005-08-22 18:34:21 +00:00
Родитель eaaf0466e4
Коммит adc0ddf8eb
4 изменённых файлов: 52 добавлений и 19 удалений

Просмотреть файл

@ -458,6 +458,8 @@ nsDOMEvent::SetEventType(const nsAString& aEventTypeArg)
mEvent->message = NS_UI_FOCUSIN;
else if (atom == nsLayoutAtoms::onDOMFocusOut)
mEvent->message = NS_UI_FOCUSOUT;
else if (atom == nsLayoutAtoms::oninput)
mEvent->message = NS_FORM_INPUT;
} else if (mEvent->eventStructType == NS_PAGETRANSITION_EVENT) {
if (atom == nsLayoutAtoms::onpageshow)
mEvent->message = NS_PAGE_SHOW;

Просмотреть файл

@ -2947,7 +2947,7 @@ nsTextControlFrame::FireOnInput()
// Dispatch the "input" event
nsEventStatus status = nsEventStatus_eIgnore;
nsGUIEvent event(PR_TRUE, NS_FORM_INPUT, nsnull);
nsUIEvent event(PR_TRUE, NS_FORM_INPUT, 0);
// Have the content handle the event, propagating it according to normal
// DOM rules.

Просмотреть файл

@ -173,8 +173,19 @@
</method>
<property name="textValue"
onget="return this.value;"
onset="return this.value = val;"/>
onget="return this.value;">
<setter><![CDATA[
// Completing a result should simulate the user typing the result,
// so fire an input event.
this.value = val;
var evt = document.createEvent("UIEvents");
evt.initUIEvent("input", true, false, window, 0);
this.mIgnoreInput = true;
this.dispatchEvent(evt);
this.mIgnoreInput = false;
return this.value;
]]></setter>
</property>
<property name="selectionStart"
onget="return this.mInputElt.selectionStart;"/>

Просмотреть файл

@ -698,7 +698,7 @@
// set textbox value to either override value, or default search result
var val = this.resultsPopup.getOverrideValue();
if (val) {
this.value = val;
this.setTextValue(val);
this.mNeedToFinish = false;
} else if (this.mTransientValue || !this.forceComplete ||
!(this.mNeedToComplete || aForceComplete)) {
@ -710,10 +710,11 @@
var results = this.mLastResults[name];
if (results && results.items.Count() > 0 && results.defaultItemIndex != -1)
{
this.value = this.getSessionValueAt(name, results.defaultItemIndex);
val = this.getSessionValueAt(name, results.defaultItemIndex);
this.setTextValue(val);
this.mDefaultMatchFilled = true;
this.mNeedToFinish = false;
break;
break;
}
}
@ -730,7 +731,9 @@
var defaultSession = this.getDefaultSession();
if (defaultSession)
{
this.value = this.getSessionValueAt(defaultSession, 0); // preselect the first one...
// preselect the first one
var first = this.getSessionValueAt(defaultSession, 0);
this.setTextValue(first);
this.mDefaultMatchFilled = true;
}
}
@ -760,17 +763,17 @@
var errItem=null;
var val = this.resultsPopup.getOverrideValue();
if (val)
this.value = val;
this.setTextValue(val);
else if (this.resultsPopup.selectedIndex != null &&
!this.noMatch) {
if (this.getSessionStatusAt(this.resultsPopup.selectedIndex) ==
Components.interfaces.nsIAutoCompleteStatus.failureItems) {
this.value = this.currentSearchString;
this.setTextValue(this.currentSearchString);
this.mTransientValue = true;
errItem = this.getResultAt(this.resultsPopup.selectedIndex);
} else {
this.value = this.getResultValueAt(
this.resultsPopup.selectedIndex);
this.setTextValue(this.getResultValueAt(
this.resultsPopup.selectedIndex));
}
}
@ -797,7 +800,7 @@
var ok = this._fireEvent("textrevert");
if ((ok || ok == undefined) && val)
this.value = val;
this.setTextValue(val);
this.userAction = "typing";
@ -988,17 +991,17 @@
if (this.getSessionStatusAt(selected) ==
Components.interfaces.nsIAutoCompleteStatus.failureItems) {
if (this.currentSearchString)
this.value = this.currentSearchString;
this.setTextValue(this.currentSearchString);
} else {
this.value = this.getResultValueAt(selected);
this.setTextValue(this.getResultValueAt(selected));
}
this.mTransientValue = true;
} else {
if (this.currentSearchString)
this.value = this.currentSearchString;
this.setTextValue(this.currentSearchString);
this.mTransientValue = false;
}
// move cursor to the end
this.mInputElt.setSelectionRange(this.value.length, this.value.length);
this.ignoreInputEvent = false;
@ -1030,17 +1033,18 @@
this.ignoreInputEvent = true;
if (match.indexOf(entry) == 0) {
var endPoint = this.value.length;
this.value = this.value + resultValue.substr(endPoint);
this.setTextValue(this.value + resultValue.substr(endPoint));
this.mInputElt.setSelectionRange(endPoint, this.value.length);
} else {
if (this.autoFillAfterMatch) {
this.value = this.value + " >> " + resultValue;
this.setTextValue(this.value + " >> " + resultValue);
this.mInputElt.setSelectionRange(entry.length, this.value.length);
} else {
var postIndex = resultValue.indexOf(this.value);
if (postIndex >= 0) {
var startPt = this.value.length;
this.value = this.value + resultValue.substr(startPt+postIndex);
this.setTextValue(this.value +
resultValue.substr(startPt+postIndex));
this.mInputElt.setSelectionRange(startPt, this.value.length);
}
}
@ -1106,6 +1110,22 @@
]]></body>
</method>
<!-- -->
<method name="setTextValue">
<parameter name="aValue"/>
<body><![CDATA[
// Completing a result should simulate the user typing the result,
// so fire an input event.
this.value = aValue;
var evt = document.createEvent("UIEvents");
evt.initUIEvent("input", true, false, window, 0);
var oldIgnoreInput = this.mIgnoreInputEvent;
this.mIgnoreInputEvent = true;
this.dispatchEvent(evt);
this.mIgnoreInputEvent = oldIgnoreInput;
]]></body>
</method>
<!-- -->
<method name="clearResultData">
<body><![CDATA[