Changeset 77137 in webkit


Ignore:
Timestamp:
Jan 31, 2011 9:57:56 AM (13 years ago)
Author:
mario@webkit.org
Message:

2011-01-31 Mario Sanchez Prada <msanchez@igalia.com>

Reviewed by Martin Robinson.

[Gtk] atk_text_set_caret_offset returns True even when it is unsuccessful
https://bugs.webkit.org/show_bug.cgi?id=53389

Return FALSE when not able to set the caret at the specified offset.

  • accessibility/gtk/AccessibilityObjectWrapperAtk.cpp: (webkit_accessible_text_set_caret_offset): Return FALSE when the range created is NULL and adjust offset to account for list markers.

2011-01-31 Mario Sanchez Prada <msanchez@igalia.com>

Reviewed by Martin Robinson.

[Gtk] atk_text_set_caret_offset returns True even when it is unsuccessful
https://bugs.webkit.org/show_bug.cgi?id=53389

New unit test to check the fix for this bug.

  • tests/testatk.c: (testWebkitAtkCaretOffsets): New. (main): Add new test.
Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r77128 r77137  
     12011-01-31  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [Gtk] atk_text_set_caret_offset returns True even when it is unsuccessful
     6        https://bugs.webkit.org/show_bug.cgi?id=53389
     7
     8        Return FALSE when not able to set the caret at the specified offset.
     9
     10        * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
     11        (webkit_accessible_text_set_caret_offset): Return FALSE when the
     12        range created is NULL and adjust offset to account for list markers.
     13
    1142011-01-28  Pavel Feldman  <pfeldman@chromium.org>
    215
  • trunk/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp

    r76822 r77137  
    17001700    AccessibilityObject* coreObject = core(text);
    17011701
     1702    if (!coreObject->isAccessibilityRenderObject())
     1703        return FALSE;
     1704
     1705    RenderObject* renderer = toAccessibilityRenderObject(coreObject)->renderer();
     1706    if (renderer && renderer->isListItem()) {
     1707        String markerText = toRenderListItem(renderer)->markerTextWithSuffix();
     1708        int markerLength = g_utf8_strlen(markerText.utf8().data(), -1);
     1709        if (offset < markerLength)
     1710            return FALSE;
     1711
     1712        // We need to adjust the offset for list items.
     1713        offset -= markerLength;
     1714    }
     1715
    17021716    PlainTextRange textRange(offset, 0);
    17031717    VisiblePositionRange range = coreObject->visiblePositionRangeForRange(textRange);
     1718    if (range.isNull())
     1719        return FALSE;
     1720
    17041721    coreObject->setSelectedVisiblePositionRange(range);
    1705 
    17061722    return TRUE;
    17071723}
  • trunk/Source/WebKit/gtk/ChangeLog

    r77061 r77137  
     12011-01-31  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [Gtk] atk_text_set_caret_offset returns True even when it is unsuccessful
     6        https://bugs.webkit.org/show_bug.cgi?id=53389
     7
     8        New unit test to check the fix for this bug.
     9
     10        * tests/testatk.c:
     11        (testWebkitAtkCaretOffsets): New.
     12        (main): Add new test.
     13
    1142011-01-29  Dan Winship  <danw@gnome.org>
    215
  • trunk/Source/WebKit/gtk/tests/testatk.c

    r76822 r77137  
    6161static const char* listsOfItems = "<html><body><ul><li>text only</li><li><a href='foo'>link only</a></li><li>text and a <a href='bar'>link</a></li></ul><ol><li>text only</li><li><a href='foo'>link only</a></li><li>text and a <a href='bar'>link</a></li></ol></body></html>";
    6262
     63static const char* textForCaretBrowsing = "<html><body><h1>A text header</h1><p>A paragraph <a href='http://foo.bar.baz/'>with a link</a> in the middle</p><ol><li>A list item</li></ol><select><option selected value='foo'>An option in a combo box</option></select></body></html>";
     64
    6365static const char* textForSelections = "<html><body><p>A paragraph with plain text</p><p>A paragraph with <a href='http://webkit.org'>a link</a> in the middle</p></body></html>";
    6466
     
    226228    testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END,
    227229                        0, "This is a test. This is the second sentence. And this the third.", 0, 64);
     230}
     231
     232static void testWebkitAtkCaretOffsets()
     233{
     234    WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
     235    g_object_ref_sink(webView);
     236    GtkAllocation allocation = { 0, 0, 800, 600 };
     237    gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
     238    webkit_web_view_load_string(webView, textForCaretBrowsing, 0, 0, 0);
     239
     240    /* Wait for the accessible objects to be created. */
     241    waitForAccessibleObjects();
     242
     243    AtkObject* object = gtk_widget_get_accessible(GTK_WIDGET(webView));
     244    g_assert(object);
     245
     246    AtkObject* header = atk_object_ref_accessible_child(object, 0);
     247    g_assert(ATK_IS_TEXT(header));
     248    gchar* text = atk_text_get_text(ATK_TEXT(header), 0, -1);
     249    g_assert_cmpstr(text, ==, "A text header");
     250    g_free (text);
     251
     252    /* It should be possible to place the caret inside a header. */
     253    gboolean result = atk_text_set_caret_offset(ATK_TEXT(header), 5);
     254    g_assert_cmpint(result, ==, TRUE);
     255    gint offset = atk_text_get_caret_offset(ATK_TEXT(header));
     256    g_assert_cmpint(offset, ==, 5);
     257
     258    AtkObject* paragraph = atk_object_ref_accessible_child(object, 1);
     259    g_assert(ATK_IS_TEXT(paragraph));
     260    text = atk_text_get_text(ATK_TEXT(paragraph), 0, -1);
     261    g_assert_cmpstr(text, ==, "A paragraph with a link in the middle");
     262    g_free (text);
     263
     264    /* It should be possible to place the caret inside a paragraph and a link. */
     265    result = atk_text_set_caret_offset(ATK_TEXT(paragraph), 5);
     266    g_assert_cmpint(result, ==, TRUE);
     267    offset = atk_text_get_caret_offset(ATK_TEXT(paragraph));
     268    g_assert_cmpint(offset, ==, 5);
     269
     270    result = atk_text_set_caret_offset(ATK_TEXT(paragraph), 20);
     271    g_assert_cmpint(result, ==, TRUE);
     272    offset = atk_text_get_caret_offset(ATK_TEXT(paragraph));
     273    g_assert_cmpint(offset, ==, 20);
     274
     275    result = atk_text_set_caret_offset(ATK_TEXT(paragraph), 30);
     276    g_assert_cmpint(result, ==, TRUE);
     277    offset = atk_text_get_caret_offset(ATK_TEXT(paragraph));
     278    g_assert_cmpint(offset, ==, 30);
     279
     280    AtkObject* list = atk_object_ref_accessible_child(object, 2);
     281    g_assert(ATK_OBJECT(list));
     282    g_assert(atk_object_get_role(list) == ATK_ROLE_LIST);
     283    g_assert_cmpint(atk_object_get_n_accessible_children(list), ==, 1);
     284
     285    AtkObject* listItem = atk_object_ref_accessible_child(list, 0);
     286    g_assert(ATK_IS_TEXT(listItem));
     287    text = atk_text_get_text(ATK_TEXT(listItem), 0, -1);
     288    g_assert_cmpstr(text, ==, "1. A list item");
     289    g_free (text);
     290
     291    /* It's not possible to place the caret inside an item's marker. */
     292    result = atk_text_set_caret_offset(ATK_TEXT(listItem), 1);
     293    g_assert_cmpint(result, ==, FALSE);
     294
     295    /* TODO: Check here that it's possible to set the caret in the
     296       middle of the text for a list item when fixing bug 53388.
     297       https://bugs.webkit.org/show_bug.cgi?id=53388 */
     298
     299    AtkObject* panel = atk_object_ref_accessible_child(object, 3);
     300    g_assert(ATK_IS_OBJECT(panel));
     301    g_assert(atk_object_get_role(panel) == ATK_ROLE_PANEL);
     302
     303    AtkObject* comboBox = atk_object_ref_accessible_child(panel, 0);
     304    g_assert(ATK_IS_OBJECT(comboBox));
     305    g_assert(atk_object_get_role(comboBox) == ATK_ROLE_COMBO_BOX);
     306
     307    AtkObject* menuPopup = atk_object_ref_accessible_child(comboBox, 0);
     308    g_assert(ATK_IS_OBJECT(menuPopup));
     309    g_assert(atk_object_get_role(menuPopup) == ATK_ROLE_MENU);
     310
     311    AtkObject* comboBoxOption = atk_object_ref_accessible_child(menuPopup, 0);
     312    g_assert(ATK_IS_OBJECT(comboBoxOption));
     313    g_assert(atk_object_get_role(comboBoxOption) == ATK_ROLE_MENU_ITEM);
     314    g_assert(ATK_IS_TEXT(comboBoxOption));
     315    text = atk_text_get_text(ATK_TEXT(comboBoxOption), 0, -1);
     316    g_assert_cmpstr(text, ==, "An option in a combo box");
     317
     318    /* It's not possible to place the caret inside an option for a combobox. */
     319    result = atk_text_set_caret_offset(ATK_TEXT(comboBoxOption), 1);
     320    g_assert_cmpint(result, ==, FALSE);
     321
     322    g_object_unref(header);
     323    g_object_unref(paragraph);
     324    g_object_unref(list);
     325    g_object_unref(listItem);
     326    g_object_unref(panel);
     327    g_object_unref(comboBox);
     328    g_object_unref(menuPopup);
     329    g_object_unref(comboBoxOption);
     330    g_object_unref(webView);
    228331}
    229332
     
    13941497
    13951498    g_test_bug_base("https://bugs.webkit.org/");
     1499    g_test_add_func("/webkit/atk/caretOffsets", testWebkitAtkCaretOffsets);
    13961500    g_test_add_func("/webkit/atk/caretOffsetsAndExtranousWhiteSpaces", testWebkitAtkCaretOffsetsAndExtranousWhiteSpaces);
    13971501    g_test_add_func("/webkit/atk/comboBox", testWebkitAtkComboBox);
Note: See TracChangeset for help on using the changeset viewer.