[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
cblu
cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:40:18 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 14d4595d2de5d949a1b098c3f76459e726144166
Author: cblu <cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue May 18 01:33:49 2004 +0000
WebKit:
Implemented new WebView pasteboard methods. Made a lot of factoring changes related to pasteboard management.
Reviewed by john.
* Misc.subproj/WebNSPasteboardExtras.h:
* Misc.subproj/WebNSPasteboardExtras.m:
(+[NSPasteboard _web_writableTypesForURL]): renamed to not include "drag" these types are also used for copying
(+[NSPasteboard _web_writableTypesForImage]): new
(-[NSPasteboard _web_bestURL]): tweak
(-[NSPasteboard _web_writeURL:andTitle:types:]): take an array of types that this method should write, don't declare the types since this complicates things for the caller
(-[NSPasteboard _web_writeImage:URL:title:archive:types:]): ditto
* Misc.subproj/WebNSViewExtras.m:
(-[NSView _web_dragImage:archive:rect:URL:title:event:]): call renamed methods
* WebView.subproj/WebDefaultContextMenuDelegate.m:
(-[WebDefaultUIDelegate copyLinkToClipboard:]): call code factored out to WebView
(-[WebDefaultUIDelegate copyImageToClipboard:]): ditto
* WebView.subproj/WebDocumentPrivate.h:
* WebView.subproj/WebHTMLView.h:
* WebView.subproj/WebHTMLView.m:
(-[WebHTMLView _selectedRTFData]): new factored out method
(-[WebHTMLView _writeSelectionToPasteboard:]): factored code out to writeSelectionWithPasteboardTypes:toPasteboard:
(-[WebHTMLView _dragImageForLinkElement:]): tweak
(-[WebHTMLView _handleMouseDragged:]): call renamed methods
(-[WebHTMLView pasteboardTypesForSelection]): new
(-[WebTextView writeSelectionWithPasteboardTypes:toPasteboard:]): new, code moved from _writeSelectionToPasteboard:
* WebView.subproj/WebHTMLViewPrivate.h:
* WebView.subproj/WebImageView.h:
* WebView.subproj/WebImageView.m:
(-[WebImageView writeImageToPasteboard:types:]): call renamed methods
(-[WebImageView copy:]):
(-[WebImageView writeSelectionToPasteboard:types:]): call renamed methods
* WebView.subproj/WebTextView.h:
* WebView.subproj/WebTextView.m:
(-[WebTextView pasteboardTypesForSelection]): new
(-[WebTextView writeSelectionWithPasteboardTypes:toPasteboard:]): new
* WebView.subproj/WebView.m:
(-[WebView _writeImageElement:withPasteboardTypes:toPasteboard:]): new
(-[WebView _writeLinkElement:withPasteboardTypes:toPasteboard:]): mew
(-[WebView dragOperationForDraggingInfo:]): implemented API
(-[WebView draggingEntered:]): call API
(-[WebView draggingUpdated:]): ditto
(-[WebView concludeDragOperation:]): ditto
(-[WebView pasteboardTypesForSelection]): implemented API
(-[WebView writeSelectionWithPasteboardTypes:toPasteboard:]): ditto
(-[WebView pasteboardTypesForElement:]): ditto
(-[WebView writeElement:withPasteboardTypes:toPasteboard:]): ditto
* WebView.subproj/WebViewPrivate.h:
WebBrowser:
Change to support renamed WebKit methods
Reviewed by john.
* BrowserNSPasteboardExtras.m: call renamed _web_writeURL
* ContextMenuHandler.m:
(-[BrowserWebView copyImageAddress:]): ditto
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6621 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index c9cad8e..62e910b 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,53 @@
+2004-05-17 Chris Blumenberg <cblu at apple.com>
+
+ Implemented new WebView pasteboard methods. Made a lot of factoring changes related to pasteboard management.
+
+ Reviewed by john.
+
+ * Misc.subproj/WebNSPasteboardExtras.h:
+ * Misc.subproj/WebNSPasteboardExtras.m:
+ (+[NSPasteboard _web_writableTypesForURL]): renamed to not include "drag" these types are also used for copying
+ (+[NSPasteboard _web_writableTypesForImage]): new
+ (-[NSPasteboard _web_bestURL]): tweak
+ (-[NSPasteboard _web_writeURL:andTitle:types:]): take an array of types that this method should write, don't declare the types since this complicates things for the caller
+ (-[NSPasteboard _web_writeImage:URL:title:archive:types:]): ditto
+ * Misc.subproj/WebNSViewExtras.m:
+ (-[NSView _web_dragImage:archive:rect:URL:title:event:]): call renamed methods
+ * WebView.subproj/WebDefaultContextMenuDelegate.m:
+ (-[WebDefaultUIDelegate copyLinkToClipboard:]): call code factored out to WebView
+ (-[WebDefaultUIDelegate copyImageToClipboard:]): ditto
+ * WebView.subproj/WebDocumentPrivate.h:
+ * WebView.subproj/WebHTMLView.h:
+ * WebView.subproj/WebHTMLView.m:
+ (-[WebHTMLView _selectedRTFData]): new factored out method
+ (-[WebHTMLView _writeSelectionToPasteboard:]): factored code out to writeSelectionWithPasteboardTypes:toPasteboard:
+ (-[WebHTMLView _dragImageForLinkElement:]): tweak
+ (-[WebHTMLView _handleMouseDragged:]): call renamed methods
+ (-[WebHTMLView pasteboardTypesForSelection]): new
+ (-[WebTextView writeSelectionWithPasteboardTypes:toPasteboard:]): new, code moved from _writeSelectionToPasteboard:
+ * WebView.subproj/WebHTMLViewPrivate.h:
+ * WebView.subproj/WebImageView.h:
+ * WebView.subproj/WebImageView.m:
+ (-[WebImageView writeImageToPasteboard:types:]): call renamed methods
+ (-[WebImageView copy:]):
+ (-[WebImageView writeSelectionToPasteboard:types:]): call renamed methods
+ * WebView.subproj/WebTextView.h:
+ * WebView.subproj/WebTextView.m:
+ (-[WebTextView pasteboardTypesForSelection]): new
+ (-[WebTextView writeSelectionWithPasteboardTypes:toPasteboard:]): new
+ * WebView.subproj/WebView.m:
+ (-[WebView _writeImageElement:withPasteboardTypes:toPasteboard:]): new
+ (-[WebView _writeLinkElement:withPasteboardTypes:toPasteboard:]): mew
+ (-[WebView dragOperationForDraggingInfo:]): implemented API
+ (-[WebView draggingEntered:]): call API
+ (-[WebView draggingUpdated:]): ditto
+ (-[WebView concludeDragOperation:]): ditto
+ (-[WebView pasteboardTypesForSelection]): implemented API
+ (-[WebView writeSelectionWithPasteboardTypes:toPasteboard:]): ditto
+ (-[WebView pasteboardTypesForElement:]): ditto
+ (-[WebView writeElement:withPasteboardTypes:toPasteboard:]): ditto
+ * WebView.subproj/WebViewPrivate.h:
+
2004-05-17 Ken Kocienda <kocienda at apple.com>
Reviewed by John
diff --git a/WebKit/Misc.subproj/WebNSPasteboardExtras.h b/WebKit/Misc.subproj/WebNSPasteboardExtras.h
index cbe638c..3890533 100644
--- a/WebKit/Misc.subproj/WebNSPasteboardExtras.h
+++ b/WebKit/Misc.subproj/WebNSPasteboardExtras.h
@@ -16,13 +16,11 @@ extern NSString *WebURLNamePboardType;
@interface NSPasteboard (WebExtras)
-// Returns the array of drag types that _web_writeURL:andTitle:withOwner: handles.
-// FIXME: It would be better to conceal this completely by changing
-// _web_writeURL:andTitle:withOwner:types: to take a list of additional types
-// instead of a complete list of types, but we're afraid to do so at this late
-// stage in Panther just in case some internal client is using _web_writeURL:andTitle:withOwner:types:
-// already and relying on its current behavior.
-+ (NSArray *)_web_writableDragTypesForURL;
+// Returns the array of types that _web_writeURL:andTitle: handles.
++ (NSArray *)_web_writableTypesForURL;
+
+// Returns the array of types that _web_writeImage::::: handles.
++ (NSArray *)_web_writableTypesForImage;
// Returns the array of drag types that _web_bestURL handles; note that the presence
// of one or more of these drag types on the pasteboard is not a guarantee that
@@ -30,15 +28,10 @@ extern NSString *WebURLNamePboardType;
+ (NSArray *)_web_dragTypesForURL;
// Finds the best URL from the data on the pasteboard, giving priority to http and https URLs
--(NSURL *)_web_bestURL;
-
-// Writes the URL to the pasteboard in all the types from _web_writableDragTypesForURL
-- (void)_web_writeURL:(NSURL *)URL andTitle:(NSString *)title withOwner:(id)owner;
+- (NSURL *)_web_bestURL;
-// Writes the URL to the pasteboard in all the types from _web_writableDragTypesForURL,
-// after declaring all the passed-in types. Any passed-in types not in _web_writableDragTypesForURL
-// must be handled by the caller separately.
-- (void)_web_writeURL:(NSURL *)URL andTitle:(NSString *)title withOwner:(id)owner types:(NSArray *)types;
+// Writes the URL to the pasteboard with the passed types.
+- (void)_web_writeURL:(NSURL *)URL andTitle:(NSString *)title types:(NSArray *)types;
// Sets the text on the NSFindPboard. Returns the new changeCount for the NSFindPboard.
+ (int)_web_setFindPasteboardString:(NSString *)string withOwner:(id)owner;
@@ -51,6 +44,7 @@ extern NSString *WebURLNamePboardType;
- (void)_web_writeImage:(WebImageRenderer *)image
URL:(NSURL *)URL
title:(NSString *)title
- archive:(WebArchive *)archive;
+ archive:(WebArchive *)archive
+ types:(NSArray *)types;
@end
diff --git a/WebKit/Misc.subproj/WebNSPasteboardExtras.m b/WebKit/Misc.subproj/WebNSPasteboardExtras.m
index c0c6137..8211c63 100644
--- a/WebKit/Misc.subproj/WebNSPasteboardExtras.m
+++ b/WebKit/Misc.subproj/WebNSPasteboardExtras.m
@@ -44,15 +44,33 @@ NSString *WebURLNamePboardType = nil;
#endif
}
-+ (NSArray *)_web_writableDragTypesForURL
++ (NSArray *)_web_writableTypesForURL
{
- return [NSArray arrayWithObjects:
- WebURLsWithTitlesPboardType,
- NSURLPboardType,
- WebURLPboardType,
- WebURLNamePboardType,
- NSStringPboardType,
- nil];
+ static NSArray *types = nil;
+ if (!types) {
+ types = [[NSArray alloc] initWithObjects:
+ WebURLsWithTitlesPboardType,
+ NSURLPboardType,
+ WebURLPboardType,
+ WebURLNamePboardType,
+ NSStringPboardType,
+ nil];
+ }
+ return types;
+}
+
++ (NSArray *)_web_writableTypesForImage
+{
+ static NSMutableArray *types = nil;
+ if (!types) {
+ types = [[NSMutableArray alloc] initWithObjects:
+ NSTIFFPboardType,
+ NSRTFDPboardType,
+ WebArchivePboardType,
+ nil];
+ [types addObjectsFromArray:[NSPasteboard _web_writableTypesForURL]];
+ }
+ return types;
}
+ (NSArray *)_web_dragTypesForURL
@@ -67,7 +85,7 @@ NSString *WebURLNamePboardType = nil;
nil];
}
--(NSURL *)_web_bestURL
+- (NSURL *)_web_bestURL
{
NSArray *types = [self types];
@@ -105,30 +123,32 @@ NSString *WebURLNamePboardType = nil;
return nil;
}
-- (void)_web_writeURL:(NSURL *)URL andTitle:(NSString *)title withOwner:(id)owner types:(NSArray *)types
+- (void)_web_writeURL:(NSURL *)URL andTitle:(NSString *)title types:(NSArray *)types
{
ASSERT(URL);
- ASSERT(types);
- [self declareTypes:types owner:owner];
-
- if(!title || [title isEqualToString:@""]){
+ if ([title length] == 0) {
title = [[URL path] lastPathComponent];
- if(!title || [title isEqualToString:@""]){
+ if ([title length] == 0) {
title = [URL _web_userVisibleString];
}
}
- [URL writeToPasteboard:self];
- [self setString:title forType:WebURLNamePboardType];
- [self setString:[URL _web_userVisibleString] forType:WebURLPboardType];
- [self setString:[URL _web_userVisibleString] forType:NSStringPboardType];
- [WebURLsWithTitles writeURLs:[NSArray arrayWithObject:URL] andTitles:[NSArray arrayWithObject:title] toPasteboard:self];
-}
-
-- (void)_web_writeURL:(NSURL *)URL andTitle:(NSString *)title withOwner:(id)owner
-{
- [self _web_writeURL:URL andTitle:title withOwner:owner types:[NSPasteboard _web_writableDragTypesForURL]];
+ if ([types containsObject:NSURLPboardType]) {
+ [URL writeToPasteboard:self];
+ }
+ if ([types containsObject:WebURLPboardType]) {
+ [self setString:[URL _web_userVisibleString] forType:WebURLPboardType];
+ }
+ if ([types containsObject:WebURLNamePboardType]) {
+ [self setString:title forType:WebURLNamePboardType];
+ }
+ if ([types containsObject:NSStringPboardType]) {
+ [self setString:[URL _web_userVisibleString] forType:NSStringPboardType];
+ }
+ if ([types containsObject:WebURLsWithTitlesPboardType]) {
+ [WebURLsWithTitles writeURLs:[NSArray arrayWithObject:URL] andTitles:[NSArray arrayWithObject:title] toPasteboard:self];
+ }
}
+ (int)_web_setFindPasteboardString:(NSString *)string withOwner:(id)owner
@@ -154,44 +174,31 @@ NSString *WebURLNamePboardType = nil;
URL:(NSURL *)URL
title:(NSString *)title
archive:(WebArchive *)archive
+ types:(NSArray *)types
{
ASSERT(image);
ASSERT(URL);
+
+ [self _web_writeURL:URL andTitle:title types:types];
- BOOL isDrag = (self == [NSPasteboard pasteboardWithName:NSDragPboard]);
- NSMutableArray *types = [NSMutableArray arrayWithObject:NSTIFFPboardType];
-
- [types addObjectsFromArray:[NSPasteboard _web_writableDragTypesForURL]];
-
- if (archive) {
- [types addObject:NSRTFDPboardType];
- [types addObject:WebArchivePboardType];
- }
- if (isDrag) {
- [types addObject:NSFilesPromisePboardType];
+ if ([types containsObject:NSTIFFPboardType]) {
+ [self setData:[image TIFFRepresentation] forType:NSTIFFPboardType];
}
-
- [self _web_writeURL:URL andTitle:title withOwner:self types:types];
- [self setData:[image TIFFRepresentation] forType:NSTIFFPboardType];
if (archive) {
- // This image data is either the only subresource of an archive (HTML image case)
- // or the main resource (standalone image case).
- WebResource *resource = [[archive subresources] objectAtIndex:0];
- if (resource == nil) {
- resource = [archive mainResource];
+ if ([types containsObject:NSRTFDPboardType]) {
+ // This image data is either the only subresource of an archive (HTML image case)
+ // or the main resource (standalone image case).
+ WebResource *resource = [[archive subresources] objectAtIndex:0];
+ if (resource == nil) {
+ resource = [archive mainResource];
+ }
+ ASSERT([[[WebImageRendererFactory sharedFactory] supportedMIMETypes] containsObject:[resource MIMEType]]);
+ [self _web_writeFileWrapperAsRTFDAttachment:[resource _fileWrapperRepresentation]];
}
- ASSERT([[[WebImageRendererFactory sharedFactory] supportedMIMETypes] containsObject:[resource MIMEType]]);
- [self _web_writeFileWrapperAsRTFDAttachment:[resource _fileWrapperRepresentation]];
- [self setData:[archive data] forType:WebArchivePboardType];
- }
- if (isDrag) {
- NSString *filename = [URL _web_suggestedFilenameWithMIMEType:[image MIMEType]];
- NSString *fileType = [filename pathExtension];
- if (!fileType) {
- fileType = @"";
+ if ([types containsObject:WebArchivePboardType]) {
+ [self setData:[archive data] forType:WebArchivePboardType];
}
- [self setPropertyList:[NSArray arrayWithObject:fileType] forType:NSFilesPromisePboardType];
}
}
diff --git a/WebKit/Misc.subproj/WebNSViewExtras.m b/WebKit/Misc.subproj/WebNSViewExtras.m
index 8168bc9..7b787d8 100644
--- a/WebKit/Misc.subproj/WebNSViewExtras.m
+++ b/WebKit/Misc.subproj/WebNSViewExtras.m
@@ -223,16 +223,17 @@
origin = NSMakePoint(mouseDownPoint.x - offset.width, mouseDownPoint.y - offset.height);
}
- NSArray *filesTypes = [NSArray arrayWithObject:fileType];
-
- NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
+ NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
+ NSMutableArray *types = [[NSMutableArray alloc] initWithObjects:NSFilesPromisePboardType, nil];
+ [types addObjectsFromArray:[NSPasteboard _web_writableTypesForImage]];
+ [pasteboard declareTypes:types owner:self];
+ [pasteboard _web_writeImage:image URL:URL title:title archive:archive types:types];
+ [types release];
- [pboard _web_writeImage:image URL:URL title:title archive:archive];
-
id source = [[NSFilePromiseDragSource alloc] initWithSource:(id)self];
- [source setTypes:filesTypes onPasteboard:pboard];
+ [source setTypes:[NSArray arrayWithObject:fileType] onPasteboard:pasteboard];
- [self dragImage:dragImage at:origin offset:offset event:event pasteboard:pboard source:source slideBack:YES];
+ [self dragImage:dragImage at:origin offset:offset event:event pasteboard:pasteboard source:source slideBack:YES];
}
@end
diff --git a/WebKit/WebView.subproj/WebDefaultContextMenuDelegate.m b/WebKit/WebView.subproj/WebDefaultContextMenuDelegate.m
index e92ea95..c23a5a8 100644
--- a/WebKit/WebView.subproj/WebDefaultContextMenuDelegate.m
+++ b/WebKit/WebView.subproj/WebDefaultContextMenuDelegate.m
@@ -191,9 +191,11 @@
{
NSDictionary *element = [sender representedObject];
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
- [pasteboard _web_writeURL:[element objectForKey:WebElementLinkURLKey]
- andTitle:[element objectForKey:WebElementLinkLabelKey]
- withOwner:self];
+ NSArray *types = [NSPasteboard _web_writableTypesForURL];
+ [pasteboard declareTypes:types owner:self];
+ [[[element objectForKey:WebElementFrameKey] webView] _writeLinkElement:element
+ withPasteboardTypes:types
+ toPasteboard:pasteboard];
}
- (void)openImageInNewWindow:(id)sender
@@ -211,11 +213,12 @@
- (void)copyImageToClipboard:(id)sender
{
NSDictionary *element = [sender representedObject];
- NSURL *linkURL = [element objectForKey:WebElementLinkURLKey];
- [[NSPasteboard generalPasteboard] _web_writeImage:[element objectForKey:WebElementImageKey]
- URL:linkURL ? linkURL : [element objectForKey:WebElementImageURLKey]
- title:[element objectForKey:WebElementImageAltStringKey]
- archive:[[element objectForKey:WebElementDOMNodeKey] webArchive]];
+ NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
+ NSArray *types = [NSPasteboard _web_writableTypesForImage];
+ [pasteboard declareTypes:types owner:self];
+ [[[element objectForKey:WebElementFrameKey] webView] _writeImageElement:element
+ withPasteboardTypes:types
+ toPasteboard:pasteboard];
}
- (void)openFrameInNewWindow:(id)sender
diff --git a/WebKit/WebView.subproj/WebDocumentPrivate.h b/WebKit/WebView.subproj/WebDocumentPrivate.h
index 0ab3305..e3c3f14 100644
--- a/WebKit/WebView.subproj/WebDocumentPrivate.h
+++ b/WebKit/WebView.subproj/WebDocumentPrivate.h
@@ -6,9 +6,6 @@
#import <WebKit/WebDocument.h>
@class DOMDocument;
- at class DOMNode;
- at class DOMRange;
- at class WebArchive;
@protocol WebDocumentImage <NSObject>
- (NSImage *)image;
@@ -17,4 +14,9 @@
// This method is deprecated as it now lives on WebFrame.
@protocol WebDocumentDOM <NSObject>
- (DOMDocument *)DOMDocument;
+ at end
+
+ at protocol WebDocumentSelection <NSObject>
+- (NSArray *)pasteboardTypesForSelection;
+- (void)writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard;
@end
\ No newline at end of file
diff --git a/WebKit/WebView.subproj/WebHTMLView.h b/WebKit/WebView.subproj/WebHTMLView.h
index cfcd646..cdf425e 100644
--- a/WebKit/WebView.subproj/WebHTMLView.h
+++ b/WebKit/WebView.subproj/WebHTMLView.h
@@ -3,9 +3,7 @@
Copyright 2002, Apple, Inc. All rights reserved.
*/
-#import <Cocoa/Cocoa.h>
-#import <WebKit/WebDocument.h>
-
+#import <WebKit/WebDocumentPrivate.h>
@class WebDataSource;
@class WebHTMLViewPrivate;
@@ -14,7 +12,7 @@
@class WebHTMLView
@discussion A document view of WebFrameView that displays HTML content.
*/
- at interface WebHTMLView : NSView <WebDocumentView, WebDocumentSearching, WebDocumentText>
+ at interface WebHTMLView : NSView <WebDocumentView, WebDocumentSearching, WebDocumentText, WebDocumentSelection>
{
@private
WebHTMLViewPrivate *_private;
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index c216a57..7641998 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -534,34 +534,19 @@ static WebHTMLView *lastHitView = nil;
return [[self _dataSource] _archiveWithMarkupString:*markupString nodes:nodes];
}
-- (void)_writeSelectionToPasteboard:(NSPasteboard *)pasteboard
+- (NSData *)_selectedRTFData
{
- [pasteboard declareTypes:[[self class] _selectionPasteboardTypes] owner:nil];
-
- // Put HTML on the pasteboard.
- NSString *markupString;
- WebArchive *archive = [self _selectedArchive:&markupString];
- [pasteboard setString:markupString forType:NSHTMLPboardType];
- [pasteboard setData:[archive data] forType:WebArchivePboardType];
-
- // Put attributed string on the pasteboard (RTF format).
NSAttributedString *attributedString = [self selectedAttributedString];
NSRange range = NSMakeRange(0, [attributedString length]);
- NSData *attributedData = [attributedString RTFFromRange:range documentAttributes:nil];
- [pasteboard setData:attributedData forType:NSRTFPboardType];
+ return [attributedString RTFFromRange:range documentAttributes:nil];
+}
- attributedData = [attributedString RTFDFromRange:range documentAttributes:nil];
- [pasteboard setData:attributedData forType:NSRTFDPboardType];
-
- // Put plain string on the pasteboard.
- // Map to a plain old space because this is better for source code, other browsers do it,
- // and because HTML forces you to do this any time you want two spaces in a row.
- NSMutableString *s = [[self selectedString] mutableCopy];
- const unichar NonBreakingSpaceCharacter = 0xA0;
- NSString *NonBreakingSpaceString = [NSString stringWithCharacters:&NonBreakingSpaceCharacter length:1];
- [s replaceOccurrencesOfString:NonBreakingSpaceString withString:@" " options:0 range:NSMakeRange(0, [s length])];
- [pasteboard setString:s forType:NSStringPboardType];
- [s release];
+- (void)_writeSelectionToPasteboard:(NSPasteboard *)pasteboard
+{
+ ASSERT([self _haveSelection]);
+ NSArray *types = [[self class] _selectionPasteboardTypes];
+ [pasteboard declareTypes:types owner:nil];
+ [self writeSelectionWithPasteboardTypes:types toPasteboard:pasteboard];
}
- (BOOL)_haveSelection
@@ -638,7 +623,7 @@ static WebHTMLView *lastHitView = nil;
}
}
--(NSImage *)_dragImageForLinkElement:(NSDictionary *)element
+- (NSImage *)_dragImageForLinkElement:(NSDictionary *)element
{
NSURL *linkURL = [element objectForKey: WebElementLinkURLKey];
@@ -755,8 +740,9 @@ static WebHTMLView *lastHitView = nil;
} else if (linkURL) {
NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
- NSString *label = [element objectForKey:WebElementLinkLabelKey];
- [pasteboard _web_writeURL:linkURL andTitle:label withOwner:self];
+ NSArray *types = [NSPasteboard _web_writableTypesForURL];
+ [pasteboard declareTypes:types owner:self];
+ [pasteboard _web_writeURL:linkURL andTitle:[element objectForKey:WebElementLinkLabelKey] types:types];
NSImage *dragImage = [self _dragImageForLinkElement:element];
NSSize offset = NSMakeSize([dragImage size].width / 2, -DRAG_LABEL_BORDER_Y);
[self dragImage:dragImage
@@ -1027,6 +1013,53 @@ static WebHTMLView *lastHitView = nil;
[NSPasteboard _web_setFindPasteboardString:[self selectedString] withOwner:self];
}
+- (NSArray *)pasteboardTypesForSelection
+{
+ return [[self class] _selectionPasteboardTypes];
+}
+
+- (void)writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard
+{
+ // Put HTML on the pasteboard.
+ NSString *markupString = nil;
+ WebArchive *archive = nil;
+ if ([types containsObject:NSHTMLPboardType]) {
+ archive = [self _selectedArchive:&markupString];
+ [pasteboard setString:markupString forType:NSHTMLPboardType];
+ }
+ if ([types containsObject:WebArchivePboardType]) {
+ if (!archive) {
+ archive = [self _selectedArchive:&markupString];
+ }
+ [pasteboard setData:[archive data] forType:WebArchivePboardType];
+ }
+
+ // Put attributed string on the pasteboard (RTF format).
+ NSData *RTFData = nil;
+ if ([types containsObject:NSRTFPboardType]) {
+ RTFData = [self _selectedRTFData];
+ [pasteboard setData:RTFData forType:NSRTFPboardType];
+ }
+ if ([types containsObject:NSRTFDPboardType]) {
+ if (!RTFData) {
+ RTFData = [self _selectedRTFData];
+ }
+ [pasteboard setData:RTFData forType:NSRTFDPboardType];
+ }
+
+ // Put plain string on the pasteboard.
+ if ([types containsObject:NSStringPboardType]) {
+ // Map to a plain old space because this is better for source code, other browsers do it,
+ // and because HTML forces you to do this any time you want two spaces in a row.
+ NSMutableString *s = [[self selectedString] mutableCopy];
+ const unichar NonBreakingSpaceCharacter = 0xA0;
+ NSString *NonBreakingSpaceString = [NSString stringWithCharacters:&NonBreakingSpaceCharacter length:1];
+ [s replaceOccurrencesOfString:NonBreakingSpaceString withString:@" " options:0 range:NSMakeRange(0, [s length])];
+ [pasteboard setString:s forType:NSStringPboardType];
+ [s release];
+ }
+}
+
- (void)copy:(id)sender
{
[self _writeSelectionToPasteboard:[NSPasteboard generalPasteboard]];
diff --git a/WebKit/WebView.subproj/WebHTMLViewPrivate.h b/WebKit/WebView.subproj/WebHTMLViewPrivate.h
index 92998a6..04c9abf 100644
--- a/WebKit/WebView.subproj/WebHTMLViewPrivate.h
+++ b/WebKit/WebView.subproj/WebHTMLViewPrivate.h
@@ -6,6 +6,7 @@
#import <WebKit/WebHTMLView.h>
+ at class WebArchive;
@class WebBridge;
@class WebView;
@class WebFrame;
@@ -71,6 +72,8 @@
+ (NSArray *)_selectionPasteboardTypes;
- (void)_writeSelectionToPasteboard:(NSPasteboard *)pasteboard;
+- (WebArchive *)_selectedArchive:(NSString **)markupString;
+- (NSData *)_selectedRTFData;
- (BOOL)_canDelete;
- (BOOL)_canPaste;
diff --git a/WebKit/WebView.subproj/WebImageView.h b/WebKit/WebView.subproj/WebImageView.h
index f342599..50ac401 100644
--- a/WebKit/WebView.subproj/WebImageView.h
+++ b/WebKit/WebView.subproj/WebImageView.h
@@ -3,11 +3,9 @@
Copyright 2002, Apple, Inc. All rights reserved.
*/
-#import <Cocoa/Cocoa.h>
+#import <WebKit/WebDocumentPrivate.h>
@class WebImageRepresentation;
- at protocol WebDocumentImage;
- at protocol WebDocumentView;
@interface WebImageView : NSView <WebDocumentView, WebDocumentImage>
{
diff --git a/WebKit/WebView.subproj/WebImageView.m b/WebKit/WebView.subproj/WebImageView.m
index 8b6e041..3319093 100644
--- a/WebKit/WebView.subproj/WebImageView.m
+++ b/WebKit/WebView.subproj/WebImageView.m
@@ -174,10 +174,10 @@
return [super validRequestorForSendType:sendType returnType:returnType];
}
-- (BOOL)writeImageToPasteboard:(NSPasteboard *)pasteboard
+- (BOOL)writeImageToPasteboard:(NSPasteboard *)pasteboard types:(NSArray *)types
{
if ([self haveCompleteImage]) {
- [pasteboard _web_writeImage:[rep image] URL:[rep URL] title:nil archive:[rep archive]];
+ [pasteboard _web_writeImage:[rep image] URL:[rep URL] title:nil archive:[rep archive] types:types];
return YES;
}
@@ -186,12 +186,12 @@
- (void)copy:(id)sender
{
- [self writeImageToPasteboard:[NSPasteboard generalPasteboard]];
+ [self writeImageToPasteboard:[NSPasteboard generalPasteboard] types:[NSPasteboard _web_writableTypesForImage]];
}
- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pasteboard types:(NSArray *)types
{
- return [self writeImageToPasteboard:pasteboard];
+ return [self writeImageToPasteboard:pasteboard types:types];
}
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
diff --git a/WebKit/WebView.subproj/WebTextView.h b/WebKit/WebView.subproj/WebTextView.h
index 6cc023f..36f12b6 100644
--- a/WebKit/WebView.subproj/WebTextView.h
+++ b/WebKit/WebView.subproj/WebTextView.h
@@ -1,17 +1,14 @@
/*
WebTextView.h
- Copyright 2002, Apple, Inc. All rights reserved.
+ Copyright 2002, Apple, Inc. All rights reserved.
*/
-#import <Cocoa/Cocoa.h>
-#import "WebSearchableTextView.h"
+#import <WebKit/WebDocumentPrivate.h>
+#import <WebKit/WebSearchableTextView.h>
@class WebDataSource;
- at protocol WebDocumentView;
- at protocol WebDocumentDragSettings;
- at protocol WebDocumentText;
- at interface WebTextView : WebSearchableTextView <WebDocumentView, WebDocumentText>
+ at interface WebTextView : WebSearchableTextView <WebDocumentView, WebDocumentText, WebDocumentSelection>
{
float _textSizeMultiplier;
}
diff --git a/WebKit/WebView.subproj/WebTextView.m b/WebKit/WebView.subproj/WebTextView.m
index 008ae84..b9af685 100644
--- a/WebKit/WebView.subproj/WebTextView.m
+++ b/WebKit/WebView.subproj/WebTextView.m
@@ -279,6 +279,16 @@
return [webView _menuForElement:element];
}
+- (NSArray *)pasteboardTypesForSelection
+{
+ return [self writablePasteboardTypes];
+}
+
+- (void)writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard
+{
+ [self writeSelectionToPasteboard:pasteboard types:types];
+}
+
// This approach could be relaxed when dealing with 3228554
- (BOOL)resignFirstResponder
{
diff --git a/WebKit/WebView.subproj/WebView.m b/WebKit/WebView.subproj/WebView.m
index dbec7b8..60e42be 100644
--- a/WebKit/WebView.subproj/WebView.m
+++ b/WebKit/WebView.subproj/WebView.m
@@ -113,6 +113,13 @@ NSString *_WebMainFrameURLKey = @"mainFrameURL";
@implementation WebProgressItem
@end
+ at interface WebView (WebViewEditingInternal)
+- (void)_alterCurrentSelection:(WebSelectionAlteration)alteration direction:(WebSelectionDirection)direction granularity:(WebSelectionGranularity)granularity;
+- (WebBridge *)_bridgeForCurrentSelection;
+- (BOOL)_currentSelectionIsEditable;
+ at end
+
+
@implementation WebViewPrivate
- init
@@ -1103,6 +1110,23 @@ NSString *_WebMainFrameURLKey = @"mainFrameURL";
return cachedResponse;
}
+- (void)_writeImageElement:(NSDictionary *)element withPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard
+{
+ NSURL *linkURL = [element objectForKey:WebElementLinkURLKey];
+ [pasteboard _web_writeImage:[element objectForKey:WebElementImageKey]
+ URL:linkURL ? linkURL : [element objectForKey:WebElementImageURLKey]
+ title:[element objectForKey:WebElementImageAltStringKey]
+ archive:[[element objectForKey:WebElementDOMNodeKey] webArchive]
+ types:types];
+}
+
+- (void)_writeLinkElement:(NSDictionary *)element withPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard
+{
+ [pasteboard _web_writeURL:[element objectForKey:WebElementLinkURLKey]
+ andTitle:[element objectForKey:WebElementLinkLabelKey]
+ types:types];
+}
+
@end
@@ -1644,28 +1668,27 @@ NS_ENDHANDLER
return _private->hostWindow;
}
-- (NSDragOperation)_dragOperationForDraggingInfo:(id <NSDraggingInfo>)sender
+- (NSDragOperation)dragOperationForDraggingInfo:(id <NSDraggingInfo>)sender
{
// Even though we may not be registered for any drag types, we may still get drag messages forwarded from WebHTMLView,
// so compare the types on the pasteboard against the types we're currently registered for.
- if ([_private->draggedTypes count] > 0 && [[sender draggingPasteboard] availableTypeFromArray:_private->draggedTypes] != nil) {
- return [self _web_dragOperationForDraggingInfo:sender];
+ NSPoint point = [[self superview] convertPoint:[sender draggingLocation] toView:nil];
+ if ([_private->draggedTypes count] > 0 &&
+ [[sender draggingPasteboard] availableTypeFromArray:_private->draggedTypes] != nil &&
+ ![[self hitTest:point] isKindOfClass:[WebBaseNetscapePluginView class]]) {
+ return [self _web_dragOperationForDraggingInfo:sender];
}
return NSDragOperationNone;
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
- return [self _dragOperationForDraggingInfo:sender];
+ return [self dragOperationForDraggingInfo:sender];
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
{
- NSPoint point = [[self superview] convertPoint:[sender draggingLocation] toView:nil];
- if ([[self hitTest:point] isKindOfClass:[WebBaseNetscapePluginView class]]) {
- return NSDragOperationNone;
- }
- return [self _dragOperationForDraggingInfo:sender];
+ return [self dragOperationForDraggingInfo:sender];
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
@@ -1680,7 +1703,7 @@ NS_ENDHANDLER
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
- if ([self _dragOperationForDraggingInfo:sender] != NSDragOperationNone) {
+ if ([self dragOperationForDraggingInfo:sender] != NSDragOperationNone) {
NSURL *URL = [[sender draggingPasteboard] _web_bestURL];
if (URL) {
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:URL];
@@ -1832,32 +1855,47 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
return _private->progressValue;
}
-- (NSDragOperation)dragOperationForDraggingInfo:(id <NSDraggingInfo>)draggingInfo
-{
- ERROR("unimplemented");
- return NSDragOperationNone;
-}
-
- (NSArray *)pasteboardTypesForSelection
{
- ERROR("unimplemented");
- return nil;
+ NSView <WebDocumentView> *documentView = [[[[self _bridgeForCurrentSelection] webFrame] frameView] documentView];
+ if ([documentView conformsToProtocol:@protocol(WebDocumentSelection)]) {
+ return [(NSView <WebDocumentSelection> *)documentView pasteboardTypesForSelection];
+ }
+ return [NSArray array];
}
- (void)writeSelectionWithPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard
{
- ERROR("unimplemented");
+ WebBridge *bridge = [self _bridgeForCurrentSelection];
+ if ([bridge haveSelection]) {
+ NSView <WebDocumentView> *documentView = [[[bridge webFrame] frameView] documentView];
+ if ([documentView conformsToProtocol:@protocol(WebDocumentSelection)]) {
+ [(NSView <WebDocumentSelection> *)documentView writeSelectionWithPasteboardTypes:types toPasteboard:pasteboard];
+ }
+ }
}
- (NSArray *)pasteboardTypesForElement:(NSDictionary *)element
{
- ERROR("unimplemented");
- return nil;
+ if ([element objectForKey:WebElementImageURLKey] != nil) {
+ return [NSPasteboard _web_writableTypesForImage];
+ } else if ([element objectForKey:WebElementLinkURLKey] != nil) {
+ return [NSPasteboard _web_writableTypesForURL];
+ } else if ([[element objectForKey:WebElementIsSelectedKey] boolValue]) {
+ return [self pasteboardTypesForSelection];
+ }
+ return [NSArray array];
}
- (void)writeElement:(NSDictionary *)element withPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard
{
- ERROR("unimplemented");
+ if ([element objectForKey:WebElementImageURLKey] != nil) {
+ [self _writeImageElement:element withPasteboardTypes:types toPasteboard:pasteboard];
+ } else if ([element objectForKey:WebElementLinkURLKey] != nil) {
+ [self _writeLinkElement:element withPasteboardTypes:types toPasteboard:pasteboard];
+ } else if ([[element objectForKey:WebElementIsSelectedKey] boolValue]) {
+ [self writeSelectionWithPasteboardTypes:types toPasteboard:pasteboard];
+ }
}
@end
@@ -2138,14 +2176,6 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
//==========================================================================================
// Editing
- at interface WebView (WebViewEditingInternal)
-
-- (void)_alterCurrentSelection:(WebSelectionAlteration)alteration direction:(WebSelectionDirection)direction granularity:(WebSelectionGranularity)granularity;
-- (WebBridge *)_bridgeForCurrentSelection;
-- (BOOL)_currentSelectionIsEditable;
-
- at end
-
@implementation WebView (WebViewEditingInternal)
- (void)_alterCurrentSelection:(WebSelectionAlteration)alteration direction:(WebSelectionDirection)direction granularity:(WebSelectionGranularity)granularity
diff --git a/WebKit/WebView.subproj/WebViewPrivate.h b/WebKit/WebView.subproj/WebViewPrivate.h
index 56434c7..672b8a3 100644
--- a/WebKit/WebView.subproj/WebViewPrivate.h
+++ b/WebKit/WebView.subproj/WebViewPrivate.h
@@ -271,6 +271,9 @@ Could be worth adding to the API.
- (NSCachedURLResponse *)_cachedResponseForURL:(NSURL *)URL;
+- (void)_writeImageElement:(NSDictionary *)element withPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard;
+- (void)_writeLinkElement:(NSDictionary *)element withPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard;
+
@end
@interface WebView (WebViewPrintingPrivate)
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list