From e2aa2a2048ceaf2bf570e8785520b3e764bdb0b7 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 7 Jun 2021 16:52:51 +0100 Subject: [PATCH] Accessibility: Throttle TreeView/ListBox Viewport move AccessibilityEvent::structureChanged notifications --- modules/juce_gui_basics/widgets/juce_ListBox.cpp | 14 +++++++++++--- .../juce_gui_basics/widgets/juce_TreeView.cpp | 16 ++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/modules/juce_gui_basics/widgets/juce_ListBox.cpp b/modules/juce_gui_basics/widgets/juce_ListBox.cpp index 6da89672e4..06c01a228e 100644 --- a/modules/juce_gui_basics/widgets/juce_ListBox.cpp +++ b/modules/juce_gui_basics/widgets/juce_ListBox.cpp @@ -274,7 +274,8 @@ public: //============================================================================== -class ListBox::ListViewport : public Viewport +class ListBox::ListViewport : public Viewport, + private Timer { public: ListViewport (ListBox& lb) : owner (lb) @@ -319,8 +320,7 @@ public: if (auto* m = owner.getModel()) m->listWasScrolled(); - if (auto* handler = owner.getAccessibilityHandler()) - handler->notifyAccessibilityEvent (AccessibilityEvent::structureChanged); + startTimer (50); } void updateVisibleArea (const bool makeSureItUpdatesContent) @@ -456,6 +456,14 @@ public: } private: + void timerCallback() override + { + stopTimer(); + + if (auto* handler = owner.getAccessibilityHandler()) + handler->notifyAccessibilityEvent (AccessibilityEvent::structureChanged); + } + ListBox& owner; OwnedArray rows; int firstIndex = 0, firstWholeIndex = 0, lastWholeIndex = 0; diff --git a/modules/juce_gui_basics/widgets/juce_TreeView.cpp b/modules/juce_gui_basics/widgets/juce_TreeView.cpp index 266123c227..54949d2f0a 100644 --- a/modules/juce_gui_basics/widgets/juce_TreeView.cpp +++ b/modules/juce_gui_basics/widgets/juce_TreeView.cpp @@ -621,7 +621,8 @@ private: }; //============================================================================== -class TreeView::TreeViewport : public Viewport +class TreeView::TreeViewport : public Viewport, + private Timer { public: TreeViewport() = default; @@ -645,9 +646,7 @@ public: lastX = newVisibleArea.getX(); updateComponents (hasScrolledSideways); - if (auto* tree = getParentComponent()) - if (auto* handler = tree->getAccessibilityHandler()) - handler->notifyAccessibilityEvent (AccessibilityEvent::structureChanged); + startTimer (50); } ContentComponent* getContentComp() const noexcept @@ -665,6 +664,15 @@ public: } private: + void timerCallback() override + { + stopTimer(); + + if (auto* tree = getParentComponent()) + if (auto* handler = tree->getAccessibilityHandler()) + handler->notifyAccessibilityEvent (AccessibilityEvent::structureChanged); + } + int lastX = -1; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TreeViewport)