+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>
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])
subresources:&subresources];
[documentAttributes release];
[string release];
- if (fragment) {
- if ([subresources count] != 0) {
- [[self _dataSource] _addSubresources:subresources];
- }
- return fragment;
- }
+ return fragment;
}
#endif
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];