Bug 616607, use screen coordinates to calculate arrow panel position, r=neil, a=blocking

This commit is contained in:
Neil Deakin 2011-01-12 20:57:36 -05:00
parent f766495afc
commit efc595427c
2 changed files with 31 additions and 14 deletions

View File

@ -17,6 +17,7 @@
<!-- Our SimpleTest/TestRunner.js runs tests inside an iframe which sizes are W=500 H=300.
'left' and 'top' values need to be set so that the panel (popup) has enough room to display on its 4 sides. -->
<label id="middle" value="+/- Centered" left="225" top="135"/>
<iframe id="frame" src="data:text/html,&lt;input id='input'&gt;" width="100" height="100" left="225" top="180"/>
</stack>
<panel id="panel" type="arrow" onpopupshown="checkPanelPosition(this)" onpopuphidden="runNextTest.next()">
@ -44,7 +45,7 @@ function nextTest()
function openPopup(position, anchor, expected, anchorEdge)
{
expectedAnchor = $(anchor);
expectedAnchor = anchor instanceof Node ? anchor : $(anchor);
expectedSide = expected;
expectedAnchorEdge = anchorEdge;
@ -114,6 +115,9 @@ function nextTest()
openPopup("rightcenter bottomleft", "middle", "left", "center bottom");
yield;
openPopup("after_start", frames[0].document.getElementById("input"), "top", "left");
yield;
SimpleTest.finish();
yield;
}
@ -145,28 +149,34 @@ function checkPanelPosition(panel)
iscentered = true;
}
let adj;
let adj = 0, hwinpos = 0, vwinpos = 0;
if (anchor.ownerDocument != document) {
var framerect = anchor.ownerDocument.defaultView.frameElement.getBoundingClientRect();
hwinpos = framerect.left;
vwinpos = framerect.top;
}
switch (expectedAnchorEdge) {
case "top":
adj = parseInt(getComputedStyle(panel, "").marginTop);
adj = vwinpos + parseInt(getComputedStyle(panel, "").marginTop);
if (iscentered)
adj += anchorRect.height / 2;
is(Math.round(panelRect.top), Math.round(anchorRect.top + adj), "anchored on top");
break;
case "bottom":
adj = parseInt(getComputedStyle(panel, "").marginBottom);
adj = vwinpos + parseInt(getComputedStyle(panel, "").marginBottom);
if (iscentered)
adj += anchorRect.height / 2;
is(Math.round(panelRect.bottom), Math.round(anchorRect.bottom - adj), "anchored on bottom");
break;
case "left":
adj = parseInt(getComputedStyle(panel, "").marginLeft);
adj = hwinpos + parseInt(getComputedStyle(panel, "").marginLeft);
if (iscentered)
adj += anchorRect.width / 2;
is(Math.round(panelRect.left), Math.round(anchorRect.left + adj), "anchored on left ");
break;
case "right":
adj = parseInt(getComputedStyle(panel, "").marginRight);
adj = hwinpos + parseInt(getComputedStyle(panel, "").marginRight);
if (iscentered)
adj += anchorRect.width / 2;
is(Math.round(panelRect.right), Math.round(anchorRect.right - adj), "anchored on right");

View File

@ -307,13 +307,20 @@
return;
}
var anchorRect = anchor.getBoundingClientRect();
var popupRect = this.getBoundingClientRect();
let anchorRect = anchor.getBoundingClientRect();
let anchorLeft = Math.round(anchor.ownerDocument.defaultView.mozInnerScreenX + anchorRect.left);
let anchorTop = Math.round(anchor.ownerDocument.defaultView.mozInnerScreenY + anchorRect.top);
let anchorRight = anchorLeft + Math.floor(anchorRect.width);
let anchorBottom = anchorTop + Math.floor(anchorRect.height);
var horizPos = (Math.round(popupRect.right) <= Math.round(anchorRect.left)) ? -1 :
(Math.round(popupRect.left) >= Math.round(anchorRect.right)) ? 1 : 0;
var vertPos = (Math.round(popupRect.bottom) <= Math.round(anchorRect.top)) ? -1 :
(Math.round(popupRect.top) >= Math.round(anchorRect.bottom)) ? 1 : 0;
let popupRect = this.getBoundingClientRect();
let popupLeft = Math.round(window.mozInnerScreenX + popupRect.left);
let popupTop = Math.round(window.mozInnerScreenY + popupRect.top);
let popupRight = popupLeft + Math.floor(popupRect.width);
let popupBottom = popupTop + Math.floor(popupRect.height);
var horizPos = popupRight <= anchorLeft ? -1 : popupLeft >= anchorRight ? 1 : 0;
var vertPos = popupBottom <= anchorTop ? -1 : popupTop >= anchorBottom ? 1 : 0;
var anchorClass = "";
var hideAnchor = false;
@ -325,7 +332,7 @@
}
else {
let rtl = (window.getComputedStyle(this).direction == "rtl");
arrowbox.pack = (popupRect.left + popupRect.width / 2 < anchorRect.left) != rtl ?
arrowbox.pack = (popupLeft + popupRect.width / 2 < anchorLeft) != rtl ?
"end" : "start";
if (vertPos == 1) {
container.dir = "";
@ -344,7 +351,7 @@
hideAnchor = true;
}
else {
arrowbox.pack = popupRect.top + popupRect.height / 2 < anchorRect.top ? "end" : "start";
arrowbox.pack = popupTop + popupRect.height / 2 < anchorTop ? "end" : "start";
if (horizPos == 1) {
container.dir = "";
anchorClass = "left";