[views-ax] Migrating kPopupForId to new system
This CL migrates the kPopupForId attribute in Views to be updated
whenever its value should change, rather than querying the value
and computing it only when needed.
This CL is part of the ViewsAX project:
https://docs.google.com/document/d/1Ku7HOyDsiZem1yaV6ccZ-tz3lO2XR2NEcm8HjR6d-VY/edit#heading=h.ke1u3utej413
Bug: 325137417
Change-Id: Ib08c80471db46ec625fc4a7cafc671231e7d544d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5648297
Commit-Queue: Sejal Anand <sejalanand@microsoft.com>
Reviewed-by: Patrick Noland <pnoland@chromium.org>
Reviewed-by: Javier Contreras <javiercon@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1325952}
diff --git a/chrome/browser/ui/views/omnibox/omnibox_popup_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_popup_view_views.cc
index acb6bfc..745a590 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_popup_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_popup_view_views.cc
@@ -170,6 +170,11 @@
location_bar_view_(location_bar_view) {
model()->set_popup_view(this);
+ if (omnibox_view_) {
+ GetViewAccessibility().SetPopupForId(
+ omnibox_view_->GetViewAccessibility().GetUniqueId());
+ }
+
// The contents is owned by the LocationBarView.
set_owned_by_client();
@@ -617,11 +622,6 @@
if (!IsOpen()) {
node_data->AddState(ax::mojom::State::kInvisible);
}
-
- if (omnibox_view_) {
- int32_t view_id = omnibox_view_->GetViewAccessibility().GetUniqueId();
- node_data->AddIntAttribute(ax::mojom::IntAttribute::kPopupForId, view_id);
- }
}
void OmniboxPopupViewViews::UpdateExpandedCollapsedAccessibleState() const {
diff --git a/chrome/browser/ui/views/omnibox/omnibox_popup_view_views_browsertest.cc b/chrome/browser/ui/views/omnibox/omnibox_popup_view_views_browsertest.cc
index 65a19f1..bce3223 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_popup_view_views_browsertest.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_popup_view_views_browsertest.cc
@@ -676,3 +676,19 @@
omnibox_view()->OnKeyEvent(&space);
EXPECT_TRUE(edit_model()->is_keyword_selected());
}
+
+IN_PROC_BROWSER_TEST_F(OmniboxPopupViewViewsTest,
+ AccesibilityAttributePopupForId) {
+ CreatePopupForTestQuery();
+ popup_view()->UpdatePopupAppearance();
+ edit_model()->SetPopupSelection(OmniboxPopupSelection(0));
+
+ ui::AXNodeData ax_node_data_omnibox;
+ popup_view()->GetViewAccessibility().GetAccessibleNodeData(
+ &ax_node_data_omnibox);
+ EXPECT_TRUE(ax_node_data_omnibox.HasIntAttribute(
+ ax::mojom::IntAttribute::kPopupForId));
+ EXPECT_EQ(ax_node_data_omnibox.GetIntAttribute(
+ ax::mojom::IntAttribute::kPopupForId),
+ omnibox_view()->GetViewAccessibility().GetUniqueId());
+}