First cut at dirt simple PDF support. This feature
authorrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Aug 2004 00:30:27 +0000 (00:30 +0000)
committerrjw <rjw@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Aug 2004 00:30:27 +0000 (00:30 +0000)
        depends on Quartz.framework (parent of PDFKit), which only exists
        on Tiger.  So, we "weak" link against Quartz.

        We do very basic PDF rendering.  Coming up are support for
        "Find..." and linearized PDF (incremental).  Linearized PDF
        support will require API changes in PDFKit.

        No UI is added to Safari, yet.

        Reviewed by John.

        * WebKit.pbproj/project.pbxproj:
        * WebView.subproj/WebDataSource.m:
        (+[WebDataSource _repTypesAllowImageTypeOmission:]):
        * WebView.subproj/WebFrameView.m:
        (+[WebFrameView _viewTypesAllowImageTypeOmission:]):
        * WebView.subproj/WebPDFRepresentation.h: Added.
        * WebView.subproj/WebPDFRepresentation.m: Added.
        (-[WebPDFRepresentation finishedLoadingWithDataSource:]):
        (-[WebPDFRepresentation canProvideDocumentSource]):
        (-[WebPDFRepresentation documentSource]):
        (-[WebPDFRepresentation title]):
        * WebView.subproj/WebPDFView.h: Added.
        * WebView.subproj/WebPDFView.m: Added.
        (-[WebPDFView initWithFrame:]):
        (-[WebPDFView setDataSource:]):
        (-[WebPDFView dataSourceUpdated:]):
        (-[WebPDFView setNeedsLayout:]):
        (-[WebPDFView layout]):
        (-[WebPDFView viewWillMoveToHostWindow:]):
        (-[WebPDFView viewDidMoveToHostWindow]):

        Copied fix from Jaguar carbon/cocoa work.

        Reviewed by Darin (Jaguar version)

        * Carbon.subproj/CarbonWindowAdapter.h:
        * Carbon.subproj/CarbonWindowAdapter.m:
        (-[CarbonWindowAdapter relinquishFocus]):
        * Carbon.subproj/HIWebView.m:
        (Click):
        (OwningWindowChanged):
        (WindowHandler):

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

WebKit/Carbon.subproj/CarbonWindowAdapter.h
WebKit/Carbon.subproj/CarbonWindowAdapter.m
WebKit/Carbon.subproj/HIWebView.m
WebKit/ChangeLog
WebKit/WebKit.pbproj/project.pbxproj
WebKit/WebView.subproj/WebDataSource.m
WebKit/WebView.subproj/WebFrameView.m
WebKit/WebView.subproj/WebPDFRepresentation.h [new file with mode: 0644]
WebKit/WebView.subproj/WebPDFRepresentation.m [new file with mode: 0644]
WebKit/WebView.subproj/WebPDFView.h [new file with mode: 0644]
WebKit/WebView.subproj/WebPDFView.m [new file with mode: 0644]

index bb5dc9743d4e6b5a1ccdb1842c525faaf7503671..1f0dae671230177eb3802302675c5fe972bdaa16 100644 (file)
@@ -41,5 +41,6 @@
 // Handle an event just like an NSWindow would.
 - (void)sendSuperEvent:(NSEvent *)inEvent;
 
+- (void)relinquishFocus;
 
 @end
index ceab8c5e42a7dbd2172bb1d9f0d950e720333844..3e59f37a172120c1cb8f07fa039a663bd1cf9b48 100644 (file)
@@ -408,6 +408,20 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
     if (!ignoreEvent) [super sendEvent:inEvent];
 }
 
+- (void)relinquishFocus
+{
+    NSResponder*  firstResponder;
+
+    // Carbon thinks that a control has the keyboard focus,
+    // or we wouldn't be being asked to relinquish focus.
+
+       firstResponder = [self firstResponder];
+       if ([firstResponder isKindOfClass:[NSView class]] ){
+               // Make the window the first responder, so that no view is the key view.
+        [self makeFirstResponder:self];
+    }
+}
+
 - (BOOL)makeFirstResponder:(NSResponder *)aResponder
 {
     // Let NSWindow focus the appropriate NSView.
index 84dd168b380374424a02594b344c5d1c57a2af5b..ec5d8c857cde4f978d08768e26308a32db502e48 100644 (file)
@@ -487,7 +487,10 @@ Click( HIWebView* inView, EventRef inEvent )
        UInt32                                  modifiers;
        Rect                                    windRect;
        
-       GetEventPlatformEventRecord( inEvent, &eventRec );
+       if (!GetEventPlatformEventRecord( inEvent, &eventRec )) {
+            NSLog (@"Unable to get platform event");
+            require_noerr( err, CantAllocNewEvent );
+        }
 
        // We need to make the event be a kEventMouseDown event, or the webkit might trip up when
        // we click on a Netscape plugin. It calls ConvertEventRefToEventRecord, assuming
@@ -721,7 +724,8 @@ OwningWindowChanged(
             { kEventClassMouse, kEventMouseWheelMoved },
             { kEventClassKeyboard, kEventRawKeyDown },
             { kEventClassKeyboard, kEventRawKeyRepeat },
-            { kEventClassKeyboard, kEventRawKeyUp }
+            { kEventClassKeyboard, kEventRawKeyUp },
+            { kEventClassControl, kEventControlClick },
             };
             
             view->fKitWindow = [[CarbonWindowAdapter alloc] initWithCarbonWindowRef: newWindow takingOwnership: NO disableOrdering:NO carbon:YES];
@@ -762,6 +766,25 @@ WindowHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData
 
     switch( GetEventClass( inEvent ) )
     {
+       case kEventClassControl:
+            {
+            switch( GetEventKind( inEvent ) )
+            {
+                case kEventControlClick:
+                    {
+                        CarbonWindowAdapter *kitWindow;
+                        OSStatus err;
+                        
+                        err = GetWindowProperty( window, NSAppKitPropertyCreator, NSCarbonWindowPropertyTag, sizeof(NSWindow *), NULL, &kitWindow);
+                        
+                        // We must be outside the HIWebView, relinquish focus.
+                        [kitWindow relinquishFocus];
+                    }
+                    break;
+                }
+            }
+            break;
+            
        case kEventClassKeyboard:
                {
                 NSWindow*              kitWindow;
index a482aef1a93968b3cab9fb7e7f5852256d15acf6..ec2865459a28092cb1d02b1f5051723c2d6d96e2 100644 (file)
@@ -1,3 +1,50 @@
+2004-08-03  Richard Williamson   <rjw@apple.com>
+
+        First cut at dirt simple PDF support.  This feature
+        depends on Quartz.framework (parent of PDFKit), which only exists
+        on Tiger.  So, we "weak" link against Quartz.
+               
+        We do very basic PDF rendering.  Coming up are support for
+        "Find..." and linearized PDF (incremental).  Linearized PDF 
+        support will require API changes in PDFKit.
+               
+        No UI is added to Safari, yet.
+               
+        Reviewed by John.
+
+        * WebKit.pbproj/project.pbxproj:
+        * WebView.subproj/WebDataSource.m:
+        (+[WebDataSource _repTypesAllowImageTypeOmission:]):
+        * WebView.subproj/WebFrameView.m:
+        (+[WebFrameView _viewTypesAllowImageTypeOmission:]):
+        * WebView.subproj/WebPDFRepresentation.h: Added.
+        * WebView.subproj/WebPDFRepresentation.m: Added.
+        (-[WebPDFRepresentation finishedLoadingWithDataSource:]):
+        (-[WebPDFRepresentation canProvideDocumentSource]):
+        (-[WebPDFRepresentation documentSource]):
+        (-[WebPDFRepresentation title]):
+        * WebView.subproj/WebPDFView.h: Added.
+        * WebView.subproj/WebPDFView.m: Added.
+        (-[WebPDFView initWithFrame:]):
+        (-[WebPDFView setDataSource:]):
+        (-[WebPDFView dataSourceUpdated:]):
+        (-[WebPDFView setNeedsLayout:]):
+        (-[WebPDFView layout]):
+        (-[WebPDFView viewWillMoveToHostWindow:]):
+        (-[WebPDFView viewDidMoveToHostWindow]):
+
+        Copied fix from Jaguar carbon/cocoa work.
+               
+        Reviewed by Darin (Jaguar version)
+
+        * Carbon.subproj/CarbonWindowAdapter.h:
+        * Carbon.subproj/CarbonWindowAdapter.m:
+        (-[CarbonWindowAdapter relinquishFocus]):
+        * Carbon.subproj/HIWebView.m:
+        (Click):
+        (OwningWindowChanged):
+        (WindowHandler):
+
 2004-08-03  David Hyatt  <hyatt@apple.com>
 
        Add the text/xsl MIME type as one that can be displayed.
index 7100ea9a85b81f57d8aec003072a5663708c9454..8571a4d487a208ef16a02bffff8b95854960d45b 100644 (file)
                                6566F34204C12D14008B3232,
                        );
                        buildSettings = {
-                               COMMON_LDFLAGS = "-no-c++filt \"$OBJECT_FILE_DIR/WebKitSecurity.a\"";
+                               COMMON_LDFLAGS = "-no-c++filt \"$OBJECT_FILE_DIR/WebKitSecurity.a\" -weak_framework Quartz";
                                COPY_PHASE_STRIP = NO;
                                DEBUG_CFLAGS = "-DNDEBUG";
                                DYLIB_COMPATIBILITY_VERSION = 1;
                                DYLIB_CURRENT_VERSION = 1;
                                EXPORTED_SYMBOLS_FILE = WebKit.exp;
-                               FRAMEWORK_SEARCH_PATHS = "\"${DSTROOT}\" \"${MERGE_DIR}/${SYSTEM_LIBRARY_DIR}/Frameworks\" \"${MERGE_DIR}/$(SYSTEM_LIBRARY_DIR)/Frameworks/WebKit.framework/Frameworks\" \"$(SYSTEM_LIBRARY_DIR)/Frameworks/WebKit.framework/Frameworks\" \"$(SYSTEM_LIBRARY_DIR)/Frameworks/ApplicationServices.framework/Frameworks\" \"$(SYSTEM_LIBRARY_DIR)/Frameworks/Carbon.framework/Frameworks\" \"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\"";
+                               FRAMEWORK_SEARCH_PATHS = "\"${DSTROOT}\" \"${MERGE_DIR}/${SYSTEM_LIBRARY_DIR}/Frameworks\" \"${MERGE_DIR}/$(SYSTEM_LIBRARY_DIR)/Frameworks/WebKit.framework/Frameworks\" \"$(SYSTEM_LIBRARY_DIR)/Frameworks/WebKit.framework/Frameworks\" \"$(SYSTEM_LIBRARY_DIR)/Frameworks/ApplicationServices.framework/Frameworks\" \"$(SYSTEM_LIBRARY_DIR)/Frameworks/Carbon.framework/Frameworks\" \"$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks\" ";
                                FRAMEWORK_VERSION = A;
                                HEADER_SEARCH_PATHS = "";
                                INSTALL_PATH = /System/Library/Frameworks;
                                93185DB606679F42005D5E7E,
                                93D1FE14067EB10B009CE68A,
                                9348903806C0040B007E7ACE,
+                               51E94C3606C0321200A9B09E,
+                               51E94C6A06C0347500A9B09E,
                        );
                        isa = PBXHeadersBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
                                BE95BEE705FD0805006E1513,
                                846171FC0624AE5B0071A4A3,
                                8373435D0624EE0D00F3B289,
+                               51E94C3706C0321200A9B09E,
+                               51E94C6B06C0347500A9B09E,
                        );
                        isa = PBXSourcesBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
                                );
                        };
                };
+               51E94C0706C02CA300A9B09E = {
+                       children = (
+                               51E94C6806C0347500A9B09E,
+                               51E94C6906C0347500A9B09E,
+                               51E94C3406C0321200A9B09E,
+                               51E94C3506C0321200A9B09E,
+                       );
+                       isa = PBXGroup;
+                       name = PDF;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               51E94C3406C0321200A9B09E = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
+                       path = WebPDFView.h;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               51E94C3506C0321200A9B09E = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = WebPDFView.m;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               51E94C3606C0321200A9B09E = {
+                       fileRef = 51E94C3406C0321200A9B09E;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
+               51E94C3706C0321200A9B09E = {
+                       fileRef = 51E94C3506C0321200A9B09E;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
+               51E94C6806C0347500A9B09E = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
+                       path = WebPDFRepresentation.h;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               51E94C6906C0347500A9B09E = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = WebPDFRepresentation.m;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               51E94C6A06C0347500A9B09E = {
+                       fileRef = 51E94C6806C0347500A9B09E;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
+               51E94C6B06C0347500A9B09E = {
+                       fileRef = 51E94C6906C0347500A9B09E;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
                51F6866C0366057300CA2D3A = {
                        fileEncoding = 30;
                        isa = PBXFileReference;
                        children = (
                                F52CA6BD02DF9D0F018635CA,
                                F52CA6BE02DF9D49018635CA,
+                               51E94C0706C02CA300A9B09E,
                                F52CA6BF02DF9D4D018635CA,
                                8373435A0624EE0D00F3B289,
                                8373435B0624EE0D00F3B289,
index ef4191ccddb5e9d3b35692b323f7c76fe7f12ee6..52cee846d42c3d9f577be8a96ec1bb51e91f6ae0 100644 (file)
 #import <WebKit/WebMainResourceClient.h>
 #import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSURLExtras.h>
+// Assume we'll only ever compile this on Panther or greater, so 
+// MAC_OS_X_VERSION_10_3 is guranateed to be defined.
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3
+#import <WebKit/WebPDFRepresentation.h>
+#endif
 #import <WebKit/WebResourceLoadDelegate.h>
 #import <WebKit/WebResourcePrivate.h>
 #import <WebKit/WebTextRepresentation.h>
             [WebHTMLRepresentation class], @"application/x-webarchive",
             [WebTextRepresentation class], @"text/",
             [WebTextRepresentation class], @"application/x-javascript",
+// Assume we'll only ever compile this on Panther or greater, so 
+// MAC_OS_X_VERSION_10_3 is guranateed to be defined.
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3
+            [WebPDFRepresentation class], @"application/pdf",
+#endif
             nil];
     }
     
index 7895557474c1c5e7afc57fcc8d1bce954d0f69a4..318d6e92c2333339734ddd3ccd9761a966898a56 100644 (file)
 #import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSPasteboardExtras.h>
 #import <WebKit/WebNSViewExtras.h>
+// Assume we'll only ever compile this on Panther or greater, so 
+// MAC_OS_X_VERSION_10_3 is guranateed to be defined.
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3
+#import <WebKit/WebPDFView.h>
+#endif
 #import <WebKit/WebTextRendererFactory.h>
 #import <WebKit/WebTextView.h>
 #import <WebKit/WebViewFactory.h>
@@ -296,6 +301,11 @@ static NSMutableDictionary *viewTypes;
             [WebHTMLView class], @"application/x-webarchive",
             [WebTextView class], @"text/",
             [WebTextView class], @"application/x-javascript",
+// Assume we'll only ever compile this on Panther or greater, so 
+// MAC_OS_X_VERSION_10_3 is guranateed to be defined.
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3
+            [WebPDFView class], @"application/pdf",
+#endif
             nil];
     }
 
diff --git a/WebKit/WebView.subproj/WebPDFRepresentation.h b/WebKit/WebView.subproj/WebPDFRepresentation.h
new file mode 100644 (file)
index 0000000..6796e67
--- /dev/null
@@ -0,0 +1,18 @@
+/*     
+    WebPDFRepresentation.h
+    Copyright 2004, Apple, Inc. All rights reserved.
+*/
+// Assume we'll only ever compile this on Panther or greater, so 
+// MAC_OS_X_VERSION_10_3 is guaranateed to be defined.
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3
+
+#import <Foundation/Foundation.h>
+
+@protocol WebDocumentRepresentation;
+
+@interface WebPDFRepresentation : NSObject <WebDocumentRepresentation>
+{
+}
+@end
+
+#endif  // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3
diff --git a/WebKit/WebView.subproj/WebPDFRepresentation.m b/WebKit/WebView.subproj/WebPDFRepresentation.m
new file mode 100644 (file)
index 0000000..dc6003d
--- /dev/null
@@ -0,0 +1,59 @@
+/*     
+    WebPDFRepresentation.m
+    Copyright 2004, Apple, Inc. All rights reserved.
+*/
+// Assume we'll only ever compile this on Panther or greater, so 
+// MAC_OS_X_VERSION_10_3 is guaranateed to be defined.
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3
+
+#import <Quartz/Quartz.h>
+
+#import <WebKit/WebDataSource.h>
+#import <WebKit/WebFrame.h>
+#import <WebKit/WebFrameView.h>
+#import <WebKit/WebPDFRepresentation.h>
+#import <WebKit/WebPDFView.h>
+
+@implementation WebPDFRepresentation
+
+- (void)setDataSource:(WebDataSource *)dataSource;
+{
+}
+
+- (void)receivedData:(NSData *)data withDataSource:(WebDataSource *)dataSource;
+{
+}
+
+- (void)receivedError:(NSError *)error withDataSource:(WebDataSource *)dataSource;
+{
+}
+
+- (void)finishedLoadingWithDataSource:(WebDataSource *)dataSource
+{
+    WebPDFView *view = (WebPDFView *)[[[dataSource webFrame] frameView] documentView];
+    PDFDocument *doc = [[PDFDocument alloc] initWithData:[dataSource data]];
+    [view setDocument:doc];
+    [doc release];
+}
+
+
+- (BOOL)canProvideDocumentSource
+{
+    return NO;
+}
+
+
+- (NSString *)documentSource
+{
+    return nil;
+}
+
+
+- (NSString *)title
+{
+    return nil;
+}
+
+@end
+
+#endif
diff --git a/WebKit/WebView.subproj/WebPDFView.h b/WebKit/WebView.subproj/WebPDFView.h
new file mode 100644 (file)
index 0000000..8bea5df
--- /dev/null
@@ -0,0 +1,14 @@
+/*     
+    WebPDFView.h
+    Copyright 2004, Apple, Inc. All rights reserved.
+*/
+// Assume we'll only ever compile this on Panther or greater, so 
+// MAC_OS_X_VERSION_10_3 is guaranateed to be defined.
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3
+
+#import <Quartz/Quartz.h>
+
+@interface WebPDFView : PDFView <WebDocumentView>
+@end
+
+#endif  // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3
diff --git a/WebKit/WebView.subproj/WebPDFView.m b/WebKit/WebView.subproj/WebPDFView.m
new file mode 100644 (file)
index 0000000..90bdbd6
--- /dev/null
@@ -0,0 +1,50 @@
+/*     
+    WebPDFView.m
+    Copyright 2004, Apple, Inc. All rights reserved.
+*/
+// Assume we'll only ever compile this on Panther or greater, so 
+// MAC_OS_X_VERSION_10_3 is guaranateed to be defined.
+#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3
+
+#import <WebKit/WebDataSource.h>
+#import <WebKit/WebPDFView.h>
+
+@implementation WebPDFView
+
+- (id)initWithFrame:(NSRect)frame
+{
+    self = [super initWithFrame:frame];
+    if (self) {
+        [self setAutoresizingMask:NSViewWidthSizable];
+    }
+    return self;
+}
+
+- (void)setDataSource:(WebDataSource *)dataSource
+{
+}
+
+- (void)dataSourceUpdated:(WebDataSource *)dataSource
+{
+}
+
+- (void)setNeedsLayout:(BOOL)flag
+{
+}
+
+- (void)layout
+{
+    [self setFrame:[[self superview] frame]];
+}
+
+- (void)viewWillMoveToHostWindow:(NSWindow *)hostWindow
+{
+}
+
+- (void)viewDidMoveToHostWindow
+{
+}
+
+@end
+
+#endif //MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_3