Changeset 78978 in webkit


Ignore:
Timestamp:
Feb 18, 2011 1:40:56 AM (13 years ago)
Author:
mario@webkit.org
Message:

2011-02-18 Mario Sanchez Prada <msanchez@igalia.com>

Reviewed by Martin Robinson.

[Gtk] atk_text_get_selection/atk_text_set_selection fails for list items
https://bugs.webkit.org/show_bug.cgi?id=53453

Ensure that atk_text_{get|set}_selection() work with list items.

  • accessibility/gtk/AccessibilityObjectWrapperAtk.cpp: (webkit_accessible_text_get_text): Properly handle list item markers when returning the text for an object for a given interval specified through the startOffset and endOffset parameters. (getSelectionOffsetsForObject): Bear in mind list item markers when returning the offsets for a selection over a list item. (webkit_accessible_text_set_selection): Adjust offsets if needed for list items with item markers. Ensure that it returns TRUE only when everything went fine setting the text selection.

2011-02-18 Mario Sanchez Prada <msanchez@igalia.com>

Reviewed by Martin Robinson.

[Gtk] atk_text_get_selection/atk_text_set_selection fails for list items
https://bugs.webkit.org/show_bug.cgi?id=53453

Update unit test to check the fix for this bug.

  • tests/testatk.c: (testWebkitAtkTextSelections): Check that functions from AtkText interface to set and get text selections work with list items.
Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r78974 r78978  
     12011-02-18  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [Gtk] atk_text_get_selection/atk_text_set_selection fails for list items
     6        https://bugs.webkit.org/show_bug.cgi?id=53453
     7
     8        Ensure that atk_text_{get|set}_selection() work with list items.
     9
     10        * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
     11        (webkit_accessible_text_get_text): Properly handle list item
     12        markers when returning the text for an object for a given interval
     13        specified through the startOffset and endOffset parameters.
     14        (getSelectionOffsetsForObject): Bear in mind list item markers
     15        when returning the offsets for a selection over a list item.
     16        (webkit_accessible_text_set_selection): Adjust offsets if needed
     17        for list items with item markers. Ensure that it returns TRUE only
     18        when everything went fine setting the text selection.
     19
    1202011-02-18  Antti Koivisto  <antti@apple.com>
    221
  • trunk/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp

    r78789 r78978  
    11231123{
    11241124    AccessibilityObject* coreObject = core(text);
     1125
     1126    int end = endOffset;
     1127    if (endOffset == -1) {
     1128        end = coreObject->stringValue().length();
     1129        if (!end)
     1130            end = coreObject->textUnderElement().length();
     1131    }
     1132
    11251133    String ret;
    1126     unsigned start = startOffset;
    1127     if (endOffset == -1) {
    1128         endOffset = coreObject->stringValue().length();
    1129         if (!endOffset)
    1130             endOffset = coreObject->textUnderElement().length();
    1131     }
    1132     int length = endOffset - startOffset;
    1133 
    11341134    if (coreObject->isTextControl())
    1135         ret = coreObject->doAXStringForRange(PlainTextRange(start, length));
     1135        ret = coreObject->doAXStringForRange(PlainTextRange(0, endOffset));
    11361136    else {
    1137         ret = coreObject->stringValue().substring(start, length);
     1137        ret = coreObject->stringValue();
    11381138        if (!ret)
    1139             ret = coreObject->textUnderElement().substring(start, length);
     1139            ret = coreObject->textUnderElement();
    11401140    }
    11411141
    11421142    if (!ret.length()) {
    11431143        // This can happen at least with anonymous RenderBlocks (e.g. body text amongst paragraphs)
    1144         ret = String(textForObject(static_cast<AccessibilityRenderObject*>(coreObject)));
    1145         if (!endOffset)
    1146             endOffset = ret.length();
    1147         ret = ret.substring(start, endOffset - startOffset);
     1144        ret = String(textForObject(toAccessibilityRenderObject(coreObject)));
     1145        if (!end)
     1146            end = ret.length();
    11481147    }
    11491148
     
    11541153            String markerText = toRenderListItem(objRenderer)->markerTextWithSuffix();
    11551154            ret = objRenderer->style()->direction() == LTR ? markerText + ret : ret + markerText;
     1155            if (endOffset == -1)
     1156                end += markerText.length();
    11561157        }
    11571158    }
    11581159
     1160    ret = ret.substring(startOffset, end - startOffset);
    11591161    return g_strdup(ret.utf8().data());
    11601162}
     
    16291631    // Set values for start and end offsets.
    16301632    startOffset = TextIterator::rangeLength(rangeInParent.get());
     1633
     1634    // We need to adjust the offsets for the list item marker.
     1635    RenderObject* renderer = toAccessibilityRenderObject(coreObject)->renderer();
     1636    if (renderer && renderer->isListItem()) {
     1637        String markerText = toRenderListItem(renderer)->markerTextWithSuffix();
     1638        startOffset += markerText.length();
     1639    }
     1640
    16311641    RefPtr<Range> nodeRange = Range::create(node->document(), nodeRangeStart, nodeRangeEnd);
    16321642    endOffset = startOffset + TextIterator::rangeLength(nodeRange.get());
     
    16851695        return FALSE;
    16861696
     1697    AccessibilityObject* coreObject = core(text);
     1698    if (!coreObject->isAccessibilityRenderObject())
     1699        return FALSE;
     1700
    16871701    // Consider -1 and out-of-bound values and correct them to length
    16881702    gint textCount = webkit_accessible_text_get_character_count(text);
     
    16921706        endOffset = textCount;
    16931707
    1694     AccessibilityObject* coreObject = core(text);
     1708    // We need to adjust the offsets for the list item marker.
     1709    RenderObject* renderer = toAccessibilityRenderObject(coreObject)->renderer();
     1710    if (renderer && renderer->isListItem()) {
     1711        String markerText = toRenderListItem(renderer)->markerTextWithSuffix();
     1712        int markerLength = markerText.length();
     1713        if (startOffset < markerLength || endOffset < markerLength)
     1714            return FALSE;
     1715
     1716        startOffset -= markerLength;
     1717        endOffset -= markerLength;
     1718    }
     1719
    16951720    PlainTextRange textRange(startOffset, endOffset - startOffset);
    16961721    VisiblePositionRange range = coreObject->visiblePositionRangeForRange(textRange);
     1722    if (range.isNull())
     1723        return FALSE;
     1724
    16971725    coreObject->setSelectedVisiblePositionRange(range);
    1698 
    16991726    return TRUE;
    17001727}
  • trunk/Source/WebKit/gtk/ChangeLog

    r78925 r78978  
     12011-02-18  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [Gtk] atk_text_get_selection/atk_text_set_selection fails for list items
     6        https://bugs.webkit.org/show_bug.cgi?id=53453
     7
     8        Update unit test to check the fix for this bug.
     9
     10        * tests/testatk.c:
     11        (testWebkitAtkTextSelections): Check that functions from AtkText
     12        interface to set and get text selections work with list items.
     13
    1142011-02-17  Robert Ancell  <rober.ancell@gmail.com>
    215
  • trunk/Source/WebKit/gtk/tests/testatk.c

    r77817 r78978  
    6363static 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>";
    6464
    65 static 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>";
     65static 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><ol><li>A list item</li></ol><select></body></html>";
    6666
    6767static const char* textWithAttributes = "<html><head><style>.st1 {font-family: monospace; color:rgb(120,121,122);} .st2 {text-decoration:underline; background-color:rgb(80,81,82);}</style></head><body><p style=\"font-size:14; text-align:right;\">This is the <i>first</i><b> sentence of this text.</b></p><p class=\"st1\">This sentence should have an style applied <span class=\"st2\">and this part should have another one</span>.</p><p>x<sub>1</sub><sup>2</sup>=x<sub>2</sub><sup>3</sup></p><p style=\"text-align:center;\">This sentence is the <strike>last</strike> one.</p></body></html>";
     
    997997    AtkText* paragraph1 = ATK_TEXT(atk_object_ref_accessible_child(object, 0));
    998998    g_assert(ATK_IS_TEXT(paragraph1));
     999
    9991000    AtkText* paragraph2 = ATK_TEXT(atk_object_ref_accessible_child(object, 1));
    10001001    g_assert(ATK_IS_TEXT(paragraph2));
     1002
    10011003    AtkText* link = ATK_TEXT(atk_object_ref_accessible_child(ATK_OBJECT(paragraph2), 0));
    10021004    g_assert(ATK_IS_TEXT(link));
     1005
     1006    AtkObject* list = atk_object_ref_accessible_child(object, 2);
     1007    g_assert(ATK_OBJECT(list));
     1008
     1009    AtkText* listItem = ATK_TEXT(atk_object_ref_accessible_child(list, 0));
     1010    g_assert(ATK_IS_TEXT(listItem));
    10031011
    10041012    /* First paragraph (simple text). */
     
    10971105    g_free (selectedText);
    10981106
     1107    /* List item */
     1108
     1109    g_assert(atk_object_get_role(list) == ATK_ROLE_LIST);
     1110    g_assert_cmpint(atk_object_get_n_accessible_children(list), ==, 1);
     1111
     1112    gchar* text = atk_text_get_text(listItem, 0, -1);
     1113    g_assert_cmpstr(text, ==, "1. A list item");
     1114    g_free (text);
     1115
     1116    /* It's not possible to select text inside an item's marker. */
     1117    result = atk_text_set_selection (listItem, 0, 0, 9);
     1118    g_assert(!result);
     1119    result = atk_text_set_selection (listItem, 0, 9, 1);
     1120    g_assert(!result);
     1121
     1122    /* It should be possible to select text inside an item's text. */
     1123    result = atk_text_set_selection (listItem, 0, 3, 9);
     1124    g_assert(result);
     1125
     1126    g_assert_cmpint(atk_text_get_n_selections(listItem), ==, 1);
     1127    selectedText = atk_text_get_selection(listItem, 0, &startOffset, &endOffset);
     1128    g_assert_cmpint(startOffset, ==, 3);
     1129    g_assert_cmpint(endOffset, ==, 9);
     1130    g_assert_cmpstr(selectedText, ==, "A list");
     1131    g_free (selectedText);
     1132
    10991133    g_object_unref(paragraph1);
    11001134    g_object_unref(paragraph2);
     1135    g_object_unref(list);
     1136    g_object_unref(listItem);
    11011137    g_object_unref(webView);
    11021138}
Note: See TracChangeset for help on using the changeset viewer.