Call IAccessible::accFocus to move a11y focus (flutter/engine#30256)
On receipt of a FOCUS_CHANGED event from the AX tree, call IAccessible::accFocus to tell screen readers to move the accessibility focus to that node. This is in addition to setting the keyboard focus via the EVENT_OBJECT_FOCUS event. Issue: https://github.com/flutter/flutter/issues/77838
This commit is contained in:
@@ -39,6 +39,7 @@ void AccessibilityBridgeDelegateWin32::OnAccessibilityEvent(
|
||||
break;
|
||||
case ui::AXEventGenerator::Event::FOCUS_CHANGED:
|
||||
DispatchWinAccessibilityEvent(win_delegate, EVENT_OBJECT_FOCUS);
|
||||
SetFocus(win_delegate);
|
||||
break;
|
||||
case ui::AXEventGenerator::Event::IGNORED_CHANGED:
|
||||
if (ax_node->IsIgnored()) {
|
||||
@@ -152,4 +153,9 @@ void AccessibilityBridgeDelegateWin32::DispatchWinAccessibilityEvent(
|
||||
node_delegate->DispatchWinAccessibilityEvent(event_type);
|
||||
}
|
||||
|
||||
void AccessibilityBridgeDelegateWin32::SetFocus(
|
||||
std::shared_ptr<FlutterPlatformNodeDelegateWin32> node_delegate) {
|
||||
node_delegate->SetFocus();
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -46,6 +46,11 @@ class AccessibilityBridgeDelegateWin32
|
||||
std::shared_ptr<FlutterPlatformNodeDelegateWin32> node_delegate,
|
||||
DWORD event_type);
|
||||
|
||||
// Sets the accessibility focus to the accessibility node associated with the
|
||||
// specified semantics node.
|
||||
virtual void SetFocus(
|
||||
std::shared_ptr<FlutterPlatformNodeDelegateWin32> node_delegate);
|
||||
|
||||
private:
|
||||
FlutterWindowsEngine* engine_;
|
||||
};
|
||||
|
||||
@@ -45,13 +45,25 @@ class AccessibilityBridgeDelegateWin32Spy
|
||||
dispatched_events_.push_back({node_delegate, event_type});
|
||||
}
|
||||
|
||||
void Reset() { dispatched_events_.clear(); }
|
||||
void SetFocus(std::shared_ptr<FlutterPlatformNodeDelegateWin32> node_delegate)
|
||||
override {
|
||||
focused_nodes_.push_back(node_delegate->GetAXNode()->id());
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
dispatched_events_.clear();
|
||||
focused_nodes_.clear();
|
||||
}
|
||||
|
||||
const std::vector<MsaaEvent>& dispatched_events() const {
|
||||
return dispatched_events_;
|
||||
};
|
||||
}
|
||||
|
||||
const std::vector<int32_t> focused_nodes() const { return focused_nodes_; }
|
||||
|
||||
private:
|
||||
std::vector<MsaaEvent> dispatched_events_;
|
||||
std::vector<int32_t> focused_nodes_;
|
||||
};
|
||||
|
||||
// Returns an engine instance configured with dummy project path values, and
|
||||
@@ -203,8 +215,25 @@ TEST(AccessibilityBridgeDelegateWin32, OnAccessibilityEventChildrenChanged) {
|
||||
}
|
||||
|
||||
TEST(AccessibilityBridgeDelegateWin32, OnAccessibilityEventFocusChanged) {
|
||||
ExpectWinEventFromAXEvent(1, ui::AXEventGenerator::Event::FOCUS_CHANGED,
|
||||
EVENT_OBJECT_FOCUS);
|
||||
auto window_binding_handler =
|
||||
std::make_unique<::testing::NiceMock<MockWindowBindingHandler>>();
|
||||
FlutterWindowsView view(std::move(window_binding_handler));
|
||||
view.SetEngine(GetTestEngine());
|
||||
view.OnUpdateSemanticsEnabled(true);
|
||||
|
||||
auto bridge = view.GetEngine()->accessibility_bridge().lock();
|
||||
PopulateAXTree(bridge);
|
||||
|
||||
AccessibilityBridgeDelegateWin32Spy spy(view.GetEngine());
|
||||
spy.OnAccessibilityEvent({AXNodeFromID(bridge, 1),
|
||||
{ui::AXEventGenerator::Event::FOCUS_CHANGED,
|
||||
ax::mojom::EventFrom::kNone,
|
||||
{}}});
|
||||
ASSERT_EQ(spy.dispatched_events().size(), 1);
|
||||
EXPECT_EQ(spy.dispatched_events()[0].event_type, EVENT_OBJECT_FOCUS);
|
||||
|
||||
ASSERT_EQ(spy.focused_nodes().size(), 1);
|
||||
EXPECT_EQ(spy.focused_nodes()[0], 1);
|
||||
}
|
||||
|
||||
TEST(AccessibilityBridgeDelegateWin32, OnAccessibilityEventIgnoredChanged) {
|
||||
|
||||
@@ -92,4 +92,11 @@ void FlutterPlatformNodeDelegateWin32::DispatchWinAccessibilityEvent(
|
||||
-ax_platform_node_->GetUniqueId());
|
||||
}
|
||||
|
||||
void FlutterPlatformNodeDelegateWin32::SetFocus() {
|
||||
VARIANT varchild{};
|
||||
varchild.vt = VT_I4;
|
||||
varchild.lVal = CHILDID_SELF;
|
||||
GetNativeViewAccessible()->accSelect(SELFLAG_TAKEFOCUS, varchild);
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -45,6 +45,10 @@ class FlutterPlatformNodeDelegateWin32 : public FlutterPlatformNodeDelegate {
|
||||
// convenience wrapper around |NotifyWinEvent|.
|
||||
virtual void DispatchWinAccessibilityEvent(DWORD event_type);
|
||||
|
||||
// Sets the accessibility focus to the accessibility node associated with
|
||||
// this object.
|
||||
void SetFocus();
|
||||
|
||||
private:
|
||||
ui::AXPlatformNode* ax_platform_node_;
|
||||
FlutterWindowsEngine* engine_;
|
||||
|
||||
Reference in New Issue
Block a user