Bug 1401991 - Ensure that we don't hide panelviews that are already reparented to another multi-view and ensure to hide other panels consistently. r=Gijs

* Harden the new `hideAllViewsExcept()` to not do erroneous things if called when
   the binding is already gone.
 * Generalize things into `hideAllViewsExcept(thisOne)`:
    - Clear `_viewShowing` in there and do the descriptionHeightWorkaround thing
      in there too,
    - For Photon panels, do all the 'current' attribute setting in there. To show
      a panel during transition, I introduced the 'in-transition' attribute.
 * I had to make sure not to over-eagerly dispatch 'ViewShowing' events, because
   that confuses some,
 * Move the temporary panel handling, which contains an ephemeral panelmultiview
   instance, internally. This cleans up the hacky, duplicate PanelUI.js code nicely.
 * Keep a local copy of `_transitionDetails` to ensure it's still there after transition,
 * Harden `_cleanupTransitionPhase()` to only clear the phase that belongs to a
   specific transition, _if_ that's passed in as an argument. This resolves any
   potential raciness that might occur when `showSubView()` is called again mid-transition.
 * Skip the UITour element visibility check when it's inside a panelview, because
   too many things need to happen and that check is too simple to be useful in
   that case.

MozReview-Commit-ID: 5HpJKs1Ny5j
This commit is contained in:
Mike de Boer
2017-09-29 13:51:51 +02:00
parent c58d812a5b
commit 3f2ca69f96
11 changed files with 225 additions and 212 deletions

View File

@@ -419,31 +419,37 @@ const PanelUI = {
tempPanel.setAttribute("animate", "false");
}
tempPanel.setAttribute("context", "");
tempPanel.setAttribute("photon", true);
document.getElementById(CustomizableUI.AREA_NAVBAR).appendChild(tempPanel);
// If the view has a footer, set a convenience class on the panel.
tempPanel.classList.toggle("cui-widget-panelWithFooter",
viewNode.querySelector(".panel-subview-footer"));
// If the panelview is already selected in another PanelMultiView instance
// as a subview, make sure to properly hide it there.
let oldMultiView = viewNode.panelMultiView;
if (oldMultiView && oldMultiView.current == viewNode) {
await oldMultiView.showMainView();
}
let viewShown = false;
let listener = () => viewShown = true;
viewNode.addEventListener("ViewShown", listener, {once: true});
let multiView = document.createElement("photonpanelmultiview");
multiView.setAttribute("id", "customizationui-widget-multiview");
multiView.setAttribute("nosubviews", "true");
multiView.setAttribute("viewCacheId", "appMenu-viewCache");
tempPanel.setAttribute("photon", true);
multiView.setAttribute("mainViewId", viewNode.id);
multiView.appendChild(viewNode);
multiView.setAttribute("ephemeral", true);
document.getElementById("appMenu-viewCache").appendChild(viewNode);
tempPanel.appendChild(multiView);
viewNode.classList.add("cui-widget-panelview");
let viewShown = false;
let panelRemover = () => {
viewNode.classList.remove("cui-widget-panelview");
if (viewShown) {
CustomizableUI.removePanelCloseListeners(tempPanel);
tempPanel.removeEventListener("popuphidden", panelRemover);
let currentView = multiView.current || viewNode;
let evt = new CustomEvent("ViewHiding", {detail: currentView});
currentView.dispatchEvent(evt);
}
aAnchor.open = false;
@@ -453,35 +459,15 @@ const PanelUI = {
tempPanel.remove();
};
// Emit the ViewShowing event so that the widget definition has a chance
// to lazily populate the subview with things.
let detail = {
blockers: new Set(),
addBlocker(aPromise) {
this.blockers.add(aPromise);
},
};
// Wait until all the tasks needed to show a view are done.
await multiView.currentShowPromise;
let evt = new CustomEvent("ViewShowing", { bubbles: true, cancelable: true, detail });
viewNode.dispatchEvent(evt);
let cancel = evt.defaultPrevented;
if (detail.blockers.size) {
try {
let results = await Promise.all(detail.blockers);
cancel = cancel || results.some(val => val === false);
} catch (e) {
Components.utils.reportError(e);
cancel = true;
}
}
if (cancel) {
if (!viewShown) {
viewNode.removeEventListener("ViewShown", listener);
panelRemover();
return;
}
viewShown = true;
CustomizableUI.addPanelCloseListeners(tempPanel);
tempPanel.addEventListener("popuphidden", panelRemover);
@@ -539,7 +525,8 @@ const PanelUI = {
withFavicons: true
});
// If there's nothing to display, or the panel is already hidden, get out.
if (!highlights.length || viewNode.panelMultiView.getAttribute("panelopen") != "true") {
let multiView = viewNode.panelMultiView;
if (!highlights.length || (multiView && multiView.getAttribute("panelopen") != "true")) {
this._loadingRecentHighlights = false;
return;
}