Changeset 76822 in webkit


Ignore:
Timestamp:
Jan 27, 2011 11:38:03 AM (13 years ago)
Author:
mario@webkit.org
Message:

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-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.
Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r76821 r76822  
     12011-01-27  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Space characters in source document interfere with reported caret offset
     6        https://bugs.webkit.org/show_bug.cgi?id=53033
     7
     8        Calculate caret offset from rendered text instead of from node contents.
     9
     10        * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
     11        (objectAndOffsetUnignored): Calculate the caret offset based only
     12        on positions and ranges, instead of using the computed offset in
     13        the container node.
     14
    1152011-01-26  Alexey Proskuryakov  <ap@apple.com>
    216
  • trunk/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp

    r76721 r76822  
    24582458AccessibilityObject* objectAndOffsetUnignored(AccessibilityObject* coreObject, int& offset, bool ignoreLinks)
    24592459{
    2460     Node* endNode = static_cast<AccessibilityRenderObject*>(coreObject)->renderer()->node();
    2461     int endOffset = coreObject->selection().end().computeOffsetInContainerNode();
    24622460    // Indication that something bogus has transpired.
    24632461    offset = -1;
     
    24742472        return 0;
    24752473
    2476     Node* node = static_cast<AccessibilityRenderObject*>(realObject)->renderer()->node();
     2474    Node* node = realObject->node();
    24772475    if (node) {
    2478         RefPtr<Range> range = rangeOfContents(node);
    2479         if (range->ownerDocument() == node->document()) {
    2480             ExceptionCode ec = 0;
    2481             range->setEndBefore(endNode, ec);
    2482             if (range->boundaryPointsValid())
    2483                 offset = range->text().length() + endOffset;
    2484         }
    2485     }
     2476        RefPtr<Range> range = Range::create(node->document(), firstPositionInNode(node), realObject->selection().end());
     2477        offset = TextIterator::rangeLength(range.get());
     2478    }
     2479
    24862480    return realObject;
    24872481}
  • trunk/Source/WebKit/gtk/ChangeLog

    r76721 r76822  
     12011-01-27  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Space characters in source document interfere with reported caret offset
     6        https://bugs.webkit.org/show_bug.cgi?id=53033
     7
     8        New unit test to check the fix for this bug.
     9
     10        * tests/testatk.c:
     11        (testWebkitAtkCaretOffsetsAndExtranousWhiteSpaces): New.
     12        (main): Add new unit test.
     13
    1142011-01-26  Mario Sanchez Prada  <msanchez@igalia.com>
    215
  • trunk/Source/WebKit/gtk/tests/testatk.c

    r76721 r76822  
    4747static 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>";
    4848
     49static const char* contentsWithExtraneousWhiteSpaces = "<html><head><body><p>This\n                          paragraph\n                                                      is\n                                                                                                                                                                                                                                                                                                                                                                            borked!</p></body></html>";
     50
    4951static const char* comboBoxSelector = "<html><body><select><option selected value='foo'>foo</option><option value='bar'>bar</option></select></body></html>";
    5052
     
    224226    testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END,
    225227                        0, "This is a test. This is the second sentence. And this the third.", 0, 64);
     228}
     229
     230static void testWebkitAtkCaretOffsetsAndExtranousWhiteSpaces()
     231{
     232    WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
     233    g_object_ref_sink(webView);
     234    GtkAllocation allocation = { 0, 0, 800, 600 };
     235    gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
     236    webkit_web_view_load_string(webView, contentsWithExtraneousWhiteSpaces, 0, 0, 0);
     237
     238    /* Wait for the accessible objects to be created. */
     239    waitForAccessibleObjects();
     240
     241    /* Enable caret browsing. */
     242    WebKitWebSettings* settings = webkit_web_view_get_settings(webView);
     243    g_object_set(G_OBJECT(settings), "enable-caret-browsing", TRUE, NULL);
     244    webkit_web_view_set_settings(webView, settings);
     245
     246    /* Get to the inner AtkText object. */
     247    AtkObject* object = gtk_widget_get_accessible(GTK_WIDGET(webView));
     248    g_assert(object);
     249    object = atk_object_ref_accessible_child(object, 0);
     250    g_assert(object);
     251
     252    AtkText* textObject = ATK_TEXT(object);
     253    g_assert(ATK_IS_TEXT(textObject));
     254
     255    gchar* text = atk_text_get_text(textObject, 0, -1);
     256    g_assert_cmpstr(text, ==, "This paragraph is borked!");
     257    g_free(text);
     258
     259    gint characterCount = atk_text_get_character_count(textObject);
     260    g_assert_cmpint(characterCount, ==, 25);
     261
     262    gboolean result = atk_text_set_caret_offset(textObject, characterCount - 1);
     263    g_assert_cmpint(result, ==, TRUE);
     264
     265    gint caretOffset = atk_text_get_caret_offset(textObject);
     266    g_assert_cmpint(caretOffset, ==, characterCount - 1);
     267
     268    g_object_unref(webView);
    226269}
    227270
     
    13511394
    13521395    g_test_bug_base("https://bugs.webkit.org/");
     1396    g_test_add_func("/webkit/atk/caretOffsetsAndExtranousWhiteSpaces", testWebkitAtkCaretOffsetsAndExtranousWhiteSpaces);
    13531397    g_test_add_func("/webkit/atk/comboBox", testWebkitAtkComboBox);
    13541398    g_test_add_func("/webkit/atk/getTextAtOffset", testWebkitAtkGetTextAtOffset);
Note: See TracChangeset for help on using the changeset viewer.