Bug 600844 - Hide the site menu when the find bar appears [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Thu, 30 Sep 2010 13:57:33 -0700
changeset 66757 0212bef3da4dacf596bebbd7c40a9b1f8a04a22f
parent 66756 0dc604c7bcd88d477d34679ab954909c5ccd1ab1
child 66758 035c05f70ad8e4ffe94d97693fc98d036d5d43d5
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
bugs600844
Bug 600844 - Hide the site menu when the find bar appears [r=mfinkle]
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
mobile/chrome/content/browser.xul
mobile/chrome/tests/Makefile.in
mobile/chrome/tests/browser_find.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -1125,25 +1125,35 @@ var TapHighlightHelper = {
     // been shown for a moment.
     if (this._guaranteeShow)
       this.hide(this._guaranteeShow);
   }
 };
 
 var PageActions = {
   init: function init() {
+    document.getElementById("pageactions-container").addEventListener("click", this, false);
+
     this.register("pageaction-reset", this.updatePagePermissions, this);
     this.register("pageaction-password", this.updateForgetPassword, this);
 #ifdef NS_PRINTING
     this.register("pageaction-saveas", this.updatePageSaveAs, this);
 #endif
     this.register("pageaction-share", this.updateShare, this);
     this.register("pageaction-search", BrowserSearch.updatePageSearchEngines, BrowserSearch);
   },
 
+  handleEvent: function handleEvent(aEvent) {
+    switch (aEvent.type) {
+      case "click":
+        getIdentityHandler().hide();
+        break;
+    }
+  },
+
   /**
    * @param aId id of a pageaction element
    * @param aCallback function that takes an element and returns true if it should be visible
    * @param aThisObj (optional) scope object for aCallback
    */
   register: function register(aId, aCallback, aThisObj) {
     this._handlers.push({id: aId, callback: aCallback, obj: aThisObj});
   },
@@ -1202,36 +1212,42 @@ var PageActions = {
 
   updateForgetPassword: function updateForgetPassword(aNode) {
     let host = Browser.selectedBrowser.currentURI;
     let logins = this._loginManager.findLogins({}, host.prePath, "", null);
 
     return logins.some(function(login) login.hostname == host.prePath);
   },
 
-  forgetPassword: function forgetPassword() {
+  forgetPassword: function forgetPassword(aEvent) {
     let host = Browser.selectedBrowser.currentURI;
     let lm = this._loginManager;
 
     lm.findLogins({}, host.prePath, "", null).forEach(function(login) {
       if (login.hostname == host.prePath)
         lm.removeLogin(login);
     });
+
+    this.hideItem(aEvent.target);
+    aEvent.stopPropagation(); // Don't hide the site menu.
   },
 
-  clearPagePermissions: function clearPagePermissions() {
+  clearPagePermissions: function clearPagePermissions(aEvent) {
     let pm = Services.perms;
     let host = Browser.selectedBrowser.currentURI;
     this._forEachPermissions(host, function(aType) {
       pm.remove(host.asciiHost, aType);
     });
 
     let lm = this._loginManager;
     if (!lm.getLoginSavingEnabled(host.prePath))
       lm.setLoginSavingEnabled(host.prePath, true);
+
+    this.hideItem(aEvent.target);
+    aEvent.stopPropagation(); // Don't hide the site menu.
   },
 
   savePageAsPDF: function saveAsPDF() {
     let browser = Browser.selectedBrowser;
     let fileName = getDefaultFileName(browser.contentTitle, browser.documentURI, null, null);
     fileName = fileName.trim() + ".pdf";
 #ifdef MOZ_PLATFORM_MAEMO
     fileName = fileName.replace(/[\*\:\?]+/g, " ");
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1231,19 +1231,20 @@ const BrowserSearch = {
   updatePageSearchEngines: function updatePageSearchEngines(aNode) {
     let items = Browser.selectedBrowser.searchEngines.filter(this.isPermanentSearchEngine);
     if (!items.length)
       return false;
 
     // XXX limit to the first search engine for now
     let engine = items[0];
     aNode.setAttribute("description", engine.title);
-    aNode.onclick = function() {
+    aNode.onclick = function(aEvent) {
       BrowserSearch.addPermanentSearchEngine(engine);
       PageActions.hideItem(aNode);
+      aEvent.stopPropagation(); // Don't hide the site menu.
     };
     return true;
   },
 
   addPermanentSearchEngine: function addPermanentSearchEngine(aEngine) {
     let iconURL = BrowserUI._favicon.src;
     Services.search.addEngine(aEngine.href, Ci.nsISearchEngine.DATA_XML, iconURL, false);
 
--- a/mobile/chrome/content/browser.xul
+++ b/mobile/chrome/content/browser.xul
@@ -339,19 +339,19 @@
           onclick="FindHelperUI.show();"/>
 #ifdef NS_PRINTING
         <pageaction id="pageaction-saveas" title="&pageactions.saveas.pdf;"
           onclick="PageActions.savePageAsPDF();"/>
 #endif
         <pageaction id="pageaction-share" title="&pageactions.share.page;"
           onclick="SharingUI.show(getBrowser().currentURI.spec, getBrowser().contentTitle);"/>
         <pageaction id="pageaction-password" title="&pageactions.password.forget;"
-          onclick="PageActions.forgetPassword(); PageActions.hideItem(this);"/>
+          onclick="PageActions.forgetPassword(event);"/>
         <pageaction id="pageaction-reset" title="&pageactions.reset;"
-          onclick="PageActions.clearPagePermissions(); PageActions.hideItem(this);"/>
+          onclick="PageActions.clearPagePermissions(event);"/>
         <pageaction id="pageaction-search" title="&pageactions.search.addNew;"/>
       </hbox>
     </vbox>
 
     <vbox id="bookmark-popup" hidden="true" class="dialog-dark" align="center">
       <label value="&bookmarkPopup.label;"/>
       <separator class="thin"/>
       <vbox>
--- a/mobile/chrome/tests/Makefile.in
+++ b/mobile/chrome/tests/Makefile.in
@@ -52,16 +52,17 @@ include $(topsrcdir)/config/rules.mk
   browser_blank_01.html \
   browser_blank_02.html \
   browser_bookmarks.js \
   browser_bookmarks_star.js \
   browser_bookmarks_tags.js \
   browser_click_content.html \
   browser_click_content.js \
   browser_contacts.js \
+  browser_find.js \
   browser_forms.html \
   browser_forms.js \
   browser_mainui.js \
   browser_navigation.js \
   browser_preferences_basic.js \
   browser_preferences_text.js \
   browser_rect.js \
   browser_select.html \
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_find.js
@@ -0,0 +1,23 @@
+// Tests for the Find In Page UI
+
+//------------------------------------------------------------------------------
+// Entry point (must be named "test")
+function test() {
+  let menu = document.getElementById("identity-container");
+  let item = document.getElementById("pageaction-findinpage");
+  let navigator = document.getElementById("content-navigator");
+
+  // Open and close the find toolbar
+
+  getIdentityHandler().show();
+  ok(!menu.hidden, "Site menu is open");
+  ok(!navigator.isActive, "Toolbar is closed");
+
+  EventUtils.sendMouseEvent({ type: "click" }, item);
+  ok(menu.hidden, "Site menu is closed");
+  ok(navigator.isActive, "Toolbar is open");
+
+  EventUtils.synthesizeKey("VK_ESCAPE", {}, window);
+  ok(menu.hidden, "Site menu is closed");
+  ok(!navigator.isActive, "Toolbar is closed");
+}