Bug 1515323 - Simplify typeRestrictToken and port to UrlbarInput. r=mak
authorDão Gottwald <dao@mozilla.com>
Fri, 21 Dec 2018 14:35:31 +0000
changeset 508864 e90e92510da2b12149c2cb076b952a41015b423d
parent 508863 492d66a0a98a1fed4b30ceecd8e0d2ae54dbe7be
child 508865 ee1524718628d63277bb7da9a909e2f5f33f63dc
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1515323
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1515323 - Simplify typeRestrictToken and port to UrlbarInput. r=mak Differential Revision: https://phabricator.services.mozilla.com/D15069
browser/base/content/urlbarBindings.xml
browser/components/urlbar/UrlbarInput.jsm
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -1160,19 +1160,17 @@ file, You can obtain one at http://mozil
               let start = urlbar.selectionStart;
               let end = urlbar.selectionEnd;
               urlbar.inputField.value = urlbar.inputField.value.substring(0, start) +
                                         urlbar.inputField.value.substring(end);
               urlbar.selectionStart = urlbar.selectionEnd = start;
 
               let event = document.createEvent("UIEvents");
               event.initUIEvent("input", true, false, window, 0);
-              urlbar.dispatchEvent(event);
-
-              SetPageProxyState("invalid");
+              urlbar.inputField.dispatchEvent(event);
             }
 
             Cc["@mozilla.org/widget/clipboardhelper;1"]
               .getService(Ci.nsIClipboardHelper)
               .copyString(val);
           },
           supportsCommand(aCommand) {
             switch (aCommand) {
@@ -1679,40 +1677,37 @@ file, You can obtain one at http://mozil
           this.focus();
           this.value = value;
 
           // Avoid selecting the text if this method is called twice in a row.
           this.selectionStart = -1;
 
           let event = document.createEvent("Events");
           event.initEvent("input", true, true);
-          this.dispatchEvent(event);
+          this.inputField.dispatchEvent(event);
 
           // handleText() ignores the value if it's the same as the previous
           // value, but we want consecutive searches with the same value to be
           // possible.  If handleText() returned false, then manually start a
           // new search here.
           if (!this._onInputHandledText) {
             this.gotResultForCurrentQuery = false;
             this.controller.startSearch(value);
           }
         ]]></body>
       </method>
 
       <method name="typeRestrictToken">
         <parameter name="char"/>
         <body><![CDATA[
-          for (let c of [char, " "]) {
-            let code = c.charCodeAt(0);
-            gURLBar.inputField.dispatchEvent(new KeyboardEvent("keypress", {
-              keyCode: code,
-              charCode: code,
-              bubbles: true,
-            }));
-          }
+          this.inputField.value = char + " ";
+
+          let event = this.document.createEvent("UIEvents");
+          event.initUIEvent("input", true, false, window, 0);
+          this.inputField.dispatchEvent(event);
         ]]></body>
       </method>
 
       <method name="removeHiddenFocus">
         <body><![CDATA[
           this.classList.remove("hidden-focus");
         ]]></body>
       </method>
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -91,20 +91,20 @@ class UrlbarInput {
         },
       });
     }
 
     XPCOMUtils.defineLazyGetter(this, "valueFormatter", () => {
       return new UrlbarValueFormatter(this);
     });
 
-    this.addEventListener("input", this);
     this.addEventListener("mousedown", this);
     this.inputField.addEventListener("blur", this);
     this.inputField.addEventListener("focus", this);
+    this.inputField.addEventListener("input", this);
     this.inputField.addEventListener("mouseover", this);
     this.inputField.addEventListener("overflow", this);
     this.inputField.addEventListener("underflow", this);
     this.inputField.addEventListener("scrollend", this);
     this.inputField.addEventListener("select", this);
     this.inputField.addEventListener("keydown", this);
     this.view.panel.addEventListener("popupshowing", this);
     this.view.panel.addEventListener("popuphidden", this);
@@ -344,16 +344,24 @@ class UrlbarInput {
       lastKey,
       maxResults: UrlbarPrefs.get("maxRichResults"),
       isPrivate: this.isPrivate,
       providers: ["UnifiedComplete"],
       muxer: "UnifiedComplete",
     }));
   }
 
+  typeRestrictToken(char) {
+    this.inputField.value = char + " ";
+
+    let event = this.document.createEvent("UIEvents");
+    event.initUIEvent("input", true, false, this.window, 0);
+    this.inputField.dispatchEvent(event);
+  }
+
   // Getters and Setters below.
 
   get focused() {
     return this.textbox.getAttribute("focused") == "true";
   }
 
   get goButton() {
     return this.document.getAnonymousElementByAttribute(this.textbox, "anonid",
@@ -787,20 +795,18 @@ class CopyCutController {
     if (command == "cmd_cut" && this.isCommandEnabled(command)) {
       let start = urlbar.selectionStart;
       let end = urlbar.selectionEnd;
       urlbar.inputField.value = urlbar.inputField.value.substring(0, start) +
                                 urlbar.inputField.value.substring(end);
       urlbar.selectionStart = urlbar.selectionEnd = start;
 
       let event = urlbar.document.createEvent("UIEvents");
-      event.initUIEvent("input", true, false, this.window, 0);
-      urlbar.textbox.dispatchEvent(event);
-
-      urlbar.window.SetPageProxyState("invalid");
+      event.initUIEvent("input", true, false, urlbar.window, 0);
+      urlbar.inputField.dispatchEvent(event);
     }
 
     ClipboardHelper.copyString(val);
   }
 
   /**
    * @param {string} command
    * @returns {boolean}