Bug 1348224 - Don't call _adjustAcItem() if result's type is different from existing item's type. r=adw draft
authorRay Lin <ralin@mozilla.com>
Fri, 17 Mar 2017 16:40:33 +0800
changeset 552521 99487c886d904e7af026fcd19596a04f54918f8d
parent 552520 079435c872f28748aeffdef5d772aa7a1aed4016
child 621830 e53cf1c0f1e743e497d5a5e9b92368e98b81f8fe
push id51368
push userbmo:ralin@mozilla.com
push dateTue, 28 Mar 2017 15:29:14 +0000
reviewersadw
bugs1348224
milestone55.0a1
Bug 1348224 - Don't call _adjustAcItem() if result's type is different from existing item's type. r=adw MozReview-Commit-ID: D0b4TPnD8KY
toolkit/content/widgets/autocomplete.xml
--- a/toolkit/content/widgets/autocomplete.xml
+++ b/toolkit/content/widgets/autocomplete.xml
@@ -1306,32 +1306,37 @@ extends="chrome://global/content/binding
           for (let i = 0; i < this.maxRows; i++) {
             if (this._currentIndex >= matchCount) {
               break;
             }
             let item;
             let reusable = false;
             let itemExists = this._currentIndex < existingItemsCount;
 
-            let originalValue, originalText;
+            let originalValue, originalText, originalType;
             let value = controller.getValueAt(this._currentIndex);
             let label = controller.getLabelAt(this._currentIndex);
             let comment = controller.getCommentAt(this._currentIndex);
             let style = controller.getStyleAt(this._currentIndex);
             let image = controller.getImageAt(this._currentIndex);
             // trim the leading/trailing whitespace
             let trimmedSearchString = controller.searchString.replace(/^\s+/, "").replace(/\s+$/, "");
 
             if (itemExists) {
               item = this.richlistbox.childNodes[this._currentIndex];
 
               originalValue = item.getAttribute("ac-value");
               originalText = item.getAttribute("ac-text");
+              originalType = item.getAttribute("originaltype");
 
-              reusable = item.getAttribute("originaltype") === style;
+              // All of types are reusable except for autofill-profile,
+              // which has different structure of <content> and overrides
+              // _adjustAcItem().
+              reusable = originalType === style ||
+                         (style !== "autofill-profile" && originalType !== "autofill-profile");
             } else {
               // need to create a new item
               item = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "richlistitem");
             }
 
             item.setAttribute("dir", this.style.direction);
             item.setAttribute("ac-image", image);
             item.setAttribute("ac-value", value);
@@ -1360,17 +1365,24 @@ extends="chrome://global/content/binding
               if (typeof item._cleanup == "function") {
                 item._cleanup();
               }
 
               item.setAttribute("originaltype", style);
             }
 
             if (itemExists) {
-              item._adjustAcItem();
+              // Adjust only when the result's type is reusable for existing
+              // item's. Otherwise, we might insensibly call old _adjustAcItem()
+              // as new binding has not been attached yet.
+              // We don't need to worry about switching to new binding, since
+              // _adjustAcItem() will fired by its own constructor accordingly.
+              if (reusable) {
+                item._adjustAcItem();
+              }
               item.collapsed = false;
             } else {
               // set the class at the end so we can use the attributes
               // in the xbl constructor
               item.className = "autocomplete-richlistitem";
               this.richlistbox.appendChild(item);
             }