home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / comm.jar / content / navigator / urlbarBindings.xml < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-21  |  15.3 KB  |  429 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="urlbarBindings"
  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.  
  8.   <binding id="urlbar" extends="chrome://global/content/autocomplete.xml#autocomplete">
  9.     <implementation>
  10.       <constructor><![CDATA[
  11.         this.mPrefs.addObserver("browser.urlbar", this.mPrefObserver);
  12.         
  13.         this.updatePref("browser.urlbar.showPopup");
  14.         this.updatePref("browser.urlbar.autoFill");
  15.       ]]></constructor>
  16.  
  17.       <destructor><![CDATA[
  18.         this.mPrefs.removeObserver("browser.urlbar", this.mPrefObserver);
  19.       ]]></destructor>
  20.  
  21.       <property name="mPrefs">
  22.         Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref);
  23.       </property>
  24.  
  25.       <property name="mPrefObserver"><![CDATA[
  26.         ({
  27.           urlbar: this,
  28.           
  29.           Observe: function(aObserver, aBlah, aPref) {
  30.             if (!aPref.indexOf("browser.urlbar"))
  31.               this.urlbar.updatePref(aPref);
  32.           }
  33.         });
  34.       ]]></property>
  35.  
  36.       <method name="updatePref">
  37.         <parameter name="aPref"/>
  38.         <body><![CDATA[
  39.           if (!aPref.indexOf("browser.urlbar.showPopup")) {
  40.             this.showPopup = this.mPrefs.GetBoolPref("browser.urlbar.showPopup");
  41.           } else if (!aPref.indexOf("browser.urlbar.autoFill")) {
  42.             this.autoFill = this.mPrefs.GetBoolPref("browser.urlbar.autoFill");
  43.           } 
  44.         ]]></body>
  45.       </method>
  46.       
  47.     </implementation>
  48.   </binding>
  49.   
  50.   <binding id="autocomplete-result-popup" extends="chrome://global/content/autocomplete.xml#autocomplete-result-popup">
  51.     <content menugenerated="true" orient="vertical">
  52.       <xul:box class="autocomplete-result-box" flex="1">
  53.         <xul:outliner anonid="outliner" class="autocomplete-outliner" flex="1">
  54.           <xul:outlinerbody anonid="outlinerbody" class="autocomplete-outlinerbody" flex="1"/>
  55.         </xul:outliner>
  56.       </xul:box>
  57.       <xul:box role="search-box" class="autocomplete-search-box"/>
  58.     </content>
  59.     
  60.     <implementation>
  61.       <constructor><![CDATA[
  62.         // listen for changes to default search engine
  63.         this.mPrefs.addObserver("browser.search", this.mPrefObserver);
  64.         this.mPrefs.addObserver("browser.urlbar", this.mPrefObserver);
  65.       ]]></constructor>
  66.  
  67.       <destructor><![CDATA[
  68.         this.mPrefs.removeObserver("browser.search", this.mPrefObserver);
  69.         this.mPrefs.removeObserver("browser.urlbar", this.mPrefObserver);
  70.       ]]></destructor>
  71.  
  72.       <property name="selectedIndex"
  73.                 onget="return this.textbox.view.selectedIndex;">
  74.         <setter>
  75.           this.mSelectedIndex = val;
  76.           if (val == null)
  77.             this.mSearchBox.selectedIndex = null;
  78.             
  79.           return val;
  80.         </setter>
  81.      </property>
  82.  
  83.       <property name="showSearch" onget="return this.mShowSearch;">
  84.         <setter><![CDATA[
  85.           this.mShowSearch = val;
  86.           if (val) {
  87.             this.updateEngines();
  88.             this.mSearchBox.removeAttribute("hidden");
  89.           } else {
  90.             this.clearEngines();
  91.             this.mSearchBox.setAttribute("hidden", "true");
  92.           }
  93.         ]]></setter>
  94.       </property>
  95.       
  96.       <property name="mSelectedIndex">
  97.         <setter>
  98.           this.textbox.view.selectedIndex = val;
  99.           return val;
  100.         </setter>
  101.      </property>
  102.  
  103.       <property name="defaultSearchEngine"
  104.                 onget="return this.textbox.getAttribute('defaultSearchEngine') == 'true';"
  105.                 onset="this.textbox.setAttribute('defaultSearchEngine', val); return val;"/>
  106.  
  107.       <property name="mSearchBox">
  108.          document.getAnonymousElementByAttribute(this, "role", "search-box");
  109.       </property>
  110.  
  111.       <property name="mPrefs">
  112.         Components.classes["@mozilla.org/preferences;1"].getService(Components.interfaces.nsIPref);
  113.       </property>
  114.  
  115.       <property name="mPrefObserver"><![CDATA[
  116.         ({
  117.           resultsPopup: this,
  118.           
  119.           Observe: function(aObserver, aBlah, aPref) {
  120.             if (!aPref.indexOf("browser.search"))
  121.               this.resultsPopup.updateEngines();
  122.             else if (!aPref.indexOf("browser.urlbar"))
  123.               this.resultsPopup.updatePref(aPref);
  124.           }
  125.         });
  126.       ]]></property>
  127.  
  128.       <property name="mInputListener"><![CDATA[
  129.         (function(aEvent) {
  130.           // "this" is the textbox, not the popup
  131.           if (this.mSearchInputTO)
  132.             window.clearTimeout(this.mSearchInputTO);
  133.           this.mSearchInputTO = window.setTimeout(this.resultsPopup.mInputTimeout, this.timeout, this);
  134.         });
  135.       ]]></property>
  136.  
  137.       <property name="mInputTimeout"><![CDATA[
  138.         (function(me) {
  139.           me.resultsPopup.mSearchBox.searchValue = me.value;
  140.           me.mSearchInputTO = 0;
  141.         });
  142.       ]]></property>
  143.  
  144.       <property name="mEnginesReady">false</property>
  145.       
  146.       <method name="getOverrideValue">
  147.         <body><![CDATA[
  148.           if (this.mSearchBox.selectedIndex != null)
  149.             return this.mSearchBox.getOverrideValue();
  150.           return null;
  151.         ]]></body>
  152.       </method>
  153.  
  154.       <method name="updatePref">
  155.         <parameter name="aPref"/>
  156.         <body><![CDATA[
  157.           if (!aPref.indexOf("browser.urlbar.showSearch"))
  158.             this.showSearch = this.mPrefs.GetBoolPref("browser.urlbar.showSearch");
  159.         ]]></body>
  160.       </method>
  161.       
  162.       <method name="addEngine">
  163.         <parameter name="aEngineId"/>
  164.         <parameter name="aName"/>
  165.         <parameter name="aIcon"/>
  166.         <parameter name="aSearchBarUrl"/>
  167.         <body><![CDATA[
  168.           var box = document.createElement("box");
  169.           box.setAttribute("class", "autocomplete-search-engine");
  170.           box.setAttribute("searchEngine", aEngineId);
  171.           box.setAttribute("name", aName);
  172.           box.setAttribute("icon", aIcon);
  173.           box.setAttribute("searchBarUrl", aSearchBarUrl);
  174.           box.setAttribute("engineIndex", this.childNodes.length);
  175.           this.mSearchBox.appendChild(box);
  176.         ]]></body>
  177.       </method>
  178.  
  179.       <method name="clearEngines">
  180.         <body><![CDATA[
  181.           var kids = this.mSearchBox.childNodes;
  182.           for (var i = kids.length-1; i >= 0; --i)
  183.             this.mSearchBox.removeChild(kids[i]);
  184.         ]]></body>
  185.       </method>
  186.    
  187.       <method name="updateEngines">
  188.         <body><![CDATA[
  189.           var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
  190.                       .getService(Components.interfaces.nsIRDFService);
  191.           var ds = rdf.GetDataSource("rdf:internetsearch");
  192.                       
  193.           const kNC_Name = rdf.GetResource("http://home.netscape.com/NC-rdf#Name");
  194.           const kNC_Icon = rdf.GetResource("http://home.netscape.com/NC-rdf#Icon");
  195.           const kNC_searchBarUrl = rdf.GetResource("http://home.netscape.com/NC-rdf#actionBar");
  196.         
  197.           var defaultEngine = null;
  198.           try {
  199.             defaultEngine = this.mPrefs.CopyUnicharPref("browser.search.defaultengine");
  200.           } catch(ex) {
  201.             this.ensureDefaultEnginePrefs(rdf, ds);
  202.             defaultEngine = this.mPrefs.CopyUnicharPref("browser.search.defaultengine");
  203.           }
  204.           
  205.           if (defaultEngine) {
  206.             this.clearEngines();
  207.             
  208.             if (ds) {
  209.               var res = rdf.GetResource(defaultEngine);
  210.               try {
  211.                  searchBarUrl = this.readRDFString(ds, res, kNC_searchBarUrl);
  212.               } catch(ex) {
  213.                 searchBarUrl = null;
  214.               }
  215.                 this.addEngine(res.Value, 
  216.                               this.readRDFString(ds, res, kNC_Name),
  217.                               this.readRDFString(ds, res, kNC_Icon),
  218.                               searchBarUrl);                                                    
  219.             }
  220.           }
  221.           
  222.           this.mEnginesReady = true;
  223.         ]]></body>
  224.       </method>
  225.  
  226.       <method name="ensureDefaultEnginePrefs">
  227.         <parameter name="aRDF"/>
  228.         <parameter name="aDS"/>
  229.         <body><![CDATA[
  230.           var defaultName = this.mPrefs.getLocalizedUnicharPref("browser.search.defaultenginename");
  231.           const kNC_Root = aRDF.GetResource("NC:SearchEngineRoot");
  232.           const kNC_child = aRDF.GetResource("http://home.netscape.com/NC-rdf#child");
  233.           const kNC_Name = aRDF.GetResource("http://home.netscape.com/NC-rdf#Name");
  234.           
  235.           var arcs = aDS.GetTargets(kNC_Root, kNC_child, true);
  236.           while (arcs.hasMoreElements()) {
  237.             var engineRes = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
  238.             var name = this.readRDFString(aDS, engineRes, kNC_Name);
  239.             if (name == defaultName)
  240.               this.mPrefs.SetUnicharPref("browser.search.defaultengine", engineRes.Value);
  241.           }
  242.         ]]></body>
  243.       </method>
  244.  
  245.       <method name="readRDFString">
  246.         <parameter name="aDS"/>
  247.         <parameter name="aRes"/>
  248.         <parameter name="aProp"/>
  249.         <body><![CDATA[
  250.           var n = aDS.GetTarget(aRes, aProp, true);
  251.           return n ? n.QueryInterface(Components.interfaces.nsIRDFLiteral).Value : null;
  252.         ]]></body>
  253.       </method>
  254.  
  255.       <method name="selectBy">
  256.         <parameter name="aDir"/>
  257.         <parameter name="aAmount"/>
  258.         <body><![CDATA[
  259.           var bx = this.outliner.outlinerBoxObject;
  260.           var view = bx.view;
  261.           var sel;
  262.           if (this.selectedIndex == null && aDir < 0) {
  263.             sel = this.mSearchBox.selectBy(aDir, aAmount);
  264.             if (sel != null)
  265.               return null;
  266.           } 
  267.           
  268.           sel = this.getNextIndex(aDir, aAmount, this.selectedIndex, view.rowCount-1);
  269.           this.mSelectedIndex = sel;
  270.  
  271.           if (sel == null && aDir > 0)
  272.             this.mSearchBox.selectBy(aDir, aAmount);
  273.           else if (this.mSearchBox.selectedIndex != null)
  274.             this.mSearchBox.selectedIndex = null;
  275.             
  276.           return sel;
  277.         ]]></body>
  278.       </method>
  279.     </implementation>
  280.  
  281.     <handlers>
  282.       <handler event="popupshowing"><![CDATA[
  283.         if (!this.mEnginesReady && this.defaultSearchEngine)
  284.           this.updatePref("browser.urlbar.showSearch");
  285.  
  286.         if (this.mShowSearch) {
  287.           this.textbox.addEventListener("input", this.mInputListener, false);
  288.           if ("searchValue" in this.mSearchBox)
  289.             this.mSearchBox.searchValue = this.textbox.currentSearchString;
  290.           else
  291.             this.mSearchBox.setAttribute("searchvalue", this.textbox.currentSearchString);
  292.         }
  293.       ]]></handler>
  294.       
  295.       <handler event="popuphiding"><![CDATA[
  296.         if (this.mShowSearch)
  297.           this.textbox.removeEventListener("input", this.mInputListener, false);
  298.       ]]></handler>      
  299.     </handlers>
  300.   </binding>
  301.  
  302.   <binding id="autocomplete-search-box">
  303.     <content orient="vertical"/>
  304.     
  305.     <implementation>
  306.       <constructor><![CDATA[
  307.         var text = this.getAttribute("searchvalue");
  308.         if (text)
  309.           this.searchValue = text;
  310.         
  311.         this.mSelectedIndex = null;
  312.       ]]></constructor>
  313.       
  314.       <property name="parentMouseoverListener">
  315.         // ensure that if a result menuitem is moused-over, any
  316.         // search selection is cleared
  317.         (function(aEvent) {
  318.           if (aEvent.target.nodeName == "menuitem")
  319.             this.mSearchBox.selectedIndex = null;
  320.          })
  321.       </property>
  322.       
  323.       <property name="parentDestroyListener">
  324.         // ensure that if the popup closes, any search selection is cleared
  325.         (function(aEvent) {
  326.            this.mSearchBox.selectedIndex = null;
  327.          })
  328.       </property>
  329.       
  330.       <property name="activeChild" 
  331.                 onget="return this.childNodes[this.mSelectedIndex]"/>
  332.  
  333.       <property name="selectedIndex">
  334.         <getter>return this.mSelectedIndex;</getter>
  335.         
  336.         <setter><![CDATA[
  337.           if (this.mSelectedIndex != null)
  338.             this.activeChild.removeAttribute("menuactive");
  339.           
  340.           this.mSelectedIndex = val;
  341.  
  342.           if (val != null) {
  343.             this.parentNode.mSelectedIndex = null;
  344.             this.parentNode.addEventListener("mouseover", this.parentMouseoverListener, false);
  345.             this.parentNode.addEventListener("popuphiding", this.parentDestroyListener, false);
  346.             if (this.activeChild)
  347.               this.activeChild.setAttribute("menuactive", "true");
  348.           } else {
  349.             this.parentNode.removeEventListener("mouseover", this.parentMouseoverListener, false);
  350.             this.parentNode.removeEventListener("popuphiding", this.parentDestroyListener, false);
  351.           }
  352.         ]]></setter>
  353.       
  354.       </property>
  355.       
  356.       <property name="searchValue">
  357.         <getter><![CDATA[
  358.           return this.mSearchValue;
  359.         ]]></getter>
  360.         <setter><![CDATA[
  361.           this.mSearchValue = val;
  362.           var kids = this.childNodes;
  363.           for (var i = 0; i < kids.length; ++i) {
  364.             var name = kids[i].getAttribute("name");
  365.             kids[i].setAttribute("label", "Search " + name + " for \"" + val + "\"");
  366.           }
  367.         ]]></setter>
  368.       </property>
  369.       
  370.       <method name="selectBy">
  371.         <parameter name="aDir"/>
  372.         <parameter name="aAmount"/>
  373.         <body><![CDATA[
  374.           var sel = this.parentNode.getNextIndex(aDir, aAmount, this.selectedIndex, this.childNodes.length-1);
  375.           this.selectedIndex = sel;
  376.           return sel;
  377.         ]]></body>
  378.       </method>
  379.  
  380.       <method name="getOverrideValue">
  381.         <body><![CDATA[
  382.           var item = this.activeChild;
  383.           if (item) {
  384.             const ISEARCH_CONTRACTID = "@mozilla.org/rdf/datasource;1?name=internetsearch";
  385.             const nsIInternetSearchService = Components.interfaces.nsIInternetSearchService;           
  386.             var searchService = Components.classes[ISEARCH_CONTRACTID].getService(nsIInternetSearchService);
  387.             var searchEng = item.getAttribute("searchEngine");
  388.             var searchEngUrl = item.getAttribute("searchBarUrl");
  389.             var escapedSearch = escape(this.mSearchValue)
  390.             if (searchEngUrl) {
  391.                 searchEngUrl += escapedSearch;
  392.                 return searchEngUrl;
  393.             } else {
  394.               return searchService.GetInternetSearchURL(item.getAttribute("searchEngine"),escapedSearch);
  395.             }
  396.           }
  397.           return null;
  398.         ]]></body>
  399.       </method>
  400.  
  401.     </implementation>
  402.  
  403.     <handlers>
  404.       <handler event="mouseup">
  405.         this.parentNode.textbox.onResultClick();
  406.       </handler>
  407.     </handlers>
  408.  
  409.   </binding>
  410.  
  411.   <binding id="autocomplete-search-engine">
  412.     <content>
  413.       <xul:image class="autocomplete-search-engine-img" inherits="src=icon"/>
  414.       <xul:text class="autocomplete-search-engine-text" inherits="value=label"/>
  415.     </content>
  416.     
  417.     <handlers>
  418.       <handler event="mouseover">
  419.         this.parentNode.selectedIndex = this.getAttribute("engineIndex");
  420.       </handler>
  421.  
  422.       <handler event="mouseout">
  423.         this.parentNode.selectedIndex = null;
  424.       </handler>
  425.     </handlers>
  426.   </binding>
  427.   
  428. </bindings>
  429.