tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

queryCaretRectUnix.html (6523B)


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