Bug 599833 Add "Paste and Go" to the context menu of the URLbar. r=Neil sr=Neil
authorPhilip Chee <philip.chee@gmail.com>
Mon, 04 Oct 2010 00:23:16 +0800
changeset 6473 53261a78051d204a0ef9bb92af208c462a48f412
parent 6472 1575284f0f7a8a3daf9df7a3036fd4c0894d8008
child 6474 068fad733a70949a5905c6ad3d98f3124a0c1aba
push idunknown
push userunknown
push dateunknown
reviewersNeil, Neil
bugs599833
Bug 599833 Add "Paste and Go" to the context menu of the URLbar. r=Neil sr=Neil
suite/browser/navigator.css
suite/browser/urlbarBindings.xml
suite/locales/en-US/chrome/common/utilityOverlay.dtd
--- a/suite/browser/navigator.css
+++ b/suite/browser/navigator.css
@@ -19,16 +19,20 @@ tabbrowser {
 }
 
 /* ::::: urlbar autocomplete ::::: */
 
 #urlbar {
   -moz-binding: url("chrome://navigator/content/urlbarBindings.xml#urlbar");
 }
 
+#urlbar > .autocomplete-textbox-container > .textbox-input-box {
+  -moz-binding: url("chrome://navigator/content/urlbarBindings.xml#input-box-paste");
+}
+
 panel[for="urlbar"] {
   -moz-binding: url("chrome://navigator/content/urlbarBindings.xml#autocomplete-result-popup") !important;
 }
 
 .autocomplete-search-box {
   -moz-binding: url("chrome://navigator/content/urlbarBindings.xml#autocomplete-search-box");
 }
 
--- a/suite/browser/urlbarBindings.xml
+++ b/suite/browser/urlbarBindings.xml
@@ -1,28 +1,35 @@
 <?xml version="1.0"?>
 
+<!DOCTYPE bindings [
+  <!ENTITY % textcontextDTD SYSTEM "chrome://communicator/locale/utilityOverlay.dtd">
+  %textcontextDTD;
+]>
+
 <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");
+        this.inputField.controllers.insertControllerAt(0, this._editItemsController);
       ]]></constructor>
 
       <destructor><![CDATA[
+        this.inputField.controllers.removeController(this._editItemsController);
         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);
@@ -88,19 +95,51 @@
                 this.mInputElt.setSelectionRange(entry.length, this.value.length);
                 this.mDefaultMatchFilled = true;
               }
               this.mNeedToComplete = true;
             }
           }
         ]]></body>
       </method>
+
+      <field name="_editItemsController"><![CDATA[
+        ({
+          editor: this.editor,
+          _fireEvent: this._fireEvent.bind(this),
+          supportsCommand: function(aCommand) {
+            switch (aCommand) {
+              case "cmd_pasteAndGo":
+                return true;
+            }
+            return false;
+          },
+          isCommandEnabled: function(aCommand) {
+            switch (aCommand) {
+              case "cmd_pasteAndGo":
+                return document.commandDispatcher
+                               .getControllerForCommand("cmd_paste")
+                               .isCommandEnabled("cmd_paste");
+            }
+          },
+          doCommand: function(aCommand) {
+            switch (aCommand) {
+              case "cmd_pasteAndGo":
+                this.value = "";
+                goDoCommand("cmd_paste");
+                this._fireEvent("textentered", "pasting");
+                break;
+            }
+          }.bind(this),
+          onEvent: function(aEventName) {}
+        })
+      ]]></field>
     </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"/>
@@ -416,10 +455,32 @@
         this.parentNode.selectedIndex = Number(this.getAttribute("engineIndex"));
       </handler>
 
       <handler event="mouseout">
         this.parentNode.selectedIndex = -1;
       </handler>
     </handlers>
   </binding>
-  
+
+  <binding id="input-box-paste" extends="chrome://global/content/bindings/textbox.xml#input-box">
+    <content context="_child">
+      <children/>
+      <xul:menupopup anonid="input-box-contextmenu"
+                     class="textbox-contextmenu"
+                     onpopupshowing="if (document.commandDispatcher.focusedElement != this.parentNode.firstChild)
+                                       this.parentNode.firstChild.focus();
+                                     this.parentNode._doPopupItemEnabling(this);"
+                     oncommand="var cmd = event.originalTarget.getAttribute('cmd'); if(cmd) { this.parentNode.doCommand(cmd); event.stopPropagation(); }">
+        <xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo"/>
+        <xul:menuseparator/>
+        <xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut"/>
+        <xul:menuitem label="&copyCmd.label;" accesskey="&copyCmd.accesskey;" cmd="cmd_copy"/>
+        <xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste"/>
+        <xul:menuitem label="&pasteGoCmd.label;" accesskey="&pasteGoCmd.accesskey;" cmd="cmd_pasteAndGo"/>
+        <xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete"/>
+        <xul:menuseparator/>
+        <xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"/>
+      </xul:menupopup>
+    </content>
+  </binding>
+
 </bindings>
--- a/suite/locales/en-US/chrome/common/utilityOverlay.dtd
+++ b/suite/locales/en-US/chrome/common/utilityOverlay.dtd
@@ -31,16 +31,18 @@
 <!ENTITY cutCmd.key							"X">  
 <!ENTITY cutCmd.accesskey					"t"> 
 <!ENTITY copyCmd.label						"Copy">  
 <!ENTITY copyCmd.key						"C">  
 <!ENTITY copyCmd.accesskey					"c"> 
 <!ENTITY pasteCmd.label						"Paste">  
 <!ENTITY pasteCmd.key						"V">  
 <!ENTITY pasteCmd.accesskey					"p"> 
+<!ENTITY pasteGoCmd.label					"Paste &amp; Go">
+<!ENTITY pasteGoCmd.accesskey				"G">
 <!ENTITY deleteCmd.label					"Delete">  
 <!ENTITY deleteCmd.accesskey				"d"> 
 <!ENTITY selectAllCmd.label					"Select All">  
 <!ENTITY selectAllCmd.key					"A">  
 <!ENTITY selectAllCmd.accesskey				"a"> 
 <!ENTITY preferencesCmd.label				"Preferences…">
 <!ENTITY preferencesCmd.key					"E">  
 <!ENTITY preferencesCmd.accesskey			"e">