diff --git a/browser/modules/UITour.jsm b/browser/modules/UITour.jsm index 43fd29f76a7..0394c0d576c 100644 --- a/browser/modules/UITour.jsm +++ b/browser/modules/UITour.jsm @@ -325,7 +325,12 @@ this.UITour = { } } - this.showInfo(contentDocument, target, data.title, data.text, iconURL, buttons); + let infoOptions = {}; + + if (typeof data.closeButtonCallbackID == "string") + infoOptions.closeButtonCallbackID = data.closeButtonCallbackID; + + this.showInfo(contentDocument, target, data.title, data.text, iconURL, buttons, infoOptions); }).then(null, Cu.reportError); break; } @@ -508,14 +513,6 @@ this.UITour = { } break; } - - case "command": { - if (aEvent.target.id == "UITourTooltipClose") { - let window = aEvent.target.ownerDocument.defaultView; - this.hideInfo(window); - } - break; - } } }, @@ -870,7 +867,20 @@ this.UITour = { this._setAppMenuStateForAnnotation(aWindow, "highlight", false); }, - showInfo: function(aContentDocument, aAnchor, aTitle = "", aDescription = "", aIconURL = "", aButtons = []) { + /** + * Show an info panel. + * + * @param {Document} aContentDocument + * @param {Node} aAnchor + * @param {String} [aTitle=""] + * @param {String} [aDescription=""] + * @param {String} [aIconURL=""] + * @param {Object[]} [aButtons=[]] + * @param {Object} [aOptions={}] + * @param {String} [aOptions.closeButtonCallbackID] + */ + showInfo: function(aContentDocument, aAnchor, aTitle = "", aDescription = "", aIconURL = "", + aButtons = [], aOptions = {}) { function showInfoPanel(aAnchorEl) { aAnchorEl.focus(); @@ -914,7 +924,16 @@ this.UITour = { tooltipButtons.hidden = !aButtons.length; let tooltipClose = document.getElementById("UITourTooltipClose"); - tooltipClose.addEventListener("command", this); + let closeButtonCallback = (event) => { + this.hideInfo(document.defaultView); + if (aOptions && aOptions.closeButtonCallbackID) + this.sendPageCallback(aContentDocument, aOptions.closeButtonCallbackID); + }; + tooltipClose.addEventListener("command", closeButtonCallback); + tooltip.addEventListener("popuphiding", function tooltipHiding(event) { + tooltip.removeEventListener("popuphiding", tooltipHiding); + tooltipClose.removeEventListener("command", closeButtonCallback); + }); tooltip.setAttribute("targetName", aAnchor.targetName); tooltip.hidden = false; diff --git a/browser/modules/test/browser_UITour3.js b/browser/modules/test/browser_UITour3.js index 8d04d96fbb0..e7c3bd836f3 100644 --- a/browser/modules/test/browser_UITour3.js +++ b/browser/modules/test/browser_UITour3.js @@ -122,4 +122,21 @@ let tests = [ let buttons = gContentWindow.makeButtons(); gContentAPI.showInfo("urlbar", "another title", "moar text", "./image.png", buttons); }, + + function test_info_close_button(done) { + let popup = document.getElementById("UITourTooltip"); + let closeButton = document.getElementById("UITourTooltipClose"); + + popup.addEventListener("popupshown", function onPopupShown() { + popup.removeEventListener("popupshown", onPopupShown); + EventUtils.synthesizeMouseAtCenter(closeButton, {}, window); + executeSoon(function() { + is(gContentWindow.callbackResult, "closeButton", "Close button callback called"); + done(); + }); + }); + + let infoOptions = gContentWindow.makeInfoOptions(); + gContentAPI.showInfo("urlbar", "Close me", "X marks the spot", null, null, infoOptions); + } ]; diff --git a/browser/modules/test/uitour.html b/browser/modules/test/uitour.html index 7941cbf1a86..057c596ce07 100644 --- a/browser/modules/test/uitour.html +++ b/browser/modules/test/uitour.html @@ -20,6 +20,12 @@ {label: "Button 2", callback: makeCallback("button2"), icon: "image.png"} ]; } + + function makeInfoOptions() { + return { + closeButtonCallback: makeCallback("closeButton") + }; + } diff --git a/browser/modules/test/uitour.js b/browser/modules/test/uitour.js index 8d136627af8..6e27907491f 100644 --- a/browser/modules/test/uitour.js +++ b/browser/modules/test/uitour.js @@ -77,7 +77,7 @@ if (typeof Mozilla == 'undefined') { _sendEvent('hideHighlight'); }; - Mozilla.UITour.showInfo = function(target, title, text, icon, buttons) { + Mozilla.UITour.showInfo = function(target, title, text, icon, buttons, options) { var buttonData = []; if (Array.isArray(buttons)) { for (var i = 0; i < buttons.length; i++) { @@ -90,12 +90,17 @@ if (typeof Mozilla == 'undefined') { } } + var closeButtonCallbackID; + if (options && options.closeButtonCallback) + closeButtonCallbackID = _waitForCallback(options.closeButtonCallback); + _sendEvent('showInfo', { target: target, title: title, text: text, icon: icon, - buttons: buttonData + buttons: buttonData, + closeButtonCallbackID: closeButtonCallbackID }); }; diff --git a/browser/themes/shared/UITour.inc.css b/browser/themes/shared/UITour.inc.css index aa331894c8d..e905ce519f8 100644 --- a/browser/themes/shared/UITour.inc.css +++ b/browser/themes/shared/UITour.inc.css @@ -51,7 +51,6 @@ } #UITourTooltipClose { - visibility: hidden; /* XXX Temporarily disabled by bug 966913 */ -moz-appearance: none; border: none; background-color: transparent;