Changeset 64475 in webkit


Ignore:
Timestamp:
Aug 2, 2010 10:53:08 AM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-08-02 Mario Sanchez Prada <msanchez@igalia.com>

Reviewed by Chris Fleizach.

[GTK] Implement support for get_character_extents and get_range_extents
https://bugs.webkit.org/show_bug.cgi?id=25677

Implement get_range_extents() and modify get_character_extents()
to properly work after "The Great Flattening" occurred in the ATK
objects hierarchy, some months ago.

In the case of the GTK port, not just the text controls should be
considered when it comes to these functions but also those
composite objects that would also allow to work with text ranges,
such as headings and links. To take care of this, a new function
AccessibilityObject::allowsTextRanges() was defined with a default
implementation in the header file and an specific one for GTK in
AccessibilityObjectAtk.cpp.

Based on a previous patch by Joanmarie Diggs.

  • accessibility/AccessibilityObject.cpp: (WebCore::AccessibilityObject::visiblePositionRangeForRange):
  • accessibility/AccessibilityObject.h: (WebCore::AccessibilityObject::allowsTextRanges): New
  • accessibility/AccessibilityRenderObject.cpp: (WebCore::AccessibilityRenderObject::visiblePositionForIndex): (WebCore::AccessibilityRenderObject::doAXBoundsForRange):
  • accessibility/gtk/AccessibilityObjectAtk.cpp: (WebCore::AccessibilityObject::allowsTextRanges): New
  • accessibility/gtk/AccessibilityObjectWrapperAtk.cpp: (textExtents): (webkit_accessible_text_get_character_extents): (webkit_accessible_text_get_range_extents): (atk_text_interface_init):

2010-08-02 Mario Sanchez Prada <msanchez@igalia.com>

Reviewed by Chris Fleizach.

[GTK] Implement support for get_character_extents and get_range_extents
https://bugs.webkit.org/show_bug.cgi?id=25677

Added new unit tests to check get_character_extents and
get_range_extents functions for the ATK_TEXT interface

Based on a previous patch by Joanmarie Diggs.

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

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64472 r64475  
     12010-08-02  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Chris Fleizach.
     4
     5        [GTK] Implement support for get_character_extents and get_range_extents
     6        https://bugs.webkit.org/show_bug.cgi?id=25677
     7
     8        Implement get_range_extents() and modify get_character_extents()
     9        to properly work after "The Great Flattening" occurred in the ATK
     10        objects hierarchy, some months ago.
     11
     12        In the case of the GTK port, not just the text controls should be
     13        considered when it comes to these functions but also those
     14        composite objects that would also allow to work with text ranges,
     15        such as headings and links. To take care of this, a new function
     16        AccessibilityObject::allowsTextRanges() was defined with a default
     17        implementation in the header file and an specific one for GTK in
     18        AccessibilityObjectAtk.cpp.
     19
     20        Based on a previous patch by Joanmarie Diggs.
     21
     22        * accessibility/AccessibilityObject.cpp:
     23        (WebCore::AccessibilityObject::visiblePositionRangeForRange):
     24        * accessibility/AccessibilityObject.h:
     25        (WebCore::AccessibilityObject::allowsTextRanges): New
     26        * accessibility/AccessibilityRenderObject.cpp:
     27        (WebCore::AccessibilityRenderObject::visiblePositionForIndex):
     28        (WebCore::AccessibilityRenderObject::doAXBoundsForRange):
     29        * accessibility/gtk/AccessibilityObjectAtk.cpp:
     30        (WebCore::AccessibilityObject::allowsTextRanges): New
     31        * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
     32        (textExtents):
     33        (webkit_accessible_text_get_character_extents):
     34        (webkit_accessible_text_get_range_extents):
     35        (atk_text_interface_init):
     36
    1372010-08-02  Chris Fleizach  <cfleizach@apple.com>
    238
  • trunk/WebCore/accessibility/AccessibilityObject.cpp

    r64088 r64475  
    374374VisiblePositionRange AccessibilityObject::visiblePositionRangeForRange(const PlainTextRange& range) const
    375375{
    376     if (range.start + range.length > text().length())
     376    unsigned textLength = text().length();
     377#if PLATFORM(GTK)
     378    // Gtk ATs need this for all text objects; not just text controls.
     379    if (!textLength) {
     380        Node* node = this->node();
     381        if (node) {
     382            RenderText* renderText = toRenderText(node->renderer());
     383            if (renderText)
     384                textLength = renderText->textLength();
     385
     386            // Get the text length from the elements under the
     387            // accessibility object if not a RenderText object.
     388            if (!textLength && allowsTextRanges())
     389                textLength = textUnderElement().length();
     390        }
     391    }
     392#endif
     393    if (range.start + range.length > textLength)
    377394        return VisiblePositionRange();
    378395
  • trunk/WebCore/accessibility/AccessibilityObject.h

    r64471 r64475  
    588588    virtual bool isDetached() const { return true; }
    589589   
     590#if PLATFORM(GTK)
     591    bool allowsTextRanges() const;
     592#else
     593    bool allowsTextRanges() const { return isTextControl(); }
     594#endif
     595
    590596#if PLATFORM(MAC)
    591597    RetainPtr<AccessibilityObjectWrapper> m_wrapper;
  • trunk/WebCore/accessibility/AccessibilityRenderObject.cpp

    r64139 r64475  
    23942394    if (isNativeTextControl())
    23952395        return toRenderTextControl(m_renderer)->visiblePositionForIndex(index);
    2396    
    2397     if (!isTextControl() && !m_renderer->isText())
     2396
     2397    if (!allowsTextRanges() && !m_renderer->isText())
    23982398        return VisiblePosition();
    23992399   
     
    26542654IntRect AccessibilityRenderObject::doAXBoundsForRange(const PlainTextRange& range) const
    26552655{
    2656     if (isTextControl())
     2656    if (allowsTextRanges())
    26572657        return boundsForVisiblePositionRange(visiblePositionRangeForRange(range));
    26582658    return IntRect();
  • trunk/WebCore/accessibility/gtk/AccessibilityObjectAtk.cpp

    r58094 r64475  
    9494}
    9595
     96bool AccessibilityObject::allowsTextRanges() const
     97{
     98    return isTextControl() || isWebArea() || isGroup() || isLink() || isHeading();
     99}
     100
    96101} // namespace WebCore
    97102
  • trunk/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp

    r62164 r64475  
    12601260}
    12611261
    1262 static void webkit_accessible_text_get_character_extents(AtkText* text, gint offset, gint* x, gint* y, gint* width, gint* height, AtkCoordType coords)
    1263 {
    1264     IntRect extents = core(text)->doAXBoundsForRange(PlainTextRange(offset, 1));
    1265     // FIXME: Use the AtkCoordType
    1266     // Requires WebCore::ScrollView::contentsToScreen() to be implemented
    1267 
    1268 #if 0
     1262static IntRect textExtents(AtkText* text, gint startOffset, gint length, AtkCoordType coords)
     1263{
     1264    gchar* textContent = webkit_accessible_text_get_text(text, startOffset, -1);
     1265    gint textLength = g_utf8_strlen(textContent, -1);
     1266
     1267    // The first case (endOffset of -1) should work, but seems broken for all Gtk+ apps.
     1268    gint rangeLength = length;
     1269    if (rangeLength < 0 || rangeLength > textLength)
     1270        rangeLength = textLength;
     1271    AccessibilityObject* coreObject = core(text);
     1272
     1273    IntRect extents = coreObject->doAXBoundsForRange(PlainTextRange(startOffset, rangeLength));
    12691274    switch(coords) {
    12701275    case ATK_XY_SCREEN:
    1271         extents = core(text)->document()->view()->contentsToScreen(extents);
     1276        extents = coreObject->document()->view()->contentsToScreen(extents);
    12721277        break;
    12731278    case ATK_XY_WINDOW:
     
    12751280        break;
    12761281    }
    1277 #endif
    1278 
     1282
     1283    return extents;
     1284}
     1285
     1286static void webkit_accessible_text_get_character_extents(AtkText* text, gint offset, gint* x, gint* y, gint* width, gint* height, AtkCoordType coords)
     1287{
     1288    IntRect extents = textExtents(text, offset, 1, coords);
    12791289    *x = extents.x();
    12801290    *y = extents.y();
    12811291    *width = extents.width();
    12821292    *height = extents.height();
     1293}
     1294
     1295static void webkit_accessible_text_get_range_extents(AtkText* text, gint startOffset, gint endOffset, AtkCoordType coords, AtkTextRectangle* rect)
     1296{
     1297    IntRect extents = textExtents(text, startOffset, endOffset - startOffset + 1, coords);
     1298    rect->x = extents.x();
     1299    rect->y = extents.y();
     1300    rect->width = extents.width();
     1301    rect->height = extents.height();
    12831302}
    12841303
     
    13921411    iface->get_default_attributes = webkit_accessible_text_get_default_attributes;
    13931412    iface->get_character_extents = webkit_accessible_text_get_character_extents;
     1413    iface->get_range_extents = webkit_accessible_text_get_range_extents;
    13941414    iface->get_character_count = webkit_accessible_text_get_character_count;
    13951415    iface->get_offset_at_point = webkit_accessible_text_get_offset_at_point;
  • trunk/WebKit/gtk/ChangeLog

    r64462 r64475  
     12010-08-02  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Chris Fleizach.
     4
     5        [GTK] Implement support for get_character_extents and get_range_extents
     6        https://bugs.webkit.org/show_bug.cgi?id=25677
     7
     8        Added new unit tests to check get_character_extents and
     9        get_range_extents functions for the ATK_TEXT interface
     10
     11        Based on a previous patch by Joanmarie Diggs.
     12
     13        * tests/testatk.c:
     14        (test_webkit_atk_get_extents):
     15        (main):
     16
    1172010-08-02  Jeremy Orlow  <jorlow@chromium.org>
    218
  • trunk/WebKit/gtk/tests/testatk.c

    r62164 r64475  
    2727#if GLIB_CHECK_VERSION(2, 16, 0) && GTK_CHECK_VERSION(2, 14, 0)
    2828
     29static const char* centeredContents = "<html><body><p style='text-align: center;'>Short line</p><p style='text-align: center;'>Long-size line with some foo bar baz content</p><p style='text-align: center;'>Short line</p><p style='text-align: center;'>This is a multi-line paragraph<br />where the first line<br />is the biggest one</p></body></html>";
     30
    2931static const char* contents = "<html><body><p>This is a test. This is the second sentence. And this the third.</p></body></html>";
    3032
     
    737739    atk_attribute_set_free(set2);
    738740    atk_attribute_set_free(set3);
     741}
     742
     743static void test_webkit_atk_get_extents(void)
     744{
     745    WebKitWebView* webView;
     746    AtkObject* obj;
     747    GMainLoop* loop;
     748
     749    webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
     750    g_object_ref_sink(webView);
     751    GtkAllocation alloc = { 0, 0, 800, 600 };
     752    gtk_widget_size_allocate(GTK_WIDGET(webView), &alloc);
     753    webkit_web_view_load_string(webView, centeredContents, NULL, NULL, NULL);
     754    loop = g_main_loop_new(NULL, TRUE);
     755
     756    g_timeout_add(100, (GSourceFunc)bail_out, loop);
     757    g_main_loop_run(loop);
     758
     759    obj = gtk_widget_get_accessible(GTK_WIDGET(webView));
     760    g_assert(obj);
     761
     762    AtkText* short_text1 = ATK_TEXT(atk_object_ref_accessible_child(obj, 0));
     763    g_assert(ATK_IS_TEXT(short_text1));
     764    AtkText* long_text = ATK_TEXT(atk_object_ref_accessible_child(obj, 1));
     765    g_assert(ATK_IS_TEXT(long_text));
     766    AtkText* short_text2 = ATK_TEXT(atk_object_ref_accessible_child(obj, 2));
     767    g_assert(ATK_IS_TEXT(short_text2));
     768    AtkText* multiline_text = ATK_TEXT(atk_object_ref_accessible_child(obj, 3));
     769    g_assert(ATK_IS_TEXT(multiline_text));
     770
     771    // Start with window extents.
     772    AtkTextRectangle sline_window1, sline_window2, lline_window, mline_window;
     773    atk_text_get_range_extents(short_text1, 0, 10, ATK_XY_WINDOW, &sline_window1);
     774    atk_text_get_range_extents(long_text, 0, 44, ATK_XY_WINDOW, &lline_window);
     775    atk_text_get_range_extents(short_text2, 0, 10, ATK_XY_WINDOW, &sline_window2);
     776    atk_text_get_range_extents(multiline_text, 0, 60, ATK_XY_WINDOW, &mline_window);
     777
     778    // Check vertical line position.
     779    g_assert_cmpint(sline_window1.y + sline_window1.height, <=, lline_window.y);
     780    g_assert_cmpint(lline_window.y + lline_window.height + sline_window2.height, <=, mline_window.y);
     781
     782    // Paragraphs 1 and 3 have identical text and alignment.
     783    g_assert_cmpint(sline_window1.x, ==, sline_window2.x);
     784    g_assert_cmpint(sline_window1.width, ==, sline_window2.width);
     785    g_assert_cmpint(sline_window1.height, ==, sline_window2.height);
     786
     787    // All lines should be the same height; line 2 is the widest line.
     788    g_assert_cmpint(sline_window1.height, ==, lline_window.height);
     789    g_assert_cmpint(sline_window1.width, <, lline_window.width);
     790
     791    // Make sure the character extents jive with the range extents.
     792    gint x, y, width, height;
     793
     794    // First paragraph (short text)
     795    atk_text_get_character_extents(short_text1, 0, &x, &y, &width, &height, ATK_XY_WINDOW);
     796    g_assert_cmpint(x, ==, sline_window1.x);
     797    g_assert_cmpint(y, ==, sline_window1.y);
     798    g_assert_cmpint(height, ==, sline_window1.height);
     799
     800    atk_text_get_character_extents(short_text1, 9, &x, &y, &width, &height, ATK_XY_WINDOW);
     801    g_assert_cmpint(x, ==, sline_window1.x + sline_window1.width - width);
     802    g_assert_cmpint(y, ==, sline_window1.y);
     803    g_assert_cmpint(height, ==, sline_window1.height);
     804
     805    // Second paragraph (long text)
     806    atk_text_get_character_extents(long_text, 0, &x, &y, &width, &height, ATK_XY_WINDOW);
     807    g_assert_cmpint(x, ==, lline_window.x);
     808    g_assert_cmpint(y, ==, lline_window.y);
     809    g_assert_cmpint(height, ==, lline_window.height);
     810
     811    atk_text_get_character_extents(long_text, 43, &x, &y, &width, &height, ATK_XY_WINDOW);
     812    g_assert_cmpint(x, ==, lline_window.x + lline_window.width - width);
     813    g_assert_cmpint(y, ==, lline_window.y);
     814    g_assert_cmpint(height, ==, lline_window.height);
     815
     816    // Third paragraph (short text)
     817    atk_text_get_character_extents(short_text2, 0, &x, &y, &width, &height, ATK_XY_WINDOW);
     818    g_assert_cmpint(x, ==, sline_window2.x);
     819    g_assert_cmpint(y, ==, sline_window2.y);
     820    g_assert_cmpint(height, ==, sline_window2.height);
     821
     822    atk_text_get_character_extents(short_text2, 9, &x, &y, &width, &height, ATK_XY_WINDOW);
     823    g_assert_cmpint(x, ==, sline_window2.x + sline_window2.width - width);
     824    g_assert_cmpint(y, ==, sline_window2.y);
     825    g_assert_cmpint(height, ==, sline_window2.height);
     826
     827    // Four paragraph (3 lines multi-line text)
     828    atk_text_get_character_extents(multiline_text, 0, &x, &y, &width, &height, ATK_XY_WINDOW);
     829    g_assert_cmpint(x, ==, mline_window.x);
     830    g_assert_cmpint(y, ==, mline_window.y);
     831    g_assert_cmpint(3 * height, ==, mline_window.height);
     832
     833    atk_text_get_character_extents(multiline_text, 59, &x, &y, &width, &height, ATK_XY_WINDOW);
     834    // Last line won't fill the whole width of the rectangle
     835    g_assert_cmpint(x, <=, mline_window.x + mline_window.width - width);
     836    g_assert_cmpint(y, ==, mline_window.y + mline_window.height - height);
     837    g_assert_cmpint(height, <=, mline_window.height);
     838
     839    g_object_unref(short_text1);
     840    g_object_unref(short_text2);
     841    g_object_unref(long_text);
     842    g_object_unref(multiline_text);
     843    g_object_unref(webView);
    739844}
    740845
     
    755860    g_test_add_func("/webkit/atk/getHeadersInTable", testWebkitAtkGetHeadersInTable);
    756861    g_test_add_func("/webkit/atk/textAttributes", testWebkitAtkTextAttributes);
     862    g_test_add_func("/webkit/atk/get_extents", test_webkit_atk_get_extents);
    757863    return g_test_run ();
    758864}
Note: See TracChangeset for help on using the changeset viewer.