Revision: 12140
          http://sourceforge.net/p/skim-app/code/12140
Author:   hofman
Date:     2021-02-28 23:59:26 +0000 (Sun, 28 Feb 2021)
Log Message:
-----------
Use color item views as accessibility children of color swatch

Modified Paths:
--------------
    trunk/ReleaseNotes.rtf
    trunk/SKColorSwatch.m

Modified: trunk/ReleaseNotes.rtf
===================================================================
--- trunk/ReleaseNotes.rtf      2021-02-28 21:37:42 UTC (rev 12139)
+++ trunk/ReleaseNotes.rtf      2021-02-28 23:59:26 UTC (rev 12140)
@@ -340,6 +340,7 @@
 \f1\i0\b0\fs22 \cf2 {\listtext \uc0\u8226      }New application icon.\
 
\pard\tx220\tx720\tx1440\tx2880\tx4320\tx5760\tx7200\li720\fi-720\partightenfactor0
 \ls2\ilvl0\cf2 {\listtext      \uc0\u8226      }Quicklook support for 
PostScript files.\
+{\listtext     \uc0\u8226      }Scale preview tool tips with current factor.\
 \pard\tx1440\tx2880\tx4320\tx5760\tx7200\partightenfactor0
 
 \f3\i\b\fs26 \cf2 \
@@ -349,6 +350,8 @@
 \f1\i0\b0\fs22 \cf2 {\listtext \uc0\u8226      }Don't try to mount external 
volumes to check recent documents.\
 
\pard\tx220\tx720\tx1440\tx2880\tx4320\tx5760\tx7200\li720\fi-720\partightenfactor0
 \ls3\ilvl0\cf2 {\listtext      \uc0\u8226      }Fix response to opening a 
large number of documents at startup.\
+{\listtext     \uc0\u8226      }Separate window title on Big Sur.\
+{\listtext     \uc0\u8226      }Avoid exception when setting up info window.\
 \pard\tx560\tx1440\tx2880\tx4320\tx5760\tx7200\partightenfactor0
 
 \f2\b\fs28 \cf2 \

Modified: trunk/SKColorSwatch.m
===================================================================
--- trunk/SKColorSwatch.m       2021-02-28 21:37:42 UTC (rev 12139)
+++ trunk/SKColorSwatch.m       2021-02-28 23:59:26 UTC (rev 12140)
@@ -69,21 +69,6 @@
 
 #define BACKGROUND_WIDTH_OFFSET 6.0
 
-@interface SKAccessibilityColorSwatchElement : NSObject {
-    SKColorSwatch *parent;
-    NSInteger index;
-}
-+ (id)elementWithIndex:(NSInteger)anIndex parent:(SKColorSwatch *)aParent;
-- (id)initWithIndex:(NSInteger)anIndex parent:(SKColorSwatch *)aParent;
-@property (nonatomic, readonly) SKColorSwatch *parent;
-@property (nonatomic, readonly) NSInteger index;
-@end
-
-@interface NSColorWell (SKExtensions)
-@end
-
-#pragma mark -
-
 @interface SKColorSwatchBackgroundView : NSControl
 @property (nonatomic) CGFloat width;
 @end
@@ -111,14 +96,14 @@
 #pragma mark -
 
 @interface SKColorSwatch (SKAccessibilityColorSwatchElementParent)
-- (NSRect)screenRectForElementAtIndex:(NSInteger)anIndex;
-- (BOOL)isElementAtIndexFocused:(NSInteger)anIndex;
-- (void)elementAtIndex:(NSInteger)anIndex setFocused:(BOOL)focused;
-- (void)pressElementAtIndex:(NSInteger)anIndex;
+- (BOOL)isItemViewFocused:(SKColorSwatchItemView *)itemView;
+- (void)itemView:(SKColorSwatchItemView *)itemView setFocused:(BOOL)focused;
+- (void)pressItemView:(SKColorSwatchItemView *)itemView;
 @end
 
 @interface SKColorSwatch ()
 @property (nonatomic) NSInteger selectedColorIndex;
+@property (nonatomic, readonly) CGFloat fitWidth;
 - (void)setColor:(NSColor *)color atIndex:(NSInteger)i 
fromPanel:(BOOL)fromPanel;
 @end
 
@@ -125,7 +110,7 @@
 @implementation SKColorSwatch
 
 @synthesize colors, autoResizes, selects, clickedColorIndex=clickedIndex, 
selectedColorIndex=selectedIndex;
-@dynamic color;
+@dynamic color, fitWidth;
 
 + (void)initialize {
     SKINITIALIZE;
@@ -494,13 +479,18 @@
 
 - (void)setColors:(NSArray *)newColors {
     NSArray *oldColors = [self colors];
+    NSUInteger i, iMax = [newColors count];
     [self deactivate];
     [colors setArray:newColors];
     if (autoResizes && [newColors count] != [oldColors count])
         [self sizeToFit];
+    if ([self window]) {
+        i = [oldColors count];
+        while (i-- > 0)
+            NSAccessibilityPostNotification([itemViews objectAtIndex:i], 
NSAccessibilityUIElementDestroyedNotification);
+    }
     [itemViews makeObjectsPerformSelector:@selector(removeFromSuperview)];
     [itemViews removeAllObjects];
-    NSUInteger i = [newColors count], iMax = [newColors count];
     for (i = 0; i < iMax; i++) {
         SKColorSwatchItemView *itemView = [[SKColorSwatchItemView alloc] init];
         [itemView setColor:[newColors objectAtIndex:i]];
@@ -510,11 +500,8 @@
     }
     [self updateSubviewLayout];
     if ([self window]) {
-        i = [oldColors count];
-        while (i-- > 0)
-            NSAccessibilityPostNotification([SKAccessibilityColorSwatchElement 
elementWithIndex:i parent:self], NSAccessibilityUIElementDestroyedNotification);
         for (i = 0; i < iMax; i++)
-            NSAccessibilityPostNotification([SKAccessibilityColorSwatchElement 
elementWithIndex:i parent:self], NSAccessibilityCreatedNotification);
+            NSAccessibilityPostNotification([itemViews objectAtIndex:i], 
NSAccessibilityCreatedNotification);
         [self invalidateIntrinsicContentSize];
     }
     [[NSNotificationCenter defaultCenter] 
postNotificationName:SKColorSwatchColorsChangedNotification object:self];
@@ -607,7 +594,7 @@
         [self willChangeColors];
         [colors replaceObjectAtIndex:i withObject:color];
         [[itemViews objectAtIndex:i] setColor:color];
-        NSAccessibilityPostNotification([SKAccessibilityColorSwatchElement 
elementWithIndex:i parent:self], NSAccessibilityValueChangedNotification);
+        NSAccessibilityPostNotification([itemViews objectAtIndex:i], 
NSAccessibilityValueChangedNotification);
         [self didChangeColors];
         if (fromPanel == NO && selectedIndex == i) {
             NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];
@@ -638,7 +625,7 @@
         [self deactivate];
         [self willChangeColors];
         [colors insertObject:color atIndex:i];
-        NSAccessibilityPostNotification([SKAccessibilityColorSwatchElement 
elementWithIndex:i parent:self], NSAccessibilityCreatedNotification);
+        NSAccessibilityPostNotification([itemViews objectAtIndex:i], 
NSAccessibilityCreatedNotification);
         [self invalidateIntrinsicContentSize];
         SKColorSwatchItemView *itemView = [[SKColorSwatchItemView alloc] 
initWithFrame:[self frameForItemViewAtIndex:i collapsedIndex:i]];
         [itemView setColor:color];
@@ -683,7 +670,7 @@
                     [self sizeToFit];
                     [self invalidateIntrinsicContentSize];
                     [self noteFocusRingMaskChanged];
-                    
NSAccessibilityPostNotification([SKAccessibilityColorSwatchElement 
elementWithIndex:i parent:self], NSAccessibilityUIElementDestroyedNotification);
+                    NSAccessibilityPostNotification([itemViews 
objectAtIndex:i], NSAccessibilityUIElementDestroyedNotification);
                 }];
         } else {
             [self willChangeColors];
@@ -693,7 +680,7 @@
             [self didChangeColors];
             [self invalidateIntrinsicContentSize];
             [self updateSubviewLayout];
-            NSAccessibilityPostNotification([SKAccessibilityColorSwatchElement 
elementWithIndex:draggedIndex parent:self], 
NSAccessibilityUIElementDestroyedNotification);
+            NSAccessibilityPostNotification([itemViews 
objectAtIndex:draggedIndex], NSAccessibilityUIElementDestroyedNotification);
         }
     }
 }
@@ -712,7 +699,7 @@
             [self addSubview:itemView positioned:NSWindowAbove 
relativeTo:[itemViews objectAtIndex:to - 1]];
         [itemView release];
         [color release];
-        NSAccessibilityPostNotification([SKAccessibilityColorSwatchElement 
elementWithIndex:to parent:self], NSAccessibilityMovedNotification);
+        NSAccessibilityPostNotification([itemViews objectAtIndex:to], 
NSAccessibilityMovedNotification);
         [self noteFocusRingMaskChanged];
         [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
                 [self animateItemViewsCollapsing:-1 frameSize:NSZeroSize];
@@ -805,11 +792,7 @@
 }
 
 - (NSArray *)accessibilityChildren {
-    NSMutableArray *children = [NSMutableArray array];
-    NSInteger i, count = [colors count];
-    for (i = 0; i < count; i++)
-        [children addObject:[SKAccessibilityColorSwatchElement 
elementWithIndex:i parent:self]];
-    return NSAccessibilityUnignoredChildren(children);
+    return NSAccessibilityUnignoredChildren(itemViews);
 }
 
 - (NSArray *)accessibilityContents {
@@ -820,8 +803,7 @@
     NSPoint localPoint = [self convertPointFromScreen:point];
     NSInteger i = [self colorIndexAtPoint:localPoint];
     if (i != -1) {
-        SKAccessibilityColorSwatchElement *color = 
[[[SKAccessibilityColorSwatchElement alloc] initWithIndex:i parent:self] 
autorelease];
-        return [color accessibilityHitTest:point];
+        return NSAccessibilityUnignoredAncestor([itemViews objectAtIndex:i]);
     } else {
         return [super accessibilityHitTest:point];
     }
@@ -829,30 +811,18 @@
 
 - (id)accessibilityFocusedUIElement {
     if (focusedIndex != -1 && focusedIndex < (NSInteger)[colors count])
-        return 
NSAccessibilityUnignoredAncestor([[[SKAccessibilityColorSwatchElement alloc] 
initWithIndex:focusedIndex parent:self] autorelease]);
+        return NSAccessibilityUnignoredAncestor([itemViews 
objectAtIndex:focusedIndex]);
     else
         return NSAccessibilityUnignoredAncestor(self);
 }
 
-- (id)valueForElementAtIndex:(NSInteger)anIndex {
-    if (anIndex >= (NSInteger)[[self colors] count])
-        return nil;
-    return [[[self colors] objectAtIndex:anIndex] accessibilityValue];
+- (BOOL)isItemViewFocused:(SKColorSwatchItemView *)itemView {
+    return focusedIndex == (NSInteger)[itemViews indexOfObject:itemView];
 }
 
-- (NSRect)screenRectForElementAtIndex:(NSInteger)anIndex {
-    NSRect rect = NSZeroRect;
-    if (anIndex < (NSInteger)[[self colors] count])
-        return [self convertRectToScreen:NSInsetRect([self 
frameForColorAtIndex:anIndex], -1.0, -1.0)];
-    return rect;
-}
-
-- (BOOL)isElementAtIndexFocused:(NSInteger)anIndex {
-    return focusedIndex == anIndex;
-}
-
-- (void)elementAtIndex:(NSInteger)anIndex setFocused:(BOOL)focused {
-    if (focused && anIndex < (NSInteger)[[self colors] count]) {
+- (void)itemView:(SKColorSwatchItemView *)itemView setFocused:(BOOL)focused {
+    NSUInteger anIndex = [itemViews indexOfObject:itemView];
+    if (focused && anIndex < [[self colors] count]) {
         [[self window] makeFirstResponder:self];
         focusedIndex = anIndex;
         [self noteFocusRingMaskChanged];
@@ -860,8 +830,9 @@
     }
 }
 
-- (void)pressElementAtIndex:(NSInteger)anIndex {
-    if (anIndex < (NSInteger)[[self colors] count])
+- (void)pressItemView:(SKColorSwatchItemView *)itemView {
+    NSUInteger anIndex = [itemViews indexOfObject:itemView];
+    if (anIndex < [[self colors] count])
         [self performClickAtIndex:anIndex];
 }
 
@@ -869,82 +840,6 @@
 
 #pragma mark -
 
-@implementation SKAccessibilityColorSwatchElement
-
-@synthesize parent, index;
-
-+ (id)elementWithIndex:(NSInteger)anIndex parent:(SKColorSwatch *)aParent {
-    return [[[self alloc] initWithIndex:anIndex parent:aParent] autorelease];
-}
-
-- (id)initWithIndex:(NSInteger)anIndex parent:(SKColorSwatch *)aParent {
-    self = [super init];
-    if (self) {
-        parent = aParent;
-        index = anIndex;
-    }
-    return self;
-}
-
-- (BOOL)isEqual:(id)other {
-    if ([other isKindOfClass:[self class]] == NO)
-        return NO;
-    SKAccessibilityColorSwatchElement *otherElement = 
(SKAccessibilityColorSwatchElement *)other;
-    return parent == [otherElement parent] && index == [otherElement index];
-}
-
-- (NSUInteger)hash {
-    return [parent hash] + ((index + 1) >> 4);
-}
-
-- (BOOL)accessibilityElement {
-    return YES;
-}
-
-- (NSString *)accessibilityRole {
-    return NSAccessibilityColorWellRole;
-}
-
-- (NSString *)accessibilityRoleDescription {
-    return NSAccessibilityRoleDescriptionForUIElement(self);
-}
-
-- (id)accessibilityValue {
-    return [parent valueForElementAtIndex:index];
-}
-
-- (BOOL)isAccessibilityFocused {
-    return [parent isElementAtIndexFocused:index];
-}
-
-- (void)setAccessibilityFocused:(BOOL)flag {
-    [parent elementAtIndex:index setFocused:flag];
-}
-
-- (NSRect)accessibilityFrame {
-    return [parent screenRectForElementAtIndex:index];
-}
-
-- (BOOL)accessibilityPerformPress {
-    [parent pressElementAtIndex:index];
-    return YES;
-}
-
-- (BOOL)accessibilityPerformPick {
-    [parent pressElementAtIndex:index];
-    return YES;
-}
-
-- (id)accessibilityHitTest:(NSPoint)point {
-    return NSAccessibilityUnignoredAncestor(self);
-}
-
-- (id)accessibilityFocusedUIElement {
-    return NSAccessibilityUnignoredAncestor(self);
-}
-
-@end
-
 @implementation NSColorWell (SKExtensions)
 
 static void (*original_activate)(id, SEL, BOOL) = NULL;
@@ -1107,5 +1002,43 @@
     }
 }
 
+- (BOOL)accessibilityElement {
+    return YES;
+}
+
+- (NSString *)accessibilityRole {
+    return NSAccessibilityColorWellRole;
+}
+
+- (NSString *)accessibilityRoleDescription {
+    return NSAccessibilityRoleDescriptionForUIElement(self);
+}
+
+- (id)accessibilityValue {
+    return [color accessibilityValue];
+}
+
+- (BOOL)isAccessibilityFocused {
+    return [(SKColorSwatch *)[self superview] isItemViewFocused:self];
+}
+
+- (void)setAccessibilityFocused:(BOOL)flag {
+    [(SKColorSwatch *)[self superview] itemView:self setFocused:flag];
+}
+
+- (BOOL)accessibilityPerformPress {
+    [(SKColorSwatch *)[self superview] pressItemView:self];
+    return YES;
+}
+
+- (BOOL)accessibilityPerformPick {
+    [(SKColorSwatch *)[self superview] pressItemView:self];
+    return YES;
+}
+
+- (id)accessibilityFocusedUIElement {
+    return NSAccessibilityUnignoredAncestor(self);
+}
+
 @end
 

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



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to