0

Mahi: Add accessibility support for Mahi menu card and panel

Make sure that the Mahi menu card has the correct a11y attributes. Also,
make sure that the correct attribute and announcement is added for
answer questions and the learn more link in the panel.

Fixed: b:356699162, b:356692319, b:356168879, b:356165820
Change-Id: I77cd92309c413b0675bcbfd66e08bf1f72610e59
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5767017
Reviewed-by: Ahmed Mehfooz <amehfooz@chromium.org>
Commit-Queue: Andre Le <leandre@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1338622}
This commit is contained in:
Andre Le
2024-08-07 18:32:41 +00:00
committed by Chromium LUCI CQ
parent f6a525ae29
commit c048725a06
6 changed files with 30 additions and 3 deletions

@ -5378,6 +5378,9 @@ No devices connected.
<message name="IDS_ASH_MAHI_RETRY_LINK_CLICK_ACTIVATION_ACCESSIBLE_NAME" desc="Text for the accessible name that announced when the retry link is clicked">
Retry link activated
</message>
<message name="IDS_ASH_MAHI_LEARN_MORE_CLICK_ACTIVATION_ACCESSIBLE_NAME" desc="Text for the accessible name that announced when the learn more button is clicked">
Opened learn more link in the browser
</message>
<message name="IDS_ASH_MAHI_EDUCATIONAL_NUDGE_TITLE" desc="Title for the educational nudge used to discover the Mahi feature">
Right-click to summarize
</message>

@ -0,0 +1 @@
f37d5507245d24e0f5e6473d13534f239725888b

@ -50,6 +50,7 @@
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/animation_builder.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
@ -674,6 +675,8 @@ MahiPanelView::MahiPanelView(MahiUiController* ui_controller)
views::CreateEmptyBorder(kInputTextfieldPadding))
.SetPlaceholderText(l10n_util::GetStringUTF16(
IDS_ASH_MAHI_PANEL_INPUT_PLACEHOLDER_TEXT))
.SetAccessibleName(l10n_util::GetStringUTF16(
IDS_ASH_MAHI_PANEL_INPUT_PLACEHOLDER_TEXT))
.SetFontList(
TypographyProvider::Get()->ResolveTypographyToken(
TypographyToken::kCrosAnnotation1))
@ -889,6 +892,8 @@ void MahiPanelView::OnLearnMoreLinkClicked() {
NewWindowDelegate::Disposition::kNewForegroundTab);
base::UmaHistogramEnumeration(mahi_constants::kMahiButtonClickHistogramName,
mahi_constants::PanelButton::kLearnMoreLink);
GetViewAccessibility().AnnounceText((l10n_util::GetStringUTF16(
IDS_ASH_MAHI_LEARN_MORE_CLICK_ACTIVATION_ACCESSIBLE_NAME)));
}
void MahiPanelView::OnSendButtonPressed() {

@ -36,6 +36,7 @@
#include "ui/compositor/layer.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/animated_image_view.h"
@ -260,16 +261,19 @@ bool MahiQuestionAnswerView::GetViewVisibility(VisibilityState state) const {
void MahiQuestionAnswerView::OnUpdated(const MahiUiUpdate& update) {
switch (update.type()) {
case MahiUiUpdateType::kAnswerLoaded:
case MahiUiUpdateType::kAnswerLoaded: {
RemoveLoadingAnimatedImage();
base::UmaHistogramTimes(
mahi_constants::kAnswerLoadingTimeHistogramName,
base::TimeTicks::Now() - answer_start_loading_time_);
AddChildView(
CreateQuestionAnswerRow(update.GetAnswer(), /*is_question=*/false));
auto& answer = update.GetAnswer();
AddChildView(CreateQuestionAnswerRow(answer, /*is_question=*/false));
GetViewAccessibility().AnnounceText(answer);
return;
}
case MahiUiUpdateType::kContentsRefreshInitiated:
question_count_reporter_.ReportDataAndReset();
RemoveAllChildViews();

@ -26,6 +26,8 @@
#include "chromeos/strings/grit/chromeos_strings.h"
#include "chromeos/ui/vector_icons/vector_icons.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/accessibility/ax_enums.mojom-shared.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
@ -39,6 +41,7 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/vector_icon_types.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/button.h"
@ -200,6 +203,7 @@ MahiMenuView::MahiMenuView(Surface surface)
views::style::CONTEXT_DIALOG_TITLE, views::style::STYLE_HEADLINE_5));
header_label->SetEnabledColorId(ui::kColorSysOnSurface);
header_label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
header_label->GetViewAccessibility().SetRole(ax::mojom::Role::kHeading);
header_left_container->AddChildView(
std::make_unique<chromeos::ExperimentBadge>());
@ -300,6 +304,11 @@ void MahiMenuView::RequestFocus() {
settings_button_->RequestFocus();
}
void MahiMenuView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->role = ax::mojom::Role::kDialog;
node_data->SetName(l10n_util::GetStringUTF16(IDS_ASH_MAHI_MENU_TITLE));
}
void MahiMenuView::UpdateBounds(const gfx::Rect& anchor_view_bounds) {
// TODO(b/318733414): Move `editor_menu::GetEditorMenuBounds` to a common
// place for use

@ -13,6 +13,10 @@
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/textfield/textfield_controller.h"
namespace ui {
struct AXNodeData;
} // namespace ui
namespace views {
class FlexLayoutView;
class ImageButton;
@ -50,6 +54,7 @@ class MahiMenuView : public chromeos::editor_menu::PreTargetHandlerView {
// chromeos::editor_menu::PreTargetHandlerView:
void RequestFocus() override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// Updates the bounds of the view according to the given `anchor_view_bounds`.
void UpdateBounds(const gfx::Rect& anchor_view_bounds);