diff --git a/mozilla/browser/base/content/browser-places.js b/mozilla/browser/base/content/browser-places.js index f0fa2595d47..3fbd9e56d77 100644 --- a/mozilla/browser/base/content/browser-places.js +++ b/mozilla/browser/base/content/browser-places.js @@ -637,69 +637,86 @@ var BookmarksEventHandler = { */ onPopupShowing: function BM_onPopupShowing(event) { var target = event.originalTarget; - if (target.localName == "menupopup" && - target.id != "bookmarksMenuPopup" && - target.getAttribute("anonid") != "chevronPopup") { - // Add the "Open All in Tabs" menuitem if there are - // at least two menuitems with places result nodes. - // Add the "Open (Feed Name)" menuitem if it's a livemark with a siteURI. - var numNodes = 0; - var hasMultipleEntries = false; - var currentChild = target.firstChild; - while (currentChild) { - if (currentChild.localName == "menuitem" && currentChild.node) - numNodes++; + if (!target.hasAttribute("placespopup")) + return; - // If the menuitem already exists, do nothing. - if (currentChild.getAttribute("openInTabs") == "true") - return; - if (currentChild.hasAttribute("siteURI")) - return; - - currentChild = currentChild.nextSibling; - } - if (numNodes > 1) - hasMultipleEntries = true; - - var itemId = target._resultNode.itemId; - var siteURIString = ""; - if (itemId != -1 && PlacesUtils.livemarks.isLivemark(itemId)) { - var siteURI = PlacesUtils.livemarks.getSiteURI(itemId); - if (siteURI) - siteURIString = siteURI.spec; - } - - if (hasMultipleEntries || siteURIString) { - var separator = document.createElement("menuseparator"); - target.appendChild(separator); - - if (siteURIString) { - var openHomePage = document.createElement("menuitem"); - openHomePage.setAttribute("siteURI", siteURIString); - openHomePage.setAttribute("oncommand", - "openUILink(this.getAttribute('siteURI'), event);"); - // If a user middle-clicks this item we serve the oncommand event - // We are using checkForMiddleClick because of Bug 246720 - // Note: stopPropagation is needed to avoid serving middle-click - // with BT_onClick that would open all items in tabs - openHomePage.setAttribute("onclick", - "checkForMiddleClick(this, event); event.stopPropagation();"); - openHomePage.setAttribute("label", - PlacesUtils.getFormattedString("menuOpenLivemarkOrigin.label", - [target.parentNode.getAttribute("label")])); - target.appendChild(openHomePage); - } - - if (hasMultipleEntries) { - var openInTabs = document.createElement("menuitem"); - openInTabs.setAttribute("openInTabs", "true"); - openInTabs.setAttribute("oncommand", - "PlacesUtils.openContainerNodeInTabs(this.parentNode._resultNode, event);"); - openInTabs.setAttribute("label", - gNavigatorBundle.getString("menuOpenAllInTabs.label")); - target.appendChild(openInTabs); + // Check if the popup contains at least 2 menuitems with places nodes + var numNodes = 0; + var hasMultipleURIs = false; + var currentChild = target.firstChild; + while (currentChild) { + if (currentChild.localName == "menuitem" && currentChild.node) { + if (++numNodes == 2) { + hasMultipleURIs = true; + break; } } + currentChild = currentChild.nextSibling; + } + + var itemId = target._resultNode.itemId; + var siteURIString = ""; + if (itemId != -1 && PlacesUtils.livemarks.isLivemark(itemId)) { + var siteURI = PlacesUtils.livemarks.getSiteURI(itemId); + if (siteURI) + siteURIString = siteURI.spec; + } + + if (!siteURIString && target._endOptOpenSiteURI) { + target.removeChild(target._endOptOpenSiteURI); + target._endOptOpenSiteURI = null; + } + + if (!hasMultipleURIs && target._endOptOpenAllInTabs) { + target.removeChild(target._endOptOpenAllInTabs); + target._endOptOpenAllInTabs = null; + } + + if (!(hasMultipleURIs || siteURIString)) { + // we don't have to show any option + if (target._endOptSeparator) { + target.removeChild(target._endOptSeparator); + target._endOptSeparator = null; + target._endMarker = -1; + } + return; + } + + if (!target._endOptSeparator) { + // create a separator before options + target._endOptSeparator = document.createElement("menuseparator"); + target._endOptSeparator.setAttribute("builder", "end"); + target._endMarker = target.childNodes.length; + target.appendChild(target._endOptSeparator); + } + + if (siteURIString && !target._endOptOpenSiteURI) { + // Add "Open (Feed Name)" menuitem if it's a livemark with a siteURI + target._endOptOpenSiteURI = document.createElement("menuitem"); + target._endOptOpenSiteURI.setAttribute("siteURI", siteURIString); + target._endOptOpenSiteURI.setAttribute("oncommand", + "openUILink(this.getAttribute('siteURI'), event);"); + // If a user middle-clicks this item we serve the oncommand event + // We are using checkForMiddleClick because of Bug 246720 + // Note: stopPropagation is needed to avoid serving middle-click + // with BT_onClick that would open all items in tabs + target._endOptOpenSiteURI.setAttribute("onclick", + "checkForMiddleClick(this, event); event.stopPropagation();"); + target._endOptOpenSiteURI.setAttribute("label", + PlacesUtils.getFormattedString("menuOpenLivemarkOrigin.label", + [target.parentNode.getAttribute("label")])); + target.appendChild(target._endOptOpenSiteURI); + } + + if (hasMultipleURIs && !target._endOptOpenAllInTabs) { + // Add the "Open All in Tabs" menuitem if there are + // at least two menuitems with places result nodes. + target._endOptOpenAllInTabs = document.createElement("menuitem"); + target._endOptOpenAllInTabs.setAttribute("oncommand", + "PlacesUtils.openContainerNodeInTabs(this.parentNode._resultNode, event);"); + target._endOptOpenAllInTabs.setAttribute("label", + gNavigatorBundle.getString("menuOpenAllInTabs.label")); + target.appendChild(target._endOptOpenAllInTabs); } }, diff --git a/mozilla/browser/components/places/content/menu.xml b/mozilla/browser/components/places/content/menu.xml index 324e3cb4ec3..1257b8a6416 100755 --- a/mozilla/browser/components/places/content/menu.xml +++ b/mozilla/browser/components/places/content/menu.xml @@ -78,6 +78,8 @@ PlacesUtils.getViewForNode(this); + false + @@ -231,14 +233,14 @@ // draw the drop indicator outside of them var betweenMarkers = true; if (this._startMarker != -1 && - target.boxObject.y < this.childNodes[this._startMarker].boxObject.y) + target.boxObject.y <= this.childNodes[this._startMarker].boxObject.y) betweenMarkers = false; if (this._endMarker != -1 && - target.boxObject.y > this.childNodes[this._endMarker].boxObject.y) + target.boxObject.y >= this.childNodes[this._endMarker].boxObject.y) betweenMarkers = false; // hide the dropmarker if current node is not a places bookmark item - return !(target && betweenMarkers && this.canDrop()); + return !(target && target.node && betweenMarkers && this.canDrop()); ]]> @@ -494,14 +496,13 @@ readonly="true" onget="return this._controller;"/> - false - @@ -522,58 +523,6 @@ ]]> - - - 0) - --this._endMarker; - } - } - - // If no static items were found at the beginning, remove all items before - // the static items at the end. - if (aPopup._startMarker == -1) { - var end = aPopup._endMarker == -1 ? - aPopup.childNodes.length - 1 : aPopup._endMarker - 1; - for (var i = end; i >=0; i--) { - // skip the empty menu item - if (aPopup._emptyMenuItem != aPopup.childNodes[i]) { - aPopup.removeChild(aPopup.childNodes[i]); - if (aPopup._endMarker > 0) - --aPopup._endMarker; - } - } - } - ]]> - - 0) { diff --git a/mozilla/browser/components/places/content/toolbar.xml b/mozilla/browser/components/places/content/toolbar.xml index 94f04289ce7..0cb326a09bb 100755 --- a/mozilla/browser/components/places/content/toolbar.xml +++ b/mozilla/browser/components/places/content/toolbar.xml @@ -983,10 +983,20 @@ @@ -996,12 +1006,7 @@ if (aPopup._built) return; - // remove previous menu items - while (aPopup.hasChildNodes()) - aPopup.removeChild(aPopup.firstChild); - // restore the empty-menu item if has been created already - if (aPopup._emptyMenuItem) - aPopup.appendChild(aPopup._emptyMenuItem); + PlacesUtils.cleanPlacesPopup(aPopup); var resultNode = aPopup._resultNode; if (!resultNode.containerOpen) @@ -1018,8 +1023,10 @@ } } else { - // add element to show it is empty. - this._showEmptyMenuItem(aPopup); + // This menu is empty. If there is no static content, add + // an element to show it is empty. + if (aPopup._startMarker == -1 && aPopup._endMarker == -1) + this._showEmptyMenuItem(aPopup); } aPopup._built = true; ]]> diff --git a/mozilla/browser/components/places/content/utils.js b/mozilla/browser/components/places/content/utils.js index 703716ed6fb..0584fa7b636 100644 --- a/mozilla/browser/components/places/content/utils.js +++ b/mozilla/browser/components/places/content/utils.js @@ -1896,6 +1896,54 @@ var PlacesUtils = { return element; }, + cleanPlacesPopup: function PU_cleanPlacesPopup(aPopup) { + // Find static menuitems at the start and at the end of the menupopup, + // marked by builder="start" and builder="end" attributes, and set + // markers to keep track of their indices. + var items = []; + aPopup._startMarker = -1; + aPopup._endMarker = -1; + for (var i = 0; i < aPopup.childNodes.length; ++i) { + var item = aPopup.childNodes[i]; + if (item.getAttribute("builder") == "start") { + aPopup._startMarker = i; + continue; + } + if (item.getAttribute("builder") == "end") { + aPopup._endMarker = i; + continue; + } + if ((aPopup._startMarker != -1) && (aPopup._endMarker == -1)) + items.push(item); + } + + // If static items at the beginning were found, remove all items between + // them and the static content at the end. + for (var i = 0; i < items.length; ++i) { + // skip the empty menu item + if (aPopup._emptyMenuItem != items[i]) { + aPopup.removeChild(items[i]); + if (this._endMarker > 0) + --this._endMarker; + } + } + + // If no static items were found at the beginning, remove all items before + // the static items at the end. + if (aPopup._startMarker == -1) { + var end = aPopup._endMarker == -1 ? + aPopup.childNodes.length - 1 : aPopup._endMarker - 1; + for (var i = end; i >= 0; i--) { + // skip the empty menu item + if (aPopup._emptyMenuItem != aPopup.childNodes[i]) { + aPopup.removeChild(aPopup.childNodes[i]); + if (aPopup._endMarker > 0) + --aPopup._endMarker; + } + } + } + }, + getBestTitle: function PU_getBestTitle(aNode) { var title; if (!aNode.title && this.uriTypes.indexOf(aNode.type) != -1) {