diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/tests/mochitest/chrome/queryCaretRectWin.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/tests/mochitest/chrome/queryCaretRectWin.html | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/dom/tests/mochitest/chrome/queryCaretRectWin.html b/dom/tests/mochitest/chrome/queryCaretRectWin.html new file mode 100644 index 0000000000..27708aad58 --- /dev/null +++ b/dom/tests/mochitest/chrome/queryCaretRectWin.html @@ -0,0 +1,218 @@ +<!DOCTYPE HTML>
+<html>
+<head>
+<title>nsIDOMWindowUtils::sendQueryContentEvent w/QUERY_CARET_RECT test</title>
+<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+<!--
+ #########################################################
+ # WARNING: this file has Windows line endings. If you
+ # update this file please maintain them. Line endings are
+ # taken into account when calculating query caret rect
+ # values.
+ #########################################################
+-->
+
+<style>
+ #text {
+ position: absolute;
+ left: 0em;
+ top: 0em;
+ font-size: 10pt;
+ font-family: monospace;
+ line-height: 20px;
+ letter-spacing: 0px;
+ margin-top:-1px; /* nix the text area border */
+ overflow: hidden;
+ width:800px;
+ height:400px;
+ }
+ #div-hor {
+ position: absolute;
+ left: 0em;
+ border-top:1px solid lightgray;
+ width: 1000px;
+ pointer-events:none;
+ }
+ #div-ver {
+ position: absolute;
+ top: 0em;
+ border-left:1px solid lightgray;
+ height: 500px;
+ pointer-events:none;
+ }
+</style>
+
+<script type="application/javascript">
+ var SimpleTest = window.opener.SimpleTest;
+
+ function ok() { window.opener.ok.apply(window.opener, arguments); }
+ function done() { window.opener.done.apply(window.opener, arguments); }
+
+ function dumpLn() {
+ for (let idx = 0; idx < arguments.length; idx++)
+ dump(arguments[idx] + " ");
+ dump("\n");
+ }
+
+ // drawn grid is 20x20
+ function drawGrid() {
+ for (var idx = 0; idx < 20; idx++) {
+ var e = document.createElement("div");
+ e.setAttribute("id", "div-hor");
+ e.style.top = (idx*20) + "px";
+ document.getElementById("container").appendChild(e);
+ }
+ for (var idx = 0; idx < 40; idx++) {
+ var e = document.createElement("div");
+ e.setAttribute("id", "div-ver");
+ e.style.left = (idx*20) + "px";
+ document.getElementById("container").appendChild(e);
+ }
+ }
+
+ function getSelection(aElement) {
+ // aElement is know to be a textarea.
+ return aElement.editor.selection;
+ }
+
+ function testCaretPosition(aDomWinUtils, aOffset, aRectDims) {
+ let rect = aDomWinUtils.sendQueryContentEvent(
+ aDomWinUtils.QUERY_CARET_RECT,
+ aOffset, 0, 0, 0,
+ aDomWinUtils.QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK);
+ ok(rect, "rect returned");
+ ok(rect.succeeded, "call succeeded");
+
+ info("left:" + rect.left + " top:" + rect.top);
+
+ ok(rect.left > aRectDims.min.left, "rect.left > " + aRectDims.min.left);
+ ok(rect.left < aRectDims.max.left, "rect.left < " + aRectDims.max.left);
+ ok(rect.top > aRectDims.min.top, "rect.top > " + aRectDims.min.top);
+ ok(rect.top < aRectDims.max.top, "rect.top < " + aRectDims.max.top);
+ }
+
+ function doTest() {
+ let domWinUtils = window.windowUtils;
+
+ let text = document.getElementById("text");
+
+ text.focus();
+
+ let textrect = text.getBoundingClientRect();
+
+ let cp = document.caretPositionFromPoint(10, 395);
+ let input = cp.offsetNode;
+ let offset = cp.offset;
+ input.selectionStart = input.selectionEnd = offset;
+
+ let selection = getSelection(text);
+
+ testCaretPosition(domWinUtils, input.selectionStart, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, input.selectionEnd, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, text.selectionStart, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, text.selectionEnd, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, selection.anchorOffset, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, selection.focusOffset, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ cp = document.caretPositionFromPoint(395, 395);
+ input = cp.offsetNode;
+ offset = cp.offset;
+ input.selectionStart = input.selectionEnd = offset;
+
+ selection = getSelection(text);
+
+ testCaretPosition(domWinUtils, input.selectionStart, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, input.selectionEnd, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, text.selectionStart, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, text.selectionEnd, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, selection.anchorOffset, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, selection.focusOffset, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ done();
+ }
+
+</script>
+
+<body onload="doTest()">
+<textarea id="text" wrap="on">
+Alice was beginning to get very tired of sitting by her sister on the bank,
+and of having nothing to do: once or twice she had peeped into the book
+her sister was reading, but it had no pictures or conversations in it,
+`and what is the use of a book,' thought Alice `without pictures or
+conversation?'
+
+So she was considering in her own mind (as well as she could, for the
+hot day made her feel very sleepy and stupid), whether the pleasure of
+making a daisy-chain would be worth the trouble of getting up and
+picking the daisies, when suddenly a White Rabbit with pink In another
+moment down went Alice after it, never once considering how in the world
+she was to get out again.
+
+The rabbit-hole went straight on like a tunnel for some way, and then
+dipped suddenly down, so suddenly that Alice had not a moment to think
+about stopping herself before she found herself falling down a very deep
+well.
+
+Either the well was very deep, or she fell very slowly, for she had
+plenty of time as she went down to look about her and to wonder what was
+ going to happen next. First, she tried to look down and make out what
+she was coming to, but it was too dark to see anything; then she looked
+at the sides of the well, and noticed that they were filled with
+cupboards and book-shelves; here and there she saw maps and pictures
+hung upon pegs. She took down a jar from one of the shelves as she
+passed; it was labelled `ORANGE MARMALADE', but to her great
+disappointment it was empty: she did not like to drop the jar for fear
+of killing somebody, so managed to put it into one of the cupboards as
+she fell past it.
+</textarea>
+<div id="container"></div>
+</body>
+</html>
|