home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / navigator / urlbarBindings.xml < prev    next >
Extensible Markup Language  |  2003-06-08  |  17KB  |  466 lines

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