summaryrefslogtreecommitdiff
path: root/platform/ios/Classes
diff options
context:
space:
mode:
authorPaul Gardiner <paul.gardiner@artifex.com>2013-10-03 15:14:01 +0100
committerPaul Gardiner <paul.gardiner@artifex.com>2013-10-09 14:31:12 +0100
commit5ac49662b7d7affd0b43c6b8e827e292b6b8e3e3 (patch)
tree35d03d97edec2db4463f7764efc95055fad3a216 /platform/ios/Classes
parent17c797eaaec9b33aedf4970fe2184f86f65b25d8 (diff)
downloadmupdf-5ac49662b7d7affd0b43c6b8e827e292b6b8e3e3.tar.xz
iOS: implement internal-link following
Also: add hooks for the other link types remove unnecessary protocol from MuPageViewReflow turn off optimizations for the debug build
Diffstat (limited to 'platform/ios/Classes')
-rw-r--r--platform/ios/Classes/MuDocumentController.m23
-rw-r--r--platform/ios/Classes/MuHitView.h2
-rw-r--r--platform/ios/Classes/MuHitView.m25
-rw-r--r--platform/ios/Classes/MuPageView.h2
-rw-r--r--platform/ios/Classes/MuPageViewNormal.m6
-rw-r--r--platform/ios/Classes/MuPageViewReflow.h2
-rw-r--r--platform/ios/Classes/MuPageViewReflow.m5
-rw-r--r--platform/ios/Classes/MuTapResult.h46
-rw-r--r--platform/ios/Classes/MuTapResult.m94
9 files changed, 203 insertions, 2 deletions
diff --git a/platform/ios/Classes/MuDocumentController.m b/platform/ios/Classes/MuDocumentController.m
index e089e0bb..8a82fa1f 100644
--- a/platform/ios/Classes/MuDocumentController.m
+++ b/platform/ios/Classes/MuDocumentController.m
@@ -460,7 +460,28 @@ static void flattenOutline(NSMutableArray *titles, NSMutableArray *pages, fz_out
float x1 = (width - GAP) - x0;
p.x -= ofs.x;
p.y -= ofs.y;
- if (p.x < x0) {
+ __block BOOL tapHandled = NO;
+ for (UIView<MuPageView> *view in [canvas subviews])
+ {
+ CGPoint pp = [sender locationInView:view];
+ if (CGRectContainsPoint(view.bounds, pp))
+ {
+ MuTapResult *result = [view handleTap:pp];
+ [result switchCaseInternal:^(MuTapResultInternalLink *link) {
+ [self gotoPage:link.pageNumber animated:NO];
+ tapHandled = YES;
+ } caseExternal:^(MuTapResultExternalLink *link) {
+ // Not currently supported
+ } caseRemote:^(MuTapResultRemoteLink *link) {
+ // Not currently supported
+ }];
+ if (tapHandled)
+ break;
+ }
+ }
+ if (tapHandled) {
+ // Do nothing further
+ } else if (p.x < x0) {
[self gotoPage: current-1 animated: YES];
} else if (p.x > x1) {
[self gotoPage: current+1 animated: YES];
diff --git a/platform/ios/Classes/MuHitView.h b/platform/ios/Classes/MuHitView.h
index 1be5dcb2..aa10d25b 100644
--- a/platform/ios/Classes/MuHitView.h
+++ b/platform/ios/Classes/MuHitView.h
@@ -6,6 +6,7 @@
//
#import <UIKit/UIKit.h>
+#import "MuTapResult.h"
#undef ABS
#undef MIN
@@ -25,4 +26,5 @@
- (id) initWithSearchResults: (int)n forDocument: (fz_document *)doc;
- (id) initWithLinks: (fz_link*)links forDocument: (fz_document *)doc;
- (void) setPageSize: (CGSize)s;
+- (MuTapResult *) handleTap:(CGPoint)pt;
@end
diff --git a/platform/ios/Classes/MuHitView.m b/platform/ios/Classes/MuHitView.m
index be67601a..5fe47d3d 100644
--- a/platform/ios/Classes/MuHitView.m
+++ b/platform/ios/Classes/MuHitView.m
@@ -66,6 +66,31 @@
[self setNeedsDisplay];
}
+- (MuTapResult *) handleTap:(CGPoint)pt
+{
+ CGSize scale = fitPageToScreen(pageSize, self.bounds.size);
+ pt.x /= scale.width;
+ pt.y /= scale.height;
+
+ for (int i = 0; i < hitCount; i++)
+ {
+ if (CGRectContainsPoint(hitRects[i], pt))
+ {
+ if (linkPage[i] >= 0)
+ {
+ return [[[MuTapResultInternalLink alloc] initWithPageNumber:linkPage[i]] autorelease];
+ }
+ if (linkUrl[i])
+ {
+ NSString *url = [NSString stringWithUTF8String:linkUrl[i]];
+ return [[[MuTapResultExternalLink alloc] initWithUrl:url] autorelease];
+ }
+ }
+ }
+
+ return nil;
+}
+
- (void) drawRect: (CGRect)r
{
CGSize scale = fitPageToScreen(pageSize, self.bounds.size);
diff --git a/platform/ios/Classes/MuPageView.h b/platform/ios/Classes/MuPageView.h
index 963a4aa0..d0b2f48d 100644
--- a/platform/ios/Classes/MuPageView.h
+++ b/platform/ios/Classes/MuPageView.h
@@ -6,6 +6,7 @@
//
#import <UIKit/UIKit.h>
+#import "MuTapResult.h"
@protocol MuPageView
-(int) number;
@@ -16,4 +17,5 @@
-(void) clearSearchResults;
-(void) resetZoomAnimated: (BOOL)animated;
-(void) setScale:(float)scale;
+-(MuTapResult *) handleTap:(CGPoint)pt;
@end
diff --git a/platform/ios/Classes/MuPageViewNormal.m b/platform/ios/Classes/MuPageViewNormal.m
index ccdd4fcd..3c25475e 100644
--- a/platform/ios/Classes/MuPageViewNormal.m
+++ b/platform/ios/Classes/MuPageViewNormal.m
@@ -525,4 +525,10 @@ static UIImage *renderPage(fz_document *doc, fz_display_list *page_list, fz_disp
- (void) setScale:(float)scale {}
+- (MuTapResult *) handleTap:(CGPoint)pt
+{
+ CGPoint lpt = [self convertPoint:pt toView:linkView];
+ return linkView ? [linkView handleTap:lpt] : nil;
+}
+
@end
diff --git a/platform/ios/Classes/MuPageViewReflow.h b/platform/ios/Classes/MuPageViewReflow.h
index 28638bc8..c7593c4d 100644
--- a/platform/ios/Classes/MuPageViewReflow.h
+++ b/platform/ios/Classes/MuPageViewReflow.h
@@ -9,7 +9,7 @@
#import "MuDocRef.h"
#import "MuPageView.h"
-@interface MuPageViewReflow : UIWebView <UIWebViewDelegate,UIGestureRecognizerDelegate,MuPageView>
+@interface MuPageViewReflow : UIWebView <UIWebViewDelegate,MuPageView>
{
int number;
float scale;
diff --git a/platform/ios/Classes/MuPageViewReflow.m b/platform/ios/Classes/MuPageViewReflow.m
index 541731fb..de47aae3 100644
--- a/platform/ios/Classes/MuPageViewReflow.m
+++ b/platform/ios/Classes/MuPageViewReflow.m
@@ -133,4 +133,9 @@ NSString *textAsHtml(fz_document *doc, int pageNum)
[self stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('content').style.zoom=\"%f\"", scale]];
}
+-(MuTapResult *) handleTap:(CGPoint)pt
+{
+ return nil;
+}
+
@end
diff --git a/platform/ios/Classes/MuTapResult.h b/platform/ios/Classes/MuTapResult.h
new file mode 100644
index 00000000..c0d930c5
--- /dev/null
+++ b/platform/ios/Classes/MuTapResult.h
@@ -0,0 +1,46 @@
+//
+// MuTapResult.h
+// MuPDF
+//
+// Copyright (c) 2013 Artifex Software, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@class MuTapResultInternalLink;
+@class MuTapResultExternalLink;
+@class MuTapResultRemoteLink;
+
+@interface MuTapResult : NSObject
+-(void) switchCaseInternal:(void (^)(MuTapResultInternalLink *))internalLinkBlock
+ caseExternal:(void (^)(MuTapResultExternalLink *))externalLinkBlock
+ caseRemote:(void (^)(MuTapResultRemoteLink *))remoteLinkBlock;
+@end
+
+@interface MuTapResultInternalLink : MuTapResult
+{
+ int pageNumber;
+}
+@property(readonly) int pageNumber;
+-(id)initWithPageNumber:(int)aNumber;
+@end
+
+@interface MuTapResultExternalLink : MuTapResult
+{
+ NSString *url;
+}
+@property(readonly) NSString *url;
+-(id)initWithUrl:(NSString *)aString;
+@end
+
+@interface MuTapResultRemoteLink : MuTapResult
+{
+ NSString *fileSpec;
+ int pageNumber;
+ BOOL newWindow;
+}
+@property(readonly) NSString *fileSpec;
+@property(readonly) int pageNumber;
+@property(readonly) BOOL newWindow;
+-(id)initWithFileSpec:(NSString *)aString pageNumber:(int)aNumber newWindow:(BOOL)aBool;
+@end
diff --git a/platform/ios/Classes/MuTapResult.m b/platform/ios/Classes/MuTapResult.m
new file mode 100644
index 00000000..7e3d71d1
--- /dev/null
+++ b/platform/ios/Classes/MuTapResult.m
@@ -0,0 +1,94 @@
+//
+// MuTapResult.m
+// MuPDF
+//
+// Copyright (c) 2013 Artifex Software, Inc. All rights reserved.
+//
+
+#import "MuTapResult.h"
+
+@implementation MuTapResult
+
+-(void) switchCaseInternal:(void (^)(MuTapResultInternalLink *))internalLinkBlock caseExternal:(void (^)(MuTapResultExternalLink *))externalLinkBlock caseRemote:(void (^)(MuTapResultRemoteLink *))remoteLinkBlock {}
+
+@end
+
+
+@implementation MuTapResultInternalLink
+
+@synthesize pageNumber;
+
+-(id) initWithPageNumber:(int)aNumber
+{
+ self = [super init];
+ if (self)
+ {
+ pageNumber = aNumber;
+ }
+ return self;
+}
+
+-(void) switchCaseInternal:(void (^)(MuTapResultInternalLink *))internalLinkBlock caseExternal:(void (^)(MuTapResultExternalLink *))externalLinkBlock caseRemote:(void (^)(MuTapResultRemoteLink *))remoteLinkBlock
+{
+ internalLinkBlock(self);
+}
+
+@end
+
+
+@implementation MuTapResultExternalLink
+
+@synthesize url;
+
+-(id) initWithUrl:(NSString *)aString
+{
+ self = [super init];
+ if (self)
+ {
+ url = [aString retain];
+ }
+ return self;
+}
+
+-(void) dealloc
+{
+ [url release];
+ [super dealloc];
+}
+
+-(void) switchCaseInternal:(void (^)(MuTapResultInternalLink *))internalLinkBlock caseExternal:(void (^)(MuTapResultExternalLink *))externalLinkBlock caseRemote:(void (^)(MuTapResultRemoteLink *))remoteLinkBlock
+{
+ externalLinkBlock(self);
+}
+
+@end
+
+
+@implementation MuTapResultRemoteLink
+
+@synthesize fileSpec, pageNumber, newWindow;
+
+-(id) initWithFileSpec:(NSString *)aString pageNumber:(int)aNumber newWindow:(BOOL)aBool
+{
+ self = [super init];
+ if (self)
+ {
+ fileSpec = [aString retain];
+ pageNumber = aNumber;
+ newWindow = aBool;
+ }
+ return self;
+}
+
+-(void) dealloc
+{
+ [fileSpec release];
+ [super dealloc];
+}
+
+-(void) switchCaseInternal:(void (^)(MuTapResultInternalLink *))internalLinkBlock caseExternal:(void (^)(MuTapResultExternalLink *))externalLinkBlock caseRemote:(void (^)(MuTapResultRemoteLink *))remoteLinkBlock
+{
+ remoteLinkBlock(self);
+}
+
+@end \ No newline at end of file