Changeset 104446 in webkit


Ignore:
Timestamp:
Jan 9, 2012 2:16:20 AM (12 years ago)
Author:
mario@webkit.org
Message:

[Gtk] Regression: text-inserted events lack text inserted and current line
https://bugs.webkit.org/show_bug.cgi?id=72830

Reviewed by Martin Robinson.

Source/WebCore:

Fix issue getting the exposed text for an accessibility object at,
before of after a given offset, after changing it at least once.

  • accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:

(webkit_accessible_class_init): Don't initialize
gailTextUtilQuark, it won't be used anymore.
(getGailTextUtilForAtk): Don't cache the GailTextUtil as object
data, but create a new one each time this function is called.
(webkit_accessible_text_get_caret_offset): Simplified code by
using the new focusedObjectAndCaretOffsetUnignored function,
instead of the old objectAndOffsetUnignored function.
(focusedObjectAndCaretOffsetUnignored): Rewrite of the old
objectAndOffsetUnignored function so it now needs less
parameters than before and takes care of carefully selecting the
start and end visible positions to calculate the position of the
caret from the point of view of the accessibility object of
reference passed as the only input parameter now. Updated callers.

  • accessibility/gtk/AccessibilityObjectWrapperAtk.h:
  • editing/gtk/FrameSelectionGtk.cpp:

(WebCore::FrameSelection::notifyAccessibilityForSelectionChange):
Simplified code by calling to focusedObjectAndCaretOffsetUnignored
function, instead of the old objectAndOffsetUnignored function.

Source/WebKit/gtk:

Updated unit tests to check that both getting the current position
for the caret and the exposed text at, before or after a given
offset for an accessible object works as expected.

  • tests/testatk.c:

(runGetTextTests): For objects implementing AtkEditableText, try
to change the exposed text and retrieve it again as a full line.
(testWebkitAtkCaretOffsets): For a text control (a text entry),
set the caret offset to a value greater than 1 and retrieve it.

Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r104445 r104446  
     12012-01-09  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        [Gtk] Regression: text-inserted events lack text inserted and current line
     4        https://bugs.webkit.org/show_bug.cgi?id=72830
     5
     6        Reviewed by Martin Robinson.
     7
     8        Fix issue getting the exposed text for an accessibility object at,
     9        before of after a given offset, after changing it at least once.
     10
     11        * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
     12        (webkit_accessible_class_init): Don't initialize
     13        gailTextUtilQuark, it won't be used anymore.
     14        (getGailTextUtilForAtk): Don't cache the GailTextUtil as object
     15        data, but create a new one each time this function is called.
     16        (webkit_accessible_text_get_caret_offset): Simplified code by
     17        using the new focusedObjectAndCaretOffsetUnignored function,
     18        instead of the old objectAndOffsetUnignored function.
     19        (focusedObjectAndCaretOffsetUnignored): Rewrite of the old
     20        objectAndOffsetUnignored function so it now needs less
     21        parameters than before and takes care of carefully selecting the
     22        start and end visible positions to calculate the position of the
     23        caret from the point of view of the accessibility object of
     24        reference passed as the only input parameter now. Updated callers.
     25        * accessibility/gtk/AccessibilityObjectWrapperAtk.h:
     26
     27        * editing/gtk/FrameSelectionGtk.cpp:
     28        (WebCore::FrameSelection::notifyAccessibilityForSelectionChange):
     29        Simplified code by calling to focusedObjectAndCaretOffsetUnignored
     30        function, instead of the old objectAndOffsetUnignored function.
     31
    1322012-01-09  Antti Koivisto  <antti@apple.com>
    233
  • trunk/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp

    r101348 r104446  
    7777using namespace WebCore;
    7878
    79 static GQuark gailTextUtilQuark = 0;
    8079static GQuark hyperlinkObjectQuark = 0;
    8180
     
    847846    klass->ref_relation_set = webkit_accessible_ref_relation_set;
    848847
    849     gailTextUtilQuark = g_quark_from_static_string("webkit-accessible-gail-text-util");
    850848    hyperlinkObjectQuark = g_quark_from_static_string("webkit-accessible-hyperlink-object");
    851849}
     
    12941292static GailTextUtil* getGailTextUtilForAtk(AtkText* textObject)
    12951293{
    1296     gpointer data = g_object_get_qdata(G_OBJECT(textObject), gailTextUtilQuark);
    1297     if (data)
    1298         return static_cast<GailTextUtil*>(data);
    1299 
    13001294    GailTextUtil* gailTextUtil = gail_text_util_new();
    13011295    gail_text_util_text_setup(gailTextUtil, webkit_accessible_text_get_text(textObject, 0, -1));
    1302     g_object_set_qdata_full(G_OBJECT(textObject), gailTextUtilQuark, gailTextUtil, g_object_unref);
    13031296    return gailTextUtil;
    13041297}
     
    13531346        return 0;
    13541347
    1355     Document* document = coreObject->document();
    1356     if (!document)
    1357         return 0;
    1358 
    1359     Node* focusedNode = coreObject->selection().end().deprecatedNode();
    1360     if (!focusedNode)
    1361         return 0;
    1362 
    1363     RenderObject* focusedRenderer = focusedNode->renderer();
    1364     AccessibilityObject* focusedObject = document->axObjectCache()->getOrCreate(focusedRenderer);
    1365 
    13661348    int offset;
    1367     // Don't ignore links if the offset is being requested for a link.
    1368     if (!objectAndOffsetUnignored(focusedObject, offset, !coreObject->isLink()))
     1349    if (!objectFocusedAndCaretOffsetUnignored(coreObject, offset))
    13691350        return 0;
    13701351
     
    27342715}
    27352716
    2736 AccessibilityObject* objectAndOffsetUnignored(AccessibilityObject* coreObject, int& offset, bool ignoreLinks)
     2717AccessibilityObject* objectFocusedAndCaretOffsetUnignored(AccessibilityObject* referenceObject, int& offset)
    27372718{
    27382719    // Indication that something bogus has transpired.
    27392720    offset = -1;
    27402721
    2741     AccessibilityObject* realObject = coreObject;
    2742     if (realObject->accessibilityIsIgnored())
    2743         realObject = realObject->parentObjectUnignored();
    2744     if (!realObject)
    2745         return 0;
    2746 
    2747     if (ignoreLinks && realObject->isLink())
    2748         realObject = realObject->parentObjectUnignored();
    2749     if (!realObject)
    2750         return 0;
    2751 
    2752     Node* node = realObject->node();
    2753     if (node) {
    2754         VisiblePosition startPosition = VisiblePosition(positionBeforeNode(node), DOWNSTREAM);
    2755         VisiblePosition endPosition = realObject->selection().visibleEnd();
    2756 
    2757         if (startPosition == endPosition)
    2758             offset = 0;
    2759         else if (!isStartOfLine(endPosition)) {
    2760             RefPtr<Range> range = makeRange(startPosition, endPosition.previous());
    2761             offset = TextIterator::rangeLength(range.get(), true) + 1;
    2762         } else {
    2763             RefPtr<Range> range = makeRange(startPosition, endPosition);
    2764             offset = TextIterator::rangeLength(range.get(), true);
    2765         }
    2766 
    2767     }
    2768 
    2769     return realObject;
     2722    Document* document = referenceObject->document();
     2723    if (!document)
     2724        return 0;
     2725
     2726    Node* focusedNode = referenceObject->selection().end().containerNode();
     2727    if (!focusedNode)
     2728        return 0;
     2729
     2730    RenderObject* focusedRenderer = focusedNode->renderer();
     2731    if (!focusedRenderer)
     2732        return 0;
     2733
     2734    AccessibilityObject* focusedObject = document->axObjectCache()->getOrCreate(focusedRenderer);
     2735    if (!focusedObject)
     2736        return 0;
     2737
     2738    // Look for the actual (not ignoring accessibility) selected object.
     2739    if (focusedObject->accessibilityIsIgnored())
     2740        focusedObject = focusedObject->parentObjectUnignored();
     2741    if (!focusedObject)
     2742        return 0;
     2743
     2744    // Don't ignore links if the offset is being requested for a link.
     2745    if (!referenceObject->isLink() && focusedObject->isLink())
     2746        focusedObject = focusedObject->parentObjectUnignored();
     2747    if (!focusedObject)
     2748        return 0;
     2749
     2750    Node* startNode = 0;
     2751    if (focusedObject != referenceObject || focusedObject->isTextControl()) {
     2752        // We need to use the first child's node of the reference
     2753        // object as the start point to calculate the caret offset
     2754        // because we want it to be relative to the object of
     2755        // reference, not just to the focused object (which could have
     2756        // previous siblings which should be taken into account too).
     2757        AccessibilityObject* axFirstChild = referenceObject->firstChild();
     2758        if (axFirstChild)
     2759            startNode = axFirstChild->node();
     2760    }
     2761    if (!startNode)
     2762        startNode = focusedObject->node();
     2763
     2764    VisiblePosition startPosition = VisiblePosition(firstPositionInNode(startNode), DOWNSTREAM);
     2765    VisiblePosition endPosition = focusedObject->selection().visibleEnd();
     2766
     2767    if (startPosition == endPosition)
     2768        offset = 0;
     2769    else if (!isStartOfLine(endPosition)) {
     2770        RefPtr<Range> range = makeRange(startPosition, endPosition.previous());
     2771        offset = TextIterator::rangeLength(range.get(), true) + 1;
     2772    } else {
     2773        RefPtr<Range> range = makeRange(startPosition, endPosition);
     2774        offset = TextIterator::rangeLength(range.get(), true);
     2775    }
     2776
     2777    return focusedObject;
    27702778}
    27712779
  • trunk/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.h

    r95901 r104446  
    6161AtkObject* webkit_accessible_get_focused_element(WebKitAccessible* accessible);
    6262
    63 WebCore::AccessibilityObject* objectAndOffsetUnignored(WebCore::AccessibilityObject* coreObject, int& offset, bool ignoreLinks);
     63WebCore::AccessibilityObject* objectFocusedAndCaretOffsetUnignored(WebCore::AccessibilityObject*, int& offset);
    6464
    6565G_END_DECLS
  • trunk/Source/WebCore/editing/gtk/FrameSelectionGtk.cpp

    r95901 r104446  
    8181        return;
    8282
    83     // Reset lastFocuseNode and return for no valid selections.
     83    // Return for no valid selections.
    8484    if (!m_selection.start().isNotNull() || !m_selection.end().isNotNull())
    8585        return;
    8686
    87     RenderObject* focusedNode = m_selection.end().deprecatedNode()->renderer();
    88     AccessibilityObject* accessibilityObject = m_frame->document()->axObjectCache()->getOrCreate(focusedNode);
    89 
    90     // Need to check this as getOrCreate could return 0,
     87    // Look for the accessibility object for the Frame.
     88    AccessibilityObject* accessibilityObject = m_frame->document()->axObjectCache()->rootObjectForFrame(m_frame);
    9189    if (!accessibilityObject)
    9290        return;
    9391
    9492    int offset;
    95     // Always report the events w.r.t. the non-linked unignored parent. (i.e. ignoreLinks == true).
    96     RefPtr<AccessibilityObject> object = objectAndOffsetUnignored(accessibilityObject, offset, true);
     93    RefPtr<AccessibilityObject> object = objectFocusedAndCaretOffsetUnignored(accessibilityObject, offset);
    9794    if (!object)
    9895        return;
  • trunk/Source/WebKit/gtk/ChangeLog

    r104194 r104446  
     12012-01-09  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        [Gtk] Regression: text-inserted events lack text inserted and current line
     4        https://bugs.webkit.org/show_bug.cgi?id=72830
     5
     6        Reviewed by Martin Robinson.
     7
     8        Updated unit tests to check that both getting the current position
     9        for the caret and the exposed text at, before or after a given
     10        offset for an accessible object works as expected.
     11
     12        * tests/testatk.c:
     13        (runGetTextTests): For objects implementing AtkEditableText, try
     14        to change the exposed text and retrieve it again as a full line.
     15        (testWebkitAtkCaretOffsets): For a text control (a text entry),
     16        set the caret offset to a value greater than 1 and retrieve it.
     17
    1182012-01-05  Martin Robinson  <mrobinson@igalia.com>
    219
  • trunk/Source/WebKit/gtk/tests/testatk.c

    r101960 r104446  
    6464static 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>";
    6565
    66 static 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>";
     66static 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><input type='text'' name='foo'' value='foo bar baz' /></body></html>";
    6767
    6868static 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>";
     
    235235                        44, " This is the second sentence.", 15, 44);
    236236
    237     /* It's trick to test these properly right now, since our a11y
     237    /* It's tricky to test these properly right now, since our a11y
    238238       implementation splits different lines in different a11y items. */
    239239    /* ATK_TEXT_BOUNDARY_LINE_START */
     
    244244    testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END,
    245245                        0, "This is a test. This is the second sentence. And this the third.", 0, 64);
     246
     247    /* For objects implementing AtkEditableText, try to change the
     248       exposed text and retrieve it again as a full line.
     249       (see https://bugs.webkit.org/show_bug.cgi?id=72830) */
     250    if (ATK_IS_EDITABLE_TEXT(textObject)) {
     251        atk_editable_text_set_text_contents(ATK_EDITABLE_TEXT(textObject), "foo bar baz");
     252        testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_START, 0, "foo bar baz", 0, 11);
     253        testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, 0, "foo bar baz", 0, 11);
     254    }
    246255}
    247256
     
    334343    result = atk_text_set_caret_offset(ATK_TEXT(comboBoxOption), 1);
    335344    g_assert_cmpint(result, ==, FALSE);
     345
     346    AtkObject* textEntry = atk_object_ref_accessible_child(panel, 1);
     347    g_assert(ATK_IS_OBJECT(textEntry));
     348    g_assert(atk_object_get_role(textEntry) == ATK_ROLE_ENTRY);
     349    g_assert(ATK_IS_TEXT(textEntry));
     350    text = atk_text_get_text(ATK_TEXT(textEntry), 0, -1);
     351    g_assert_cmpstr(text, ==, "foo bar baz");
     352
     353    result = atk_text_set_caret_offset(ATK_TEXT(textEntry), 5);
     354    g_assert_cmpint(result, ==, TRUE);
     355    offset = atk_text_get_caret_offset(ATK_TEXT(textEntry));
     356    g_assert_cmpint(offset, ==, 5);
    336357
    337358    g_object_unref(header);
     
    343364    g_object_unref(menuPopup);
    344365    g_object_unref(comboBoxOption);
     366    g_object_unref(textEntry);
    345367    g_object_unref(webView);
    346368}
Note: See TracChangeset for help on using the changeset viewer.