Fixed: <rdar://problem/3766915> PDF content needs search to work
authorcblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 19 Dec 2004 19:09:10 +0000 (19:09 +0000)
committercblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 19 Dec 2004 19:09:10 +0000 (19:09 +0000)
        Reviewed by kevin, john.

        * WebView.subproj/WebPDFView.m:
(-[WebPDFView searchFor:direction:caseSensitive:wrap:]): implemented
        (-[WebPDFView takeFindStringFromSelection:]): new
        (-[WebPDFView jumpToSelection:]): new
        (-[WebPDFView validateUserInterfaceItem:]): new

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8252 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/WebView.subproj/WebPDFView.m

index 7d9a2208025493288c2aed0b53a130061e35bae9..dc82eb59b1169bb66e722fddab6b18dd0e011ebb 100644 (file)
@@ -1,3 +1,15 @@
+2004-12-18  Chris Blumenberg  <cblu@apple.com>
+
+       Fixed: <rdar://problem/3766915> PDF content needs search to work
+
+        Reviewed by kevin, john.
+
+        * WebView.subproj/WebPDFView.m:
+       (-[WebPDFView searchFor:direction:caseSensitive:wrap:]): implemented
+        (-[WebPDFView takeFindStringFromSelection:]): new
+        (-[WebPDFView jumpToSelection:]): new
+        (-[WebPDFView validateUserInterfaceItem:]): new
+
 2004-12-17  Richard Williamson   <rjw@apple.com>
 
        Make image decoding as lazy as possible for non threaded case; in some cases
index cadd1d4a304b2aaeb4429bef4f0cc11d5b668ebf..0b9288a06d262bc9fc542adf77e5ccb52f41ed4d 100644 (file)
@@ -10,6 +10,7 @@
 #import <WebKit/WebAssertions.h>
 #import <WebKit/WebDataSource.h>
 #import <WebKit/WebLocalizableStrings.h>
+#import <WebKit/WebNSPasteboardExtras.h>
 #import <WebKit/WebPDFView.h>
 
 #import <Quartz/Quartz.h>
@@ -202,15 +203,46 @@ static void applicationInfoForMIMEType(NSString *type, NSString **name, NSImage
     }
 }
 
-- (BOOL)searchFor: (NSString *)string direction: (BOOL)forward caseSensitive: (BOOL)caseFlag wrap: (BOOL)wrapFlag;
+- (BOOL)searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag;
 {
-    BOOL lastFindWasSuccessful = NO;
-    
-    // FIXME:  Insert find code here when ready.
-    
-    return lastFindWasSuccessful;
+    int options = 0;
+    if (!forward) {
+        options |= NSBackwardsSearch;
+    }
+    if (!caseFlag) {
+        options |= NSCaseInsensitiveSearch;
+    }
+    PDFDocument *document = [PDFSubview document];
+    PDFSelection *selection = [document findString:string fromSelection:[PDFSubview currentSelection] withOptions:options];
+    if (selection == nil && wrapFlag) {
+        selection = [document findString:string fromSelection:nil withOptions:options];
+    }
+    if (selection != nil) {
+        [PDFSubview setCurrentSelection:selection];
+        [PDFSubview scrollSelectionToVisible:nil];
+        return YES;
+    }
+    return NO;
 }
 
+- (void)takeFindStringFromSelection:(id)sender
+{
+    [NSPasteboard _web_setFindPasteboardString:[[PDFSubview currentSelection] string] withOwner:self];
+}
+
+- (void)jumpToSelection:(id)sender
+{
+    [PDFSubview scrollSelectionToVisible:nil];
+}
+
+- (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item 
+{
+    SEL action = [item action];    
+    if (action == @selector(takeFindStringFromSelection:) || action == @selector(jumpToSelection:)) {
+        return [PDFSubview currentSelection] != nil;
+    }
+    return YES;
+}
 
 @end