More work on autocomplete. NOT YET PART OF THE BUILD
git-svn-id: svn://10.0.0.236/trunk@65599 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
a4a087a39b
commit
48de6c967a
@ -44,4 +44,7 @@ interface nsIAutoCompleteListener : nsISupports {
|
||||
|
||||
/* onAutoComplete is called by the autocomplete session when the search is done or over */
|
||||
void onAutoComplete(in nsIAutoCompleteResults result, in AutoCompleteStatus status);
|
||||
|
||||
/* private param used by the autocomplete widget */
|
||||
attribute nsISupports param;
|
||||
};
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsICollection.idl"
|
||||
#include "nsISupportsArray.idl"
|
||||
|
||||
[scriptable, uuid(88DCFA80-062F-11d4-a449-B36A1A94C0FC)]
|
||||
interface nsIAutoCompleteItem : nsISupports {
|
||||
@ -39,12 +39,11 @@ interface nsIAutoCompleteItem : nsISupports {
|
||||
[scriptable, uuid(88DCFA81-062F-11d4-a449-B36A1A94C0FC)]
|
||||
interface nsIAutoCompleteResults : nsISupports {
|
||||
attribute wstring searchString; // the original search string
|
||||
attribute nsISupports param; // param use by the the search engine
|
||||
|
||||
attribute nsICollection items; // Array of result items (nsIAutoCompleteItem)
|
||||
attribute long defaultItemIndex; // Index (0 base) of the defaut item that will be preselected and displayed
|
||||
attribute wstring defaultComment; // will be displayed in the input element only if the selected item doesn't
|
||||
// have its own comment (blurr type only)
|
||||
attribute nsISupportsArray items; // Array of result items (nsIAutoCompleteItem)
|
||||
attribute long defaultItemIndex; // Index (0 base) of the default item that will be preselected and displayed
|
||||
|
||||
attribute nsISupports param; // param use by the the search engine
|
||||
};
|
||||
|
||||
%{ C++
|
||||
|
||||
@ -36,13 +36,13 @@ interface nsIDOMEvents;
|
||||
interface nsIAutoCompleteSession : nsISupports {
|
||||
|
||||
/* onStartLookup is called when the user has stop typing for a predifined elapse time */
|
||||
void onStartLookup(in nsIDOMEvents event, in nsIAutoCompleteResults previousSearchResult,
|
||||
in nsIAutoCompleteListener listener);
|
||||
void onStartLookup(in nsIDOMEvents event, in wstring searchString,
|
||||
in nsIAutoCompleteResults previousSearchResult, in nsIAutoCompleteListener listener);
|
||||
|
||||
/* onStopLookup is called each time the user press a key */
|
||||
void onStopLookup(in nsIDOMEvents event);
|
||||
|
||||
/* onAutoComplete is called either when the user press enter/return or when the input element loose focus */
|
||||
void onAutoComplete(in nsIDOMEvents event, in nsIAutoCompleteResults previousSearchResult,
|
||||
in nsIAutoCompleteListener listener);
|
||||
void onAutoComplete(in nsIDOMEvents event, in wstring searchString,
|
||||
in nsIAutoCompleteResults previousSearchResult, in nsIAutoCompleteListener listener);
|
||||
};
|
||||
|
||||
@ -1,129 +1,120 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<bindings id="autocompleteBindings"
|
||||
xmlns="http://www.mozilla.org/xbl"
|
||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<binding name="autocomplete" extends="xul:box">
|
||||
<content>
|
||||
<bindings id="autocompleteBindings"
|
||||
xmlns="http://www.mozilla.org/xbl"
|
||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<binding name="autocomplete" extends="xul:box">
|
||||
<content excludes="template,observes,menupopup">
|
||||
<xul:box
|
||||
onkeydown="me = this.parentNode;
|
||||
me.callListener('stopLookup', this);
|
||||
if (me.autoCompleteTimer) {
|
||||
onkeydown=" me = this.parentNode;
|
||||
me.callListener(this, event, 'stopLookup');
|
||||
if (me.autoCompleteTimer) {
|
||||
clearTimeout(me.autoCompleteTimer);
|
||||
dump(' Clear timer id=' + me.autoCompleteTimer + '\n');
|
||||
me.autoCompleteTimer = 0;
|
||||
}"
|
||||
onkeyup="me = this.parentNode;
|
||||
if (me.autoCompleteTimer)
|
||||
clearTimeout(me.autoCompleteTimer);
|
||||
if (event.which != 13) {
|
||||
me.needToAutocomplete = true;
|
||||
me.autoCompleteTimer = setTimeout(me.callListener, me.timeout, 'startLookup', this);
|
||||
dump('timer id=' + me.autoCompleteTimer + ', timeout=' + me.timeout + '\n');
|
||||
}
|
||||
"
|
||||
}"
|
||||
onkeyup=" me = this.parentNode;
|
||||
if (me.autoCompleteTimer)
|
||||
clearTimeout(me.autoCompleteTimer);
|
||||
if (event.which != 13) {
|
||||
me.needToAutocomplete = true;
|
||||
me.autoCompleteTimer = setTimeout(me.callListener, me.timeout, this, event, 'startLookup');
|
||||
}"
|
||||
>
|
||||
|
||||
<xul:textfield class="addressingWidget" inherits="value,timeout"/>
|
||||
<xul:menupopup/>
|
||||
<xul:menupopup>
|
||||
<xul:menuitem id="0" value="item 1"/>
|
||||
<xul:menuitem id="2" value="item 2"/>
|
||||
</xul:menupopup>
|
||||
</xul:box>
|
||||
</content>
|
||||
</content>
|
||||
|
||||
<interface>
|
||||
|
||||
<property name="value" onset="dump('SET VALUE ATTRIBUTE\n');return this.anonymousContent[0].firstChild.value = val;"
|
||||
<interface>
|
||||
<property name="value" onset="return this.anonymousContent[0].firstChild.value = val;"
|
||||
onget="return this.anonymousContent[0].firstChild.value;"/>
|
||||
|
||||
<property name="timeout" onset="return this.setAttribute('timeout', val);"
|
||||
onget="return this.getAttribute('timeout');"/>
|
||||
|
||||
<property name="autoCompleteSession">
|
||||
<property name="autoCompleteSession">
|
||||
<![CDATA[
|
||||
searchSession = 'component://' + unescape(this.getAttribute('searchSessionClass'));
|
||||
try {
|
||||
Components.classes[searchSession].getService(Components.interfaces.nsIAbAutoCompleteSession);
|
||||
} catch (e) {}
|
||||
if (this.getAttribute('searchSessionClass') != "") {
|
||||
searchSession = 'component://' + unescape(this.getAttribute('searchSessionClass'));
|
||||
try {
|
||||
Components.classes[searchSession].getService(Components.interfaces.nsIAutoCompleteSession);
|
||||
} catch (e) {}
|
||||
}
|
||||
]]>
|
||||
</property>
|
||||
</property>
|
||||
|
||||
<property name="autoCompleteTimer">
|
||||
<property name="autoCompleteTimer">
|
||||
<![CDATA[
|
||||
0;
|
||||
]]>
|
||||
</property>
|
||||
|
||||
<property name="autoCompleteListener">
|
||||
<![CDATA[
|
||||
({
|
||||
onAutoCompleteResult: function(aItem, aOriginalString, aMatch)
|
||||
{
|
||||
dump("onAutoCompleteResult, item=" + aItem + ", match=" + aMatch + "\n");
|
||||
dump("textfield= " + aItem.anonymousContent[0].firstChild + "\n");
|
||||
dump("input=" + aItem.anonymousContent[0].firstChild.anonymousContent[0].firstChild + "\n");
|
||||
if ( aItem )
|
||||
{
|
||||
aItem.value = aMatch;
|
||||
}
|
||||
}
|
||||
})
|
||||
]]>
|
||||
</property>
|
||||
</property>
|
||||
|
||||
<method name="autoComplete">
|
||||
<argument name="aSearchString"/>
|
||||
<argument name="resultListener"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
return this.autoCompleteSession.autoComplete(null, this, aSearchString, this.autoCompleteListener);
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
<property name="autoCompleteListener">
|
||||
<![CDATA[
|
||||
({
|
||||
onAutoComplete: function(result, status) {
|
||||
dump("onAutoComplete, result=" + result + ", status=" + status + "\n");
|
||||
item = result.items.QueryElementAt(result.defaultItemIndex, Components.interfaces.nsIAutoCompleteItem);
|
||||
this.param.value = item.value;
|
||||
menu = this.param.anonymousContent[0].childNodes[1];
|
||||
dump("menun=" + menu + "\n");
|
||||
//TODO: show the popup menu now. How do we to that?
|
||||
},
|
||||
|
||||
<method name="callListener">
|
||||
<argument name="action"/>
|
||||
<argument name="me"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
dump("callListener, action=" + action + ", me=" + me + "\n");
|
||||
switch (action) {
|
||||
case 'startLookup':
|
||||
dump('>>> startLookup...\n');
|
||||
break;
|
||||
case 'stopLookup':
|
||||
dump('>>> stopLookup...\n');
|
||||
break;
|
||||
case 'autoComplete':
|
||||
dump('>>> autoComplete...\n');
|
||||
if (this.autoCompleteTimer) {
|
||||
clearTimeout(this.autoCompleteTimer);
|
||||
this.autoCompleteTimer = 0;
|
||||
}
|
||||
autoComplete(me.value, me.autoCompleteListener);
|
||||
this.needToAutocomplete = false;
|
||||
break;
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
</interface>
|
||||
param: this
|
||||
})
|
||||
]]>
|
||||
</property>
|
||||
|
||||
<method name="callListener">
|
||||
<argument name="me"/>
|
||||
<argument name="event"/>
|
||||
<argument name="action"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
dump("callListener, action=" + action + ", me=" + me + "\n");
|
||||
switch (action) {
|
||||
case 'startLookup':
|
||||
dump('>>> startLookup...\n');
|
||||
//TODO: this.autoCompleteSession.onStartLookup(event, me.value, null, me.autoCompleteListener);
|
||||
break;
|
||||
|
||||
case 'stopLookup':
|
||||
dump('>>> stopLookup...\n');
|
||||
//TODO: hide the popup menu now. How do we to that?
|
||||
this.autoCompleteSession.onStopLookup(event, me.value, null, me.autoCompleteListener);
|
||||
break;
|
||||
|
||||
case 'autoComplete':
|
||||
dump('>>> autoComplete...\n');
|
||||
if (this.autoCompleteTimer) {
|
||||
clearTimeout(this.autoCompleteTimer);
|
||||
this.autoCompleteTimer = 0;
|
||||
}
|
||||
this.autoCompleteSession.onAutoComplete(event, me.value, null, me.autoCompleteListener);
|
||||
this.needToAutocomplete = false;
|
||||
break;
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
</interface>
|
||||
|
||||
<handlers>
|
||||
<handler type="keypress" keycode="vk_return"
|
||||
value="dump('value=' + this.value + '\n'); this.callListener('autoComplete', me);"
|
||||
/>
|
||||
<handler type="keypress" keycode="vk_return"
|
||||
value="dump('value=' + this.value + '\n'); this.callListener(this, event, 'autoComplete');"/>
|
||||
|
||||
<handler type="focus" value="this.needToAutocomplete = false;" />
|
||||
<handler type="focus" value="this.needToAutocomplete = false;"/>
|
||||
|
||||
<handler type="blur"
|
||||
value="if (this.needToAutocomplete)
|
||||
this.callListener('autoComplete', this);
|
||||
"
|
||||
/>
|
||||
<handler type="blur"
|
||||
value="if (this.needToAutocomplete) this.callListener(me, event, 'autoComplete');"/>
|
||||
</handlers>
|
||||
|
||||
</binding>
|
||||
</binding>
|
||||
|
||||
|
||||
</bindings>
|
||||
|
||||
@ -139,7 +139,8 @@ NS_IMPL_ISUPPORTS1(nsAutoCompleteResults, nsIAutoCompleteResults)
|
||||
nsAutoCompleteResults::nsAutoCompleteResults() :
|
||||
mDefaultItemIndex(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
NS_NewISupportsArray(getter_AddRefs(mItems));
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsAutoCompleteResults::~nsAutoCompleteResults()
|
||||
@ -173,7 +174,7 @@ NS_IMETHODIMP nsAutoCompleteResults::SetParam(nsISupports * aParam)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAutoCompleteResults::GetItems(nsICollection * *aItems)
|
||||
NS_IMETHODIMP nsAutoCompleteResults::GetItems(nsISupportsArray * *aItems)
|
||||
{
|
||||
if (!aItems) return NS_ERROR_NULL_POINTER;
|
||||
*aItems = mItems;
|
||||
@ -181,7 +182,7 @@ NS_IMETHODIMP nsAutoCompleteResults::GetItems(nsICollection * *aItems)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAutoCompleteResults::SetItems(nsICollection * aItems)
|
||||
NS_IMETHODIMP nsAutoCompleteResults::SetItems(nsISupportsArray * aItems)
|
||||
{
|
||||
mItems = aItems;
|
||||
return NS_OK;
|
||||
@ -199,16 +200,3 @@ NS_IMETHODIMP nsAutoCompleteResults::SetDefaultItemIndex(PRInt32 aDefaultItemInd
|
||||
mDefaultItemIndex = aDefaultItemIndex;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAutoCompleteResults::GetDefaultComment(PRUnichar * *aDefaultComment)
|
||||
{
|
||||
if (!aDefaultComment) return NS_ERROR_NULL_POINTER;
|
||||
*aDefaultComment = mDefaultComment.ToNewUnicode();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAutoCompleteResults::SetDefaultComment(const PRUnichar * aDefaultComment)
|
||||
{
|
||||
mDefaultComment = aDefaultComment;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -65,13 +65,11 @@ public:
|
||||
NS_DECL_NSIAUTOCOMPLETERESULTS
|
||||
|
||||
private:
|
||||
nsString mSearchString;
|
||||
nsCOMPtr<nsISupports> mParam;
|
||||
nsCOMPtr<nsIDOMHTMLInputElement> mInputElement;
|
||||
|
||||
nsCOMPtr<nsICollection> mItems;
|
||||
nsString mSearchString;
|
||||
nsCOMPtr<nsISupportsArray> mItems;
|
||||
PRInt32 mDefaultItemIndex;
|
||||
nsString mDefaultComment;
|
||||
|
||||
nsCOMPtr<nsISupports> mParam;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user