Bug 935823 - UITour: Add a close button to info panels. r=Unfocused

This commit is contained in:
Matthew Noorenberghe 2014-03-07 13:00:18 -05:00
parent 316891bb1b
commit dd6388f495
5 changed files with 60 additions and 14 deletions

View File

@ -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;

View File

@ -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);
}
];

View File

@ -20,6 +20,12 @@
{label: "Button 2", callback: makeCallback("button2"), icon: "image.png"}
];
}
function makeInfoOptions() {
return {
closeButtonCallback: makeCallback("closeButton")
};
}
</script>
</head>
<body>

View File

@ -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
});
};

View File

@ -51,7 +51,6 @@
}
#UITourTooltipClose {
visibility: hidden; /* XXX Temporarily disabled by bug 966913 */
-moz-appearance: none;
border: none;
background-color: transparent;