Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve accessibility of Find dialog (+small stuff) #1221

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions Frameworks/Find/src/FindWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,36 @@ - (void)updateIntrinsicContentSizeToEncompassString:(NSString*)aString
}
@end

static OakAutoSizingTextField* OakCreateTextField (id <NSTextFieldDelegate> delegate)
static OakAutoSizingTextField* OakCreateTextField (id <NSTextFieldDelegate> delegate, NSObject* accessibilityLabel = nil)
{
OakAutoSizingTextField* res = [[OakAutoSizingTextField alloc] initWithFrame:NSZeroRect];
res.font = OakControlFont();
[[res cell] setWraps:YES];
OakSetAccessibilityLabel(res, accessibilityLabel);
res.delegate = delegate;
return res;
}

static NSButton* OakCreateHistoryButton ()
static NSButton* OakCreateHistoryButton (NSString* toolTip)
{
NSButton* res = [[NSButton alloc] initWithFrame:NSZeroRect];
res.bezelStyle = NSRoundedDisclosureBezelStyle;
res.buttonType = NSMomentaryLightButton;
res.title = @"";
res.toolTip = toolTip;
OakSetAccessibilityLabel(res, toolTip);
return res;
}

static NSOutlineView* OakCreateOutlineView (NSScrollView** scrollViewOut)
static NSOutlineView* OakCreateOutlineView (NSScrollView** scrollViewOut, NSObject* accessibilityLabel)
{
NSOutlineView* res = [[NSOutlineView alloc] initWithFrame:NSZeroRect];
res.focusRingType = NSFocusRingTypeNone;
res.allowsMultipleSelection = YES;
res.autoresizesOutlineColumn = NO;
res.usesAlternatingRowBackgroundColors = YES;
res.headerView = nil;
OakSetAccessibilityLabel(res, accessibilityLabel);

NSTableColumn* tableColumn = [[NSTableColumn alloc] initWithIdentifier:@"checkbox"];
NSButtonCell* dataCell = [NSButtonCell new];
Expand Down Expand Up @@ -113,6 +117,7 @@ - (void)updateIntrinsicContentSizeToEncompassString:(NSString*)aString
res.image = [NSImage imageNamed:NSImageNameStopProgressFreestandingTemplate];
res.imagePosition = NSImageOnly;
res.toolTip = @"Stop Search";
OakSetAccessibilityLabel(res, res.toolTip);
res.keyEquivalent = @".";
res.keyEquivalentModifierMask = NSCommandKeyMask;
[res.cell setImageScaling:NSImageScaleProportionallyDown];
Expand Down Expand Up @@ -190,13 +195,16 @@ - (id)init
self.window.restorable = NO;

self.findLabel = OakCreateLabel(@"Find:");
self.findTextField = OakCreateTextField(self);
self.findHistoryButton = OakCreateHistoryButton();
self.findTextField = OakCreateTextField(self, self.findLabel);
self.findHistoryButton = OakCreateHistoryButton(@"Show Find History");
self.countButton = OakCreateButton(@"Σ", NSSmallSquareBezelStyle);

self.countButton.toolTip = @"Show Results Count";
OakSetAccessibilityLabel(self.countButton, self.countButton.toolTip);

self.replaceLabel = OakCreateLabel(@"Replace:");
self.replaceTextField = OakCreateTextField(self);
self.replaceHistoryButton = OakCreateHistoryButton();
self.replaceTextField = OakCreateTextField(self, self.replaceLabel);
self.replaceHistoryButton = OakCreateHistoryButton(@"Show Replace History");

self.optionsLabel = OakCreateLabel(@"Options:");

Expand All @@ -206,14 +214,14 @@ - (id)init
self.wrapAroundCheckBox = OakCreateCheckBox(@"Wrap Around");

self.whereLabel = OakCreateLabel(@"In:");
self.wherePopUpButton = OakCreatePopUpButton();
self.wherePopUpButton = OakCreatePopUpButton(NO, nil, self.whereLabel);
self.matchingLabel = OakCreateLabel(@"matching");
self.globTextField = OakCreateComboBox();
self.globTextField = OakCreateComboBox(self.matchingLabel);
self.actionsPopUpButton = OakCreateActionPopUpButton(YES /* bordered */);

NSScrollView* resultsScrollView = nil;
self.resultsTopDivider = OakCreateHorizontalLine([NSColor colorWithCalibratedWhite:0.500 alpha:1]);
self.resultsOutlineView = OakCreateOutlineView(&resultsScrollView);
self.resultsOutlineView = OakCreateOutlineView(&resultsScrollView, @"Results");
self.resultsScrollView = resultsScrollView;
self.resultsBottomDivider = OakCreateHorizontalLine([NSColor colorWithCalibratedWhite:0.500 alpha:1]);

Expand Down Expand Up @@ -698,6 +706,21 @@ - (void)setFindErrorString:(NSString*)aString
}
}

- (void)setStatusString:(NSString*)statusString
{
if (_statusString != statusString && ![_statusString isEqualToString:statusString])
{
_statusString = statusString;
}

for (id element in @[
self.countButton.cell,
])
NSAccessibilityPostNotificationWithUserInfo(element, NSAccessibilityAnnouncementRequestedNotification, @{
NSAccessibilityAnnouncementKey: statusString,
});
}

- (void)updateFindErrorString
{
NSString* errorString = nil;
Expand Down
7 changes: 4 additions & 3 deletions Frameworks/OakAppKit/src/OakUIConstructionFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ PUBLIC NSTextField* OakCreateLabel (NSString* label = @"");
PUBLIC NSTextField* OakCreateSmallLabel (NSString* label = @"");
PUBLIC NSButton* OakCreateCheckBox (NSString* label);
PUBLIC NSButton* OakCreateButton (NSString* label, NSBezelStyle bezel = NSRoundedBezelStyle);
PUBLIC NSPopUpButton* OakCreatePopUpButton (BOOL pullsDown = NO, NSString* initialItemTitle = nil);
PUBLIC NSPopUpButton* OakCreatePopUpButton (BOOL pullsDown = NO, NSString* initialItemTitle = nil, NSObject* accessibilityLabel = nil);
PUBLIC NSPopUpButton* OakCreateActionPopUpButton (BOOL bordered = NO);
PUBLIC NSPopUpButton* OakCreateStatusBarPopUpButton (NSString* initialItemTitle = nil);
PUBLIC NSComboBox* OakCreateComboBox ();
PUBLIC NSPopUpButton* OakCreateStatusBarPopUpButton (NSString* initialItemTitle = nil, NSObject* accessibilityLabel = nil);
PUBLIC NSComboBox* OakCreateComboBox (NSObject* accessibilityLabel = nil);
PUBLIC NSImageView* OakCreateDividerImageView ();

PUBLIC NSBox* OakCreateViewWithColor (NSColor* color = nil, NSColor* secondaryColor = nil);
PUBLIC NSBox* OakCreateVerticalLine (NSColor* primaryColor, NSColor* secondaryColor = nil);
PUBLIC NSBox* OakCreateHorizontalLine (NSColor* primaryColor, NSColor* secondaryColor = nil);
PUBLIC BOOL OakSetAccessibilityLabel(NSObject* element, NSObject* label);
31 changes: 27 additions & 4 deletions Frameworks/OakAppKit/src/OakUIConstructionFunctions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@
return res;
}

NSPopUpButton* OakCreatePopUpButton (BOOL pullsDown, NSString* initialItemTitle)
NSPopUpButton* OakCreatePopUpButton (BOOL pullsDown, NSString* initialItemTitle, NSObject* accessibilityLabel)
{
NSPopUpButton* res = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:pullsDown];
res.font = OakControlFont();
if(initialItemTitle)
[[res cell] setMenuItem:[[NSMenuItem alloc] initWithTitle:initialItemTitle action:@selector(nop:) keyEquivalent:@""]];
OakSetAccessibilityLabel(res, accessibilityLabel);
return res;
}

Expand All @@ -77,24 +78,26 @@

[[res cell] setUsesItemFromMenu:NO];
[[res cell] setMenuItem:item];
[[res cell] accessibilitySetOverrideValue:@"Actions" forAttribute:NSAccessibilityDescriptionAttribute];
OakSetAccessibilityLabel(res, @"Actions");

return res;
}

NSPopUpButton* OakCreateStatusBarPopUpButton (NSString* initialItemTitle)
NSPopUpButton* OakCreateStatusBarPopUpButton (NSString* initialItemTitle, NSObject* accessibilityLabel)
{
NSPopUpButton* res = OakCreatePopUpButton(NO, initialItemTitle);
[[res cell] setBackgroundStyle:NSBackgroundStyleRaised];
res.font = OakStatusBarFont();
res.bordered = NO;
OakSetAccessibilityLabel(res, accessibilityLabel);
return res;
}

NSComboBox* OakCreateComboBox ()
NSComboBox* OakCreateComboBox (NSObject* accessibilityLabel)
{
NSComboBox* res = [[NSComboBox alloc] initWithFrame:NSZeroRect];
res.font = OakControlFont();
OakSetAccessibilityLabel(res, accessibilityLabel);
return res;
}

Expand Down Expand Up @@ -211,3 +214,23 @@ - (NSArray*)accessibilityAttributeNames
[res setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationVertical];
return res;
}

BOOL OakSetAccessibilityLabel(NSObject* element, NSObject* label)
{
if([element isKindOfClass:[NSControl class]])
element = [(NSControl*)element cell] ?: element; // e.g. NSTableView is an NSControl with a nil cell
else if(!([element isKindOfClass:[NSView class]] || [element isKindOfClass:[NSCell class]]))
return NO;

NSString* attribute = NSAccessibilityDescriptionAttribute;
if([label isKindOfClass:[NSView class]] || [label isKindOfClass:[NSCell class]])
{
attribute = NSAccessibilityTitleUIElementAttribute;
if ([label isKindOfClass:[NSControl class]])
label = [(NSControl*)label cell] ?: label;
}
else if(![label isKindOfClass:[NSString class]])
return NO;

return [element accessibilitySetOverrideValue:label forAttribute:attribute];
}
16 changes: 6 additions & 10 deletions Frameworks/OakTextView/src/OTVStatusBar.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
return res;
}

static NSButton* OakCreateImageToggleButton (NSImage* image)
static NSButton* OakCreateImageToggleButton (NSImage* image, NSObject* accessibilityLabel)
{
NSButton* res = [NSButton new];

Expand All @@ -35,6 +35,7 @@

[res setImage:image];
[res setImagePosition:NSImageOnly];
OakSetAccessibilityLabel(res, accessibilityLabel);

return res;
}
Expand All @@ -57,19 +58,15 @@ - (id)initWithFrame:(NSRect)aRect
if(self = [super initWithGradient:[[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithCalibratedWhite:1.000 alpha:0.68], 0.0, [NSColor colorWithCalibratedWhite:1.000 alpha:0.5], 0.0416, [NSColor colorWithCalibratedWhite:1.000 alpha:0.0], 1.0, nil] inactiveGradient:[[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithCalibratedWhite:1.000 alpha:0.68], 0.0, [NSColor colorWithCalibratedWhite:1.000 alpha:0.5], 0.0416, [NSColor colorWithCalibratedWhite:1.000 alpha:0.0], 1.0, nil]])
{
self.selectionField = OakCreateTextField(@"1:1");
self.grammarPopUp = OakCreateStatusBarPopUpButton(@"");
self.grammarPopUp = OakCreateStatusBarPopUpButton(@"", @"Grammar");
self.tabSizePopUp = OakCreateStatusBarPopUpButton();
self.tabSizePopUp.pullsDown = YES;
self.bundleItemsPopUp = OakCreateStatusBarPopUpButton();
self.symbolPopUp = OakCreateStatusBarPopUpButton(@"");
self.macroRecordingButton = OakCreateImageToggleButton([NSImage imageNamed:@"Recording" inSameBundleAsClass:[self class]]);
self.bundleItemsPopUp = OakCreateStatusBarPopUpButton(nil, @"Bundle Item");
self.symbolPopUp = OakCreateStatusBarPopUpButton(@"", @"Symbol");
self.macroRecordingButton = OakCreateImageToggleButton([NSImage imageNamed:@"Recording" inSameBundleAsClass:[self class]], @"Record a macro");
self.macroRecordingButton.action = @selector(toggleMacroRecording:);
self.macroRecordingButton.toolTip = @"Click to start recording a macro";

[self.grammarPopUp.cell accessibilitySetOverrideValue:@"Grammar" forAttribute:NSAccessibilityDescriptionAttribute];
[self.symbolPopUp.cell accessibilitySetOverrideValue:@"Symbol" forAttribute:NSAccessibilityDescriptionAttribute];
[self.macroRecordingButton.cell accessibilitySetOverrideValue:@"Record a macro" forAttribute:NSAccessibilityDescriptionAttribute];

[self setupTabSizeMenu:self];

// ===========================
Expand All @@ -80,7 +77,6 @@ - (id)initWithFrame:(NSRect)aRect
item.image = [NSImage imageNamed:NSImageNameActionTemplate];
[[self.bundleItemsPopUp cell] setUsesItemFromMenu:NO];
[[self.bundleItemsPopUp cell] setMenuItem:item];
[[self.bundleItemsPopUp cell] accessibilitySetOverrideValue:@"Bundle Item" forAttribute:NSAccessibilityDescriptionAttribute];

NSView* wrappedBundleItemsPopUpButton = [NSView new];
[wrappedBundleItemsPopUpButton addSubview:self.bundleItemsPopUp];
Expand Down
1 change: 1 addition & 0 deletions bin/gen_credits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def self.initialize(dbm_file)
@db['7640cae93abde468b73f35d6620a9b04'] = 'caleb'
@db['f889181fc58ccb702822b54fe3702d24'] = 'codykrieger'
@db['571db4b87bd7d2fec3dcd5524cb7d9ae'] = 'rdwampler'
@db['a4c0d688809489ab98a162b10c57381c'] = 'dusek'
ObjectSpace.define_finalizer(@db, proc {|id| db.close })
end

Expand Down