Bug 475529 - Add button in "new folder" dialog not default anymore, r=dietrich a191=beltzner
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 15 Apr 2009 22:24:43 +0200
changeset 24735 0796c6d5a6803d70a95b55a7593e52c048b88ceb
parent 24734 a1f1d53aae307ebf2c49d1c35dcbc1479d6a7477
child 24736 451da1dd30fc41557ec559e339e1a1b089f899a2
push id1205
push usermak77@bonardo.net
push dateWed, 15 Apr 2009 20:25:28 +0000
reviewersdietrich
bugs475529
milestone1.9.1b4pre
Bug 475529 - Add button in "new folder" dialog not default anymore, r=dietrich a191=beltzner
browser/components/places/content/bookmarkProperties.js
browser/components/places/tests/browser/browser_bookmarksProperties.js
--- a/browser/components/places/content/bookmarkProperties.js
+++ b/browser/components/places/content/bookmarkProperties.js
@@ -351,80 +351,92 @@ var BookmarkPropertiesPanel = {
     // When collapsible elements change their collapsed attribute we must
     // resize the dialog.
     // sizeToContent is not usable due to bug 90276, so we'll use resizeTo
     // instead and cache the element size. See WSucks in the legacy
     // UI code (addBookmark2.js).
     if (!this._element("tagsRow").collapsed) {
       this._element("tagsSelectorRow")
           .addEventListener("DOMAttrModified", this, false);
-      // Set on document to get the event before an autocomplete popup could
-      // be hidden on Enter.
-      document.addEventListener("keypress", this, true);
     }
     if (!this._element("folderRow").collapsed) {
       this._element("folderTreeRow")
           .addEventListener("DOMAttrModified", this, false);
     }
 
-    // Listen on uri fields to enable accept button if input is valid
-    if (this._itemType == BOOKMARK_ITEM) {
-      this._element("locationField")
-          .addEventListener("input", this, false);
-    }
-    else if (this._itemType == LIVEMARK_CONTAINER) {
-      this._element("feedLocationField")
-          .addEventListener("input", this, false);
-      this._element("siteLocationField")
-          .addEventListener("input", this, false);
+    if (!this._readOnly) {
+      // Listen on uri fields to enable accept button if input is valid
+      if (this._itemType == BOOKMARK_ITEM) {
+        this._element("locationField")
+            .addEventListener("input", this, false);
+      }
+      else if (this._itemType == LIVEMARK_CONTAINER) {
+        this._element("feedLocationField")
+            .addEventListener("input", this, false);
+        this._element("siteLocationField")
+            .addEventListener("input", this, false);
+      }
+
+      // Set on document to get the event before an autocomplete popup could
+      // be hidden on Enter.
+      document.addEventListener("keypress", this, true);
     }
 
     window.sizeToContent();
   },
 
   // nsIDOMEventListener
   _elementsHeight: [],
   handleEvent: function BPP_handleEvent(aEvent) {
+    var target = aEvent.target;
     switch (aEvent.type) {
       case "keypress":
+        function canAcceptDialog(aElement) {
+          // on Enter we accept the dialog unless:
+          // - the folder tree is focused
+          // - an expander is focused
+          // - an autocomplete (eg. tags) popup is open
+          // - a menulist is open
+          // - a multiline textbox is focused
+          return aElement.localName != "tree" &&
+                 aElement.className != "expander-up" &&
+                 aElement.className != "expander-down" &&
+                 !aElement.popupOpen &&
+                 !aElement.open &&
+                 !(aElement.localName == "textbox" &&
+                   aElement.getAttribute("multiline") == "true");
+        }
         if (aEvent.keyCode == KeyEvent.DOM_VK_RETURN &&
-            aEvent.target.localName != "tree" &&
-            aEvent.target.className != "expander-up" &&
-            aEvent.target.className != "expander-down" &&
-            !aEvent.target.popupOpen) {
-          // Accept the dialog unless the folder tree or an expander are focused
-          // or an autocomplete popup is open.
+            canAcceptDialog(target))
           document.documentElement.acceptDialog();
-        }
         break;
 
       case "input":
-        if (aEvent.target.id == "editBMPanel_locationField" ||
-            aEvent.target.id == "editBMPanel_feedLocationField" ||
-            aEvent.target.id == "editBMPanel_siteLocationField") {
+        if (target.id == "editBMPanel_locationField" ||
+            target.id == "editBMPanel_feedLocationField" ||
+            target.id == "editBMPanel_siteLocationField") {
           // Check uri fields to enable accept button if input is valid
           document.documentElement
                   .getButton("accept").disabled = !this._inputIsValid();
         }
         break;
 
       case "DOMAttrModified":
         // this is called when collapsing a node, but also its direct children,
         // we only need to resize when the original node changes.
-        if ((aEvent.target.id == "editBMPanel_tagsSelectorRow" ||
-             aEvent.target.id == "editBMPanel_folderTreeRow") &&
+        if ((target.id == "editBMPanel_tagsSelectorRow" ||
+             target.id == "editBMPanel_folderTreeRow") &&
             aEvent.attrName == "collapsed" &&
-            aEvent.target == aEvent.originalTarget) {
-          var element = aEvent.target;
-          var id = element.id;
+            target == aEvent.originalTarget) {
+          var id = target.id;
           var newHeight = window.outerHeight;
           if (aEvent.newValue) // is collapsed
             newHeight -= this._elementsHeight[id];
           else {
-            this._elementsHeight[id] = element.boxObject.height;
+            this._elementsHeight[id] = target.boxObject.height;
             newHeight += this._elementsHeight[id];
           }
 
           window.resizeTo(window.outerWidth, newHeight);
         }
         break;
     }
   },
--- a/browser/components/places/tests/browser/browser_bookmarksProperties.js
+++ b/browser/components/places/tests/browser/browser_bookmarksProperties.js
@@ -236,17 +236,17 @@ gTests.push({
     var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(TEST_URL), {});
     is(tags[0], "testTag", "Tag on node has not changed");
 
     // Cleanup.
     PlacesUtils.tagging.untagURI(PlacesUtils._uri(TEST_URL), ["testTag"]);
     PlacesUtils.bookmarks.removeItem(this._itemId);
   }
 });
-/* 1.9.1 Temporarly disabled waiting for bugs approvals
+
 //------------------------------------------------------------------------------
 // Bug 475529 -  Add button in new folder dialog not default anymore
 
 gTests.push({
   desc: "Bug 475529 - Add button in new folder dialog not default anymore",
   sidebar: SIDEBAR_BOOKMARKS_ID,
   action: ACTION_ADD,
   itemType: TYPE_FOLDER,
@@ -291,17 +291,17 @@ gTests.push({
     // Check that folder name has been changed.
     is(PlacesUtils.bookmarks.getItemTitle(this._itemId), "n",
        "Folder name has been edited");
 
     // Cleanup.
     PlacesUtils.bookmarks.removeItem(this._itemId);
   }
 });
-*/
+
 //------------------------------------------------------------------------------
 // Bug 476020 - Pressing Esc while having the tag autocomplete open closes the bookmarks panel
 
 gTests.push({
   desc: "Bug 476020 - Pressing Esc while having the tag autocomplete open closes the bookmarks panel",
   sidebar: SIDEBAR_BOOKMARKS_ID,
   action: ACTION_EDIT,
   itemType: null,