Changeset 68415 in webkit


Ignore:
Timestamp:
Sep 27, 2010 12:35:10 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-09-27 Mario Sanchez Prada <msanchez@igalia.com>

Reviewed by Chris Fleizach.

[Gtk] Adjust atk_text_get_text_at_offset to account for bullets/numbers in list items
https://bugs.webkit.org/show_bug.cgi?id=45381

Ensure list markers are consistently used in the Atk wrapper.

This patch does two things (both needed to fix the bug): It
improves the way list items markers are exposed through the Atk
Wrapper (by exposing the exact text in the marker, including the
marker suffix, if any) and makes sure the marker is consistently
considered and treated in those methods of the AtkText interface
that would need it (like atk_text_get_character_count or
atk_text_get_run_attributes, for instance).

  • accessibility/gtk/AccessibilityObjectWrapperAtk.cpp: (textForObject):

Append/prepend list marker when needed.

(webkit_accessible_text_get_text):

Use the new function markerTextWithSuffix() to expose a more
accurate value.

(accessibilityObjectLength):

Consider list items marker to return the length of an object,
if needed. Also, added some extra checks.

(webkit_accessible_text_get_character_count):

Just delegate on accessibilityObjectLength, to make it
cleaner and more consistent.

  • rendering/RenderListItem.cpp: (WebCore::RenderListItem::markerTextWithSuffix):

New public function to return a single string with the
marker associated to the item and its suffix, considering
text direction (LTR or RTL).

  • rendering/RenderListItem.h:
  • rendering/RenderListMarker.cpp: (WebCore::RenderListMarker::suffix):

New public function to return a String with the suffix
associated to the marker.

  • rendering/RenderListMarker.h:

2010-09-27 Mario Sanchez Prada <msanchez@igalia.com>

Reviewed by Chris Fleizach.

[Gtk] Adjust atk_text_get_text_at_offset to account for bullets/numbers in list items
https://bugs.webkit.org/show_bug.cgi?id=45381

Updated test to match the new exposure of list item markers.

Also, added some extra assertions in that test to make sure the
accessible objects associated to the items implement AtkText.

  • tests/testatk.c: (testWebkitAtkListsOfItems): (main):
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r68412 r68415  
     12010-09-27  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Chris Fleizach.
     4
     5        [Gtk] Adjust atk_text_get_text_at_offset to account for bullets/numbers in list items
     6        https://bugs.webkit.org/show_bug.cgi?id=45381
     7
     8        Ensure list markers are consistently used in the Atk wrapper.
     9
     10        This patch does two things (both needed to fix the bug): It
     11        improves the way list items markers are exposed through the Atk
     12        Wrapper (by exposing the exact text in the marker, including the
     13        marker suffix, if any) and makes sure the marker is consistently
     14        considered and treated in those methods of the AtkText interface
     15        that would need it (like atk_text_get_character_count or
     16        atk_text_get_run_attributes, for instance).
     17
     18        * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
     19        (textForObject):
     20           Append/prepend list marker when needed.
     21        (webkit_accessible_text_get_text):
     22           Use the new function markerTextWithSuffix() to expose a more
     23           accurate value.
     24        (accessibilityObjectLength):
     25           Consider list items marker to return the length of an object,
     26           if needed. Also, added some extra checks.
     27        (webkit_accessible_text_get_character_count):
     28           Just delegate on accessibilityObjectLength, to make it
     29           cleaner and more consistent.
     30
     31        * rendering/RenderListItem.cpp:
     32        (WebCore::RenderListItem::markerTextWithSuffix):
     33           New public function to return a single string with the
     34           marker associated to the item and its suffix, considering
     35           text direction (LTR or RTL).
     36        * rendering/RenderListItem.h:
     37        * rendering/RenderListMarker.cpp:
     38        (WebCore::RenderListMarker::suffix):
     39           New public function to return a String with the suffix
     40           associated to the marker.
     41        * rendering/RenderListMarker.h:
     42
    1432010-09-27  Sheriff Bot  <webkit.review.bot@gmail.com>
    244
  • trunk/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp

    r68023 r68415  
    5656#include "IntRect.h"
    5757#include "NotImplemented.h"
     58#include "RenderListItem.h"
    5859#include "RenderListMarker.h"
    5960#include "RenderText.h"
     
    879880            range = accObject->doAXRangeForLine(++lineNumber);
    880881        }
    881     } else if (accObject->renderer()) {
     882    } else {
     883        RenderObject* renderer = accObject->renderer();
     884        if (!renderer)
     885            return g_string_free(str, FALSE);
     886
    882887        // For RenderBlocks, piece together the text from the RenderText objects they contain.
    883         for (RenderObject* obj = accObject->renderer()->firstChild(); obj; obj = obj->nextSibling()) {
     888        for (RenderObject* obj = renderer->firstChild(); obj; obj = obj->nextSibling()) {
    884889            if (obj->isBR()) {
    885890                g_string_append(str, "\n");
     
    908913            }
    909914        }
    910     }
     915
     916        // Insert the text of the marker for list item in the right place, if present
     917        if (renderer->isListItem()) {
     918            String markerText = toRenderListItem(renderer)->markerTextWithSuffix();
     919            if (renderer->style()->direction() == LTR)
     920                g_string_prepend(str, markerText.utf8().data());
     921            else
     922                g_string_append(str, markerText.utf8().data());
     923        }
     924    }
     925
    911926    return g_string_free(str, FALSE);
    912927}
     
    940955    if (coreObject->roleValue() == ListItemRole) {
    941956        RenderObject* objRenderer = static_cast<AccessibilityRenderObject*>(coreObject)->renderer();
    942         RenderObject* markerRenderer = objRenderer ? objRenderer->firstChild() : 0;
    943         if (markerRenderer && markerRenderer->isListMarker()) {
    944             String markerTxt = toRenderListMarker(markerRenderer)->text();
    945             ret = markerTxt.length() > 0 ? markerTxt + " " + ret : ret;
     957        if (objRenderer && objRenderer->isListItem()) {
     958            String markerText = toRenderListItem(objRenderer)->markerTextWithSuffix();
     959            ret = objRenderer->style()->direction() == LTR ? markerText + ret : ret + markerText;
    946960        }
    947961    }
     
    11861200static guint accessibilityObjectLength(const AccessibilityObject* object)
    11871201{
    1188     GOwnPtr<gchar> text(webkit_accessible_text_get_text(ATK_TEXT(object->wrapper()), 0, -1));
    1189     return g_utf8_strlen(text.get(), -1);
     1202    // Non render objects are not taken into account
     1203    if (!object->isAccessibilityRenderObject())
     1204        return 0;
     1205
     1206    // For those objects implementing the AtkText interface we use the
     1207    // well known API to always get the text in a consistent way
     1208    AtkObject* atkObj = ATK_OBJECT(object->wrapper());
     1209    if (ATK_IS_TEXT(atkObj)) {
     1210        GOwnPtr<gchar> text(webkit_accessible_text_get_text(ATK_TEXT(atkObj), 0, -1));
     1211        return g_utf8_strlen(text.get(), -1);
     1212    }
     1213
     1214    // Even if we don't expose list markers to Assistive
     1215    // Technologies, we need to have a way to measure their length
     1216    // for those cases when it's needed to take it into account
     1217    // separately (as in getAccessibilityObjectForOffset)
     1218    RenderObject* renderer = static_cast<const AccessibilityRenderObject*>(object)->renderer();
     1219    if (renderer && renderer->isListMarker()) {
     1220        RenderListMarker* marker = toRenderListMarker(renderer);
     1221        return marker->text().length() + marker->suffix().length();
     1222    }
     1223
     1224    return 0;
    11901225}
    11911226
     
    13221357static gint webkit_accessible_text_get_character_count(AtkText* text)
    13231358{
    1324     AccessibilityObject* coreObject = core(text);
    1325 
    1326     if (coreObject->isTextControl())
    1327         return coreObject->textLength();
    1328     else
    1329         return coreObject->textUnderElement().length();
     1359    return accessibilityObjectLength(core(text));
    13301360}
    13311361
  • trunk/WebCore/rendering/RenderListItem.cpp

    r68408 r68415  
    315315}
    316316
     317String RenderListItem::markerTextWithSuffix() const
     318{
     319    if (!m_marker)
     320        return String();
     321
     322    // Append the suffix for the marker in the right place depending
     323    // on the direction of the text (right-to-left or left-to-right).
     324
     325    const String& markerText = m_marker->text();
     326    const String markerSuffix = m_marker->suffix();
     327    Vector<UChar> resultVector;
     328
     329    if (m_marker->style()->direction() == RTL)
     330        resultVector.append(markerSuffix.characters(), markerSuffix.length());
     331
     332    resultVector.append(markerText.characters(), markerText.length());
     333
     334    if (m_marker->style()->direction() == LTR)
     335        resultVector.append(markerSuffix.characters(), markerSuffix.length());
     336
     337    return String::adopt(resultVector);
     338}
     339
    317340void RenderListItem::explicitValueChanged()
    318341{
  • trunk/WebCore/rendering/RenderListItem.h

    r68276 r68415  
    4646
    4747    const String& markerText() const;
     48    String markerTextWithSuffix() const;
    4849
    4950    void updateListMarkerNumbers();
  • trunk/WebCore/rendering/RenderListMarker.cpp

    r68408 r68415  
    15231523}
    15241524
     1525String RenderListMarker::suffix() const
     1526{
     1527    EListStyleType type = style()->listStyleType();
     1528    const UChar suffix = listMarkerSuffix(type, m_listItem->value());
     1529
     1530    Vector<UChar> resultVector;
     1531    resultVector.append(suffix);
     1532
     1533    // If the suffix is not ' ', an extra space is needed
     1534    if (suffix != ' ') {
     1535        if (style()->direction() == LTR)
     1536            resultVector.append(' ');
     1537        else
     1538            resultVector.prepend(' ');
     1539    }
     1540
     1541    return String::adopt(resultVector);
     1542}
     1543
    15251544bool RenderListMarker::isInside() const
    15261545{
  • trunk/WebCore/rendering/RenderListMarker.h

    r68276 r68415  
    4242
    4343    const String& text() const { return m_text; }
     44    String suffix() const;
    4445
    4546    bool isInside() const;
  • trunk/WebKit/gtk/ChangeLog

    r68404 r68415  
     12010-09-27  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Chris Fleizach.
     4
     5        [Gtk] Adjust atk_text_get_text_at_offset to account for bullets/numbers in list items
     6        https://bugs.webkit.org/show_bug.cgi?id=45381
     7
     8        Updated test to match the new exposure of list item markers.
     9
     10        Also, added some extra assertions in that test to make sure the
     11        accessible objects associated to the items implement AtkText.
     12
     13        * tests/testatk.c:
     14        (testWebkitAtkListsOfItems):
     15        (main):
     16
    1172010-09-27  Philippe Normand  <pnormand@igalia.com>
    218
  • trunk/WebKit/gtk/tests/testatk.c

    r68111 r68415  
    967967static void testWebkitAtkListsOfItems(void)
    968968{
    969     WebKitWebView* webView;
    970     AtkObject* obj;
    971     AtkObject* uList;
    972     AtkObject* oList;
    973     AtkObject* item1;
    974     AtkObject* item2;
    975     AtkObject* item3;
    976     GMainLoop* loop;
    977 
    978     webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
     969    WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
    979970    g_object_ref_sink(webView);
    980971    GtkAllocation alloc = { 0, 0, 800, 600 };
    981972    gtk_widget_size_allocate(GTK_WIDGET(webView), &alloc);
    982973    webkit_web_view_load_string(webView, listsOfItems, NULL, NULL, NULL);
    983     loop = g_main_loop_new(NULL, TRUE);
    984 
    985     g_idle_add((GSourceFunc)bail_out, loop);
    986     g_main_loop_run(loop);
    987 
    988     obj = gtk_widget_get_accessible(GTK_WIDGET(webView));
     974    GMainLoop* loop = g_main_loop_new(NULL, TRUE);
     975
     976    g_idle_add((GSourceFunc)bail_out, loop);
     977    g_main_loop_run(loop);
     978
     979    AtkObject* obj = gtk_widget_get_accessible(GTK_WIDGET(webView));
    989980    g_assert(obj);
    990981
    991982    // Unordered list
    992983
    993     uList = atk_object_ref_accessible_child(obj, 0);
     984    AtkObject* uList = atk_object_ref_accessible_child(obj, 0);
    994985    g_assert(ATK_OBJECT(uList));
    995986    g_assert(atk_object_get_role(uList) == ATK_ROLE_LIST);
    996987    g_assert_cmpint(atk_object_get_n_accessible_children(uList), ==, 3);
    997988
    998     item1 = atk_object_ref_accessible_child(uList, 0);
    999     item2 = atk_object_ref_accessible_child(uList, 1);
    1000     item3 = atk_object_ref_accessible_child(uList, 2);
     989    AtkObject* item1 = atk_object_ref_accessible_child(uList, 0);
     990    g_assert(ATK_IS_TEXT(item1));
     991    AtkObject* item2 = atk_object_ref_accessible_child(uList, 1);
     992    g_assert(ATK_IS_TEXT(item2));
     993    AtkObject* item3 = atk_object_ref_accessible_child(uList, 2);
     994    g_assert(ATK_IS_TEXT(item3));
    1001995
    1002996    g_assert_cmpint(atk_object_get_n_accessible_children(item1), ==, 0);
     
    10141008    // Ordered list
    10151009
    1016     oList = atk_object_ref_accessible_child(obj, 1);
     1010    AtkObject* oList = atk_object_ref_accessible_child(obj, 1);
    10171011    g_assert(ATK_OBJECT(oList));
    10181012    g_assert(atk_object_get_role(oList) == ATK_ROLE_LIST);
     
    10201014
    10211015    item1 = atk_object_ref_accessible_child(oList, 0);
     1016    g_assert(ATK_IS_TEXT(item1));
    10221017    item2 = atk_object_ref_accessible_child(oList, 1);
     1018    g_assert(ATK_IS_TEXT(item2));
    10231019    item3 = atk_object_ref_accessible_child(oList, 2);
    1024 
    1025     g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item1), 0, -1), ==, "1 text only");
    1026     g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item2), 0, -1), ==, "2 link only");
    1027     g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item3), 0, -1), ==, "3 text and a link");
     1020    g_assert(ATK_IS_TEXT(item3));
     1021
     1022    g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item1), 0, -1), ==, "1. text only");
     1023    g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item2), 0, -1), ==, "2. link only");
     1024    g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item3), 0, -1), ==, "3. text and a link");
    10281025
    10291026    g_assert_cmpint(atk_object_get_n_accessible_children(item1), ==, 0);
Note: See TracChangeset for help on using the changeset viewer.