From 18489bb7d75d143708299d6ea20a5825647ae3d0 Mon Sep 17 00:00:00 2001 From: attila Date: Thu, 27 Apr 2023 15:27:31 +0200 Subject: [PATCH] WebBrowserComponent: iOS: Add accessibility integration --- .../accessibility/juce_Accessibility_ios.mm | 3 ++- .../native/juce_UIViewComponentPeer_ios.mm | 22 ++++++++++++++----- .../embedding/juce_UIViewComponent.h | 2 ++ .../native/juce_UIViewComponent_ios.mm | 12 +++++++++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/modules/juce_gui_basics/native/accessibility/juce_Accessibility_ios.mm b/modules/juce_gui_basics/native/accessibility/juce_Accessibility_ios.mm index 38dda05858..3afb6325d9 100644 --- a/modules/juce_gui_basics/native/accessibility/juce_Accessibility_ios.mm +++ b/modules/juce_gui_basics/native/accessibility/juce_Accessibility_ios.mm @@ -277,7 +277,8 @@ private: if (handler->getComponent().isOnDesktop()) return static_cast (handler->getComponent().getWindowHandle()); - if (! handler->getChildren().empty()) + if ( ! handler->getChildren().empty() + || AccessibilityHandler::getNativeChildForComponent (handler->getComponent()) != nullptr) { if (UIAccessibilityElement* container = getContainer (self)) return container; diff --git a/modules/juce_gui_basics/native/juce_UIViewComponentPeer_ios.mm b/modules/juce_gui_basics/native/juce_UIViewComponentPeer_ios.mm index b72a86122a..0d457cf2a6 100644 --- a/modules/juce_gui_basics/native/juce_UIViewComponentPeer_ios.mm +++ b/modules/juce_gui_basics/native/juce_UIViewComponentPeer_ios.mm @@ -56,19 +56,31 @@ static NSArray* getContainerAccessibilityElements (AccessibilityHandler& handler { id accessibleElement = [&childHandler] { - id native = static_cast (childHandler->getNativeImplementation()); + id nativeChild = static_cast (childHandler->getNativeImplementation()); - if (! childHandler->getChildren().empty()) - return [native accessibilityContainer]; + if ( ! childHandler->getChildren().empty() + || AccessibilityHandler::getNativeChildForComponent (childHandler->getComponent()) != nullptr) + { + return [nativeChild accessibilityContainer]; + } - return native; + return nativeChild; }(); if (accessibleElement != nil) [accessibleChildren addObject: accessibleElement]; } - [accessibleChildren addObject: static_cast (handler.getNativeImplementation())]; + id nativeHandler = static_cast (handler.getNativeImplementation()); + + if (auto* view = static_cast (AccessibilityHandler::getNativeChildForComponent (handler.getComponent()))) + { + [static_cast (view) setAccessibilityContainer: [nativeHandler accessibilityContainer]]; + + [accessibleChildren addObject: view]; + } + + [accessibleChildren addObject: nativeHandler]; return accessibleChildren; } diff --git a/modules/juce_gui_extra/embedding/juce_UIViewComponent.h b/modules/juce_gui_extra/embedding/juce_UIViewComponent.h index a225e6a02f..129164c6e3 100644 --- a/modules/juce_gui_extra/embedding/juce_UIViewComponent.h +++ b/modules/juce_gui_extra/embedding/juce_UIViewComponent.h @@ -74,6 +74,8 @@ public: //============================================================================== /** @internal */ void paint (Graphics&) override; + /** @internal */ + std::unique_ptr createAccessibilityHandler() override; private: diff --git a/modules/juce_gui_extra/native/juce_UIViewComponent_ios.mm b/modules/juce_gui_extra/native/juce_UIViewComponent_ios.mm index b1c3731623..d1c58c4047 100644 --- a/modules/juce_gui_extra/native/juce_UIViewComponent_ios.mm +++ b/modules/juce_gui_extra/native/juce_UIViewComponent_ios.mm @@ -103,7 +103,10 @@ private: //============================================================================== UIViewComponent::UIViewComponent() {} -UIViewComponent::~UIViewComponent() {} +UIViewComponent::~UIViewComponent() +{ + AccessibilityHandler::setNativeChildForComponent (*this, nullptr); +} void UIViewComponent::setView (void* view) { @@ -113,6 +116,8 @@ void UIViewComponent::setView (void* view) if (view != nullptr) pimpl.reset (new Pimpl ((UIView*) view, *this)); + + AccessibilityHandler::setNativeChildForComponent (*this, getView()); } } @@ -129,4 +134,9 @@ void UIViewComponent::resizeToFitView() void UIViewComponent::paint (Graphics&) {} +std::unique_ptr UIViewComponent::createAccessibilityHandler() +{ + return std::make_unique (*this, AccessibilityRole::group); +} + } // namespace juce