home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / firefox-3.0.14 / chrome / browser.jar / content / browser / urlbarBindings.xml < prev    next >
Encoding:
Extensible Markup Language  |  2008-03-28  |  13.9 KB  |  389 lines

  1. <?xml version="1.0"?>
  2.  
  3.  
  4. <bindings id="urlbarBindings" xmlns="http://www.mozilla.org/xbl">
  5.  
  6.   <binding id="urlbar" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete">
  7.     <implementation implements="nsIObserver, nsIDOMEventListener">
  8.       <constructor><![CDATA[
  9.         this._prefs = Components.classes["@mozilla.org/preferences-service;1"]
  10.                                 .getService(Components.interfaces.nsIPrefService)
  11.                                 .getBranch("browser.urlbar.")
  12.                                 .QueryInterface(Components.interfaces.nsIPrefBranch2);
  13.  
  14.         this._prefs.addObserver("", this, false);
  15.         this.clickSelectsAll = this._prefs.getBoolPref("clickSelectsAll");
  16.         this.doubleClickSelectsAll = this._prefs.getBoolPref("doubleClickSelectsAll");
  17.         this.completeDefaultIndex = this._prefs.getBoolPref("autoFill");
  18.  
  19.         this._urlTooltip = document.getElementById("urlTooltip");
  20.  
  21.         this.inputField.controllers.insertControllerAt(0, this._copyCutController);
  22.         this.inputField.addEventListener("mousedown", this, false);
  23.         this.inputField.addEventListener("mousemove", this, false);
  24.         this.inputField.addEventListener("mouseout", this, false);
  25.       ]]></constructor>
  26.  
  27.       <destructor><![CDATA[
  28.         this._prefs.removeObserver("", this);
  29.         this._prefs = null;
  30.         this.inputField.controllers.removeController(this._copyCutController);
  31.         this.inputField.removeEventListener("mousedown", this, false);
  32.         this.inputField.removeEventListener("mousemove", this, false);
  33.         this.inputField.removeEventListener("mouseout", this, false);
  34.       ]]></destructor>
  35.  
  36.       <method name="_initURLTooltip">
  37.         <body><![CDATA[
  38.           if (this.focused || this.value == "")
  39.             return;
  40.           if (this._tooltipTimer)
  41.             clearTimeout(this._tooltipTimer);
  42.           this._tooltipTimer = setTimeout(function (self) {
  43.             self._tooltipTimer = 0;
  44.             var label = self._urlTooltip.firstChild;
  45.             label.value = self.value;
  46.             var bO = self.boxObject;
  47.             self._urlTooltip.maxWidth = bO.width;
  48.             self._urlTooltip.showPopup(self, bO.screenX, bO.screenY + bO.height, "tooltip");
  49.           }, 700, this);
  50.         ]]></body>
  51.       </method>
  52.  
  53.       <method name="_hideURLTooltip">
  54.         <body><![CDATA[
  55.           if (this._tooltipTimer) {
  56.             clearTimeout(this._tooltipTimer);
  57.             this._tooltipTimer = 0;
  58.           }
  59.           this._urlTooltip.hidePopup();
  60.         ]]></body>
  61.       </method>
  62.  
  63.       <method name="onDragOver">
  64.         <body>
  65.           return true;
  66.         </body>
  67.       </method>
  68.  
  69.       <method name="onDrop">
  70.         <parameter name="aEvent"/>
  71.         <parameter name="aXferData"/>
  72.         <parameter name="aDragSession"/>
  73.         <body><![CDATA[
  74.           var url = transferUtils.retrieveURLFromData(aXferData.data, aXferData.flavour.contentType);
  75.  
  76.           // The URL bar automatically handles inputs with newline characters,
  77.           // so we can get away with treating text/x-moz-url flavours as text/unicode.
  78.           if (url) {
  79.             nsDragAndDrop.dragDropSecurityCheck(aEvent, aDragSession, url);
  80.  
  81.             this.value = url;
  82.             SetPageProxyState("invalid");
  83.             try {
  84.               urlSecurityCheck(this.value,
  85.                                gBrowser.contentPrincipal,
  86.                                Ci.nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
  87.             } catch (ex) {
  88.               return;
  89.             }
  90.             handleURLBarCommand();
  91.           }
  92.         ]]></body>
  93.       </method>
  94.  
  95.       <method name="getSupportedFlavours">
  96.         <body><![CDATA[
  97.           var flavourSet = new FlavourSet();
  98.  
  99.           // Favor text/x-moz-url since text/unicode coming from Win32 1.8 branch
  100.           // drops contains URL\ntext.  The previous comment here said that
  101.           // plain text drops often come with text/x-moz-url flavor, but I
  102.           // haven't seen that, so hopefully that behavior has changed.
  103.           flavourSet.appendFlavour("text/x-moz-url");
  104.           flavourSet.appendFlavour("text/unicode");
  105.           flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
  106.           return flavourSet;
  107.         ]]></body>
  108.       </method>
  109.  
  110.       <field name="_copyCutController"><![CDATA[
  111.         ({
  112.           urlbar: this,
  113.           doCommand: function(aCommand) {
  114.             var urlbar = this.urlbar;
  115.             var start = urlbar.selectionStart;
  116.             var end = urlbar.selectionEnd;
  117.             if (start == end)
  118.               return;
  119.             var val;
  120.             if (start == 0 && end == urlbar.textLength) {
  121.               val = urlbar.value;
  122.  
  123.               // If the entire value is selected and it's a valid non-javascript,
  124.               // non-data URI, encode it.
  125.               var uri;
  126.               if (urlbar.getAttribute("pageproxystate") == "valid") {
  127.                 var ioService = Cc["@mozilla.org/network/io-service;1"]
  128.                                   .getService(Ci.nsIIOService);
  129.                 try {
  130.                   uri = ioService.newURI(val, null, null);
  131.                 } catch (e) {}
  132.               }
  133.               if (uri && !uri.schemeIs("javascript") && !uri.schemeIs("data"))
  134.                  val = uri.spec;
  135.  
  136.               if (aCommand == "cmd_cut" && this.isCommandEnabled(aCommand)) {
  137.                 urlbar.value = "";
  138.                 SetPageProxyState("invalid");
  139.               }
  140.             } else {
  141.               val = urlbar.value.substring(start, end);
  142.               if (aCommand == "cmd_cut" && this.isCommandEnabled(aCommand)) {
  143.                 urlbar.value = urlbar.value.substring(0, start) + urlbar.value.substring(end);
  144.                 urlbar.selectionStart = urlbar.selectionEnd = start;
  145.                 SetPageProxyState("invalid");
  146.               }
  147.             }
  148.             Cc["@mozilla.org/widget/clipboardhelper;1"]
  149.               .getService(Ci.nsIClipboardHelper)
  150.               .copyString(val);
  151.           },
  152.           supportsCommand: function(aCommand) {
  153.             switch (aCommand) {
  154.               case "cmd_copy":
  155.               case "cmd_cut":
  156.                 return true;
  157.             }
  158.             return false;
  159.           },
  160.           isCommandEnabled: function(aCommand) {
  161.             return this.supportsCommand(aCommand) &&
  162.                    (aCommand != "cmd_cut" || !this.urlbar.readOnly) &&
  163.                    this.urlbar.selectionStart < this.urlbar.selectionEnd;
  164.           },
  165.           onEvent: function(aEventName) {}
  166.         })
  167.       ]]></field>
  168.  
  169.       <method name="observe">
  170.         <parameter name="aSubject"/>
  171.         <parameter name="aTopic"/>
  172.         <parameter name="aData"/>
  173.         <body><![CDATA[
  174.           if (aTopic == "nsPref:changed") {
  175.             switch(aData) {
  176.               case "clickSelectsAll":
  177.               case "doubleClickSelectsAll":
  178.                 this[aData] = this._prefs.getBoolPref(aData);
  179.                 break;
  180.               case "autoFill":
  181.                 this.completeDefaultIndex = this._prefs.getBoolPref(aData);
  182.                 break;
  183.             }
  184.           }
  185.         ]]></body>
  186.       </method>
  187.  
  188.       <method name="handleEvent">
  189.         <parameter name="aEvent"/>
  190.         <body><![CDATA[
  191.           switch (aEvent.type) {
  192.             case "mousedown":
  193.               if (this.doubleClickSelectsAll &&
  194.                   aEvent.button == 0 && aEvent.detail == 2) {
  195.                 this.editor.selectAll();
  196.                 aEvent.preventDefault();
  197.               }
  198.               break;
  199.             case "mousemove":
  200.               this._initURLTooltip();
  201.               break;
  202.             case "mouseout":
  203.               this._hideURLTooltip();
  204.               break;
  205.           }
  206.         ]]></body>
  207.       </method>
  208.  
  209.       <property name="textValue"
  210.                 onget="return this.value;">
  211.         <setter>
  212.           <![CDATA[
  213.           try {
  214.             let uri = Cc["@mozilla.org/network/io-service;1"].
  215.                       getService(Ci.nsIIOService).
  216.                       newURI(val, null, null);
  217.             val = losslessDecodeURI(uri);
  218.           } catch (ex) { }
  219.           this.value = val;
  220.  
  221.           // Completing a result should simulate the user typing the result, so
  222.           // fire an input event.
  223.           let evt = document.createEvent("UIEvents");
  224.           evt.initUIEvent("input", true, false, window, 0);
  225.           this.mIgnoreInput = true;
  226.           this.dispatchEvent(evt);
  227.           this.mIgnoreInput = false;
  228.  
  229.           return this.value;
  230.           ]]>
  231.         </setter>
  232.       </property>
  233.     </implementation>
  234.  
  235.     <handlers>
  236.       <handler event="focus" phase="capturing" action="this._hideURLTooltip();"/>
  237.       <handler event="dragover" phase="capturing" action="nsDragAndDrop.dragOver(event, this);"/>
  238.       <handler event="dragdrop" phase="capturing" action="nsDragAndDrop.drop(event, this);"/>
  239.     </handlers>
  240.  
  241.   </binding>
  242.  
  243.   <!-- Note: this binding is applied to the autocomplete popup used in the Search bar and in web page content -->
  244.   <binding id="browser-autocomplete-result-popup" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete-result-popup">
  245.     <implementation>
  246.       <method name="openAutocompletePopup">
  247.         <parameter name="aInput"/>
  248.         <parameter name="aElement"/>
  249.         <body>
  250.           <![CDATA[
  251.           // initially the panel is hidden
  252.           // to avoid impacting startup / new window performance
  253.           aInput.popup.hidden = false;
  254.  
  255.           // this method is defined on the base binding
  256.           this._openAutocompletePopup(aInput, aElement);
  257.         ]]></body>
  258.       </method>
  259.  
  260.       <method name="onPopupClick">
  261.         <parameter name="aEvent"/>
  262.         <body><![CDATA[
  263.           // Ignore all right-clicks
  264.           if (aEvent.button == 2)
  265.             return;
  266.  
  267.           var controller = this.view.QueryInterface(Components.interfaces.nsIAutoCompleteController);
  268.  
  269.           // Check for unmodified left-click, and use default behavior
  270.           if (aEvent.button == 0 && !aEvent.shiftKey && !aEvent.ctrlKey &&
  271.               !aEvent.altKey && !aEvent.metaKey) {
  272.             controller.handleEnter(true);
  273.             return;
  274.           }
  275.  
  276.           // Check for middle-click or modified clicks on the search bar
  277.           var searchBar = BrowserSearch.searchBar;
  278.           if (searchBar && searchBar.textbox == this.mInput) {
  279.             // Handle search bar popup clicks
  280.             var search = controller.getValueAt(this.selectedIndex);
  281.   
  282.             // close the autocomplete popup and revert the entered search term
  283.             this.closePopup();
  284.             controller.handleEscape();
  285.  
  286.             // Fill in the search bar's value
  287.             searchBar.value = search;
  288.  
  289.             // open the search results according to the clicking subtlety
  290.             var where = whereToOpenLink(aEvent, false, true);
  291.             searchBar.doSearch(search, where);
  292.           }
  293.           ]]></body>
  294.         </method>
  295.       </implementation>
  296.     </binding>
  297.  
  298.     <binding id="urlbar-rich-result-popup" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete-rich-result-popup">
  299.       <implementation>
  300.       <field name="_maxResults">0</field>
  301.  
  302.       <field name="_bundle" readonly="true">
  303.         Cc["@mozilla.org/intl/stringbundle;1"].
  304.           getService(Ci.nsIStringBundleService).
  305.           createBundle("chrome://browser/locale/places/places.properties");
  306.       </field>
  307.  
  308.       <property name="maxResults" readonly="true">
  309.         <getter>
  310.           <![CDATA[
  311.             if (!this._maxResults) {
  312.               var prefService =
  313.                 Components.classes["@mozilla.org/preferences-service;1"]
  314.                           .getService(Components.interfaces.nsIPrefBranch);
  315.               this._maxResults = prefService.getIntPref("browser.urlbar.maxRichResults");
  316.             }
  317.             return this._maxResults;
  318.           ]]>
  319.         </getter>
  320.       </property>
  321.  
  322.       <method name="openAutocompletePopup">
  323.         <parameter name="aInput"/>
  324.         <parameter name="aElement"/>
  325.         <body>
  326.           <![CDATA[
  327.           // initially the panel is hidden
  328.           // to avoid impacting startup / new window performance
  329.           aInput.popup.hidden = false;
  330.  
  331.           // this method is defined on the base binding
  332.           this._openAutocompletePopup(aInput, aElement);
  333.         ]]></body>
  334.       </method>
  335.  
  336.       <method name="onPopupClick">
  337.         <parameter name="aEvent"/>
  338.         <body>
  339.           <![CDATA[
  340.           // Ignore right-clicks
  341.           if (aEvent.button == 2)
  342.             return;
  343.  
  344.           var controller = this.view.QueryInterface(Components.interfaces.nsIAutoCompleteController);
  345.  
  346.           // Check for unmodified left-click, and use default behavior
  347.           if (aEvent.button == 0 && !aEvent.shiftKey && !aEvent.ctrlKey &&
  348.               !aEvent.altKey && !aEvent.metaKey) {
  349.             controller.handleEnter(true);
  350.             return;
  351.           }
  352.  
  353.           // Check for middle-click or modified clicks on the URL bar
  354.           if (gURLBar && this.mInput == gURLBar) {
  355.             var url = controller.getValueAt(this.selectedIndex);
  356.  
  357.             // close the autocomplete popup and revert the entered address
  358.             this.closePopup();
  359.             controller.handleEscape();
  360.  
  361.             // respect the usual clicking subtleties
  362.             openUILink(url, aEvent);
  363.           }
  364.         ]]>
  365.         </body>
  366.       </method>
  367.  
  368.       <method name="createResultLabel">
  369.         <parameter name="aTitle"/>
  370.         <parameter name="aUrl"/>
  371.         <parameter name="aType"/>
  372.         <body>
  373.           <![CDATA[
  374.             var label = aTitle + " " + aUrl;
  375.             // convert aType (ex: "ac-result-type-<aType>") to text to be spoke aloud
  376.             // by screen readers.  convert "tag" and "bookmark" to the localized versions,
  377.             // but don't do anything for "favicon" (the default)
  378.             if (aType != "favicon") {
  379.               label += " " + this._bundle.GetStringFromName(aType + "ResultLabel");
  380.             }
  381.             return label;
  382.           ]]>
  383.         </body>
  384.       </method>
  385.  
  386.     </implementation>
  387.   </binding>
  388. </bindings>
  389.