home *** CD-ROM | disk | FTP | other *** search
/ Minami 80 / MINAMI80.iso / Extra / DivXInstaller.exe / $PLUGINSDIR / GoogleToolbarFirefox.msi / xpi / chrome / google-toolbar.jar / content / autocomplete-menulist.xml < prev    next >
Extensible Markup Language  |  2006-05-15  |  9KB  |  243 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="AutocompleteMenulistBindings"
  4.           xmlns="http://www.mozilla.org/xbl"
  5.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  6.           xmlns:xbl="http://www.mozilla.org/xbl">
  7.  
  8.   <binding id="autocomplete-menulist" extends="chrome://global/content/bindings/menulist.xml#menulist-editable">
  9.     <content sizetopopup="pref">
  10.       <!-- Autocomplete is off until we need it.  Make sure showcommentcolumn
  11.            is false at startup to work around autocomplete bug. -->
  12.       <xul:textbox class="gtb-search-box" type="autocomplete" autocompletesearch="google-search-suggest" flex="1" anonid="textbox"
  13.                    autocompletepopup="gtbPopupAutoComplete"
  14.                    completeselectedindex="true"
  15.                    tabscrolling="true"
  16.                    showcommentcolumn="false"
  17.                    xbl:inherits="disableautocomplete,src,width,minwidth"/>
  18.       <xul:dropmarker class="menulist-dropmarker" type="menu"/>
  19.       <children includes="menupopup"/>
  20.     </content>
  21.  
  22.     <implementation>
  23.       <field name="alreadySearched">false</field>  
  24.       <field name="mTextBox">null</field>
  25.      
  26.       <property name="textBox">
  27.         <getter><![CDATA[
  28.           if(!this.mTextBox) {
  29.             this.mTextBox = document.getAnonymousElementByAttribute(this, "anonid", "textbox");
  30.           }
  31.           return this.mTextBox;
  32.         ]]></getter>
  33.       </property>
  34.  
  35.       <property name="value" onget="return this.inputField.value;">
  36.         <setter><![CDATA[
  37.           // Override editable menulist's value setter to refer to the textBox
  38.           // instead of inputField.  This prevents the autocomplete pop-up
  39.           // from showing when the menulist value is re-set
  40.           this.textBox.value = val;
  41.           this.setAttribute('value', val);
  42.           this.setAttribute('label', val);
  43.           this._selectInputFieldValueInList();
  44.           return val;
  45.         ]]></setter>
  46.       </property>
  47.  
  48.       <property name="inputField" readonly="true">
  49.         <getter><![CDATA[
  50.           if(!this.mInputField) {
  51.             this.mInputField = this.textBox.mInputElt;
  52.           }
  53.           return this.mInputField;
  54.         ]]></getter>
  55.       </property>
  56.  
  57.       <property name="selectedItem">
  58.         <getter>
  59.           <![CDATA[
  60.             // Need to override selectedItem() in editable menulist to access
  61.             // the inputField via the textbox only--otherwise the textBox 
  62.             // autocomplete pop-up will show after selection from the menulist
  63.             // drop-down
  64.  
  65.             // Make sure internally-selected item
  66.             //  is in sync with inputField.value
  67.             this._selectInputFieldValueInList();
  68.             return this.selectedInternal;
  69.           ]]>
  70.         </getter>
  71.  
  72.         <setter>
  73.           <![CDATA[
  74.             // This doesn't touch textBox.value or "value" and "label" attributes
  75.             this.setSelectionInternal(val);
  76.  
  77.             if (!this.selectedInternal) {
  78.               this.inputField.value = "";
  79.               this.removeAttribute('value');
  80.               this.removeAttribute('label');
  81.               return val;
  82.             }
  83.  
  84.             // Editable menulist uses "label" as its "value"
  85.             var label = val.getAttribute('label');
  86.             this.textBox.value = label;
  87.             this.setAttribute('value', label);
  88.             this.setAttribute('label', label);
  89.  
  90.             //need to re-set the focus to the text-box so that
  91.             //it will populate the pop-up with the correct suggestions.
  92.             this.textBox.focus();
  93.             return val;
  94.           ]]>
  95.         </setter>
  96.       </property>
  97.       
  98.     </implementation>
  99.   </binding>
  100.  
  101.   <binding id="gtb-search-box" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete">
  102.     <resources>
  103.       <stylesheet src="chrome://google-toolbar/skin/google-toolbar.css"/>
  104.     </resources>
  105.  
  106.     <implementation>
  107.       <!-- These variables keep track of whether attachController()
  108.            and detachController() may have been called before the 
  109.            constructor. -->
  110.       <field name="mPendingAttach">false</field>
  111.       <field name="mPendingDetach">false</field>
  112.  
  113.       <constructor><![CDATA[
  114.         // If attachController() or detachController() were called
  115.         // before the constructor, call them now that the base class
  116.         // constructor has set mController correctly.
  117.         
  118.         if (this.mPendingAttach) {
  119.           this.attachController();
  120.         }
  121.         if (this.mPendingDetach) {
  122.           this.detachController();
  123.         }
  124.       ]]></constructor>
  125.  
  126.       <method name="onTextEntered"> 
  127.         <body><![CDATA[
  128.           this.parentNode.alreadySearched = false;
  129.           setTimeout("GTB_GoogleToolbar.doSuggestSearch()", 100);
  130.            //need to re-set the focus to the text-box so that
  131.            //it will populate the pop-up with the correct suggestions.
  132.           this.focus();
  133.         ]]></body>
  134.       </method>
  135.  
  136.       <!-- There is a weird bug where attachController can be
  137.            called before the constructor.  This causes problems
  138.            because mController will be null.  In this case, set 
  139.            a variable to tell the contstructor to attach the 
  140.            controller when it is called. -->
  141.       <method name="attachController">
  142.         <body><![CDATA[
  143.           if (!this.mController) {
  144.             // Defer attaching to the constructor.
  145.             this.mPendingAttach = true;
  146.             this.mPendingDetach = false;
  147.             return;
  148.           }
  149.           if (this.mController.input != this) {
  150.             this.mController.input = this;
  151.           }
  152.         ]]></body>
  153.       </method>
  154.  
  155.       <!-- There is a weird bug where detachController can be
  156.            called before the constructor.  This causes problems
  157.            because mController will be null.  In this case, set 
  158.            a variable to tell the contstructor to attach the 
  159.            controller when it is called. -->
  160.       <method name="detachController">
  161.         <body><![CDATA[
  162.           if (!this.mController) {
  163.             // Defer detatching to the constructor.
  164.             this.mPendingDetach = true;
  165.             this.mPendingAttach = false;
  166.             return;
  167.           }
  168.           if (this.mController.input == this) {
  169.             this.mController.input = null;
  170.           }
  171.         ]]></body>
  172.       </method>
  173.       
  174.       <!-- Override the openPopup menu so we can control
  175.            showCommentColumn. -->
  176.       <method name="openPopup">
  177.         <body><![CDATA[
  178.           var searchBox = this.parentNode;
  179.           GTB_Assert(searchBox && "gtbGoogleSearchBox" == searchBox.id,
  180.                      'unable to find search box');
  181.           var x = searchBox.boxObject.screenX;
  182.           var y = searchBox.boxObject.screenY + searchBox.boxObject.height;
  183.           var w = searchBox.boxObject.width;
  184.           this.popup.showCommentColumn = true;
  185.           this.popup.openPopup(this, x, y, w);
  186.           return true;
  187.         ]]></body>
  188.       </method>
  189.       
  190.       <!-- Firefox's autocomplete code is broken.  It sets the ID of the
  191.            comment column such that if there are two autocomplete boxes, the
  192.            IDs collide.  To prevent the ID collision, we remove the comment
  193.            column when we're not using it. -->
  194.       <method name="closePopup">
  195.         <body><![CDATA[
  196.           this.popup.closePopup();
  197.           this.popup.showCommentColumn = false;
  198.         ]]></body>
  199.       </method>
  200.     </implementation>
  201.   </binding>
  202.  
  203.   <!-- Overload showCommentColumn to apply the styles we want. -->
  204.   <binding id="gtb-search-popup" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete-result-popup">
  205.     <implementation>
  206.       <property name="showCommentColumn"
  207.                 onget="return this.mShowCommentColumn;">
  208.         <setter><![CDATA[
  209.           // add or remove the comment column
  210.           if (!val && this.mShowCommentColumn) {
  211.             this.removeColumn("treecolAutoCompleteComment");
  212.           } else if (val && !this.mShowCommentColumn) {
  213.             var col = this.addColumn({
  214.               id: "treecolAutoCompleteComment",
  215.               flex: 0,
  216.               width: '150px',
  217.               style: 'text-align: right',
  218.             });
  219.           }
  220.           this.mShowCommentColumn = val;
  221.           return val;
  222.         ]]></setter> 
  223.       </property>
  224.       
  225.       <method name="removeColumn">
  226.         <parameter name="aColId"/>
  227.         <body><![CDATA[
  228.           // Override original code that uses doc.getElementById which
  229.           // may collide.
  230.           var i, node;
  231.           for (i = 0, node = null; node = this.treecols.childNodes[i]; ++i) {
  232.             if (node.id == aColId) {
  233.               this.treecols.removeChild(node);
  234.               return true;
  235.             }
  236.           }
  237.           return false;
  238.         ]]></body>
  239.       </method>
  240.     </implementation>
  241.   </binding>
  242. </bindings>
  243.