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
|
|
|
|
|
|
|
|
- (NSArray*)accessibilityAttributeNames
|
|
|
|
{
|
2008-02-22 23:13:17 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
static NSArray *attributes = nil;
|
|
|
|
if (!attributes) {
|
|
|
|
attributes = [[NSArray alloc] initWithObjects:NSAccessibilityParentAttribute, // required
|
|
|
|
NSAccessibilityRoleAttribute, // required
|
2012-01-27 10:14:09 +04:00
|
|
|
NSAccessibilityRoleDescriptionAttribute,
|
2006-11-15 14:08:14 +03:00
|
|
|
NSAccessibilityPositionAttribute, // required
|
|
|
|
NSAccessibilitySizeAttribute, // required
|
|
|
|
NSAccessibilityWindowAttribute, // required
|
|
|
|
NSAccessibilityPositionAttribute, // required
|
2011-12-09 11:25:25 +04:00
|
|
|
NSAccessibilityTopLevelUIElementAttribute, // required
|
2006-11-15 14:08:14 +03:00
|
|
|
NSAccessibilityHelpAttribute,
|
|
|
|
NSAccessibilityEnabledAttribute, // required
|
|
|
|
NSAccessibilityFocusedAttribute, // required
|
|
|
|
NSAccessibilityTitleAttribute, // required
|
2015-05-29 18:41:54 +03:00
|
|
|
NSAccessibilityChildrenAttribute,
|
2011-12-09 11:25:25 +04:00
|
|
|
NSAccessibilityDescriptionAttribute,
|
2012-01-27 19:50:04 +04:00
|
|
|
#if DEBUG
|
|
|
|
@"AXMozDescription",
|
|
|
|
#endif
|
2006-11-15 14:08:14 +03:00
|
|
|
nil];
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-12-06 16:35:56 +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]) {
|
|
|
|
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]) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-11-15 14:08:14 +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
|
|
|
}
|
|
|
|
|
|
|
|
- (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])
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-05-29 18:41:54 +03:00
|
|
|
- (NSString*)accessibilityActionDescription:(NSString*)action
|
2006-11-15 14:08:14 +03:00
|
|
|
{
|
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]) {
|
|
|
|
if ([self isTab])
|
|
|
|
return utils::LocalizedString(NS_LITERAL_STRING("switch"));
|
2015-05-29 18:41:54 +03:00
|
|
|
|
2006-11-15 14:08:14 +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]) {
|
|
|
|
if ([action isEqualToString:NSAccessibilityShowMenuAction])
|
|
|
|
return @"show menu";
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-05-29 18:41:54 +03:00
|
|
|
- (void)accessibilityPerformAction:(NSString*)action
|
2006-11-15 14:08:14 +03:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
- (void)click
|
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2012-01-27 10:14:09 +04:00
|
|
|
- (BOOL)isTab
|
|
|
|
{
|
2015-08-04 21:56:18 +03:00
|
|
|
if (AccessibleWrap* accWrap = [self getGeckoAccessible])
|
|
|
|
return accWrap->Role() == roles::PAGETAB;
|
|
|
|
|
|
|
|
if (ProxyAccessible* proxy = [self getProxyAccessible])
|
|
|
|
return proxy->Role() == roles::PAGETAB;
|
|
|
|
|
|
|
|
return false;
|
2012-01-27 10:14:09 +04:00
|
|
|
}
|
|
|
|
|
2015-05-29 18:41:54 +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
|
|
|
|
|
2015-08-04 21:56:18 +03:00
|
|
|
- (NSString*)accessibilityActionDescription:(NSString*)action
|
2006-11-15 14:08:14 +03:00
|
|
|
{
|
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]) {
|
2006-11-24 17:37:00 +03:00
|
|
|
if ([self isChecked] != kUnchecked)
|
2006-11-15 14:08:14 +03:00
|
|
|
return @"uncheck checkbox"; // XXX: localize this later?
|
2015-06-08 17:59:19 +03:00
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
return @"check checkbox"; // XXX: localize this later?
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2006-11-24 17:37:00 +03:00
|
|
|
- (int)isChecked
|
2006-11-15 14:08:14 +03:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
- (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
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[mTabs release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)accessibilityAttributeNames
|
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
- (id)accessibilityAttributeValue:(NSString *)attribute
|
2015-06-08 17:59:19 +03:00
|
|
|
{
|
2012-01-27 10:14:09 +04:00
|
|
|
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)
|
|
|
|
*/
|
|
|
|
- (id)value
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
- (id)tabs
|
|
|
|
{
|
|
|
|
if (mTabs)
|
|
|
|
return mTabs;
|
|
|
|
|
|
|
|
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]))
|
|
|
|
if ([obj isTab])
|
|
|
|
[mTabs addObject:obj];
|
|
|
|
|
|
|
|
return mTabs;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)invalidateChildren
|
|
|
|
{
|
|
|
|
[super invalidateChildren];
|
|
|
|
|
|
|
|
[mTabs release];
|
|
|
|
mTabs = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2012-06-29 03:04:50 +04:00
|
|
|
|
|
|
|
@implementation mozPaneAccessible
|
|
|
|
|
2012-07-12 04:29:19 +04:00
|
|
|
- (NSUInteger)accessibilityArrayAttributeCount:(NSString*)attribute
|
|
|
|
{
|
2015-08-04 21:56:18 +03:00
|
|
|
AccessibleWrap* accWrap = [self getGeckoAccessible];
|
|
|
|
ProxyAccessible* proxy = [self getProxyAccessible];
|
|
|
|
if (!accWrap && !proxy)
|
2012-07-12 04:29:19 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// 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]) {
|
|
|
|
if (accWrap)
|
|
|
|
return accWrap->ChildCount() ? 1 : 0;
|
|
|
|
|
|
|
|
return proxy->ChildrenCount() ? 1 : 0;
|
|
|
|
}
|
2012-07-12 04:29:19 +04:00
|
|
|
|
|
|
|
return [super accessibilityArrayAttributeCount:attribute];
|
|
|
|
}
|
|
|
|
|
2012-06-29 03:04:50 +04:00
|
|
|
- (NSArray*)children
|
|
|
|
{
|
2015-05-22 17:59:26 +03:00
|
|
|
if (![self getGeckoAccessible])
|
2012-06-29 03:04:50 +04:00
|
|
|
return nil;
|
|
|
|
|
2015-05-22 17:59:26 +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();
|
2015-05-22 17:59:26 +03:00
|
|
|
selectedAcc = [self getGeckoAccessible]->Document()->GetAccessible(node);
|
2012-06-29 03:04:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedAcc) {
|
|
|
|
mozAccessible *curNative = GetNativeFromGeckoAccessible(selectedAcc);
|
|
|
|
if (curNative)
|
|
|
|
return [NSArray arrayWithObjects:GetObjectOrRepresentedView(curNative), nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|