Use QObject pointer as QCocoaAccessibleElement id.
Each QCocoaAccessibleElement needs to provide a unique stable id through the -(NSUnterger)hash method. The previous approach of basing the hash on the parent hash plus the child index is unpractical now that childAt() can return distant descendants instead of immediate children only. Use the QObject pointer, which is set for all accessible interfaces today. Change-Id: I5868e3a81c1b4da7233504f30003ab8060e9fa3f Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
This commit is contained in:
parent
7ed6a247bf
commit
95ea9cb191
@ -48,16 +48,13 @@
|
||||
@class QCocoaAccessibleElement;
|
||||
|
||||
@interface QCocoaAccessibleElement : NSObject {
|
||||
NSUInteger index;
|
||||
NSString *role;
|
||||
NSObject * parent;
|
||||
void *accessibleInterface;
|
||||
|
||||
}
|
||||
|
||||
- (id)initWithIndex:(int)aIndex parent:(id)aParent accessibleInterface:(void *)anQAccessibleInterface;
|
||||
+ (QCocoaAccessibleElement *)elementWithIndex:(int)aIndex parent:(id)aParent accessibleInterface:(void *)anQAccessibleInterface;
|
||||
- (NSUInteger)index;
|
||||
- (id)initWithInterface:(void *)anQAccessibleInterface parent:(id)aParent;
|
||||
+ (QCocoaAccessibleElement *)elementWithInterface:(void *)anQAccessibleInterface parent:(id)aParent;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -54,23 +54,21 @@ static QAccessibleInterface *acast(void *ptr)
|
||||
|
||||
@implementation QCocoaAccessibleElement
|
||||
|
||||
- (id)initWithIndex:(int)aIndex parent:(id)aParent accessibleInterface:(void *)anQAccessibleInterface
|
||||
- (id)initWithInterface:(void *)anQAccessibleInterface parent:(id)aParent
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
index = aIndex;
|
||||
accessibleInterface = anQAccessibleInterface;
|
||||
role = QCocoaAccessible::macRole(acast(accessibleInterface)->role());
|
||||
parent = aParent;
|
||||
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (QCocoaAccessibleElement *)elementWithIndex:(int)aIndex parent:(id)aParent accessibleInterface:(void *)anQAccessibleInterface
|
||||
+ (QCocoaAccessibleElement *)elementWithInterface:(void *)anQAccessibleInterface parent:(id)aParent
|
||||
{
|
||||
return [[[self alloc] initWithIndex:aIndex parent:aParent accessibleInterface:anQAccessibleInterface] autorelease];
|
||||
return [[[self alloc] initWithInterface:anQAccessibleInterface parent:aParent] autorelease];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
@ -80,17 +78,14 @@ static QAccessibleInterface *acast(void *ptr)
|
||||
- (BOOL)isEqual:(id)object {
|
||||
if ([object isKindOfClass:[QCocoaAccessibleElement class]]) {
|
||||
QCocoaAccessibleElement *other = object;
|
||||
return (index == other->index) && [role isEqualToString:other->role] && [parent isEqual:other->parent];
|
||||
} else
|
||||
return acast(other->accessibleInterface)->object() == acast(accessibleInterface)->object();
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSUInteger)hash {
|
||||
return [parent hash] + index;
|
||||
}
|
||||
|
||||
- (NSUInteger)index {
|
||||
return index;
|
||||
return qHash(acast(accessibleInterface)->object());
|
||||
}
|
||||
|
||||
//
|
||||
@ -129,7 +124,7 @@ static QAccessibleInterface *acast(void *ptr)
|
||||
NSMutableArray *kids = [NSMutableArray arrayWithCapacity:numKids];
|
||||
for (int i = 0; i < numKids; ++i) {
|
||||
QAccessibleInterface *childInterface = acast(accessibleInterface)->child(i);
|
||||
[kids addObject:[QCocoaAccessibleElement elementWithIndex:i parent:self accessibleInterface:(void*)childInterface]];
|
||||
[kids addObject:[QCocoaAccessibleElement elementWithInterface:(void*)childInterface parent:self]];
|
||||
}
|
||||
|
||||
return NSAccessibilityUnignoredChildren(kids);
|
||||
@ -232,8 +227,7 @@ static QAccessibleInterface *acast(void *ptr)
|
||||
}
|
||||
|
||||
// hit a child, forward to child accessible interface.
|
||||
int childIndex = acast(accessibleInterface)->indexOfChild(childInterface);
|
||||
QCocoaAccessibleElement *accessibleElement = [QCocoaAccessibleElement elementWithIndex:childIndex parent:self accessibleInterface: childInterface];
|
||||
QCocoaAccessibleElement *accessibleElement = [QCocoaAccessibleElement elementWithInterface:childInterface parent:self];
|
||||
return [accessibleElement accessibilityHitTest:point];
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@
|
||||
int numKids = m_accessibleRoot->childCount();
|
||||
NSMutableArray *kids = [NSMutableArray arrayWithCapacity:numKids];
|
||||
for (int i = 0; i < numKids; ++i) {
|
||||
[kids addObject:[QCocoaAccessibleElement elementWithIndex:i parent:self accessibleInterface:(void*)m_accessibleRoot->child(i)]];
|
||||
[kids addObject:[QCocoaAccessibleElement elementWithInterface: m_accessibleRoot->child(i) parent:self ]];
|
||||
}
|
||||
|
||||
return NSAccessibilityUnignoredChildren(kids);
|
||||
@ -96,8 +96,8 @@
|
||||
}
|
||||
|
||||
// Hit a child, forward to child accessible interface.
|
||||
int childIndex = m_accessibleRoot->indexOfChild(childInterface);
|
||||
QCocoaAccessibleElement *accessibleElement = [QCocoaAccessibleElement elementWithIndex:childIndex -1 parent:self accessibleInterface: childInterface];
|
||||
|
||||
QCocoaAccessibleElement *accessibleElement = [QCocoaAccessibleElement elementWithInterface: childInterface parent:self ];
|
||||
return [accessibleElement accessibilityHitTest:point];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user