<!DOCTYPEHTML>
<title>nsIDOMWindowUtils::nodesFromRect test - bug 489127</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script> var SimpleTest = window.opener.SimpleTest;
function ok() { window.opener.ok.apply(window.opener, arguments); }
function done() { window.opener.done.apply(window.opener, arguments); }
function info() { window.opener.info.apply(window.opener, arguments); }
let e = {};
let dwu = window.windowUtils;
function check(x, y, top, right, bottom, left, onlyVisible, list, aListIsComplete = false, aOpacityThreshold = 1.0) {
let nodes = dwu.nodesFromRect(x, y, top, right, bottom, left, /* aIgnoreRootScrollFrame = */ true, /* aFlushLayout = */ true, onlyVisible, aOpacityThreshold);
if (!aListIsComplete) {
list.push(e.body);
list.push(e.html);
}
if (nodes.length != list.length) {
ok(false, "Different number of nodes (" + nodes.length + " vs. " + list.length + ") for rect [" + x + "," + y + "], " + "[" + top + "," + right + "," + bottom + "," + left + "]");
return;
}
for (var i = 0; i < nodes.length; i++) {
if (nodes[i] != list[i]) {
ok(false, `Unexpected node #${i} (${nodes[i].id} vs. ${list[i].id}) ` +
`[${x}, ${y}] [${top}, ${right}, ${bottom}, ${left}]`);
return;
}
}
ok(true, "All correct nodes found for rect " + "[" + x + "," + y + "], " + "[" + top + "," + right + "," + bottom + "," + left + "]");
}
function doTest() {
// Set up shortcut access to elements
e.html = document.documentElement;
['h1', 'd1', 'd2', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'span', 'a1', 'a2', 'a3', 'transf', 'iframe1', 'body', 'opacity', 'host'].forEach(function(a) {
e[a] = document.getElementById(a);
});
// Elements inside iframe shouldn't be returned:
check(15, 410, 0, 30, 50, 0, false, [e.iframe1]);
// Area with links and text nodes:
let [x1, y1] = getCenterFor(e.a1);
let [x2, y2] = getCenterFor(e.a2);
let [x3, y3] = getCenterFor(e.a3);
let [xt, yt] = [(x2 + x1) / 2, y1]; //text node between a1 and a2
{
info("opacity: with and without aVisibleOnly = true");
let [x, y] = getCenterFor(e.opacity);
check(x, y, 1, 1, 1, 1, false, [e.opacity]);
check(x, y, 1, 1, 1, 1, true, []);
}
// Check elements behind opaque backgrounds of other elements don't show up
// in the list when aVisibleOnly = true.
{
info("elements behind opaque backgrounds of other elements with aVisibleOnly=true");
let container = document.getElementById('obscured-test');
let fg = document.getElementById('obscured-test-foreground');
let bg = document.getElementById('obscured-test-background');
let [x, y] = getCenterFor(container);
check(x, y, 1, 1, 1, 1, false, [fg, bg, container]);
const kListIsComplete = true;
check(x, y, 1, 1, 1, 1, true, [fg], kListIsComplete);
check(x, y, 1, 1, 1, 1, true, [fg], kListIsComplete, 0.5);
info("Occluded with different opacity thresholds, with background colors and opacity");
fg.style.backgroundColor = "rgba(0, 255, 0, 0.5)";
check(x, y, 1, 1, 1, 1, true, [fg], kListIsComplete, 0.4);
check(x, y, 1, 1, 1, 1, true, [fg, bg], kListIsComplete, 0.6);
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.