LayoutTests:
authoradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Apr 2006 02:06:51 +0000 (02:06 +0000)
committeradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Apr 2006 02:06:51 +0000 (02:06 +0000)
        - Tests for http://bugzilla.opendarwin.org/show_bug.cgi?id=8158
        REGRESSION: Clicking past RTL text in a new text field puts the caret on the wrong side of the text

        * editing/selection/caret-rtl-expected.checksum: Added.
        * editing/selection/caret-rtl-expected.png: Added.
        * editing/selection/caret-rtl-expected.txt: Added.
        * editing/selection/caret-rtl.html: Added.
        * editing/selection/caret-rtl-2-expected.checksum: Added.
        * editing/selection/caret-rtl-2-expected.png: Added.
        * editing/selection/caret-rtl-2-expected.txt: Added.
        * editing/selection/caret-rtl-2.html: Added.

WebCore:

        Reviewed by Justin.

        - Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=8158
        REGRESSION: Clicking past RTL text in a new text field puts the caret on the wrong side of the text

        Tests:
        editing/selection/caret-rtl.html
        editing/selection/caret-rtl-2.html

        * rendering/RenderText.cpp: (WebCore::RenderText::positionForCoordinates):
        When calculating the position for the beginning or end of an InlineTextBox,
        we now use offsetForPosition instead of just using m_start and m_len, because
        offsetForPosition will take rtl text into account.  I also made some formatting
        changes.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@13696 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/editing/selection/caret-rtl-2-expected.checksum [new file with mode: 0644]
LayoutTests/editing/selection/caret-rtl-2-expected.png [new file with mode: 0644]
LayoutTests/editing/selection/caret-rtl-2-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/caret-rtl-2.html [new file with mode: 0644]
LayoutTests/editing/selection/caret-rtl-expected.checksum [new file with mode: 0644]
LayoutTests/editing/selection/caret-rtl-expected.png [new file with mode: 0644]
LayoutTests/editing/selection/caret-rtl-expected.txt [new file with mode: 0644]
LayoutTests/editing/selection/caret-rtl.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/rendering/RenderText.cpp

index 1015d0f4041566b198f870e0777be53456f5800d..6bdd6706f426965839973483c3d46d4332f6c092 100644 (file)
@@ -1,3 +1,17 @@
+2006-04-04  Adele Peterson  <adele@apple.com>
+
+        - Tests for http://bugzilla.opendarwin.org/show_bug.cgi?id=8158
+        REGRESSION: Clicking past RTL text in a new text field puts the caret on the wrong side of the text
+
+        * editing/selection/caret-rtl-expected.checksum: Added.
+        * editing/selection/caret-rtl-expected.png: Added.
+        * editing/selection/caret-rtl-expected.txt: Added.
+        * editing/selection/caret-rtl.html: Added.
+        * editing/selection/caret-rtl-2-expected.checksum: Added.
+        * editing/selection/caret-rtl-2-expected.png: Added.
+        * editing/selection/caret-rtl-2-expected.txt: Added.
+        * editing/selection/caret-rtl-2.html: Added.
+
 2006-04-04  Adele Peterson  <adele@apple.com>
 
         New results for
diff --git a/LayoutTests/editing/selection/caret-rtl-2-expected.checksum b/LayoutTests/editing/selection/caret-rtl-2-expected.checksum
new file mode 100644 (file)
index 0000000..fb45e79
--- /dev/null
@@ -0,0 +1 @@
+0469b8fccf17f3df252e64a69b637346
\ No newline at end of file
diff --git a/LayoutTests/editing/selection/caret-rtl-2-expected.png b/LayoutTests/editing/selection/caret-rtl-2-expected.png
new file mode 100644 (file)
index 0000000..c77e7f0
Binary files /dev/null and b/LayoutTests/editing/selection/caret-rtl-2-expected.png differ
diff --git a/LayoutTests/editing/selection/caret-rtl-2-expected.txt b/LayoutTests/editing/selection/caret-rtl-2-expected.txt
new file mode 100644 (file)
index 0000000..9667709
--- /dev/null
@@ -0,0 +1,22 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of DIV > BODY > HTML > #document to 0 of DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x576
+      RenderBlock (anonymous) at (0,0) size 784x18
+        RenderText {TEXT} at (0,0) size 596x18
+          text run at (0,0) width 596: "This tests that clicking in a contenteditable div will set the caret in the right position for rtl text. "
+        RenderBR {BR} at (0,0) size 0x0
+      RenderBlock {P} at (0,34) size 784x18
+        RenderText {TEXT} at (0,0) size 649x18
+          text run at (0,0) width 200: "Click in the middle of the field. "
+          text run at (200,0) width 449: "The caret should be on the edge of the text closer to where you clicked."
+layer at (10,70) size 152x20
+  RenderBlock (positioned) {DIV} at (10,70) size 152x20 [border: (1px solid #000000)]
+    RenderText {TEXT} at (1,1) size 58x18
+      text run at (1,1) width 58 RTL: "\x{5E9}\x{5D3}\x{5D4} \x{5D1}\x{5D5}\x{5E8}"
+caret: position 0 of child 0 {TEXT} of child 5 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/selection/caret-rtl-2.html b/LayoutTests/editing/selection/caret-rtl-2.html
new file mode 100644 (file)
index 0000000..875efa6
--- /dev/null
@@ -0,0 +1,23 @@
+<html>
+<head>
+<script>
+function test()
+{    
+    if (window.layoutTestController) {
+        eventSender.mouseMoveTo(145, 75);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+    }
+}
+</script>
+</head>
+<body onload="test()">
+This tests that clicking in a contenteditable div will set the caret in the right position for rtl text.
+<br>
+<p>
+    Click in the middle of the field.  The caret should be on the edge of the text closer to where you clicked.
+</p>
+<div style="width:150px; border: solid thin black; position: absolute; top: 70; left: 10;" contenteditable>&#x05e9;&#x05d3;&#x05d4; &#x05d1;&#x05d5;&#x05e8;</div>
+</body>
+</html>
+
diff --git a/LayoutTests/editing/selection/caret-rtl-expected.checksum b/LayoutTests/editing/selection/caret-rtl-expected.checksum
new file mode 100644 (file)
index 0000000..0a77641
--- /dev/null
@@ -0,0 +1 @@
+cdd88ee6dd6cdd32a9d5e46847a641d6
\ No newline at end of file
diff --git a/LayoutTests/editing/selection/caret-rtl-expected.png b/LayoutTests/editing/selection/caret-rtl-expected.png
new file mode 100644 (file)
index 0000000..f671274
Binary files /dev/null and b/LayoutTests/editing/selection/caret-rtl-expected.png differ
diff --git a/LayoutTests/editing/selection/caret-rtl-expected.txt b/LayoutTests/editing/selection/caret-rtl-expected.txt
new file mode 100644 (file)
index 0000000..14e4300
--- /dev/null
@@ -0,0 +1,22 @@
+EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
+EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification
+EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 7 of #text > DIV > BODY > HTML > #document to 7 of #text > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x576
+      RenderBlock (anonymous) at (0,0) size 784x18
+        RenderText {TEXT} at (0,0) size 596x18
+          text run at (0,0) width 596: "This tests that clicking in a contenteditable div will set the caret in the right position for rtl text. "
+        RenderBR {BR} at (0,0) size 0x0
+      RenderBlock {P} at (0,34) size 784x18
+        RenderText {TEXT} at (0,0) size 649x18
+          text run at (0,0) width 200: "Click in the middle of the field. "
+          text run at (200,0) width 449: "The caret should be on the edge of the text closer to where you clicked."
+layer at (10,70) size 152x20
+  RenderBlock (positioned) {DIV} at (10,70) size 152x20 [border: (1px solid #000000)]
+    RenderText {TEXT} at (93,1) size 58x18
+      text run at (93,1) width 58 RTL: "\x{5E9}\x{5D3}\x{5D4} \x{5D1}\x{5D5}\x{5E8}"
+caret: position 7 of child 0 {TEXT} of child 5 {DIV} of child 1 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/editing/selection/caret-rtl.html b/LayoutTests/editing/selection/caret-rtl.html
new file mode 100644 (file)
index 0000000..0f6c9bf
--- /dev/null
@@ -0,0 +1,23 @@
+<html>
+<head>
+<script>
+function test()
+{    
+    if (window.layoutTestController) {
+        eventSender.mouseMoveTo(25, 75);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+    }
+}
+</script>
+</head>
+<body onload="test()">
+This tests that clicking in a contenteditable div will set the caret in the right position for rtl text.
+<br>
+<p>
+    Click in the middle of the field.  The caret should be on the edge of the text closer to where you clicked.
+</p>
+<div style="direction: rtl; width:150px; border: solid thin black; position: absolute; top: 70; left: 10;" contenteditable>&#x05e9;&#x05d3;&#x05d4; &#x05d1;&#x05d5;&#x05e8;</div>
+</body>
+</html>
+
index 7eb6dab87df180e31aa673d279fb6f04daf39322..8f4865612551dcb6d58d02ebd5069f2303d8f5b4 100644 (file)
@@ -1,3 +1,20 @@
+2006-04-04  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Justin.
+
+        - Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=8158
+        REGRESSION: Clicking past RTL text in a new text field puts the caret on the wrong side of the text
+
+        Tests:
+        editing/selection/caret-rtl.html
+        editing/selection/caret-rtl-2.html
+
+        * rendering/RenderText.cpp: (WebCore::RenderText::positionForCoordinates):
+        When calculating the position for the beginning or end of an InlineTextBox,
+        we now use offsetForPosition instead of just using m_start and m_len, because
+        offsetForPosition will take rtl text into account.  I also made some formatting
+        changes.
+
 2006-04-04  David Hyatt  <hyatt@apple.com>
 
         Fix for bug 8065, inline blocks incorrectly loses spaces between them.
index 5cb34e0abefd4f389ef3d30cc5ee64769e4877f0..7fc02408e29a6b4d370ef8dc5ddb672264618ed3 100644 (file)
@@ -253,38 +253,42 @@ VisiblePosition RenderText::positionForCoordinates(int _x, int _y)
     if (cb->hasOverflowClip())
         cb->layer()->subtractScrollOffset(absx, absy);
 
+    // Get the offset for the position, since this will take rtl text into account.
+    int offset;
+    
+    // FIXME: We should be able to roll these special cases into the general cases in the loop below.
     if (firstTextBox() && _y < absy + firstTextBox()->root()->bottomOverflow() && _x < absx + firstTextBox()->m_x) {
         // at the y coordinate of the first line or above
         // and the x coordinate is to the left than the first text box left edge
-        return VisiblePosition(element(), firstTextBox()->m_start, DOWNSTREAM);
+        offset = firstTextBox()->offsetForPosition(_x - absx);
+        return VisiblePosition(element(), offset + firstTextBox()->m_start, DOWNSTREAM);
     }
-
     if (lastTextBox() && _y >= absy + lastTextBox()->root()->topOverflow() && _x >= absx + lastTextBox()->m_x + lastTextBox()->m_width) {
         // at the y coordinate of the last line or below
         // and the x coordinate is to the right than the last text box right edge
-        return VisiblePosition(element(), lastTextBox()->m_start + lastTextBox()->m_len, DOWNSTREAM);
+        offset = lastTextBox()->offsetForPosition(_x - absx);
+        return VisiblePosition(element(), offset + lastTextBox()->m_start, DOWNSTREAM);
     }
 
     for (InlineTextBox *box = firstTextBox(); box; box = box->nextTextBox()) {
         if (_y >= absy + box->root()->topOverflow() && _y < absy + box->root()->bottomOverflow()) {
-            if (_x < absx + box->m_x + box->m_width) {
+            offset = box->offsetForPosition(_x - absx);
+
+            if (_x < absx + box->m_x + box->m_width)
                 // and the x coordinate is to the left of the right edge of this box
                 // check to see if position goes in this box
-                int offset = box->offsetForPosition(_x - absx);
-                if (offset != -1)
-                    return VisiblePosition(element(), offset + box->m_start, VP_UPSTREAM_IF_POSSIBLE);
-            }
-            else if (!box->prevOnLine() && _x < absx + box->m_x) {
+                return VisiblePosition(element(), offset + box->m_start, VP_UPSTREAM_IF_POSSIBLE);
+
+            if (!box->prevOnLine() && _x < absx + box->m_x)
                 // box is first on line
                 // and the x coordinate is to the left of the first text box left edge
-                return VisiblePosition(element(), box->m_start, DOWNSTREAM);
-            }
-            else if (!box->nextOnLine() && _x >= absx + box->m_x + box->m_width) {
+                return VisiblePosition(element(), offset + box->m_start, DOWNSTREAM);
+
+            if (!box->nextOnLine())
                 // box is last on line
                 // and the x coordinate is to the right of the last text box right edge
                 // generate VisiblePosition, use UPSTREAM affinity if possible
-                return VisiblePosition(element(), box->m_start + box->m_len, VP_UPSTREAM_IF_POSSIBLE);
-            }
+                return VisiblePosition(element(), offset + box->m_start, VP_UPSTREAM_IF_POSSIBLE);
         }
     }