1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS Regions: document.elementFromPoint() for elements flowed into regions</title>
<link rel="author" title="Mihai Balan" href="mailto:mibalan@adobe.com">
<link rel="help" href="http://www.w3.org/TR/css3-regions/#the-flow-into-property">
<link rel="help" href="http://www.w3.org/TR/css3-regions/#flow-from">
<meta name="assert" content="document.elementFromPoint() should return the correct element when provided with coordinates of points corresponding to elements flowed into regions">
<meta name="flags" content="dom interact">
<style>
p {
margin: 0;
}
ol {
padding: 0;
margin: 0;
}
#content {
flow-into: f;
}
#region {
flow-from: f;
margin-left: 40px;
width: 200px;
height: 150px;
background-color: lightgray;
}
#region p {
font-weight: bold;
color: red;
}
</style>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="content">
</div>
<div id="region">
<p>FAIL</p>
</div>
<div id="log"></div>
<script type="text/javascript">
var testElements = [
{ tag: "p", content: "Some text here", description: "Block content" },
{ tag: "span", content: "Some text here", description: "Inline content", around: "mmm" },
{ tag: "img", description: "Replaced content", src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAT0lEQVR42u2WMQoAIAwD+/9Px9VFoUJNhjvoKDmKhVQBQA9tYw3/LiGngJwChBN+CtfjWMOvEp0HIwL2DUT8gYgrQAKJyD4Q0YgiOiHACAvTEtAwKdXD6AAAAABJRU5ErkJggg==", style: { width: "32px", height: "32px"} },
{ tag: "li", content: "Some text here", description: "Elements with parents", parent: "ol"},
{ tag: "foobar", content: "Some text here", description: "Unknown element type" },
{ tag: "div", content: "Floating content", description: "Floating content", style: { float: "right" } },
],
regionBox = document.querySelector("#region").getBoundingClientRect();
function insertElement(elem) {
var node, parent, content;
node = document.createElement(elem.tag);
node.appendChild(document.createTextNode(elem.content));
if (elem.parent) {
parent = document.createElement(elem.parent);
parent.appendChild(node);
}
if (elem.src) {
node.src = elem.src;
}
for (var prop in elem.style) {
node.style[prop] = elem.style[prop];
}
if (elem.around) {
content = elem.around + (parent ? parent.outerHTML : node.outerHTML) + elem.around;
} else {
content = (parent ? parent.outerHTML : node.outerHTML);
}
document.querySelector("#content").innerHTML = content;
}
function pointForElement(elem) {
var elemBox, result, aroundElem, aroundBox;
elemBox = document.querySelector("#content " + elem.tag).getBoundingClientRect();
result = {
top : regionBox.top + elemBox.height/2,
left : regionBox.left + elemBox.width/2
};
if (elem.around) {
aroundElem = document.createElement("span");
aroundElem.innerHTML = elem.around;
aroundElem.style.visibility = "hidden";
document.body.insertBefore(aroundElem, null);
document.body.offsetTop;
aroundBox = aroundElem.getBoundingClientRect();
document.body.removeChild(aroundElem);
result.left += aroundBox.width;
}
if (elem.style && elem.style.float == "right") {
result.left = regionBox.right - (aroundBox ? aroundBox.width : 0) - elemBox.width/2;
}
return result;
}
testElements.forEach(function(elem) {
test(function() {
var point, fromSelector;
insertElement(elem);
point = pointForElement(elem);
fromSelector = document.querySelector("#content " + elem.tag);
assert_equals(fromSelector, document.elementFromPoint(point.left, point.top));
}, elem.description)
});
</script>
</body>
</html>
|