Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>nsIDOMWindowUtils::sendQueryContentEvent w/QUERY_CARET_RECT test</title> |
michael@0 | 5 | <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> |
michael@0 | 7 | |
michael@0 | 8 | <!-- |
michael@0 | 9 | ######################################################### |
michael@0 | 10 | # WARNING: this file has Windows line endings. If you |
michael@0 | 11 | # update this file please maintain them. Line endings are |
michael@0 | 12 | # taken into account when calculating query caret rect |
michael@0 | 13 | # values. |
michael@0 | 14 | ######################################################### |
michael@0 | 15 | --> |
michael@0 | 16 | |
michael@0 | 17 | <style> |
michael@0 | 18 | #text { |
michael@0 | 19 | position: absolute; |
michael@0 | 20 | left: 0em; |
michael@0 | 21 | top: 0em; |
michael@0 | 22 | font-size: 10pt; |
michael@0 | 23 | font-family: monospace; |
michael@0 | 24 | line-height: 20px; |
michael@0 | 25 | letter-spacing: 0px; |
michael@0 | 26 | margin-top:-1px; /* nix the text area border */ |
michael@0 | 27 | overflow: hidden; |
michael@0 | 28 | width:800px; |
michael@0 | 29 | height:400px; |
michael@0 | 30 | } |
michael@0 | 31 | #div-hor { |
michael@0 | 32 | position: absolute; |
michael@0 | 33 | left: 0em; |
michael@0 | 34 | border-top:1px solid lightgray; |
michael@0 | 35 | width: 1000px; |
michael@0 | 36 | pointer-events:none; |
michael@0 | 37 | } |
michael@0 | 38 | #div-ver { |
michael@0 | 39 | position: absolute; |
michael@0 | 40 | top: 0em; |
michael@0 | 41 | border-left:1px solid lightgray; |
michael@0 | 42 | height: 500px; |
michael@0 | 43 | pointer-events:none; |
michael@0 | 44 | } |
michael@0 | 45 | </style> |
michael@0 | 46 | |
michael@0 | 47 | <script type="application/javascript;version=1.8"> |
michael@0 | 48 | let SimpleTest = window.opener.SimpleTest; |
michael@0 | 49 | let Ci = Components.interfaces; |
michael@0 | 50 | |
michael@0 | 51 | function ok() { window.opener.ok.apply(window.opener, arguments); } |
michael@0 | 52 | function done() { window.opener.done.apply(window.opener, arguments); } |
michael@0 | 53 | |
michael@0 | 54 | function dumpLn() { |
michael@0 | 55 | for (let idx = 0; idx < arguments.length; idx++) |
michael@0 | 56 | dump(arguments[idx] + " "); |
michael@0 | 57 | dump("\n"); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | // drawn grid is 20x20 |
michael@0 | 61 | function drawGrid() { |
michael@0 | 62 | for (var idx = 0; idx < 20; idx++) { |
michael@0 | 63 | var e = document.createElement("div"); |
michael@0 | 64 | e.setAttribute("id", "div-hor"); |
michael@0 | 65 | e.style.top = (idx*20) + "px"; |
michael@0 | 66 | document.getElementById("container").appendChild(e); |
michael@0 | 67 | } |
michael@0 | 68 | for (var idx = 0; idx < 40; idx++) { |
michael@0 | 69 | var e = document.createElement("div"); |
michael@0 | 70 | e.setAttribute("id", "div-ver"); |
michael@0 | 71 | e.style.left = (idx*20) + "px"; |
michael@0 | 72 | document.getElementById("container").appendChild(e); |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function getSelection(aElement) { |
michael@0 | 77 | if (aElement instanceof Ci.nsIDOMNSEditableElement) { |
michael@0 | 78 | return aElement.QueryInterface(Ci.nsIDOMNSEditableElement) |
michael@0 | 79 | .editor.selection; |
michael@0 | 80 | } |
michael@0 | 81 | return null; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | function testCaretPosition(aDomWinUtils, aOffset, aRectDims) { |
michael@0 | 85 | let rect = aDomWinUtils.sendQueryContentEvent( |
michael@0 | 86 | aDomWinUtils.QUERY_CARET_RECT, |
michael@0 | 87 | aOffset, 0, 0, 0, |
michael@0 | 88 | aDomWinUtils.QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK); |
michael@0 | 89 | ok(rect, "rect returned"); |
michael@0 | 90 | ok(rect.succeeded, "call succeeded"); |
michael@0 | 91 | |
michael@0 | 92 | info("left:" + rect.left + " top:" + rect.top); |
michael@0 | 93 | |
michael@0 | 94 | ok(rect.left > aRectDims.min.left, "rect.left > " + aRectDims.min.left); |
michael@0 | 95 | ok(rect.left < aRectDims.max.left, "rect.left < " + aRectDims.max.left); |
michael@0 | 96 | ok(rect.top > aRectDims.min.top, "rect.top > " + aRectDims.min.top); |
michael@0 | 97 | ok(rect.top < aRectDims.max.top, "rect.top < " + aRectDims.max.top); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | function doTest() { |
michael@0 | 101 | let domWinUtils = window.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 102 | .getInterface(Ci.nsIDOMWindowUtils); |
michael@0 | 103 | |
michael@0 | 104 | let text = document.getElementById("text"); |
michael@0 | 105 | |
michael@0 | 106 | text.focus(); |
michael@0 | 107 | |
michael@0 | 108 | let textrect = text.getBoundingClientRect(); |
michael@0 | 109 | |
michael@0 | 110 | let cp = document.caretPositionFromPoint(10, 395); |
michael@0 | 111 | let input = cp.offsetNode; |
michael@0 | 112 | let offset = cp.offset; |
michael@0 | 113 | input.selectionStart = input.selectionEnd = offset; |
michael@0 | 114 | |
michael@0 | 115 | let selection = getSelection(text); |
michael@0 | 116 | |
michael@0 | 117 | testCaretPosition(domWinUtils, input.selectionStart, { |
michael@0 | 118 | min: { left: 10, top: 380 }, |
michael@0 | 119 | max: { left: 25, top: 390 }, |
michael@0 | 120 | }); |
michael@0 | 121 | |
michael@0 | 122 | testCaretPosition(domWinUtils, input.selectionEnd, { |
michael@0 | 123 | min: { left: 10, top: 380 }, |
michael@0 | 124 | max: { left: 25, top: 390 }, |
michael@0 | 125 | }); |
michael@0 | 126 | |
michael@0 | 127 | testCaretPosition(domWinUtils, text.selectionStart, { |
michael@0 | 128 | min: { left: 10, top: 380 }, |
michael@0 | 129 | max: { left: 25, top: 390 }, |
michael@0 | 130 | }); |
michael@0 | 131 | |
michael@0 | 132 | testCaretPosition(domWinUtils, text.selectionEnd, { |
michael@0 | 133 | min: { left: 10, top: 380 }, |
michael@0 | 134 | max: { left: 25, top: 390 }, |
michael@0 | 135 | }); |
michael@0 | 136 | |
michael@0 | 137 | testCaretPosition(domWinUtils, selection.anchorOffset, { |
michael@0 | 138 | min: { left: 10, top: 380 }, |
michael@0 | 139 | max: { left: 25, top: 390 }, |
michael@0 | 140 | }); |
michael@0 | 141 | |
michael@0 | 142 | testCaretPosition(domWinUtils, selection.focusOffset, { |
michael@0 | 143 | min: { left: 10, top: 380 }, |
michael@0 | 144 | max: { left: 25, top: 390 }, |
michael@0 | 145 | }); |
michael@0 | 146 | |
michael@0 | 147 | cp = document.caretPositionFromPoint(395, 395); |
michael@0 | 148 | input = cp.offsetNode; |
michael@0 | 149 | offset = cp.offset; |
michael@0 | 150 | input.selectionStart = input.selectionEnd = offset; |
michael@0 | 151 | |
michael@0 | 152 | let selection = getSelection(text); |
michael@0 | 153 | |
michael@0 | 154 | testCaretPosition(domWinUtils, input.selectionStart, { |
michael@0 | 155 | min: { left: 390, top: 380 }, |
michael@0 | 156 | max: { left: 400, top: 390 }, |
michael@0 | 157 | }); |
michael@0 | 158 | |
michael@0 | 159 | testCaretPosition(domWinUtils, input.selectionEnd, { |
michael@0 | 160 | min: { left: 390, top: 380 }, |
michael@0 | 161 | max: { left: 400, top: 390 }, |
michael@0 | 162 | }); |
michael@0 | 163 | |
michael@0 | 164 | testCaretPosition(domWinUtils, text.selectionStart, { |
michael@0 | 165 | min: { left: 390, top: 380 }, |
michael@0 | 166 | max: { left: 400, top: 390 }, |
michael@0 | 167 | }); |
michael@0 | 168 | |
michael@0 | 169 | testCaretPosition(domWinUtils, text.selectionEnd, { |
michael@0 | 170 | min: { left: 390, top: 380 }, |
michael@0 | 171 | max: { left: 400, top: 390 }, |
michael@0 | 172 | }); |
michael@0 | 173 | |
michael@0 | 174 | testCaretPosition(domWinUtils, selection.anchorOffset, { |
michael@0 | 175 | min: { left: 390, top: 380 }, |
michael@0 | 176 | max: { left: 400, top: 390 }, |
michael@0 | 177 | }); |
michael@0 | 178 | |
michael@0 | 179 | testCaretPosition(domWinUtils, selection.focusOffset, { |
michael@0 | 180 | min: { left: 390, top: 380 }, |
michael@0 | 181 | max: { left: 400, top: 390 }, |
michael@0 | 182 | }); |
michael@0 | 183 | |
michael@0 | 184 | done(); |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | </script> |
michael@0 | 188 | |
michael@0 | 189 | <body onload="doTest()"> |
michael@0 | 190 | <textarea id="text" wrap="on"> |
michael@0 | 191 | Alice was beginning to get very tired of sitting by her sister on the bank, |
michael@0 | 192 | and of having nothing to do: once or twice she had peeped into the book |
michael@0 | 193 | her sister was reading, but it had no pictures or conversations in it, |
michael@0 | 194 | `and what is the use of a book,' thought Alice `without pictures or |
michael@0 | 195 | conversation?' |
michael@0 | 196 | |
michael@0 | 197 | So she was considering in her own mind (as well as she could, for the |
michael@0 | 198 | hot day made her feel very sleepy and stupid), whether the pleasure of |
michael@0 | 199 | making a daisy-chain would be worth the trouble of getting up and |
michael@0 | 200 | picking the daisies, when suddenly a White Rabbit with pink In another |
michael@0 | 201 | moment down went Alice after it, never once considering how in the world |
michael@0 | 202 | she was to get out again. |
michael@0 | 203 | |
michael@0 | 204 | The rabbit-hole went straight on like a tunnel for some way, and then |
michael@0 | 205 | dipped suddenly down, so suddenly that Alice had not a moment to think |
michael@0 | 206 | about stopping herself before she found herself falling down a very deep |
michael@0 | 207 | well. |
michael@0 | 208 | |
michael@0 | 209 | Either the well was very deep, or she fell very slowly, for she had |
michael@0 | 210 | plenty of time as she went down to look about her and to wonder what was |
michael@0 | 211 | going to happen next. First, she tried to look down and make out what |
michael@0 | 212 | she was coming to, but it was too dark to see anything; then she looked |
michael@0 | 213 | at the sides of the well, and noticed that they were filled with |
michael@0 | 214 | cupboards and book-shelves; here and there she saw maps and pictures |
michael@0 | 215 | hung upon pegs. She took down a jar from one of the shelves as she |
michael@0 | 216 | passed; it was labelled `ORANGE MARMALADE', but to her great |
michael@0 | 217 | disappointment it was empty: she did not like to drop the jar for fear |
michael@0 | 218 | of killing somebody, so managed to put it into one of the cupboards as |
michael@0 | 219 | she fell past it. |
michael@0 | 220 | </textarea> |
michael@0 | 221 | <div id="container"></div> |
michael@0 | 222 | </body> |
michael@0 | 223 | </html> |