12 <script src=
"../../resources/js-test.js"></script>
19 if (window
.testRunner
)
20 testRunner
.dumpAsText();
22 // The 2nd parameter 22 is the last character in textarea with id "textarea_rtl".
23 testCaretRect("textarea_rtl", 22, "rtl", "horizontal");
24 // 6 is the last character in textarea with id "textarea_ltr".
25 testCaretRect("textarea_ltr", 6, "ltr", "horizontal");
26 // 22 is the last character in "vertical_rl" div.
27 testCaretRect("vertical_rl", 22, "rtl", "vertical");
35 e
.style
.fontFamily
= "sans-serif";
36 e
.style
.fontSize
= 10 + "px";
39 function testCaretRect(id
, characterIndex
, direction
, writingMode
)
41 var e
= document
.getElementById("span_" + id
);
45 if (writingMode
== "horizontal")
46 length
= e
.offsetWidth
;
48 length
= e
.offsetHeight
;
50 e
.style
.visibility
= "hidden";
52 testCaretRectInTextArea(id
, length
, characterIndex
, direction
, writingMode
);
53 testCaretRectInTextArea(id
+ "_no_wrap", length
, characterIndex
, direction
, writingMode
);
56 function testCaretRectInTextArea(id
, length
, characterIndex
, direction
, writingMode
)
58 e
= document
.getElementById(id
);
64 var originalLength
= length
;
65 if (id
.match("_no_wrap"))
66 length
= parseInt(length
* 0.9);
68 if (writingMode
== "horizontal")
69 e
.style
.width
= length
+ "px";
71 e
.style
.height
= length
+ "px";
75 if (window
.textInputController
) {
76 var first
= caretRectForCharacter(0, writingMode
);
77 var last
= caretRectForCharacter(characterIndex
, writingMode
);
80 if (direction
== "rtl")
81 caretRange
= first
- last
;
83 caretRange
= last
- first
;
84 caretRange
= Math
.abs(caretRange
);
86 if (caretRange
!= originalLength
- 1) {
89 testFailed("test id: " + id
+ " (text width: " + originalLength
+ " != caretRange: " + caretRange
+ ")," +
90 " which means moving caret in the text, caret might be invisible or overlap with element.");
93 e
.style
.visibility
= "hidden";
97 function caretRectForCharacter(characterIndex
, writingMode
)
99 var caretRect
= textInputController
.firstRectForCharacterRange(characterIndex
, 0);
100 if (writingMode
== "horizontal")
108 <!-- Following <div>/<span> is for width calculation -->
109 <div class=
"editable"><span id=
"span_textarea_rtl" class=
"editable" dir=
"rtl">דגלחכ גדכ לחידגכ יחעדד</span></div>
111 <p>autowrap text area with dir=rtl.
112 <textarea id=
"textarea_rtl" style=
"font-size:10px;" dir=
"rtl">דגלחכ גדכ לחידגכ יחעדד</textarea>
114 <p>nowrap text area with dir=rtl.
115 <!-- caret position overlaps with character (http://webkit.org/b/56854) -->
116 <textarea id=
"textarea_rtl_no_wrap" style=
"white-space:nowrap; font-size: 10px" dir=
"rtl">דגלחכ גדכ לחידגכ יחעדד</textarea>
118 <!-- Following <div>/<span> is for width calculation -->
119 <div class=
"editable"><pre class=
"editable"><span id=
"span_textarea_ltr" class=
"editable">www
</span></pre></div>
121 <p>autowrap text area with dir=ltr.
122 <textarea id=
"textarea_ltr" style=
"font-size:10px">www
</textarea>
124 <!-- Following <div>/<span> is for width calculation -->
125 <div style=
"-webkit-writing-mode:vertical-rl;" class=
"editable"><span id=
"span_vertical_rl" class=
"editable">דגלחכ גדכ לחידגכ יחעדד</span></div>
128 <div contenteditable
id=
"vertical_rl" style=
"-webkit-writing-mode:vertical-rl;" class=
"editable">דגלחכ גדכ לחידגכ יחעדד</div>
130 <ul id=
"console"></ul>
133 <script>runTest();</script>