2006-11-24 17:37:00 +03:00
|
|
|
/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-11-24 17:37:00 +03:00
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
#import "mozActionElements.h"
|
2012-01-27 10:14:09 +04:00
|
|
|
|
|
|
|
#import "MacUtils.h"
|
2012-04-13 18:17:03 +04:00
|
|
|
#include "Accessible-inl.h"
|
2012-06-29 03:04:50 +04:00
|
|
|
#include "DocAccessible.h"
|
2012-06-11 03:44:50 +04:00
|
|
|
#include "XULTabAccessible.h"
|
2006-11-15 14:08:14 +03:00
|
|
|
|
2012-06-29 03:04:50 +04:00
|
|
|
#include "nsDeckFrame.h"
|
2008-02-22 23:13:17 +03:00
|
|
|
#include "nsObjCExceptions.h"
|
|
|
|
|
2011-07-27 16:43:01 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2006-11-24 17:37:00 +03:00
|
|
|
enum CheckboxValue {
|
|
|
|
// these constants correspond to the values in the OS
|
|
|
|
kUnchecked = 0,
|
|
|
|
kChecked = 1,
|
|
|
|
kMixed = 2
|
|
|
|
};
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
@implementation mozButtonAccessible
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (NSArray*)accessibilityAttributeNames {
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
static NSArray* attributes = nil;
|
2006-11-15 14:08:14 +03:00
|
|
|
if (!attributes) {
|
2019-01-21 20:18:16 +03:00
|
|
|
attributes = [[NSArray alloc]
|
|
|
|
initWithObjects:NSAccessibilityParentAttribute, // required
|
|
|
|
NSAccessibilityRoleAttribute, // required
|
|
|
|
NSAccessibilityRoleDescriptionAttribute,
|
|
|
|
NSAccessibilityPositionAttribute, // required
|
|
|
|
NSAccessibilitySizeAttribute, // required
|
|
|
|
NSAccessibilityWindowAttribute, // required
|
|
|
|
NSAccessibilityPositionAttribute, // required
|
|
|
|
NSAccessibilityTopLevelUIElementAttribute, // required
|
|
|
|
NSAccessibilityHelpAttribute,
|
|
|
|
NSAccessibilityEnabledAttribute, // required
|
|
|
|
NSAccessibilityFocusedAttribute, // required
|
|
|
|
NSAccessibilityTitleAttribute, // required
|
|
|
|
NSAccessibilityChildrenAttribute, NSAccessibilityDescriptionAttribute,
|
2012-01-27 19:50:04 +04:00
|
|
|
#if DEBUG
|
2019-01-21 20:18:16 +03:00
|
|
|
@"AXMozDescription",
|
2012-01-27 19:50:04 +04:00
|
|
|
#endif
|
2019-01-21 20:18:16 +03:00
|
|
|
nil];
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
return attributes;
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute {
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2015-05-29 18:41:54 +03:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
|
2019-01-21 20:18:16 +03:00
|
|
|
if ([self hasPopup]) return [self children];
|
2006-12-06 16:35:56 +03:00
|
|
|
return nil;
|
2015-05-29 18:41:54 +03:00
|
|
|
}
|
|
|
|
|
2012-01-27 10:14:09 +04:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityRoleDescriptionAttribute]) {
|
2019-01-21 20:18:16 +03:00
|
|
|
if ([self isTab]) return utils::LocalizedString(NS_LITERAL_STRING("tab"));
|
2015-05-29 18:41:54 +03:00
|
|
|
|
2012-01-27 10:14:09 +04:00
|
|
|
return NSAccessibilityRoleDescription([self role], nil);
|
|
|
|
}
|
2015-05-29 18:41:54 +03:00
|
|
|
|
2006-12-06 16:35:56 +03:00
|
|
|
return [super accessibilityAttributeValue:attribute];
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-12-06 16:35:56 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (BOOL)accessibilityIsIgnored {
|
2015-07-17 00:35:29 +03:00
|
|
|
return ![self getGeckoAccessible] && ![self getProxyAccessible];
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (NSArray*)accessibilityActionNames {
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2015-05-29 18:41:54 +03:00
|
|
|
if ([self isEnabled]) {
|
|
|
|
if ([self hasPopup])
|
2019-01-21 20:18:16 +03:00
|
|
|
return
|
|
|
|
[NSArray arrayWithObjects:NSAccessibilityPressAction, NSAccessibilityShowMenuAction, nil];
|
2006-11-15 14:08:14 +03:00
|
|
|
return [NSArray arrayWithObject:NSAccessibilityPressAction];
|
2015-05-29 18:41:54 +03:00
|
|
|
}
|
2006-11-15 14:08:14 +03:00
|
|
|
return nil;
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (NSString*)accessibilityActionDescription:(NSString*)action {
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2012-01-27 10:14:09 +04:00
|
|
|
if ([action isEqualToString:NSAccessibilityPressAction]) {
|
2019-01-21 20:18:16 +03:00
|
|
|
if ([self isTab]) return utils::LocalizedString(NS_LITERAL_STRING("switch"));
|
2015-05-29 18:41:54 +03:00
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
return @"press button"; // XXX: localize this later?
|
2012-01-27 10:14:09 +04:00
|
|
|
}
|
2015-05-29 18:41:54 +03:00
|
|
|
|
|
|
|
if ([self hasPopup]) {
|
2019-01-21 20:18:16 +03:00
|
|
|
if ([action isEqualToString:NSAccessibilityShowMenuAction]) return @"show menu";
|
2015-05-29 18:41:54 +03:00
|
|
|
}
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
return nil;
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (void)accessibilityPerformAction:(NSString*)action {
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2015-05-29 18:41:54 +03:00
|
|
|
if ([self isEnabled] && [action isEqualToString:NSAccessibilityPressAction]) {
|
|
|
|
// TODO: this should bring up the menu, but currently doesn't.
|
|
|
|
// once msaa and atk have merged better, they will implement
|
|
|
|
// the action needed to show the menu.
|
2006-11-15 14:08:14 +03:00
|
|
|
[self click];
|
2015-05-29 18:41:54 +03:00
|
|
|
}
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (void)click {
|
2006-11-15 14:08:14 +03:00
|
|
|
// both buttons and checkboxes have only one action. we should really stop using arbitrary
|
|
|
|
// arrays with actions, and define constants for these actions.
|
2015-08-04 21:56:20 +03:00
|
|
|
if (AccessibleWrap* accWrap = [self getGeckoAccessible])
|
|
|
|
accWrap->DoAction(0);
|
|
|
|
else if (ProxyAccessible* proxy = [self getProxyAccessible])
|
|
|
|
proxy->DoAction(0);
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (BOOL)isTab {
|
|
|
|
if (AccessibleWrap* accWrap = [self getGeckoAccessible]) return accWrap->Role() == roles::PAGETAB;
|
2015-08-04 21:56:18 +03:00
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
if (ProxyAccessible* proxy = [self getProxyAccessible]) return proxy->Role() == roles::PAGETAB;
|
2015-08-04 21:56:18 +03:00
|
|
|
|
|
|
|
return false;
|
2012-01-27 10:14:09 +04:00
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (BOOL)hasPopup {
|
2015-08-04 21:56:18 +03:00
|
|
|
if (AccessibleWrap* accWrap = [self getGeckoAccessible])
|
|
|
|
return accWrap->NativeState() & states::HASPOPUP;
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = [self getProxyAccessible])
|
|
|
|
return proxy->NativeState() & states::HASPOPUP;
|
|
|
|
|
|
|
|
return false;
|
2015-05-29 18:41:54 +03:00
|
|
|
}
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation mozCheckboxAccessible
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (NSString*)accessibilityActionDescription:(NSString*)action {
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
if ([action isEqualToString:NSAccessibilityPressAction]) {
|
2019-01-21 20:18:16 +03:00
|
|
|
if ([self isChecked] != kUnchecked) return @"uncheck checkbox"; // XXX: localize this later?
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
return @"check checkbox"; // XXX: localize this later?
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
return nil;
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (int)isChecked {
|
2015-08-04 21:56:18 +03:00
|
|
|
uint64_t state = 0;
|
|
|
|
if (AccessibleWrap* accWrap = [self getGeckoAccessible])
|
|
|
|
state = accWrap->NativeState();
|
|
|
|
else if (ProxyAccessible* proxy = [self getProxyAccessible])
|
|
|
|
state = proxy->NativeState();
|
2007-04-04 14:36:38 +04:00
|
|
|
|
2006-11-24 17:37:00 +03:00
|
|
|
// check if we're checked or in a mixed state
|
2011-04-10 03:38:06 +04:00
|
|
|
if (state & states::CHECKED) {
|
|
|
|
return (state & states::MIXED) ? kMixed : kChecked;
|
2006-11-24 17:37:00 +03:00
|
|
|
}
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2006-11-24 17:37:00 +03:00
|
|
|
return kUnchecked;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (id)value {
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2006-11-24 17:37:00 +03:00
|
|
|
return [NSNumber numberWithInt:[self isChecked]];
|
2008-02-22 23:13:17 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-11-15 14:08:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2006-12-06 16:35:56 +03:00
|
|
|
|
2012-01-27 10:14:09 +04:00
|
|
|
@implementation mozTabsAccessible
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (void)dealloc {
|
2012-01-27 10:14:09 +04:00
|
|
|
[mTabs release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (NSArray*)accessibilityAttributeNames {
|
2012-01-27 10:14:09 +04:00
|
|
|
// standard attributes that are shared and supported by root accessible (AXMain) elements.
|
|
|
|
static NSMutableArray* attributes = nil;
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2012-01-27 10:14:09 +04:00
|
|
|
if (!attributes) {
|
|
|
|
attributes = [[super accessibilityAttributeNames] mutableCopy];
|
|
|
|
[attributes addObject:NSAccessibilityContentsAttribute];
|
|
|
|
[attributes addObject:NSAccessibilityTabsAttribute];
|
|
|
|
}
|
2015-06-08 17:59:19 +03:00
|
|
|
|
|
|
|
return attributes;
|
2012-01-27 10:14:09 +04:00
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute {
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityContentsAttribute]) return [super children];
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityTabsAttribute]) return [self tabs];
|
2015-06-08 17:59:19 +03:00
|
|
|
|
|
|
|
return [super accessibilityAttributeValue:attribute];
|
2012-01-27 10:14:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the selected tab (the mozAccessible)
|
|
|
|
*/
|
2019-01-21 20:18:16 +03:00
|
|
|
- (id)value {
|
2012-01-27 10:14:09 +04:00
|
|
|
mozAccessible* nativeAcc = nil;
|
2015-08-04 21:56:20 +03:00
|
|
|
if (AccessibleWrap* accWrap = [self getGeckoAccessible]) {
|
2016-02-24 22:14:04 +03:00
|
|
|
if (Accessible* accTab = accWrap->GetSelectedItem(0)) {
|
|
|
|
accTab->GetNativeInterface((void**)&nativeAcc);
|
|
|
|
}
|
2015-08-04 21:56:20 +03:00
|
|
|
} else if (ProxyAccessible* proxy = [self getProxyAccessible]) {
|
2016-02-24 22:14:04 +03:00
|
|
|
if (ProxyAccessible* proxyTab = proxy->GetSelectedItem(0)) {
|
|
|
|
nativeAcc = GetNativeFromProxy(proxyTab);
|
|
|
|
}
|
2015-08-04 21:56:20 +03:00
|
|
|
}
|
2014-10-22 04:49:28 +04:00
|
|
|
|
2012-01-27 10:14:09 +04:00
|
|
|
return nativeAcc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the mozAccessibles that are the tabs.
|
|
|
|
*/
|
2019-01-21 20:18:16 +03:00
|
|
|
- (id)tabs {
|
|
|
|
if (mTabs) return mTabs;
|
2012-01-27 10:14:09 +04:00
|
|
|
|
|
|
|
NSArray* children = [self children];
|
|
|
|
NSEnumerator* enumerator = [children objectEnumerator];
|
|
|
|
mTabs = [[NSMutableArray alloc] init];
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2012-01-27 10:14:09 +04:00
|
|
|
id obj;
|
|
|
|
while ((obj = [enumerator nextObject]))
|
2019-01-21 20:18:16 +03:00
|
|
|
if ([obj isTab]) [mTabs addObject:obj];
|
2012-01-27 10:14:09 +04:00
|
|
|
|
|
|
|
return mTabs;
|
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (void)invalidateChildren {
|
2012-01-27 10:14:09 +04:00
|
|
|
[super invalidateChildren];
|
|
|
|
|
|
|
|
[mTabs release];
|
|
|
|
mTabs = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2012-06-29 03:04:50 +04:00
|
|
|
|
|
|
|
@implementation mozPaneAccessible
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (NSUInteger)accessibilityArrayAttributeCount:(NSString*)attribute {
|
2015-08-04 21:56:18 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
ProxyAccessible* proxy = [self getProxyAccessible];
|
2019-01-21 20:18:16 +03:00
|
|
|
if (!accWrap && !proxy) return 0;
|
2012-07-12 04:29:19 +04:00
|
|
|
|
|
|
|
// By default this calls -[[mozAccessible children] count].
|
|
|
|
// Since we don't cache mChildren. This is faster.
|
2015-08-04 21:56:18 +03:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
|
2019-01-21 20:18:16 +03:00
|
|
|
if (accWrap) return accWrap->ChildCount() ? 1 : 0;
|
2015-08-04 21:56:18 +03:00
|
|
|
|
|
|
|
return proxy->ChildrenCount() ? 1 : 0;
|
|
|
|
}
|
2012-07-12 04:29:19 +04:00
|
|
|
|
|
|
|
return [super accessibilityArrayAttributeCount:attribute];
|
|
|
|
}
|
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
- (NSArray*)children {
|
|
|
|
if (![self getGeckoAccessible]) return nil;
|
2012-06-29 03:04:50 +04:00
|
|
|
|
2019-01-21 20:18:16 +03:00
|
|
|
nsDeckFrame* deckFrame = do_QueryFrame([self getGeckoAccessible] -> GetFrame());
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame* selectedFrame = deckFrame ? deckFrame->GetSelectedBox() : nullptr;
|
2012-06-29 03:04:50 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
Accessible* selectedAcc = nullptr;
|
2012-06-29 03:04:50 +04:00
|
|
|
if (selectedFrame) {
|
|
|
|
nsINode* node = selectedFrame->GetContent();
|
2019-01-21 20:18:16 +03:00
|
|
|
selectedAcc = [self getGeckoAccessible] -> Document() -> GetAccessible(node);
|
2012-06-29 03:04:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedAcc) {
|
2019-01-21 20:18:16 +03:00
|
|
|
mozAccessible* curNative = GetNativeFromGeckoAccessible(selectedAcc);
|
|
|
|
if (curNative) return [NSArray arrayWithObjects:GetObjectOrRepresentedView(curNative), nil];
|
2012-06-29 03:04:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|