Changeset 19764 in webkit
- Timestamp:
- Feb 20, 2007 10:00:26 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r19763 r19764 1 2007-02-20 Beth Dakin <bdakin@apple.com> 2 3 Reviewed by Maciej. 4 5 Implement writeImage() on Pasteboard so that the context menus can 6 call into the editor for the "Copy image" command instead of 7 calling across the clients. 8 9 * WebCore.exp: 10 * WebCore.xcodeproj/project.pbxproj: 11 * editing/Editor.cpp: 12 (WebCore::Editor::copyImage): Call into the Pasteboard. 13 * editing/Editor.h: 14 * loader/mac/LoaderNSURLExtras.h: A new NSURL extra needed inside 15 WebCore. 16 * loader/mac/LoaderNSURLExtras.m: Made this file Objective-C++ 17 (from Objective-C) since the call into the MIMETypeRegistry will 18 return a Vector. 19 (urlByRemovingComponent): Cast to build as Obj-C++ 20 (urlWithDataRelativeToURL): Same. 21 (vectorContainsString): Helper. 22 (suggestedFilenameWithMIMEType): New function. 23 * page/ContextMenuClient.h: Remove copyImageToClipboard() 24 * page/ContextMenuController.cpp: 25 (WebCore::ContextMenuController::contextMenuItemSelected): Call 26 into the editor instead of the client. 27 * page/mac/WebCoreViewFactory.h: New localized String. 28 * platform/LocalizedStrings.h: Same. 29 * platform/MimeTypeRegistry.h: Expose two additional functions for 30 MIMEType information from WebCore System Interface. 31 * platform/Pasteboard.h: 32 * platform/SharedBuffer.h: Make platformData() and platformDataSize 33 () public since they are needed to write the image to the 34 pasteboard. 35 * platform/mac/LocalizedStringsMac.mm: New localized string. 36 (WebCore::copyImageUnknownFileLabel): 37 * platform/mac/MimeTypeRegistryMac.mm: 38 (WebCore::MimeTypeRegistry::getExtensionsForMIMEType): 39 (WebCore::MimeTypeRegistry::getPreferredExtensionForMIMEType): 40 * platform/mac/PasteboardMac.mm: 41 (WebCore::writableTypesForImage): 42 (WebCore::Pasteboard::writeURL): Write the correct types if the url 43 is for an image. 44 (WebCore::fileWrapperForImage): 45 (WebCore::Pasteboard::writeFileWrapperAsRTFDAttachment): 46 (WebCore::Pasteboard::writeImage): 47 * platform/mac/WebCoreNSStringExtras.h: Added. Some the the 48 NSStringExtras that were in WebKit are now needed by WebCore. To 49 avoid having two copies of these functions, I just moved the 50 implementations to WebCore. The WebKit functions just call into 51 WebCore. 52 * platform/mac/WebCoreNSStringExtras.mm: Added. 53 (hasCaseInsensitiveSuffix): 54 (hasCaseInsensitiveSubstring): 55 (filenameByFixingIllegalCharacters): 56 * platform/mac/WebCoreSystemInterface.h: 57 wkGetPreferredExtensionForMIMEType and wkGetExtensionsForMIMEType 58 are now needed in WebCore as well as WebKit. 59 * platform/mac/WebCoreSystemInterface.mm: 60 1 61 2007-02-20 Adam Roben <aroben@apple.com> 2 62 -
trunk/WebCore/WebCore.exp
r19762 r19764 602 602 __ZNK7WebCore9TimerBase8isActiveEv 603 603 _canonicalURL 604 _filenameByFixingIllegalCharacters 605 _hasCaseInsensitiveSubstring 606 _hasCaseInsensitiveSuffix 604 607 _stringIsFileURL 608 _suggestedFilenameWithMIMEType 605 609 _urlByRemovingComponent 606 610 _urlByRemovingFragment … … 627 631 _wkGetCGFontFromNSFont 628 632 _wkGetDefaultGlyphForChar 633 _wkGetExtensionsForMIMEType 629 634 _wkGetFontInLanguageForCharacter 630 635 _wkGetFontInLanguageForRange … … 639 644 _wkGetNSURLResponseLastModifiedDate 640 645 _wkGetNSURLResponseMustRevalidate 646 _wkGetPreferredExtensionForMIMEType 641 647 _wkInitializeGlyphVector 642 648 _wkNSURLProtocolClassForReqest -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r19762 r19764 1457 1457 933A14B90B7D1D5200A53FFD /* JSTextEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 933A14B70B7D1D5200A53FFD /* JSTextEvent.h */; }; 1458 1458 934706AB0AACD809002C1D43 /* TextDecoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 932CA7420AAA198E00AD1FAD /* TextDecoder.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1459 934D9BA50B8C116B007B42A9 /* WebCoreNSStringExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 934D9BA40B8C116B007B42A9 /* WebCoreNSStringExtras.mm */; }; 1460 934D9BA70B8C1175007B42A9 /* WebCoreNSStringExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 934D9BA60B8C1175007B42A9 /* WebCoreNSStringExtras.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1459 1461 934FE9E50B5CA539003E4A73 /* FileChooser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 934FE9E40B5CA539003E4A73 /* FileChooser.cpp */; }; 1460 1462 9352071909BD3BA500F2038D /* StaticConstructors.h in Headers */ = {isa = PBXBuildFile; fileRef = 9352071709BD3BA500F2038D /* StaticConstructors.h */; }; … … 3501 3503 656B85370AEA1F9A00A095B4 /* ResourceHandle.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ResourceHandle.h; sourceTree = "<group>"; }; 3502 3504 656D371A0ADBA5DE00A4554D /* LoaderNSURLExtras.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LoaderNSURLExtras.h; sourceTree = "<group>"; }; 3503 656D371B0ADBA5DE00A4554D /* LoaderNSURLExtras.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = LoaderNSURLExtras.m; sourceTree = "<group>"; };3505 656D371B0ADBA5DE00A4554D /* LoaderNSURLExtras.m */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 30; path = LoaderNSURLExtras.m; sourceTree = "<group>"; }; 3504 3506 656D371E0ADBA5DE00A4554D /* DocumentLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DocumentLoader.h; sourceTree = "<group>"; }; 3505 3507 656D371F0ADBA5DE00A4554D /* DocumentLoaderMac.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 30; path = DocumentLoaderMac.mm; sourceTree = "<group>"; }; … … 4526 4528 933A14B60B7D1D5200A53FFD /* JSTextEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTextEvent.cpp; sourceTree = "<group>"; }; 4527 4529 933A14B70B7D1D5200A53FFD /* JSTextEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTextEvent.h; sourceTree = "<group>"; }; 4530 934D9BA40B8C116B007B42A9 /* WebCoreNSStringExtras.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSStringExtras.mm; sourceTree = "<group>"; }; 4531 934D9BA60B8C1175007B42A9 /* WebCoreNSStringExtras.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = WebCoreNSStringExtras.h; sourceTree = "<group>"; }; 4528 4532 934FE9E40B5CA539003E4A73 /* FileChooser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileChooser.cpp; sourceTree = "<group>"; }; 4529 4533 9352071709BD3BA500F2038D /* StaticConstructors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StaticConstructors.h; sourceTree = "<group>"; }; … … 6874 6878 84B2B1F7056BEF3A00D2B771 /* WebCoreKeyGenerator.h */, 6875 6879 84B2B1F8056BEF3A00D2B771 /* WebCoreKeyGenerator.m */, 6880 934D9BA60B8C1175007B42A9 /* WebCoreNSStringExtras.h */, 6881 934D9BA40B8C116B007B42A9 /* WebCoreNSStringExtras.mm */, 6876 6882 DD05FE0B0B8BA3C6009ACDFE /* WebCoreObjCExtras.h */, 6877 6883 DD05FE0C0B8BA3C6009ACDFE /* WebCoreObjCExtras.c */, … … 11143 11149 DD05FE0D0B8BA3C6009ACDFE /* WebCoreObjCExtras.h in Headers */, 11144 11150 06A6A73D0B8BA44800DF1703 /* StringTruncator.h in Headers */, 11151 934D9BA70B8C1175007B42A9 /* WebCoreNSStringExtras.h in Headers */, 11145 11152 ); 11146 11153 runOnlyForDeploymentPostprocessing = 0; … … 12506 12513 DD05FE0E0B8BA3C6009ACDFE /* WebCoreObjCExtras.c in Sources */, 12507 12514 06A6A73C0B8BA44800DF1703 /* StringTruncator.cpp in Sources */, 12515 934D9BA50B8C116B007B42A9 /* WebCoreNSStringExtras.mm in Sources */, 12508 12516 ); 12509 12517 runOnlyForDeploymentPostprocessing = 0; -
trunk/WebCore/editing/Editor.cpp
r19702 r19764 1383 1383 } 1384 1384 1385 void Editor::copyImage(const HitTestResult& result) 1386 { 1387 Pasteboard::generalPasteboard()->writeImage(result); 1388 } 1389 1385 1390 bool Editor::isContinuousSpellCheckingEnabled() 1386 1391 { -
trunk/WebCore/editing/Editor.h
r19702 r19764 91 91 92 92 void copyURL(const KURL&, const String&); 93 void copyImage(const HitTestResult&); 93 94 94 95 void indent(); -
trunk/WebCore/loader/mac/LoaderNSURLExtras.h
r17025 r19764 44 44 BOOL urlIsEmpty(NSURL *url); 45 45 NSURL *canonicalURL(NSURL *url); 46 NSString *suggestedFilenameWithMIMEType(NSURL *url, NSString *MIMEType); 46 47 47 48 #ifdef __cplusplus -
trunk/WebCore/loader/mac/LoaderNSURLExtras.m
r17259 r19764 32 32 33 33 #import <wtf/Assertions.h> 34 #import <wtf/Vector.h> 35 #import "KURL.h" 36 #import "LocalizedStrings.h" 37 #import "MimeTypeRegistry.h" 38 #import "PlatformString.h" 39 #import "WebCoreNSStringExtras.h" 34 40 #import "WebCoreSystemInterface.h" 41 42 using namespace WebCore; 35 43 36 44 NSURL *urlByRemovingComponent(NSURL *url, CFURLComponentType component) … … 48 56 if (numBytes == -1) { 49 57 numBytes = CFURLGetBytes((CFURLRef)url, NULL, 0); 50 urlBytes = malloc(numBytes);58 urlBytes = static_cast<UInt8*>(malloc(numBytes)); 51 59 CFURLGetBytes((CFURLRef)url, urlBytes, numBytes); 52 60 } else … … 125 133 baseURL = urlByRemovingResourceSpecifier(baseURL); 126 134 127 const UInt8 *bytes = [data bytes];135 const UInt8 *bytes = static_cast<const UInt8*>([data bytes]); 128 136 // NOTE: We use UTF-8 here since this encoding is used when computing strings when returning URL components 129 137 // (e.g calls to NSURL -path). However, this function is not tolerant of illegal UTF-8 sequences, which … … 187 195 return result; 188 196 } 197 198 static bool vectorContainsString(Vector<String> vector, String string) 199 { 200 int size = vector.size(); 201 for (int i = 0; i < size; i++) 202 if (vector[i] == string) 203 return true; 204 return false; 205 } 206 207 NSString *suggestedFilenameWithMIMEType(NSURL *url, NSString *MIMEType) 208 { 209 // Get the filename from the URL. Try the lastPathComponent first. 210 NSString *lastPathComponent = [[url path] lastPathComponent]; 211 NSString *filename = filenameByFixingIllegalCharacters(lastPathComponent); 212 NSString *extension = nil; 213 214 if ([filename length] == 0 || [lastPathComponent isEqualToString:@"/"]) { 215 // lastPathComponent is no good, try the host. 216 NSString *host = (NSString *)(KURL(url).host()); 217 filename = filenameByFixingIllegalCharacters(host); 218 if ([filename length] == 0) { 219 // Can't make a filename using this URL, use "unknown". 220 filename = copyImageUnknownFileLabel(); 221 } 222 } else { 223 // Save the extension for later correction. Only correct the extension of the lastPathComponent. 224 // For example, if the filename ends up being the host, we wouldn't want to correct ".com" in "www.apple.com". 225 extension = [filename pathExtension]; 226 } 227 228 // No mime type reported. Just return the filename we have now. 229 if (!MIMEType) { 230 return filename; 231 } 232 233 // Do not correct filenames that are reported with a mime type of tar, and 234 // have a filename which has .tar in it or ends in .tgz 235 if (([MIMEType isEqualToString:@"application/tar"] || [MIMEType isEqualToString:@"application/x-tar"]) 236 && (hasCaseInsensitiveSubstring(filename, @".tar") 237 || hasCaseInsensitiveSuffix(filename, @".tgz"))) { 238 return filename; 239 } 240 241 // I don't think we need to worry about this for the image case 242 // If the type is known, check the extension and correct it if necessary. 243 if (![MIMEType isEqualToString:@"application/octet-stream"] && ![MIMEType isEqualToString:@"text/plain"]) { 244 Vector<String> extensions = MimeTypeRegistry::getExtensionsForMIMEType(MIMEType); 245 246 if (!extensions.size() || (extensions && !vectorContainsString(extensions, extension))) { 247 // The extension doesn't match the MIME type. Correct this. 248 NSString *correctExtension = MimeTypeRegistry::getPreferredExtensionForMIMEType(MIMEType); 249 if ([correctExtension length] != 0) { 250 // Append the correct extension. 251 filename = [filename stringByAppendingPathExtension:correctExtension]; 252 } 253 } 254 } 255 256 return filename; 257 } -
trunk/WebCore/page/ContextMenuClient.h
r18748 r19764 46 46 47 47 virtual void downloadURL(const KURL& url) = 0; 48 virtual void copyImageToClipboard(const HitTestResult&) = 0;49 48 virtual void searchWithGoogle(const Frame*) = 0; 50 49 virtual void lookUpInDictionary(Frame*) = 0; -
trunk/WebCore/page/ContextMenuController.cpp
r19547 r19764 135 135 // FIXME: The Pasteboard class is not written yet 136 136 // For now, call into the client. This is temporary! 137 m_client->copyImageToClipboard(result);137 frame->editor()->copyImage(result); 138 138 break; 139 139 case ContextMenuItemTagOpenFrameInNewWindow: { -
trunk/WebCore/page/mac/WebCoreViewFactory.h
r18554 r19764 45 45 - (NSString *)fileButtonChooseFileLabel; 46 46 - (NSString *)fileButtonNoFileSelectedLabel; 47 - (NSString *)copyImageUnknownFileLabel; 47 48 48 49 // Context menu item titles -
trunk/WebCore/platform/LocalizedStrings.h
r18554 r19764 37 37 String fileButtonChooseFileLabel(); 38 38 String fileButtonNoFileSelectedLabel(); 39 String copyImageUnknownFileLabel(); 39 40 String contextMenuItemTagOpenLinkInNewWindow(); 40 41 String contextMenuItemTagDownloadLinkToDisk(); -
trunk/WebCore/platform/MimeTypeRegistry.h
r19702 r19764 30 30 #include "StringHash.h" 31 31 #include <wtf/HashSet.h> 32 #include <wtf/Vector.h> 32 33 33 34 namespace WebCore { … … 36 37 public: 37 38 static String getMIMETypeForExtension(const String& ext); 39 static Vector<String> getExtensionsForMIMEType(const String& type); 40 static String getPreferredExtensionForMIMEType(const String& type); 38 41 static String getMIMETypeForPath(const String& path); 39 42 -
trunk/WebCore/platform/Pasteboard.h
r19689 r19764 36 36 37 37 #if PLATFORM(MAC) 38 class NSFileWrapper; 38 39 class NSPasteboard; 39 40 class NSArray; … … 58 59 class DocumentFragment; 59 60 class Frame; 61 class HitTestResult; 60 62 class KURL; 61 63 class Range; … … 67 69 //Helper functions to allow Clipboard to share code 68 70 static void writeSelection(NSPasteboard* pasteboard, Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame); 69 static void writeURL(NSPasteboard* pasteboard, NSArray* types, const KURL& url, const String& titleStr, Frame* frame );71 static void writeURL(NSPasteboard* pasteboard, NSArray* types, const KURL& url, const String& titleStr, Frame* frame, bool isImage = false); 70 72 #endif 71 73 72 74 static Pasteboard* generalPasteboard(); 73 75 void writeSelection(Range*, bool canSmartCopyOrDelete, Frame*); 74 void writeURL(const KURL&, const String&, Frame* = 0); 76 void writeURL(const KURL&, const String&, Frame* = 0, bool isImage = false); 77 void writeImage(const HitTestResult&); 78 #if PLATFORM(MAC) 79 void writeFileWrapperAsRTFDAttachment(NSFileWrapper*); 80 #endif 75 81 void clear(); 76 82 bool canSmartReplace(); -
trunk/WebCore/platform/SharedBuffer.h
r18728 r19764 57 57 void append(const char*, int); 58 58 void clear(); 59 const char* platformData() const; 60 unsigned platformDataSize() const; 59 61 60 62 private: … … 62 64 void maybeTransferPlatformData(); 63 65 bool hasPlatformData() const; 64 const char* platformData() const;65 unsigned platformDataSize() const;66 66 67 67 Vector<char> m_buffer; -
trunk/WebCore/platform/mac/LocalizedStringsMac.mm
r18554 r19764 81 81 } 82 82 83 String copyImageUnknownFileLabel() 84 { 85 BEGIN_BLOCK_OBJC_EXCEPTIONS; 86 return [[WebCoreViewFactory sharedFactory] copyImageUnknownFileLabel]; 87 END_BLOCK_OBJC_EXCEPTIONS; 88 return String(); 89 } 90 83 91 String contextMenuItemTagOpenLinkInNewWindow() 84 92 { -
trunk/WebCore/platform/mac/MimeTypeRegistryMac.mm
r19702 r19764 47 47 } 48 48 49 Vector<String> MimeTypeRegistry::getExtensionsForMIMEType(const String& type) 50 { 51 NSArray *stringsArray = wkGetExtensionsForMIMEType(type); 52 Vector<String> stringsVector = Vector<String>(); 53 unsigned count = [stringsArray count]; 54 if (count > 0) { 55 NSEnumerator* enumerator = [stringsArray objectEnumerator]; 56 NSString* string; 57 while ((string = [enumerator nextObject]) != nil) 58 stringsVector.append(string); 59 } 60 return stringsVector; 49 61 } 62 63 String MimeTypeRegistry::getPreferredExtensionForMIMEType(const String& type) 64 { 65 return wkGetPreferredExtensionForMIMEType(type); 66 } 67 68 } -
trunk/WebCore/platform/mac/PasteboardMac.mm
r19689 r19764 27 27 #import "Pasteboard.h" 28 28 29 #import "Cache.h" 30 #import "CachedResource.h" 29 31 #import "CharacterNames.h" 30 32 #import "DOMRangeInternal.h" 33 #import "Document.h" 31 34 #import "DocumentFragment.h" 32 35 #import "Editor.h" 33 36 #import "EditorClient.h" 37 #import "HitTestResult.h" 38 #import "Image.h" 34 39 #import "KURL.h" 40 #import "LoaderNSURLExtras.h" 41 #import "MimeTypeRegistry.h" 35 42 #import "RetainPtr.h" 43 #import "WebCoreNSStringExtras.h" 36 44 #import "WebCoreSystemInterface.h" 37 45 #import "markup.h" … … 77 85 NSStringPboardType, 78 86 nil]; 87 } 88 return types; 89 } 90 91 static NSArray* writableTypesForImage() 92 { 93 static NSMutableArray *types = nil; 94 if (!types) { 95 types = [[NSMutableArray alloc] initWithObjects:NSTIFFPboardType, nil]; 96 [types addObjectsFromArray:writableTypesForURL()]; 97 [types addObject:NSRTFDPboardType]; 79 98 } 80 99 return types; … … 182 201 } 183 202 184 void Pasteboard::writeURL(NSPasteboard* pasteboard, NSArray* types, const KURL& url, const String& titleStr, Frame* frame )203 void Pasteboard::writeURL(NSPasteboard* pasteboard, NSArray* types, const KURL& url, const String& titleStr, Frame* frame, bool isImage) 185 204 { 186 205 if (WebArchivePboardType == nil) … … 188 207 189 208 if (types == nil) { 190 types = writableTypesForURL(); 209 if (isImage) 210 types = writableTypesForImage(); 211 else 212 types = writableTypesForURL(); 191 213 [pasteboard declareTypes:types owner:nil]; 192 214 } … … 219 241 } 220 242 221 void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame) 222 { 223 Pasteboard::writeURL(m_pasteboard, nil, url, titleStr, frame); 224 } 225 243 void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame, bool isImage) 244 { 245 Pasteboard::writeURL(m_pasteboard, nil, url, titleStr, frame, isImage); 246 } 247 248 static NSFileWrapper* fileWrapperForImage(CachedResource* resource, NSURL *URL) 249 { 250 SharedBuffer* coreData = resource->allData(); 251 NSData *data = [[[NSData alloc] initWithBytes:coreData->platformData() 252 length:coreData->platformDataSize()] autorelease]; 253 NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:data] autorelease]; 254 String coreMIMEType = resource->response().mimeType(); 255 NSString *MIMEType = nil; 256 if (!coreMIMEType.isNull()) 257 MIMEType = coreMIMEType; 258 [wrapper setPreferredFilename:suggestedFilenameWithMIMEType(URL, MIMEType)]; 259 return wrapper; 260 } 261 262 void Pasteboard::writeFileWrapperAsRTFDAttachment(NSFileWrapper* wrapper) 263 { 264 NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:wrapper]; 265 266 NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attachment]; 267 [attachment release]; 268 269 NSData *RTFDData = [string RTFDFromRange:NSMakeRange(0, [string length]) documentAttributes:nil]; 270 [m_pasteboard setData:RTFDData forType:NSRTFDPboardType]; 271 } 272 273 void Pasteboard::writeImage(const HitTestResult& result) 274 { 275 KURL coreURL = result.absoluteLinkURL(); 276 if (coreURL.isEmpty()) 277 coreURL = result.absoluteImageURL(); 278 NSURL *URL = coreURL.getNSURL(); 279 ASSERT(URL); 280 281 NSString *title = result.altDisplayString().isNull() ? nil : (NSString*)(result.altDisplayString()); 282 Frame* frame = result.innerNonSharedNode()->document()->frame(); 283 284 writeURL(URL, title, frame, true); 285 NSArray *types = [m_pasteboard types]; 286 [m_pasteboard declareTypes:types owner:nil]; 287 288 NSImage *image = (NSImage *)(result.image() ? result.image()->getNSImage() : nil); 289 ASSERT(image); 290 [m_pasteboard setData:[image TIFFRepresentation] forType:NSTIFFPboardType]; 291 292 CachedResource* imageResource = WebCore::cache()->resourceForURL(result.absoluteImageURL().url()); 293 ASSERT(imageResource); 294 String MIMEType = imageResource->response().mimeType(); 295 ASSERT(MimeTypeRegistry::isSupportedImageResourceMIMEType(MIMEType)); 296 297 if (imageResource) 298 writeFileWrapperAsRTFDAttachment(fileWrapperForImage(imageResource, URL)); 299 } 226 300 227 301 bool Pasteboard::canSmartReplace() -
trunk/WebCore/platform/mac/WebCoreSystemInterface.h
r18541 r19764 45 45 @class NSURLRequest; 46 46 #else 47 typedef struct NSArray NSArray; 47 48 typedef struct NSDate NSDate; 48 49 typedef struct NSFont NSFont; … … 97 98 extern int (*wkGetGlyphVectorNumGlyphs)(void* glyphVector); 98 99 extern size_t (*wkGetGlyphVectorRecordSize)(void* glyphVector); 100 extern NSString* (*wkGetPreferredExtensionForMIMEType)(NSString*); 101 extern NSArray* (*wkGetExtensionsForMIMEType)(NSString*); 99 102 extern NSString* (*wkGetMIMETypeForExtension)(NSString*); 100 103 extern ATSUFontID (*wkGetNSFontATSUFontId)(NSFont*); -
trunk/WebCore/platform/mac/WebCoreSystemInterface.mm
r18541 r19764 47 47 int (*wkGetGlyphVectorNumGlyphs)(void* glyphVector); 48 48 size_t (*wkGetGlyphVectorRecordSize)(void* glyphVector); 49 NSString* (*wkGetPreferredExtensionForMIMEType)(NSString*); 50 NSArray* (*wkGetExtensionsForMIMEType)(NSString*); 49 51 NSString* (*wkGetMIMETypeForExtension)(NSString*); 50 52 ATSUFontID (*wkGetNSFontATSUFontId)(NSFont*); -
trunk/WebKit/ChangeLog
r19762 r19764 1 2007-02-20 Beth Dakin <bdakin@apple.com> 2 3 Reviewed by Maciej. 4 5 WebKit changes needed to implement writeImage() in WebCore's 6 Pasteboard class. 7 8 * Misc/WebKitNSStringExtras.m: Call into WebCore for these 9 implementations. 10 (-[NSString _webkit_hasCaseInsensitiveSuffix:]): 11 (-[NSString _webkit_hasCaseInsensitiveSubstring:]): 12 (-[NSString _webkit_filenameByFixingIllegalCharacters]): 13 * Misc/WebNSURLExtras.m: Same. 14 (-[NSURL _webkit_suggestedFilenameWithMIMEType:]): 15 * WebCoreSupport/WebContextMenuClient.h: Remove 16 copyImageToClipboard() 17 * WebCoreSupport/WebContextMenuClient.mm: 18 * WebCoreSupport/WebSystemInterface.m: Expose 19 GetExtensionsForMIMEType and GetPreferredExtensionForMIMEType to 20 WebCore. 21 (InitWebCoreSystemInterface): 22 * WebCoreSupport/WebViewFactory.mm: New localized string for 23 WebCore. 24 (-[WebViewFactory copyImageUnknownFileLabel]): 25 1 26 2007-02-20 Adam Roben <aroben@apple.com> 2 27 -
trunk/WebKit/Misc/WebKitNSStringExtras.m
r19744 r19764 32 32 #import <WebKit/WebNSFileManagerExtras.h> 33 33 34 #import <WebCore/WebCoreNSStringExtras.h> 34 35 #import <WebCore/WebCoreTextRenderer.h> 35 36 … … 200 201 -(BOOL)_webkit_hasCaseInsensitiveSuffix:(NSString *)suffix 201 202 { 202 return [self rangeOfString:suffix options:(NSCaseInsensitiveSearch | NSBackwardsSearch | NSAnchoredSearch)].location != NSNotFound;203 return hasCaseInsensitiveSuffix(self, suffix); 203 204 } 204 205 205 206 -(BOOL)_webkit_hasCaseInsensitiveSubstring:(NSString *)substring 206 207 { 207 return [self rangeOfString:substring options:NSCaseInsensitiveSearch].location != NSNotFound;208 return hasCaseInsensitiveSubstring(self, substring); 208 209 } 209 210 210 211 -(NSString *)_webkit_filenameByFixingIllegalCharacters 211 212 { 212 NSMutableString *filename = [[self mutableCopy] autorelease]; 213 214 // Strip null characters. 215 unichar nullChar = 0; 216 [filename replaceOccurrencesOfString:[NSString stringWithCharacters:&nullChar length:0] withString:@"" options:0 range:NSMakeRange(0, [filename length])]; 217 218 // Replace "/" with "-". 219 [filename replaceOccurrencesOfString:@"/" withString:@"-" options:0 range:NSMakeRange(0, [filename length])]; 220 221 // Replace ":" with "-". 222 [filename replaceOccurrencesOfString:@":" withString:@"-" options:0 range:NSMakeRange(0, [filename length])]; 223 224 // Strip leading dots. 225 while ([filename hasPrefix:@"."]) { 226 [filename deleteCharactersInRange:NSMakeRange(0,1)]; 227 } 228 229 return filename; 213 return filenameByFixingIllegalCharacters(self); 230 214 } 231 215 -
trunk/WebKit/Misc/WebNSURLExtras.m
r19439 r19764 682 682 - (NSString *)_webkit_suggestedFilenameWithMIMEType:(NSString *)MIMEType 683 683 { 684 // Get the filename from the URL. Try the lastPathComponent first. 685 NSString *lastPathComponent = [[self path] lastPathComponent]; 686 NSString *filename = [lastPathComponent _webkit_filenameByFixingIllegalCharacters]; 687 NSString *extension = nil; 688 689 if ([filename length] == 0 || [lastPathComponent isEqualToString:@"/"]) { 690 // lastPathComponent is no good, try the host. 691 filename = [[self _web_hostString] _webkit_filenameByFixingIllegalCharacters]; 692 if ([filename length] == 0) { 693 // Can't make a filename using this URL, use "unknown". 694 filename = UI_STRING("unknown", "Unknown filename"); 695 } 696 } else { 697 // Save the extension for later correction. Only correct the extension of the lastPathComponent. 698 // For example, if the filename ends up being the host, we wouldn't want to correct ".com" in "www.apple.com". 699 extension = [filename pathExtension]; 700 } 701 702 // No mime type reported. Just return the filename we have now. 703 if (!MIMEType) { 704 return filename; 705 } 706 707 // Do not correct filenames that are reported with a mime type of tar, and 708 // have a filename which has .tar in it or ends in .tgz 709 if (([MIMEType isEqualToString:@"application/tar"] || [MIMEType isEqualToString:@"application/x-tar"]) && 710 ([filename _webkit_hasCaseInsensitiveSubstring:@".tar"] || [filename _webkit_hasCaseInsensitiveSuffix:@".tgz"])) { 711 return filename; 712 } 713 714 // If the type is known, check the extension and correct it if necessary. 715 if (![MIMEType isEqualToString:@"application/octet-stream"] && ![MIMEType isEqualToString:@"text/plain"]) { 716 NSArray *extensions = WKGetExtensionsForMIMEType(MIMEType); 717 718 if (![extension length] || (extensions && ![extensions containsObject:extension])) { 719 // The extension doesn't match the MIME type. Correct this. 720 NSString *correctExtension = WKGetPreferredExtensionForMIMEType(MIMEType); 721 if ([correctExtension length] != 0) { 722 // Append the correct extension. 723 filename = [filename stringByAppendingPathExtension:correctExtension]; 724 } 725 } 726 } 727 728 return filename; 684 return suggestedFilenameWithMIMEType(self, MIMEType); 729 685 } 730 686 -
trunk/WebKit/WebCoreSupport/WebContextMenuClient.h
r18748 r19764 43 43 44 44 virtual void downloadURL(const WebCore::KURL&); 45 virtual void copyImageToClipboard(const WebCore::HitTestResult&);46 45 virtual void searchWithGoogle(const WebCore::Frame*); 47 46 virtual void lookUpInDictionary(WebCore::Frame*); -
trunk/WebKit/WebCoreSupport/WebContextMenuClient.mm
r19529 r19764 242 242 } 243 243 244 void WebContextMenuClient::copyImageToClipboard(const HitTestResult& hitTestResult)245 {246 NSDictionary *element = [[[WebElementDictionary alloc] initWithHitTestResult:hitTestResult] autorelease];247 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];248 NSArray *types = [NSPasteboard _web_writableTypesForImageIncludingArchive:(hitTestResult.innerNonSharedNode() != 0)];249 [pasteboard declareTypes:types owner:m_webView];250 [m_webView _writeImageForElement:element withPasteboardTypes:types toPasteboard:pasteboard];251 }252 253 244 void WebContextMenuClient::searchWithSpotlight() 254 245 { -
trunk/WebKit/WebCoreSupport/WebSystemInterface.m
r18541 r19764 45 45 INIT(CreateCustomCFReadStream); 46 46 INIT(CreateNSURLConnectionDelegateProxy); 47 INIT(CreateURLNPasteboardFlavorTypeName); 47 48 INIT(CreateURLPasteboardFlavorTypeName); 48 INIT(CreateURLNPasteboardFlavorTypeName);49 49 INIT(DrawBezeledTextArea); 50 50 INIT(DrawBezeledTextFieldCell); 51 INIT(DrawFocusRing); 51 52 INIT(DrawTextFieldCellFocusRing); 52 INIT(DrawFocusRing);53 53 INIT(FontSmoothingModeIsLCD); 54 54 INIT(GetATSStyleGroup); 55 55 INIT(GetCGFontFromNSFont); 56 56 INIT(GetDefaultGlyphForChar); 57 INIT(GetExtensionsForMIMEType); 57 58 INIT(GetFontInLanguageForCharacter); 58 59 INIT(GetFontInLanguageForRange); … … 67 68 INIT(GetNSURLResponseLastModifiedDate); 68 69 INIT(GetNSURLResponseMustRevalidate); 70 INIT(GetPreferredExtensionForMIMEType); 69 71 INIT(InitializeGlyphVector); 72 INIT(NSURLProtocolClassForReqest); 70 73 INIT(PathFromFont); 71 74 INIT(PopupMenu); 72 75 INIT(ReleaseStyleGroup); 76 INIT(SecondsSinceLastInputEvent); 73 77 INIT(SetCGFontRenderingMode); 74 78 INIT(SetDragImage); … … 80 84 INIT(SignalCFReadStreamHasBytes); 81 85 INIT(SupportsMultipartXMixedReplace); 82 INIT(NSURLProtocolClassForReqest); 83 INIT(SecondsSinceLastInputEvent); 86 84 87 85 88 didInit = true; -
trunk/WebKit/WebCoreSupport/WebViewFactory.mm
r18725 r19764 129 129 } 130 130 131 - (NSString *)copyImageUnknownFileLabel 132 { 133 return UI_STRING("unknown", "Unknown filename"); 134 } 135 131 136 - (NSMenu *)cellMenuForSearchField 132 137 {
Note: See TracChangeset
for help on using the changeset viewer.