Reviewed by Richard Williamson.
authorsullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Jul 2005 20:36:53 +0000 (20:36 +0000)
committersullivan <sullivan@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Jul 2005 20:36:53 +0000 (20:36 +0000)
        - fixed <rdar://problem/4184366> WebPDFView should conform to the WebDocumentSelection protocol

        * Misc.subproj/WebNSAttributedStringExtras.h: Added.
        * Misc.subproj/WebNSAttributedStringExtras.m: Added.
        (-[NSAttributedString _web_attributedStringByStrippingAttachmentCharacters]):
        New category on NSAttributedString, initially contains this one method that had been in WebHTMLView.

        * WebView.subproj/WebHTMLView.m:
        (-[WebHTMLView _writeSelectionWithPasteboardTypes:toPasteboard:cachedAttributedString:]):
        now uses _web_attributedStringByStrippingAttachmentCharacters

        * WebView.subproj/WebPDFView.h:
        now conforms to WebDocumentSelection protocol
        * WebView.subproj/WebPDFView.m:
        (-[WebPDFView selectionRect]):
        new, implementation of WebDocumentSelection protocol method
        (-[WebPDFView pasteboardTypesForSelection]):
        ditto
        (-[WebPDFView writeSelectionWithPasteboardTypes:toPasteboard:]):
        ditto

        * WebKit.pbproj/project.pbxproj:
        updated for new files

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

WebKit/ChangeLog
WebKit/Misc.subproj/WebNSAttributedStringExtras.h [new file with mode: 0644]
WebKit/Misc.subproj/WebNSAttributedStringExtras.m [new file with mode: 0644]
WebKit/WebKit.pbproj/project.pbxproj
WebKit/WebView.subproj/WebHTMLView.m
WebKit/WebView.subproj/WebPDFView.h
WebKit/WebView.subproj/WebPDFView.m

index 1eaf5e2..0ca28fc 100644 (file)
@@ -1,5 +1,33 @@
 2005-07-18  John Sullivan  <sullivan@apple.com>
 
+        Reviewed by Richard Williamson.
+        
+        - fixed <rdar://problem/4184366> WebPDFView should conform to the WebDocumentSelection protocol
+
+        * Misc.subproj/WebNSAttributedStringExtras.h: Added.
+        * Misc.subproj/WebNSAttributedStringExtras.m: Added.
+        (-[NSAttributedString _web_attributedStringByStrippingAttachmentCharacters]):
+        New category on NSAttributedString, initially contains this one method that had been in WebHTMLView.
+        
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView _writeSelectionWithPasteboardTypes:toPasteboard:cachedAttributedString:]):
+        now uses _web_attributedStringByStrippingAttachmentCharacters
+        
+        * WebView.subproj/WebPDFView.h:
+        now conforms to WebDocumentSelection protocol
+        * WebView.subproj/WebPDFView.m:
+        (-[WebPDFView selectionRect]):
+        new, implementation of WebDocumentSelection protocol method
+        (-[WebPDFView pasteboardTypesForSelection]):
+        ditto
+        (-[WebPDFView writeSelectionWithPasteboardTypes:toPasteboard:]):
+        ditto
+
+        * WebKit.pbproj/project.pbxproj:
+        updated for new files
+
+2005-07-18  John Sullivan  <sullivan@apple.com>
+
         Reviewed by Chris Blumenberg.
         
         - some refactoring cleanup in the selection/searching code
diff --git a/WebKit/Misc.subproj/WebNSAttributedStringExtras.h b/WebKit/Misc.subproj/WebNSAttributedStringExtras.h
new file mode 100644 (file)
index 0000000..733ec2b
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+    * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+@interface NSAttributedString (WebKitExtras)
+
+- (NSAttributedString *)_web_attributedStringByStrippingAttachmentCharacters;
+
+@end
diff --git a/WebKit/Misc.subproj/WebNSAttributedStringExtras.m b/WebKit/Misc.subproj/WebNSAttributedStringExtras.m
new file mode 100644 (file)
index 0000000..14cf192
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+    * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "WebNSAttributedStringExtras.h"
+
+
+@implementation NSAttributedString (WebKitExtras)
+
+- (NSAttributedString *)_web_attributedStringByStrippingAttachmentCharacters
+{
+    // This code was originally copied from NSTextView
+    NSRange attachmentRange;
+    NSString *originalString = [self string];
+    static NSString *attachmentCharString = nil;
+    
+    if (!attachmentCharString) {
+        unichar chars[2];
+        if (!attachmentCharString) {
+            chars[0] = NSAttachmentCharacter;
+            chars[1] = 0;
+            attachmentCharString = [[NSString alloc] initWithCharacters:chars length:1];
+        }
+    }
+    
+    attachmentRange = [originalString rangeOfString:attachmentCharString];
+    if (attachmentRange.location != NSNotFound && attachmentRange.length > 0) {
+        NSMutableAttributedString *newAttributedString = [[self mutableCopyWithZone:NULL] autorelease];
+        
+        while (attachmentRange.location != NSNotFound && attachmentRange.length > 0) {
+            [newAttributedString replaceCharactersInRange:attachmentRange withString:@""];
+            attachmentRange = [[newAttributedString string] rangeOfString:attachmentCharString];
+        }
+        return newAttributedString;
+    }
+    
+    return self;
+}
+
+@end
index ceb8e59..4254398 100644 (file)
                                BEE52D4B0473032500CA289C,
                                BEE18F990472B73200CA289C,
                                BEE18F9A0472B73200CA289C,
+                               ED6BE2E5088C32B50044DEDC,
+                               ED6BE2E6088C32B50044DEDC,
                                9345DDB20365FFD0008635CE,
                                9345DDB30365FFD0008635CE,
                                65EEDE51084FFB920002DB25,
                                65EEDE57084FFC9E0002DB25,
                                65E0F88408500917007E5CB9,
                                65E0F9E608500F23007E5CB9,
+                               ED6BE2E7088C32B50044DEDC,
                        );
                        isa = PBXHeadersBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
                                65EEDE58084FFC9E0002DB25,
                                65E0F88508500917007E5CB9,
                                65E0F9E708500F23007E5CB9,
+                               ED6BE2E8088C32B50044DEDC,
                        );
                        isa = PBXSourcesBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
                        refType = 4;
                        sourceTree = "<group>";
                };
+               ED6BE2E5088C32B50044DEDC = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
+                       path = WebNSAttributedStringExtras.h;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               ED6BE2E6088C32B50044DEDC = {
+                       fileEncoding = 30;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = WebNSAttributedStringExtras.m;
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               ED6BE2E7088C32B50044DEDC = {
+                       fileRef = ED6BE2E5088C32B50044DEDC;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
+               ED6BE2E8088C32B50044DEDC = {
+                       fileRef = ED6BE2E6088C32B50044DEDC;
+                       isa = PBXBuildFile;
+                       settings = {
+                       };
+               };
                EDD1A5C605C83987008E3150 = {
                        fileEncoding = 4;
                        isa = PBXFileReference;
index 529819b..a196e6b 100644 (file)
@@ -48,6 +48,7 @@
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebKitNSStringExtras.h>
 #import <WebKit/WebNetscapePluginEmbeddedView.h>
+#import <WebKit/WebNSAttributedStringExtras.h>
 #import <WebKit/WebNSEventExtras.h>
 #import <WebKit/WebNSFileManagerExtras.h>
 #import <WebKit/WebNSImageExtras.h>
@@ -573,36 +574,6 @@ void *_NSSoftLinkingGetFrameworkFuncPtr(NSString *inUmbrellaFrameworkName,
     return hitView;
 }
 
-// This method is copied from NSTextView
-- (NSAttributedString *)_stripAttachmentCharactersFromAttributedString:(NSAttributedString *)originalAttributedString
-{
-    NSRange attachmentRange;
-    NSString *originalString = [originalAttributedString string];
-    static NSString *attachmentCharString = nil;
-    
-    if (!attachmentCharString) {
-        unichar chars[2];
-        if (!attachmentCharString) {
-            chars[0] = NSAttachmentCharacter;
-            chars[1] = 0;
-            attachmentCharString = [[NSString alloc] initWithCharacters:chars length:1];
-        }
-    }
-    
-    attachmentRange = [originalString rangeOfString:attachmentCharString];
-    if (attachmentRange.location != NSNotFound && attachmentRange.length > 0) {
-        NSMutableAttributedString *newAttributedString = [[originalAttributedString mutableCopyWithZone:NULL] autorelease];
-        
-        while (attachmentRange.location != NSNotFound && attachmentRange.length > 0) {
-            [newAttributedString replaceCharactersInRange:attachmentRange withString:@""];
-            attachmentRange = [[newAttributedString string] rangeOfString:attachmentCharString];
-        }
-        return newAttributedString;
-    } else {
-        return originalAttributedString;
-    }
-}
-
 - (void)_writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard cachedAttributedString:(NSAttributedString *)attributedString
 {
     // Put HTML on the pasteboard.
@@ -624,7 +595,7 @@ void *_NSSoftLinkingGetFrameworkFuncPtr(NSString *inUmbrellaFrameworkName,
             attributedString = [self selectedAttributedString];
         }
         if ([attributedString containsAttachments]) {
-            attributedString = [self _stripAttachmentCharactersFromAttributedString:attributedString];
+            attributedString = [attributedString _web_attributedStringByStrippingAttachmentCharacters];
         }
         NSData *RTFData = [attributedString RTFFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil];
         [pasteboard setData:RTFData forType:NSRTFPboardType];
index 8ffcea2..1360efa 100644 (file)
@@ -32,8 +32,9 @@
 @class WebDataSource;
 
 @protocol _web_WebDocumentTextSizing;
+@protocol WebDocumentSelection;
 
-@interface WebPDFView : NSView <WebDocumentView, WebDocumentSearching, WebDocumentText, _web_WebDocumentTextSizing>
+@interface WebPDFView : NSView <WebDocumentView, WebDocumentSearching, WebDocumentText, _web_WebDocumentTextSizing, WebDocumentSelection>
 {
     PDFView *PDFSubview;
     WebDataSource *dataSource;
index fa23dbb..6f2dcb0 100644 (file)
 #import <WebKit/WebAssertions.h>
 #import <WebKit/WebDataSource.h>
 #import <WebKit/WebDocumentInternal.h>
+#import <WebKit/WebDocumentPrivate.h>
 #import <WebKit/WebFrame.h>
 #import <WebKit/WebFrameInternal.h>
 #import <WebKit/WebFrameView.h>
 #import <WebKit/WebLocalizableStrings.h>
+#import <WebKit/WebNSAttributedStringExtras.h>
 #import <WebKit/WebNSPasteboardExtras.h>
 #import <WebKit/WebNSViewExtras.h>
 #import <WebKit/WebPDFView.h>
@@ -554,6 +556,51 @@ static BOOL PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *select
     [PDFSubview clearSelection];
 }
 
+- (NSRect)selectionRect
+{
+    NSRect result = NSZeroRect;
+    PDFSelection *selection = [PDFSubview currentSelection];
+    NSEnumerator *pages = [[selection pages] objectEnumerator];
+    PDFPage *page;
+    while ((page = [pages nextObject]) != nil) {
+        NSRect selectionOnPageInViewCoordinates = [PDFSubview convertRect:[selection boundsForPage:page] fromPage:page];
+        if (NSIsEmptyRect(result)) {
+            result = selectionOnPageInViewCoordinates;
+        } else {
+            result = NSUnionRect(result, selectionOnPageInViewCoordinates);
+        }
+    }
+    
+    return result;
+}
+
+- (NSArray *)pasteboardTypesForSelection
+{
+    return [NSArray arrayWithObjects:NSRTFDPboardType, NSRTFPboardType, NSStringPboardType, nil];
+}
+
+- (void)writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard
+{
+    NSAttributedString *attributedString = [self selectedAttributedString];
+    
+    if ([types containsObject:NSRTFDPboardType]) {
+        NSData *RTFDData = [attributedString RTFDFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil];
+        [pasteboard setData:RTFDData forType:NSRTFDPboardType];
+    }        
+    
+    if ([types containsObject:NSRTFPboardType]) {
+        if ([attributedString containsAttachments]) {
+            attributedString = [attributedString _web_attributedStringByStrippingAttachmentCharacters];
+        }
+        NSData *RTFData = [attributedString RTFFromRange:NSMakeRange(0, [attributedString length]) documentAttributes:nil];
+        [pasteboard setData:RTFData forType:NSRTFPboardType];
+    }
+    
+    if ([types containsObject:NSStringPboardType]) {
+        [pasteboard setString:[self selectedString] forType:NSStringPboardType];
+    }
+}
+
 @end
 
 #endif // OMIT_TIGER_FEATURES