Skip to content

Commit 108f89b

Browse files
authored
AccountView: make entry validated screen reader accessible (#211)
1 parent 9eb2990 commit 108f89b

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You'll need the following dependencies:
1414
* libgranite-7-dev >= 7.4.0
1515
* libaccountsservice-dev
1616
* libgnomekbd-dev
17-
* libgtk-4-dev
17+
* libgtk-4-dev >=4.14
1818
* libadwaita-1-dev >= 1.4
1919
* libjson-glib-dev
2020
* libpantheon-wayland-1-dev

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ gee_dep = dependency('gee-0.8')
1616
glib_dep = dependency('glib-2.0', version: '>=2.74')
1717
gobject_dep = dependency('gobject-2.0')
1818
granite_dep = dependency('granite-7', version: '>=7.4.0')
19-
gtk_dep = dependency('gtk4')
19+
gtk_dep = dependency('gtk4', version: '>=4.14') # Gtk.Accessible.announce
2020
gtk_wayland_dep = dependency('gtk4-wayland')
2121
gtk_x11_dep = dependency('gtk4-x11')
2222
adw_dep = dependency('libadwaita-1', version: '>=1.4.0')

src/Views/AccountView.vala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class Installer.AccountView : AbstractInstallerView {
4646
private Gtk.LevelBar pw_levelbar;
4747
private Granite.ValidatedEntry hostname_entry;
4848

49+
private uint announce_timeout_id;
50+
4951
construct {
5052
var avatar = new Adw.Avatar (104, null, true) {
5153
margin_top = 12,
@@ -102,6 +104,7 @@ public class Installer.AccountView : AbstractInstallerView {
102104
sensitive = false,
103105
visibility = false
104106
};
107+
confirm_entry.update_property (Gtk.AccessibleProperty.REQUIRED, true, -1);
105108

106109
var confirm_label = new Granite.HeaderLabel (_("Confirm Password")) {
107110
mnemonic_widget = confirm_entry
@@ -227,13 +230,23 @@ public class Installer.AccountView : AbstractInstallerView {
227230
pw_error_revealer.reveal_child = false;
228231

229232
pw_levelbar.value = quality;
233+
234+
if (quality <= 50) {
235+
queue_announce (pw_entry, _("Acceptable password"));
236+
} else if (quality <= 75) {
237+
queue_announce (pw_entry, _("Good password"));
238+
} else {
239+
queue_announce (pw_entry, _("Great password"));
240+
}
230241
} else {
231242
pw_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "dialog-warning-symbolic");
232243

233244
pw_error_revealer.reveal_child = true;
234245
pw_error_revealer.label = ((PasswordQuality.Error) quality).to_string (error);
235246

236247
pw_levelbar.value = 0;
248+
249+
queue_announce (pw_entry, pw_error_revealer.label);
237250
}
238251
return true;
239252
}
@@ -246,8 +259,11 @@ public class Installer.AccountView : AbstractInstallerView {
246259
if (pw_entry.text != confirm_entry.text) {
247260
confirm_entry_revealer.label = _("Passwords do not match");
248261
confirm_entry_revealer.reveal_child = true;
262+
263+
queue_announce (confirm_entry, confirm_entry_revealer.label);
249264
} else {
250265
confirm_entry_revealer.reveal_child = false;
266+
queue_announce (confirm_entry, _("Passwords match"));
251267
return true;
252268
}
253269
} else {
@@ -257,6 +273,19 @@ public class Installer.AccountView : AbstractInstallerView {
257273
return false;
258274
}
259275

276+
private void queue_announce (Gtk.Entry entry, string announcement) {
277+
if (announce_timeout_id != 0) {
278+
Source.remove (announce_timeout_id);
279+
announce_timeout_id = 0;
280+
}
281+
282+
announce_timeout_id = Timeout.add (500, () => {
283+
entry.announce (announcement, MEDIUM);
284+
announce_timeout_id = 0;
285+
return GLib.Source.REMOVE;
286+
});
287+
}
288+
260289
private bool check_username () {
261290
string username_entry_text = username_entry.text;
262291
bool username_is_valid = is_valid_username (username_entry_text);
@@ -275,6 +304,7 @@ public class Installer.AccountView : AbstractInstallerView {
275304
}
276305

277306
username_error_revealer.reveal_child = true;
307+
queue_announce (username_entry, username_error_revealer.label);
278308
}
279309

280310
return false;

0 commit comments

Comments
 (0)