Skip to content

Commit

Permalink
[ViewsAX] Move default implementation to AXPlatformNodeDelegate
Browse files Browse the repository at this point in the history
This CL is the second in splitting up CL:3923649, following
CL:4010922.

This CL refactors and moves more fairly trivial functions
in `BrowserAccessibility` and `AXPlatformNodeDelegateBase` that are
pure virtual in `AXPlatformNodeDelegate` up to the latter class.

Follow up CLs will continue this refactoring, removing code from
`BrowserAccessibility` to `AXPlatformNodeDelegate` as well as
moving implementations from `AXPlatformNodeDelegateBase` to the
root `AXPlatformNodeDelegate` class so we can get rid of the
former class in a follow up CL.

AX_relnotes: n/a.

Change-Id: I03a6a5b8c913498c9a46f68ebf049e97b530b125
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4037221
Commit-Queue: Javier Contreras <javiercon@microsoft.com>
Reviewed-by: Benjamin Beaudry <benjamin.beaudry@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1078684}
  • Loading branch information
Javier Contreras Tenorio authored and Chromium LUCI CQ committed Dec 2, 2022
1 parent cd40cb0 commit c7fae74
Show file tree
Hide file tree
Showing 6 changed files with 539 additions and 718 deletions.
85 changes: 0 additions & 85 deletions content/browser/accessibility/browser_accessibility.cc
Expand Up @@ -176,10 +176,6 @@ bool BrowserAccessibility::IsDescendantOf(
return node()->IsDescendantOfCrossingTreeBoundary(ancestor->node());
}

bool BrowserAccessibility::IsIgnored() const {
return node()->IsIgnored();
}

bool BrowserAccessibility::IsIgnoredForTextNavigation() const {
return node()->IsIgnoredForTextNavigation();
}
Expand Down Expand Up @@ -722,13 +718,6 @@ bool BrowserAccessibility::HasExplicitlyEmptyName() const {
return GetNameFrom() == ax::mojom::NameFrom::kAttributeExplicitlyEmpty;
}

BrowserAccessibility::AXPosition BrowserAccessibility::CreatePositionAt(
int offset,
ax::mojom::TextAffinity affinity) const {
return ui::AXNodePosition::CreatePosition(
*node(), /* child_index_or_text_offset */ offset);
}

// |offset| could either be a text character or a child index in case of
// non-text objects.
// Currently, to be safe, we convert to text leaf equivalents and we don't use
Expand All @@ -744,29 +733,12 @@ std::u16string BrowserAccessibility::GetNameAsString16() const {
return node()->GetNameUTF16();
}

const std::string& BrowserAccessibility::GetDescription() const {
return GetStringAttribute(ax::mojom::StringAttribute::kDescription);
}

std::u16string BrowserAccessibility::GetHypertext() const {
// Overloaded by platforms which require a hypertext accessibility text
// implementation.
return std::u16string();
}

const std::map<int, int>&
BrowserAccessibility::GetHypertextOffsetToHyperlinkChildIndex() const {
return node()->GetHypertextOffsetToHyperlinkChildIndex();
}

std::u16string BrowserAccessibility::GetTextContentUTF16() const {
return node()->GetTextContentUTF16();
}

std::u16string BrowserAccessibility::GetValueForControl() const {
return base::UTF8ToUTF16(node()->GetValueForControl());
}

gfx::Rect BrowserAccessibility::RelativeToAbsoluteBounds(
gfx::RectF bounds,
const ui::AXCoordinateSystem coordinate_system,
Expand Down Expand Up @@ -844,14 +816,6 @@ bool BrowserAccessibility::IsOffscreen() const {
return offscreen_result == ui::AXOffscreenResult::kOffscreen;
}

bool BrowserAccessibility::IsMinimized() const {
return false;
}

bool BrowserAccessibility::IsText() const {
return node()->IsText();
}

bool BrowserAccessibility::IsWebContent() const {
return true;
}
Expand Down Expand Up @@ -928,10 +892,6 @@ std::set<ui::AXPlatformNode*> BrowserAccessibility::GetReverseRelations(
manager_->ax_tree()->GetReverseRelations(attr, GetData().id));
}

std::u16string BrowserAccessibility::GetAuthorUniqueId() const {
return node()->GetHtmlAttribute("id");
}

const ui::AXUniqueId& BrowserAccessibility::GetUniqueId() const {
// This is not the same as GetData().id which comes from Blink, because
// those ids are only unique within the Blink process. We need one that is
Expand Down Expand Up @@ -969,39 +929,10 @@ BrowserAccessibility::GetUIADirectChildrenInRange(
return {};
}

gfx::NativeViewAccessible BrowserAccessibility::GetNativeViewAccessible() {
// TODO(703369) On Windows, where we have started to migrate to an
// AXPlatformNode implementation, the BrowserAccessibilityWin subclass has
// overridden this method. On all other platforms, this method should not be
// called yet. In the future, when all subclasses have moved over to be
// implemented by AXPlatformNode, we may make this method completely virtual.
NOTREACHED();
return nullptr;
}

//
// AXPlatformNodeDelegate.
//

const ui::AXNodeData& BrowserAccessibility::GetData() const {
return node()->data();
}

BrowserAccessibility::AXPosition BrowserAccessibility::CreateTextPositionAt(
int offset,
ax::mojom::TextAffinity affinity) const {
DCHECK(node()->IsDataValid());
DCHECK(manager_->GetNode(GetId()))
<< "No node for id: " << GetId() << " " << node()->id() << " "
<< node()->data().id;
return ui::AXNodePosition::CreateTextPosition(*node(), offset, affinity);
}

gfx::NativeViewAccessible BrowserAccessibility::GetNSWindow() {
NOTREACHED();
return nullptr;
}

gfx::NativeViewAccessible BrowserAccessibility::GetParent() const {
BrowserAccessibility* parent = PlatformGetParent();
if (parent)
Expand All @@ -1025,10 +956,6 @@ gfx::NativeViewAccessible BrowserAccessibility::ChildAtIndex(size_t index) {
return child->GetNativeViewAccessible();
}

bool BrowserAccessibility::HasModalDialog() const {
return false;
}

gfx::NativeViewAccessible BrowserAccessibility::GetFirstChild() {
BrowserAccessibility* child = PlatformGetFirstChild();
if (!child)
Expand Down Expand Up @@ -1057,10 +984,6 @@ gfx::NativeViewAccessible BrowserAccessibility::GetPreviousSibling() {
return sibling->GetNativeViewAccessible();
}

bool BrowserAccessibility::IsChildOfLeaf() const {
return node()->IsChildOfLeaf();
}

bool BrowserAccessibility::IsEmptyLeaf() const {
return node()->IsEmptyLeaf();
}
Expand Down Expand Up @@ -1097,10 +1020,6 @@ bool BrowserAccessibility::IsToplevelBrowserWindow() {
return false;
}

bool BrowserAccessibility::IsDescendantOfAtomicTextField() const {
return node()->IsDescendantOfAtomicTextField();
}

bool BrowserAccessibility::IsPlatformDocument() const {
return ui::IsPlatformDocument(GetRole());
}
Expand Down Expand Up @@ -1967,10 +1886,6 @@ ui::TextAttributeList BrowserAccessibility::ComputeTextAttributes() const {
return ui::TextAttributeList();
}

std::string BrowserAccessibility::GetInheritedFontFamilyName() const {
return GetInheritedStringAttribute(ax::mojom::StringAttribute::kFontFamily);
}

ui::TextAttributeMap BrowserAccessibility::GetSpellingAndGrammarAttributes()
const {
// TODO(crbug.com/1049261): This is one of the few methods that won't be moved
Expand Down
24 changes: 0 additions & 24 deletions content/browser/accessibility/browser_accessibility.h
Expand Up @@ -375,32 +375,16 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate {
std::u16string GetNameAsString16() const;

// `AXPlatformNodeDelegate` implementation.
std::u16string GetAuthorUniqueId() const override;
const ui::AXNodeData& GetData() const override;
AXPosition CreatePositionAt(
int offset,
ax::mojom::TextAffinity affinity =
ax::mojom::TextAffinity::kDownstream) const override;
AXPosition CreateTextPositionAt(
int offset,
ax::mojom::TextAffinity affinity =
ax::mojom::TextAffinity::kDownstream) const override;
gfx::NativeViewAccessible GetNSWindow() override;
gfx::NativeViewAccessible GetNativeViewAccessible() override;
gfx::NativeViewAccessible GetParent() const override;
size_t GetChildCount() const override;
gfx::NativeViewAccessible ChildAtIndex(size_t index) override;
bool HasModalDialog() const override;
gfx::NativeViewAccessible GetFirstChild() override;
gfx::NativeViewAccessible GetLastChild() override;
gfx::NativeViewAccessible GetNextSibling() override;
gfx::NativeViewAccessible GetPreviousSibling() override;
bool IsChildOfLeaf() const override;
bool IsDescendantOfAtomicTextField() const override;
bool IsPlatformDocument() const override;
bool IsLeaf() const override;
bool IsFocused() const override;
bool IsIgnored() const override;
bool IsToplevelBrowserWindow() override;
gfx::NativeViewAccessible GetLowestPlatformAncestor() const override;
gfx::NativeViewAccessible GetTextFieldAncestor() const override;
Expand All @@ -410,13 +394,8 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate {
std::unique_ptr<ChildIterator> ChildrenBegin() override;
std::unique_ptr<ChildIterator> ChildrenEnd() override;

const std::string& GetDescription() const override;
std::u16string GetHypertext() const override;
const std::map<int, int>& GetHypertextOffsetToHyperlinkChildIndex()
const override;
bool SetHypertextSelection(int start_offset, int end_offset) override;
std::u16string GetTextContentUTF16() const override;
std::u16string GetValueForControl() const override;
gfx::Rect GetBoundsRect(
const ui::AXCoordinateSystem coordinate_system,
const ui::AXClippingBehavior clipping_behavior,
Expand Down Expand Up @@ -459,11 +438,8 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate {
std::u16string GetStyleNameAttributeAsLocalizedString() const override;
ui::TextAttributeMap ComputeTextAttributeMap(
const ui::TextAttributeList& default_attributes) const override;
std::string GetInheritedFontFamilyName() const override;
bool ShouldIgnoreHoveredStateForTesting() override;
bool IsOffscreen() const override;
bool IsMinimized() const override;
bool IsText() const override;
bool IsWebContent() const override;
bool HasVisibleCaretOrSelection() const override;
ui::AXPlatformNode* GetTargetNodeForRelation(
Expand Down

0 comments on commit c7fae74

Please sign in to comment.