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
|
2011-12-09 11:25:25 +04:00
|
|
|
NSAccessibilityChildrenAttribute, NSAccessibilityDescriptionAttribute,
|
2020-05-07 21:07:34 +03:00
|
|
|
NSAccessibilityRequiredAttribute, NSAccessibilityHasPopupAttribute,
|
|
|
|
NSAccessibilityPopupValueAttribute,
|
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;
|
|
|
|
|
2020-05-07 21:07:34 +03:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityHasPopupAttribute]) {
|
|
|
|
return [NSNumber numberWithBool:[self hasPopup]];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityPopupValueAttribute]) {
|
|
|
|
if ([self hasPopup]) {
|
|
|
|
return utils::GetAccAttr(self, "haspopup");
|
|
|
|
} else {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-05-29 18:41:54 +03:00
|
|
|
- (BOOL)hasPopup {
|
2020-05-07 21:07:34 +03:00
|
|
|
return ([self stateWithMask:states::HASPOPUP] != 0);
|
2015-05-29 18:41:54 +03:00
|
|
|
}
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
@end
|
|
|
|
|
2020-05-16 00:31:08 +03:00
|
|
|
@implementation mozPopupButtonAccessible
|
2020-05-29 01:41:13 +03:00
|
|
|
- (NSString*)moxTitle {
|
2020-05-16 00:31:08 +03:00
|
|
|
// Popup buttons don't have titles.
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)accessibilityAttributeNames {
|
|
|
|
static NSMutableArray* supportedAttributes = nil;
|
|
|
|
if (!supportedAttributes) {
|
|
|
|
supportedAttributes = [[super accessibilityAttributeNames] mutableCopy];
|
|
|
|
// We need to remove AXHasPopup from a AXPopupButton for it to be reported
|
|
|
|
// as a popup button. Otherwise VO reports it as a button that has a popup
|
|
|
|
// which is not consistent with Safari.
|
|
|
|
[supportedAttributes removeObject:NSAccessibilityHasPopupAttribute];
|
|
|
|
[supportedAttributes addObject:NSAccessibilityValueAttribute];
|
|
|
|
}
|
|
|
|
|
|
|
|
return supportedAttributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute {
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
|
|
|
if ([attribute isEqualToString:NSAccessibilityHasPopupAttribute]) {
|
|
|
|
// We need to null on AXHasPopup for it to be reported as a popup button.
|
|
|
|
// Otherwise VO reports it as a button that has a popup which is not
|
|
|
|
// consistent with Safari.
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [super accessibilityAttributeValue:attribute];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
|
|
|
}
|
|
|
|
|
2020-05-29 01:41:13 +03:00
|
|
|
- (NSArray*)moxChildren {
|
2020-05-16 00:31:08 +03:00
|
|
|
if ([self stateWithMask:states::EXPANDED] == 0) {
|
|
|
|
// If the popup button is collapsed don't return its children.
|
|
|
|
return @[];
|
|
|
|
}
|
|
|
|
|
2020-05-29 01:41:13 +03:00
|
|
|
return [super moxChildren];
|
2020-05-16 00:31:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)stateChanged:(uint64_t)state isEnabled:(BOOL)enabled {
|
|
|
|
[super stateChanged:state isEnabled:enabled];
|
|
|
|
|
|
|
|
if (state == states::EXPANDED) {
|
|
|
|
// If the EXPANDED state is updated, fire AXMenu events on the
|
|
|
|
// popups child which is the actual menu.
|
|
|
|
if (mozAccessible* popup = (mozAccessible*)[self childAt:0]) {
|
2020-05-27 20:24:44 +03:00
|
|
|
[popup moxPostNotification:(enabled ? @"AXMenuOpened" : @"AXMenuClosed")];
|
2020-05-16 00:31:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)ignoreWithParent:(mozAccessible*)parent {
|
2020-05-27 18:50:47 +03:00
|
|
|
if (Accessible* acc = mGeckoAccessible.AsAccessible()) {
|
|
|
|
if (acc->IsContent() && acc->GetContent()->IsXULElement(nsGkAtoms::menulist)) {
|
2020-05-16 00:31:08 +03:00
|
|
|
// The way select elements work is that content has a COMBOBOX accessible, when it is clicked
|
|
|
|
// it expands a COMBOBOX in our top-level main XUL window. The latter COMBOBOX is a stand-in
|
|
|
|
// for the content one while it is expanded.
|
|
|
|
// XXX: VO focus behaves weirdly if we expose the dummy XUL COMBOBOX in the tree.
|
|
|
|
// We are only interested in its menu child.
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [super ignoreWithParent:parent];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
@implementation mozCheckboxAccessible
|
|
|
|
|
2006-11-24 17:37:00 +03:00
|
|
|
- (int)isChecked {
|
|
|
|
// check if we're checked or in a mixed state
|
2020-04-02 08:47:43 +03:00
|
|
|
uint64_t state = [self stateWithMask:(states::CHECKED | states::PRESSED | states::MIXED)];
|
2020-03-14 08:39:59 +03:00
|
|
|
if (state & (states::CHECKED | states::PRESSED)) {
|
|
|
|
return kChecked;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state & states::MIXED) {
|
|
|
|
return kMixed;
|
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
|
|
|
}
|
|
|
|
|
2020-05-29 01:41:13 +03:00
|
|
|
- (id)moxValue {
|
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-06-29 03:04:50 +04:00
|
|
|
@implementation mozPaneAccessible
|
|
|
|
|
2012-07-12 04:29:19 +04:00
|
|
|
- (NSUInteger)accessibilityArrayAttributeCount:(NSString*)attribute {
|
2020-05-27 18:50:47 +03:00
|
|
|
if ([self isExpired]) {
|
|
|
|
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]) {
|
2020-05-27 18:50:47 +03:00
|
|
|
return mGeckoAccessible.ChildCount() ? 1 : 0;
|
2015-08-04 21:56:18 +03:00
|
|
|
}
|
2012-07-12 04:29:19 +04:00
|
|
|
|
|
|
|
return [super accessibilityArrayAttributeCount:attribute];
|
|
|
|
}
|
|
|
|
|
2020-05-29 01:41:13 +03:00
|
|
|
- (NSArray*)moxChildren {
|
2020-05-27 18:50:47 +03:00
|
|
|
if (!mGeckoAccessible.AsAccessible()) return nil;
|
2012-06-29 03:04:50 +04:00
|
|
|
|
2020-05-27 18:50:47 +03:00
|
|
|
nsDeckFrame* deckFrame = do_QueryFrame(mGeckoAccessible.AsAccessible()->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();
|
2020-05-27 18:50:47 +03:00
|
|
|
selectedAcc = mGeckoAccessible.AsAccessible()->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
|
2020-03-17 20:32:33 +03:00
|
|
|
|
2020-04-28 20:20:16 +03:00
|
|
|
@implementation mozIncrementableAccessible
|
2020-03-17 20:32:33 +03:00
|
|
|
|
|
|
|
- (NSArray*)accessibilityActionNames {
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
NSArray* actions = [super accessibilityActionNames];
|
|
|
|
|
|
|
|
static NSArray* sliderAttrs = nil;
|
|
|
|
if (!sliderAttrs) {
|
|
|
|
NSMutableArray* tempArray = [NSMutableArray new];
|
|
|
|
[tempArray addObject:NSAccessibilityIncrementAction];
|
|
|
|
[tempArray addObject:NSAccessibilityDecrementAction];
|
|
|
|
sliderAttrs = [[NSArray alloc] initWithArray:tempArray];
|
|
|
|
[tempArray release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [actions arrayByAddingObjectsFromArray:sliderAttrs];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)accessibilityPerformAction:(NSString*)action {
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if ([action isEqualToString:NSAccessibilityIncrementAction]) {
|
|
|
|
[self changeValueBySteps:1];
|
|
|
|
} else if ([action isEqualToString:NSAccessibilityDecrementAction]) {
|
|
|
|
[self changeValueBySteps:-1];
|
|
|
|
} else {
|
|
|
|
[super accessibilityPerformAction:action];
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Updates the accessible's current value by (factor * step).
|
|
|
|
* If incrementing factor should be positive, if decrementing
|
|
|
|
* factor should be negative.
|
|
|
|
*/
|
|
|
|
|
|
|
|
- (void)changeValueBySteps:(int)factor {
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2020-05-27 18:50:47 +03:00
|
|
|
if (Accessible* acc = mGeckoAccessible.AsAccessible()) {
|
|
|
|
double newVal = acc->CurValue() + (acc->Step() * factor);
|
|
|
|
double min = acc->MinValue();
|
|
|
|
double max = acc->MaxValue();
|
2020-04-28 20:20:16 +03:00
|
|
|
if ((IsNaN(min) || newVal >= min) && (IsNaN(max) || newVal <= max)) {
|
2020-05-27 18:50:47 +03:00
|
|
|
acc->SetCurValue(newVal);
|
2020-03-17 20:32:33 +03:00
|
|
|
}
|
2020-05-27 18:50:47 +03:00
|
|
|
} else if (ProxyAccessible* proxy = mGeckoAccessible.AsProxy()) {
|
2020-03-17 20:32:33 +03:00
|
|
|
double newVal = proxy->CurValue() + (proxy->Step() * factor);
|
2020-04-28 20:20:16 +03:00
|
|
|
double min = proxy->MinValue();
|
|
|
|
double max = proxy->MaxValue();
|
|
|
|
// Because min and max are not required attributes, we first check
|
|
|
|
// if the value is undefined. If this check fails,
|
|
|
|
// the value is defined, and we we verify our new value falls
|
|
|
|
// within the bound (inclusive).
|
|
|
|
if ((IsNaN(min) || newVal >= min) && (IsNaN(max) || newVal <= max)) {
|
2020-03-17 20:32:33 +03:00
|
|
|
proxy->SetCurValue(newVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2020-04-10 01:57:47 +03:00
|
|
|
- (void)handleAccessibleEvent:(uint32_t)eventType {
|
2020-03-27 20:12:33 +03:00
|
|
|
switch (eventType) {
|
2020-04-28 20:20:16 +03:00
|
|
|
case nsIAccessibleEvent::EVENT_TEXT_VALUE_CHANGE:
|
2020-03-27 20:12:33 +03:00
|
|
|
case nsIAccessibleEvent::EVENT_VALUE_CHANGE:
|
2020-05-27 20:24:44 +03:00
|
|
|
[self moxPostNotification:NSAccessibilityValueChangedNotification];
|
2020-03-27 20:12:33 +03:00
|
|
|
break;
|
|
|
|
default:
|
2020-04-10 01:57:47 +03:00
|
|
|
[super handleAccessibleEvent:eventType];
|
2020-03-27 20:12:33 +03:00
|
|
|
break;
|
|
|
|
}
|
2020-03-17 20:32:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|