Bug 590779 - Virtual keyboard should not been showed on urlbar first tap [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Fri, 27 Aug 2010 00:48:27 +0200
changeset 66498 80a1e1d4e56f8163da6a959183ceed82a412ce14
parent 66497 a94ad6b166eaf3e0c6bcc53f72d7bd1a858e6ab8
child 66499 49eefc2a59257eebc77ab7b3f826e76d9f4cbefe
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
bugs590779
Bug 590779 - Virtual keyboard should not been showed on urlbar first tap [r=mfinkle]
mobile/chrome/content/Util.js
mobile/chrome/content/bindings.xml
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.xul
mobile/themes/core/browser.css
--- a/mobile/chrome/content/Util.js
+++ b/mobile/chrome/content/Util.js
@@ -295,16 +295,17 @@ Util.Timeout.prototype = {
 /**
  * Cache of commonly used elements.
  */
 let Elements = {};
 
 [
   ["browserBundle",      "bundle_browser"],
   ["contentShowing",     "bcast_contentShowing"],
+  ["urlbarState",        "bcast_urlbarState"],
   ["stack",              "stack"],
   ["panelUI",            "panel-container"],
   ["viewBuffer",         "view-buffer"],
   ["toolbarContainer",   "toolbar-container"],
 ].forEach(function (elementGlobal) {
   let [name, id] = elementGlobal;
   Elements.__defineGetter__(name, function () {
     let element = document.getElementById(id);
--- a/mobile/chrome/content/bindings.xml
+++ b/mobile/chrome/content/bindings.xml
@@ -11,23 +11,20 @@
     xmlns:svg="http://www.w3.org/2000/svg"
     xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
   <binding id="autocomplete-aligned" extends="chrome://global/content/bindings/autocomplete.xml#autocomplete">
     <implementation>
       <method name="openPopup">
         <body><![CDATA[
           this.popup.openAutocompletePopup(this, null);
-          this.setAttribute("open", "true");
         ]]></body>
       </method>
       <method name="closePopup">
         <body><![CDATA[
-          this.removeAttribute("open");
-
           // hack! we want to revert to the "all results" popup when the
           // controller would otherwise close us because of an empty search
           // string.
           if (this.value == "")
             this.showHistoryPopup();
         ]]></body>
       </method>
     </implementation>
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -135,23 +135,22 @@ var BrowserUI = {
     let back = document.getElementById("cmd_back");
     let forward = document.getElementById("cmd_forward");
 
     back.setAttribute("disabled", !aBrowser.canGoBack);
     forward.setAttribute("disabled", !aBrowser.canGoForward);
   },
 
   _updateToolbar: function _updateToolbar() {
-    let icons = document.getElementById("urlbar-icons");
-    let mode = icons.getAttribute("mode");
+    let mode = Elements.urlbarState.getAttribute("mode");
     if (Browser.selectedTab.isLoading() && mode != "loading") {
-      icons.setAttribute("mode", "loading");
+      Elements.urlbarState.setAttribute("mode", "loading");
     }
     else if (mode != "view") {
-      icons.setAttribute("mode", "view");
+      Elements.urlbarState.setAttribute("mode", "view");
     }
   },
 
   _tabSelect: function(aEvent) {
     let browser = Browser.selectedBrowser;
     this._titleChanged(browser);
     this._updateToolbar();
     this._updateButtons(browser);
@@ -191,31 +190,37 @@ var BrowserUI = {
   _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;
+    if (aEdit) {
+      let isOpened = this._edit.hasAttribute("open");
+      if (!isOpened) {
+        Elements.urlbarState.setAttribute("mode", "edit");
+        this._edit.defaultValue = this._edit.value;
+      }
 
+      // Replace the web page title by the url of the page
       let urlString = this.getDisplayURI(Browser.selectedBrowser);
       if (Util.isURLEmpty(urlString))
         urlString = "";
       this._edit.value = urlString;
 
-      // This is a workaround for bug 488420, needed to cycle focus for the
-      // IME state to be set properly. Testing shows we only really need to
-      // do this the first time.
-      this._edit.blur();
-      gFocusManager.setFocus(this._edit, Ci.nsIFocusManager.FLAG_NOSCROLL);
+      if (!this._edit.readOnly) {
+        // This is a workaround needed to cycle focus for the IME state
+        // to be set properly (bug 488420)
+        this._edit.blur();
+        gFocusManager.setFocus(this._edit, Ci.nsIFocusManager.FLAG_NOSCROLL);
+      }
+
+      this._edit.readOnly = !isOpened;
     }
     else if (!aEdit) {
       this._updateToolbar();
     }
   },
 
   updateAwesomeHeader: function updateAwesomeHeader(aVisible) {
     document.getElementById("awesome-header").hidden = aVisible;
@@ -373,16 +378,20 @@ var BrowserUI = {
     this._edit = document.getElementById("urlbar-edit");
     this._throbber = document.getElementById("urlbar-throbber");
     this._favicon = document.getElementById("urlbar-favicon");
     this._favicon.addEventListener("error", this, false);
 
     this._edit.addEventListener("click", this, false);
     this._edit.addEventListener("mousedown", this, false);
 
+    let awesomePopup = document.getElementById("popup_autocomplete");
+    awesomePopup.addEventListener("popupshown", this, false);
+    awesomePopup.addEventListener("popuphidden", this, false);
+
     document.getElementById("toolbar-main").ignoreDrag = true;
 
     let tabs = document.getElementById("tabs");
     tabs.addEventListener("TabSelect", this, true);
     tabs.addEventListener("TabOpen", this, true);
 
     // listen content messages
     messageManager.addMessageListener("DOMLinkAdded", this);
@@ -437,30 +446,29 @@ var BrowserUI = {
   },
 
   uninit: function() {
     ExtensionsView.uninit();
     ConsoleView.uninit();
   },
 
   update: function(aState) {
-    let icons = document.getElementById("urlbar-icons");
     let browser = Browser.selectedBrowser;
 
     switch (aState) {
       case TOOLBARSTATE_LOADED:
-        if (icons.getAttribute("mode") != "edit")
+        if (Elements.urlbarState.getAttribute("mode") != "edit")
           this._updateToolbar();
 
         this._updateIcon(browser.mIconURL);
         this.unlockToolbar();
         break;
 
       case TOOLBARSTATE_LOADING:
-        if (icons.getAttribute("mode") != "edit")
+        if (Elements.urlbarState.getAttribute("mode") != "edit")
           this._updateToolbar();
 
         browser.mIconURL = "";
         this._updateIcon();
         this.lockToolbar();
         break;
     }
   },
@@ -769,16 +777,24 @@ var BrowserUI = {
           this._edit.editor.selectAll();
           aEvent.preventDefault();
         }
         break;
       // Favicon events
       case "error":
         this._favicon.src = "";
         break;
+      // Awesome popup event
+      case "popupshown":
+        this._edit.setAttribute("open", "true");
+        break;
+      case "popuphidden":
+        this._edit.removeAttribute("open");
+        this._edit.readOnly = true;
+        break;
     }
   },
 
   receiveMessage: function receiveMessage(aMessage) {
     let browser = aMessage.target;
     let json = aMessage.json;
     switch (aMessage.name) {
       case "DOMTitleChanged":
--- a/mobile/chrome/content/browser.xul
+++ b/mobile/chrome/content/browser.xul
@@ -93,16 +93,17 @@
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="bundle_browser" src="chrome://browser/locale/browser.properties"/>
     <stringbundle id="bundle_brand" src="chrome://branding/locale/brand.properties"/>
   </stringbundleset>
 
   <broadcasterset id="broadcasterset">
     <broadcaster id="bcast_contentShowing"/>
+    <broadcaster id="bcast_urlbarState" mode="view"/>
   </broadcasterset>
 
   <observerset id="observerset">
     <observes id="observe_contentShowing" element="bcast_contentShowing" attribute="disabled"/>
   </observerset>
 
   <commandset id="mainCommandSet">
     <!-- basic navigation -->
@@ -246,18 +247,19 @@
                              maxrows="6"
                              completeselectedindex="true"
                              minresultsforpopup="0"
                              oncontextmenu="event.preventDefault();"
                              onsearchbegin="BrowserUI.updateAwesomeHeader(this.controller.searchString != '');"
                              emptytext="&urlbar.emptytext;"
                              flex="1"
                              ontextentered="BrowserUI.goToURI();"
+                             readonly="true"
                              clickSelectsAll="true"/>
-                    <hbox id="urlbar-icons" mode="view">
+                    <hbox id="urlbar-icons" observes="bcast_urlbarState">
                       <toolbarbutton id="tool-reload" class="urlbar-cap-button"
                                      oncommand="CommandUpdater.doCommand(event.shiftKey ? 'cmd_forceReload' : 'cmd_reload');"/>
                       <toolbarbutton id="tool-stop" class="urlbar-cap-button" command="cmd_stop"/>
                       <toolbarbutton id="tool-go" class="urlbar-cap-button" command="cmd_go"/>
                     </hbox>
                   </hbox>
                   <toolbarbutton id="tool-app-close" class="urlbar-button button-image" command="cmd_close"/>
                 </toolbar>
--- a/mobile/themes/core/browser.css
+++ b/mobile/themes/core/browser.css
@@ -244,29 +244,29 @@ toolbarbutton.urlbar-cap-button {
   margin: 0 !important;
   padding: 0 !important;
   border: none !important;
   border-top: 1px solid #262629 !important;
   border-bottom: 3px solid #262629 !important;
   -moz-border-radius: 0;
 }
 
+#urlbar-edit:not([open]):hover:active {
+  background-color: #8db8d8;
+}
+
 #urlbar-edit > hbox > .textbox-input-box {
   margin: 0;
 }
 
 #urlbar-edit > hbox > hbox > .textbox-input {
   min-height: 60px;
   text-indent: 3px;
 }
 
-#urlbar-edit:not([open]):hover:active {
-  background-color: #8db8d8;
-}
-
 /* make sure this endcap matches the other endcap */
 #urlbar-icons {
   min-height: 64px;
   min-width: 64px;
   background: url("images/rightcap-default-64.png") top right no-repeat;
   -moz-box-pack: center;
 }