Bug 1805678 - clean up cruft in browserPlacesViews, r=mak

`.footer` is no longer used on extraClasses, so I got rid of that.

I simplified the `.entry` bits because they were unnecessarily
verbose. Honestly I think we may be able to remove the getter/setter
for `options` entirely, but I got bored of trying to modernize things...

PlacesPanelMenuView was introduced in bug 963095 and then replaced
as part of Photon (with PlacesPanelview) and then I removed the only
callsite (that was already behind a pref) in bug 1354117, so that was
just dead code, AFAICT, so I removed it.

Differential Revision: https://phabricator.services.mozilla.com/D164757
This commit is contained in:
Gijs Kruitbosch 2022-12-16 08:06:08 +00:00
parent 3d859095f0
commit 6adf438bc8

View File

@ -373,7 +373,7 @@ class PlacesViewBase {
aPopup._emptyMenuitem.setAttribute("label", label);
aPopup._emptyMenuitem.setAttribute("disabled", true);
aPopup._emptyMenuitem.className = "bookmark-item";
if (typeof this.options.extraClasses.entry == "string") {
if (this.options?.extraClasses?.entry) {
aPopup._emptyMenuitem.classList.add(this.options.extraClasses.entry);
}
}
@ -437,7 +437,7 @@ class PlacesViewBase {
element.appendChild(popup);
element.className = "menu-iconic bookmark-item";
if (typeof this.options.extraClasses.entry == "string") {
if (this.options?.extraClasses?.entry) {
element.classList.add(this.options.extraClasses.entry);
}
@ -466,7 +466,7 @@ class PlacesViewBase {
let element = this._createDOMNodeForPlacesNode(aNewChild);
if (element.localName == "menuitem" || element.localName == "menu") {
if (typeof this.options.extraClasses.entry == "string") {
if (this.options?.extraClasses?.entry) {
element.classList.add(this.options.extraClasses.entry);
}
}
@ -759,16 +759,11 @@ class PlacesViewBase {
aPopup._endOptOpenAllInTabs = document.createXULElement("menuitem");
aPopup._endOptOpenAllInTabs.className = "openintabs-menuitem";
if (typeof this.options.extraClasses.entry == "string") {
if (this.options?.extraClasses?.entry) {
aPopup._endOptOpenAllInTabs.classList.add(
this.options.extraClasses.entry
);
}
if (typeof this.options.extraClasses.footer == "string") {
aPopup._endOptOpenAllInTabs.classList.add(
this.options.extraClasses.footer
);
}
aPopup._endOptOpenAllInTabs.setAttribute(
"oncommand",
@ -2075,135 +2070,6 @@ class PlacesMenu extends PlacesViewBase {
}
}
/**
*
*/
class PlacesPanelMenuView extends PlacesViewBase {
constructor(aPlace, aViewId, aRootId, aOptions = {}) {
aOptions.rootElt = document.getElementById(aRootId);
aOptions.viewElt = document.getElementById(aViewId);
super(aPlace, aOptions);
this._viewElt._placesView = this;
this.options = aOptions;
}
_insertNewItem(aChild, aInsertionNode, aBefore = null) {
this._domNodes.delete(aChild);
let type = aChild.type;
let button;
if (type == Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR) {
button = document.createXULElement("toolbarseparator");
} else {
button = document.createXULElement("toolbarbutton");
button.className = "bookmark-item";
if (typeof this.options.extraClasses.entry == "string") {
button.classList.add(this.options.extraClasses.entry);
}
button.setAttribute("label", aChild.title || "");
let icon = aChild.icon;
if (icon) {
button.setAttribute("image", icon);
}
if (PlacesUtils.containerTypes.includes(type)) {
button.setAttribute("container", "true");
if (PlacesUtils.nodeIsQuery(aChild)) {
button.setAttribute("query", "true");
if (PlacesUtils.nodeIsTagQuery(aChild)) {
button.setAttribute("tagContainer", "true");
}
}
} else if (PlacesUtils.nodeIsURI(aChild)) {
button.setAttribute(
"scheme",
PlacesUIUtils.guessUrlSchemeForUI(aChild.uri)
);
}
}
button._placesNode = aChild;
if (!this._domNodes.has(aChild)) {
this._domNodes.set(aChild, button);
}
aInsertionNode.insertBefore(button, aBefore);
return button;
}
nodeInserted(aParentPlacesNode, aPlacesNode, aIndex) {
let parentElt = this._getDOMNodeForPlacesNode(aParentPlacesNode);
if (parentElt != this._rootElt) {
return;
}
let children = this._rootElt.children;
this._insertNewItem(
aPlacesNode,
this._rootElt,
aIndex < children.length ? children[aIndex] : null
);
}
nodeRemoved(aParentPlacesNode, aPlacesNode, aIndex) {
let parentElt = this._getDOMNodeForPlacesNode(aParentPlacesNode);
if (parentElt != this._rootElt) {
return;
}
let elt = this._getDOMNodeForPlacesNode(aPlacesNode);
this._removeChild(elt);
}
nodeMoved(
aPlacesNode,
aOldParentPlacesNode,
aOldIndex,
aNewParentPlacesNode,
aNewIndex
) {
let parentElt = this._getDOMNodeForPlacesNode(aNewParentPlacesNode);
if (parentElt != this._rootElt) {
return;
}
let elt = this._getDOMNodeForPlacesNode(aPlacesNode);
this._removeChild(elt);
this._rootElt.insertBefore(elt, this._rootElt.children[aNewIndex]);
}
nodeTitleChanged(aPlacesNode, aNewTitle) {
let elt = this._getDOMNodeForPlacesNode(aPlacesNode);
// There's no UI representation for the root node.
if (elt == this._rootElt) {
return;
}
super.nodeTitleChanged(aPlacesNode, aNewTitle);
}
invalidateContainer(aPlacesNode) {
let elt = this._getDOMNodeForPlacesNode(aPlacesNode);
if (elt != this._rootElt) {
return;
}
// Container is the toolbar itself.
while (this._rootElt.hasChildNodes()) {
this._rootElt.firstChild.remove();
}
let fragment = document.createDocumentFragment();
for (let i = 0; i < this._resultNode.childCount; ++i) {
this._insertNewItem(this._resultNode.getChild(i), fragment);
}
this._rootElt.appendChild(fragment);
}
}
// This is used from CustomizableWidgets.jsm using a `window` reference,
// so we have to expose this on the global.
this.PlacesPanelview = class PlacesPanelview extends PlacesViewBase {
@ -2361,7 +2227,7 @@ this.PlacesPanelview = class PlacesPanelview extends PlacesViewBase {
panelview._emptyMenuitem.setAttribute("label", label);
panelview._emptyMenuitem.setAttribute("disabled", true);
panelview._emptyMenuitem.className = "subviewbutton";
if (typeof this.options.extraClasses.entry == "string") {
if (this.options?.extraClasses?.entry) {
panelview._emptyMenuitem.classList.add(this.options.extraClasses.entry);
}
}