Fixed: <rdar://problem/3948862> REGRESSION: missing images when RTFD is pasted into...
authorcblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Jan 2005 21:25:03 +0000 (21:25 +0000)
committercblu <cblu@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Jan 2005 21:25:03 +0000 (21:25 +0000)
This problem occurred because we were creating image elements before creating corresponding image resources. The fix is to have AppKit call us back to create the resources before it creates the elements.

        Reviewed by john.

        * WebView.subproj/WebHTMLView.m:
        (-[WebHTMLView _documentFragmentFromPasteboard:allowPlainText:]): don't deal with subresources since that's now done by the following method
        (-[WebHTMLView resourceForData:preferredFilename:]): new handler method called by AppKit

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

WebKit/ChangeLog
WebKit/WebView.subproj/WebHTMLView.m

index fa12c62e2f5d058325123f65b62ba57445177c22..d17c3e1d69ecc624e1d06aa4ddc260c75a7267c7 100644 (file)
@@ -1,3 +1,15 @@
+2005-01-10  Chris Blumenberg  <cblu@apple.com>
+
+       Fixed: <rdar://problem/3948862> REGRESSION: missing images when RTFD is pasted into editable WebView
+
+       This problem occurred because we were creating image elements before creating corresponding image resources. The fix is to have AppKit call us back to create the resources before it creates the elements.
+
+        Reviewed by john.
+
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView _documentFragmentFromPasteboard:allowPlainText:]): don't deal with subresources since that's now done by the following method
+        (-[WebHTMLView resourceForData:preferredFilename:]): new handler method called by AppKit
+
 === Safari-178 ===
 
 2005-01-06  David Harrison  <harrison@apple.com>
index a392c484c3b8cd565a68042bba5e60d13b07d433..71a6a8565ef26c5f9d877becb43c3c5412c16275 100644 (file)
@@ -328,8 +328,12 @@ static BOOL forceRealHitTest = NO;
         string = [[NSAttributedString alloc] initWithRTF:[pasteboard dataForType:NSRTFPboardType] documentAttributes:NULL];
     }
     if (string != nil) {
-        NSArray *elements = [[NSArray alloc] initWithObjects:@"style", nil];
-        NSDictionary *documentAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:elements, NSExcludedElementsDocumentAttribute, nil];
+        NSArray *elements = [[NSArray alloc] initWithObjects:
+            // Omit style since we want style to be inline so the fragment can be easily inserted.
+            @"style", nil];
+        NSDictionary *documentAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
+            elements, NSExcludedElementsDocumentAttribute,
+            self, @"WebResourceHandler", nil];
         [elements release];
         NSArray *subresources;
         DOMDocumentFragment *fragment = [string _documentFromRange:NSMakeRange(0, [string length]) 
@@ -338,12 +342,7 @@ static BOOL forceRealHitTest = NO;
                                                       subresources:&subresources];
         [documentAttributes release];
         [string release];
-        if (fragment) {
-            if ([subresources count] != 0) {
-                [[self _dataSource] _addSubresources:subresources];
-            }
-            return fragment;
-        }
+        return fragment;
     }
 #endif
     
@@ -361,6 +360,31 @@ static BOOL forceRealHitTest = NO;
     return nil;
 }
 
+#ifdef USE_APPKIT_FOR_ATTRIBUTED_STRINGS
+- (WebResource *)resourceForData:(NSData *)data preferredFilename:(NSString *)name
+{
+    // This method is called by [NSAttributedString _documentFromRange::::] 
+    // which uses the URL of the resource for the fragment that it returns.
+    NSString *extension = [name pathExtension];
+    NSString *MIMEType = nil;
+    if ([extension length] != 0) {
+        MIMEType = [[NSURLFileTypeMappings sharedMappings] MIMETypeForExtension:extension];
+    }
+    // Only support image resources.
+    if (MIMEType == nil || ![[[WebImageRendererFactory sharedFactory] supportedMIMETypes] containsObject:MIMEType]) {
+        return nil;
+    }
+    NSURL *URL = [NSURL _web_URLWithUserTypedString:[NSString stringWithFormat:@"/%@", name] relativeToURL:[NSURL _web_uniqueWebDataURL]];
+    WebResource *resource = [[[WebResource alloc] initWithData:data
+                                                           URL:URL
+                                                      MIMEType:MIMEType 
+                                              textEncodingName:nil
+                                                     frameName:nil] autorelease];
+    [[self _dataSource] addSubresource:resource];
+    return resource;
+}
+#endif
+
 - (void)_pasteWithPasteboard:(NSPasteboard *)pasteboard allowPlainText:(BOOL)allowPlainText
 {
     DOMDocumentFragment *fragment = [self _documentFragmentFromPasteboard:pasteboard allowPlainText:allowPlainText];