fix: NVDA says the section focus enters, a setting's explanation and each fog step

NVDA passes over a group that is not content as well as control, so titled
panels and the landmarks are now both. A setting's explanation and the note on
why the simulator ignores it are read after its name. The key under each setting
is no longer a silent stop for Tab, and a step of the fog slider moves the shown
distance.
This commit is contained in:
maj00r
2026-11-15 18:45:06 +01:00
parent d2b8cdf3ba
commit edd530cb4b
7 changed files with 86 additions and 6 deletions

View File

@@ -92,7 +92,7 @@ public class NamedGroupTests
Assert.Equal("Scenerie", AutomationProperties.GetName(panel));
Assert.Equal(AutomationControlType.Group, AutomationProperties.GetControlTypeOverride(panel));
Assert.True(AutomationProperties.GetIsControlElementOverride(panel));
Assert.Equal(AccessibilityView.Content, AutomationProperties.GetAccessibilityView(panel));
}
[Fact]
@@ -103,6 +103,7 @@ public class NamedGroupTests
Assert.Null(AutomationProperties.GetName(panel));
Assert.Null(AutomationProperties.GetControlTypeOverride(panel));
Assert.Equal(AccessibilityView.Default, AutomationProperties.GetAccessibilityView(panel));
}
[Fact]

View File

@@ -141,6 +141,34 @@ public class ScreenReaderNamesTests
Assert.Null(AutomationProperties.GetName(browse));
}
[Fact]
public void A_setting_row_describes_its_inputs_with_its_explanation()
{
var check = new CheckBox { Content = "Tryb pełnoekranowy" };
var slider = new Slider();
var row = new SettingRow { Label = "Ekran", Content = Row(check, slider) };
row.Description = "Gra zajmie cały ekran.";
row.IdleNote = "Ten symulator nie zna tego ustawienia.";
Assert.Equal("Gra zajmie cały ekran., Ten symulator nie zna tego ustawienia.", AutomationProperties.GetHelpText(check));
Assert.Equal(AutomationProperties.GetHelpText(check), AutomationProperties.GetHelpText(slider));
Assert.Null(AutomationProperties.GetName(check));
row.Description = null;
row.IdleNote = null;
Assert.Null(AutomationProperties.GetHelpText(check));
}
[Fact]
public void A_description_given_on_purpose_is_left_alone()
{
var box = new TextBox();
AutomationProperties.SetHelpText(box, "Ścieżka do exe");
_ = new SettingRow { Content = box, Description = "Plik symulatora" };
Assert.Equal("Ścieżka do exe", AutomationProperties.GetHelpText(box));
}
[Fact]
public void A_setting_row_without_a_label_leaves_its_input_unnamed()
{

View File

@@ -154,12 +154,47 @@ public static class ScreenReaderNames
string? name = TextOf(panel.Header);
Give(panel, name);
AutomationProperties.SetControlTypeOverride(panel, name is null ? null : AutomationControlType.Group);
AutomationProperties.SetIsControlElementOverride(panel, name is null ? null : true);
// Content as well as control: NVDA passes over a group that is not both.
AutomationProperties.SetAccessibilityView(panel, name is null ? AccessibilityView.Default : AccessibilityView.Content);
}
private static void NameButton(Button button) =>
Give(button, button.Content is string ? null : TextOf(ToolTip.GetTip(button)) ?? TextOf(button.Content));
// The descriptions given here, so a later one replaces it but nothing else.
private static readonly ConditionalWeakTable<StyledElement, string> Described = new();
/// <summary>
/// The inputs of a setting row, described by the row's explanation and the note on
/// why the simulator would pass it over: a reader hears them after the name, where
/// a sighted one sees them under it.
/// </summary>
public static void DescribeInputs(object? content, params string?[] notes)
{
string? text = Join(notes) is { Length: > 0 } joined ? joined : null;
foreach (var input in DescribedInputs(content))
Describe(input, text);
}
private static void Describe(StyledElement target, string? text)
{
string? current = AutomationProperties.GetHelpText(target);
bool ours = Described.TryGetValue(target, out string? given) && current == given;
if (!string.IsNullOrEmpty(current) && !ours)
return;
if (string.IsNullOrEmpty(text))
{
if (ours)
target.ClearValue(AutomationProperties.HelpTextProperty);
Described.Remove(target);
return;
}
AutomationProperties.SetHelpText(target, text);
Described.AddOrUpdate(target, text);
}
/// <summary>
/// The inputs of a setting row, named by the row's label: a list, a slider or a box
/// beside the label otherwise had no name at all.
@@ -188,6 +223,15 @@ public static class ScreenReaderNames
_ => Array.Empty<Control>()
};
// A check box says its own text, so it is described but never named by the row.
private static IEnumerable<Control> DescribedInputs(object? content) => content switch
{
CheckBox box => new[] { (Control)box },
Panel panel => panel.Children.SelectMany(DescribedInputs),
Decorator decorator => DescribedInputs(decorator.Child),
_ => Inputs(content)
};
/// <summary>The text a reader would see on it, or null when it shows none.</summary>
public static string? TextOf(object? content)
{

View File

@@ -80,6 +80,10 @@ public class SettingRow : ContentControl
if (change.Property == ValueTextProperty || change.Property == ContentProperty)
ScreenReaderNames.TellValue(Content, ValueText);
if (change.Property == DescriptionProperty || change.Property == IdleNoteProperty ||
change.Property == ContentProperty)
ScreenReaderNames.DescribeInputs(Content, Description, IdleNote);
}
// Again once in the window: a panel given as content may be filled after it was set.
@@ -88,6 +92,7 @@ public class SettingRow : ContentControl
base.OnLoaded(e);
ScreenReaderNames.NameInputs(Content, Label);
ScreenReaderNames.TellValue(Content, ValueText);
ScreenReaderNames.DescribeInputs(Content, Description, IdleNote);
}
private void UpdatePseudoClasses()

View File

@@ -27,7 +27,7 @@
<Grid ColumnDefinitions="Auto,*,Auto" Background="Transparent">
<StackPanel x:Name="TopBarLeft" Grid.Column="0" AutomationProperties.LandmarkType="Navigation" AutomationProperties.ControlTypeOverride="Group" AutomationProperties.IsControlElementOverride="True" Orientation="Horizontal" VerticalAlignment="Stretch">
<StackPanel x:Name="TopBarLeft" Grid.Column="0" AutomationProperties.LandmarkType="Navigation" AutomationProperties.ControlTypeOverride="Group" AutomationProperties.AccessibilityView="Content" Orientation="Horizontal" VerticalAlignment="Stretch">
<RadioButton x:Name="NavScenarios" GroupName="nav" Theme="{StaticResource NavTab}"
Tag="scenarios" IsChecked="True"
IsCheckedChanged="Nav_OnCheckedChanged"
@@ -123,7 +123,7 @@
</Grid>
<!-- Scrolls only below the size the pages are laid out for; see KeepPagesUsable. -->
<ScrollViewer x:Name="PageScroll" AutomationProperties.LandmarkType="Main" Margin="3,3,3,0" TabIndex="1"
<ScrollViewer x:Name="PageScroll" AutomationProperties.LandmarkType="Main" AutomationProperties.AccessibilityView="Content" Margin="3,3,3,0" TabIndex="1"
HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled">
<Panel x:Name="PageHost">
<views:Scenarios x:Name="ScenariosView" />

View File

@@ -61,8 +61,10 @@
with no label hides PART_Label, and without this the
column would collapse onto the key and every
explanation would start at a different place again. -->
<!-- Selectable for copying, but no stop for Tab: a reader found
nothing there to say between one setting and the next. -->
<SelectableTextBlock Name="PART_ConfigKey"
Grid.Row="1" Grid.Column="0"
Grid.Row="1" Grid.Column="0" IsTabStop="False"
Text="{TemplateBinding ConfigKey}"
FontFamily="Consolas, DejaVu Sans Mono, Liberation Mono, Menlo, Courier New"
FontSize="11"

View File

@@ -166,7 +166,7 @@
Foreground="{StaticResource CarbonFgDim}"
Text="{Binding [Visibility], Source={x:Static starterNg:App.Loc}}" />
<ctl:ReadableSlider Grid.Row="7" Grid.Column="2" Name="weatherFog" AutomationProperties.Name="{Binding [Visibility], Source={x:Static starterNg:App.Loc}}"
Minimum="0" Maximum="1000"
Minimum="0" Maximum="1000" SmallChange="20" LargeChange="100"
TickFrequency="1" IsSnapToTickEnabled="True"
ValueChanged="Weather_OnSliderChanged" />
<TextBlock Grid.Row="7" Grid.Column="4" Name="weatherFogLabel"