Commit 0448e5ac authored by Nektarios Paisios's avatar Nektarios Paisios Committed by Chromium LUCI CQ

Adds ability in AXPosition to stop at the boundary of a window-like node

One of the consequences of exposing Views as an AXTree is that
certain assumptions in AXPosition are no longer true.
One of those assumptions is that if a null position has been returned from a method
that moves from a non-null position to some other position, such as `CreatePositionAtEndOfAnchor`,
then the beginning or the end of the whole content has been reached.
This is no longer true when a tree of Views is connected to the main tree
representing the currently visible webpage.
It's also not true when AXPosition starts to be used more on Chrome OS, where the whole desktop
is exposed using a forest of AXTrees.

In this patch, the entirety of the AXPosition code was scanned for any assumptions that would
prevent it from working when the webpage's main tree is connected to a Views tree.
Also, care was taken to ensure that UI Automation text range provider methods work as before,
for e example navigating by word, line, etc. shouldnot stop at iframe boundaries.

AX-Relnotes: n/a.

Split out from patch that fixes CreatePositionAtStart/EndOfContent
https://chromium-review.googlesource.com/c/chromium/src/+/2595454/

Bug: 1049261
R=dmazzoni@chromium.org, aleventhal@chromium.org

Change-Id: I1a25d9f715c50773b418d322c2f7c52eacbd6732
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2597568
Commit-Queue: Nektarios Paisios <nektar@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarKurt Catti-Schmidt <kschmi@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#839989}
parent 0c676097
...@@ -1360,12 +1360,10 @@ id content::AXTextMarkerRangeFrom(id anchor_textmarker, id focus_textmarker) { ...@@ -1360,12 +1360,10 @@ id content::AXTextMarkerRangeFrom(id anchor_textmarker, id focus_textmarker) {
// Returns a text marker that points to the last character in the document that // Returns a text marker that points to the last character in the document that
// can be selected with VoiceOver. // can be selected with VoiceOver.
- (id)endTextMarker { - (id)endTextMarker {
const BrowserAccessibility* root = _owner->manager()->GetRoot(); if (![self instanceActive])
if (!root)
return nil; return nil;
BrowserAccessibilityPositionInstance position = _owner->CreatePositionAt(0);
BrowserAccessibilityPositionInstance position = root->CreatePositionAt(0); return CreateTextMarker(position->CreatePositionAtEndOfContent());
return CreateTextMarker(position->CreatePositionAtEndOfAnchor());
} }
- (NSNumber*)expanded { - (NSNumber*)expanded {
...@@ -2355,12 +2353,10 @@ id content::AXTextMarkerRangeFrom(id anchor_textmarker, id focus_textmarker) { ...@@ -2355,12 +2353,10 @@ id content::AXTextMarkerRangeFrom(id anchor_textmarker, id focus_textmarker) {
// Returns a text marker that points to the first character in the document that // Returns a text marker that points to the first character in the document that
// can be selected with VoiceOver. // can be selected with VoiceOver.
- (id)startTextMarker { - (id)startTextMarker {
const BrowserAccessibility* root = _owner->manager()->GetRoot(); if (![self instanceActive])
if (!root)
return nil; return nil;
BrowserAccessibilityPositionInstance position = _owner->CreatePositionAt(0);
BrowserAccessibilityPositionInstance position = root->CreatePositionAt(0); return CreateTextMarker(position->CreatePositionAtStartOfContent());
return CreateTextMarker(position->CreatePositionAtStartOfAnchor());
} }
// Returns a subrole based upon the role. // Returns a subrole based upon the role.
......
...@@ -2700,7 +2700,7 @@ std::vector<int> AutomationInternalCustomBindings::CalculateSentenceBoundary( ...@@ -2700,7 +2700,7 @@ std::vector<int> AutomationInternalCustomBindings::CalculateSentenceBoundary(
if (!head_pos->AtStartOfParagraph()) { if (!head_pos->AtStartOfParagraph()) {
ui::AXNodePosition::AXPositionInstance start_para_pos = ui::AXNodePosition::AXPositionInstance start_para_pos =
head_pos->CreatePreviousParagraphStartPosition( head_pos->CreatePreviousParagraphStartPosition(
ui::AXBoundaryBehavior::CrossBoundary); ui::AXBoundaryBehavior::StopAtLastAnchorBoundary);
ui::AXRange<ui::AXPosition<ui::AXNodePosition, ui::AXNode>> pre_range( ui::AXRange<ui::AXPosition<ui::AXNodePosition, ui::AXNode>> pre_range(
start_para_pos->Clone(), head_pos->Clone()); start_para_pos->Clone(), head_pos->Clone());
pre_str = pre_range.GetText(); pre_str = pre_range.GetText();
...@@ -2710,7 +2710,7 @@ std::vector<int> AutomationInternalCustomBindings::CalculateSentenceBoundary( ...@@ -2710,7 +2710,7 @@ std::vector<int> AutomationInternalCustomBindings::CalculateSentenceBoundary(
// node to the end of the paragraph. // node to the end of the paragraph.
ui::AXNodePosition::AXPositionInstance end_para_pos = ui::AXNodePosition::AXPositionInstance end_para_pos =
head_pos->CreateNextParagraphEndPosition( head_pos->CreateNextParagraphEndPosition(
ui::AXBoundaryBehavior::CrossBoundary); ui::AXBoundaryBehavior::StopAtLastAnchorBoundary);
ui::AXRange<ui::AXPosition<ui::AXNodePosition, ui::AXNode>> post_range( ui::AXRange<ui::AXPosition<ui::AXNodePosition, ui::AXNode>> post_range(
head_pos->Clone(), end_para_pos->Clone()); head_pos->Clone(), end_para_pos->Clone());
post_str = post_range.GetText(); post_str = post_range.GetText();
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment