Merge branch 'accessible_sidebar' into 'main'

sidebar: Fix a11y

See merge request GNOME/fractal!1491
This commit is contained in:
Lukáš Tyrychtr 2023-12-15 18:45:02 +00:00
commit 6f1efe33a2
3 changed files with 46 additions and 4 deletions

View File

@ -21,6 +21,9 @@ mod imp {
/// The `CategoryType` to show a label for during a drag-and-drop
/// operation.
pub show_label_for_category: Cell<CategoryType>,
/// The label showing the category name.
#[template_child]
pub display_name: TemplateChild<gtk::Label>,
}
#[glib::object_subclass]
@ -214,4 +217,9 @@ impl CategoryRow {
self.notify("show-label-for-category");
self.notify("label");
}
/// Returns the display name widget.
pub fn display_name(&self) -> gtk::Label {
self.imp().display_name.clone()
}
}

View File

@ -1,10 +1,11 @@
use adw::{prelude::*, subclass::prelude::*};
use gettextrs::gettext;
use gtk::{gdk, glib, glib::clone, CompositeTemplate};
use gtk::{accessible::Property, gdk, glib, glib::clone, CompositeTemplate};
use super::Row;
use crate::{
components::{ContextMenuBin, ContextMenuBinExt, ContextMenuBinImpl},
i18n::gettext_f,
session::model::{HighlightFlags, Room, RoomType},
spawn, toast,
utils::{message_dialog, BoundObject},
@ -219,12 +220,18 @@ impl RoomRow {
obj.update_direct_icon();
}),
);
let name_handler =
room.connect_display_name_notify(clone!(@weak self as obj => move |_| {
obj.update_accessibility_label();
}));
if room.category() == RoomType::Left {
imp.display_name.add_css_class("dim-label");
}
imp.room.set(room, vec![highlight_handler, direct_handler]);
imp.room
.set(room, vec![highlight_handler, direct_handler, name_handler]);
self.update_accessibility_label();
}
self.update_highlight();
@ -413,4 +420,27 @@ impl RoomRow {
imp.display_name_box.remove(&icon);
}
}
fn update_accessibility_label(&self) {
self.parent()
.unwrap()
.update_property(&[Property::Label(&self.accessible_label())]);
}
fn accessible_label(&self) -> String {
let Some(room) = self.room() else {
return String::new();
};
if room.is_direct() {
gettext_f(
// Translators: Do NOT translate the content between '{' and '}', this is a
// variable name. Presented to screen readers when a
// room is a direct chat with another user.
"Direct chat with {name}",
&[("name", &room.display_name())],
)
} else {
room.display_name()
}
}
}

View File

@ -1,6 +1,6 @@
use adw::{prelude::*, subclass::prelude::*};
use gettextrs::gettext;
use gtk::{gdk, glib, glib::clone};
use gtk::{accessible::Relation, gdk, glib, glib::clone};
use super::{CategoryRow, IconItemRow, RoomRow, Sidebar, VerificationRow};
use crate::{
@ -34,6 +34,7 @@ mod imp {
fn class_init(klass: &mut Self::Class) {
klass.set_css_name("sidebar-row");
klass.set_accessible_role(gtk::AccessibleRole::ListItem);
}
}
@ -186,6 +187,9 @@ impl Row {
} else {
let child = CategoryRow::new();
self.set_child(Some(&child));
self.update_relation(&[Relation::LabelledBy(&[&child
.display_name()
.upcast()])]);
child
};
child.set_category(Some(category.clone()));