mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 958071 - PopupNotification consumers should have a way to replace the "Not Now" item, r=dolske.
This commit is contained in:
parent
910454863e
commit
c3a1c7ce25
@ -982,7 +982,7 @@ var tests = [
|
||||
},
|
||||
onHidden: function() { }
|
||||
},
|
||||
{ // Test #31 - Moving a tab to a new window should remove non-swappable
|
||||
{ // Test #34 - Moving a tab to a new window should remove non-swappable
|
||||
// notifications.
|
||||
run: function() {
|
||||
gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
||||
@ -1002,7 +1002,7 @@ var tests = [
|
||||
});
|
||||
}
|
||||
},
|
||||
{ // Test #32 - Moving a tab to a new window should preserve swappable notifications.
|
||||
{ // Test #35 - Moving a tab to a new window should preserve swappable notifications.
|
||||
run: function() {
|
||||
gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
||||
let notifyObj = new basicNotification();
|
||||
@ -1024,6 +1024,50 @@ var tests = [
|
||||
goNext();
|
||||
});
|
||||
}
|
||||
},
|
||||
{ // Test #36 - the hideNotNow option
|
||||
run: function () {
|
||||
this.notifyObj = new basicNotification();
|
||||
this.notifyObj.options.hideNotNow = true;
|
||||
this.notifyObj.mainAction.dismiss = true;
|
||||
showNotification(this.notifyObj);
|
||||
},
|
||||
onShown: function (popup) {
|
||||
// checkPopup verifies that the Not Now item is hidden, and that no separator is added.
|
||||
checkPopup(popup, this.notifyObj);
|
||||
triggerMainCommand(popup);
|
||||
},
|
||||
onHidden: function (popup) { }
|
||||
},
|
||||
{ // Test #37 - the main action callback can keep the notification.
|
||||
run: function () {
|
||||
this.notifyObj = new basicNotification();
|
||||
this.notifyObj.mainAction.dismiss = true;
|
||||
showNotification(this.notifyObj);
|
||||
},
|
||||
onShown: function (popup) {
|
||||
checkPopup(popup, this.notifyObj);
|
||||
triggerMainCommand(popup);
|
||||
},
|
||||
onHidden: function (popup) {
|
||||
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback was triggered");
|
||||
ok(!this.notifyObj.removedCallbackTriggered, "removed callback wasn't triggered");
|
||||
}
|
||||
},
|
||||
{ // Test #38 - a secondary action callback can keep the notification.
|
||||
run: function () {
|
||||
this.notifyObj = new basicNotification();
|
||||
this.notifyObj.secondaryActions[0].dismiss = true;
|
||||
showNotification(this.notifyObj);
|
||||
},
|
||||
onShown: function (popup) {
|
||||
checkPopup(popup, this.notifyObj);
|
||||
triggerSecondaryCommand(popup, 0);
|
||||
},
|
||||
onHidden: function (popup) {
|
||||
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback was triggered");
|
||||
ok(!this.notifyObj.removedCallbackTriggered, "removed callback wasn't triggered");
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@ -1063,7 +1107,12 @@ function checkPopup(popup, notificationObj) {
|
||||
function (child) child.nodeName == "menuitem");
|
||||
let secondaryActions = notificationObj.secondaryActions || [];
|
||||
let actualSecondaryActionsCount = actualSecondaryActions.length;
|
||||
if (secondaryActions.length) {
|
||||
if (notificationObj.options.hideNotNow) {
|
||||
is(notification.getAttribute("hidenotnow"), "true", "Not Now item hidden");
|
||||
if (secondaryActions.length)
|
||||
is(notification.lastChild.tagName, "menuitem", "no menuseparator");
|
||||
}
|
||||
else if (secondaryActions.length) {
|
||||
is(notification.lastChild.tagName, "menuseparator", "menuseparator exists");
|
||||
}
|
||||
is(actualSecondaryActionsCount, secondaryActions.length, actualSecondaryActions.length + " secondary actions");
|
||||
|
@ -468,7 +468,7 @@
|
||||
<children/>
|
||||
<xul:menuitem class="menuitem-iconic popup-notification-closeitem close-icon"
|
||||
label="&closeNotificationItem.label;"
|
||||
xbl:inherits="oncommand=closeitemcommand"/>
|
||||
xbl:inherits="oncommand=closeitemcommand,hidden=hidenotnow"/>
|
||||
</xul:menupopup>
|
||||
</xul:button>
|
||||
</xul:hbox>
|
||||
|
@ -196,6 +196,8 @@ PopupNotifications.prototype = {
|
||||
* - accessKey (string): the button's accessKey.
|
||||
* - callback (function): a callback to be invoked when the button is
|
||||
* pressed.
|
||||
* - [optional] dismiss (boolean): If this is true, the notification
|
||||
* will be dismissed instead of removed after running the callback.
|
||||
* If null, the notification will not have a button, and
|
||||
* secondaryActions will be ignored.
|
||||
* @param secondaryActions
|
||||
@ -249,6 +251,11 @@ PopupNotifications.prototype = {
|
||||
* removed when they would have otherwise been dismissed
|
||||
* (i.e. any time the popup is closed due to user
|
||||
* interaction).
|
||||
* hideNotNow: If true, indicates that the 'Not Now' menuitem should
|
||||
* not be shown. If 'Not Now' is hidden, it needs to be
|
||||
* replaced by another 'do nothing' item, so providing at
|
||||
* least one secondary action is required; and one of the
|
||||
* actions needs to have the 'dismiss' property set to true.
|
||||
* popupIconURL:
|
||||
* A string. URL of the image to be displayed in the popup.
|
||||
* Normally specified in CSS using list-style-image and the
|
||||
@ -269,6 +276,10 @@ PopupNotifications.prototype = {
|
||||
throw "PopupNotifications_show: invalid mainAction";
|
||||
if (secondaryActions && secondaryActions.some(isInvalidAction))
|
||||
throw "PopupNotifications_show: invalid secondaryActions";
|
||||
if (options && options.hideNotNow &&
|
||||
(!secondaryActions || !secondaryActions.length ||
|
||||
!secondaryActions.concat(mainAction).some(action => action.dismiss)))
|
||||
throw "PopupNotifications_show: 'Not Now' item hidden without replacement";
|
||||
|
||||
let notification = new Notification(id, message, anchorID, mainAction,
|
||||
secondaryActions, browser, this, options);
|
||||
@ -549,7 +560,10 @@ PopupNotifications.prototype = {
|
||||
popupnotification.appendChild(item);
|
||||
}, this);
|
||||
|
||||
if (n.secondaryActions.length) {
|
||||
if (n.options.hideNotNow) {
|
||||
popupnotification.setAttribute("hidenotnow", "true");
|
||||
}
|
||||
else if (n.secondaryActions.length) {
|
||||
let closeItemSeparator = doc.createElementNS(XUL_NS, "menuseparator");
|
||||
popupnotification.appendChild(closeItemSeparator);
|
||||
}
|
||||
@ -894,6 +908,11 @@ PopupNotifications.prototype = {
|
||||
Cu.reportError(error);
|
||||
}
|
||||
|
||||
if (notification.mainAction.dismiss) {
|
||||
this._dismiss();
|
||||
return;
|
||||
}
|
||||
|
||||
this._remove(notification);
|
||||
this._update();
|
||||
},
|
||||
@ -910,6 +929,11 @@ PopupNotifications.prototype = {
|
||||
Cu.reportError(error);
|
||||
}
|
||||
|
||||
if (target.action.dismiss) {
|
||||
this._dismiss();
|
||||
return;
|
||||
}
|
||||
|
||||
this._remove(target.notification);
|
||||
this._update();
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user