Revision: 27749
          http://sourceforge.net/p/bibdesk/svn/27749
Author:   hofman
Date:     2022-07-21 17:13:23 +0000 (Thu, 21 Jul 2022)
Log Message:
-----------
use a proxy for the button cell in an editor text field as accessibility 
element, redirecting the parent to the text field cell rather than the text 
field parent.

Modified Paths:
--------------
    trunk/bibdesk/BDSKComplexStringCell.h
    trunk/bibdesk/BDSKComplexStringCell.m
    trunk/bibdesk/BDSKEditor.m
    trunk/bibdesk/BDSKEditorTextField.h
    trunk/bibdesk/BDSKEditorTextField.m
    trunk/bibdesk/Base.lproj/BDSKEditor.xib

Modified: trunk/bibdesk/BDSKComplexStringCell.h
===================================================================
--- trunk/bibdesk/BDSKComplexStringCell.h       2022-07-21 14:24:59 UTC (rev 
27748)
+++ trunk/bibdesk/BDSKComplexStringCell.h       2022-07-21 17:13:23 UTC (rev 
27749)
@@ -39,10 +39,5 @@
 #import <Cocoa/Cocoa.h>
 
 
-@interface BDSKComplexStringCell : NSTextFieldCell {
-    CGFloat rightInset;
-}
-
-@property (nonatomic ) CGFloat rightInset;
-
+@interface BDSKComplexStringCell : NSTextFieldCell
 @end

Modified: trunk/bibdesk/BDSKComplexStringCell.m
===================================================================
--- trunk/bibdesk/BDSKComplexStringCell.m       2022-07-21 14:24:59 UTC (rev 
27748)
+++ trunk/bibdesk/BDSKComplexStringCell.m       2022-07-21 17:13:23 UTC (rev 
27749)
@@ -42,41 +42,6 @@
 
 @implementation BDSKComplexStringCell
 
-@synthesize rightInset;
-
-- (id)initTextCell:(NSString *)aString {
-    self = [super initTextCell:aString];
-    if (self) {
-        rightInset = 0.0;
-    }
-    return self;
-}
-
-- (id)initWithCoder:(NSCoder *)decoder {
-    self = [super initWithCoder:decoder];
-    if (self) {
-        rightInset = [decoder decodeDoubleForKey:@"rightInset"];
-    }
-    return self;
-}
-
-- (void)encodeWithCoder:(NSCoder *)encoder {
-    [super encodeWithCoder:encoder];
-    [encoder encodeDouble:rightInset forKey:@"rightInset"];
-}
-
-- (NSRect)drawingRectForBounds:(NSRect)theRect {
-    NSRect rect = [super drawingRectForBounds:theRect];
-    rect.size.width -= rightInset;
-    return rect;
-}
-
-- (NSSize)cellSizeForBounds:(NSRect)aRect {
-    NSSize cellSize = [super cellSizeForBounds:aRect];
-    cellSize.width += rightInset;
-    return cellSize;
-}
-
 - (void)editWithFrame:(NSRect)rect inView:(NSView *)controlView editor:(NSText 
*)textObj delegate:(id)delegate event:(NSEvent *)event {
     [super editWithFrame:rect inView:controlView editor:textObj 
delegate:delegate event:event];
     if ([[self formatter] respondsToSelector:@selector(didStartEditor:)])

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2022-07-21 14:24:59 UTC (rev 27748)
+++ trunk/bibdesk/BDSKEditor.m  2022-07-21 17:13:23 UTC (rev 27749)
@@ -3731,10 +3731,10 @@
 
 
 @implementation BDSKEditorCellView
-
+/*
 - (NSArray *)accessibilityChildren {
     return NSAccessibilityUnignoredChildren([NSArray arrayWithObjects:[self 
textField], [(BDSKEditorTextField *)[self textField] button], nil]);
-}
+}*/
 
 @end
 

Modified: trunk/bibdesk/BDSKEditorTextField.h
===================================================================
--- trunk/bibdesk/BDSKEditorTextField.h 2022-07-21 14:24:59 UTC (rev 27748)
+++ trunk/bibdesk/BDSKEditorTextField.h 2022-07-21 17:13:23 UTC (rev 27749)
@@ -37,20 +37,31 @@
  */
 
 #import <Cocoa/Cocoa.h>
+#import "BDSKComplexStringCell.h"
 
+@class BDSKDragButton;
 
 @interface BDSKEditorTextField : NSTextField {
-    NSButton *button;
+    BDSKDragButton *button;
     SEL buttonAction;
 }
 @property (nonatomic) SEL buttonAction;
 @property (nonatomic, retain) id representedObject;
-@property (nonatomic, readonly) NSButton * button;
 @end
 
 
-@interface BDSKDragButton : NSButton <NSDraggingSource>
+@interface BDSKEditorTextFieldCell : BDSKComplexStringCell {
+    CGFloat rightInset;
+}
+@property (nonatomic ) CGFloat rightInset;
 @end
 
+
+@interface BDSKDragButton : NSButton <NSDraggingSource> {
+    id cellProxy;
+}
+@property (readonly) id cellProxy;
+@end
+
 @interface BDSKDragButtonCell : NSButtonCell
 @end

Modified: trunk/bibdesk/BDSKEditorTextField.m
===================================================================
--- trunk/bibdesk/BDSKEditorTextField.m 2022-07-21 14:24:59 UTC (rev 27748)
+++ trunk/bibdesk/BDSKEditorTextField.m 2022-07-21 17:13:23 UTC (rev 27749)
@@ -40,16 +40,25 @@
 #import "BDSKComplexStringCell.h"
 #import "NSImage_BDSKExtensions.h"
 #import "NSGeometry_BDSKExtensions.h"
+#import "NSView_BDSKExtensions.h"
 
 #define BUTTON_MARGIN_X 2.0
 #define BUTTON_MARGIN_Y 4.0
 
+@interface BDSKButtonCellProxy : NSObject <NSAccessibilityButton> {
+    id parent;
+    NSButtonCell *buttonCell;
+}
+- (id)initWithParent:(id)aParent buttonCell:(NSButtonCell *)aButtonCell;
+@end
+
+
 @implementation BDSKEditorTextField
 
 @synthesize buttonAction;
-@dynamic representedObject, button;
+@dynamic representedObject;
 
-+ (Class)cellClass { return [BDSKComplexStringCell class]; }
++ (Class)cellClass { return [BDSKEditorTextFieldCell class]; }
 
 - (id)initWithCoder:(NSCoder *)decoder {
     self = [super initWithCoder:decoder];
@@ -130,11 +139,11 @@
         }
         [button setImage:linkImage];
     }
-    [(BDSKComplexStringCell *)[self cell] setRightInset:object ? 
NSWidth([button frame]) + BUTTON_MARGIN_X : 0.0];
+    [(BDSKEditorTextFieldCell *)[self cell] setRightInset:object ? 
NSWidth([button frame]) + BUTTON_MARGIN_X : 0.0];
     [self setNeedsDisplay:YES];
 }
 
-- (NSButton *)button {
+- (BDSKDragButton *)button {
     return [button superview] ? button : nil;
 }
 
@@ -141,10 +150,84 @@
 @end
 
 
+@implementation BDSKEditorTextFieldCell
+
+@synthesize rightInset;
+
+- (id)initTextCell:(NSString *)aString {
+    self = [super initTextCell:aString];
+    if (self) {
+        rightInset = 0.0;
+    }
+    return self;
+}
+
+- (id)initWithCoder:(NSCoder *)decoder {
+    self = [super initWithCoder:decoder];
+    if (self) {
+        rightInset = [decoder decodeDoubleForKey:@"rightInset"];
+    }
+    return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)encoder {
+    [super encodeWithCoder:encoder];
+    [encoder encodeDouble:rightInset forKey:@"rightInset"];
+}
+
+- (NSRect)drawingRectForBounds:(NSRect)theRect {
+    NSRect rect = [super drawingRectForBounds:theRect];
+    rect.size.width -= rightInset;
+    return rect;
+}
+
+- (NSSize)cellSizeForBounds:(NSRect)aRect {
+    NSSize cellSize = [super cellSizeForBounds:aRect];
+    cellSize.width += rightInset;
+    return cellSize;
+}
+
+- (NSArray *)accessibilityChildren {
+    BDSKDragButton *button = [(BDSKEditorTextField *)[self controlView] 
button];
+    if (button)
+        return NSAccessibilityUnignoredChildren([NSArray 
arrayWithObjects:[button cellProxy], nil]);
+    return nil;
+}
+
+- (id)accessibilityHitTest:(NSPoint)point {
+    NSButton *button = [(BDSKEditorTextField *)[self controlView] button];
+    if (button && NSPointInRect(point, [button convertRectToScreen:[button 
bounds]]))
+        return [button accessibilityHitTest:point];
+    return NSAccessibilityUnignoredAncestor(self);
+}
+
+- (NSArray *)accessibilityAttributeNames {
+    return [[super accessibilityAttributeNames] 
arrayByAddingObject:NSAccessibilityChildrenAttribute];
+}
+
+- (id)accessibilityAttributeValue:(NSString *)attribute {
+    if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpartial-availability"
+        return [self accessibilityChildren];
+#pragma clang diagnostic pop
+    return [super accessibilityAttributeValue:attribute];
+}
+
+@end
+
+
 @implementation BDSKDragButton : NSButton
 
+@dynamic cellProxy;
+
 + (Class)cellClass { return [BDSKDragButtonCell class]; }
 
+- (void)dealloc {
+    BDSKDESTROY(cellProxy);
+    [super dealloc];
+}
+
 - (BOOL)canBecomeFirstResponder { return NO; }
 
 - (NSDragOperation)draggingSession:(NSDraggingSession *)session 
sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
@@ -151,6 +234,16 @@
     return NSDragOperationGeneric;
 }
 
+- (id)cellProxy {
+    if (cellProxy == nil)
+        cellProxy = [[BDSKButtonCellProxy alloc] initWithParent:[(id)[self 
superview] cell] buttonCell:[self cell]];
+    return cellProxy;
+}
+
+- (id)accessibilityHitTest:(NSPoint)point {
+    return NSAccessibilityUnignoredAncestor([self cellProxy]);
+}
+
 @end
 
 
@@ -172,3 +265,117 @@
 }
 
 @end
+
+
+@implementation BDSKButtonCellProxy
+
+- (id)initWithParent:(id)aParent buttonCell:(NSButtonCell *)aButtonCell {
+    self = [super init];
+    if (self) {
+        parent = aParent;
+        buttonCell = [aButtonCell retain];
+    }
+    return self;
+}
+
+- (void)dealloc {
+    BDSKDESTROY(buttonCell);
+    [super dealloc];
+}
+
+- (id)accessibilityParent {
+    return NSAccessibilityUnignoredAncestor(parent);
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpartial-availability"
+
+- (id)accessibilityRole {
+    return [buttonCell accessibilityRole];
+}
+
+- (id)accessibilityRoleDescription {
+    return [buttonCell accessibilityRoleDescription];
+}
+
+- (NSRect)accessibilityFrame {
+    return [buttonCell accessibilityFrame];
+}
+
+- (NSString *)accessibilityLabel {
+    return [buttonCell accessibilityLabel];
+}
+
+- (NSString *)accessibilityTitle {
+    return [buttonCell accessibilityTitle];
+}
+
+- (NSString *)accessibilityValue {
+    return [buttonCell accessibilityValue];
+}
+
+- (NSString *)accessibilityHelp {
+    return [buttonCell accessibilityHelp];
+}
+
+- (id)accessibilityTopLevelUIElement {
+    return [buttonCell accessibilityTopLevelUIElement];
+}
+
+- (id)accessibilityWindow {
+    return [buttonCell accessibilityWindow];
+}
+
+- (BOOL)isAccessibilityFocused {
+    return [buttonCell isAccessibilityFocused];
+}
+
+- (void)setAccessibilityFocused:(BOOL)focused {
+    [buttonCell setAccessibilityFocused:focused];
+}
+
+- (BOOL)isAccessibilityEnabled {
+    return [buttonCell isAccessibilityEnabled];
+}
+
+- (BOOL)accessibilityPerformPress {
+    return [buttonCell accessibilityPerformPress];
+}
+
+#pragma clang diagnostic pop
+
+- (id)accessibilityHitTest:(NSPoint)point {
+    return NSAccessibilityUnignoredAncestor(self);
+}
+
+- (BOOL)accessibilityIsIgnored {
+    return NO;
+}
+
+- (NSArray *)accessibilityAttributeNames {
+    return [buttonCell accessibilityAttributeNames];
+}
+
+- (id)accessibilityAttributeValue:(NSString *)attribute {
+    if ([attribute isEqualToString:NSAccessibilityParentAttribute])
+        return NSAccessibilityUnignoredAncestor(parent);
+    return [buttonCell accessibilityAttributeValue:attribute];
+}
+
+- (BOOL)accessibilityIsAttributeSettable:(NSString *)attribute {
+    return [buttonCell accessibilityIsAttributeSettable:attribute];
+}
+
+- (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute {
+    return [buttonCell accessibilitySetValue:value forAttribute:attribute];
+}
+
+- (NSArray *)accessibilityActionNames {
+    return [buttonCell accessibilityActionNames];
+}
+
+- (void)accessibilityPerformAction:(NSString *)anAction {
+    [buttonCell accessibilityPerformAction:anAction];
+}
+
+@end

Modified: trunk/bibdesk/Base.lproj/BDSKEditor.xib
===================================================================
--- trunk/bibdesk/Base.lproj/BDSKEditor.xib     2022-07-21 14:24:59 UTC (rev 
27748)
+++ trunk/bibdesk/Base.lproj/BDSKEditor.xib     2022-07-21 17:13:23 UTC (rev 
27749)
@@ -273,7 +273,7 @@
                                                                                
         <subviews>
                                                                                
             <textField horizontalHuggingPriority="251" 
verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" 
translatesAutoresizingMaskIntoConstraints="NO" id="KJ8-73-C65" 
customClass="BDSKEditorTextField">
                                                                                
                 <rect key="frame" x="0.0" y="1" width="416" height="21"/>
-                                                                               
                 <textFieldCell key="cell" scrollable="YES" 
lineBreakMode="clipping" sendsActionOnEndEditing="YES" borderStyle="bezel" 
drawsBackground="YES" id="JS8-KM-s9E" customClass="BDSKComplexStringCell">
+                                                                               
                 <textFieldCell key="cell" scrollable="YES" 
lineBreakMode="clipping" sendsActionOnEndEditing="YES" borderStyle="bezel" 
drawsBackground="YES" id="JS8-KM-s9E" customClass="BDSKEditorTextFieldCell">
                                                                                
                     <font key="font" usesAppearanceFont="YES"/>
                                                                                
                     <color key="textColor" name="controlTextColor" 
catalog="System" colorSpace="catalog"/>
                                                                                
                     <color key="backgroundColor" name="textBackgroundColor" 
catalog="System" colorSpace="catalog"/>

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to