forked from mirrors/gecko-dev
Instead of using a framescript, change promiseFocus to use the SpecialPowers actor. In addition, promiseFocus may now take a browsing context to focus a specific subframe's window. If that subframe is deeply nested, messages will be passed back and forth between the parent and each successive subframe to get to the one subframe that is desired to be focused. Similarly, this process is used when focusing a higher level frame that already has its focused element set to a subframe. Differential Revision: https://phabricator.services.mozilla.com/D116387
190 lines
8.1 KiB
HTML
190 lines
8.1 KiB
HTML
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
align="start">
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
|
|
<script><![CDATA[
|
|
var is = window.arguments[0].SimpleTest.is;
|
|
window.onerror = window.arguments[0].onerror;
|
|
|
|
const anchorPositions =
|
|
[ "before_start", "before_end", "after_start", "after_end",
|
|
"start_before", "start_after", "end_before", "end_after", "overlap", "screen"];
|
|
var currentPosition;
|
|
|
|
function testResizer(resizerid, noShrink, hResize, vResize, testid)
|
|
{
|
|
var rect = document.getElementById(resizerid + "-container").getBoundingClientRect();
|
|
var resizer = document.getElementById(resizerid);
|
|
var resizerrect = resizer.getBoundingClientRect();
|
|
|
|
var originalX = resizerrect.left;
|
|
var originalY = resizerrect.top;
|
|
|
|
const scale = 20;
|
|
for (var mouseX = -1; mouseX <= 1; ++mouseX) {
|
|
for (var mouseY = -1; mouseY <= 1; ++mouseY) {
|
|
var expectedWidth = rect.width + hResize * mouseX * scale;
|
|
var expectedHeight = rect.height + vResize * mouseY * scale;
|
|
|
|
if (noShrink) {
|
|
if (mouseX == -1)
|
|
expectedWidth = rect.width;
|
|
if (mouseY == -1)
|
|
expectedHeight = rect.height;
|
|
}
|
|
|
|
synthesizeMouse(document.documentElement, originalX + 5, originalY + 5, { type:"mousedown" });
|
|
synthesizeMouse(document.documentElement, originalX + 5 + mouseX * scale,
|
|
originalY + 5 + mouseY * scale, { type:"mousemove" });
|
|
|
|
var newrect = document.getElementById(resizerid + "-container").getBoundingClientRect();
|
|
is(Math.round(newrect.width), Math.round(expectedWidth), "resize element " + resizerid +
|
|
" " + testid + " width moving " + mouseX + "," + mouseY + ",,," + hResize);
|
|
is(Math.round(newrect.height), Math.round(expectedHeight), "resize element " + resizerid +
|
|
" " + testid + " height moving " + mouseX + "," + mouseY);
|
|
// release
|
|
synthesizeMouse(document.documentElement, originalX + 5 + mouseX * scale,
|
|
originalY + 5 + mouseY * scale, { type:"mouseup" });
|
|
// return to the original size
|
|
synthesizeMouse(document.documentElement, originalX + 5 + mouseX * scale,
|
|
originalY + 5 + mouseY * scale, { type:"dblclick" });
|
|
var newrect = document.getElementById(resizerid + "-container").getBoundingClientRect();
|
|
is(Math.round(newrect.width), Math.round(rect.width), "resize element " + resizerid +
|
|
" " + testid + " doubleclicking to restore original size");
|
|
is(Math.round(newrect.height), Math.round(rect.height), "resize element " + resizerid +
|
|
" " + testid + " doubleclicking to restore original size");
|
|
}
|
|
}
|
|
}
|
|
|
|
function doTest() {
|
|
// first, check if a resizer with a element attribute set to an element that
|
|
// does not exist does not cause a problem
|
|
var resizer = document.getElementById("notfound");
|
|
synthesizeMouse(resizer, 5, 5, { type:"mousedown" });
|
|
synthesizeMouse(resizer, 10, 10, { type:"mousemove" });
|
|
synthesizeMouse(resizer, 5, 5, { type:"mouseup" });
|
|
|
|
testResizer("outside", true, 1, 1, "");
|
|
testResizer("html", true, 1, 1, "");
|
|
testResizer("inside", true, 1, 1, "");
|
|
testResizer("inside-large", false, 1, 1, "");
|
|
testResizer("inside-with-border", true, 1, 1, "");
|
|
|
|
document.getElementById("inside-popup-container").
|
|
openPopupAtScreen(Math.ceil(window.mozInnerScreenX) + 100, Math.ceil(window.mozInnerScreenY) + 100);
|
|
}
|
|
|
|
function popupShown(event)
|
|
{
|
|
testResizer("inside-popup", false, 1, 1, "");
|
|
document.getElementById("inside-popup-container").id = "outside-popup-container";
|
|
testResizer("outside-popup", false, 1, 1, "");
|
|
|
|
var resizerrect = document.getElementById("inside-popup").getBoundingClientRect();
|
|
synthesizeMouse(document.documentElement, resizerrect.left + 5, resizerrect.top + 5, { type:"mousedown" });
|
|
synthesizeMouse(document.documentElement, resizerrect.left + 2000, resizerrect.top + 2000, { type:"mousemove" });
|
|
|
|
var isMac = (navigator.platform.includes("Mac"));
|
|
var popuprect = document.getElementById("outside-popup-container").getBoundingClientRect();
|
|
// subtract 3 due to space left for panel dropshadow
|
|
is(Math.ceil(window.mozInnerScreenX) + popuprect.right,
|
|
(isMac ? screen.availLeft + screen.availWidth : screen.left + screen.width) - 3, "resized to edge width");
|
|
is(Math.ceil(window.mozInnerScreenY) + popuprect.bottom,
|
|
(isMac ? screen.availTop + screen.availHeight : screen.top + screen.height) - 3, "resized to edge height");
|
|
|
|
resizerrect = document.getElementById("inside-popup").getBoundingClientRect();
|
|
synthesizeMouse(document.documentElement, resizerrect.left + 5, resizerrect.top + 5, { type:"mouseup" });
|
|
|
|
event.target.hidePopup();
|
|
}
|
|
|
|
function popupHidden()
|
|
{
|
|
if (anchorPositions.length == 0) {
|
|
window.close();
|
|
window.arguments[0].SimpleTest.finish();
|
|
return;
|
|
}
|
|
|
|
currentPosition = anchorPositions.shift();
|
|
var anchor = document.getElementById("anchor");
|
|
var popup = document.getElementById("anchored-panel-container");
|
|
|
|
if (currentPosition == "screen")
|
|
popup.openPopupAtScreen(window.screenX + 100, window.screenY + 100);
|
|
else
|
|
popup.openPopup(anchor, currentPosition);
|
|
}
|
|
|
|
function anchoredPopupShown(event)
|
|
{
|
|
var leftAllowed = (!currentPosition.includes("end_") && !currentPosition.includes("_start"));
|
|
var rightAllowed = (!currentPosition.includes("start_") && !currentPosition.includes("_end"));
|
|
var topAllowed = (!currentPosition.includes("after_") && !currentPosition.includes("_before"));
|
|
var bottomAllowed = (!currentPosition.includes("before_") && !currentPosition.includes("_after"));
|
|
|
|
if (currentPosition == "overlap") {
|
|
leftAllowed = topAllowed = false;
|
|
rightAllowed = bottomAllowed = true;
|
|
}
|
|
|
|
var resizerTypes = [ "topleft", "top", "topright", "left", "right",
|
|
"bottomleft", "bottom", "bottomright", "bottomend" ];
|
|
for (var r = 0; r < resizerTypes.length; r++) {
|
|
var resizerType = resizerTypes[r];
|
|
var horiz = 0, vert = 0;
|
|
if (leftAllowed && resizerType.includes("left")) horiz = -1;
|
|
else if (rightAllowed && (resizerType.includes("right") || resizerType == "bottomend")) horiz = 1;
|
|
|
|
if (topAllowed && resizerType.includes("top")) vert = -1;
|
|
else if (bottomAllowed && resizerType.includes("bottom")) vert = 1;
|
|
|
|
document.getElementById("anchored-panel").dir = resizerType;
|
|
testResizer("anchored-panel", false, horiz, vert, currentPosition + " " + resizerType);
|
|
}
|
|
|
|
event.target.hidePopup();
|
|
}
|
|
|
|
SimpleTest.executeSoon(() => {
|
|
window.arguments[0].SimpleTest.waitForFocus(doTest, window);
|
|
});
|
|
]]></script>
|
|
|
|
<resizer id="outside" dir="bottomend" element="outside-container"/>
|
|
<resizer id="notfound" dir="bottomend" element="nothing"/>
|
|
<hbox id="outside-container">
|
|
<hbox minwidth="46" minheight="39"/>
|
|
</hbox>
|
|
<html:div id="html-container" xmlns:html="http://www.w3.org/1999/xhtml">
|
|
<html:button>One</html:button><html:br/>
|
|
<resizer id="html" dir="bottomend" element="_parent"/>
|
|
</html:div>
|
|
<hbox id="anchor" align="start" style="margin-left: 100px;">
|
|
<hbox id="inside-container" align="start">
|
|
<hbox minwidth="45" minheight="41"/>
|
|
<resizer id="inside" dir="bottomend" element="_parent"/>
|
|
</hbox>
|
|
<hbox id="inside-large-container" width="70" height="70" align="start">
|
|
<resizer id="inside-large" dir="bottomend" element="_parent"/>
|
|
</hbox>
|
|
<hbox id="inside-with-border-container" style="border: 5px solid red; padding: 2px; margin: 2px;" align="start">
|
|
<hbox minwidth="35" minheight="30"/>
|
|
<resizer id="inside-with-border" dir="bottomend" element="_parent"/>
|
|
</hbox>
|
|
</hbox>
|
|
|
|
<panel id="inside-popup-container" align="start" onpopupshown="popupShown(event)" onpopuphidden="popupHidden()">
|
|
<resizer id="inside-popup" dir="bottomend"/>
|
|
<hbox width="50" height="50" flex="1"/>
|
|
</panel>
|
|
<resizer id="outside-popup" dir="bottomend" element="outside-popup-container"/>
|
|
|
|
<panel id="anchored-panel-container" align="start" onpopupshown="anchoredPopupShown(event)"
|
|
onpopuphidden="popupHidden()">
|
|
<hbox width="50" height="50" flex="1"/>
|
|
<resizer id="anchored-panel" width="20" height="20"/>
|
|
</panel>
|
|
|
|
</window>
|