Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions shell/platform/windows/accessibility_bridge_delegate_win32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void AccessibilityBridgeDelegateWin32::OnAccessibilityEvent(
break;
case ui::AXEventGenerator::Event::FOCUS_CHANGED:
DispatchWinAccessibilityEvent(win_delegate, EVENT_OBJECT_FOCUS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this line do anything?

Copy link
Member Author

@cbracken cbracken Dec 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sets the HWND focus.

SetFocus(win_delegate);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just win_delegate->SetFocus()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purely so I can capture the call in the test :(

break;
case ui::AXEventGenerator::Event::IGNORED_CHANGED:
if (ax_node->IsIgnored()) {
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions shell/platform/windows/accessibility_bridge_delegate_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions shell/platform/windows/flutter_platform_node_delegate_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down