home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / toolkit.jar / content / global / autocomplete.xml < prev    next >
Extensible Markup Language  |  2002-12-06  |  57KB  |  1,572 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="autocompleteBindings"
  4.           xmlns="http://www.mozilla.org/xbl"
  5.           xmlns:html="http://www.w3.org/1999/xhtml"
  6.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  7.           xmlns:xbl="http://www.mozilla.org/xbl">
  8.  
  9.   <binding id="autocomplete"
  10.            extends="chrome://global/content/bindings/textbox.xml#textbox">
  11.     <resources>
  12.       <stylesheet src="chrome://global/content/autocomplete.css"/>
  13.       <stylesheet src="chrome://global/skin/autocomplete.css"/>
  14.     </resources>
  15.  
  16.     <content sizetopopup="pref">
  17.       <xul:hbox class="autocomplete-textbox-container" flex="1">
  18.         <children includes="image|deck">
  19.           <xul:image class="autocomplete-icon" allowevents="true"/>
  20.         </children>
  21.  
  22.         <xul:hbox class="textbox-input-box" flex="1" xbl:inherits="tooltiptext=inputtooltiptext">
  23.           <html:input anonid="input" class="autocomplete-textbox textbox-input"
  24.                       flex="1" allowevents="true"
  25.                       xbl:inherits="tooltiptext=inputtooltiptext,onfocus,onblur,value,type,maxlength,disabled,size,readonly,userAction"/>
  26.         </xul:hbox>
  27.       </xul:hbox>
  28.                           
  29.       <xul:dropmarker class="autocomplete-history-dropmarker" allowevents="true"
  30.                       xbl:inherits="open,hidden=disablehistory" anonid="historydropmarker"/>
  31.  
  32.       <xul:popupset>
  33.         <xul:popup ignorekeys="true" anonid="popup" class="autocomplete-result-popup" hidden="true" xbl:inherits="for=id,nomatch"/>
  34.       </xul:popupset>
  35.       
  36.       <children includes="menupopup"/>
  37.     </content>
  38.  
  39.     <implementation implements="nsIDOMXULMenuListElement, nsIAccessibleProvider">
  40.  
  41.       <constructor><![CDATA[
  42.         // set default property values
  43.         this.ifSetAttribute("timeout", 50);
  44.         this.ifSetAttribute("maxrows", 5);
  45.         this.ifSetAttribute("showpopup", true);
  46.         this.ifSetAttribute("disablehistory", true);
  47.         this.ifSetAttribute("disableKeyNavigation", true);
  48.         
  49.         // initialize the search sessions
  50.         this.searchSessions = this.getAttribute("searchSessions");
  51.         
  52.         // hack to work around lack of bottom-up constructor calling
  53.         if ("initialize" in this.resultsPopup)
  54.           this.resultsPopup.initialize();
  55.       ]]></constructor>
  56.  
  57.       <destructor><![CDATA[
  58.       ]]></destructor>
  59.       
  60.       <!-- =================== PUBLIC PROPERTIES =================== -->
  61.  
  62.       <property name="value"
  63.                 onset="this.ignoreInputEvent = true;
  64.                        this.mInputElt.value = val;
  65.                        this.ignoreInputEvent = false;
  66.                        return val;"
  67.                 onget="return this.mInputElt ? this.mInputElt.value : null;"/>
  68.   
  69.       <property name="focused"
  70.                 onget="return this.getAttribute('focused') == 'true';"/>
  71.  
  72.       <!-- space-delimited string of search session types to use -->
  73.       <property name="searchSessions" onget="return this.getAttribute('searchSessions')">
  74.         <setter><![CDATA[
  75.           val = val ? val : "";
  76.           var list = val.split(" ");
  77.           this.mSessions = {};
  78.           this.mListeners = {};
  79.           this.mLastResults = {};
  80.           this.mLastStatus = {};
  81.  
  82.           for (var i in list) {
  83.             var name = list[i];
  84.             if (name != "") {
  85.               var contractid = "@mozilla.org/autocompleteSession;1?type=" + name;
  86.               try {
  87.                 var session =
  88.                   Components.classes[contractid].getService(Components.interfaces.nsIAutoCompleteSession);
  89.               } catch (e) {
  90.                 dump("### ERROR - unable to create search session \"" + session + "\".\n");
  91.                 break;
  92.               }
  93.               this.mSessions[name] = session;
  94.               this.mListeners[name] = new (this.mAutoCompleteListener)(name);
  95.               this.mLastResults[name] = null;
  96.               this.mLastStatus[name] = null;
  97.               ++this.sessionCount;
  98.             }
  99.           }
  100.         ]]></setter>
  101.       </property>
  102.  
  103.       <!-- the number of sessions currently in use -->
  104.       <field name="sessionCount">0</field>
  105.  
  106.       <!-- number of milliseconds after a keystroke before a search begins -->
  107.       <property name="timeout"
  108.                 onset="this.setAttribute('timeout', val); return val;"
  109.                 onget="var t = parseInt(this.getAttribute('timeout')); return t ? t : 0;"/>
  110.  
  111.       <!-- number of milliseconds after a keystroke before a search begins -->
  112.       <property name="maxRows"
  113.                 onset="this.setAttribute('maxrows', val); return val;"
  114.                 onget="var t = parseInt(this.getAttribute('maxrows')); return t ? t : 0;"/>
  115.  
  116.       <!-- option for filling the textbox with the best match while typing 
  117.            and selecting the difference -->
  118.       <property name="autoFill"
  119.                 onset="this.setAttribute('autoFill', val); return val;"
  120.                 onget="return this.getAttribute('autoFill') == 'true';"/>
  121.  
  122.       <!-- if the resulting match string is not at the beginning of the typed string,
  123.            this will optionally autofill like this "bar |>> foobar|" -->
  124.       <property name="autoFillAfterMatch"
  125.                 onset="this.setAttribute('autoFillAfterMatch', val); return val;"
  126.                 onget="return this.getAttribute('autoFillAfterMatch') == 'true';"/>
  127.                 
  128.       <!-- toggles a second column in the results list which contains
  129.            the string in the comment field of each autocomplete result -->
  130.       <property name="showCommentColumn"
  131.                 onget=
  132.           "return this.getAttribute('showCommentColumn') == 'true';">
  133.         <setter><![CDATA[
  134.  
  135.           var currentState = this.getAttribute('showCommentColumn');          
  136.  
  137.           // if comment column has been switched from off to on
  138.           //
  139.           if (val && (currentState == 'false')) { 
  140.  
  141.             // reset the flex on the value column and add the comment column
  142.             //
  143.             document.getElementById("value").setAttribute("flex", 2);
  144.             this.resultsPopup.addColumn({id: "comment", flex: 1});
  145.  
  146.           // if comment column has been switched from on to off
  147.           //
  148.           } else if (!val && (currentState == 'true')) {
  149.  
  150.             // reset the flex on the value column and add the comment column
  151.             //
  152.             document.getElementById("value").setAttribute("flex", 1);
  153.             this.resultsPopup.removeColumn('comment');
  154.           }
  155.  
  156.           // save and return the current state
  157.           //
  158.           this.setAttribute('showCommentColumn', val); return val;
  159.         ]]></setter>
  160.       </property>
  161.  
  162.                 
  163.       <!-- option for completing to the default result whenever the user hits
  164.            enter or the textbox loses focus -->
  165.       <property name="forceComplete"
  166.                 onset="this.setAttribute('forceComplete', val); return val;"
  167.                 onget="return this.getAttribute('forceComplete') == 'true';"/>
  168.  
  169.       <!-- option to show the popup containing the results -->
  170.       <property name="showPopup"
  171.                 onset="this.setAttribute('showpopup', val); return val;"
  172.                 onget="return this.getAttribute('showpopup') == 'true';"/>
  173.  
  174.       <!-- option to keep the popup open while typing, even when there are no matches -->
  175.       <property name="alwaysOpenPopup"
  176.                 onset="this.setAttribute('alwaysopenpopup', val); return val;"
  177.                 onget="return this.getAttribute('alwaysopenpopup') == 'true';"/>
  178.  
  179.       <!-- option to allow scrolling through the list via the tab key, rather than
  180.            tab moving focus out of the textbox -->
  181.       <property name="tabScrolling"
  182.                 onset="return this.setAttribute('tabScrolling', val); return val;"
  183.                 onget="return this.getAttribute('tabScrolling') == 'true';"/>
  184.  
  185.       <!-- option to turn off autocomplete -->
  186.       <property name="disableAutocomplete"
  187.                 onset="this.setAttribute('disableAutocomplete', val); return val;"
  188.                 onget="return this.getAttribute('disableAutocomplete') == 'true';"/>
  189.  
  190.       <!-- option to completely ignore any blur events while  
  191.            searches are still going on.  This is useful so that nothing
  192.            gets autopicked if the window is required to lose focus for
  193.            some reason (eg in LDAP autocomplete, another window may be
  194.            brought up so that the user can enter a password to authenticate
  195.            to an LDAP server).  -->
  196.       <property name="ignoreBlurWhileSearching"
  197.                 onset="this.setAttribute('ignoreBlurWhileSearching', val); return val;"
  198.                 onget="return this.getAttribute('ignoreBlurWhileSearching') == 'true';"/>
  199.  
  200.       <property name="minResultsForPopup"
  201.                 onset="this.setAttribute('minResultsForPopup', val); return val;"
  202.                 onget="var t = parseInt(this.getAttribute('minResultsForPopup')); return t ? t : 0;"/>
  203.       
  204.       <!-- state which indicates the current action being performed by the user.
  205.            Possible values are : none, typing, scrolling -->
  206.       <property name="userAction"
  207.                 onset="this.setAttribute('userAction', val); return val;"
  208.                 onget="return this.getAttribute('userAction');"/>
  209.       
  210.       <!-- state which indicates if the last search had no matches -->
  211.       <field name="noMatch">true</field>
  212.  
  213.       <!-- state which indicates a search is currently happening -->
  214.       <field name="isSearching">false</field>
  215.  
  216.       <!-- state which indicates a search timeout is current waiting -->
  217.       <property name="isWaiting" 
  218.                 onget="return this.mAutoCompleteTimer != 0;"/>
  219.  
  220.       <!-- reference to the results popup element -->
  221.       <field name="resultsPopup"><![CDATA[
  222.         var elt = document.getAnonymousElementByAttribute(this, "anonid", "popup");
  223.         elt.__AUTOCOMPLETE_BOX__ = this;
  224.         elt;
  225.       ]]></field>
  226.  
  227.       <!-- nsIAccessibleProvider --> 
  228.       <property name="accessible">
  229.         <getter>
  230.           <![CDATA[
  231.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  232.             return accService.createXULComboboxAccessible(this);
  233.           ]]>
  234.         </getter>
  235.       </property>
  236.  
  237.       <!-- nsIDOMXULMenuListElement properties -->
  238.  
  239.       <property name="editable" readonly="true" onget="return true;" />  
  240.  
  241.       <property name="crop" onset="this.setAttribute('crop',val); return val;"
  242.                             onget="return this.getAttribute('crop');"/>
  243.  
  244.       <property name="label" onset="this.setAttribute('label',val); return val;"
  245.                              onget="return this.getAttribute('label');"/>
  246.  
  247.       <property name="open">
  248.         <getter>
  249.           <![CDATA[
  250.             return this.getAttribute('open') == 'true';
  251.           ]]>
  252.         </getter>
  253.         <setter>
  254.           <![CDATA[
  255.             var historyPopup = document.getAnonymousElementByAttribute(this, "anonid", "historydropmarker");
  256.             if (val) {
  257.               this.setAttribute('open',true); 
  258.               historyPopup.showPopup();
  259.             }
  260.             else {
  261.               this.removeAttribute('open');
  262.               historyPopup.hidePopup();
  263.             }
  264.           ]]>
  265.         </setter>
  266.       </property>
  267.  
  268.       <!-- =================== PRIVATE PROPERTIES =================== -->
  269.  
  270.       <field name="mSessions">null</field>
  271.       <field name="mListeners">null</field>
  272.       <field name="mLastResults">null</field>
  273.       <field name="mLastStatus">null</field>
  274.       <field name="mLastKeyCode">null</field>
  275.       <field name="mAutoCompleteTimer">0</field>
  276.       <field name="mMenuOpen">false</field>
  277.       <field name="mFireAfterSearch">false</field>
  278.       <field name="mFinishAfterSearch">false</field>
  279.       <field name="mNeedToFinish">false</field>
  280.       <field name="mNeedToComplete">false</field>
  281.       <field name="mTransientValue">false</field>
  282.       <field name="mView">null</field>
  283.       <field name="currentSearchString">null</field>
  284.       <field name="ignoreInputEvent">false</field>
  285.       <field name="oninit">null</field>
  286.       <field name="ontextcommand">null</field>
  287.       <field name="ontextrevert">null</field>
  288.       <field name="onerrorcommand">null</field>
  289.       <field name="mDefaultMatchFilled">false</field>
  290.  
  291.       <field name="mAutoCompleteListener"><![CDATA[
  292.         var listener = function(aSession) { this.sessionName = aSession };
  293.         listener.prototype = {
  294.           param: this,
  295.           sessionName: null,
  296.           onAutoComplete: function(aResults, aStatus) 
  297.           {
  298.             this.param.processResults(this.sessionName, aResults, aStatus);
  299.           }
  300.         };
  301.         listener;
  302.       ]]></field>
  303.  
  304.       <field name="mInputElt"><![CDATA[
  305.         document.getAnonymousElementByAttribute(this, "anonid", "input");
  306.       ]]></field>
  307.  
  308.       <!-- =================== PUBLIC METHODS =================== -->
  309.  
  310.       <!-- get the result object from the autocomplete results from a specific session -->
  311.       <method name="getResultAt">
  312.         <parameter name="aIndex"/>
  313.         <body><![CDATA[
  314.           var obj = this.convertIndexToSession(aIndex);
  315.           if (obj && this.mLastResults[obj.session]) {
  316.             var nsIAutoCompleteItem = Components.interfaces.nsIAutoCompleteItem;
  317.             if (obj.index >= 0) {
  318.               var item = this.mLastResults[obj.session].items.QueryElementAt(obj.index, nsIAutoCompleteItem);
  319.               return item;
  320.             }
  321.           }
  322.           return null;
  323.         ]]></body>
  324.       </method>
  325.  
  326.       <!-- get the autocomplete session status returned by the session
  327.            that a given item came from -->
  328.       <method name="getSessionStatusAt">
  329.         <parameter name="aIndex"/>
  330.         <body><![CDATA[
  331.           var obj = this.convertIndexToSession(aIndex);
  332.           return obj ? this.mLastStatus[obj.session] : null;
  333.         ]]></body>
  334.       </method>
  335.  
  336.  
  337.       <!-- get a value from the autocomplete results as a string via an absolute index-->
  338.       <method name="getResultValueAt">
  339.         <parameter name="aIndex"/>
  340.         <body><![CDATA[
  341.           var obj = this.convertIndexToSession(aIndex);
  342.           return obj ? this.getSessionValueAt(obj.session, obj.index) : null;
  343.         ]]></body>
  344.       </method>
  345.  
  346.       <!-- get the result object from the autocomplete results from a specific session -->
  347.       <method name="getSessionResultAt">
  348.         <parameter name="aSession"/>
  349.         <parameter name="aIndex"/>
  350.         <body><![CDATA[
  351.           var session = this.mLastResults[aSession];
  352.           if (session) {
  353.             var item = session.items.QueryElementAt(aIndex, Components.interfaces.nsIAutoCompleteItem);
  354.             return item;
  355.           }
  356.           return null;
  357.         ]]></body>
  358.       </method>
  359.  
  360.       <!-- get a value from the autocomplete results as a string from a specific session -->
  361.       <method name="getSessionValueAt">
  362.         <parameter name="aSession"/>
  363.         <parameter name="aIndex"/>
  364.         <body><![CDATA[
  365.           var result = this.getSessionResultAt(aSession, aIndex);
  366.           if (result)
  367.             return result.value;
  368.           return null;
  369.         ]]></body>
  370.       </method>
  371.  
  372.       <!-- get the total number of results in a specific session or overall if session is null-->
  373.       <method name="getResultCount">
  374.         <parameter name="aSession"/>
  375.         <body><![CDATA[
  376.           return this.view.rowCount;
  377.         ]]></body>
  378.       </method>
  379.       
  380.       <!-- get a session object by index -->
  381.       <method name="getSession">
  382.         <parameter name="aIndex"/>
  383.         <body><![CDATA[
  384.           var idx = 0;
  385.           for (var name in this.mSessions) {
  386.             if (idx == aIndex)
  387.               return this.mSessions[name];
  388.             ++idx;
  389.           }
  390.           return null;
  391.         ]]></body>
  392.       </method>
  393.  
  394.       <!-- get a session object by name -->
  395.       <method name="getSessionByName">
  396.         <parameter name="aSessionName"/>
  397.         <body><![CDATA[
  398.           return this.mSessions[aSessionName];
  399.         ]]></body>
  400.       </method>
  401.  
  402.       <!-- add a session by reference -->
  403.       <method name="addSession">
  404.         <parameter name="aSession"/>
  405.         <body><![CDATA[
  406.           ++this.sessionCount;
  407.           var name = "anon_"+this.sessionCount;
  408.           this.mSessions[name] = aSession;
  409.           this.mListeners[name] = new (this.mAutoCompleteListener)(name);
  410.           this.mLastResults[name] = null;
  411.           this.mLastStatus[name] = null;
  412.         ]]></body>
  413.       </method>
  414.  
  415.       <!-- remove a session by reference -->
  416.       <method name="removeSession">
  417.         <parameter name="aSession"/>
  418.         <body><![CDATA[
  419.           for (var name in this.mSessions) {
  420.             if (this.mSessions[name] == aSession) {
  421.               delete this.mSessions[name];
  422.               delete this.mListeners[name];
  423.               delete this.mLastResults[name];
  424.               delete this.mLastStatus[name];
  425.               --this.sessionCount;
  426.               break;
  427.             }
  428.           }
  429.         ]]></body>
  430.       </method>
  431.  
  432.       <!-- make this widget listen to all of the same autocomplete sessions 
  433.            from another autocomplete widget -->
  434.       <method name="syncSessions">
  435.         <parameter name="aCopyFrom"/>
  436.         <body><![CDATA[
  437.           this.sessionCount = aCopyFrom.sessionCount;
  438.           this.mSessions = {};
  439.           this.mListeners = {};
  440.           this.mLastResults = {};
  441.           this.mLastStatus = {};
  442.           for (var name in aCopyFrom.mSessions) {
  443.             this.mSessions[name] = aCopyFrom.mSessions[name];
  444.             this.mListeners[name] = new (this.mAutoCompleteListener)(name);
  445.             this.mLastResults[name] = null;
  446.             this.mLastStatus[name] = null;
  447.           }
  448.         ]]></body>
  449.       </method>
  450.  
  451.       <!-- get the first session that has results -->
  452.       <method name="getDefaultSession">
  453.         <body><![CDATA[
  454.           for (var name in this.mLastResults) {
  455.             var results = this.mLastResults[name];
  456.             if (results && results.items.Count() > 0)
  457.               return name;
  458.           }
  459.           return null;
  460.         ]]></body>
  461.       </method>
  462.  
  463.       <!-- empty the cached result data and empty the results popup -->
  464.       <method name="clearResults">
  465.         <parameter name="aInvalidate"/>
  466.         <body><![CDATA[
  467.           this.clearResultData();
  468.           this.clearResultElements(aInvalidate);
  469.         ]]></body>
  470.       </method>
  471.  
  472.       <!-- =================== PRIVATE METHODS =================== -->
  473.   
  474.       <!-- ::::::::::::: session searching ::::::::::::: -->
  475.  
  476.       <!--  -->
  477.       <method name="callListener">
  478.         <parameter name="me"/>
  479.         <parameter name="aAction"/>
  480.         <body><![CDATA[
  481.           // bail if the binding was detached or the element removed from
  482.           // document during the timeout
  483.           if (!("startLookup" in me) || !me.ownerDocument || !me.parentNode)
  484.             return;
  485.  
  486.           me.clearTimer();
  487.             
  488.           if (me.disableAutocomplete)
  489.             return;
  490.  
  491.           switch (aAction) {
  492.             case "startLookup":
  493.               me.startLookup();
  494.               break;
  495.  
  496.             case "stopLookup":
  497.               me.stopLookup();
  498.               break;
  499.  
  500.             case "autoComplete":
  501.               me.autoComplete();
  502.               break;
  503.           }
  504.         ]]></body>
  505.       </method>
  506.  
  507.       <!--  -->
  508.       <method name="startLookup">
  509.         <body><![CDATA[
  510.           var str = this.value;
  511.           
  512.           this.isSearching = true;
  513.           this.mSessionReturns = this.sessionCount;
  514.           this.mFailureCount = 0;
  515.           this.mFailureItems = 0;
  516.           this.mDefaultMatchFilled = false; // clear out our prefill state.
  517.  
  518.           // tell each session to start searching...
  519.           for (var name in this.mSessions)
  520.             try {
  521.               this.mSessions[name].onStartLookup(str, this.mLastResults[name], this.mListeners[name]);
  522.             } catch (e) {
  523.               --this.mSessionReturns;
  524.               this.searchFailed();
  525.             }
  526.         ]]></body>
  527.       </method>
  528.  
  529.       <!--  -->
  530.       <method name="stopLookup">
  531.         <body><![CDATA[
  532.           for (var name in this.mSessions)
  533.             this.mSessions[name].onStopLookup();
  534.         ]]></body>
  535.       </method>
  536.  
  537.       <!--  -->
  538.       <method name="autoComplete">
  539.         <body><![CDATA[
  540.           for (var name in this.mSessions)
  541.             this.mSessions[name].onAutoComplete(this.value, 
  542.                                                 this.mLastResults[name],
  543.                                                 this.mListeners[name]);
  544.         ]]></body>
  545.       </method>
  546.  
  547.       <!--  -->
  548.       <method name="processResults">
  549.         <parameter name="aSessionName"/>
  550.         <parameter name="aResults"/>
  551.         <parameter name="aStatus"/>
  552.         <body><![CDATA[
  553.           if (this.disableAutocomplete)
  554.             return;
  555.  
  556.           --this.mSessionReturns;
  557.  
  558.           var firstReturn = this.mSessionReturns == (this.sessionCount-1) - this.mFailureCount;
  559.           
  560.           if (firstReturn)
  561.             this.clearResults(false); // clear results, but don't repaint yet
  562.  
  563.           this.mLastStatus[aSessionName] = aStatus;
  564.  
  565.           // check the many criteria for failure
  566.           if (aStatus == Components.interfaces.nsIAutoCompleteStatus.failed ||
  567.               aStatus == Components.interfaces.nsIAutoCompleteStatus.ignored || 
  568.               aStatus == Components.interfaces.nsIAutoCompleteStatus.noMatch ||
  569.               aResults == null ||
  570.               aResults.items.Count() == 0 ||
  571.               aResults.searchString != this.currentSearchString)
  572.           {
  573.             this.mLastResults[aSessionName] = null;
  574.             this.searchFailed();
  575.             return;
  576.           } else if (aStatus == 
  577.                      Components.interfaces.nsIAutoCompleteStatus.failureItems){
  578.             ++this.mFailureItems;
  579.           }
  580.           
  581.           this.mLastResults[aSessionName] = aResults;
  582.  
  583.           this.autoFillInput(aSessionName, aResults, false);
  584.  
  585.           // always call openResultPopup...we may not have opened it
  586.           // if a previous search session didn't return enough search results.
  587.           // it's smart and doesn't try to open itself multiple times...
  588.           // be sure to add our result elements before calling openResultPopuup as we need
  589.           // to know the total # of results found so far.
  590.           this.addResultElements(aSessionName, aResults);      
  591.           this.openResultPopup();
  592.          
  593.           // if this is the last session to return... 
  594.           if (this.mSessionReturns == 0) 
  595.             this.postSearchCleanup();
  596.                
  597.         ]]></body>
  598.       </method>
  599.  
  600.       <!-- called each time a search fails, except when failure items need
  601.            to be displayed. If all searches have failed, clear the list
  602.            and close the popup -->
  603.       <method name="searchFailed">
  604.         <body><![CDATA[
  605.           // if it's the last session to return, time to clean up...
  606.           if (this.mSessionReturns == 0)
  607.             this.postSearchCleanup();
  608.  
  609.           ++this.mFailureCount;
  610.           
  611.           // if all searches are done and they all failed...
  612.           if (this.mSessionReturns == 0 && this.mFailureCount == this.sessionCount) {
  613.             if (this.alwaysOpenPopup) {
  614.               this.clearResults(true); // clear data and repaint empty
  615.               
  616.               if (this.value) {
  617.                 this.openResultPopup();
  618.               } else
  619.                 this.closeResultPopup(); 
  620.             } else
  621.               this.closeResultPopup(); 
  622.           }
  623.         ]]></body>
  624.       </method>
  625.  
  626.       <!-- does some stuff after a search is done (success or failure) -->
  627.       <method name="postSearchCleanup">
  628.         <body><![CDATA[
  629.           this.isSearching = false;
  630.  
  631.           // figure out if there are no matches in all search sessions
  632.           var failed = true;
  633.           for (var name in this.mSessions) {
  634.             if (this.mLastResults[name])
  635.               failed = this.mLastResults[name].items.Count() < 1;
  636.             if (!failed)
  637.               break;
  638.           }
  639.           this.noMatch = failed;
  640.           if (this.noMatch)
  641.             this.setAttribute("nomatch", 1);
  642.           else
  643.             this.removeAttribute("nomatch");
  644.           
  645.           // if we have processed all of our searches, and none of them gave us a default index,
  646.           // then we should try to auto fill the input field with the first match. 
  647.           // note: autoFillInput is smart enough to kick out if we've already prefilled something...
  648.           if (!this.noMatch) {
  649.              var defaultSession = this.getDefaultSession();
  650.              if (defaultSession)
  651.                 this.autoFillInput(defaultSession, this.mLastResults[defaultSession], true);         
  652.           }
  653.           
  654.           if (this.mFinishAfterSearch)
  655.             this.finishAutoComplete(false, this.mFireAfterSearch, null);
  656.         ]]></body>
  657.       </method>
  658.  
  659.       <!-- when the focus exits the widget or user hits return, 
  660.            determine what value to leave in the textbox -->
  661.       <method name="finishAutoComplete">
  662.         <parameter name="aForceComplete"/>
  663.         <parameter name="aFireTextCommand"/>
  664.         <parameter name="aTriggeringEvent"/>
  665.         <body><![CDATA[
  666.           this.mFinishAfterSearch = false;
  667.           this.mFireAfterSearch = false;
  668.           if (this.mNeedToFinish && !this.disableAutocomplete) {
  669.             // if a search is happening at this juncture, bail out of this function
  670.             // and let the search finish, and tell it to come back here when it's done
  671.             if (this.isSearching || this.isWaiting) {
  672.               this.mFinishAfterSearch = true;
  673.               this.mFireAfterSearch = aFireTextCommand;
  674.               return;
  675.             }
  676.             
  677.             this.mNeedToFinish = false;
  678.  
  679.             // set textbox value to either override value, or default search result 
  680.             var val = this.resultsPopup.getOverrideValue();
  681.             if (val) {
  682.               this.value = val;
  683.             } else if (this.mTransientValue) {
  684.               // do nothing
  685.             } else if (this.forceComplete && (this.mNeedToComplete || aForceComplete)) {
  686.               var defaultSession = this.getDefaultSession();
  687.  
  688.               // we want to use the default item index for the first session which gave us a valid
  689.               // default item index...
  690.               var results;
  691.               for (var name in this.mLastResults) {
  692.                results = this.mLastResults[name];
  693.                if (results && results.items.Count() > 0 && results.defaultItemIndex != -1)
  694.                {
  695.                  defaultSession = name;
  696.                  break;
  697.                }
  698.               }
  699.  
  700.               if (defaultSession) {
  701.                 results = this.mLastResults[defaultSession];
  702.                 if (results && !this.noMatch)
  703.                   if (results.defaultItemIndex != -1)
  704.                   this.value = this.getSessionValueAt(defaultSession, results.defaultItemIndex);
  705.                   else
  706.                     this.value = this.getSessionValueAt(defaultSession, 0); // preselect the first one...
  707.               }
  708.             }
  709.  
  710.             this.closeResultPopup();
  711.           }
  712.           
  713.           this.mNeedToComplete = false;
  714.           this.clearTimer();
  715.  
  716.           if (aFireTextCommand)
  717.             this._fireEvent("textcommand", this.userAction, aTriggeringEvent);
  718.         ]]></body>
  719.       </method>
  720.  
  721.       <!--  when the user clicks an entry in the autocomplete popup -->
  722.       <method name="onResultClick">
  723.         <body><![CDATA[
  724.          // set textbox value to either override value, or the clicked result
  725.           var errItem=null;
  726.           var val = this.resultsPopup.getOverrideValue();
  727.             if (val)
  728.               this.value = val;
  729.           else if (this.resultsPopup.selectedIndex != null &&
  730.                    !this.noMatch) {
  731.             if (this.getSessionStatusAt(this.resultsPopup.selectedIndex) ==
  732.                 Components.interfaces.nsIAutoCompleteStatus.failureItems) {
  733.               this.value = this.currentSearchString;
  734.               this.mTransientValue = true;
  735.               errItem = this.getResultAt(this.resultsPopup.selectedIndex);
  736.             } else { 
  737.               this.value = this.getResultValueAt(
  738.                                              this.resultsPopup.selectedIndex);
  739.             }
  740.           }
  741.  
  742.           this.mNeedToFinish = false;
  743.           this.mNeedToComplete = false;
  744.           
  745.           this.closeResultPopup();
  746.  
  747.           this.currentSearchString = "";
  748.  
  749.           if (errItem)
  750.             this._fireEvent("errorcommand", errItem);
  751.           this._fireEvent("textcommand", "clicking");
  752.         ]]></body>
  753.       </method>
  754.  
  755.       <!-- when the user hits escape, revert the previously typed value in the textbox -->
  756.       <method name="undoAutoComplete">
  757.         <body><![CDATA[
  758.           var val = this.currentSearchString;
  759.  
  760.           var ok = this._fireEvent("textrevert");
  761.           if ((ok || ok == undefined) && val)
  762.             this.value = val;
  763.  
  764.           this.userAction = "typing";
  765.  
  766.           this.currentSearchString = this.value;
  767.           this.mNeedToComplete = false;
  768.         ]]></body>
  769.       </method>
  770.  
  771.       <!-- convert an absolute result index into a session name/index pair -->
  772.       <method name="convertIndexToSession">
  773.         <parameter name="aIndex"/>
  774.         <body><![CDATA[
  775.           var idx = 0;
  776.           for (var name in this.mLastResults) {
  777.             if (this.mLastResults[name]) {
  778.               if ((idx+this.mLastResults[name].items.Count())-1 >= aIndex) {
  779.                 return {session: name, index: aIndex-idx};
  780.               }
  781.               idx += this.mLastResults[name].items.Count();
  782.             }
  783.           }
  784.           return null;
  785.         ]]></body>
  786.       </method>
  787.  
  788.       <!-- ::::::::::::: user input handling ::::::::::::: -->
  789.  
  790.       <!--  -->
  791.       <method name="processInput">
  792.         <body><![CDATA[
  793.           // stop current lookup in case it's async.
  794.           this.stopLookup();
  795.           // stop the queued up lookup on a timer
  796.           this.clearTimer();
  797.  
  798.           if (this.ignoreInputEvent)
  799.             return;
  800.           
  801.           if (this.disableAutocomplete)
  802.             return;
  803.  
  804.           this.userAction = "typing";
  805.           this.mNeedToFinish = true;
  806.           this.mTransientValue = false;
  807.           this.mNeedToComplete = true;
  808.           var str = this.value;
  809.           this.currentSearchString = str;
  810.           this.resultsPopup.selectedIndex = null;
  811.           
  812.           // We want to autocomplete only if the user is editing at the end of the text
  813.           if (this.mInputElt.selectionEnd >= str.length)
  814.             this.mAutoCompleteTimer = setTimeout(this.callListener, this.timeout, this, "startLookup");
  815.           else
  816.             this.noMatch = true;
  817.         ]]></body>
  818.       </method>
  819.  
  820.       <!--  -->
  821.       <method name="processKeyPress">
  822.         <parameter name="aEvent"/>
  823.         <body><![CDATA[
  824.           this.mLastKeyCode = aEvent.keyCode;
  825.           
  826.           var killEvent = false;
  827.           
  828.           switch (aEvent.keyCode) {
  829.             case KeyEvent.DOM_VK_TAB:
  830.               if (this.tabScrolling) {
  831.                 // don't kill this event if alt-tab or ctrl-tab is hit
  832.                 if (!aEvent.altKey && !aEvent.ctrlKey) {
  833.                   killEvent = this.mMenuOpen;
  834.                   if (killEvent)
  835.                     this.keyNavigation(aEvent);
  836.                 }
  837.               } 
  838.               break;              
  839.               
  840.             case KeyEvent.DOM_VK_RETURN:
  841.  
  842.               // if this is a failure item, save it for fireErrorCommand
  843.               var errItem = null;
  844.               if (this.resultsPopup.selectedIndex != null && 
  845.                   this.getSessionStatusAt(this.resultsPopup.selectedIndex) ==
  846.                   Components.interfaces.nsIAutoCompleteStatus.failureItems) {
  847.                 errItem = this.getResultAt(this.resultsPopup.selectedIndex);
  848.               }
  849.  
  850.               killEvent = this.mMenuOpen;
  851.               this.finishAutoComplete(true, true, aEvent);
  852.               this.closeResultPopup();
  853.               if (errItem) {
  854.                   this._fireEvent("errorcommand", errItem);
  855.               }
  856.               break;
  857.  
  858.             case KeyEvent.DOM_VK_ESCAPE:
  859.               this.clearTimer();
  860.               killEvent = this.mMenuOpen;
  861.               this.undoAutoComplete();
  862.               this.closeResultPopup();
  863.               break;
  864.   
  865.             case KeyEvent.DOM_VK_LEFT:
  866.             case KeyEvent.DOM_VK_RIGHT:
  867.               this.finishAutoComplete(false, false, aEvent);
  868.               this.clearTimer();
  869.               this.closeResultPopup();
  870.               break;
  871.  
  872.             case KeyEvent.DOM_VK_DOWN:
  873.               if (!aEvent.altKey) {
  874.                 this.clearTimer();
  875.                 killEvent = true;
  876.                 this.keyNavigation(aEvent);
  877.                 break;
  878.               }
  879.             // Alt+Down falls through to history popup toggling code
  880.               
  881.             case KeyEvent.DOM_VK_F4:
  882.               if (!aEvent.ctrlKey && !aEvent.shiftKey && this.getAttribute("disablehistory") != "true") {
  883.                 var historyPopup = document.getAnonymousElementByAttribute(this, "anonid", "historydropmarker");
  884.                 if (historyPopup)
  885.                   historyPopup.showPopup();
  886.                 else
  887.                   historyPopup.hidePopup();
  888.               }
  889.               break;
  890.             case KeyEvent.DOM_VK_PAGE_UP:
  891.             case KeyEvent.DOM_VK_PAGE_DOWN:
  892.             case KeyEvent.DOM_VK_UP:
  893.               if (!aEvent.ctrlKey && !aEvent.metaKey) {
  894.                 this.clearTimer();
  895.                 killEvent = true;
  896.                 this.keyNavigation(aEvent);
  897.               }
  898.               break;
  899.           }
  900.           
  901.           if (killEvent) {
  902.             aEvent.preventDefault();
  903.             aEvent.preventBubble();
  904.           }
  905.           
  906.           return true;
  907.         ]]></body>
  908.       </method>
  909.  
  910.       <!--  -->
  911.       <method name="keyNavigation">
  912.         <parameter name="aEvent"/>
  913.         <body><![CDATA[
  914.           var k = aEvent.keyCode;
  915.           if (k == KeyEvent.DOM_VK_TAB ||
  916.               k == KeyEvent.DOM_VK_UP || k == KeyEvent.DOM_VK_DOWN ||
  917.               k == KeyEvent.DOM_VK_PAGE_UP || k == KeyEvent.DOM_VK_PAGE_DOWN)
  918.           {
  919.             // up/down keys while menu is closed will open menu
  920.             if (!this.mMenuOpen && (this.view.rowCount > 0 || this.alwaysOpenPopup)) {
  921.               this.openResultPopup();
  922.               return;
  923.             }
  924.             
  925.             this.userAction = "scrolling";
  926.             this.mNeedToComplete = false;
  927.             
  928.             var dir = k == KeyEvent.DOM_VK_DOWN ||
  929.                       k == KeyEvent.DOM_VK_PAGE_DOWN ||
  930.                      (k == KeyEvent.DOM_VK_TAB && !aEvent.shiftKey) ? 1 : -1;
  931.             var amt = k == KeyEvent.DOM_VK_PAGE_UP ||
  932.                       k == KeyEvent.DOM_VK_PAGE_DOWN ? this.resultsPopup.pageCount-1 : 1;
  933.             var selected = this.resultsPopup.selectBy(dir, amt);
  934.           
  935.             // determine which value to place in the textbox
  936.             this.ignoreInputEvent = true;
  937.             if (selected != null) {
  938.               if (this.getSessionStatusAt(selected) == 
  939.                   Components.interfaces.nsIAutoCompleteStatus.failureItems) { 
  940.                 if (this.currentSearchString)
  941.                   this.value = this.currentSearchString;
  942.               } else {
  943.                 this.value = this.getResultValueAt(selected);
  944.               }
  945.               this.mTransientValue = true;
  946.             } else {
  947.               if (this.currentSearchString)
  948.                 this.value = this.currentSearchString;
  949.               this.mTransientValue = false;
  950.             }
  951.             
  952.             // move cursor to the end
  953.             this.mInputElt.setSelectionRange(this.value.length, this.value.length);
  954.             this.ignoreInputEvent = false;
  955.           }
  956.         ]]></body>
  957.       </method>
  958.  
  959.       <!-- while the user is typing, fill the textbox with the "default" value
  960.            if one can be assumed, and select the end of the text -->
  961.       <method name="autoFillInput">
  962.         <parameter name="aSessionName"/>
  963.         <parameter name="aResults"/>
  964.         <parameter name="aUseFirstMatchIfNoDefault"/>
  965.         <body><![CDATA[
  966.           if (this.mDefaultMatchFilled) return;
  967.             
  968.           if (!this.mFinishAfterSearch && this.autoFill && 
  969.               this.mLastKeyCode != KeyEvent.DOM_VK_BACK_SPACE &&
  970.               this.mLastKeyCode != KeyEvent.DOM_VK_DELETE) {
  971.             var indexToUse = aResults.defaultItemIndex;
  972.             if (aUseFirstMatchIfNoDefault && indexToUse == -1)
  973.               indexToUse = 0;      
  974.               
  975.             if (indexToUse != -1) {
  976.               var resultValue = this.getSessionValueAt(aSessionName, indexToUse);
  977.               var match = resultValue.toLowerCase();
  978.               var entry = this.currentSearchString.toLowerCase();
  979.               this.ignoreInputEvent = true;
  980.               if (match.indexOf(entry) == 0) {
  981.                 var endPoint = this.value.length;
  982.                 this.value = this.value + resultValue.substr(endPoint);
  983.                 this.mInputElt.setSelectionRange(endPoint, this.value.length);
  984.               } else {
  985.                 if (this.autoFillAfterMatch) {
  986.                   this.value = this.value + " >> " + resultValue;
  987.                   this.mInputElt.setSelectionRange(entry.length, this.value.length);
  988.                 } else {
  989.                   var postIndex = resultValue.indexOf(this.value);
  990.                   if (postIndex >= 0) {
  991.                     var startPt = this.value.length;
  992.                     this.value = this.value + resultValue.substr(startPt+postIndex);
  993.                     this.mInputElt.setSelectionRange(startPt, this.value.length);
  994.                   }
  995.                 }
  996.               }
  997.               this.mNeedToComplete = true;
  998.               this.ignoreInputEvent = false;
  999.               this.mDefaultMatchFilled = true;
  1000.             }
  1001.           } 
  1002.         ]]></body>
  1003.       </method>
  1004.  
  1005.       <!-- ::::::::::::: popup and tree ::::::::::::: -->
  1006.  
  1007.       <!--  -->
  1008.       <method name="openResultPopup">
  1009.         <body><![CDATA[
  1010.           if (!this.mMenuOpen && this.showPopup && this.focused &&
  1011.                (this.getResultCount("") >= this.minResultsForPopup
  1012.                 || this.mFailureItems)) {
  1013.             var w = this.boxObject.width;
  1014.             if (w != this.resultsPopup.boxObject.width)
  1015.               this.resultsPopup.setAttribute("width", w);
  1016.             this.resultsPopup.removeAttribute("hidden");
  1017.             this.resultsPopup.showPopup(this, -1, -1, "popup", "bottomleft", "topleft");
  1018.             this.mMenuOpen = true;
  1019.           }
  1020.         ]]></body>
  1021.       </method>
  1022.  
  1023.       <!--  -->
  1024.       <method name="closeResultPopup">
  1025.         <body><![CDATA[
  1026.           if (this.resultsPopup && this.mMenuOpen) {
  1027.             this.resultsPopup.hidePopup();
  1028.             this.resultsPopup.setAttribute("hidden", "true");
  1029.             this.mMenuOpen = false;
  1030.           }
  1031.         ]]></body>
  1032.       </method>
  1033.  
  1034.       <!--  -->
  1035.       <method name="addResultElements">
  1036.         <parameter name="aSessionName"/>
  1037.         <parameter name="aResults"/>
  1038.         <body><![CDATA[
  1039.           if (this.focused) {
  1040.             this.view.addResults(aResults);
  1041.             this.resultsPopup.adjustHeight();
  1042.           }
  1043.         ]]></body>
  1044.       </method>
  1045.  
  1046.       <!--  -->
  1047.       <method name="clearResultElements">
  1048.         <parameter name="aInvalidate"/>
  1049.         <body><![CDATA[
  1050.           this.view.clearResults(aInvalidate);
  1051.           if (aInvalidate)
  1052.             this.resultsPopup.adjustHeight();
  1053.  
  1054.           this.noMatch = true;
  1055.         ]]></body>
  1056.       </method>
  1057.  
  1058.       <!--  -->
  1059.       <method name="clearResultData">
  1060.         <body><![CDATA[
  1061.           for (var name in this.mSessions) {
  1062.             this.mLastResults[name] = null;
  1063.             this.mLastStatus[name] = null;
  1064.           }
  1065.         ]]></body>
  1066.       </method>
  1067.  
  1068.       <!-- ::::::::::::: miscellaneous ::::::::::::: -->
  1069.  
  1070.       <!--  -->
  1071.       <method name="ifSetAttribute">
  1072.         <parameter name="aAttr"/>
  1073.         <parameter name="aVal"/>
  1074.         <body><![CDATA[
  1075.           if (this.getAttribute(aAttr) == "")
  1076.             this.setAttribute(aAttr, aVal);
  1077.         ]]></body>
  1078.       </method>
  1079.  
  1080.       <!--  -->
  1081.       <method name="clearTimer">
  1082.         <parameter name=""/>
  1083.         <body><![CDATA[
  1084.           if (this.mAutoCompleteTimer) {
  1085.             clearTimeout(this.mAutoCompleteTimer);
  1086.             this.mAutoCompleteTimer = 0;
  1087.           }
  1088.         ]]></body>
  1089.       </method>
  1090.  
  1091.       <!-- ::::::::::::: event dispatching ::::::::::::: -->
  1092.  
  1093.       <method name="_fireEvent">
  1094.         <parameter name="aEventType"/>
  1095.         <parameter name="aEventParam"/>
  1096.         <parameter name="aTriggeringEvent"/>
  1097.         <body>
  1098.         <![CDATA[
  1099.           var noCancel = true;
  1100.           // handle any xml attribute event handlers
  1101.           var handler = this.getAttribute("on"+aEventType);
  1102.           if (handler) {
  1103.             var fn = new Function("eventParam", "domEvent", handler);
  1104.             var returned = fn.apply(this, [aEventParam, aTriggeringEvent]);
  1105.             if (returned == false)
  1106.               noCancel = false;
  1107.           }
  1108.           
  1109.           return noCancel;
  1110.         ]]>
  1111.         </body>
  1112.       </method>
  1113.  
  1114.       <!-- =================== TREE VIEW =================== -->
  1115.  
  1116.       <field name="view"><![CDATA[
  1117.         ({
  1118.           mTextbox: this,
  1119.           mTree: null,
  1120.           mBoxObject: null,
  1121.           mResults: [],
  1122.           mRowCount: 0,
  1123.           mSelectedIndex: null,
  1124.           
  1125.           get treeBoxObject()
  1126.           {
  1127.             return this.mTree;
  1128.           },
  1129.           
  1130.           set selectedIndex(aRow)
  1131.           {
  1132.             if (!this.mBoxObject)
  1133.               return;
  1134.               
  1135.             if (this.mSelectedIndex != null)
  1136.               this.mBoxObject.invalidateRow(this.mSelectedIndex);
  1137.               
  1138.             this.mSelectedIndex = aRow;
  1139.             
  1140.             this.mBoxObject.invalidateRow(aRow);
  1141.             
  1142.             if (aRow != null)
  1143.               this.mBoxObject.ensureRowIsVisible(aRow);
  1144.           },
  1145.           
  1146.           get selectedIndex()
  1147.           {
  1148.             return this.mSelectedIndex;
  1149.           },
  1150.           
  1151.           clearResults: function(aInvalidate)
  1152.           {
  1153.             this.mRowCount = 0;  
  1154.             this.mResults = [];
  1155.             
  1156.             if (aInvalidate && this.mTree)
  1157.               this.mTree.invalidate();
  1158.           },
  1159.           
  1160.           addResults: function(aResults)
  1161.           {
  1162.             this.mResults.push(aResults);
  1163.             var oldCount = this.mRowCount;
  1164.             this.mRowCount += aResults.items.Count();
  1165.             
  1166.             if (this.mTree)
  1167.               this.mTree.rowCountChanged(oldCount, this.mRowCount);
  1168.           },
  1169.           
  1170.           createAtom: function(aVal)
  1171.           {
  1172.             try {
  1173.               var i = Components.interfaces.nsIAtomService;
  1174.               var svc = Components.classes["@mozilla.org/atom-service;1"].getService(i);
  1175.               return svc.getAtom(aVal);
  1176.             } catch(ex) { }
  1177.             return null; // XXX equivalent to falling off the end?
  1178.           },
  1179.  
  1180.           //////////////////////////////////////////////////////////
  1181.           // nsITreeView interface
  1182.           
  1183.           get rowCount() {
  1184.             return this.mRowCount;
  1185.           },
  1186.           
  1187.           // implementing these results in a crash
  1188.           // get selection() {},
  1189.           // set selection(aVal) { },
  1190.           
  1191.           setTree: function(aTree)
  1192.           {
  1193.             this.mTree = aTree;
  1194.             
  1195.             if (aTree) {
  1196.               this.mBoxObject = this.mTextbox.resultsPopup.tree.treeBoxObject;
  1197.             
  1198.               // cache atoms for pseudoelement properties
  1199.               this.mAtomSelected = this.createAtom("menuactive")
  1200.             }
  1201.           },
  1202.           
  1203.           getCellText: function(aRow, aColId)
  1204.           {
  1205.             var result = this.mTextbox.getResultAt(aRow);
  1206.             if (!result) return "";
  1207.             return aColId == "value" ? result.value : (aColId == "comment" ? result.comment : "");
  1208.           },
  1209.  
  1210.           getRowProperties: function(aIndex, aProperties) 
  1211.           {
  1212.             if (aIndex == this.mSelectedIndex)
  1213.               aProperties.AppendElement(this.mAtomSelected);
  1214.           },
  1215.  
  1216.           getCellProperties: function(aIndex, aColId, aProperties)
  1217.           {
  1218.             this.getRowProperties(aIndex, aProperties);
  1219.  
  1220.             // for the value column, append nsIAutoCompleteItem::className
  1221.             // to the property list so that we can style this column
  1222.             // using that property
  1223.             try { 
  1224.               if (aColId == "value") {
  1225.                 var className = this.mTextbox.getResultAt(aIndex).className;
  1226.                   if ( className != "" ) {
  1227.                     aProperties.AppendElement(this.createAtom(className));
  1228.                   }
  1229.               }
  1230.             } catch (ex) {
  1231.               // the ability to style here is a frill, so don't abort
  1232.               // if there's a problem
  1233.             } 
  1234.           },
  1235.  
  1236.           getColumnProperties: function(aColId, aColElt, aProperties) 
  1237.           {
  1238.           },
  1239.           
  1240.           getParentIndex: function(aRowIndex) { },
  1241.           hasNextSibling: function(aRowIndex, aAfterIndex) { },
  1242.           getLevel: function(aIndex) {},
  1243.           getImageSrc: function(aRow, aColId) {},
  1244.           getProgressMode: function(aRow, aColId) {},
  1245.           getCellValue: function(aRow, aColId) {},
  1246.           isContainer: function(aIndex) {},
  1247.           isContainerOpen: function(aIndex) {},
  1248.           isContainerEmpty: function(aIndex) {},
  1249.           isSeparator: function(aIndex) {},
  1250.           isSorted: function() {},
  1251.           toggleOpenState: function(aIndex) {},
  1252.           selectionChanged: function() {},
  1253.           cycleHeader: function(aColId, aElt) {},
  1254.           cycleCell: function(aRow, aColId) {},
  1255.           isEditable: function(aRow, aColId) {},
  1256.           setCellText: function(aRow, aColId, aValue) {},
  1257.           performAction: function(aAction) {},
  1258.           performActionOnRow: function(aAction, aRow) {},
  1259.           performActionOnCell: function(aAction, aRow, aColId) {}
  1260.         });
  1261.       ]]></field>
  1262.  
  1263.     </implementation>
  1264.  
  1265.     <handlers>
  1266.       <handler event="input"
  1267.                action="this.processInput();"/>
  1268.  
  1269.       <handler event="keypress" phase="capturing"
  1270.                 action="return this.processKeyPress(event);"/>
  1271.  
  1272.       <handler event="focus" phase="capturing"
  1273.                action="this.userAction = 'typing';"/>
  1274.  
  1275.       <handler event="blur" phase="capturing"
  1276.                action="if ( !(this.ignoreBlurWhileSearching && this.isSearching) ) {this.userAction = 'none'; this.finishAutoComplete(false, false, event);}"/>
  1277.  
  1278.       <handler event="mousedown" phase="capturing"
  1279.                action="if ( !this.mMenuOpen ) this.finishAutoComplete(false, false, event);"/>
  1280.     </handlers>
  1281.   </binding> 
  1282.  
  1283.   <binding id="autocomplete-result-popup" extends="chrome://global/content/bindings/popup.xml#popup">
  1284.     <content>
  1285.       <xul:tree anonid="tree" class="autocomplete-tree plain" flex="1">
  1286.         <xul:treecols anonid="treecols"/>
  1287.         <xul:treechildren anonid="treebody" class="autocomplete-treebody"/>
  1288.       </xul:tree>
  1289.     </content>
  1290.     
  1291.     <implementation>
  1292.       <constructor><![CDATA[
  1293.         if (this.textbox && this.textbox.view)
  1294.           this.initialize();
  1295.       ]]></constructor>
  1296.  
  1297.      <property name="textbox"
  1298.                 onget="return '__AUTOCOMPLETE_BOX__' in this ? this.__AUTOCOMPLETE_BOX__ : null;"/>
  1299.       
  1300.       <field name="tree">
  1301.         document.getAnonymousElementByAttribute(this, "anonid", "tree");
  1302.       </field>
  1303.  
  1304.       <field name="treecols">
  1305.         document.getAnonymousElementByAttribute(this, "anonid", "treecols");
  1306.       </field>
  1307.  
  1308.       <field name="treebody">
  1309.         document.getAnonymousElementByAttribute(this, "anonid", "treebody");
  1310.       </field>
  1311.  
  1312.       <property name="view" onget="return this.mView;">
  1313.         <setter><![CDATA[
  1314.           this.mView = val;
  1315.           var bx = this.tree.boxObject;
  1316.           bx = bx.QueryInterface(Components.interfaces.nsITreeBoxObject);
  1317.           bx.view = val;
  1318.         ]]></setter>
  1319.       </property>
  1320.  
  1321.      <property name="pageCount"
  1322.                onget="return this.tree.treeBoxObject.getPageCount();"/>
  1323.  
  1324.       <property name="selectedIndex"
  1325.                 onget="return this.textbox.view.selectedIndex"
  1326.                 onset="this.textbox.view.selectedIndex = val; return val;"/>
  1327.  
  1328.      <field name="mLastRows">0</field>
  1329.  
  1330.       <method name="initialize">
  1331.         <body><![CDATA[
  1332.         this.tree.__AUTOCOMPLETE_BOX__ = this.textbox;
  1333.         this.treebody.__AUTOCOMPLETE_BOX__ = this.textbox;
  1334.  
  1335.         this._selectedIndex = null;
  1336.  
  1337.         this.initColumns();
  1338.         this.view = this.textbox.view;
  1339.         ]]></body>
  1340.       </method>
  1341.  
  1342.       <!-- initialize the columns in the tree -->
  1343.       <method name="initColumns">
  1344.         <body><![CDATA[
  1345.           if (this.textbox.showCommentColumn) {
  1346.             this.addColumn({id: "value", flex: 2});
  1347.             this.addColumn({id: "comment", flex: 1});
  1348.           } else
  1349.             this.addColumn({id: "value", flex: 1});
  1350.         ]]></body>
  1351.       </method>
  1352.  
  1353.       <method name="addColumn">
  1354.         <parameter name="aAttrs"/>
  1355.         <body><![CDATA[
  1356.           var col = document.createElement("treecol");
  1357.           col.setAttribute("class", "autocomplete-treecol");
  1358.           for (var name in aAttrs)
  1359.             col.setAttribute(name, aAttrs[name]);
  1360.           this.treecols.appendChild(col);
  1361.           return col;
  1362.         ]]></body>
  1363.       </method>
  1364.  
  1365.       <!-- remove a single column from the tree, specified by
  1366.            element id -->
  1367.       <method name="removeColumn">
  1368.         <parameter name="aColId"/>
  1369.         <body><![CDATA[
  1370.           return this.tree.removeChild(document.getElementById(aColId));
  1371.         ]]></body>
  1372.       </method>
  1373.  
  1374.       <method name="adjustHeight">
  1375.         <body><![CDATA[
  1376.           // detect the desired height of the tree
  1377.           var bx = this.tree.treeBoxObject;
  1378.           var view = this.textbox.view;
  1379.           var rows = this.textbox.maxRows;
  1380.           if (!view.rowCount || (rows && view.rowCount < rows))
  1381.             rows = view.rowCount;
  1382.           
  1383.           var height = rows * bx.rowHeight;
  1384.           
  1385.           if (height == 0)
  1386.             this.tree.setAttribute("collapsed", "true");
  1387.           else {
  1388.             if (this.tree.hasAttribute("collapsed"))
  1389.               this.tree.removeAttribute("collapsed");
  1390.             this.tree.setAttribute("height", height);
  1391.           }
  1392.           this.tree.setAttribute("hidescrollbar", view.rowCount <= rows);
  1393.         ]]></body>
  1394.       </method>
  1395.  
  1396.       <method name="selectBy">
  1397.         <parameter name="aDir"/>
  1398.         <parameter name="aAmount"/>
  1399.         <body><![CDATA[
  1400.           try {
  1401.             var bx = this.tree.treeBoxObject;
  1402.             var view = bx.view;
  1403.             this.selectedIndex = this.getNextIndex(aDir, aAmount, this.selectedIndex, view.rowCount-1);
  1404.   
  1405.             return this.selectedIndex;
  1406.           } catch (ex) {
  1407.             // do nothing - occasionally timer-related js errors happen here
  1408.             // e.g. "this.selectedIndex has no properties", when you type fast and hit a
  1409.             // navigation key before this popup has opened
  1410.             return null;
  1411.           }
  1412.         ]]></body>
  1413.       </method>
  1414.  
  1415.       <method name="getNextIndex">
  1416.         <parameter name="aDir"/>
  1417.         <parameter name="aAmount"/>
  1418.         <parameter name="aIndex"/>
  1419.         <parameter name="aMaxRow"/>
  1420.         <body><![CDATA[
  1421.           if (aMaxRow < 0)
  1422.             return null;
  1423.             
  1424.           var newIdx = aIndex + aDir*aAmount;
  1425.           if (aDir < 0 && aIndex == null || newIdx > aMaxRow && aIndex != aMaxRow)
  1426.             newIdx = aMaxRow;
  1427.           else if (aDir > 0 && aIndex == null || newIdx < 0 && aIndex != 0)
  1428.             newIdx = 0;
  1429.           
  1430.           if (newIdx < 0 && aIndex == 0 || newIdx > aMaxRow && aIndex == aMaxRow)
  1431.             aIndex = null;
  1432.           else
  1433.             aIndex = newIdx;
  1434.           
  1435.           return aIndex;
  1436.         ]]></body>
  1437.       </method>
  1438.  
  1439.       <!-- This method is meant to be overriden by bindings extending this one.  When the 
  1440.            user selects an item from the list by hitting enter or clicking, this method
  1441.            can set the value of the textbox to a different value if it wants to. -->
  1442.       <method name="getOverrideValue">
  1443.         <body><![CDATA[
  1444.           return null;
  1445.         ]]></body>
  1446.       </method>
  1447.  
  1448.     </implementation>
  1449.  
  1450.     <handlers>
  1451.       <handler event="popupshowing">
  1452.         this.textbox.mMenuOpen = true;
  1453.       </handler>
  1454.  
  1455.       <handler event="popuphiding">
  1456.         this.textbox.mMenuOpen = false;
  1457.         this.selectedIndex = null;
  1458.       </handler>
  1459.     </handlers>
  1460.   </binding>
  1461.  
  1462.   <binding id="autocomplete-tree" extends="chrome://global/content/bindings/tree.xml#tree">
  1463.     <content>
  1464.       <children includes="treecols"/>
  1465.       <xul:treerows class="autocomplete-treerows tree-rows" xbl:inherits="hidescrollbar" flex="1">
  1466.         <children/>
  1467.       </xul:treerows>
  1468.     </content>
  1469.  
  1470.     <implementation>
  1471.       <property name="textbox"
  1472.                 onget="return this.__AUTOCOMPLETE_BOX__;"/>
  1473.     </implementation>
  1474.   </binding>
  1475.  
  1476.   <binding id="autocomplete-treebody">
  1477.     <implementation>
  1478.       <property name="textbox"
  1479.                 onget="return this.__AUTOCOMPLETE_BOX__;"/>
  1480.  
  1481.       <field name="mLastMoveTime">new Date()</field>
  1482.  
  1483.       <method name="getHoverCell">
  1484.         <parameter name="aEvent"/>
  1485.         <body><![CDATA[
  1486.            var row = {}; var col = {}; var obj = {};
  1487.            var x = aEvent.screenX - this.boxObject.screenX + this.boxObject.x;
  1488.            var y = aEvent.screenY - this.boxObject.screenY + this.boxObject.y;
  1489.            this.textbox.view.treeBoxObject.getCellAt(x, y, row, col, obj);
  1490.            if (row.value >= 0)
  1491.              return {row: row.value, column: col.value};
  1492.            else
  1493.             return null;
  1494.         ]]></body>
  1495.       </method>
  1496.     </implementation>
  1497.     
  1498.     <handlers>
  1499.       <handler event="mouseout" action="this.textbox.view.selectedIndex = null;"/>
  1500.       <handler event="mouseup" action="this.textbox.onResultClick();"/>
  1501.  
  1502.       <handler event="mousemove"><![CDATA[
  1503.         if (new Date() - this.mLastMoveTime > 30) {
  1504.          var rc = this.getHoverCell(event);
  1505.          if (rc && rc.row != this.textbox.view.selectedIndex) 
  1506.             this.textbox.view.selectedIndex = rc.row;
  1507.           this.mLastMoveTime = new Date();
  1508.         }
  1509.       ]]></handler>
  1510.     </handlers>
  1511.   </binding>
  1512.  
  1513.   <binding id="autocomplete-treerows">
  1514.     <content onmousedown="event.preventDefault()">
  1515.       <xul:hbox flex="1" class="tree-bodybox">
  1516.         <children/>
  1517.       </xul:hbox>
  1518.       <xul:scrollbar xbl:inherits="hidescrollbar" orient="vertical" class="tree-scrollbar"/>
  1519.     </content>
  1520.   </binding>
  1521.  
  1522.   <binding id="autocomplete-history-popup"
  1523.            extends="chrome://global/content/bindings/popup.xml#popup-scrollbars">
  1524.     <resources>
  1525.       <stylesheet src="chrome://global/content/autocomplete.css"/>
  1526.       <stylesheet src="chrome://global/skin/autocomplete.css"/>
  1527.     </resources>
  1528.     
  1529.     <handlers>
  1530.       <handler event="popuphiding"><![CDATA[
  1531.         parentNode.removeAttribute("open");
  1532.       ]]></handler>
  1533.     </handlers>
  1534.   </binding>
  1535.  
  1536.   <binding id="history-dropmarker" extends="xul:button">
  1537.     <content>
  1538.       <xul:image class="dropmarker-image"/>
  1539.     </content>
  1540.       
  1541.     <implementation implements="nsIAccessibleProvider">
  1542.       <property name="accessible">
  1543.         <getter>
  1544.           <![CDATA[
  1545.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  1546.             return accService.createXULDropmarkerAccessible(this);
  1547.           ]]>
  1548.         </getter>
  1549.       </property>
  1550.  
  1551.       <method name="showPopup">
  1552.         <body><![CDATA[
  1553.           var textbox = document.getBindingParent(this);
  1554.           var kids = textbox.getElementsByTagName("menupopup");
  1555.           if (kids.length) {
  1556.             kids[0].showPopup(textbox, -1, -1, "popup", "bottomleft", "topleft");
  1557.             textbox.setAttribute("open", true);
  1558.           }
  1559.         ]]></body>
  1560.       </method>
  1561.     </implementation>
  1562.     
  1563.     <handlers>
  1564.       <handler event="mousedown"><![CDATA[
  1565.         this.showPopup();
  1566.       ]]></handler>
  1567.     </handlers>
  1568.   </binding>
  1569.  
  1570. </bindings>
  1571.  
  1572.