Bug 741506 - Removing nodes while a bookmarks popup is open in OS X native menubar zombifies them.

r=Mano
This commit is contained in:
Marco Bonardo 2012-04-14 14:08:43 +02:00
parent be570c6dfc
commit 1648fe7a21

View File

@ -166,14 +166,26 @@ PlacesViewBase.prototype = {
window.content.focus();
},
_cleanPopup: function PVB_cleanPopup(aPopup) {
_cleanPopup: function PVB_cleanPopup(aPopup, aDelay) {
// Remove Places nodes from the popup.
let child = aPopup._startMarker;
while (child.nextSibling != aPopup._endMarker) {
if (child.nextSibling._placesNode)
aPopup.removeChild(child.nextSibling);
else
let sibling = child.nextSibling;
if (sibling._placesNode && !aDelay) {
aPopup.removeChild(sibling);
}
else if (sibling._placesNode && aDelay) {
// HACK (bug 733419): the popups originating from the OS X native
// menubar don't live-update while open, thus we don't clean it
// until the next popupshowing, to avoid zombie menuitems.
if (!aPopup._delayedRemovals)
aPopup._delayedRemovals = [];
aPopup._delayedRemovals.push(sibling);
child = child.nextSibling;
}
else {
child = child.nextSibling;
}
}
},
@ -395,7 +407,8 @@ PlacesViewBase.prototype = {
}
else {
// The livemark has finished loading.
aPopup.removeChild(aPopup._statusMenuitem);
if (aPopup._statusMenuitem.parentNode == aPopup)
aPopup.removeChild(aPopup._statusMenuitem);
}
},
@ -671,7 +684,9 @@ PlacesViewBase.prototype = {
_populateLivemarkPopup: function PVB__populateLivemarkPopup(aPopup)
{
this._setLivemarkSiteURIMenuItem(aPopup);
this._setLivemarkStatusMenuItem(aPopup, Ci.mozILivemark.STATUS_LOADING);
// Show the loading status only if there are no entries yet.
if (aPopup._startMarker.nextSibling == aPopup._endMarker)
this._setLivemarkStatusMenuItem(aPopup, Ci.mozILivemark.STATUS_LOADING);
PlacesUtils.livemarks.getLivemark({ id: aPopup._placesNode.itemId },
(function (aStatus, aLivemark) {
@ -679,8 +694,10 @@ PlacesViewBase.prototype = {
if (!Components.isSuccessCode(aStatus) || !placesNode.containerOpen)
return;
this._setLivemarkStatusMenuItem(aPopup, aLivemark.status);
this._cleanPopup(aPopup);
if (aLivemark.status != Ci.mozILivemark.STATUS_LOADING)
this._setLivemarkStatusMenuItem(aPopup, aLivemark.status);
this._cleanPopup(aPopup,
this._nativeView && aPopup.parentNode.hasAttribute("open"));
let children = aLivemark.getNodesForContainer(placesNode);
for (let i = 0; i < children.length; i++) {
@ -835,6 +852,13 @@ PlacesViewBase.prototype = {
this._ensureMarkers(popup);
// Remove any delayed element, see _cleanPopup for details.
if ("_delayedRemovals" in popup) {
while (popup._delayedRemovals.length > 0) {
popup.removeChild(popup._delayedRemovals.shift());
}
}
if (popup._placesNode && PlacesUIUtils.getViewForNode(popup) == this) {
if (!popup._placesNode.containerOpen)
popup._placesNode.containerOpen = true;
@ -1738,8 +1762,12 @@ function PlacesMenu(aPopupShowingEvent, aPlace) {
this._addEventListeners(window, ["unload"], false);
#ifdef XP_MACOSX
if (this._viewElt.parentNode.localName == "menubar") {
this._nativeView = true;
// Must walk up to support views in sub-menus, like Bookmarks Toolbar menu.
for (let elt = this._viewElt.parentNode; elt; elt = elt.parentNode) {
if (elt.localName == "menubar") {
this._nativeView = true;
break;
}
}
#endif