1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

macOS Accessibility: Use @available keyword where possible to check if accessibility support is available at runtime

This commit is contained in:
ed 2021-06-07 16:54:49 +01:00
parent 8b2f3088d7
commit e4f9e7f79b
6 changed files with 43 additions and 20 deletions

View file

@ -70,6 +70,10 @@
#define JUCE_CXX14_IS_AVAILABLE (__cplusplus >= 201402L)
#define JUCE_CXX17_IS_AVAILABLE (__cplusplus >= 201703L)
#if defined (__OBJC__)
#define JUCE_OBJC_HAS_AVAILABLE_FEATURE (__clang_major__ >= 9)
#endif
#endif
//==============================================================================

View file

@ -328,18 +328,4 @@ void AccessibilityHandler::takeFocus()
}
}
//==============================================================================
#if ! ((JUCE_MAC && (defined (MAC_OS_X_VERSION_10_10) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10)) \
|| (JUCE_WINDOWS && ! JUCE_MINGW))
class AccessibilityHandler::AccessibilityNativeImpl { public: AccessibilityNativeImpl (AccessibilityHandler&) {} };
void AccessibilityHandler::notifyAccessibilityEvent (AccessibilityEvent) const {}
void AccessibilityHandler::postAnnouncement (const String&, AnnouncementPriority) {}
AccessibilityNativeHandle* AccessibilityHandler::getNativeImplementation() const { return nullptr; }
AccessibilityHandler::AccessibilityNativeImpl* AccessibilityHandler::createNativeImpl (AccessibilityHandler&) { return nullptr; }
void AccessibilityHandler::DestroyNativeImpl::operator() (AccessibilityHandler::AccessibilityNativeImpl*) const noexcept {}
void notifyAccessibilityEventInternal (const AccessibilityHandler&, InternalAccessibilityEvent) {}
#endif
} // namespace juce

View file

@ -323,3 +323,16 @@ bool getComponentAsyncLayerBackedViewDisabled (juce::Component& comp)
#endif
#endif
#if ! JUCE_NATIVE_ACCESSIBILITY_INCLUDED
namespace juce
{
class AccessibilityHandler::AccessibilityNativeImpl { public: AccessibilityNativeImpl (AccessibilityHandler&) {} };
void AccessibilityHandler::notifyAccessibilityEvent (AccessibilityEvent) const {}
void AccessibilityHandler::postAnnouncement (const String&, AnnouncementPriority) {}
AccessibilityNativeHandle* AccessibilityHandler::getNativeImplementation() const { return nullptr; }
AccessibilityHandler::AccessibilityNativeImpl* AccessibilityHandler::createNativeImpl (AccessibilityHandler&) { return nullptr; }
void AccessibilityHandler::DestroyNativeImpl::operator() (AccessibilityHandler::AccessibilityNativeImpl*) const noexcept {}
void notifyAccessibilityEventInternal (const AccessibilityHandler&, InternalAccessibilityEvent) {}
}
#endif

View file

@ -31,7 +31,9 @@ namespace juce
using NSAccessibilityNotificationName = NSString*;
#endif
#if (defined (MAC_OS_X_VERSION_10_10) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10)
#if JUCE_OBJC_HAS_AVAILABLE_FEATURE || (defined (MAC_OS_X_VERSION_10_10) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10)
#define JUCE_NATIVE_ACCESSIBILITY_INCLUDED 1
//==============================================================================
class AccessibilityHandler::AccessibilityNativeImpl
@ -65,10 +67,17 @@ private:
static Holder create (AccessibilityHandler& handler)
{
static AccessibilityElement cls;
Holder element ([cls.createInstance() init]);
object_setInstanceVariable (element.get(), "handler", &handler);
return element;
#if JUCE_OBJC_HAS_AVAILABLE_FEATURE
if (@available (macOS 10.10, *))
#endif
{
static AccessibilityElement cls;
Holder element ([cls.createInstance() init]);
object_setInstanceVariable (element.get(), "handler", &handler);
return element;
}
return {};
}
private:

View file

@ -26,6 +26,8 @@
namespace juce
{
#define JUCE_NATIVE_ACCESSIBILITY_INCLUDED 1
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wlanguage-extension-token")
static bool isStartingUpOrShuttingDown()

View file

@ -95,7 +95,16 @@ public:
backing: NSBackingStoreBuffered
defer: YES];
setOwner (window, this);
[window setAccessibilityElement: component.getAccessibilityHandler() != nullptr];
#if JUCE_OBJC_HAS_AVAILABLE_FEATURE || (defined (MAC_OS_X_VERSION_10_10) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10)
#if JUCE_OBJC_HAS_AVAILABLE_FEATURE
if (@available (macOS 10.10, *))
#endif
{
[window setAccessibilityElement: component.getAccessibilityHandler() != nullptr];
}
#endif
[window orderOut: nil];
[window setDelegate: (id<NSWindowDelegate>) window];