Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a388914

Browse files
committed
expose Semantics.identifier as Windows UIA AutomationId
1 parent afc1898 commit a388914

12 files changed

+36
-6
lines changed

shell/platform/common/accessibility_bridge.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ void AccessibilityBridge::ConvertFlutterUpdate(const SemanticsNode& node,
280280
SetIntAttributesFromFlutterUpdate(node_data, node);
281281
SetIntListAttributesFromFlutterUpdate(node_data, node);
282282
SetStringListAttributesFromFlutterUpdate(node_data, node);
283+
SetIdentifierFromFlutterUpdate(node_data, node);
283284
SetNameFromFlutterUpdate(node_data, node);
284285
SetValueFromFlutterUpdate(node_data, node);
285286
SetTooltipFromFlutterUpdate(node_data, node);
@@ -519,6 +520,13 @@ void AccessibilityBridge::SetStringListAttributesFromFlutterUpdate(
519520
}
520521
}
521522

523+
void AccessibilityBridge::SetIdentifierFromFlutterUpdate(
524+
ui::AXNodeData& node_data,
525+
const SemanticsNode& node) {
526+
node_data.AddStringAttribute(ax::mojom::StringAttribute::kAuthorUniqueId,
527+
node.identifier);
528+
}
529+
522530
void AccessibilityBridge::SetNameFromFlutterUpdate(ui::AXNodeData& node_data,
523531
const SemanticsNode& node) {
524532
node_data.SetName(node.label);
@@ -587,6 +595,9 @@ AccessibilityBridge::FromFlutterSemanticsNode(
587595
result.scroll_extent_min = flutter_node.scroll_extent_min;
588596
result.elevation = flutter_node.elevation;
589597
result.thickness = flutter_node.thickness;
598+
if (flutter_node.identifier) {
599+
result.identifier = std::string(flutter_node.identifier);
600+
}
590601
if (flutter_node.label) {
591602
result.label = std::string(flutter_node.label);
592603
}

shell/platform/common/accessibility_bridge.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class AccessibilityBridge
172172
double scroll_extent_min;
173173
double elevation;
174174
double thickness;
175+
std::string identifier;
175176
std::string label;
176177
std::string hint;
177178
std::string value;
@@ -225,6 +226,8 @@ class AccessibilityBridge
225226
const SemanticsNode& node);
226227
void SetIntListAttributesFromFlutterUpdate(ui::AXNodeData& node_data,
227228
const SemanticsNode& node);
229+
void SetIdentifierFromFlutterUpdate(ui::AXNodeData& node_data,
230+
const SemanticsNode& node);
228231
void SetStringListAttributesFromFlutterUpdate(ui::AXNodeData& node_data,
229232
const SemanticsNode& node);
230233
void SetNameFromFlutterUpdate(ui::AXNodeData& node_data,

shell/platform/common/flutter_platform_node_delegate.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <utility>
88

9+
#include "flutter/fml/platform/win/wstring_conversion.h"
910
#include "flutter/shell/platform/common/accessibility_bridge.h"
1011
#include "flutter/third_party/accessibility/ax/ax_action_data.h"
1112
#include "flutter/third_party/accessibility/ax/ax_tree_manager_map.h"
@@ -61,6 +62,12 @@ const ui::AXNodeData& FlutterPlatformNodeDelegate::GetData() const {
6162
return ax_node_->data();
6263
}
6364

65+
std::u16string FlutterPlatformNodeDelegate::GetAuthorUniqueId() const {
66+
return fml::WideStringToUtf16(
67+
fml::Utf8ToWideString(GetData().GetStringAttribute(
68+
ax::mojom::StringAttribute::kAuthorUniqueId)));
69+
}
70+
6471
gfx::NativeViewAccessible FlutterPlatformNodeDelegate::GetParent() {
6572
if (!ax_node_->parent()) {
6673
return nullptr;

shell/platform/common/flutter_platform_node_delegate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class FlutterPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase {
101101
// |ui::AXPlatformNodeDelegateBase|
102102
const ui::AXUniqueId& GetUniqueId() const override { return unique_id_; }
103103

104+
// |ui::AXPlatformNodeDelegateBase|
105+
std::u16string GetAuthorUniqueId() const override;
106+
104107
// |ui::AXPlatformNodeDelegateBase|
105108
const ui::AXNodeData& GetData() const override;
106109

shell/platform/common/flutter_platform_node_delegate_unittests.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ TEST(FlutterPlatformNodeDelegateTest, canPerfomActions) {
4646
root.actions = static_cast<FlutterSemanticsAction>(0);
4747
root.text_selection_base = -1;
4848
root.text_selection_extent = -1;
49+
root.identifier = "";
4950
root.label = "root";
5051
root.hint = "";
5152
root.value = "";

shell/platform/embedder/embedder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,8 @@ typedef struct {
13641364
double elevation;
13651365
/// Describes how much space the semantics node takes up along the z-axis.
13661366
double thickness;
1367+
/// A technical identifier for the node.
1368+
const char* identifier;
13671369
/// A textual description of the node.
13681370
const char* label;
13691371
/// A brief description of the result of performing an action on the node.

shell/platform/embedder/embedder_semantics_update.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ void EmbedderSemanticsUpdate2::AddNode(const SemanticsNode& node) {
153153
node.scrollExtentMin,
154154
node.elevation,
155155
node.thickness,
156+
node.identifier.c_str(),
156157
node.label.c_str(),
157158
node.hint.c_str(),
158159
node.value.c_str(),

shell/platform/windows/flutter_window.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,12 +806,9 @@ LRESULT FlutterWindow::OnGetObject(UINT const message,
806806
}
807807

808808
gfx::NativeViewAccessible root_view = GetNativeViewAccessible();
809-
// TODO(schectman): UIA is currently disabled by default.
810-
// https://github.com/flutter/flutter/issues/114547
811809
if (root_view) {
812810
CreateAxFragmentRoot();
813811
if (is_uia_request) {
814-
#ifdef FLUTTER_ENGINE_USE_UIA
815812
// Retrieve UIA object for the root view.
816813
Microsoft::WRL::ComPtr<IRawElementProviderSimple> root;
817814
if (SUCCEEDED(
@@ -824,7 +821,6 @@ LRESULT FlutterWindow::OnGetObject(UINT const message,
824821
} else {
825822
FML_LOG(ERROR) << "Failed to query AX fragment root.";
826823
}
827-
#endif // FLUTTER_ENGINE_USE_UIA
828824
} else if (is_msaa_request) {
829825
// Create the accessibility root if it does not already exist.
830826
// Return the IAccessible for the root view.

shell/platform/windows/window_unittests.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,7 @@ TEST(MockWindow, DISABLED_GetObjectUia) {
366366
bool uia_called = false;
367367
ON_CALL(window, OnGetObject)
368368
.WillByDefault(Invoke([&uia_called](UINT msg, WPARAM wpar, LPARAM lpar) {
369-
#ifdef FLUTTER_ENGINE_USE_UIA
370369
uia_called = true;
371-
#endif // FLUTTER_ENGINE_USE_UIA
372370
return static_cast<LRESULT>(0);
373371
}));
374372
EXPECT_CALL(window, OnGetObject).Times(1);

third_party/accessibility/ax/ax_enum_util.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,8 @@ const char* ToString(ax::mojom::StringAttribute string_attribute) {
14131413
return "accessKey";
14141414
case ax::mojom::StringAttribute::kAriaInvalidValue:
14151415
return "ariaInvalidValue";
1416+
case ax::mojom::StringAttribute::kAuthorUniqueId:
1417+
return "authorUniqueId";
14161418
case ax::mojom::StringAttribute::kAutoComplete:
14171419
return "autoComplete";
14181420
case ax::mojom::StringAttribute::kChildTreeId:
@@ -1473,6 +1475,8 @@ ax::mojom::StringAttribute ParseStringAttribute(const char* string_attribute) {
14731475
return ax::mojom::StringAttribute::kAccessKey;
14741476
if (0 == strcmp(string_attribute, "ariaInvalidValue"))
14751477
return ax::mojom::StringAttribute::kAriaInvalidValue;
1478+
if (0 == strcmp(string_attribute, "authorUniqueId"))
1479+
return ax::mojom::StringAttribute::kAuthorUniqueId;
14761480
if (0 == strcmp(string_attribute, "autoComplete"))
14771481
return ax::mojom::StringAttribute::kAutoComplete;
14781482
if (0 == strcmp(string_attribute, "childTreeId"))

third_party/accessibility/ax/ax_enums.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ enum class StringAttribute {
523523
kAccessKey,
524524
// Only used when invalid_state == invalid_state_other.
525525
kAriaInvalidValue,
526+
kAuthorUniqueId,
526527
kAutoComplete,
527528
kChildTreeId,
528529
kClassName,

third_party/accessibility/ax/ax_node_data.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,9 @@ std::string AXNodeData::ToString() const {
14441444
case ax::mojom::StringAttribute::kAriaInvalidValue:
14451445
result += " aria_invalid_value=" + value;
14461446
break;
1447+
case ax::mojom::StringAttribute::kAuthorUniqueId:
1448+
result += " author_unique_id=" + value;
1449+
break;
14471450
case ax::mojom::StringAttribute::kAutoComplete:
14481451
result += " autocomplete=" + value;
14491452
break;

0 commit comments

Comments
 (0)