bug 805684 fix flicker of flyout panel on first open, r=felipe

This commit is contained in:
Shane Caraveo 2013-05-31 13:22:51 -07:00
parent 501c3a34a7
commit f057836ef2
2 changed files with 59 additions and 46 deletions

View File

@ -444,8 +444,14 @@ SocialFlyout = {
return document.getElementById("social-flyout-panel");
},
get iframe() {
if (!this.panel.firstChild)
this._createFrame();
return this.panel.firstChild;
},
dispatchPanelEvent: function(name) {
let doc = this.panel.firstChild.contentDocument;
let doc = this.iframe.contentDocument;
let evt = doc.createEvent("CustomEvent");
evt.initCustomEvent(name, true, true, {});
doc.documentElement.dispatchEvent(evt);
@ -466,13 +472,9 @@ SocialFlyout = {
},
setFlyoutErrorMessage: function SF_setFlyoutErrorMessage() {
let iframe = this.panel.firstChild;
if (!iframe)
return;
iframe.removeAttribute("src");
iframe.webNavigation.loadURI("about:socialerror?mode=compactInfo", null, null, null, null);
sizeSocialPanelToContent(this.panel, iframe);
this.iframe.removeAttribute("src");
this.iframe.webNavigation.loadURI("about:socialerror?mode=compactInfo", null, null, null, null);
sizeSocialPanelToContent(this.panel, this.iframe);
},
unload: function() {
@ -488,7 +490,7 @@ SocialFlyout = {
onShown: function(aEvent) {
let panel = this.panel;
let iframe = panel.firstChild;
let iframe = this.iframe;
this._dynamicResizer = new DynamicResizeWatcher();
iframe.docShell.isActive = true;
iframe.docShell.isAppTab = true;
@ -512,10 +514,37 @@ SocialFlyout = {
onHidden: function(aEvent) {
this._dynamicResizer.stop();
this._dynamicResizer = null;
this.panel.firstChild.docShell.isActive = false;
this.iframe.docShell.isActive = false;
this.dispatchPanelEvent("socialFrameHide");
},
load: function(aURL, cb) {
if (!Social.provider)
return;
this.panel.hidden = false;
let iframe = this.iframe;
// same url with only ref difference does not cause a new load, so we
// want to go right to the callback
let src = iframe.contentDocument && iframe.contentDocument.documentURIObject;
if (!src || !src.equalsExceptRef(Services.io.newURI(aURL, null, null))) {
iframe.addEventListener("load", function documentLoaded() {
iframe.removeEventListener("load", documentLoaded, true);
cb();
}, true);
// Force a layout flush by calling .clientTop so
// that the docShell of this frame is created
iframe.clientTop;
Social.setErrorListener(iframe, SocialFlyout.setFlyoutErrorMessage.bind(SocialFlyout))
iframe.setAttribute("src", aURL);
} else {
// we still need to set the src to trigger the contents hashchange event
// for ref changes
iframe.setAttribute("src", aURL);
cb();
}
},
open: function(aURL, yOffset, aCallback) {
// Hide any other social panels that may be open.
document.getElementById("social-notification-panel").hidePopup();
@ -523,44 +552,24 @@ SocialFlyout = {
if (!SocialUI.enabled)
return;
let panel = this.panel;
if (!panel.firstChild)
this._createFrame();
panel.hidden = false;
let iframe = panel.firstChild;
let iframe = this.iframe;
let src = iframe.getAttribute("src");
if (src != aURL) {
iframe.addEventListener("load", function documentLoaded() {
iframe.removeEventListener("load", documentLoaded, true);
if (aCallback) {
try {
aCallback(iframe.contentWindow);
} catch(e) {
Cu.reportError(e);
}
}
}, true);
iframe.setAttribute("src", aURL);
}
else if (aCallback) {
try {
aCallback(iframe.contentWindow);
} catch(e) {
Cu.reportError(e);
this.load(aURL, function() {
sizeSocialPanelToContent(panel, iframe);
let anchor = document.getElementById("social-sidebar-browser");
if (panel.state == "open") {
panel.moveToAnchor(anchor, "start_before", 0, yOffset, false);
} else {
panel.openPopup(anchor, "start_before", 0, yOffset, false, false);
}
}
sizeSocialPanelToContent(panel, iframe);
let anchor = document.getElementById("social-sidebar-browser");
if (panel.state == "open") {
panel.moveToAnchor(anchor, "start_before", 0, yOffset, false);
} else {
panel.openPopup(anchor, "start_before", 0, yOffset, false, false);
// Force a layout flush by calling .clientTop so
// that the docShell of this frame is created
panel.firstChild.clientTop;
Social.setErrorListener(iframe, this.setFlyoutErrorMessage.bind(this))
}
if (aCallback) {
try {
aCallback(iframe.contentWindow);
} catch(e) {
Cu.reportError(e);
}
}
});
}
}

View File

@ -20,6 +20,10 @@ function test() {
var tests = {
testOpenCloseFlyout: function(next) {
let panel = document.getElementById("social-flyout-panel");
panel.addEventListener("popupshowing", function onShowing() {
panel.removeEventListener("popupshowing", onShowing);
is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing");
});
let port = Social.provider.getWorkerPort();
ok(port, "provider has a port");
port.onmessage = function (e) {