2011-01-27 Mario Sanchez Prada <msanchez@igalia.com>
authormario@webkit.org <mario@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Jan 2011 19:38:03 +0000 (19:38 +0000)
committermario@webkit.org <mario@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Jan 2011 19:38:03 +0000 (19:38 +0000)
        Reviewed by Martin Robinson.

        [GTK] Space characters in source document interfere with reported caret offset
        https://bugs.webkit.org/show_bug.cgi?id=53033

        Calculate caret offset from rendered text instead of from node contents.

        * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
        (objectAndOffsetUnignored): Calculate the caret offset based only
        on positions and ranges, instead of using the computed offset in
        the container node.
2011-01-27  Mario Sanchez Prada  <msanchez@igalia.com>

        Reviewed by Martin Robinson.

        [GTK] Space characters in source document interfere with reported caret offset
        https://bugs.webkit.org/show_bug.cgi?id=53033

        New unit test to check the fix for this bug.

        * tests/testatk.c:
        (testWebkitAtkCaretOffsetsAndExtranousWhiteSpaces): New.
        (main): Add new unit test.

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

Source/WebCore/ChangeLog
Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp
Source/WebKit/gtk/ChangeLog
Source/WebKit/gtk/tests/testatk.c

index d4fc183..10715dc 100644 (file)
@@ -1,3 +1,17 @@
+2011-01-27  Mario Sanchez Prada  <msanchez@igalia.com>
+
+        Reviewed by Martin Robinson.
+
+        [GTK] Space characters in source document interfere with reported caret offset
+        https://bugs.webkit.org/show_bug.cgi?id=53033
+
+        Calculate caret offset from rendered text instead of from node contents.
+
+        * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
+        (objectAndOffsetUnignored): Calculate the caret offset based only
+        on positions and ranges, instead of using the computed offset in
+        the container node.
+
 2011-01-26  Alexey Proskuryakov  <ap@apple.com>
 
         Reviewed by Darin Adler.
index de3b324..99da07b 100644 (file)
@@ -2457,8 +2457,6 @@ AtkObject* webkit_accessible_get_focused_element(WebKitAccessible* accessible)
 
 AccessibilityObject* objectAndOffsetUnignored(AccessibilityObject* coreObject, int& offset, bool ignoreLinks)
 {
-    Node* endNode = static_cast<AccessibilityRenderObject*>(coreObject)->renderer()->node();
-    int endOffset = coreObject->selection().end().computeOffsetInContainerNode();
     // Indication that something bogus has transpired.
     offset = -1;
 
@@ -2473,16 +2471,12 @@ AccessibilityObject* objectAndOffsetUnignored(AccessibilityObject* coreObject, i
     if (!realObject)
         return 0;
 
-    Node* node = static_cast<AccessibilityRenderObject*>(realObject)->renderer()->node();
+    Node* node = realObject->node();
     if (node) {
-        RefPtr<Range> range = rangeOfContents(node);
-        if (range->ownerDocument() == node->document()) {
-            ExceptionCode ec = 0;
-            range->setEndBefore(endNode, ec);
-            if (range->boundaryPointsValid())
-                offset = range->text().length() + endOffset;
-        }
+        RefPtr<Range> range = Range::create(node->document(), firstPositionInNode(node), realObject->selection().end());
+        offset = TextIterator::rangeLength(range.get());
     }
+
     return realObject;
 }
 
index 1f4e31c..93cf03c 100644 (file)
@@ -1,3 +1,16 @@
+2011-01-27  Mario Sanchez Prada  <msanchez@igalia.com>
+
+        Reviewed by Martin Robinson.
+
+        [GTK] Space characters in source document interfere with reported caret offset
+        https://bugs.webkit.org/show_bug.cgi?id=53033
+
+        New unit test to check the fix for this bug.
+
+        * tests/testatk.c:
+        (testWebkitAtkCaretOffsetsAndExtranousWhiteSpaces): New.
+        (main): Add new unit test.
+
 2011-01-26  Mario Sanchez Prada  <msanchez@igalia.com>
 
         Reviewed by Martin Robinson.
index eb48fc7..f7a5c59 100644 (file)
@@ -46,6 +46,8 @@ static const char* contentsInTable = "<html><body><table><tr><td>foo</td><td>bar
 
 static const char* contentsInTableWithHeaders = "<html><body><table><tr><th>foo</th><th>bar</th><th colspan='2'>baz</th></tr><tr><th>qux</th><td>1</td><td>2</td><td>3</td></tr><tr><th rowspan='2'>quux</th><td>4</td><td>5</td><td>6</td></tr><tr><td>6</td><td>7</td><td>8</td></tr><tr><th>corge</th><td>9</td><td>10</td><td>11</td></tr></table><table><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table></body></html>";
 
+static const char* contentsWithExtraneousWhiteSpaces = "<html><head><body><p>This\n                          paragraph\n                                                      is\n                                                                                                                                                                                                                                                                                                                                                                            borked!</p></body></html>";
+
 static const char* comboBoxSelector = "<html><body><select><option selected value='foo'>foo</option><option value='bar'>bar</option></select></body></html>";
 
 static const char* formWithTextInputs = "<html><body><form><input type='text' name='entry' /></form></body></html>";
@@ -225,6 +227,47 @@ static void runGetTextTests(AtkText* textObject)
                         0, "This is a test. This is the second sentence. And this the third.", 0, 64);
 }
 
+static void testWebkitAtkCaretOffsetsAndExtranousWhiteSpaces()
+{
+    WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
+    g_object_ref_sink(webView);
+    GtkAllocation allocation = { 0, 0, 800, 600 };
+    gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
+    webkit_web_view_load_string(webView, contentsWithExtraneousWhiteSpaces, 0, 0, 0);
+
+    /* Wait for the accessible objects to be created. */
+    waitForAccessibleObjects();
+
+    /* Enable caret browsing. */
+    WebKitWebSettings* settings = webkit_web_view_get_settings(webView);
+    g_object_set(G_OBJECT(settings), "enable-caret-browsing", TRUE, NULL);
+    webkit_web_view_set_settings(webView, settings);
+
+    /* Get to the inner AtkText object. */
+    AtkObject* object = gtk_widget_get_accessible(GTK_WIDGET(webView));
+    g_assert(object);
+    object = atk_object_ref_accessible_child(object, 0);
+    g_assert(object);
+
+    AtkText* textObject = ATK_TEXT(object);
+    g_assert(ATK_IS_TEXT(textObject));
+
+    gchar* text = atk_text_get_text(textObject, 0, -1);
+    g_assert_cmpstr(text, ==, "This paragraph is borked!");
+    g_free(text);
+
+    gint characterCount = atk_text_get_character_count(textObject);
+    g_assert_cmpint(characterCount, ==, 25);
+
+    gboolean result = atk_text_set_caret_offset(textObject, characterCount - 1);
+    g_assert_cmpint(result, ==, TRUE);
+
+    gint caretOffset = atk_text_get_caret_offset(textObject);
+    g_assert_cmpint(caretOffset, ==, characterCount - 1);
+
+    g_object_unref(webView);
+}
+
 static void testWebkitAtkComboBox()
 {
     WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
@@ -1350,6 +1393,7 @@ int main(int argc, char** argv)
     gtk_test_init(&argc, &argv, 0);
 
     g_test_bug_base("https://bugs.webkit.org/");
+    g_test_add_func("/webkit/atk/caretOffsetsAndExtranousWhiteSpaces", testWebkitAtkCaretOffsetsAndExtranousWhiteSpaces);
     g_test_add_func("/webkit/atk/comboBox", testWebkitAtkComboBox);
     g_test_add_func("/webkit/atk/getTextAtOffset", testWebkitAtkGetTextAtOffset);
     g_test_add_func("/webkit/atk/getTextAtOffsetForms", testWebkitAtkGetTextAtOffsetForms);