Bug 615318 - Add a "not now" choice to all doorhanger notification split buttons. r=gavin, a=blocking-beta9

--HG--
extra : rebase_source : 8b350d4d9c5ce5c8a5c6b75c3d0ad45fd5abc2ec
This commit is contained in:
Margaret Leibovic 2010-12-16 09:53:24 -08:00
parent bcbf8e92d5
commit 3624c54d2e
8 changed files with 70 additions and 10 deletions

View File

@ -527,6 +527,22 @@ var tests = [
"geo anchor should be visible");
}
},
// Test notification "Not Now" menu item
{ // Test #17
run: function () {
this.notifyObj = new basicNotification(),
this.notification = showNotification(this.notifyObj);
},
onShown: function (popup) {
checkPopup(popup, this.notifyObj);
triggerSecondaryCommand(popup, 1);
},
onHidden: function (popup) {
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
this.notification.remove();
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
}
},
];
function showNotification(notifyObj) {
@ -558,7 +574,13 @@ function checkPopup(popup, notificationObj) {
}
let actualSecondaryActions = notification.childNodes;
let secondaryActions = notificationObj.secondaryActions || [];
is(actualSecondaryActions.length, secondaryActions.length, actualSecondaryActions.length + " secondary actions");
let actualSecondaryActionsCount = actualSecondaryActions.length;
if (secondaryActions.length) {
let lastChild = actualSecondaryActions.item(actualSecondaryActions.length - 1);
is(lastChild.tagName, "menuseparator", "menuseparator exists");
actualSecondaryActionsCount--;
}
is(actualSecondaryActionsCount, secondaryActions.length, actualSecondaryActions.length + " secondary actions");
secondaryActions.forEach(function (a, i) {
is(actualSecondaryActions[i].getAttribute("label"), a.label, "label for secondary action " + i + " matches");
is(actualSecondaryActions[i].getAttribute("accesskey"), a.accessKey, "accessKey for secondary action " + i + " matches");

View File

@ -39,6 +39,11 @@
#
# ***** END LICENSE BLOCK *****
<!DOCTYPE bindings [
<!ENTITY % notificationDTD SYSTEM "chrome://global/locale/notification.dtd">
%notificationDTD;
]>
<bindings id="urlbarBindings" xmlns="http://www.mozilla.org/xbl"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
@ -1045,11 +1050,15 @@
<xul:label anonid="learnmore" class="text-link geolocation-text-link"/>
<xul:spacer flex="1"/>
<xul:button anonid="button"
type="menu-button"
class="popup-notification-menubutton"
xbl:inherits="oncommand=buttoncommand,label=buttonlabel,accesskey=buttonaccesskey,type=buttontype">
xbl:inherits="oncommand=buttoncommand,label=buttonlabel,accesskey=buttonaccesskey">
<xul:menupopup anonid="menupopup"
xbl:inherits="oncommand=menucommand">
<children/>
<xul:menuitem class="menuitem-iconic popup-notification-closeitem"
label="&closeNotificationItem.label;"
xbl:inherits="oncommand=closeitemcommand"/>
</xul:menupopup>
</xul:button>
</xul:hbox>

View File

@ -339,6 +339,13 @@ PopupNotifications.prototype = {
notifications.splice(index, 1);
this._fireCallback(notification, "removed");
},
/**
* Dismisses the notification without removing it.
*/
_dismiss: function PopupNotifications_dismiss() {
this.panel.hidePopup();
},
/**
* Hides the notification popup.
@ -370,15 +377,11 @@ PopupNotifications.prototype = {
popupnotification.setAttribute("buttonlabel", n.mainAction.label);
popupnotification.setAttribute("buttonaccesskey", n.mainAction.accessKey);
popupnotification.setAttribute("buttoncommand", "PopupNotifications._onButtonCommand(event);");
if (n.secondaryActions.length) {
popupnotification.setAttribute("buttontype", "menu-button");
popupnotification.setAttribute("menucommand", "PopupNotifications._onMenuCommand(event);");
}
popupnotification.setAttribute("menucommand", "PopupNotifications._onMenuCommand(event);");
popupnotification.setAttribute("closeitemcommand", "PopupNotifications._dismiss();event.stopPropagation();");
}
popupnotification.notification = n;
this.panel.appendChild(popupnotification);
if (n.secondaryActions) {
n.secondaryActions.forEach(function (a) {
let item = doc.createElementNS(XUL_NS, "menuitem");
@ -389,7 +392,14 @@ PopupNotifications.prototype = {
popupnotification.appendChild(item);
}, this);
if (n.secondaryActions.length) {
let closeItemSeparator = doc.createElementNS(XUL_NS, "menuseparator");
popupnotification.appendChild(closeItemSeparator);
}
}
this.panel.appendChild(popupnotification);
}, this);
},

View File

@ -429,10 +429,14 @@
<xul:hbox pack="end">
<xul:button anonid="button"
class="popup-notification-menubutton"
xbl:inherits="oncommand=buttoncommand,label=buttonlabel,accesskey=buttonaccesskey,type=buttontype">
type="menu-button"
xbl:inherits="oncommand=buttoncommand,label=buttonlabel,accesskey=buttonaccesskey">
<xul:menupopup anonid="menupopup"
xbl:inherits="oncommand=menucommand">
<children/>
<xul:menuitem class="menuitem-iconic popup-notification-closeitem"
label="&closeNotificationItem.label;"
xbl:inherits="oncommand=closeitemcommand"/>
</xul:menupopup>
</xul:button>
</xul:hbox>

View File

@ -1 +1,3 @@
<!ENTITY closeNotification.tooltip "Close this message">
<!ENTITY closeNotification.tooltip "Close this message">
<!ENTITY closeNotificationItem.label "Not Now">

View File

@ -58,3 +58,7 @@ notification[type="critical"] .messageImage {
.popup-notification-description {
max-width: 248px;
}
.popup-notification-closeitem {
list-style-image: url("moz-icon://stock/gtk-close?size=menu");
}

View File

@ -154,3 +154,7 @@ notification[type="critical"] .messageImage {
inset 0 1px 7px rgba(0,0,0,.4),
0 1px 0 rgba(255,255,255,.1);
}
.popup-notification-closeitem > .menu-iconic-left {
display: none;
}

View File

@ -151,3 +151,8 @@ notification[type="critical"] .messageImage {
}
}
%endif
.popup-notification-closeitem {
list-style-image: url("chrome://global/skin/icons/close.png");
-moz-image-region: rect(0, 16px, 16px, 0);
}