1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/chrome/queryCaretRectUnix.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,214 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 +<title>nsIDOMWindowUtils::sendQueryContentEvent w/QUERY_CARET_RECT test</title> 1.8 +<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.9 +<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 1.10 + 1.11 +<style> 1.12 + #text { 1.13 + position: absolute; 1.14 + left: 0em; 1.15 + top: 0em; 1.16 + font-size: 10pt; 1.17 + font-family: monospace; 1.18 + line-height: 20px; 1.19 + letter-spacing: 0px; 1.20 + margin-top:-1px; /* nix the text area border */ 1.21 + overflow: hidden; 1.22 + width:800px; 1.23 + height:400px; 1.24 + } 1.25 + #div-hor { 1.26 + position: absolute; 1.27 + left: 0em; 1.28 + border-top:1px solid lightgray; 1.29 + width: 1000px; 1.30 + pointer-events:none; 1.31 + } 1.32 + #div-ver { 1.33 + position: absolute; 1.34 + top: 0em; 1.35 + border-left:1px solid lightgray; 1.36 + height: 500px; 1.37 + pointer-events:none; 1.38 + } 1.39 +</style> 1.40 + 1.41 +<script type="application/javascript;version=1.8"> 1.42 + let SimpleTest = window.opener.SimpleTest; 1.43 + let Ci = Components.interfaces; 1.44 + 1.45 + function ok() { window.opener.ok.apply(window.opener, arguments); } 1.46 + function done() { window.opener.done.apply(window.opener, arguments); } 1.47 + 1.48 + function dumpLn() { 1.49 + for (let idx = 0; idx < arguments.length; idx++) 1.50 + dump(arguments[idx] + " "); 1.51 + dump("\n"); 1.52 + } 1.53 + 1.54 + // drawn grid is 20x20 1.55 + function drawGrid() { 1.56 + for (var idx = 0; idx < 20; idx++) { 1.57 + var e = document.createElement("div"); 1.58 + e.setAttribute("id", "div-hor"); 1.59 + e.style.top = (idx*20) + "px"; 1.60 + document.getElementById("container").appendChild(e); 1.61 + } 1.62 + for (var idx = 0; idx < 40; idx++) { 1.63 + var e = document.createElement("div"); 1.64 + e.setAttribute("id", "div-ver"); 1.65 + e.style.left = (idx*20) + "px"; 1.66 + document.getElementById("container").appendChild(e); 1.67 + } 1.68 + } 1.69 + 1.70 + function getSelection(aElement) { 1.71 + if (aElement instanceof Ci.nsIDOMNSEditableElement) { 1.72 + return aElement.QueryInterface(Ci.nsIDOMNSEditableElement) 1.73 + .editor.selection; 1.74 + } 1.75 + return null; 1.76 + } 1.77 + 1.78 + function testCaretPosition(aDomWinUtils, aOffset, aRectDims) { 1.79 + let rect = aDomWinUtils.sendQueryContentEvent( 1.80 + aDomWinUtils.QUERY_CARET_RECT, 1.81 + aOffset, 0, 0, 0, 1.82 + aDomWinUtils.QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK); 1.83 + ok(rect, "rect returned"); 1.84 + ok(rect.succeeded, "call succeeded"); 1.85 + 1.86 + info("left:" + rect.left + " top:" + rect.top); 1.87 + 1.88 + ok(rect.left > aRectDims.min.left, "rect.left > " + aRectDims.min.left); 1.89 + ok(rect.left < aRectDims.max.left, "rect.left < " + aRectDims.max.left); 1.90 + ok(rect.top > aRectDims.min.top, "rect.top > " + aRectDims.min.top); 1.91 + ok(rect.top < aRectDims.max.top, "rect.top < " + aRectDims.max.top); 1.92 + } 1.93 + 1.94 + function doTest() { 1.95 + let domWinUtils = window.QueryInterface(Ci.nsIInterfaceRequestor) 1.96 + .getInterface(Ci.nsIDOMWindowUtils); 1.97 + 1.98 + let text = document.getElementById("text"); 1.99 + 1.100 + text.focus(); 1.101 + 1.102 + let textrect = text.getBoundingClientRect(); 1.103 + 1.104 + let cp = document.caretPositionFromPoint(10, 395); 1.105 + let input = cp.offsetNode; 1.106 + let offset = cp.offset; 1.107 + input.selectionStart = input.selectionEnd = offset; 1.108 + 1.109 + let selection = getSelection(text); 1.110 + 1.111 + testCaretPosition(domWinUtils, input.selectionStart, { 1.112 + min: { left: 5, top: 380 }, 1.113 + max: { left: 25, top: 390 }, 1.114 + }); 1.115 + 1.116 + testCaretPosition(domWinUtils, input.selectionEnd, { 1.117 + min: { left: 5, top: 380 }, 1.118 + max: { left: 25, top: 390 }, 1.119 + }); 1.120 + 1.121 + testCaretPosition(domWinUtils, text.selectionStart, { 1.122 + min: { left: 5, top: 380 }, 1.123 + max: { left: 25, top: 390 }, 1.124 + }); 1.125 + 1.126 + testCaretPosition(domWinUtils, text.selectionEnd, { 1.127 + min: { left: 5, top: 380 }, 1.128 + max: { left: 25, top: 390 }, 1.129 + }); 1.130 + 1.131 + testCaretPosition(domWinUtils, selection.anchorOffset, { 1.132 + min: { left: 5, top: 380 }, 1.133 + max: { left: 25, top: 390 }, 1.134 + }); 1.135 + 1.136 + testCaretPosition(domWinUtils, selection.focusOffset, { 1.137 + min: { left: 5, top: 380 }, 1.138 + max: { left: 25, top: 390 }, 1.139 + }); 1.140 + 1.141 + cp = document.caretPositionFromPoint(395, 395); 1.142 + input = cp.offsetNode; 1.143 + offset = cp.offset; 1.144 + input.selectionStart = input.selectionEnd = offset; 1.145 + 1.146 + let selection = getSelection(text); 1.147 + 1.148 + testCaretPosition(domWinUtils, input.selectionStart, { 1.149 + min: { left: 390, top: 380 }, 1.150 + max: { left: 400, top: 390 }, 1.151 + }); 1.152 + 1.153 + testCaretPosition(domWinUtils, input.selectionEnd, { 1.154 + min: { left: 390, top: 380 }, 1.155 + max: { left: 400, top: 390 }, 1.156 + }); 1.157 + 1.158 + testCaretPosition(domWinUtils, text.selectionStart, { 1.159 + min: { left: 390, top: 380 }, 1.160 + max: { left: 400, top: 390 }, 1.161 + }); 1.162 + 1.163 + testCaretPosition(domWinUtils, text.selectionEnd, { 1.164 + min: { left: 390, top: 380 }, 1.165 + max: { left: 400, top: 390 }, 1.166 + }); 1.167 + 1.168 + testCaretPosition(domWinUtils, selection.anchorOffset, { 1.169 + min: { left: 390, top: 380 }, 1.170 + max: { left: 400, top: 390 }, 1.171 + }); 1.172 + 1.173 + testCaretPosition(domWinUtils, selection.focusOffset, { 1.174 + min: { left: 390, top: 380 }, 1.175 + max: { left: 400, top: 390 }, 1.176 + }); 1.177 + 1.178 + done(); 1.179 + } 1.180 + 1.181 +</script> 1.182 + 1.183 +<body onload="doTest()"> 1.184 +<textarea id="text" wrap="on"> 1.185 +Alice was beginning to get very tired of sitting by her sister on the bank, 1.186 +and of having nothing to do: once or twice she had peeped into the book 1.187 +her sister was reading, but it had no pictures or conversations in it, 1.188 +`and what is the use of a book,' thought Alice `without pictures or 1.189 +conversation?' 1.190 + 1.191 +So she was considering in her own mind (as well as she could, for the 1.192 +hot day made her feel very sleepy and stupid), whether the pleasure of 1.193 +making a daisy-chain would be worth the trouble of getting up and 1.194 +picking the daisies, when suddenly a White Rabbit with pink In another 1.195 +moment down went Alice after it, never once considering how in the world 1.196 +she was to get out again. 1.197 + 1.198 +The rabbit-hole went straight on like a tunnel for some way, and then 1.199 +dipped suddenly down, so suddenly that Alice had not a moment to think 1.200 +about stopping herself before she found herself falling down a very deep 1.201 +well. 1.202 + 1.203 +Either the well was very deep, or she fell very slowly, for she had 1.204 +plenty of time as she went down to look about her and to wonder what was 1.205 + going to happen next. First, she tried to look down and make out what 1.206 +she was coming to, but it was too dark to see anything; then she looked 1.207 +at the sides of the well, and noticed that they were filled with 1.208 +cupboards and book-shelves; here and there she saw maps and pictures 1.209 +hung upon pegs. She took down a jar from one of the shelves as she 1.210 +passed; it was labelled `ORANGE MARMALADE', but to her great 1.211 +disappointment it was empty: she did not like to drop the jar for fear 1.212 +of killing somebody, so managed to put it into one of the cupboards as 1.213 +she fell past it. 1.214 +</textarea> 1.215 +<div id="container"></div> 1.216 +</body> 1.217 +</html>