Commit fe0c8801 authored by John Pham's avatar John Pham Committed by Commit Bot

Return the correct focused virtual view

Defining focus: the parent view's active descendant

Problem: An active virtual view reports itself as having keyboard focus even if keyboard focus is somewhere else. This leads to more than 1 virtual view reporting that they have keyboard focus when only 1 virtual view should be.

Bug: 811277
Change-Id: I8985129ad4eafffa658159b1b73993cff2f01b96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095466
Commit-Queue: John Pham <johnp@microsoft.com>
Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751486}
parent 17ffaf48
......@@ -333,11 +333,13 @@ gfx::NativeViewAccessible AXVirtualView::HitTestSync(int x, int y) const {
}
gfx::NativeViewAccessible AXVirtualView::GetFocus() {
if (parent_view_)
return parent_view_->GetFocusedDescendant();
if (virtual_parent_view_)
return virtual_parent_view_->GetFocus();
auto* owner_view = GetOwnerView();
if (owner_view) {
if (!(owner_view->HasFocus())) {
return nullptr;
}
return owner_view->GetViewAccessibility().GetFocusedDescendant();
}
// This virtual view hasn't been added to a parent view yet.
return nullptr;
......
......@@ -534,6 +534,20 @@ TEST_F(AXVirtualViewTest, OverrideFocus) {
ExpectReceivedAccessibilityEvents(
{std::make_pair(virtual_child_3, ax::mojom::Event::kFocus)});
// Test that calling GetFocus() while the owner view is not focused will
// return nullptr.
EXPECT_EQ(nullptr, virtual_label_->GetFocus());
EXPECT_EQ(nullptr, virtual_child_1->GetFocus());
EXPECT_EQ(nullptr, virtual_child_2->GetFocus());
EXPECT_EQ(nullptr, virtual_child_3->GetFocus());
button_->SetFocusBehavior(View::FocusBehavior::ALWAYS);
button_->RequestFocus();
ExpectReceivedAccessibilityEvents(
{std::make_pair(GetButtonAccessibility(), ax::mojom::Event::kFocus),
std::make_pair(GetButtonAccessibility(),
ax::mojom::Event::kChildrenChanged)});
// Test that calling GetFocus() from any object in the tree will return the
// same result.
EXPECT_EQ(virtual_child_3->GetNativeObject(), virtual_label_->GetFocus());
......
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