</head> <!-- Elements are styled in such a way that they don't overlap visually unless they also overlap structurally.
This file is designed to be opened from test_bug199692.html in a popup window, to guarantee that the window in which document.elementFromPoint runs is large enough to display all the elements being tested.
-->
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=199692">Mozilla Bug 199692</a>
var SimpleTest = window.opener.SimpleTest;
function ok() { window.opener.ok.apply(window.opener, arguments); }
function is() { window.opener.is.apply(window.opener, arguments); }
function todo() { window.opener.todo.apply(window.opener, arguments); }
function todo_is() { window.opener.todo_is.apply(window.opener, arguments); }
function $(id) { return document.getElementById(id); }
/**
* Like is, but for tests which don't always succeed or always fail on all
* platforms.
*/
function random_fail(a, b, m)
{
if (a != b)
todo_is(a, b, m);
else
is(a, b, m);
}
/* Test for Bug 199692 */
function getCoords(elt)
{ var x = 0, y = 0;
do
{
x += elt.offsetLeft;
y += elt.offsetTop;
} while ((elt = elt.offsetParent));
function testPoints()
{
ok('elementFromPoint' in document, "document.elementFromPoint must exist");
ok(typeof document.elementFromPoint === "function", "must be a function");
var doc = document;
doc.pt = doc.elementFromPoint; // for shorter lines
is(doc.pt(-1, 0), null, "Negative coordinates (-1, 0) should return null");
is(doc.pt(0, -1), null, "Negative coordinates (0, -1) should return null");
is(doc.pt(-1, -1), null, "Negative coordinates (-1, -1) should return null");
var pos;
for (var i = 0; i < elts.length; i++)
{ var id = elts[i]; var elt = $(id);
// The upper left corner of an element (with a moderate offset) will
// usually contain text, and the lower right corner usually won't. var pos = getCoords(elt); var x = pos.x, y = pos.y; var w = elt.offsetWidth, h = elt.offsetHeight;
var d = 5;
is(doc.pt(x + d, y + d), elt, "(" + (x + d) + "," + (y + d) + ") IDs should match (upper left " + "corner of " + id + ")");
is(doc.pt(x + w - d, y + h - d), elt, "(" + (x + w - d) + "," + (y + h - d) + ") IDs should match (lower " + "right corner of " + id + ")");
}
// content var c = $("content");
pos = getCoords(c);
x = pos.x + c.offsetWidth / 2;
y = pos.y;
// This fails on some platforms but not others for unknown reasons
random_fail(doc.pt(x, y), c, "Point to right of #txt should be #content");
is(doc.pt(x, y + 1), c, "Point to right of #txt should be #content");
random_fail(doc.pt(x + 1, y), c, "Point to right of #txt should be #content");
is(doc.pt(x + 1, y + 1), c, "Point to right of #txt should be #content");
// hidden
c = $("hidden");
pos = getCoords(c);
x = pos.x;
y = pos.y;
is(doc.pt(x, y), $("hidden-wrapper"), "Hit testing should bypass hidden elements.");
// iframe nested variframe = $("our-iframe");
pos = getCoords(iframe);
x = pos.x;
y = pos.y;
is(doc.pt(x + 20, y + 20), $("our-iframe"), "Element from nested iframe returned is from calling document");
// iframe, doubly nested
is(doc.pt(x + 60, y + 60), $("our-iframe"), "Element from doubly nested iframe returned is from calling document");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.