Bug 513290: Page loads do not respect visibility of Awesome Bar Results, r=mfinkle
authorVivien Nicolas <21@vingtetun.org>
Sat, 19 Sep 2009 00:17:52 -0400
changeset 65578 73413e896bbcd06385f8c3ca001df7fe3fa12141
parent 65577 c05dd0e245a750495777c3c24908ed5784ab19de
child 65579 51b99ac87d1e8082c0ee2516b8d1980494b14eb7
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs513290
Bug 513290: Page loads do not respect visibility of Awesome Bar Results, r=mfinkle
mobile/chrome/content/bindings.xml
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/bindings.xml
+++ b/mobile/chrome/content/bindings.xml
@@ -16,27 +16,21 @@
         <body><![CDATA[
           this.popup.openAutocompletePopup(this, null);
         ]]></body>
       </method>
       <method name="closePopup">
         <body><![CDATA[
           // hack! we want to revert to the "all results" popup when the
           // controller would otherwise close us because of an empty search
-          // string, and handle closing ourselves (via reallyClosePopup).
+          // string.
           if (this.value == "")
             this.showHistoryPopup();
         ]]></body>
       </method>
-      <method name="reallyClosePopup">
-        <body><![CDATA[
-          this.mConsumeRollupEvent = false;
-          this.popup.closePopup();
-        ]]></body>
-      </method>
     </implementation>
     <handlers>
       <handler event="keypress" keycode="VK_RETURN" phase="capturing">
         <![CDATA[
           if (this.popup.allBookmarksItemSelected) {
             this.popup.closePopup();
             CommandUpdater.doCommand("cmd_bookmarks");
           }
@@ -169,25 +163,26 @@
 
           // Scroll to the top left for the next open (only if necessary).
           // Doing this now rather than in open() turns out to be faster,
           // possibly because it avoids scrolling too soon after we uncollapse
           // ourselves
           if (this._items.scrollTop || this._items.scrollLeft)
             this._scrollBoxObject.scrollTo(0, 0);
 
-          BrowserUI.showToolbar();
+          BrowserUI.showToolbar(false);
           BrowserUI.popDialog();
         ]]></body>
       </method>
 
       <!-- Helper used by active dialog system -->
       <method name="close">
         <body><![CDATA[
           this.input.reset();
+          this.input.blur();
           this.closePopup();
         ]]></body>
       </method>
 
       <field name="_XULNS">("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul")</field>
 
       <method name="invalidate">
         <body><![CDATA[
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -84,17 +84,18 @@ var BrowserUI = {
       return;
 
     var caption = aDocument.title;
     if (!caption) {
       caption = this.getDisplayURI(browser);
       if (caption == "about:blank")
         caption = "";
     }
-    this._edit.value = caption;
+
+    this._setURI(caption);
   },
 
   /*
    * Dispatched by window.close() to allow us to turn window closes into tabs
    * closes.
    */
   _domWindowClose: function (aEvent) {
     if (!aEvent.isTrusted)
@@ -173,17 +174,17 @@ var BrowserUI = {
     browser.mIconURL = faviconURI.spec;
 
     fis.setAndLoadFaviconForPage(browser.currentURI, faviconURI, true);
     this._favicon.src = faviconURI.spec;
   },
 
   showToolbar : function showToolbar(aEdit) {
     this.hidePanel();
-    this._editToolbar(aEdit);
+    this._editURI(aEdit);
   },
 
   _toolbarLocked: 0,
   lockToolbar: function lockToolbar() {
     this._toolbarLocked++;
     document.getElementById("toolbar-moveable-container").top = "0";
   },
   
@@ -191,32 +192,36 @@ var BrowserUI = {
     if (!this._toolbarLocked)
       return;
     
     this._toolbarLocked--;
     if (!this._toolbarLocked)
       document.getElementById("toolbar-moveable-container").top = "";
   },
 
-  _editToolbar : function _editToolbar(aEdit) {
+  _setURI: function _setURI(aCaption) {
+    if (this.isAutoCompleteOpen())
+      this._edit.defaultValue = aCaption;
+    else
+      this._edit.value = aCaption;
+  },
+
+  _editURI : function _editURI(aEdit) {
     var icons = document.getElementById("urlbar-icons");
     if (aEdit && icons.getAttribute("mode") != "edit") {
       icons.setAttribute("mode", "edit");
       this._edit.defaultValue = this._edit.value;
 
       let urlString = this.getDisplayURI(Browser.selectedBrowser);
       if (urlString == "about:blank")
         urlString = "";
       this._edit.value = urlString;
-      this._edit.inputField.focus();
     }
     else if (!aEdit && icons.getAttribute("mode") != "view") {
       icons.setAttribute("mode", "view");
-      this._edit.inputField.blur();
-      this._edit.reallyClosePopup();
     }
   },
 
   _closeOrQuit: function _closeOrQuit() {
     // Close active dialog, if we have one. If not then close the application.
     let dialog = this.activeDialog;
     if (dialog)
       dialog.close();
@@ -398,36 +403,29 @@ var BrowserUI = {
     let icons = document.getElementById("urlbar-icons");
 
     // Use documentURIObject in the favicon construction so that we
     // do the right thing with about:-style error pages.  Bug 515188
     let uri = Browser.selectedBrowser.contentDocument.documentURIObject;
 
     switch (aState) {
       case TOOLBARSTATE_LOADED:
-        icons.setAttribute("mode", "view");
+        if (icons.getAttribute("mode" != "edit"))
+          icons.setAttribute("mode", "view");
         
-        // We handle showing the toolbar for new tabs in BrowserUI.newTab()
-        if (uri.spec != "about:blank") {
-          this.showToolbar(false);
-        }
-
         if (!this._faviconLink)
           this._faviconLink = uri.prePath + "/favicon.ico";
         this._setIcon(this._faviconLink);
         this.updateIcon();
         this._faviconLink = null;
         break;
 
       case TOOLBARSTATE_LOADING:
-        this.showToolbar();
-        
-        // Force the mode back to "loading" since showToolbar() changes it to "view"
-        // and that messes up the CSS rules depending on the "mode" attribute
-        icons.setAttribute("mode", "loading");
+        if (icons.getAttribute("mode" != "edit"))
+          icons.setAttribute("mode", "loading");
 
         this._favicon.src = "";
         this._faviconLink = null;
         this.updateIcon();
         break;
     }
   },
 
@@ -453,100 +451,109 @@ var BrowserUI = {
     try {
       uri = this._URIFixup.createExposableURI(uri);
     } catch (ex) {}
 
     return uri.spec;
   },
 
   /* Set the location to the current content */
-  setURI : function() {
+  updateURI : function() {
     var browser = Browser.selectedBrowser;
 
     // FIXME: deckbrowser should not fire TabSelect on the initial tab (bug 454028)
     if (!browser.currentURI)
       return;
 
     // Update the navigation buttons
     this._updateButtons(browser);
 
     // Check for a bookmarked page
     this.updateStar();
 
     var urlString = this.getDisplayURI(browser);
     if (urlString == "about:blank")
       urlString = "";
 
-    this._edit.value = urlString;
+    this._setURI(urlString);
   },
 
   goToURI : function(aURI) {
     aURI = aURI || this._edit.value;
     if (!aURI)
       return;
 
-    this._edit.reallyClosePopup();
+    this._edit.popup.close();
 
     var flags = Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
     getBrowser().loadURIWithFlags(aURI, flags, null, null);
 
     gHistSvc.markPageAsTyped(gURIFixup.createFixupURI(aURI, 0));
   },
 
   search : function() {
     var queryURI = "http://www.google.com/search?q=" + this._edit.value + "&hl=en&lr=&btnG=Search";
     getBrowser().loadURI(queryURI, null, null, false);
   },
 
-  showAutoComplete : function(showDefault) {
+  showAutoComplete : function() {
+    if (this.isAutoCompleteOpen())
+      return;
     BrowserSearch.updateSearchButtons();
     this._edit.showHistoryPopup();
   },
 
+  isAutoCompleteOpen: function isAutoCompleteOpen() {
+    return this._edit.popup.popupOpen;
+  },
+
   doButtonSearch : function(button) {
     if (!("engine" in button) || !button.engine)
       return;
 
-    var urlbar = this._edit;
-    urlbar.open = false;
-    var value = urlbar.value;
+    // We don't want the button to look pressed for now
+    button.parentNode.selectedItem = null;
+    
+    this._edit.popup.closePopup();
 
-    var submission = button.engine.getSubmission(value, null);
+    var submission = button.engine.getSubmission(this._edit.value, null);
     getBrowser().loadURI(submission.uri.spec, null, submission.postData, false);
   },
 
   updateStar : function() {
     if (PlacesUtils.getMostRecentBookmarkForURI(Browser.selectedBrowser.currentURI) != -1)
       this.starButton.setAttribute("starred", "true");
     else
       this.starButton.removeAttribute("starred");
   },
 
   goToBookmark : function goToBookmark(aEvent) {
     if (aEvent.originalTarget.localName == "button")
       return;
 
     var list = document.getElementById("urllist-items");
-    BrowserUI.goToURI(list.selectedItem.value);
+    this.goToURI(list.selectedItem.value);
   },
 
   showHistory : function() {
     // XXX Fix me with a real UI
   },
 
   showBookmarks : function () {
     BookmarkList.show();
   },
 
   newTab : function newTab(aURI) {
     aURI = aURI || "about:blank";
     let tab = Browser.addTab(aURI, true);
 
-    if (aURI == "about:blank")
+    if (aURI == "about:blank") {
+      this.showToolbar(true);
       this.showAutoComplete();
+    }
     return tab;
   },
 
   closeTab : function closeTab(aTab) {
     // If no tab is passed in, assume the current tab
     Browser.closeTab(aTab || Browser.selectedTab);
   },
 
@@ -618,17 +625,17 @@ var BrowserUI = {
           NewTabPopup.show(aEvent.target);
         break;
       // URL textbox events
       case "click":
         this.doCommand("cmd_openLocation");
         break;
       case "keypress":
         if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE) {
-          let dialog = BrowserUI.activeDialog;
+          let dialog = this.activeDialog;
           if (dialog)
             dialog.close();
         }
         break;
       case "mousedown":
         this._updatePopup(aEvent);
 
         if (aEvent.detail == 2 &&
@@ -698,17 +705,17 @@ var BrowserUI = {
       case "cmd_search":
         this.search();
         break;
       case "cmd_go":
         this.goToURI();
         break;
       case "cmd_openLocation":
         this.showToolbar(true);
-        BrowserUI.showAutoComplete();
+        this.showAutoComplete();
         break;
       case "cmd_star":
       {
         var bookmarkURI = browser.currentURI;
         var bookmarkTitle = browser.contentDocument.title || bookmarkURI.spec;
 
         let autoClose = false;
 
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -703,17 +703,17 @@ var Browser = {
 
     bv.setBrowser(tab.browser, tab.browserViewportState, false);
     bv.forceContainerResize();
 
     document.getElementById("tabs").selectedTab = tab.chromeTab;
 
     if (!firstTab) {
       // Update all of our UI to reflect the new tab's location
-      BrowserUI.setURI();
+      BrowserUI.updateURI();
       getIdentityHandler().checkIdentity();
 
       let event = document.createEvent("Events");
       event.initEvent("TabSelect", true, false);
       tab.chromeTab.dispatchEvent(event);
     }
 
     tab.lastSelected = Date.now();
@@ -2203,17 +2203,17 @@ ProgressController.prototype = {
   /** This method is called to indicate a change to the current location. */
   onLocationChange: function(aWebProgress, aRequest, aLocationURI) {
     let location = aLocationURI ? aLocationURI.spec : "";
     let selectedBrowser = Browser.selectedBrowser;
 
     this._hostChanged = true;
 
     if (this._tab == Browser.selectedTab) {
-      BrowserUI.setURI();
+      BrowserUI.updateURI();
 
       // We're about to have new page content, to scroll the content area
       // to the top so the new paints will draw correctly.
       Browser.scrollContentToTop();
     }
   },
 
   /**
@@ -2268,17 +2268,17 @@ ProgressController.prototype = {
 
     this._tab.updateThumbnail();
   },
 
   _documentStop: function() {
     // translate any phone numbers
     Browser.translatePhoneNumbers();
 
-    if (this._tab == Browser.selectedTab) {
+    if (this._tab == Browser.selectedTab && !BrowserUI.isAutoCompleteOpen()) {
       // focus the dom window
       if (this.browser.currentURI.spec != "about:blank")
         this.browser.contentWindow.focus();
     }
   }
 };