- fixed text box search code for caret rect to properly account for BIDI text (4038674)
authorkali <kali@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 Mar 2005 22:33:02 +0000 (22:33 +0000)
committerkali <kali@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 6 Mar 2005 22:33:02 +0000 (22:33 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8802 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/rendering/render_text.cpp

index af0149a51d32a787017458c4e7c46a25fcf4bba6..5d6088ab32c36b44f71d5978ef571085d96a75d1 100644 (file)
@@ -1,3 +1,11 @@
+2005-03-06  Christy Warren  kali@appple.com
+
+        Reviewed by Ken
+
+        * khtml/rendering/render_text.cpp:
+        (lastRendererOnPrevLine): helper for RenderText::caretRect
+        (RenderText::caretRect): added code to properly handle bidi ordered text boxes
+
 2005-03-06  Christy Warren  <set EMAIL_ADDRESS environment variable>
 
         Reviewed by Darin.
index 80c248b9cac73560899af3db75f50fda56525b96..9f35319047d78410a5f1e8580d6f52bbeb627945 100644 (file)
@@ -986,6 +986,29 @@ static RenderObject *firstRendererOnNextLine(InlineBox *box)
     return firstChild->object();
 }
 
+static RenderObject *lastRendererOnPrevLine(InlineBox *box)
+{
+    if (!box)
+        return 0;
+    
+    RootInlineBox *root = box->root();
+    if (!root)
+        return 0;
+    
+    if (root->endsWithBreak())
+        return 0;
+    
+    RootInlineBox *prevRoot = root->prevRootBox();
+    if (!prevRoot)
+        return 0;
+    
+    InlineBox *lastChild = prevRoot->lastChild();
+    if (!lastChild)
+        return 0;
+    
+    return lastChild->object();
+}
+
 QRect RenderText::caretRect(int offset, EAffinity affinity, int *extraWidthToEndOfLine)
 {
     if (!firstTextBox() || stringLength() == 0) {
@@ -995,24 +1018,35 @@ QRect RenderText::caretRect(int offset, EAffinity affinity, int *extraWidthToEnd
     // Find the text box for the given offset
     InlineTextBox *box = 0;
     for (box = firstTextBox(); box; box = box->nextTextBox()) {
-        if (offset <= box->m_start + box->m_len) {
+        if ((offset >= box->m_start) && (offset <= box->m_start + box->m_len)) {
             // Check if downstream affinity would make us move to the next line.
             InlineTextBox *nextBox = box->nextTextBox();
-            if (affinity == DOWNSTREAM && nextBox && !box->nextOnLine() && offset == box->m_start + box->m_len) {
+            if (offset == box->m_start + box->m_len && affinity == DOWNSTREAM  && nextBox &&  !box->nextOnLine()) {
                 // We're at the end of a line broken on a word boundary and affinity is downstream.
                 // Try to jump down to the next line.
                 if (nextBox) {
                     // Use the next text box
                     box = nextBox;
                     offset = box->m_start;
-                }
-                else {
+                } else {
                     // Look on the next line
                     RenderObject *object = firstRendererOnNextLine(box);
                     if (object)
                         return object->caretRect(0, affinity);
                 }
-            }
+            } else {
+               InlineTextBox *prevBox = box->prevTextBox();
+               if (offset == box->m_start && affinity == UPSTREAM && prevBox && !box->prevOnLine()) {
+                   if (prevBox) {
+                       box = prevBox;
+                       offset = box->m_start + box->m_len;
+                   } else {
+                       RenderObject *object = lastRendererOnPrevLine(box);
+                       if (object)
+                           return object->caretRect(0, affinity);
+                   }
+               }
+           }
             break;
         }
     }