summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Weidauer <sven@5sw.de>2017-06-07 22:33:07 +0200
committerSven Weidauer <sven@5sw.de>2017-06-07 22:33:07 +0200
commit8ce6d02fbd4fcf3a660812a7b9e5a60f2beca807 (patch)
tree851974fe816236bbe35dde7ff1b021579c99c909
parentf81e8a53d7f532f22da163f3bdd694184b8e72a8 (diff)
downloadnetsurf-8ce6d02fbd4fcf3a660812a7b9e5a60f2beca807.tar.gz
netsurf-8ce6d02fbd4fcf3a660812a7b9e5a60f2beca807.tar.bz2
Convert URLFieldCell to use dragging sessions instead of the deprecated dragImage:... method
-rw-r--r--frontends/cocoa/URLFieldCell.m48
1 files changed, 40 insertions, 8 deletions
diff --git a/frontends/cocoa/URLFieldCell.m b/frontends/cocoa/URLFieldCell.m
index 760052e38..54b240d02 100644
--- a/frontends/cocoa/URLFieldCell.m
+++ b/frontends/cocoa/URLFieldCell.m
@@ -21,7 +21,10 @@
#import "utils/nsurl.h"
#import "netsurf/url_db.h"
-@interface URLFieldCell ()
+@interface URLFieldCell () <
+ NSPasteboardWriting,
+ NSDraggingSource
+>
@property (nonatomic) NSButtonCell *refreshCell;
@@ -128,13 +131,14 @@
point.x -= urlBounds.size.height / 2;
point.y += urlBounds.size.height / 2;
- [view dragImage:image
- at:point
- offset:NSZeroSize
- event:[NSApp currentEvent]
- pasteboard:pb
- source:self
- slideBack:YES];
+ NSDraggingItem *item = [[NSDraggingItem alloc] initWithPasteboardWriter: self];
+ item.imageComponentsProvider = ^NSArray<NSDraggingImageComponent *> * _Nonnull{
+ NSDraggingImageComponent *component = [NSDraggingImageComponent draggingImageComponentWithKey: NSDraggingImageComponentIconKey];
+ component.contents = image;
+ return @[component];
+ };
+
+ [view beginDraggingSessionWithItems:@[item] event:NSApp.currentEvent source:self];
}
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
@@ -219,4 +223,32 @@
return self.refreshCell.action;
}
+- (nullable id) pasteboardPropertyListForType:(nonnull NSPasteboardType)type {
+ if ([type isEqualToString: NSPasteboardTypeString] || [type isEqualToString: @"public.url"]) {
+ return self.stringValue;
+ } else if ([type isEqualToString: @"public.url-name"]) {
+ nsurl *nsurl;
+
+ if (nsurl_create(self.stringValue.UTF8String, &nsurl) == NSERROR_OK) {
+
+ const struct url_data *data = urldb_get_url_data(nsurl);
+ nsurl_unref(nsurl);
+
+ if (data && data->title) {
+ return @(data->title);
+ }
+ }
+ }
+
+ return nil;
+}
+
+- (nonnull NSArray<NSPasteboardType> *) writableTypesForPasteboard:(nonnull NSPasteboard *)pasteboard {
+ return @[NSPasteboardTypeString, @"public.url", @"public.url-name"];
+}
+
+- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
+ return NSDragOperationCopy;
+}
+
@end