1/* 2 * Copyright (C) 2006, 2007, 2008, 2010, 2011 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#import <WebKitLegacy/WebDocumentPrivate.h> 27 28#if TARGET_OS_IPHONE 29 30@class UIColor; 31@class UIPDFDocument; 32@protocol WebPDFViewPlaceholderDelegate; 33 34/*! 35 @class WebPDFViewPlaceholder 36 @discussion This class represents a placeholder for PDFs. It is intended to allow main frame PDFs 37 be drawn to the UI by some other object (ideally the delegate of this class) while still interfacing 38 with WAK and WebKit correctly. 39*/ 40@interface WebPDFViewPlaceholder : WAKView <WebPDFDocumentView, WebPDFDocumentRepresentation> { 41 NSString *_title; 42 NSArray *_pageRects; 43 NSArray *_pageYOrigins; 44 CGPDFDocumentRef _document; 45 WebDataSource *_dataSource; // weak to prevent cycles. 46 47 NSObject<WebPDFViewPlaceholderDelegate> *_delegate; 48 49 BOOL _didFinishLoadAndMemoryMap; 50 51 CGSize _containerSize; 52} 53 54/*! 55 @method setAsPDFDocRepAndView 56 @abstract This methods sets [WebPDFViewPlaceholder class] as the document and view representations 57 for PDF. 58*/ 59+ (void)setAsPDFDocRepAndView; 60 61 62/*! 63 @property delegate 64 @abstract A delegate object conforming to WebPDFViewPlaceholderDelegate that will be informed about various state changes. 65 */ 66@property (assign) NSObject<WebPDFViewPlaceholderDelegate> *delegate; 67 68/*! 69 @property pageRects 70 @abstract An array of CGRects (as NSValues) representing the bounds of each page in PDF document coordinate space. 71 */ 72@property (readonly, retain) NSArray *pageRects; 73 74/*! 75 @property pageYOrigins 76 @abstract An array of CGFloats (as NSNumbers) representing the minimum y for every page in the document. 77 */ 78@property (readonly, retain) NSArray *pageYOrigins; 79 80/*! 81 @property document 82 @abstract The CGPDFDocumentRef that this object represents. Until the document has loaded, this property will be NULL. 83 */ 84@property (readonly) CGPDFDocumentRef document; 85@property (readonly) CGPDFDocumentRef doc; 86 87/*! 88 @property totalPages 89 @abstract Convenience access for the total number of pages in the wrapped document. 90 */ 91@property (readonly) NSUInteger totalPages; 92 93/*! 94 @property title 95 @abstract PDFs support a meta data field for the document's title. If this field is present in the PDF, title will be that string. 96 If not, title will be the file name. 97 */ 98@property (readonly, retain) NSString *title; 99 100/*! 101 @property containerSize 102 @abstract sets the size for the containing view. This is used to determine how big the shadows between pages should be. 103 */ 104@property (assign) CGSize containerSize; 105 106@property (nonatomic, readonly) BOOL didCompleteLayout; 107 108- (void)clearDocument; 109 110/*! 111 @method didUnlockDocument 112 @abstract Informs the PDF view placeholder that the PDF document has been unlocked. The result of this involves laying 113 out the pages, retaining the document title, and re-evaluating the document's javascript. This should be called on the WebThread. 114 */ 115- (void)didUnlockDocument; 116 117/*! 118 @method rectForPageNumber 119 @abstract Returns the PDF document coordinate space rect given a page number. pageNumber must be in the range [1,totalPages], 120 since page numbers are 1-based. 121 */ 122- (CGRect)rectForPageNumber:(NSUInteger)pageNumber; 123 124/*! 125 @method simulateClickOnLinkToURL: 126 @abstract This method simulates a user clicking on the passed in URL. 127 */ 128- (void)simulateClickOnLinkToURL:(NSURL *)URL; 129 130@end 131 132 133/*! 134 @protocol WebPDFViewPlaceholderDelegate 135 @discussion This protocol is used to inform the object using the placeholder that the layout for the 136 document has been calculated. 137*/ 138@protocol WebPDFViewPlaceholderDelegate 139 140@optional 141 142/*! 143 @method viewWillClose 144 @abstract This method is called to inform the delegate that the placeholder view's lifetime has ended. This might 145 be called from either the main thread or the WebThread. 146 */ 147- (void)viewWillClose; 148 149/*! 150 @method didCompleteLayout 151 @abstract This method is called to inform the delegate that the placeholder has completed layout 152 and determined the document's bounds. Will always be called on the main thread. 153*/ 154- (void)didCompleteLayout; 155 156@required 157 158/*! 159 @method cgPDFDocument 160 @abstract The WebPDFViewPlaceholder may have abdicated responsibility for the underlying CGPDFDocument to the WebPDFViewPlaceholderDelegate. 161 That means that there may be times when the document is needed, but the WebPDFViewPlaceholder no longer has a reference to it. In which case 162 the WebPDFViewPlaceholderDelegate will be asked for the document. 163 */ 164- (CGPDFDocumentRef)cgPDFDocument; 165 166- (void)setBackgroundColor:(UIColor *)backgroundColor; 167 168@end 169 170#endif /* TARGET_OS_IPHONE */ 171