┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/kitemlistview.cpp
diff options
context:
space:
mode:
authorFelix Ernst <[email protected]>2024-10-28 13:25:10 +0000
committerFelix Ernst <[email protected]>2024-10-28 13:25:10 +0000
commitf208acd5f68c8516b9f6a920cc229803637e23e9 (patch)
treef748d6386ed579c494497998097bdc92a432e704 /src/kitemviews/kitemlistview.cpp
parent4d5cab6a5fcaa8edeb18cbacd2061cc098054882 (diff)
Overhaul main view accessibility
This commit brings the main view of Dolphin into a usable state accessibility-wise. Users of screen readers should have a way better experience while browsing files and folders and navigating along the file system hierarchy. This commit fixes most of the remaining already-identified accessibility issues listed in https://invent.kde.org/teams/accessibility/collaboration/-/issues/28, but not all. Namely, these should now be fixed: 1. Orca should read the element type in dolphin (file, folder, device, link to folder, link to file) 2. Orca should read complete label in icon and compact view mode, currently it only speaks the name, but there could be additional information like the number of elements or the file size. 3. Orca is not able to announce Selecting / Unselecting files in Dolphin. It also never announces how many items are selected in total. (Announcing the total selection can be done by reading out the view element or by pressing the Tab key to get to the status bar with the relevant information.) 4. Dolphin opens on the home directory, but Orca doesn't tell you so. Consider enclosing the area in a frame/panel which updates its accessible name each time you modify the current path by entering or leaving a directory. 5. I don't know what the folder presentation widget is, but it should be presented as a grid view. Currently, we have a terrible experience because the entire row of folders is read at once, with no indication that we can move left and right with the arrows to go between the elements of a row. When I found that out, however, I discovered that when you're on the last icon of the first row and press right arrow, you get to the first icon of the next row, but that's not announced, instead, the whole row is announced at once 6. Orca should announce the current elements instead of "layered pane" when the Folder / File view gets the focus in dolphin 7. Orca reads only name in Table View only of Dolphin 8. Items are sometimes confusingly announced as "collapsed" in contexts in which there is no concept of collapsing/expanding e.g. in icon view mode. A lot of code was moved around and renamed. The three accessibility classes, which all used to be in the same file, are moved into separate files. *Acknowledgement* Thanks to Christian Hempfling and bgt lover for testing as well as originally identifying a lot of the pain points being addressed here. This work is part of a my project funded through the NGI0 Entrust Fund, a fund established by NLnet with financial support from the European Commission's Next Generation Internet programme, under the aegis of DG Communications Networks, Content and Technology. https://kde.org/announcements/2024_ngi_openletter/
Diffstat (limited to 'src/kitemviews/kitemlistview.cpp')
-rw-r--r--src/kitemviews/kitemlistview.cpp61
1 files changed, 51 insertions, 10 deletions
diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp
index afc392810..b0ea32940 100644
--- a/src/kitemviews/kitemlistview.cpp
+++ b/src/kitemviews/kitemlistview.cpp
@@ -8,12 +8,16 @@
#include "kitemlistview.h"
+#ifndef QT_NO_ACCESSIBILITY
+#include "accessibility/kitemlistcontaineraccessible.h"
+#include "accessibility/kitemlistdelegateaccessible.h"
+#include "accessibility/kitemlistviewaccessible.h"
+#endif
#include "dolphindebug.h"
#include "kitemlistcontainer.h"
#include "kitemlistcontroller.h"
#include "kitemlistheader.h"
#include "kitemlistselectionmanager.h"
-#include "kitemlistviewaccessible.h"
#include "kstandarditemlistwidget.h"
#include "private/kitemlistheaderwidget.h"
@@ -1240,6 +1244,11 @@ void KItemListView::slotItemsInserted(const KItemRangeList &itemRanges)
if (useAlternateBackgrounds()) {
updateAlternateBackgrounds();
}
+#ifndef QT_NO_ACCESSIBILITY
+ if (QAccessible::isActive()) { // Announce that the count of items has changed.
+ static_cast<KItemListViewAccessible *>(QAccessible::queryAccessibleInterface(this))->announceDescriptionChange();
+ }
+#endif
}
void KItemListView::slotItemsRemoved(const KItemRangeList &itemRanges)
@@ -1358,6 +1367,11 @@ void KItemListView::slotItemsRemoved(const KItemRangeList &itemRanges)
if (useAlternateBackgrounds()) {
updateAlternateBackgrounds();
}
+#ifndef QT_NO_ACCESSIBILITY
+ if (QAccessible::isActive()) { // Announce that the count of items has changed.
+ static_cast<KItemListViewAccessible *>(QAccessible::queryAccessibleInterface(this))->announceDescriptionChange();
+ }
+#endif
}
void KItemListView::slotItemsMoved(const KItemRange &itemRange, const QList<int> &movedToIndexes)
@@ -1416,10 +1430,12 @@ void KItemListView::slotItemsChanged(const KItemRangeList &itemRanges, const QSe
doLayout(NoAnimation);
}
+#ifndef QT_NO_ACCESSIBILITY
QAccessibleTableModelChangeEvent ev(this, QAccessibleTableModelChangeEvent::DataChanged);
ev.setFirstRow(itemRange.index);
ev.setLastRow(itemRange.index + itemRange.count);
QAccessible::updateAccessibility(&ev);
+#endif
}
doLayout(NoAnimation);
@@ -1483,8 +1499,6 @@ void KItemListView::slotSortRoleChanged(const QByteArray &current, const QByteAr
void KItemListView::slotCurrentChanged(int current, int previous)
{
- Q_UNUSED(previous)
-
// In SingleSelection mode (e.g., in the Places Panel), the current item is
// always the selected item. It is not necessary to highlight the current item then.
if (m_controller->selectionBehavior() != KItemListController::SingleSelection) {
@@ -1496,25 +1510,52 @@ void KItemListView::slotCurrentChanged(int current, int previous)
KItemListWidget *currentWidget = m_visibleItems.value(current, nullptr);
if (currentWidget) {
currentWidget->setCurrent(true);
+ if (hasFocus() || (previousWidget && previousWidget->hasFocus())) {
+ currentWidget->setFocus(); // Mostly for accessibility, because keyboard events are handled correctly either way.
+ }
}
}
-
- QAccessibleEvent ev(this, QAccessible::Focus);
- ev.setChild(current);
- QAccessible::updateAccessibility(&ev);
+#ifndef QT_NO_ACCESSIBILITY
+ if (QAccessible::isActive()) {
+ if (current >= 0) {
+ QAccessibleEvent accessibleFocusCurrentItemEvent(this, QAccessible::Focus);
+ accessibleFocusCurrentItemEvent.setChild(current);
+ QAccessible::updateAccessibility(&accessibleFocusCurrentItemEvent);
+ }
+ static_cast<KItemListViewAccessible *>(QAccessible::queryAccessibleInterface(this))->announceDescriptionChange();
+ }
+#endif
}
void KItemListView::slotSelectionChanged(const KItemSet &current, const KItemSet &previous)
{
- Q_UNUSED(previous)
-
QHashIterator<int, KItemListWidget *> it(m_visibleItems);
while (it.hasNext()) {
it.next();
const int index = it.key();
KItemListWidget *widget = it.value();
- widget->setSelected(current.contains(index));
+ const bool isSelected(current.contains(index));
+ widget->setSelected(isSelected);
+
+#ifndef QT_NO_ACCESSIBILITY
+ if (!QAccessible::isActive()) {
+ continue;
+ }
+ // Let the screen reader announce "selected" or "not selected" for the active item.
+ const bool wasSelected(previous.contains(index));
+ if (isSelected != wasSelected) {
+ QAccessibleEvent accessibleSelectionChangedEvent(this, QAccessible::Selection);
+ accessibleSelectionChangedEvent.setChild(index);
+ QAccessible::updateAccessibility(&accessibleSelectionChangedEvent);
+ }
}
+ // Usually the below does not have an effect because the view will not have focus at this moment but one of its list items. Still we announce the
+ // change of the accessibility description just in case the user manually moved focus up by one.
+ static_cast<KItemListViewAccessible *>(QAccessible::queryAccessibleInterface(this))->announceDescriptionChange();
+#else
+ }
+ Q_UNUSED(previous)
+#endif
}
void KItemListView::slotAnimationFinished(QGraphicsWidget *widget, KItemListViewAnimation::AnimationType type)