зеркало из https://github.com/mozilla/gecko-dev.git
Bug 798212 - social flyout may be horizontally misaligned after resizing. r=jaws
This commit is contained in:
Родитель
179b54d53a
Коммит
f78a21f8ab
|
@ -3,7 +3,7 @@
|
|||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
// The minimum sizes for the auto-resize panel code.
|
||||
const PANEL_MIN_HEIGHT = 300;
|
||||
const PANEL_MIN_HEIGHT = 100;
|
||||
const PANEL_MIN_WIDTH = 330;
|
||||
|
||||
let SocialUI = {
|
||||
|
@ -203,7 +203,7 @@ let SocialChatBar = {
|
|||
}
|
||||
}
|
||||
|
||||
function sizeSocialPanelToContent(iframe) {
|
||||
function sizeSocialPanelToContent(panel, iframe) {
|
||||
// FIXME: bug 764787: Maybe we can use nsIDOMWindowUtils.getRootBounds() here?
|
||||
let doc = iframe.contentDocument;
|
||||
if (!doc || !doc.body) {
|
||||
|
@ -214,9 +214,17 @@ function sizeSocialPanelToContent(iframe) {
|
|||
let cs = doc.defaultView.getComputedStyle(body);
|
||||
let computedHeight = parseInt(cs.marginTop) + body.offsetHeight + parseInt(cs.marginBottom);
|
||||
let height = Math.max(computedHeight, PANEL_MIN_HEIGHT);
|
||||
iframe.style.height = height + "px";
|
||||
let computedWidth = parseInt(cs.marginLeft) + body.offsetWidth + parseInt(cs.marginRight);
|
||||
let width = Math.max(computedWidth, PANEL_MIN_WIDTH);
|
||||
let wDiff = width - iframe.getBoundingClientRect().width;
|
||||
// A panel resize will move the right margin - if that is where the anchor
|
||||
// arrow is, the arrow will be mis-aligned from the anchor. So we move the
|
||||
// popup to compensate for that. See bug 799014.
|
||||
if (wDiff !== 0 && panel.getAttribute("side") == "right") {
|
||||
let box = panel.boxObject;
|
||||
panel.moveTo(box.screenX - wDiff, box.screenY);
|
||||
}
|
||||
iframe.style.height = height + "px";
|
||||
iframe.style.width = width + "px";
|
||||
}
|
||||
|
||||
|
@ -225,18 +233,18 @@ function DynamicResizeWatcher() {
|
|||
}
|
||||
|
||||
DynamicResizeWatcher.prototype = {
|
||||
start: function DynamicResizeWatcher_start(iframe) {
|
||||
start: function DynamicResizeWatcher_start(panel, iframe) {
|
||||
this.stop(); // just in case...
|
||||
let doc = iframe.contentDocument;
|
||||
this._mutationObserver = new iframe.contentWindow.MutationObserver(function(mutations) {
|
||||
sizeSocialPanelToContent(iframe);
|
||||
sizeSocialPanelToContent(panel, iframe);
|
||||
});
|
||||
// Observe anything that causes the size to change.
|
||||
let config = {attributes: true, characterData: true, childList: true, subtree: true};
|
||||
this._mutationObserver.observe(doc, config);
|
||||
// and since this may be setup after the load event has fired we do an
|
||||
// initial resize now.
|
||||
sizeSocialPanelToContent(iframe);
|
||||
sizeSocialPanelToContent(panel, iframe);
|
||||
},
|
||||
stop: function DynamicResizeWatcher_stop() {
|
||||
if (this._mutationObserver) {
|
||||
|
@ -309,19 +317,20 @@ let SocialFlyout = {
|
|||
},
|
||||
|
||||
onShown: function(aEvent) {
|
||||
let iframe = this.panel.firstChild;
|
||||
let panel = this.panel;
|
||||
let iframe = panel.firstChild;
|
||||
this._dynamicResizer = new DynamicResizeWatcher();
|
||||
iframe.docShell.isActive = true;
|
||||
iframe.docShell.isAppTab = true;
|
||||
if (iframe.contentDocument.readyState == "complete") {
|
||||
this._dynamicResizer.start(iframe);
|
||||
this._dynamicResizer.start(panel, iframe);
|
||||
this.dispatchPanelEvent("socialFrameShow");
|
||||
} else {
|
||||
// first time load, wait for load and dispatch after load
|
||||
iframe.addEventListener("load", function panelBrowserOnload(e) {
|
||||
iframe.removeEventListener("load", panelBrowserOnload, true);
|
||||
setTimeout(function() {
|
||||
SocialFlyout._dynamicResizer.start(iframe);
|
||||
SocialFlyout._dynamicResizer.start(panel, iframe);
|
||||
SocialFlyout.dispatchPanelEvent("socialFrameShow");
|
||||
}, 0);
|
||||
}, true);
|
||||
|
@ -366,7 +375,7 @@ let SocialFlyout = {
|
|||
}
|
||||
}
|
||||
|
||||
sizeSocialPanelToContent(iframe);
|
||||
sizeSocialPanelToContent(panel, iframe);
|
||||
let anchor = document.getElementById("social-sidebar-browser");
|
||||
if (panel.state == "open") {
|
||||
// this is painful - there is no way to say "move to a new anchor offset",
|
||||
|
@ -792,13 +801,13 @@ var SocialToolbar = {
|
|||
notificationFrame.docShell.isActive = true;
|
||||
notificationFrame.docShell.isAppTab = true;
|
||||
if (notificationFrame.contentDocument.readyState == "complete") {
|
||||
dynamicResizer.start(notificationFrame);
|
||||
dynamicResizer.start(panel, notificationFrame);
|
||||
dispatchPanelEvent("socialFrameShow");
|
||||
} else {
|
||||
// first time load, wait for load and dispatch after load
|
||||
notificationFrame.addEventListener("load", function panelBrowserOnload(e) {
|
||||
notificationFrame.removeEventListener("load", panelBrowserOnload, true);
|
||||
dynamicResizer.start(notificationFrame);
|
||||
dynamicResizer.start(panel, notificationFrame);
|
||||
setTimeout(function() {
|
||||
dispatchPanelEvent("socialFrameShow");
|
||||
}, 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче