--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -830,35 +830,35 @@ this.UITour = {
this.hideInfo(aWindow);
let panels = [
{
name: "appMenu",
node: aWindow.PanelUI.panel,
events: [
[ "popuphidden", this.onPanelHidden ],
- [ "popuphiding", this.hideAppMenuAnnotations ],
- [ "ViewShowing", this.hideAppMenuAnnotations ]
+ [ "popuphiding", this.onAppMenuHiding ],
+ [ "ViewShowing", this.onAppMenuSubviewShowing ]
]
},
{
name: "pageActionPanel",
node: aWindow.BrowserPageActions.panelNode,
events: [
[ "popuphidden", this.onPanelHidden ],
- [ "popuphiding", this.hidePageActionPanelAnnotations ],
- [ "ViewShowing", this.hidePageActionPanelAnnotations ]
+ [ "popuphiding", this.onPageActionPanelHiding ],
+ [ "ViewShowing", this.onPageActionPanelSubviewShowing ]
]
},
{
name: "controlCenter",
node: aWindow.gIdentityHandler._identityPopup,
events: [
[ "popuphidden", this.onPanelHidden ],
- [ "popuphiding", this.hideControlCenterAnnotations ]
+ [ "popuphiding", this.onControlCenterHiding ]
]
},
];
for (let panel of panels) {
// Ensure the menu panel is hidden and clean up panel listeners after calling hideMenu.
if (panel.node.state != "closed") {
await new Promise(resolve => {
panel.node.addEventListener("popuphidden", resolve, { once: true });
@@ -1120,17 +1120,17 @@ this.UITour = {
* @param aChromeWindow The chrome window that the highlight is in. Necessary since some targets
* are in a sub-frame so the defaultView is not the same as the chrome
* window.
* @param aTarget The element to highlight.
* @param aEffect (optional) The effect to use from UITour.highlightEffects or "none".
* @see UITour.highlightEffects
*/
async showHighlight(aChromeWindow, aTarget, aEffect = "none") {
- let showHighlightPanel = (aAnchorEl) => {
+ let showHighlightElement = (aAnchorEl) => {
let highlighter = aChromeWindow.document.getElementById("UITourHighlight");
let effect = aEffect;
if (effect == "random") {
// Exclude "random" from the randomly selected effects.
let randomEffect = 1 + Math.floor(Math.random() * (this.highlightEffects.length - 1));
if (randomEffect == this.highlightEffects.length)
randomEffect--; // On the order of 1 in 2^62 chance of this happening.
@@ -1180,27 +1180,31 @@ this.UITour = {
let offsetY = (targetRect.height - highlightHeightWithMin) / 2;
this._addAnnotationPanelMutationObserver(highlighter.parentElement);
highlighter.parentElement.openPopup(highlightAnchor, "overlap", offsetX, offsetY);
};
try {
await this._ensureTarget(aChromeWindow, aTarget);
let anchorEl = await this._correctAnchor(aChromeWindow, aTarget);
- showHighlightPanel(anchorEl);
+ showHighlightElement(anchorEl);
} catch (e) {
log.warn(e);
}
},
- hideHighlight(aWindow) {
+ _hideHighlightElement(aWindow) {
let highlighter = aWindow.document.getElementById("UITourHighlight");
this._removeAnnotationPanelMutationObserver(highlighter.parentElement);
highlighter.parentElement.hidePopup();
highlighter.removeAttribute("active");
+ },
+
+ hideHighlight(aWindow) {
+ this._hideHighlightElement(aWindow);
this._setMenuStateForAnnotation(aWindow, false, "appMenu");
this._setMenuStateForAnnotation(aWindow, false, "pageActionPanel");
},
/**
* Show an info panel.
*
* @param {ChromeWindow} aChromeWindow
@@ -1210,17 +1214,17 @@ this.UITour = {
* @param {String} [aIconURL=""]
* @param {Object[]} [aButtons=[]]
* @param {Object} [aOptions={}]
* @param {String} [aOptions.closeButtonCallback]
* @param {String} [aOptions.targetCallback]
*/
async showInfo(aChromeWindow, aAnchor, aTitle = "", aDescription = "",
aIconURL = "", aButtons = [], aOptions = {}) {
- let showInfoPanel = (aAnchorEl) => {
+ let showInfoElement = (aAnchorEl) => {
aAnchorEl.focus();
let document = aChromeWindow.document;
let tooltip = document.getElementById("UITourTooltip");
let tooltipTitle = document.getElementById("UITourTooltipTitle");
let tooltipDesc = document.getElementById("UITourTooltipDescription");
let tooltipIcon = document.getElementById("UITourTooltipIcon");
let tooltipButtons = document.getElementById("UITourTooltipButtons");
@@ -1309,41 +1313,44 @@ this.UITour = {
tooltip.openPopup(aAnchorEl, alignment);
}, {once: true});
}
};
try {
await this._ensureTarget(aChromeWindow, aAnchor);
let anchorEl = await this._correctAnchor(aChromeWindow, aAnchor);
- showInfoPanel(anchorEl);
+ showInfoElement(anchorEl);
} catch (e) {
log.warn(e);
}
},
isInfoOnTarget(aChromeWindow, aTargetName) {
let document = aChromeWindow.document;
let tooltip = document.getElementById("UITourTooltip");
return tooltip.getAttribute("targetName") == aTargetName && tooltip.state != "closed";
},
- hideInfo(aWindow) {
+ _hideInfoElement(aWindow) {
let document = aWindow.document;
let tooltip = document.getElementById("UITourTooltip");
this._removeAnnotationPanelMutationObserver(tooltip);
tooltip.hidePopup();
- this._setMenuStateForAnnotation(aWindow, false, "appMenu");
- this._setMenuStateForAnnotation(aWindow, false, "pageActionPanel");
-
let tooltipButtons = document.getElementById("UITourTooltipButtons");
while (tooltipButtons.firstChild)
tooltipButtons.firstChild.remove();
},
+ hideInfo(aWindow) {
+ this._hideInfoElement(aWindow);
+ this._setMenuStateForAnnotation(aWindow, false, "appMenu");
+ this._setMenuStateForAnnotation(aWindow, false, "pageActionPanel");
+ },
+
showMenu(aWindow, aMenuName, aOpenCallback = null) {
log.debug("showMenu:", aMenuName);
function openMenuButton(aMenuBtn) {
if (!aMenuBtn || !aMenuBtn.boxObject || aMenuBtn.open) {
if (aOpenCallback)
aOpenCallback();
return;
}
@@ -1353,45 +1360,47 @@ this.UITour = {
}
if (aMenuName == "appMenu" || aMenuName == "pageActionPanel") {
let menu = {
onPanelHidden: this.onPanelHidden
};
if (aMenuName == "appMenu") {
menu.node = aWindow.PanelUI.panel;
- menu.hideMenuAnnotations = this.hideAppMenuAnnotations;
+ menu.onPopupHiding = this.onAppMenuHiding;
+ menu.onViewShowing = this.onAppMenuSubviewShowing;
menu.show = () => aWindow.PanelUI.show();
} else {
menu.node = aWindow.BrowserPageActions.panelNode;
- menu.hideMenuAnnotations = this.hidePageActionPanelAnnotations;
+ menu.onPopupHiding = this.onPageActionPanelHiding;
+ menu.onViewShowing = this.onPageActionPanelSubviewShowing;
menu.show = () => aWindow.BrowserPageActions.showPanel();
}
menu.node.setAttribute("noautohide", "true");
// If the popup is already opened, don't recreate the widget as it may cause a flicker.
if (menu.node.state != "open") {
this.recreatePopup(menu.node);
}
if (aOpenCallback) {
menu.node.addEventListener("popupshown", aOpenCallback, { once: true });
}
menu.node.addEventListener("popuphidden", menu.onPanelHidden);
- menu.node.addEventListener("popuphiding", menu.hideMenuAnnotations);
- menu.node.addEventListener("ViewShowing", menu.hideMenuAnnotations);
+ menu.node.addEventListener("popuphiding", menu.onPopupHiding);
+ menu.node.addEventListener("ViewShowing", menu.onViewShowing);
menu.show();
} else if (aMenuName == "bookmarks") {
let menuBtn = aWindow.document.getElementById("bookmarks-menu-button");
openMenuButton(menuBtn);
} else if (aMenuName == "controlCenter") {
let popup = aWindow.gIdentityHandler._identityPopup;
// Add the listener even if the panel is already open since it will still
// only get registered once even if it was UITour that opened it.
- popup.addEventListener("popuphiding", this.hideControlCenterAnnotations);
+ popup.addEventListener("popuphiding", this.onControlCenterHiding);
popup.addEventListener("popuphidden", this.onPanelHidden);
popup.setAttribute("noautohide", "true");
this.clearAvailableTargetsCache();
if (popup.state == "open") {
if (aOpenCallback) {
aOpenCallback();
@@ -1486,22 +1495,32 @@ this.UITour = {
aWindow.BrowserPageActions.panelNode.hidePopup();
}
},
showNewTab(aWindow, aBrowser) {
aWindow.openLinkIn("about:newtab", "current", {targetBrowser: aBrowser});
},
- _hideAnnotationsForPanel(aEvent, aTargetPositionCallback) {
+ _hideAnnotationsForPanel(aEvent, aShouldClosePanel, aTargetPositionCallback) {
let win = aEvent.target.ownerGlobal;
+ let hideHighlightMethod = null;
+ let hideInfoMethod = null;
+ if (aShouldClosePanel) {
+ hideHighlightMethod = aWin => this.hideHighlight(aWin);
+ hideInfoMethod = aWin => this.hideInfo(aWin);
+ } else {
+ // Don't have to close panel, let's only hide annotation elements
+ hideHighlightMethod = aWin => this._hideHighlightElement(aWin);
+ hideInfoMethod = aWin => this._hideInfoElement(aWin);
+ }
let annotationElements = new Map([
// [annotationElement (panel), method to hide the annotation]
- [win.document.getElementById("UITourHighlightContainer"), UITour.hideHighlight.bind(UITour)],
- [win.document.getElementById("UITourTooltip"), UITour.hideInfo.bind(UITour)],
+ [win.document.getElementById("UITourHighlightContainer"), hideHighlightMethod],
+ [win.document.getElementById("UITourTooltip"), hideInfoMethod],
]);
annotationElements.forEach((hideMethod, annotationElement) => {
if (annotationElement.state != "closed") {
let targetName = annotationElement.getAttribute("targetName");
UITour.getTarget(win, targetName).then((aTarget) => {
// Since getTarget is async, we need to make sure that the target hasn't
// changed since it may have just moved to somewhere outside of the app menu.
if (annotationElement.getAttribute("targetName") != aTarget.targetName ||
@@ -1510,26 +1529,34 @@ this.UITour = {
return;
}
hideMethod(win);
}).catch(log.error);
}
});
},
- hideAppMenuAnnotations(aEvent) {
- UITour._hideAnnotationsForPanel(aEvent, UITour.targetIsInAppMenu);
+ onAppMenuHiding(aEvent) {
+ UITour._hideAnnotationsForPanel(aEvent, true, UITour.targetIsInAppMenu);
+ },
+
+ onAppMenuSubviewShowing(aEvent) {
+ UITour._hideAnnotationsForPanel(aEvent, false, UITour.targetIsInAppMenu);
},
- hidePageActionPanelAnnotations(aEvent) {
- UITour._hideAnnotationsForPanel(aEvent, UITour.targetIsInPageActionPanel);
+ onPageActionPanelHiding(aEvent) {
+ UITour._hideAnnotationsForPanel(aEvent, true, UITour.targetIsInPageActionPanel);
},
- hideControlCenterAnnotations(aEvent) {
- UITour._hideAnnotationsForPanel(aEvent, (aTarget) => {
+ onPageActionPanelSubviewShowing(aEvent) {
+ UITour._hideAnnotationsForPanel(aEvent, false, UITour.targetIsInPageActionPanel);
+ },
+
+ onControlCenterHiding(aEvent) {
+ UITour._hideAnnotationsForPanel(aEvent, true, (aTarget) => {
return aTarget.targetName.startsWith("controlCenter-");
});
},
onPanelHidden(aEvent) {
aEvent.target.removeAttribute("noautohide");
UITour.recreatePopup(aEvent.target);
UITour.clearAvailableTargetsCache();