mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-14 02:31:59 +00:00
Bug 600501 - Implement support for removed() callback (notificationbox); r=neil
This commit is contained in:
parent
47eca82a8c
commit
5b969cdb06
@ -49,6 +49,24 @@ function testtag_notificationbox(nb)
|
||||
runTimedTests(tests, -1, nb, null);
|
||||
}
|
||||
|
||||
var notification_last_event, notification_last_event_item;
|
||||
function notification_eventCallback(event)
|
||||
{
|
||||
notification_last_event = event;
|
||||
notification_last_event_item = this;
|
||||
}
|
||||
|
||||
function testtag_notification_eventCallback(expectedEvent, ntf, testName)
|
||||
{
|
||||
SimpleTest.is(notification_last_event, expectedEvent,
|
||||
testName + ": event name");
|
||||
SimpleTest.is(notification_last_event_item, ntf,
|
||||
testName + ": event item");
|
||||
|
||||
notification_last_event = null;
|
||||
notification_last_event_item = null;
|
||||
}
|
||||
|
||||
var tests =
|
||||
[
|
||||
{
|
||||
@ -90,6 +108,33 @@ var tests =
|
||||
ise(exh, true, "removeNotification again");
|
||||
testtag_notificationbox_State(nb, "removeNotification again", null, 0);
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
test: function(nb, ntf) {
|
||||
// append a new notification, but now with an event callback
|
||||
var ntf = nb.appendNotification("Notification", "note", "happy.png",
|
||||
nb.PRIORITY_INFO_LOW,
|
||||
testtag_notificationbox_buttons,
|
||||
notification_eventCallback);
|
||||
ise(ntf && ntf.localName == "notification", true, "append notification with callback");
|
||||
return ntf;
|
||||
},
|
||||
result: function(nb, ntf) {
|
||||
testtag_notificationbox_State(nb, "append with callback", ntf, 1);
|
||||
return ntf;
|
||||
}
|
||||
},
|
||||
{
|
||||
test: function(nb, ntf) {
|
||||
nb.removeNotification(ntf);
|
||||
return ntf;
|
||||
},
|
||||
result: function(nb, ntf) {
|
||||
testtag_notificationbox_State(nb, "removeNotification with callback",
|
||||
null, 0);
|
||||
|
||||
testtag_notification_eventCallback("removed", ntf, "removeNotification()");
|
||||
return [1, null];
|
||||
}
|
||||
},
|
||||
|
@ -77,6 +77,7 @@
|
||||
<parameter name="aImage"/>
|
||||
<parameter name="aPriority"/>
|
||||
<parameter name="aButtons"/>
|
||||
<parameter name="aEventCallback"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
if (aPriority < this.PRIORITY_INFO_LOW ||
|
||||
@ -99,6 +100,7 @@
|
||||
newitem.setAttribute("value", aValue);
|
||||
if (aImage)
|
||||
newitem.setAttribute("image", aImage);
|
||||
newitem.eventCallback = aEventCallback;
|
||||
|
||||
if (aButtons) {
|
||||
for (var b = 0; b < aButtons.length; b++) {
|
||||
@ -148,12 +150,23 @@
|
||||
if (aItem == this.currentNotification)
|
||||
this.removeCurrentNotification(aSkipAnimation);
|
||||
else if (aItem != this._closedNotification)
|
||||
this.removeChild(aItem);
|
||||
this._removeNotificationElement(aItem);
|
||||
return aItem;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="_removeNotificationElement">
|
||||
<parameter name="aChild"/>
|
||||
<body>
|
||||
<![CDATA[
|
||||
if (aChild.eventCallback)
|
||||
aChild.eventCallback("removed");
|
||||
this.removeChild(aChild);
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
<method name="removeCurrentNotification">
|
||||
<parameter name="aSkipAnimation"/>
|
||||
<body>
|
||||
@ -170,7 +183,7 @@
|
||||
var notifications = this.allNotifications;
|
||||
for (var n = notifications.length - 1; n >= 0; n--) {
|
||||
if (aImmediate)
|
||||
this.removeChild(notifications[n]);
|
||||
this._removeNotificationElement(notifications[n]);
|
||||
else
|
||||
this.removeNotification(notifications[n]);
|
||||
}
|
||||
@ -228,7 +241,7 @@
|
||||
this.currentNotification = (idx >= 0) ? notifications[idx] : null;
|
||||
|
||||
if (skipAnimation) {
|
||||
this.removeChild(this._closedNotification);
|
||||
this._removeNotificationElement(this._closedNotification);
|
||||
this._closedNotification = null;
|
||||
this._setBlockingState(this.currentNotification);
|
||||
return;
|
||||
@ -248,7 +261,7 @@
|
||||
if (this._animating) {
|
||||
this._animating = false;
|
||||
if (this._closedNotification) {
|
||||
this.removeChild(this._closedNotification);
|
||||
this._removeNotificationElement(this._closedNotification);
|
||||
this._closedNotification = null;
|
||||
}
|
||||
this._setBlockingState(this.currentNotification);
|
||||
|
Loading…
Reference in New Issue
Block a user