0

[views-ax] Migrate a11y kName attribute in TooltipViewAura

This ensures that the name is updated in the accessibility cache
as soon as the underlying condition changes or the view is
constructed.

UnitTest - https://source.chromium.org/chromium/chromium/src/+/main:ui/views/corewm/tooltip_controller_unittest.cc;drc=10848b3ce7557094ccb22c038017927595f9cb73;l=346

The remaining instances will be migrated in follow-up CLs.

This CL is part of the ViewsAX project:
https://docs.google.com/document/d/1Ku7HOyDsiZem1yaV6ccZ-

Bug: 325137417
Change-Id: I3819fdef73a56088db30e8a966f5cf436c9663d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5812851
Reviewed-by: Dirk Pranke <dpranke@google.com>
Reviewed-by: Benjamin Beaudry <benjamin.beaudry@microsoft.com>
Commit-Queue: Sejal Anand <sejalanand@microsoft.com>
Reviewed-by: Javier Contreras <javiercon@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1358976}
This commit is contained in:
Sejal Anand
2024-09-23 19:45:49 +00:00
committed by Chromium LUCI CQ
parent a382ec0316
commit 2fff00d52c
2 changed files with 12 additions and 3 deletions

@ -40,6 +40,7 @@ TooltipViewAura::TooltipViewAura()
kBorderInset - gfx::Insets(kTooltipBorderThickness)));
GetViewAccessibility().SetRole(ax::mojom::Role::kTooltip);
UpdateAccessibleName();
ResetDisplayRect();
}
@ -54,6 +55,7 @@ void TooltipViewAura::SetText(const std::u16string& text) {
std::u16string new_text(text);
base::ReplaceChars(new_text, u"\t", u" ", &new_text);
render_text_->SetText(std::move(new_text));
UpdateAccessibleName();
SchedulePaint();
}
@ -109,12 +111,19 @@ void TooltipViewAura::OnThemeChanged() {
GetColorProvider()->GetColor(ui::kColorTooltipForeground));
}
void TooltipViewAura::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->SetNameChecked(render_text_->GetDisplayText());
void TooltipViewAura::UpdateAccessibleName() {
if (render_text_->GetDisplayText().empty()) {
GetViewAccessibility().SetName(
std::u16string(), ax::mojom::NameFrom::kAttributeExplicitlyEmpty);
return;
}
GetViewAccessibility().SetName(render_text_->GetDisplayText());
}
void TooltipViewAura::ResetDisplayRect() {
render_text_->SetDisplayRect(gfx::Rect(0, 0, max_width_, 100000));
UpdateAccessibleName();
}
BEGIN_METADATA(TooltipViewAura)

@ -41,9 +41,9 @@ class VIEWS_EXPORT TooltipViewAura : public views::View {
gfx::Size CalculatePreferredSize(
const SizeBounds& /*available_size*/) const override;
void OnThemeChanged() override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
private:
void UpdateAccessibleName();
void ResetDisplayRect();
std::unique_ptr<gfx::RenderText> render_text_;