Revision: 3800
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3800&view=rev
Author:   hofman
Date:     2008-04-23 04:51:57 -0700 (Wed, 23 Apr 2008)

Log Message:
-----------
Leave some accessibility attributes and actions to the parent of the annotation 
element.

Modified Paths:
--------------
    trunk/PDFDisplayView_SKExtensions.h
    trunk/PDFDisplayView_SKExtensions.m
    trunk/SKAccessibilityPDFAnnotationElement.h
    trunk/SKAccessibilityPDFAnnotationElement.m

Modified: trunk/PDFDisplayView_SKExtensions.h
===================================================================
--- trunk/PDFDisplayView_SKExtensions.h 2008-04-23 10:13:30 UTC (rev 3799)
+++ trunk/PDFDisplayView_SKExtensions.h 2008-04-23 11:51:57 UTC (rev 3800)
@@ -46,7 +46,10 @@
 @end
 
 @interface PDFDisplayView (SKExtensions)
-- (SKPDFView *)skpdfView;
+- (NSRect)screenRectForAnnotationElement:(id)element;
+- (BOOL)isAnnotationElementFocused:(id)element;
+- (void)setFocused:(BOOL)focused forAnnotationElement:(id)element;
+- (void)pressAnnotationElement:(id)element;
 @end
 
 @interface SKAccessibilityPDFDisplayViewElement : NSObject {

Modified: trunk/PDFDisplayView_SKExtensions.m
===================================================================
--- trunk/PDFDisplayView_SKExtensions.m 2008-04-23 10:13:30 UTC (rev 3799)
+++ trunk/PDFDisplayView_SKExtensions.m 2008-04-23 11:51:57 UTC (rev 3800)
@@ -70,28 +70,27 @@
 }
 
 - (NSArray *)replacementAccessibilityAttributeNames {
-    if ([self skpdfView])
-        return [originalAccessibilityAttributeNames(self, _cmd) 
arrayByAddingObject:NSAccessibilityChildrenAttribute];
-    else
+    if ([self skpdfView]) {
+        static NSArray *attributes = nil;
+        if (attributes == nil)
+            attributes = [[originalAccessibilityAttributeNames(self, _cmd) 
arrayByAddingObject:NSAccessibilityChildrenAttribute] retain];
+        return attributes;
+    } else {
         return originalAccessibilityAttributeNames(self, _cmd);
+    }
 }
 
 - (id)replacementAccessibilityAttributeValue:(NSString *)attribute {
     SKPDFView *pdfView = [self skpdfView];
-    if (pdfView == nil) {
-        return originalAccessibilityAttributeValue(self, _cmd, attribute);
-    } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
-        return NSAccessibilityGroupRole;
-    } else if ([attribute 
isEqualToString:NSAccessibilityRoleDescriptionAttribute]) {
-        return NSAccessibilityRoleDescription(NSAccessibilityGroupRole, nil);
-    } else if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) {
-        return NSAccessibilityUnignoredChildren([pdfView 
accessibilityChildren]);
-    } else if ([attribute isEqualToString:NSAccessibilityFocusedAttribute]) {
-        NSNumber *focused = originalAccessibilityAttributeValue(self, _cmd, 
attribute);
-        return [NSNumber numberWithBool:[pdfView activeAnnotation] == nil && 
[focused boolValue]];
-    } else {
-        return originalAccessibilityAttributeValue(self, _cmd, attribute);
+    if (pdfView) {
+        if ([attribute isEqualToString:NSAccessibilityRoleAttribute])
+            return NSAccessibilityGroupRole;
+        else if ([attribute 
isEqualToString:NSAccessibilityRoleDescriptionAttribute])
+            return NSAccessibilityRoleDescription(NSAccessibilityGroupRole, 
nil);
+        else if ([attribute isEqualToString:NSAccessibilityChildrenAttribute])
+            return NSAccessibilityUnignoredChildren([pdfView 
accessibilityChildren]);
     }
+    return originalAccessibilityAttributeValue(self, _cmd, attribute);
 }
 
 - (id)replacementAccessibilityHitTest:(NSPoint)point {
@@ -101,9 +100,8 @@
         PDFPage *page = [pdfView pageForPoint:localPoint nearest:NO];
         if (page) {
             PDFAnnotation *annotation = [page annotationAtPoint:[pdfView 
convertPoint:localPoint toPage:page]];
-            if ([[annotation type] isEqualToString:SKLinkString] || 
[annotation isNoteAnnotation]) {
+            if ([[annotation type] isEqualToString:SKLinkString] || 
[annotation isNoteAnnotation])
                 return [[SKAccessibilityPDFAnnotationElement 
elementWithAnnotation:annotation parent:self] accessibilityHitTest:point];
-            }
         }
         return [[SKAccessibilityPDFDisplayViewElement elementWithParent:self] 
accessibilityHitTest:point];
     } else {
@@ -125,10 +123,42 @@
     }
 }
 
-- (BOOL)accessibilityIsIgnored {
-    return NO;
+- (NSRect)screenRectForAnnotationElement:(id)element {
+    NSRect rect = NSZeroRect;
+    SKPDFView *pdfView = [self skpdfView];
+    if (pdfView) {
+        PDFAnnotation *annotation = [element annotation];
+        rect = [pdfView convertRect:[pdfView convertRect:[annotation bounds] 
fromPage:[annotation page]] toView:nil];
+        rect.origin = [[pdfView window] convertBaseToScreen:rect.origin];
+    }
+    return rect;
 }
 
+- (BOOL)isAnnotationElementFocused:(id)element {
+    return [[self skpdfView] activeAnnotation] == [element annotation];
+}
+
+- (void)setFocused:(BOOL)focused forAnnotationElement:(id)element {
+    SKPDFView *pdfView = [self skpdfView];
+    if (pdfView) {
+        PDFAnnotation *annotation = [element annotation];
+        if (focused)
+            [pdfView setActiveAnnotation:annotation];
+        else if ([pdfView activeAnnotation] == annotation)
+            [pdfView setActiveAnnotation:nil];
+    }
+}
+
+- (void)pressAnnotationElement:(id)element {
+    SKPDFView *pdfView = [self skpdfView];
+    if (pdfView) {
+        PDFAnnotation *annotation = [element annotation];
+        if ([pdfView activeAnnotation] != annotation)
+            [pdfView setActiveAnnotation:annotation];
+        [pdfView editActiveAnnotation:self];
+    }
+}
+
 + (void)load {
     if ([self instancesRespondToSelector:@selector(passwordEntered:)])
         originalPasswordEntered = 
OBReplaceMethodImplementationWithSelector(self, @selector(passwordEntered:), 
@selector(replacementPasswordEntered:));
@@ -189,12 +219,6 @@
 - (id)accessibilityAttributeValue:(NSString *)attribute {
     if ([attribute isEqualToString:NSAccessibilityParentAttribute])
         return NSAccessibilityUnignoredAncestor(parent);
-    else if ([attribute isEqualToString:NSAccessibilityWindowAttribute])
-        // We're in the same window as our parent.
-        return [NSAccessibilityUnignoredAncestor(parent) 
accessibilityAttributeValue:NSAccessibilityWindowAttribute];
-    else if ([attribute 
isEqualToString:NSAccessibilityTopLevelUIElementAttribute])
-        // We're in the same top level element as our parent.
-        return [NSAccessibilityUnignoredAncestor(parent) 
accessibilityAttributeValue:NSAccessibilityTopLevelUIElementAttribute];
     else if (originalAccessibilityAttributeValue != NULL)
         return originalAccessibilityAttributeValue(parent, _cmd, attribute);
     else if ([parent respondsToSelector:_cmd])

Modified: trunk/SKAccessibilityPDFAnnotationElement.h
===================================================================
--- trunk/SKAccessibilityPDFAnnotationElement.h 2008-04-23 10:13:30 UTC (rev 
3799)
+++ trunk/SKAccessibilityPDFAnnotationElement.h 2008-04-23 11:51:57 UTC (rev 
3800)
@@ -46,4 +46,5 @@
 }
 + (id)elementWithAnnotation:(PDFAnnotation *)anAnnotation parent:(id)aParent;
 - (id)initWithAnnotation:(PDFAnnotation *)anAnnotation parent:(id)aParent;
+- (PDFAnnotation *)annotation;
 @end

Modified: trunk/SKAccessibilityPDFAnnotationElement.m
===================================================================
--- trunk/SKAccessibilityPDFAnnotationElement.m 2008-04-23 10:13:30 UTC (rev 
3799)
+++ trunk/SKAccessibilityPDFAnnotationElement.m 2008-04-23 11:51:57 UTC (rev 
3800)
@@ -38,7 +38,6 @@
 
 #import "SKAccessibilityPDFAnnotationElement.h"
 #import <Quartz/Quartz.h>
-#import "SKPDFView.h"
 #import "PDFAnnotation_SKExtensions.h"
 #import "PDFDisplayView_SKExtensions.h"
 #import "SKStringConstants.h"
@@ -77,6 +76,10 @@
     return [annotation hash] + [parent hash];
 }
 
+- (PDFAnnotation *)annotation {
+    return annotation;
+}
+
 - (NSArray *)accessibilityAttributeNames {
     return [annotation accessibilityAttributeNames];
 }
@@ -109,17 +112,13 @@
         // We're in the same top level element as our parent.
         return [NSAccessibilityUnignoredAncestor(parent) 
accessibilityAttributeValue:NSAccessibilityTopLevelUIElementAttribute];
     } else if ([attribute isEqualToString:NSAccessibilityFocusedAttribute]) {
-        return [NSNumber numberWithBool:[[parent skpdfView] activeAnnotation] 
== annotation];
+        return [NSNumber numberWithBool:[parent 
isAnnotationElementFocused:self]];
     } else if ([attribute isEqualToString:NSAccessibilityEnabledAttribute]) {
         return [NSNumber numberWithBool:NO];
     } else if ([attribute isEqualToString:NSAccessibilityPositionAttribute]) {
-        SKPDFView *pdfView = [parent skpdfView];
-        NSRect rect = [pdfView convertRect:[annotation bounds] 
fromPage:[annotation page]];
-        return [NSValue valueWithPoint:[[pdfView window] 
convertBaseToScreen:[pdfView convertPoint:rect.origin toView:nil]]];
+        return [NSValue valueWithPoint:[parent 
screenRectForAnnotationElement:self].origin];
     } else if ([attribute isEqualToString:NSAccessibilitySizeAttribute]) {
-        SKPDFView *pdfView = [parent skpdfView];
-        NSRect rect = [pdfView convertRect:[annotation bounds] 
fromPage:[annotation page]];
-        return [NSValue valueWithSize:[pdfView convertSize:rect.size 
toView:nil]];
+        return [NSValue valueWithSize:[parent 
screenRectForAnnotationElement:self].size];
     } else {
         return nil;
     }
@@ -130,12 +129,8 @@
 }
 
 - (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute {
-    if ([attribute isEqualToString:NSAccessibilityFocusedAttribute]) {
-        if ([value boolValue])
-            [[parent skpdfView] setActiveAnnotation:annotation];
-        else if ([[parent skpdfView] activeAnnotation] == annotation)
-            [[parent skpdfView] setActiveAnnotation:nil];
-    }
+    if ([attribute isEqualToString:NSAccessibilityFocusedAttribute])
+        [parent setFocused:[value boolValue] forAnnotationElement:self];
 }
 
 - (BOOL)accessibilityIsIgnored {
@@ -162,12 +157,8 @@
 }
 
 - (void)accessibilityPerformAction:(NSString *)anAction {
-    if ([anAction isEqualToString:NSAccessibilityPressAction]) {
-        SKPDFView *pdfView = [parent skpdfView];
-        if ([pdfView activeAnnotation] != annotation)
-            [pdfView setActiveAnnotation:annotation];
-        [pdfView editActiveAnnotation:self];
-    }
+    if ([anAction isEqualToString:NSAccessibilityPressAction])
+        [parent pressAnnotationElement:self];
 }
 
 @end


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

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to