Commit bf692704 authored by Benjamin Beaudry's avatar Benjamin Beaudry Committed by Commit Bot

Make HasVisibleCaretOrSelection() virtual

* I added the pure virtual function HasVisibleCaretOrSelection() on
AXPlatformNodeDelegate so we can use it in AXPlatformNodeTextProviderWin
without a dynamic cast.

* The default value in the AXPlatformNodeDelegateBase is false.

* The implementation is unchanged, but I moved it with other
AXPlatformNodeDelgate overrides.

Bug: 928948
Change-Id: If80c0a441415cb57ea0b4c352132a4d330fb56d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1881993Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarKurt Catti-Schmidt <kschmi@microsoft.com>
Commit-Queue: Benjamin Beaudry <benjamin.beaudry@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#710855}
parent e1aacdeb
...@@ -1077,28 +1077,6 @@ bool BrowserAccessibility::HasAction(ax::mojom::Action action_enum) const { ...@@ -1077,28 +1077,6 @@ bool BrowserAccessibility::HasAction(ax::mojom::Action action_enum) const {
return GetData().HasAction(action_enum); return GetData().HasAction(action_enum);
} }
bool BrowserAccessibility::HasVisibleCaretOrSelection() const {
ui::AXTree::Selection unignored_selection =
manager()->ax_tree()->GetUnignoredSelection();
int32_t focus_id = unignored_selection.focus_object_id;
BrowserAccessibility* focus_object = manager()->GetFromID(focus_id);
if (!focus_object)
return false;
// Selection or caret will be visible in a focused editable area.
if (HasState(ax::mojom::State::kEditable)) {
return IsPlainTextField() ? focus_object == this
: focus_object->IsDescendantOf(this);
}
// The selection will be visible in non-editable content only if it is not
// collapsed into a caret.
return (focus_id != unignored_selection.anchor_object_id ||
unignored_selection.focus_offset !=
unignored_selection.anchor_offset) &&
focus_object->IsDescendantOf(this);
}
bool BrowserAccessibility::IsWebAreaForPresentationalIframe() const { bool BrowserAccessibility::IsWebAreaForPresentationalIframe() const {
if (GetRole() != ax::mojom::Role::kWebArea && if (GetRole() != ax::mojom::Role::kWebArea &&
GetRole() != ax::mojom::Role::kRootWebArea) { GetRole() != ax::mojom::Role::kRootWebArea) {
...@@ -1296,6 +1274,28 @@ bool BrowserAccessibility::IsWebContent() const { ...@@ -1296,6 +1274,28 @@ bool BrowserAccessibility::IsWebContent() const {
return true; return true;
} }
bool BrowserAccessibility::HasVisibleCaretOrSelection() const {
ui::AXTree::Selection unignored_selection =
manager()->ax_tree()->GetUnignoredSelection();
int32_t focus_id = unignored_selection.focus_object_id;
BrowserAccessibility* focus_object = manager()->GetFromID(focus_id);
if (!focus_object)
return false;
// Selection or caret will be visible in a focused editable area.
if (HasState(ax::mojom::State::kEditable)) {
return IsPlainTextField() ? focus_object == this
: focus_object->IsDescendantOf(this);
}
// The selection will be visible in non-editable content only if it is not
// collapsed into a caret.
return (focus_id != unignored_selection.anchor_object_id ||
unignored_selection.focus_offset !=
unignored_selection.anchor_offset) &&
focus_object->IsDescendantOf(this);
}
std::set<ui::AXPlatformNode*> BrowserAccessibility::GetNodesForNodeIdSet( std::set<ui::AXPlatformNode*> BrowserAccessibility::GetNodesForNodeIdSet(
const std::set<int32_t>& ids) { const std::set<int32_t>& ids) {
std::set<ui::AXPlatformNode*> nodes; std::set<ui::AXPlatformNode*> nodes;
......
...@@ -386,9 +386,6 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate { ...@@ -386,9 +386,6 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate {
bool HasState(ax::mojom::State state_enum) const; bool HasState(ax::mojom::State state_enum) const;
bool HasAction(ax::mojom::Action action_enum) const; bool HasAction(ax::mojom::Action action_enum) const;
// Returns true if the caret or selection is visible on this object.
bool HasVisibleCaretOrSelection() const;
// True if this is a web area, and its grandparent is a presentational iframe. // True if this is a web area, and its grandparent is a presentational iframe.
bool IsWebAreaForPresentationalIframe() const; bool IsWebAreaForPresentationalIframe() const;
...@@ -533,6 +530,7 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate { ...@@ -533,6 +530,7 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate {
bool IsOffscreen() const override; bool IsOffscreen() const override;
bool IsMinimized() const override; bool IsMinimized() const override;
bool IsWebContent() const override; bool IsWebContent() const override;
bool HasVisibleCaretOrSelection() const override;
ui::AXPlatformNode* GetTargetNodeForRelation( ui::AXPlatformNode* GetTargetNodeForRelation(
ax::mojom::IntAttribute attr) override; ax::mojom::IntAttribute attr) override;
std::set<ui::AXPlatformNode*> GetTargetNodesForRelation( std::set<ui::AXPlatformNode*> GetTargetNodesForRelation(
......
...@@ -220,6 +220,9 @@ class AX_EXPORT AXPlatformNodeDelegate { ...@@ -220,6 +220,9 @@ class AX_EXPORT AXPlatformNodeDelegate {
// Get whether this node is in web content. // Get whether this node is in web content.
virtual bool IsWebContent() const = 0; virtual bool IsWebContent() const = 0;
// Returns true if the caret or selection is visible on this object.
virtual bool HasVisibleCaretOrSelection() const = 0;
// Get another node from this same tree. // Get another node from this same tree.
virtual AXPlatformNode* GetFromNodeID(int32_t id) = 0; virtual AXPlatformNode* GetFromNodeID(int32_t id) = 0;
......
...@@ -445,6 +445,10 @@ bool AXPlatformNodeDelegateBase::IsWebContent() const { ...@@ -445,6 +445,10 @@ bool AXPlatformNodeDelegateBase::IsWebContent() const {
return false; return false;
} }
bool AXPlatformNodeDelegateBase::HasVisibleCaretOrSelection() const {
return false;
}
AXPlatformNode* AXPlatformNodeDelegateBase::GetTargetNodeForRelation( AXPlatformNode* AXPlatformNodeDelegateBase::GetTargetNodeForRelation(
ax::mojom::IntAttribute attr) { ax::mojom::IntAttribute attr) {
DCHECK(IsNodeIdIntAttribute(attr)); DCHECK(IsNodeIdIntAttribute(attr));
......
...@@ -149,6 +149,9 @@ class AX_EXPORT AXPlatformNodeDelegateBase : public AXPlatformNodeDelegate { ...@@ -149,6 +149,9 @@ class AX_EXPORT AXPlatformNodeDelegateBase : public AXPlatformNodeDelegate {
// Get whether this node is in web content. // Get whether this node is in web content.
bool IsWebContent() const override; bool IsWebContent() const override;
// Returns true if the caret or selection is visible on this object.
bool HasVisibleCaretOrSelection() const override;
// Get another node from this same tree. // Get another node from this same tree.
AXPlatformNode* GetFromNodeID(int32_t id) override; AXPlatformNode* GetFromNodeID(int32_t id) override;
......
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