Add searchEdit as accessible state

The search state is used by VoiceOver on iOS to announce a search field.

Change-Id: I464125827dbbf275daf38104e26e9591bb23365a
Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
This commit is contained in:
Frederik Gladhorn 2014-10-16 17:58:54 +02:00 committed by Frederik Gladhorn
parent e859de3fb5
commit 18a538ed40
6 changed files with 24 additions and 3 deletions

View File

@ -166,6 +166,7 @@ QT_BEGIN_NAMESPACE
\value playsSound The object produces sound when interacted with.
\value pressed The object is pressed.
\value readOnly The object can usually be edited, but is explicitly set to read-only.
\value searchEdit The object is a line edit that is the input for search queries.
\value selectable The object is selectable.
\value selectableText The object has text which can be selected. This is different from selectable which refers to the object's children.
\value selected The object is selected, this is independent of text selection.

View File

@ -185,6 +185,8 @@ public:
quint64 selectableText : 1;
quint64 supportsAutoCompletion : 1;
quint64 searchEdit : 1;
// quint64 horizontal : 1;
// quint64 vertical : 1;
// quint64 invalidEntry : 1;

View File

@ -70,6 +70,7 @@ namespace QCocoaAccessible {
*/
NSString *macRole(QAccessibleInterface *interface);
NSString *macSubrole(QAccessibleInterface *interface);
bool shouldBeIgnored(QAccessibleInterface *interface);
NSArray *unignoredChildren(QAccessibleInterface *interface);
NSString *getTranslatedAction(const QString &qtAction);

View File

@ -162,7 +162,7 @@ static void populateRoleMap()
}
/*
Returns a Mac accessibility role for the given interface, or
Returns a Cocoa accessibility role for the given interface, or
NSAccessibilityUnknownRole if no role mapping is found.
*/
NSString *macRole(QAccessibleInterface *interface)
@ -190,13 +190,24 @@ NSString *macRole(QAccessibleInterface *interface)
}
/*
Mac accessibility supports ignoring elements, which means that
Returns a Cocoa sub role for the given interface.
*/
NSString *macSubrole(QAccessibleInterface *interface)
{
QAccessible::State s = interface->state();
if (s.searchEdit)
return NSAccessibilitySearchFieldSubrole;
return nil;
}
/*
Cocoa accessibility supports ignoring elements, which means that
the elements are still present in the accessibility tree but is
not used by the screen reader.
*/
bool shouldBeIgnored(QAccessibleInterface *interface)
{
// Mac accessibility does not have an attribute that corresponds to the Invisible/Offscreen
// Cocoa accessibility does not have an attribute that corresponds to the Invisible/Offscreen
// state. Ignore interfaces with those flags set.
const QAccessible::State state = interface->state();
if (state.invisible ||

View File

@ -135,6 +135,7 @@
defaultAttributes = [[NSArray alloc] initWithObjects:
NSAccessibilityRoleAttribute,
NSAccessibilityRoleDescriptionAttribute,
NSAccessibilitySubroleAttribute,
NSAccessibilityChildrenAttribute,
NSAccessibilityFocusedAttribute,
NSAccessibilityParentAttribute,
@ -221,6 +222,8 @@
if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
return role;
} else if ([attribute isEqualToString:NSAccessibilitySubroleAttribute]) {
return QCocoaAccessible::macSubrole(iface);
} else if ([attribute isEqualToString:NSAccessibilityRoleDescriptionAttribute]) {
return NSAccessibilityRoleDescription(role, nil);
} else if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {

View File

@ -152,6 +152,9 @@
if (state.disabled)
traits |= UIAccessibilityTraitNotEnabled;
if (state.searchEdit)
traits |= UIAccessibilityTraitSearchField;
if (iface->role() == QAccessible::Button)
traits |= UIAccessibilityTraitButton;