Changeset 155516 in webkit


Ignore:
Timestamp:
Sep 11, 2013 3:32:00 AM (11 years ago)
Author:
mario@webkit.org
Message:

[GTK] Reimplement atk_text_get_text_*_offset for LINE boundaries
https://bugs.webkit.org/show_bug.cgi?id=114872

Reviewed by Gustavo Noronha Silva.

Source/WebCore:

Re-implement these functions without using GailTextUtil nor Pango.

  • accessibility/atk/WebKitAccessibleInterfaceText.cpp:

(lineAtPositionForAtkBoundary): New helper function to find the
line at a given position considering values of AtkTextBoundary.
(webkitAccessibleTextLineForBoundary): New function,
implementing atk_text_get_text_*_offset for LINE.
(webkitAccessibleTextGetTextForOffset): Replace usage of Gail for
LINE boundaries with webkitAccessibleTextLineForBoundary().

Source/WebKit/gtk:

Fixed wrong unit test.

  • tests/testatk.c:

(testWebkitAtkGetTextAtOffsetWithPreformattedText): This test was
reporting a trailing '\n' for some reason for a <pre> block, which
is plainly wrong since, in order to return that, there should be
at least a trailing empty space after that and before the </pre>
closing tag. This is fixed now.
(testWebkitAtkGetTextAtOffsetWithWrappedLines): Uncommented tests
that were previously not passing due to a bug in GailTextUtil.

Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r155514 r155516  
     12013-09-10  Mario Sanchez Prada  <mario.prada@samsung.com>
     2
     3        [GTK] Reimplement atk_text_get_text_*_offset for LINE boundaries
     4        https://bugs.webkit.org/show_bug.cgi?id=114872
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        Re-implement these functions without using GailTextUtil nor Pango.
     9
     10        * accessibility/atk/WebKitAccessibleInterfaceText.cpp:
     11        (lineAtPositionForAtkBoundary): New helper function to find the
     12        line at a given position considering values of AtkTextBoundary.
     13        (webkitAccessibleTextLineForBoundary): New function,
     14        implementing atk_text_get_text_*_offset for LINE.
     15        (webkitAccessibleTextGetTextForOffset): Replace usage of Gail for
     16        LINE boundaries with webkitAccessibleTextLineForBoundary().
     17
    1182013-09-11  Andreas Kling  <akling@apple.com>
    219
  • trunk/Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp

    r155308 r155516  
    974974}
    975975
     976static VisibleSelection lineAtPositionForAtkBoundary(const AccessibilityObject* coreObject, const VisiblePosition& position, AtkTextBoundary boundaryType)
     977{
     978    VisiblePosition startPosition;
     979    VisiblePosition endPosition;
     980
     981    switch (boundaryType) {
     982    case ATK_TEXT_BOUNDARY_LINE_START:
     983        startPosition = isStartOfLine(position) ? position : logicalStartOfLine(position);
     984        endPosition = logicalEndOfLine(position);
     985
     986        // In addition to checking that we are not at the end of a block, we need
     987        // to check that endPosition has not UPSTREAM affinity, since that would
     988        // cause trouble inside of text controls (we would be advancing too much).
     989        if (!isEndOfBlock(endPosition) && endPosition.affinity() != UPSTREAM)
     990            endPosition = endPosition.next();
     991        break;
     992
     993    case ATK_TEXT_BOUNDARY_LINE_END:
     994        startPosition = isEndOfLine(position) ? position : logicalStartOfLine(position);
     995        if (!isStartOfBlock(startPosition))
     996            startPosition = startPosition.previous();
     997        endPosition = logicalEndOfLine(position);
     998        break;
     999
     1000    default:
     1001        ASSERT_NOT_REACHED();
     1002    }
     1003
     1004    VisibleSelection selectedLine(startPosition, endPosition);
     1005
     1006    // We mark the selection as 'upstream' so we can use that information later,
     1007    // when finding the actual offsets in getSelectionOffsetsForObject().
     1008    if (boundaryType == ATK_TEXT_BOUNDARY_LINE_END)
     1009        selectedLine.setAffinity(UPSTREAM);
     1010
     1011    return selectedLine;
     1012}
     1013
     1014static char* webkitAccessibleTextLineForBoundary(AtkText* text, int offset, AtkTextBoundary boundaryType, GetTextRelativePosition textPosition, int* startOffset, int* endOffset)
     1015{
     1016    AccessibilityObject* coreObject = core(text);
     1017    Document* document = coreObject->document();
     1018    if (!document)
     1019        return emptyTextSelectionAtOffset(0, startOffset, endOffset);
     1020
     1021    Node* node = getNodeForAccessibilityObject(coreObject);
     1022    if (!node)
     1023        return emptyTextSelectionAtOffset(0, startOffset, endOffset);
     1024
     1025    int actualOffset = atkOffsetToWebCoreOffset(text, offset);
     1026
     1027    // Besides the usual conversion from ATK offsets to WebCore offsets,
     1028    // we need to consider the potential embedded objects that might have been
     1029    // inserted in the text exposed through AtkText when calculating the offset.
     1030    actualOffset -= numberOfReplacedElementsBeforeOffset(text, actualOffset);
     1031
     1032    VisiblePosition caretPosition = coreObject->visiblePositionForIndex(actualOffset);
     1033    VisibleSelection currentLine = lineAtPositionForAtkBoundary(coreObject, caretPosition, boundaryType);
     1034
     1035    // Take into account other relative positions, if needed, by
     1036    // calculating the new position that we would need to consider.
     1037    VisiblePosition newPosition = caretPosition;
     1038    switch (textPosition) {
     1039    case GetTextPositionAt:
     1040        // No need to do additional work if we are using the "at" position, we just
     1041        // explicitly list this case option to catch invalid values in the default case.
     1042        break;
     1043
     1044    case GetTextPositionBefore:
     1045        // Early return if asking for the previous line while already at the beginning.
     1046        if (isFirstVisiblePositionInNode(currentLine.visibleStart(), node))
     1047            return emptyTextSelectionAtOffset(0, startOffset, endOffset);
     1048        newPosition = currentLine.visibleStart().previous();
     1049        break;
     1050
     1051    case GetTextPositionAfter:
     1052        // Early return if asking for the following word while already at the end.
     1053        if (isLastVisiblePositionInNode(currentLine.visibleEnd(), node))
     1054            return emptyTextSelectionAtOffset(accessibilityObjectLength(coreObject), startOffset, endOffset);
     1055        newPosition = currentLine.visibleEnd().next();
     1056        break;
     1057
     1058    default:
     1059        ASSERT_NOT_REACHED();
     1060    }
     1061
     1062    // Determine the relevant line we are actually interested in
     1063    // and calculate the ATK offsets for it, then return everything.
     1064    VisibleSelection selectedLine = newPosition != caretPosition ? lineAtPositionForAtkBoundary(coreObject, newPosition, boundaryType) : currentLine;
     1065    getSelectionOffsetsForObject(coreObject, selectedLine, *startOffset, *endOffset);
     1066
     1067    // We might need to adjust the start or end offset to include the list item marker,
     1068    // if present, when printing the first or the last full line for a list item.
     1069    RenderObject* renderer = coreObject->renderer();
     1070    if (renderer->isListItem()) {
     1071        // For Left-to-Right, the list item marker is at the beginning of the exposed text.
     1072        if (renderer->style()->direction() == LTR && isFirstVisiblePositionInNode(selectedLine.visibleStart(), node))
     1073            *startOffset = 0;
     1074
     1075        // For Right-to-Left, the list item marker is at the end of the exposed text.
     1076        if (renderer->style()->direction() == RTL && isLastVisiblePositionInNode(selectedLine.visibleEnd(), node))
     1077            *endOffset = accessibilityObjectLength(coreObject);
     1078    }
     1079
     1080    return webkitAccessibleTextGetText(text, *startOffset, *endOffset);
     1081}
     1082
    9761083static gchar* webkitAccessibleTextGetTextForOffset(AtkText* text, gint offset, AtkTextBoundary boundaryType, GetTextRelativePosition textPosition, gint* startOffset, gint* endOffset)
    9771084{
     
    9881095    if (boundaryType == ATK_TEXT_BOUNDARY_SENTENCE_START || boundaryType == ATK_TEXT_BOUNDARY_SENTENCE_END)
    9891096        return webkitAccessibleTextSentenceForBoundary(text, offset, boundaryType, textPosition, startOffset, endOffset);
     1097
     1098    if (boundaryType == ATK_TEXT_BOUNDARY_LINE_START || boundaryType == ATK_TEXT_BOUNDARY_LINE_END)
     1099        return webkitAccessibleTextLineForBoundary(text, offset, boundaryType, textPosition, startOffset, endOffset);
    9901100
    9911101#if PLATFORM(GTK)
  • trunk/Source/WebKit/gtk/ChangeLog

    r155507 r155516  
     12013-09-10  Mario Sanchez Prada  <mario.prada@samsung.com>
     2
     3        [GTK] Reimplement atk_text_get_text_*_offset for LINE boundaries
     4        https://bugs.webkit.org/show_bug.cgi?id=114872
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        Fixed wrong unit test.
     9
     10        * tests/testatk.c:
     11        (testWebkitAtkGetTextAtOffsetWithPreformattedText): This test was
     12        reporting a trailing '\n' for some reason for a <pre> block, which
     13        is plainly wrong since, in order to return that, there should be
     14        at least a trailing empty space after that and before the </pre>
     15        closing tag. This is fixed now.
     16        (testWebkitAtkGetTextAtOffsetWithWrappedLines): Uncommented tests
     17        that were previously not passing due to a bug in GailTextUtil.
     18
    1192013-09-11  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
    220
  • trunk/Source/WebKit/gtk/tests/testatk.c

    r154953 r155516  
    3434static const char* contentsWithNewlines = "<html><body><p>This is a test. \n\nThis\n is the second sentence. And this the third.</p></body></html>";
    3535
    36 static const char* contentsWithPreformattedText = "<html><body><pre>\n\t\n\tfirst line\n\tsecond line\n</pre></body></html>";
     36static const char* contentsWithPreformattedText = "<html><body><pre>\n\t\n\tfirst line\n\tsecond line\n\t\n</pre></body></html>";
    3737
    3838static const char* contentsWithSpecialChars = "<html><body><p>&laquo;&nbsp;This is a paragraph with &ldquo;special&rdquo; characters inside.&nbsp;&raquo;</p><ul><li style='max-width:100px;'>List item with some text that wraps across different lines.</li><li style='max-width:100px;'><p>List item with some text that wraps across different lines.</p></li></ul></body></html>";
     
    908908    g_assert(ATK_IS_TEXT(preformattedText));
    909909    char* text = atk_text_get_text(ATK_TEXT(preformattedText), 0, -1);
    910     g_assert_cmpstr(text, ==, "\t\n\tfirst line\n\tsecond line\n");
     910    g_assert_cmpstr(text, ==, "\t\n\tfirst line\n\tsecond line\n\t\n");
    911911    g_free(text);
    912912
     
    10281028    testGetTextFunction(paragraph1, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_LINE_START, 17, "of the maximum ", 33, 48);
    10291029
    1030     /* The following line won't work at the moment because of a bug in GailTextUtil.
    1031        see https://bugzilla.gnome.org/show_bug.cgi?id=703554
    1032        testGetTextFunction(paragraph1, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_LINE_END, 17, "This is one line", 0, 16); */
     1030    testGetTextFunction(paragraph1, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_LINE_END, 17, "This is one line", 0, 16);
    10331031    testGetTextFunction(paragraph1, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, 17, " wrapped because", 16, 32);
    10341032    testGetTextFunction(paragraph1, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_LINE_END, 17, " of the maximum", 32, 47);
     
    10601058    testGetTextFunction(paragraph2, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_LINE_START, 30, "line break in the middle.", 51, 76);
    10611059
    1062     /* The following line won't work at the moment because of a bug in GailTextUtil.
    1063        see https://bugzilla.gnome.org/show_bug.cgi?id=703554
    1064        testGetTextFunction(paragraph2, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_LINE_END, 30, "This is another line wrapped", 0, 28); */
     1060    testGetTextFunction(paragraph2, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_LINE_END, 30, "This is another line wrapped", 0, 28);
    10651061    testGetTextFunction(paragraph2, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, 30, "\nbecause of one forced", 28, 50);
    10661062    testGetTextFunction(paragraph2, atk_text_get_text_after_offset, ATK_TEXT_BOUNDARY_LINE_END, 30, "\nline break in the middle.", 50, 76);
Note: See TracChangeset for help on using the changeset viewer.