1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-11 23:54:18 +00:00

Accessibility: Correctly report number of disclosed rows in TreeView on macOS

This commit is contained in:
reuk 2022-07-04 20:30:08 +01:00
parent 081412eb13
commit dd92f66387
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
3 changed files with 58 additions and 0 deletions

View file

@ -56,6 +56,9 @@ public:
/** Returns the AccessibilityHandler of the table which contains the cell. */
virtual const AccessibilityHandler* getTableHandler() const = 0;
/** Returns a list of the accessibility elements that are disclosed by this element, if any. */
virtual std::vector<const AccessibilityHandler*> getDisclosedRows() const { return {}; }
};
} // namespace juce

View file

@ -528,6 +528,33 @@ private:
return 0;
});
addMethod (@selector (accessibilityDisclosedRows), [] (id self, SEL) -> id
{
if (auto* handler = getHandler (self))
{
if (auto* cellInterface = handler->getCellInterface())
{
const auto rows = cellInterface->getDisclosedRows();
auto* result = [NSMutableArray arrayWithCapacity: rows.size()];
for (const auto& row : rows)
{
if (row != nullptr)
[result addObject: static_cast<id> (row->getNativeImplementation())];
else
[result addObject: [NSAccessibilityElement accessibilityElementWithRole: NSAccessibilityRowRole
frame: NSZeroRect
label: @"Offscreen Row"
parent: self]];
}
return result;
}
}
return nil;
});
addMethod (@selector (isAccessibilityExpanded), [] (id self, SEL) -> BOOL
{
if (auto* handler = getHandler (self))

View file

@ -161,6 +161,34 @@ private:
return getItemDepth (&itemComponent.getRepresentedItem());
}
std::vector<const AccessibilityHandler*> getDisclosedRows() const override
{
const auto& representedItem = itemComponent.getRepresentedItem();
const auto* tree = representedItem.getOwnerView();
if (tree == nullptr)
return {};
const auto numSubItems = representedItem.isOpen() ? representedItem.getNumSubItems() : 0;
std::vector<const AccessibilityHandler*> result;
result.reserve ((size_t) numSubItems);
for (auto i = 0; i < numSubItems; ++i)
{
result.push_back ([&]() -> const AccessibilityHandler*
{
if (auto* subItem = representedItem.getSubItem (i))
if (auto* component = tree->getItemComponent (subItem))
return component->getAccessibilityHandler();
return nullptr;
}());
}
return result;
}
const AccessibilityHandler* getTableHandler() const override
{
if (auto* tree = itemComponent.getRepresentedItem().getOwnerView())