Bug 233336 - AX: WebKit: need a method to get visible text and frame of an element on screen
Summary: AX: WebKit: need a method to get visible text and frame of an element on screen
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Accessibility (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: chris fleizach
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-11-18 14:42 PST by chris fleizach
Modified: 2021-11-22 12:34 PST (History)
10 users (show)

See Also:


Attachments
patch (26.34 KB, patch)
2021-11-18 14:52 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (26.37 KB, patch)
2021-11-18 16:04 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (26.39 KB, patch)
2021-11-18 16:06 PST, chris fleizach
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
patch (27.12 KB, patch)
2021-11-19 00:15 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (48.47 KB, patch)
2021-11-19 17:07 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (48.47 KB, patch)
2021-11-19 17:09 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (56.51 KB, patch)
2021-11-19 17:16 PST, chris fleizach
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
patch (57.65 KB, patch)
2021-11-19 23:58 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (49.81 KB, patch)
2021-11-19 23:59 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (49.52 KB, patch)
2021-11-20 00:00 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (49.52 KB, patch)
2021-11-20 00:11 PST, chris fleizach
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
patch (50.32 KB, patch)
2021-11-20 22:05 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (50.29 KB, patch)
2021-11-20 22:55 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (50.30 KB, patch)
2021-11-20 23:37 PST, chris fleizach
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
patch (50.36 KB, patch)
2021-11-21 21:34 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (50.19 KB, patch)
2021-11-21 21:37 PST, chris fleizach
no flags Details | Formatted Diff | Diff
patch (50.19 KB, patch)
2021-11-21 21:38 PST, chris fleizach
andresg_22: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
patch (50.16 KB, patch)
2021-11-22 07:41 PST, chris fleizach
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description chris fleizach 2021-11-18 14:42:16 PST
We can determine what elements are on screen, but there is no good way to determine if the content in an element is on screen. If an element is only partially visible, we need to know what the visible content is, and what the accessibilityFrame is of that content.

This is to support Books 

<rdar://problem/83657171>
Comment 1 chris fleizach 2021-11-18 14:52:05 PST
Created attachment 444744 [details]
patch
Comment 2 Tyler Wilcock 2021-11-18 15:48:11 PST
Comment on attachment 444744 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=444744&action=review

> Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm:491
> +    std::optional<BoundaryPoint> endBoundary = range->end;

Can these be auto?

> Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm:498
> +        std::optional<BoundaryPoint> testStartBoundary = makeBoundaryPoint(nextLinePosition);

Can this be auto?

> Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm:511
> +        std::optional<BoundaryPoint> testEndBoundary = makeBoundaryPoint(previousLinePosition);

Can this be auto?

> Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm:784
> +- (WebCore::AXCoreObject*)initializeBackingsStore

Is this a typo (extra s)? initializeBackingsStore vs. initializeBackingStore
Comment 3 chris fleizach 2021-11-18 15:49:55 PST
Comment on attachment 444744 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=444744&action=review

>> Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm:491
>> +    std::optional<BoundaryPoint> endBoundary = range->end;
> 
> Can these be auto?

no it picks the wrong type

>> Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm:498
>> +        std::optional<BoundaryPoint> testStartBoundary = makeBoundaryPoint(nextLinePosition);
> 
> Can this be auto?

ditto

>> Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm:784
>> +- (WebCore::AXCoreObject*)initializeBackingsStore
> 
> Is this a typo (extra s)? initializeBackingsStore vs. initializeBackingStore

yea true
Comment 4 chris fleizach 2021-11-18 16:04:56 PST
Created attachment 444750 [details]
patch
Comment 5 chris fleizach 2021-11-18 16:06:51 PST
Created attachment 444751 [details]
patch
Comment 6 chris fleizach 2021-11-19 00:15:39 PST
Created attachment 444785 [details]
patch
Comment 7 Andres Gonzalez 2021-11-19 05:41:05 PST
(In reply to chris fleizach from comment #6)
> Created attachment 444785 [details]
> patch

--- a/LayoutTests/accessibility/mac/visible-character-range.html
+++ a/LayoutTests/accessibility/mac/visible-character-range.html

+<script src="../../resources/js-test-pre.js"></script>

Do just 

+<script src="../../resources/js-test.js"></script>

no -pre.

+<p id="description"></p>
+<div id="console"></div>

Remove these two lines, no needed any more.

+    if (window.accessibilityController) {
+
+          var text = accessibilityController.accessibleElementById("group").childAtIndex(0);

looks like indentation is off here, extra spaces.

+<script src="../../resources/js-test-post.js"></script>

Remove this line, not needed any more.
Comment 8 Andres Gonzalez 2021-11-19 06:51:18 PST
(In reply to chris fleizach from comment #6)
> Created attachment 444785 [details]
> patch

--- a/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm
+++ a/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm

+#import "Position.h"
...
+#import "SimpleRange.h"

Doesn't seem right that we have to import Position.h here.

+- (CGRect)frameForRange:(NSRange)range
+{
+    auto webRange = [self convertToDOMRange:range];
+    if (!webRange)
+        return CGRectZero;
+    auto rect = self.axBackingObject->boundsForRange(*webRange);
+    return [self convertRectToSpace:rect space:AccessibilityConversionSpace::Screen];
+}

Don't we need to check for

    if (![self _prepareAccessibilityCall])

--- a/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.h
+++ a/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.h

+- (WebCore::FloatRect)accessibilityUnobscuredContentRect;

Shouldn't this be in the core code instead of in the wrapper?

+- (std::optional<WebCore::SimpleRange>)convertToDOMRange:(NSRange)range;
...
+extern NSRange convertToNSRange(const WebCore::SimpleRange&);

Can we make the first one also a function so that we have a symmetric pair of convert functions? Also consider "make" instead of "convert" for the names since it seems that that's the trend in other conversion functions in WebKit.

--- a/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm
+++ a/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm

+- (FloatRect)accessibilityUnobscuredContentRect
+{
+    auto document = self.axBackingObject->document();
+    if (!document || !document->view())
+        return { };
+    return FloatRect(snappedIntRect(document->view()->unobscuredContentRect()));
+}

Should be an AXCoreObject method instead.

+- (NSRange)accessibilityVisibleCharacterRange

The algorithm implementation of moving by line and intersecting with the given rect should be a core method, and then this wrapper method would do the conversions to NSRange of the result.

+    NSRange fullRange = convertToNSRange(SimpleRange(*startBoundary, *endBoundary));

Can we use initializer list instead of SimpleRange(...)?

+- (WebCore::AXCoreObject*)initializeBackingStore

This does more than initializing, it updates. Since we already are using updateObjectBackingStore, perhaps we can call this one just updateBackingStore? or _updateBackingStore?
Comment 9 Andres Gonzalez 2021-11-19 06:54:15 PST
(In reply to chris fleizach from comment #6)
> Created attachment 444785 [details]
> patch

The test should also be enabled on iOS.
Comment 10 chris fleizach 2021-11-19 17:07:52 PST
Created attachment 444872 [details]
patch
Comment 11 chris fleizach 2021-11-19 17:09:34 PST
Created attachment 444873 [details]
patch
Comment 12 chris fleizach 2021-11-19 17:16:15 PST
Created attachment 444874 [details]
patch
Comment 13 chris fleizach 2021-11-19 23:58:09 PST
Created attachment 444885 [details]
patch
Comment 14 chris fleizach 2021-11-19 23:59:01 PST
Created attachment 444886 [details]
patch
Comment 15 chris fleizach 2021-11-20 00:00:09 PST
Created attachment 444887 [details]
patch
Comment 16 chris fleizach 2021-11-20 00:11:55 PST
Created attachment 444889 [details]
patch
Comment 17 chris fleizach 2021-11-20 22:05:10 PST
Created attachment 444916 [details]
patch
Comment 18 chris fleizach 2021-11-20 22:55:32 PST
Created attachment 444917 [details]
patch
Comment 19 chris fleizach 2021-11-20 23:37:11 PST
Created attachment 444918 [details]
patch
Comment 20 chris fleizach 2021-11-21 21:34:51 PST
Created attachment 444940 [details]
patch
Comment 21 chris fleizach 2021-11-21 21:37:10 PST
Created attachment 444941 [details]
patch
Comment 22 chris fleizach 2021-11-21 21:38:26 PST
Created attachment 444942 [details]
patch
Comment 23 Andres Gonzalez 2021-11-22 06:52:26 PST
(In reply to chris fleizach from comment #22)
> Created attachment 444942 [details]
> patch

--- a/Source/WebCore/accessibility/AccessibilityObject.cpp
+++ a/Source/WebCore/accessibility/AccessibilityObject.cpp

+std::optional<SimpleRange> AccessibilityObject::visibleCharacterRange() const
+{
...
+    return SimpleRange(*startBoundary, *endBoundary);
+}

I think you may be able to do the more stylish:

    return {{ *startBoundary, *endBoundary }};
Comment 24 chris fleizach 2021-11-22 07:41:00 PST
Created attachment 444966 [details]
patch
Comment 25 EWS 2021-11-22 12:34:26 PST
Committed r286116 (244503@main): <https://commits.webkit.org/244503@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 444966 [details].