Bug 1516088 - Implement UrlbarInput::handleRevert and Escape key handling. r=Standard8
authorDão Gottwald <dao@mozilla.com>
Thu, 03 Jan 2019 14:53:20 +0000
changeset 509625 46fd6f5124ff0e8cc890208ac92d8663606b7711
parent 509624 777128d1fd48dff16999326fb8a475784a5de03a
child 509626 8908b6922e23707e92e6bd7a55c5c5460f4fa717
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)
reviewersStandard8
bugs1516088
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 1516088 - Implement UrlbarInput::handleRevert and Escape key handling. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D15253
browser/components/urlbar/UrlbarController.jsm
browser/components/urlbar/UrlbarInput.jsm
--- a/browser/components/urlbar/UrlbarController.jsm
+++ b/browser/components/urlbar/UrlbarController.jsm
@@ -160,27 +160,31 @@ class UrlbarController {
         event.ctrlKey &&
         (event.key == "n" || event.key == "p")) {
       this.view.selectNextItem({ reverse: event.key == "p" });
       event.preventDefault();
       return;
     }
 
     switch (event.keyCode) {
+      case KeyEvent.DOM_VK_ESCAPE:
+        this.input.handleRevert();
+        event.preventDefault();
+        break;
       case KeyEvent.DOM_VK_RETURN:
         if (AppConstants.platform == "macosx" &&
             event.metaKey) {
           // Prevent beep on Mac.
           event.preventDefault();
         }
         // TODO: We may have an autoFill entry, so we should use that instead.
         // TODO: We should have an input bufferrer so that we can use search results
         // if appropriate.
         this.input.handleCommand(event);
-        return;
+        break;
       case KeyEvent.DOM_VK_TAB:
         if (this.view.isOpen) {
           this.view.selectNextItem({ reverse: event.shiftKey });
           event.preventDefault();
         }
         break;
       case KeyEvent.DOM_VK_DOWN:
       case KeyEvent.DOM_VK_UP:
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -246,16 +246,24 @@ class UrlbarInput {
         }
       });
       return;
     }
 
     this._loadURL(url, where, openParams);
   }
 
+  handleRevert() {
+    this.window.gBrowser.userTypedValue = null;
+    this.window.URLBarSetURI(null, true);
+    if (this.value && this.focused) {
+      this.select();
+    }
+  }
+
   /**
    * Called by the view when a result is picked.
    *
    * @param {Event} event The event that picked the result.
    * @param {UrlbarMatch} result The result that was picked.
    */
   pickResult(event, result) {
     this.setValueFromResult(result);
@@ -268,18 +276,17 @@ class UrlbarInput {
     let where = this._whereToOpen(event);
     let openParams = {
       postData: null,
       allowInheritPrincipal: false,
     };
 
     switch (result.type) {
       case UrlbarUtils.MATCH_TYPE.TAB_SWITCH: {
-        // TODO: Implement handleRevert or equivalent on the input.
-        // this.input.handleRevert();
+        this.handleRevert();
         let prevTab = this.window.gBrowser.selectedTab;
         let loadOpts = {
           adoptIntoActiveWindow: UrlbarPrefs.get("switchTabs.adoptIntoActiveWindow"),
         };
 
         if (this.window.switchToTabHavingURI(Services.io.newURI(result.payload.url), false, loadOpts) &&
             prevTab.isEmpty) {
           this.window.gBrowser.removeTab(prevTab);
@@ -585,28 +592,26 @@ class UrlbarInput {
     }
 
     // Focus the content area before triggering loads, since if the load
     // occurs in a new tab, we want focus to be restored to the content
     // area when the current tab is re-selected.
     browser.focus();
 
     if (openUILinkWhere != "current") {
-      // TODO: Implement handleRevert or equivalent on the input.
-      // this.input.handleRevert();
+      this.handleRevert();
     }
 
     try {
       this.window.openTrustedLinkIn(url, openUILinkWhere, params);
     } catch (ex) {
       // This load can throw an exception in certain cases, which means
       // we'll want to replace the URL with the loaded URL:
       if (ex.result != Cr.NS_ERROR_LOAD_SHOWED_ERRORPAGE) {
-        // TODO: Implement handleRevert or equivalent on the input.
-        // this.input.handleRevert();
+        this.handleRevert();
       }
     }
 
     // TODO This should probably be handed via input.
     // Ensure the start of the URL is visible for usability reasons.
     // this.selectionStart = this.selectionEnd = 0;
 
     this.closePopup();