summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/mac/PasteboardMac.mm
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/platform/mac/PasteboardMac.mm')
-rw-r--r--Source/WebCore/platform/mac/PasteboardMac.mm45
1 files changed, 44 insertions, 1 deletions
diff --git a/Source/WebCore/platform/mac/PasteboardMac.mm b/Source/WebCore/platform/mac/PasteboardMac.mm
index 0625287..71e4046 100644
--- a/Source/WebCore/platform/mac/PasteboardMac.mm
+++ b/Source/WebCore/platform/mac/PasteboardMac.mm
@@ -191,7 +191,7 @@ void Pasteboard::writeSelection(NSPasteboard* pasteboard, Range* selectedRange,
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.
- String text = selectedRange->text();
+ String text = frame->editor()->selectedText();
NSMutableString *s = [[[(NSString*)text copy] autorelease] mutableCopy];
NSString *NonBreakingSpaceString = [NSString stringWithCharacters:&noBreakSpace length:1];
@@ -436,7 +436,50 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart)
return URL;
}
+
+NSURL *Pasteboard::getBestURL(Frame* frame)
+{
+ NSArray *types = [m_pasteboard.get() types];
+
+ // FIXME: using the editorClient to call into webkit, for now, since
+ // calling webkit_canonicalize from WebCore involves migrating a sizable amount of
+ // helper code that should either be done in a separate patch or figured out in another way.
+
+ if ([types containsObject:NSURLPboardType]) {
+ NSURL *URLFromPasteboard = [NSURL URLFromPasteboard:m_pasteboard.get()];
+ NSString *scheme = [URLFromPasteboard scheme];
+ if ([scheme isEqualToString:@"http"] || [scheme isEqualToString:@"https"]) {
+ return frame->editor()->client()->canonicalizeURL(URLFromPasteboard);
+ }
+ }
+
+ if ([types containsObject:NSStringPboardType]) {
+ NSString *URLString = [m_pasteboard.get() stringForType:NSStringPboardType];
+ NSURL *URL = frame->editor()->client()->canonicalizeURLString(URLString);
+ if (URL)
+ return URL;
+ }
+
+ if ([types containsObject:NSFilenamesPboardType]) {
+ NSArray *files = [m_pasteboard.get() propertyListForType:NSFilenamesPboardType];
+ // FIXME: Maybe it makes more sense to allow multiple files and only use the first one?
+ if ([files count] == 1) {
+ NSString *file = [files objectAtIndex:0];
+ BOOL isDirectory;
+ if ([[NSFileManager defaultManager] fileExistsAtPath:file isDirectory:&isDirectory] && isDirectory)
+ return nil;
+ return frame->editor()->client()->canonicalizeURL([NSURL fileURLWithPath:file]);
+ }
+ }
+ return nil;
+}
+
+String Pasteboard::asURL(Frame* frame)
+{
+ return [getBestURL(frame) absoluteString];
+}
+
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText)
{
NSArray *types = [m_pasteboard.get() types];