Backed out changeset 7d7f59076479

This commit is contained in:
Robert O'Callahan 2009-11-10 13:58:35 +13:00
Родитель 2590e098c8
Коммит dabda822fc
5 изменённых файлов: 19 добавлений и 109 удалений

Просмотреть файл

@ -763,6 +763,9 @@ nsMenuPopupFrame::AdjustPositionForAnchorAlign(const nsRect& anchorRect,
// first, determine at which corner of the anchor the popup should appear // first, determine at which corner of the anchor the popup should appear
nsPoint pnt; nsPoint pnt;
switch (popupAnchor) { switch (popupAnchor) {
case POPUPALIGNMENT_TOPLEFT:
pnt = anchorRect.TopLeft();
break;
case POPUPALIGNMENT_TOPRIGHT: case POPUPALIGNMENT_TOPRIGHT:
pnt = anchorRect.TopRight(); pnt = anchorRect.TopRight();
break; break;
@ -772,10 +775,6 @@ nsMenuPopupFrame::AdjustPositionForAnchorAlign(const nsRect& anchorRect,
case POPUPALIGNMENT_BOTTOMRIGHT: case POPUPALIGNMENT_BOTTOMRIGHT:
pnt = anchorRect.BottomRight(); pnt = anchorRect.BottomRight();
break; break;
case POPUPALIGNMENT_TOPLEFT:
default:
pnt = anchorRect.TopLeft();
break;
} }
// If the alignment is on the right edge of the popup, move the popup left // If the alignment is on the right edge of the popup, move the popup left
@ -785,6 +784,9 @@ nsMenuPopupFrame::AdjustPositionForAnchorAlign(const nsRect& anchorRect,
nsMargin margin(0, 0, 0, 0); nsMargin margin(0, 0, 0, 0);
GetStyleMargin()->GetMargin(margin); GetStyleMargin()->GetMargin(margin);
switch (popupAlign) { switch (popupAlign) {
case POPUPALIGNMENT_TOPLEFT:
pnt.MoveBy(margin.left, margin.top);
break;
case POPUPALIGNMENT_TOPRIGHT: case POPUPALIGNMENT_TOPRIGHT:
pnt.MoveBy(-mRect.width - margin.right, margin.top); pnt.MoveBy(-mRect.width - margin.right, margin.top);
break; break;
@ -794,15 +796,11 @@ nsMenuPopupFrame::AdjustPositionForAnchorAlign(const nsRect& anchorRect,
case POPUPALIGNMENT_BOTTOMRIGHT: case POPUPALIGNMENT_BOTTOMRIGHT:
pnt.MoveBy(-mRect.width - margin.right, -mRect.height - margin.bottom); pnt.MoveBy(-mRect.width - margin.right, -mRect.height - margin.bottom);
break; break;
case POPUPALIGNMENT_TOPLEFT:
default:
pnt.MoveBy(margin.left, margin.top);
break;
} }
// Flipping vertically is allowed as long as the popup is above or below the // Flipping horizontally is allowed as long as the popup is above or below
// anchor. This will happen if both the anchor and alignment are top or both // the anchor. This will happen if both the anchor and alignment are top or
// are bottom, but different values. Similarly, flipping horizontally is // both are bottom, but different values. Similarly, flipping vertically is
// allowed if the popup is to the left or right of the anchor. In this case, // allowed if the popup is to the left or right of the anchor. In this case,
// the values of the constants are such that both must be positive or both // the values of the constants are such that both must be positive or both
// must be negative. A special case, used for overlap, allows flipping // must be negative. A special case, used for overlap, allows flipping
@ -860,7 +858,6 @@ nsMenuPopupFrame::FlipOrResize(nscoord& aScreenPoint, nscoord aSize,
aScreenPoint = aScreenEnd - aSize; aScreenPoint = aScreenEnd - aSize;
} }
else { else {
aScreenPoint = aAnchorEnd + aMarginBegin;
popupSize = aScreenEnd - aScreenPoint; popupSize = aScreenEnd - aScreenPoint;
} }
} }
@ -883,22 +880,7 @@ nsMenuPopupFrame::FlipOrResize(nscoord& aScreenPoint, nscoord aSize,
} }
} }
// Make sure that the point in within the screen boundaries and that the return popupSize;
// size isn't off the edge of the screen. This can happen when a large
// positive or negative margin is used.
if (aScreenPoint < aScreenBegin) {
aScreenPoint = aScreenBegin;
}
if (aScreenPoint > aScreenEnd) {
aScreenPoint = aScreenEnd - aSize;
}
// If popupSize ended up being negative, or the original size was actually
// smaller than the calculated popup size, just use the original size instead.
if (popupSize <= 0 || aSize < popupSize) {
popupSize = aSize;
}
return NS_MIN(popupSize, aScreenEnd - aScreenPoint);
} }
nsresult nsresult

Просмотреть файл

@ -35,7 +35,6 @@ var gTestEventIndex = 0;
var gAutoHide = false; var gAutoHide = false;
var gExpectedEventDetails = null; var gExpectedEventDetails = null;
var gWindowUtils; var gWindowUtils;
var gPopupWidth = -1, gPopupHeight = -1;
function startPopupTests(tests) function startPopupTests(tests)
{ {
@ -300,15 +299,9 @@ function compareEdge(anchor, popup, edge, offsetX, offsetY, testname)
var popuprect = popup.getBoundingClientRect(); var popuprect = popup.getBoundingClientRect();
var check1 = false, check2 = false; var check1 = false, check2 = false;
if (gPopupWidth == -1) { ok((Math.round(popuprect.right) - Math.round(popuprect.left)) &&
ok((Math.round(popuprect.right) - Math.round(popuprect.left)) && (Math.round(popuprect.bottom) - Math.round(popuprect.top)),
(Math.round(popuprect.bottom) - Math.round(popuprect.top)), testname + " size");
testname + " size");
}
else {
is(Math.round(popuprect.width), gPopupWidth, testname + " width");
is(Math.round(popuprect.height), gPopupHeight, testname + " height");
}
if (edge == "after_pointer") { if (edge == "after_pointer") {
is(Math.round(popuprect.left), Math.round(anchorrect.left) + offsetX, testname + " x position"); is(Math.round(popuprect.left), Math.round(anchorrect.left) + offsetX, testname + " x position");

Просмотреть файл

@ -32,11 +32,6 @@ var popupTests = [
events: [ "popupshowing thepopup", "popupshown thepopup" ], events: [ "popupshowing thepopup", "popupshown thepopup" ],
test: function() { synthesizeMouse(gTrigger, 4, 4, { }); }, test: function() { synthesizeMouse(gTrigger, 4, 4, { }); },
result: function (testname) { result: function (testname) {
// this will be used in some tests to ensure the size doesn't change
var popuprect = gMenuPopup.getBoundingClientRect();
gPopupWidth = Math.round(popuprect.width);
gPopupHeight = Math.round(popuprect.height);
checkActive(gMenuPopup, "", testname); checkActive(gMenuPopup, "", testname);
checkOpen("trigger", testname); checkOpen("trigger", testname);
// if a menu, the popup should be opened underneath the menu in the // if a menu, the popup should be opened underneath the menu in the
@ -194,67 +189,6 @@ var popupTests = [
gMenuPopup.removeAttribute("style"); gMenuPopup.removeAttribute("style");
} }
}, },
{
testname: "open popup with large positive margin",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
steps: ["before_start", "before_end", "after_start", "after_end",
"start_before", "start_after", "end_before", "end_after", "after_pointer", "overlap"],
test: function(testname, step) {
gMenuPopup.setAttribute("style", "margin: 1000px;");
gMenuPopup.openPopup(gTrigger, step, 0, 0, false, false);
},
result: function(testname, step) {
var popuprect = gMenuPopup.getBoundingClientRect();
// as there is more room on the 'end' or 'after' side, popups will always
// appear on the right or bottom corners, depending on which side they are
// allowed to be flipped by.
var expectedleft = step == "before_end" || step == "after_end" ?
0 : Math.round(window.innerWidth - gPopupWidth);
var expectedtop = step == "start_after" || step == "end_after" ?
0 : Math.round(window.innerHeight - gPopupHeight);
is(Math.round(popuprect.left), expectedleft, testname + " x position " + step);
is(Math.round(popuprect.top), expectedtop, testname + " y position " + step);
gMenuPopup.removeAttribute("style");
}
},
{
testname: "open popup with large negative margin",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
steps: ["before_start", "before_end", "after_start", "after_end",
"start_before", "start_after", "end_before", "end_after", "after_pointer", "overlap"],
test: function(testname, step) {
gMenuPopup.setAttribute("style", "margin: -1000px;");
gMenuPopup.openPopup(gTrigger, step, 0, 0, false, false);
},
result: function(testname, step) {
var popuprect = gMenuPopup.getBoundingClientRect();
// using negative margins causes the reverse of positive margins, and
// popups will appear on the left or top corners.
var expectedleft = step == "before_end" || step == "after_end" ?
Math.round(window.innerWidth - gPopupWidth) : 0;
var expectedtop = step == "start_after" || step == "end_after" ?
Math.round(window.innerHeight - gPopupHeight) : 0;
is(Math.round(popuprect.left), expectedleft, testname + " x position " + step);
is(Math.round(popuprect.top), expectedtop, testname + " y position " + step);
gMenuPopup.removeAttribute("style");
}
},
{
testname: "popup with unknown step",
events: [ "popupshowing thepopup", "popupshown thepopup" ],
autohide: "thepopup",
test: function() {
gMenuPopup.openPopup(gTrigger, "other", 0, 0, false, false);
},
result: function (testname) {
var triggerrect = gMenuPopup.getBoundingClientRect();
var popuprect = gMenuPopup.getBoundingClientRect();
is(Math.round(popuprect.left), triggerrect.left, testname + " x position ");
is(Math.round(popuprect.top), triggerrect.top, testname + " y position ");
}
},
{ {
// these tests check to ensure that the position attribute can be used // these tests check to ensure that the position attribute can be used
// to set the position of a popup instead of passing it as an argument // to set the position of a popup instead of passing it as an argument
@ -737,5 +671,6 @@ var popupTests = [
var popup = document.getElementById("thepopup"); var popup = document.getElementById("thepopup");
popup.parentNode.removeChild(popup); popup.parentNode.removeChild(popup);
} }
} },
]; ];

Просмотреть файл

@ -13,8 +13,8 @@
window.opener.SimpleTest.waitForFocus(runTests, window); window.opener.SimpleTest.waitForFocus(runTests, window);
</script> </script>
<hbox style="margin-left: 200px; margin-top: 310px;"> <hbox style="margin-left: 325px; margin-top: 325px;">
<label id="trigger" popup="thepopup" value="Popup" height="20"/> <label id="trigger" popup="thepopup" value="Popup"/>
</hbox> </hbox>
<menupopup id="thepopup"> <menupopup id="thepopup">

Просмотреть файл

@ -13,8 +13,8 @@
window.opener.SimpleTest.waitForFocus(runTests, window); window.opener.SimpleTest.waitForFocus(runTests, window);
</script> </script>
<hbox style="margin-left: 200px; margin-top: 310px;"> <hbox style="margin-left: 325px; margin-top: 325px;">
<button id="trigger" type="menu" label="Popup" width="100" height="20"> <button id="trigger" type="menu" label="Popup">
<menupopup id="thepopup"> <menupopup id="thepopup">
<menuitem id="item1" label="First"/> <menuitem id="item1" label="First"/>
<menuitem id="item2" label="Main Item"/> <menuitem id="item2" label="Main Item"/>