Bug 1348224 - Don't call _adjustAcItem() if result's type is different from existing item's type. r=adw
MozReview-Commit-ID: D0b4TPnD8KY
--- 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);
}