Bug 783691 - show/hide events for social content. r=gavin

This commit is contained in:
Shane Caraveo 2012-08-20 11:25:47 -07:00
parent 1e2b93b58c
commit 0be33283e4
5 changed files with 53 additions and 18 deletions

View File

@ -262,7 +262,7 @@ var SocialToolbar = {
removeItem.setAttribute("accesskey", accesskey);
let statusAreaPopup = document.getElementById("social-statusarea-popup");
statusAreaPopup.addEventListener("popupshowing", function(e) {
statusAreaPopup.addEventListener("popupshown", function(e) {
this.button.setAttribute("open", "true");
}.bind(this));
statusAreaPopup.addEventListener("popuphidden", function(e) {
@ -410,12 +410,34 @@ var SocialToolbar = {
sizePanelToContent();
function dispatchPanelEvent(name) {
let evt = notifBrowser.contentDocument.createEvent("CustomEvent");
evt.initCustomEvent(name, true, true, {});
notifBrowser.contentDocument.documentElement.dispatchEvent(evt);
}
panel.addEventListener("popuphiding", function onpopuphiding() {
panel.removeEventListener("popuphiding", onpopuphiding);
SocialToolbar.button.removeAttribute("open");
dispatchPanelEvent("socialFrameHide");
});
panel.addEventListener("popupshown", function onpopupshown() {
panel.removeEventListener("popupshown", onpopupshown);
SocialToolbar.button.setAttribute("open", "true");
if (notifBrowser.contentDocument.readyState == "complete") {
dispatchPanelEvent("socialFrameShow");
} else {
// first time load, wait for load and dispatch after load
notifBrowser.addEventListener("load", function panelBrowserOnload(e) {
notifBrowser.removeEventListener("load", panelBrowserOnload, true);
setTimeout(function() {
dispatchPanelEvent("socialFrameShow");
}, 0);
}, true);
}
});
this.button.setAttribute("open", "true");
panel.openPopup(iconImage, "bottomcenter topleft", 0, 0, false, false);
}
}
@ -469,7 +491,7 @@ var SocialSidebar = {
let sbrowser = document.getElementById("social-sidebar-browser");
if (hideSidebar) {
this.dispatchEvent("sidebarhide");
this.dispatchEvent("socialFrameHide");
// If we're disabled, unload the sidebar content
if (!this.canShow) {
sbrowser.removeAttribute("origin");
@ -484,11 +506,11 @@ var SocialSidebar = {
sbrowser.removeEventListener("load", sidebarOnShow);
// let load finish, then fire our event
setTimeout(function () {
SocialSidebar.dispatchEvent("sidebarshow");
SocialSidebar.dispatchEvent("socialFrameShow");
}, 0);
});
} else {
this.dispatchEvent("sidebarshow");
this.dispatchEvent("socialFrameShow");
}
}
}

View File

@ -37,20 +37,21 @@ var tests = {
let port = Social.provider.port;
ok(port, "provider has a port");
port.postMessage({topic: "test-init"});
Social.provider.port.onmessage = function (e) {
port.onmessage = function (e) {
let topic = e.data.topic;
switch (topic) {
case "got-panel-message":
ok(true, "got panel message");
// Wait for the panel to close before ending the test
let panel = document.getElementById("social-notification-panel");
panel.addEventListener("popuphidden", function hiddenListener() {
panel.removeEventListener("popuphidden", hiddenListener);
next();
});
panel.hidePopup();
break;
case "got-social-panel-visibility":
if (e.data.result == "shown") {
ok(true, "panel shown");
let panel = document.getElementById("social-notification-panel");
panel.hidePopup();
} else if (e.data.result == "hidden") {
ok(true, "panel hidden");
next();
}
case "got-sidebar-message":
// The sidebar message will always come first, since it loads by default
ok(true, "got sidebar message");
@ -59,6 +60,7 @@ var tests = {
break;
}
}
port.postMessage({topic: "test-init"});
// Our worker sets up ambient notification at the same time as it responds to
// the workerAPI initialization. If it's already initialized, we can

View File

@ -38,13 +38,13 @@ function doTest(finishcb) {
ok(!command.hidden, "toggle command should be visible");
checkShown(true);
browser.addEventListener("sidebarhide", function sidebarhide() {
browser.removeEventListener("sidebarhide", sidebarhide);
browser.addEventListener("socialFrameHide", function sidebarhide() {
browser.removeEventListener("socialFrameHide", sidebarhide);
checkShown(false);
browser.addEventListener("sidebarshow", function sidebarshow() {
browser.removeEventListener("sidebarshow", sidebarshow);
browser.addEventListener("socialFrameShow", function sidebarshow() {
browser.removeEventListener("socialFrameShow", sidebarshow);
checkShown(true);

View File

@ -6,6 +6,14 @@
var port = navigator.mozSocial.getWorker().port;
port.postMessage({topic: "panel-message", result: "ok"});
}
window.addEventListener("socialFrameShow", function(e) {
var port = navigator.mozSocial.getWorker().port;
port.postMessage({topic: "status-panel-visibility", result: "shown"});
}, false);
window.addEventListener("socialFrameHide", function(e) {
var port = navigator.mozSocial.getWorker().port;
port.postMessage({topic: "status-panel-visibility", result: "hidden"});
}, false);
</script>
</head>
<body onload="pingWorker();">

View File

@ -39,6 +39,9 @@ onconnect = function(e) {
if (testPort && event.data.result == "ok")
testPort.postMessage({topic:"got-panel-message"});
break;
case "status-panel-visibility":
testPort.postMessage({topic:"got-social-panel-visibility", result: event.data.result });
break;
case "social.initialize":
// This is the workerAPI port, respond and set up a notification icon.
port.postMessage({topic: "social.initialize-response"});