0

desk_profiles: Customize chromevox strings for desk action context menu

This customizes chromevox strings for desk action context menu.

Bug: b/324001629
Test: Manual
Change-Id: Ib993c131b68de8c3c8efe95e3ef8bd8c0a1701e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5278679
Reviewed-by: Daniel Andersson <dandersson@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1258179}
This commit is contained in:
Yongshun Liu
2024-02-08 21:54:49 +00:00
parent e2213fe186
commit 8ba9013887
4 changed files with 47 additions and 5 deletions

@ -2686,6 +2686,12 @@ Style notes:
<message name="IDS_ASH_DESKS_DESK_PROFILES_BUTTON" desc="The desk profile button's accessible name">
Desk profile menu
</message>
<message name="IDS_ASH_DESKS_MENU_ITEM_PROFILE_CHECKED" desc="The profile menu item's accessible name">
<ph name="PROFILE_NAME">$1</ph> <ph name="EMAIL">$2</ph> Check box checked.
</message>
<message name="IDS_ASH_DESKS_MENU_ITEM_PROFILE_NOT_CHECKED" desc="The profile menu item's accessible name">
<ph name="PROFILE_NAME">$1</ph> <ph name="EMAIL">$2</ph> Check box not checked.
</message>
<message name="IDS_ASH_DESKS_OPEN_PROFILE_MANAGER" desc="The tooltip and context menu text that describes the action of open the profile manager.">
Manage profiles
</message>

@ -0,0 +1 @@
a428ef2c5a7fd289b1a681691db2c189798d8bc2

@ -0,0 +1 @@
8cce2004a794380f9335e2874f77d3561a9403e4

@ -4,6 +4,8 @@
#include "ash/wm/desks/desk_action_context_menu.h"
#include <string>
#include "ash/public/cpp/desk_profiles_delegate.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
@ -18,6 +20,7 @@
#include "ui/views/controls/menu/menu_item_view.h"
#include "ui/views/controls/menu/menu_model_adapter.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/menu/submenu_view.h"
#include "ui/views/layout/box_layout_view.h"
#include "ui/views/view.h"
@ -88,6 +91,9 @@ DeskActionContextMenu::DeskActionContextMenu(Config config)
}
};
// Set the accessible name for menu items here and then pipe the information
// to the view instances during `ShowContextMenuForViewImpl()`.
if (config_.profiles.size() > 1) {
for (size_t i = 0; i != config_.profiles.size(); ++i) {
const auto& summary = config_.profiles[i];
@ -105,32 +111,44 @@ DeskActionContextMenu::DeskActionContextMenu(Config config)
auto entry_index = context_menu_model_.GetItemCount() - 1;
context_menu_model_.SetMinorText(entry_index, summary.email);
int profile_a11y_id = IDS_ASH_DESKS_MENU_ITEM_PROFILE_NOT_CHECKED;
if (summary.profile_id == config_.current_lacros_profile_id) {
context_menu_model_.SetMinorIcon(
entry_index, ui::ImageModel::FromVectorIcon(
kHollowCheckCircleIcon,
cros_tokens::kCrosSysPrimary, kCheckButtonSize));
profile_a11y_id = IDS_ASH_DESKS_MENU_ITEM_PROFILE_CHECKED;
}
context_menu_model_.SetAccessibleNameAt(
entry_index, l10n_util::GetStringFUTF16(profile_a11y_id, summary.name,
summary.email));
}
context_menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
const std::u16string profile_manager_a11y =
l10n_util::GetStringUTF16(IDS_ASH_DESKS_OPEN_PROFILE_MANAGER);
context_menu_model_.AddItemWithIcon(
CommandId::kShowProfileManager,
l10n_util::GetStringUTF16(IDS_ASH_DESKS_OPEN_PROFILE_MANAGER),
CommandId::kShowProfileManager, profile_manager_a11y,
ui::ImageModel::FromVectorIcon(
kSettingsIcon, cros_tokens::kCrosSysOnSurface, kCheckButtonSize));
context_menu_model_.SetAccessibleNameAt(
context_menu_model_.GetItemCount() - 1, profile_manager_a11y);
separator_needed = true;
}
if (config_.combine_desks_target_name) {
maybe_add_separator();
context_menu_model_.AddItemWithIcon(
CommandId::kCombineDesks,
const std::u16string combine_desks_a11y =
l10n_util::GetStringFUTF16(IDS_ASH_DESKS_COMBINE_DESKS_DESCRIPTION,
*config_.combine_desks_target_name),
*config_.combine_desks_target_name);
context_menu_model_.AddItemWithIcon(
CommandId::kCombineDesks, combine_desks_a11y,
ui::ImageModel::FromVectorIcon(kCombineDesksIcon,
ui::kColorAshSystemUIMenuIcon));
context_menu_model_.SetAccessibleNameAt(
context_menu_model_.GetItemCount() - 1, combine_desks_a11y);
}
if (config_.close_all_target_name) {
@ -141,6 +159,8 @@ DeskActionContextMenu::DeskActionContextMenu(Config config)
CommandId::kCloseAll, close_all_a11y,
ui::ImageModel::FromVectorIcon(kMediumOrLargeCloseButtonIcon,
ui::kColorAshSystemUIMenuIcon));
context_menu_model_.SetAccessibleNameAt(
context_menu_model_.GetItemCount() - 1, close_all_a11y);
}
menu_model_adapter_ =
@ -197,6 +217,20 @@ void DeskActionContextMenu::ShowContextMenuForViewImpl(
/*button_controller=*/nullptr,
/*bounds=*/gfx::Rect(point, gfx::Size()),
config_.anchor_position, source_type);
// Pipe accessible names from the menu model to the view instances. Please
// note, a separator in menu model does *not* end up being represented by a
// view instance.
auto item_views = root_menu_item_view_->GetSubmenu()->GetMenuItems();
const size_t model_count = context_menu_model_.GetItemCount();
CHECK_LE(item_views.size(), model_count);
for (size_t view_index = 0, model_index = 0; model_index < model_count;
model_index++) {
if (auto a11y_name = context_menu_model_.GetAccessibleNameAt(model_index);
!a11y_name.empty()) {
item_views[view_index++]->SetAccessibleName(a11y_name);
}
}
}
void DeskActionContextMenu::MaybeSetLacrosProfileId(int command_id) {