DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
<?xml version="1.0"?>

<bindings id="urlbarBindings"
          xmlns="http://www.mozilla.org/xbl"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
          xmlns:xbl="http://www.mozilla.org/xbl">

  <binding id="urlbar" extends="chrome://global/content/autocomplete.xml#autocomplete">
    <implementation>
      <constructor><![CDATA[
        var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
        if (pbi)
          pbi.addObserver("browser.urlbar", this.mPrefObserver, false);
        
        this.updatePref("browser.urlbar.showPopup");
        this.updatePref("browser.urlbar.autoFill");
        this.updatePref("browser.urlbar.showSearch");
      ]]></constructor>

      <destructor><![CDATA[
        var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
        if (pbi)
          pbi.removeObserver("browser.urlbar", this.mPrefObserver);
      ]]></destructor>

      <field name="mPrefs">
        var svc = Components.classes["@mozilla.org/preferences-service;1"]
                            .getService(Components.interfaces.nsIPrefService);
        svc.getBranch(null);
      </field>

      <field name="mPrefObserver"><![CDATA[
        ({
          urlbar: this,
          
          observe: function(aObserver, aBlah, aPref) {
            if (/^browser\.urlbar\./.test(aPref))
              this.urlbar.updatePref(aPref);
          }
        });
      ]]></field>

      <method name="updatePref">
        <parameter name="aPref"/>
        <body><![CDATA[
          if (aPref == "browser.urlbar.showPopup") {
            this.showPopup = this.mPrefs.getBoolPref("browser.urlbar.showPopup");
          } else if (aPref == "browser.urlbar.autoFill") {
            this.autoFill = this.mPrefs.getBoolPref("browser.urlbar.autoFill");
          } else if (aPref == "browser.urlbar.showSearch") {
            this.minResultsForPopup = this.mPrefs.getBoolPref("browser.urlbar.showSearch") ?
                                      0 : 1;
          }
        ]]></body>
      </method>
      
    </implementation>
  </binding>
  
  <binding id="autocomplete-result-popup" extends="chrome://global/content/autocomplete.xml#autocomplete-result-popup">
    <content>
      <xul:tree anonid="tree" class="autocomplete-tree plain" flex="1">
        <xul:treecols anonid="treecols">
          <xul:treecol class="autocomplete-treecol" id="treecolAutoCompleteValue" flex="2"/>
          <xul:treecol class="autocomplete-treecol" id="treecolAutoCompleteComment" flex="1" hidden="true"/>
        </xul:treecols>
        <xul:treechildren anonid="treebody" class="autocomplete-treebody" flex="1"/>
      </xul:tree>
      <xul:box role="search-box" class="autocomplete-search-box"/>
    </content>
    
    <implementation>
      <constructor><![CDATA[
        // listen for changes to default search engine
        var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
        if (pbi) {
          pbi.addObserver("browser.search", this.mPrefObserver, false);
          pbi.addObserver("browser.urlbar", this.mPrefObserver, false);
        }
      ]]></constructor>

      <destructor><![CDATA[
        var pbi = this.mPrefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
        if (pbi) {
          pbi.removeObserver("browser.search", this.mPrefObserver);
          pbi.removeObserver("browser.urlbar", this.mPrefObserver);
        }
      ]]></destructor>

      <property name="showSearch" onget="return this.mShowSearch;">
        <setter><![CDATA[
          this.mShowSearch = val;
          if (val) {
            this.updateEngines();
            this.mSearchBox.removeAttribute("hidden");
          } else {
            this.clearEngines();
            this.mSearchBox.setAttribute("hidden", "true");
          }
        ]]></setter>
      </property>
      
      <property name="defaultSearchEngine"
                onget="return this.textbox.getAttribute('defaultSearchEngine') == 'true';"
                onset="this.textbox.setAttribute('defaultSearchEngine', val); return val;"/>

      <field name="mSearchBox">
         document.getAnonymousElementByAttribute(this, "role", "search-box");
      </field>

      <field name="mPrefs">
        var svc = Components.classes["@mozilla.org/preferences-service;1"]
                            .getService(Components.interfaces.nsIPrefService);
        svc.getBranch(null);
      </field>

      <field name="mPrefObserver"><![CDATA[
        ({
          resultsPopup: this,
          
          observe: function(aObserver, aBlah, aPref) {
            if (/^browser\.search\./.test(aPref))
              this.resultsPopup.updateEngines();
            else if (/^browser\.urlbar\./.test(aPref))
              this.resultsPopup.updatePref(aPref);
          }
        });
      ]]></field>

      <field name="mInputListener"><![CDATA[
        (function(aEvent) {
          // "this" is the textbox, not the popup
          if (this.mSearchInputTO)
            window.clearTimeout(this.mSearchInputTO);
          this.mSearchInputTO = window.setTimeout(this.resultsPopup.mInputTimeout, this.timeout, this);
        });
      ]]></field>

      <field name="mInputTimeout"><![CDATA[
        (function(me) {
          me.resultsPopup.mSearchBox.searchValue = me.value;
          me.mSearchInputTO = 0;
        });
      ]]></field>

      <field name="mEnginesReady">false</field>
      
      <property name="overrideValue" readonly="true">
        <getter><![CDATA[
          if (this.mSearchBox.selectedIndex != -1) {
            // save the value.  RevealSearchPanel can close the popup
            var returnValue = this.mSearchBox.overrideValue;
            try {
              if (pref.getBoolPref("browser.search.opensidebarsearchpanel"))
                RevealSearchPanel();
            } catch (ex) {
            }
            return returnValue;
          }
          return null;
        ]]></getter>
      </property>

      <method name="updatePref">
        <parameter name="aPref"/>
        <body><![CDATA[
          if (aPref == "browser.urlbar.showSearch")
            this.showSearch = this.mPrefs.getBoolPref("browser.urlbar.showSearch");
        ]]></body>
      </method>
      
      <method name="addEngine">
        <parameter name="aEngineId"/>
        <parameter name="aName"/>
        <parameter name="aIcon"/>
        <parameter name="aSearchBarUrl"/>
        <body><![CDATA[
          var box = document.createElement("box");
          box.setAttribute("class", "autocomplete-search-engine");
          box.setAttribute("searchEngine", aEngineId);
          box.setAttribute("name", aName);
          box.setAttribute("icon", aIcon);
          box.setAttribute("searchBarUrl", aSearchBarUrl);
          box.setAttribute("engineIndex", this.childNodes.length);
          this.mSearchBox.appendChild(box);
        ]]></body>
      </method>

      <method name="clearEngines">
        <body><![CDATA[
          while (this.mSearchBox.hasChildNodes())
            this.mSearchBox.removeChild(this.mSearchBox.lastChild);
        ]]></body>
      </method>
   
      <method name="updateEngines">
        <body><![CDATA[
          var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
                      .getService(Components.interfaces.nsIRDFService);
          try {
            var ds = rdf.GetDataSource("rdf:internetsearch");
          } catch (ex) {
            // sometimes bad profiles cause this error, which horks the hold urlbar
            return;
          }
                              
          const kNC_Name = rdf.GetResource("http://home.netscape.com/NC-rdf#Name");
          const kNC_Icon = rdf.GetResource("http://home.netscape.com/NC-rdf#Icon");
          const kNC_searchBarUrl = rdf.GetResource("http://home.netscape.com/NC-rdf#actionBar");
        
          var defaultEngine = null;
          try {
            defaultEngine = this.mPrefs.getComplexValue("browser.search.defaultengine",
                                                        Components.interfaces.nsISupportsString).data;
          } catch(ex) {
            // this will re-invoke updateEngines via the pref observer if the pref changes
            this.ensureDefaultEnginePrefs(rdf, ds);
            return;
          }
          
          if (defaultEngine) {
            this.clearEngines();
            
            if (ds) {
              var res = rdf.GetResource(defaultEngine);
              try {
                var searchBarUrl = this.readRDFString(ds, res, kNC_searchBarUrl);
              } catch(ex) {
                searchBarUrl = null;
              }
              if (searchBarUrl == null) {
                // this will re-invoke updateEngines via the pref observer if the pref changes
                this.ensureDefaultEnginePrefs(rdf, ds);
                return;
              }
              this.addEngine(res.Value, 
                            this.readRDFString(ds, res, kNC_Name),
                            this.readRDFString(ds, res, kNC_Icon),
                            searchBarUrl);
            }
          }
          
          this.mEnginesReady = true;
        ]]></body>
      </method>

      <method name="ensureDefaultEnginePrefs">
        <parameter name="aRDF"/>
        <parameter name="aDS"/>
        <body><![CDATA[
          var defaultName = this.mPrefs.getComplexValue("browser.search.defaultenginename",
                                                        Components.interfaces.nsIPrefLocalizedString).data;
          const kNC_Root = aRDF.GetResource("NC:SearchEngineRoot");
          const kNC_child = aRDF.GetResource("http://home.netscape.com/NC-rdf#child");
          const kNC_Name = aRDF.GetResource("http://home.netscape.com/NC-rdf#Name");
          
          var arcs = aDS.GetTargets(kNC_Root, kNC_child, true);
          while (arcs.hasMoreElements()) {
            var engineRes = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
            var name = this.readRDFString(aDS, engineRes, kNC_Name);
            if (name == defaultName) {
              var str = Components.classes["@mozilla.org/supports-string;1"]
                                  .createInstance(Components.interfaces.nsISupportsString);
              str.data = engineRes.Value;
              this.mPrefs.setComplexValue("browser.search.defaultengine",
                                          Components.interfaces.nsISupportsString,
                                          str);
            }
          }
        ]]></body>
      </method>

      <method name="readRDFString">
        <parameter name="aDS"/>
        <parameter name="aRes"/>
        <parameter name="aProp"/>
        <body><![CDATA[
          var n = aDS.GetTarget(aRes, aProp, true);
          return n ? n.QueryInterface(Components.interfaces.nsIRDFLiteral).Value : null;
        ]]></body>
      </method>

      <method name="clearSelection">
        <body>
          this.view.selection.clearSelection();
          this.mSearchBox.selectedIndex = -1;
        </body>
      </method>

      <method name="selectBy">
        <parameter name="aReverse"/>
        <parameter name="aPage"/>
        <body><![CDATA[
          var sel;
          if (this.selectedIndex == -1 && aReverse ||
              this.mSearchBox.selectedIndex != -1) {
            sel = this.mSearchBox.selectBy(aReverse, aPage);
            if (sel != -1 || !aReverse)
              return -1;
          } 
          
          sel = this.getNextIndex(aReverse, aPage, this.selectedIndex, this.view.rowCount - 1);
          this.selectedIndex = sel;
          if (sel == -1 && !aReverse)
            this.mSearchBox.selectBy(aReverse, aPage);
          else if (this.mSearchBox.selectedIndex != -1)
            this.mSearchBox.selectedIndex = -1;
          return sel;
        ]]></body>
      </method>
    </implementation>

    <handlers>
      <handler event="popupshowing"><![CDATA[
        // sync up with prefs about showing search in the URL bar if
        // the URL bar hasn't finished initializing the default engine info
        //   -or-
        // the search sidebar tab was displayed already triggering a change
        // notification to the browser.search pref branch listener here which 
        // calls updateEngines but doesn't cause the ``Search for ...'' 
        // display string to be updated
        if ( (!this.mEnginesReady && this.defaultSearchEngine) ||
             !("mShowSearch" in this) ) 
          this.updatePref("browser.urlbar.showSearch");

        if (this.mShowSearch) {
          this.textbox.mSearchInputTO = 0;
          this.textbox.addEventListener("input", this.mInputListener, false);
          if ("searchValue" in this.mSearchBox)
            this.mSearchBox.searchValue = this.textbox.currentSearchString;
          else
            this.mSearchBox.setAttribute("searchvalue", this.textbox.currentSearchString);
        }
      ]]></handler>
      
      <handler event="popuphiding"><![CDATA[
        if (this.mShowSearch)
          this.textbox.removeEventListener("input", this.mInputListener, false);
      ]]></handler>      
    </handlers>
  </binding>

  <binding id="autocomplete-search-box">
    <content orient="vertical"/>
    
    <implementation>
      <constructor><![CDATA[
        var text = this.getAttribute("searchvalue");
        if (text)
          this.searchValue = text;
      ]]></constructor>

      <field name="mSelectedIndex">
        -1
      </field>

      <property name="activeChild" 
                onget="return this.childNodes[this.mSelectedIndex]"/>

      <property name="selectedIndex">
        <getter>return this.mSelectedIndex;</getter>
        
        <setter><![CDATA[
          if (this.mSelectedIndex != -1)
            this.activeChild.removeAttribute("menuactive");
          
          this.mSelectedIndex = val;

          if (val != -1)
            this.activeChild.setAttribute("menuactive", "true");
          return val;
        ]]></setter>
      
      </property>
      
      <property name="searchValue">
        <getter><![CDATA[
          return this.mSearchValue;
        ]]></getter>
        <setter><![CDATA[
          this.mSearchValue = val;
          var kids = this.childNodes;
          var searchForStrBundle = srGetStrBundle("chrome://navigator/locale/navigator.properties");
          for (var i = 0; i < kids.length; ++i) {
            var name = kids[i].getAttribute("name");
            var searchForStr = searchForStrBundle.formatStringFromName("searchFor",  [name, val], 2);
            kids[i].setAttribute("label", searchForStr);
          }
        ]]></setter>
      </property>
      
      <method name="selectBy">
        <parameter name="aReverse"/>
        <parameter name="aPage"/>
        <body><![CDATA[
          return this.selectedIndex = this.parentNode.getNextIndex(aReverse, aPage, this.selectedIndex, this.childNodes.length - 1);
        ]]></body>
      </method>

      <property name="overrideValue" readonly="true">
        <getter><![CDATA[
          var item = this.activeChild;
          if (item) {
            const ISEARCH_CONTRACTID = "@mozilla.org/rdf/datasource;1?name=internetsearch";
            const nsIInternetSearchService = Components.interfaces.nsIInternetSearchService;           
            var searchService = Components.classes[ISEARCH_CONTRACTID].getService(nsIInternetSearchService);
            var searchEng = item.getAttribute("searchEngine");
            var searchEngUrl = item.getAttribute("searchBarUrl");
            var escapedSearch = encodeURIComponent(this.mSearchValue)
            if (searchEngUrl) {
                searchEngUrl += escapedSearch;
                return searchEngUrl;
            } else {
              return searchService.GetInternetSearchURL(item.getAttribute("searchEngine"),escapedSearch, 0, 0, {value:0});
            }
          }
          return null;
        ]]></getter>
      </property>

    </implementation>

    <handlers>
      <handler event="mouseup">
        this.parentNode.textbox.onResultClick();
      </handler>
    </handlers>

  </binding>

  <binding id="autocomplete-search-engine">
    <content>
      <xul:image class="autocomplete-search-engine-img" xbl:inherits="src=icon"/>
      <xul:label class="autocomplete-search-engine-text" xbl:inherits="value=label" crop="right" flex="1"/>
    </content>
    
    <handlers>
      <handler event="mouseover">
        this.parentNode.selectedIndex = Number(this.getAttribute("engineIndex"));
      </handler>

      <handler event="mouseout">
        this.parentNode.selectedIndex = -1;
      </handler>
    </handlers>
  </binding>
  
</bindings>