0

Fix volume slider accessibility

This CL adds extra accessibility info on the
volume slider in quick settings to warn the
user that pressing enter will mute audio.
We also update the accessibility info between
the muted and unmuted states.

Bug: b/324593756
Change-Id: I9dc9f548ac8661b172be4f57aec0b9e105f56f2d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5789939
Commit-Queue: Ahmed Mehfooz <amehfooz@chromium.org>
Reviewed-by: Jiaming Cheng <jiamingc@chromium.org>
Auto-Submit: Ahmed Mehfooz <amehfooz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1343299}
This commit is contained in:
amehfooz
2024-08-18 22:17:27 +00:00
committed by Chromium LUCI CQ
parent 993e0d67cd
commit f3b72b265c
8 changed files with 56 additions and 1 deletions

@ -1118,7 +1118,11 @@ Style notes:
<message name="IDS_ASH_STATUS_TRAY_VOLUME_SLIDER_LABEL" desc="The accessible text for the volume slider in the tray.">
Volume
</message>
<message name="IDS_ASH_STATUS_TRAY_VOLUME_SLIDER_ACCESSIBILITY_ANNOUNCEMENT" desc="The accessibile text for the slider when it is focused and not muted.">
<ph name="VOLUME_LEVEL">$1<ex>55</ex></ph>, Hitting enter will mute audio.
</message>
<message name="IDS_ASH_STATUS_TRAY_VOLUME_SLIDER_MUTED_ACCESSIBILITY_ANNOUNCEMENT" desc="The accessible text for the slider when it is muted.">
<ph name="VOLUME_LEVEL">$1<ex>55</ex></ph>, Muted </message>
<message name="IDS_ASH_ACCESSIBILITY_FEATURE_SHORTCUT_DISABLED_TITLE"
desc="Title to indicate that the shortcut for an accessibility feature has been disabled.">
Shortcut turned off

@ -0,0 +1 @@
388fc27de81ddea9c1163006165a1df8726df7fc

@ -0,0 +1 @@
906edc23d0254f166fc5ebaf5704c75f2365e380

@ -525,6 +525,11 @@ LabeledSliderView* AudioDetailedView::CreateLabeledSliderView(
device.IsInternalMic());
} else {
slider = unified_volume_slider_controller_->CreateVolumeSlider(device.id);
if (device.active) {
views::AsViewClass<QuickSettingsSlider>(
views::AsViewClass<UnifiedVolumeView>(slider.get())->slider())
->set_is_toggleable_volume_slider(true);
}
}
auto* labeled_slider_view = views::AsViewClass<LabeledSliderView>(

@ -4,10 +4,12 @@
#include "ash/system/unified/quick_settings_slider.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/style/color_util.h"
#include "base/notreached.h"
#include "cc/paint/paint_flags.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/color/color_id.h"
@ -110,6 +112,28 @@ int QuickSettingsSlider::GetInactiveRadioSliderRoundedCornerRadius() {
return kInactiveRadioSliderRoundedRadius + kFocusOffset;
}
void QuickSettingsSlider::GetAccessibleNodeData(ui::AXNodeData* node_data) {
View::GetAccessibleNodeData(node_data);
node_data->role = ax::mojom::Role::kSlider;
std::u16string volume_level = base::UTF8ToUTF16(
base::StringPrintf("%d%%", static_cast<int>(GetValue() * 100 + 0.5)));
if (is_toggleable_volume_slider_) {
std::u16string message = l10n_util::GetStringFUTF16(
slider_style_ == Style::kDefaultMuted
? IDS_ASH_STATUS_TRAY_VOLUME_SLIDER_MUTED_ACCESSIBILITY_ANNOUNCEMENT
: IDS_ASH_STATUS_TRAY_VOLUME_SLIDER_ACCESSIBILITY_ANNOUNCEMENT,
volume_level);
node_data->SetValue(message);
} else {
node_data->SetValue(volume_level);
}
node_data->AddAction(ax::mojom::Action::kIncrement);
node_data->AddAction(ax::mojom::Action::kDecrement);
}
SkColor QuickSettingsSlider::GetThumbColor() const {
switch (slider_style_) {
case Style::kDefault:

@ -74,8 +74,14 @@ class ASH_EXPORT QuickSettingsSlider : public views::Slider {
gfx::Rect GetInactiveRadioSliderRect();
int GetInactiveRadioSliderRoundedCornerRadius();
void set_is_toggleable_volume_slider(bool is_toggleable_volume_slider) {
is_toggleable_volume_slider_ = is_toggleable_volume_slider;
}
bool is_toggleable_volume_slider() { return is_toggleable_volume_slider_; }
private:
// views::Slider:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
SkColor GetThumbColor() const override;
SkColor GetTroughColor() const override;
@ -83,7 +89,13 @@ class ASH_EXPORT QuickSettingsSlider : public views::Slider {
void OnPaint(gfx::Canvas* canvas) override;
void OnThemeChanged() override;
// The style of the slider.
Style slider_style_;
// Indicates if the slider can be toggled to mute/unmute volume. Used for
// additional accessibility warnings to make sure a user cannot accidentally
// turn off volume.
bool is_toggleable_volume_slider_ = false;
};
// A slider that ignores inputs. This will be used in the

@ -143,6 +143,10 @@ void UnifiedSliderView::OnEvent(ui::Event* event) {
return;
}
if (slider_ && !slider_->GetEnableAccessibilityEvents()) {
slider_->SetEnableAccessibilityEvents(true);
}
auto* key_event = event->AsKeyEvent();
auto key_code = key_event->key_code();

@ -21,6 +21,7 @@
#include "ash/system/accessibility/unified_accessibility_detailed_view_controller.h"
#include "ash/system/audio/unified_audio_detailed_view_controller.h"
#include "ash/system/audio/unified_volume_slider_controller.h"
#include "ash/system/audio/unified_volume_view.h"
#include "ash/system/bluetooth/bluetooth_detailed_view_controller.h"
#include "ash/system/bluetooth/bluetooth_feature_pod_controller.h"
#include "ash/system/brightness/quick_settings_display_detailed_view_controller.h"
@ -137,6 +138,9 @@ UnifiedSystemTrayController::CreateQuickSettingsView(int max_height) {
std::make_unique<UnifiedVolumeSliderController>(this);
unified_volume_view_ =
qs_view->AddSliderView(volume_slider_controller_->CreateView());
views::AsViewClass<QuickSettingsSlider>(
views::AsViewClass<UnifiedVolumeView>(unified_volume_view_)->slider())
->set_is_toggleable_volume_slider(true);
brightness_slider_controller_ =
std::make_unique<UnifiedBrightnessSliderController>(