5 This tests that clicking in a contenteditable div will set the caret in the right position for LTR/RTL text in a RTL/LTR block.
8 <dt>Clicking the first letter of RTL text in a LTR block
</dt>
9 <dd><div id=
"rtl-in-ltr-first" style=
"font-size: 70px; width: 20ex; border: solid thin black; padding: 10px;" contenteditable
>שדה בור</div></dd>
10 <dt>Clicking the last letter of RTL text in a LTR block
</dt>
11 <dd><div id=
"rtl-in-ltr-last" style=
"font-size: 70px; width: 20ex; border: solid thin black; padding: 10px;" contenteditable
>שדה בור</div></dd>
12 <dt>Clicking the first letter of LTR text in a RTL block
</dt>
13 <dd><div id=
"ltr-in-rtl-first" style=
"direction: rtl; font-size: 70px; width: 20ex; border: solid thin black; padding: 10px;" contenteditable
>WebKitW
</div></dd>
14 <dt>Clicking the last letter of LTR text in a RTL block
</dt>
15 <dd><div id=
"ltr-in-rtl-last" style=
"direction: rtl; font-size: 70px; width: 20ex; border: solid thin black; padding: 10px;" contenteditable
>WebKitW
</div></dd>
17 <script src=
"resources/caret-edge-shared.js"></script>
20 if (window
.testRunner
)
21 testRunner
.dumpAsText();
23 function runTest(div
, clickOn
, expectedOffset
) {
24 var elementToCalulateTextWidth
= document
.createElement('span');
25 elementToCalulateTextWidth
.appendChild(div
.firstChild
.cloneNode());
26 document
.body
.appendChild(elementToCalulateTextWidth
);
27 elementToCalulateTextWidth
.style
.fontSize
= '70px';
29 var inRTLBlock
= div
.style
.direction
== 'rtl';
31 if ((!inRTLBlock
&& clickOn
== 'last') || (inRTLBlock
&& clickOn
== 'first'))
32 x
= elementToCalulateTextWidth
.offsetWidth
;
34 x
= div
.offsetWidth
- x
;
36 document
.body
.removeChild(elementToCalulateTextWidth
);
38 var verify = function() {
39 if (!window
.getSelection().isCollapsed
)
40 return log(div
, 'FAIL: selection not collapsed');
42 var range
= window
.getSelection().getRangeAt(0);
43 if (range
.startContainer
!= div
.firstChild
)
44 return log(div
, 'FAIL: wrong container');
45 if (range
.startOffset
!= expectedOffset
)
46 return log(div
, 'FAIL: wrong offset ' + range
.startOffset
+ ', expected ' + expectedOffset
);
48 return log(div
, 'PASS');
51 if (!window
.testRunner
) {
52 div
.addEventListener('mouseup', verify
);
56 eventSender
.mouseMoveTo(div
.offsetLeft
+ x
, div
.offsetTop
+ div
.offsetHeight
/ 2);
57 eventSender
.leapForward(200);
58 eventSender
.mouseDown();
59 eventSender
.leapForward(200);
60 eventSender
.mouseUp();
61 verify({target
: div
});
64 function log(div
, message
) {
65 div
.innerHTML
= message
;
68 runTest(document
.getElementById('rtl-in-ltr-first'), 'first', 0);
69 runTest(document
.getElementById('rtl-in-ltr-last'), 'last', 7);
70 runTest(document
.getElementById('ltr-in-rtl-first'), 'first', 7);
71 runTest(document
.getElementById('ltr-in-rtl-last'), 'last', 0);