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

Refactor GetEnclosingElement

This CL is just a simple refactor of
AXPlatformNodeTextRangeProviderWin::GetEnclosingElement. It introduces
GetLowestAccessibleCommonPlatformNode, which returns the lowest common
accessible platform node for a range.

I think the refactor makes this method a bit easier to understand.

Bug: 928948
Change-Id: Ic8bd371d076505c14961c9ec79ccb43943c5a3b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2068925Reviewed-by: default avatarKurt Catti-Schmidt <kschmi@microsoft.com>
Commit-Queue: Benjamin Beaudry <benjamin.beaudry@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#744336}
parent d01f073b
......@@ -554,22 +554,10 @@ HRESULT AXPlatformNodeTextRangeProviderWin::GetEnclosingElement(
WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TEXTRANGE_GETENCLOSINGELEMENT);
UIA_VALIDATE_TEXTRANGEPROVIDER_CALL_1_OUT(element);
AXNode* common_anchor = start_->LowestCommonAnchor(*end_);
DCHECK(common_anchor);
if (!common_anchor)
AXPlatformNodeWin* enclosing_node = GetLowestAccessibleCommonPlatformNode();
if (!enclosing_node)
return UIA_E_ELEMENTNOTAVAILABLE;
const AXTreeID tree_id = common_anchor->tree()->GetAXTreeID();
const AXNode::AXID node_id = common_anchor->id();
AXPlatformNodeWin* enclosing_node =
static_cast<AXPlatformNodeWin*>(AXPlatformNode::FromNativeViewAccessible(
GetDelegate(tree_id, node_id)->GetNativeViewAccessible()));
DCHECK(enclosing_node);
// If this node has an ancestor that is a control type, use that as the
// enclosing element.
enclosing_node = enclosing_node->GetLowestAccessibleElement();
DCHECK(enclosing_node);
while (enclosing_node->GetData().IsIgnored() ||
enclosing_node->GetData().role == ax::mojom::Role::kInlineTextBox) {
AXPlatformNodeWin* parent = static_cast<AXPlatformNodeWin*>(
......@@ -1265,4 +1253,21 @@ void AXPlatformNodeTextRangeProviderWin::ValidateStartAndEndPositions() {
end_->SnapToMaxTextOffsetIfBeyond();
}
AXPlatformNodeWin*
AXPlatformNodeTextRangeProviderWin::GetLowestAccessibleCommonPlatformNode()
const {
AXNode* common_anchor = start_->LowestCommonAnchor(*end_);
if (!common_anchor)
return nullptr;
const AXTreeID tree_id = common_anchor->tree()->GetAXTreeID();
const AXNode::AXID node_id = common_anchor->id();
AXPlatformNodeWin* platform_node =
static_cast<AXPlatformNodeWin*>(AXPlatformNode::FromNativeViewAccessible(
GetDelegate(tree_id, node_id)->GetNativeViewAccessible()));
DCHECK(platform_node);
return platform_node->GetLowestAccessibleElement();
}
} // namespace ui
......@@ -160,6 +160,7 @@ class AX_EXPORT __declspec(uuid("3071e40d-a10d-45ff-a59f-6e8e1138e2c1"))
void RemoveFocusFromPreviousSelectionIfNeeded(
const AXNodeRange& new_selection);
void ValidateStartAndEndPositions();
AXPlatformNodeWin* GetLowestAccessibleCommonPlatformNode() const;
Microsoft::WRL::ComPtr<AXPlatformNodeWin> owner_;
AXPositionInstance start_;
......
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