Changeset 281920 in webkit


Ignore:
Timestamp:
Sep 2, 2021 5:45:25 AM (11 months ago)
Author:
Andres Gonzalez
Message:

Braille display is blank in contenteditable elements when the field is followed by another element.
https://bugs.webkit.org/show_bug.cgi?id=229713
rdar://82095237

Reviewed by Chris Fleizach.

Source/WebCore:

Test: accessibility/mac/range-for-line-index.html

We were making the length of line ranges in text fields 1 more than the
number of characters in the line even when no line break character
existed, like in the case of a single line text field.
Clients like VoiceOver expect the length of the line ranges in text
fields to match the number of charaters in the line including the line
break if one exists.

  • accessibility/AccessibilityRenderObject.cpp:

(WebCore::isHardLineBreak): Helper function used in doAXRangeForLine.
Determines whether the given VisiblePosition corresponds to a hard line
break.
(WebCore::AccessibilityRenderObject::doAXRangeForLine const):
Returns a PlainTextRange whose length matches the number of characters
in the given line, accounting for line break characters.

LayoutTests:

  • accessibility/mac/range-for-line-index-expected.txt: Added.
  • accessibility/mac/range-for-line-index.html: Added.
  • platform/mac/accessibility/content-editable-as-textarea-expected.txt:
  • platform/win/accessibility/content-editable-as-textarea-expected.txt:
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r281918 r281920  
     12021-09-02  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        Braille display is blank in contenteditable elements when the field is followed by another element.
     4        https://bugs.webkit.org/show_bug.cgi?id=229713
     5        rdar://82095237
     6
     7        Reviewed by Chris Fleizach.
     8
     9        * accessibility/mac/range-for-line-index-expected.txt: Added.
     10        * accessibility/mac/range-for-line-index.html: Added.
     11        * platform/mac/accessibility/content-editable-as-textarea-expected.txt:
     12        * platform/win/accessibility/content-editable-as-textarea-expected.txt:
     13
    1142021-09-02  Philippe Normand  <pnormand@igalia.com>
    215
  • trunk/LayoutTests/platform/mac/accessibility/content-editable-as-textarea-expected.txt

    r230064 r281920  
    3636Line for index(7): 1
    3737Range for line(0): {0, 6}
    38 Range for line(1): {6, 6}
     38Range for line(1): {6, 5}
    3939Bounds for range: {{-1.000000, -1.000000}, {32.000000, 36.000000}}
    4040Selected text range: {0, 3}
  • trunk/LayoutTests/platform/win/accessibility/content-editable-as-textarea-expected.txt

    r180176 r281920  
    3535Line for index(7): 1
    3636Range for line(0): {0, 6}
    37 Range for line(1): {6, 6}
     37Range for line(1): {6, 5}
    3838Bounds for range: {{-1.000000, -1.000000}, {31.000000, 36.000000}}
    3939Selected text range: {0, 3}
  • trunk/Source/WebCore/ChangeLog

    r281913 r281920  
     12021-09-02  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        Braille display is blank in contenteditable elements when the field is followed by another element.
     4        https://bugs.webkit.org/show_bug.cgi?id=229713
     5        rdar://82095237
     6
     7        Reviewed by Chris Fleizach.
     8
     9        Test: accessibility/mac/range-for-line-index.html
     10
     11        We were making the length of line ranges in text fields 1 more than the
     12        number of characters in the line even when no line break character
     13        existed, like in the case of a single line text field.
     14        Clients like VoiceOver expect the length of the line ranges in text
     15        fields to match the number of charaters in the line including the line
     16        break if one exists.
     17
     18        * accessibility/AccessibilityRenderObject.cpp:
     19        (WebCore::isHardLineBreak): Helper function used in doAXRangeForLine.
     20        Determines whether the given VisiblePosition corresponds to a hard line
     21        break.
     22        (WebCore::AccessibilityRenderObject::doAXRangeForLine const):
     23        Returns a PlainTextRange whose length matches the number of characters
     24        in the given line, accounting for line break characters.
     25
    1262021-09-02  Rob Buis  <rbuis@igalia.com>
    227
  • trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp

    r281691 r281920  
    5252#include "HTMLAreaElement.h"
    5353#include "HTMLAudioElement.h"
     54#include "HTMLBRElement.h"
    5455#include "HTMLDetailsElement.h"
    5556#include "HTMLFormElement.h"
     
    24442445}
    24452446
     2447static bool isHardLineBreak(const VisiblePosition& position)
     2448{
     2449    if (!isEndOfLine(position))
     2450        return false;
     2451
     2452    auto next = position.next();
     2453
     2454    auto lineBreakRange = makeSimpleRange(position, next);
     2455    if (!lineBreakRange)
     2456        return false;
     2457
     2458    TextIterator it(*lineBreakRange);
     2459    if (it.atEnd())
     2460        return false;
     2461
     2462    if (is<HTMLBRElement>(it.node()))
     2463        return true;
     2464
     2465    if (it.node() != position.deepEquivalent().anchorNode())
     2466        return false;
     2467
     2468    return it.text().length() == 1 && it.text()[0] == '\n';
     2469}
     2470
    24462471// Given a line number, the range of characters of the text associated with this accessibility
    24472472// object that contains the line number.
     
    24492474{
    24502475    if (!isTextControl())
    2451         return PlainTextRange();
    2452    
    2453     // iterate to the specified line
    2454     VisiblePosition visiblePos = visiblePositionForIndex(0);
    2455     VisiblePosition savedVisiblePos;
    2456     for (unsigned lineCount = lineNumber; lineCount; lineCount -= 1) {
    2457         savedVisiblePos = visiblePos;
    2458         visiblePos = nextLinePosition(visiblePos, 0);
    2459         if (visiblePos.isNull() || visiblePos == savedVisiblePos)
    2460             return PlainTextRange();
     2476        return { };
     2477
     2478    // Iterate to the specified line.
     2479    auto lineStart = visiblePositionForIndex(0);
     2480    for (unsigned lineCount = lineNumber; lineCount; --lineCount) {
     2481        auto nextLineStart = nextLinePosition(lineStart, 0);
     2482        if (nextLineStart.isNull() || nextLineStart == lineStart)
     2483            return { };
     2484        lineStart = nextLineStart;
    24612485    }
    24622486
    24632487    // Get the end of the line based on the starting position.
    2464     VisiblePosition endPosition = endOfLine(visiblePos);
    2465 
    2466     int index1 = indexForVisiblePosition(visiblePos);
    2467     int index2 = indexForVisiblePosition(endPosition);
    2468    
    2469     // add one to the end index for a line break not caused by soft line wrap (to match AppKit)
    2470     if (endPosition.affinity() == Affinity::Downstream && endPosition.next().isNotNull())
    2471         index2 += 1;
    2472    
    2473     // return nil rather than an zero-length range (to match AppKit)
    2474     if (index1 == index2)
    2475         return PlainTextRange();
    2476    
    2477     return PlainTextRange(index1, index2 - index1);
     2488    auto lineEnd = endOfLine(lineStart);
     2489
     2490    int index1 = indexForVisiblePosition(lineStart);
     2491    int index2 = indexForVisiblePosition(lineEnd);
     2492
     2493    if (isHardLineBreak(lineEnd))
     2494        ++index2;
     2495
     2496    if (index1 < 0 || index2 < 0 || index2 <= index1)
     2497        return { };
     2498
     2499    return { static_cast<unsigned>(index1), static_cast<unsigned>(index2 - index1) };
    24782500}
    24792501
Note: See TracChangeset for help on using the changeset viewer.