cocoawebview 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/cocoawebview/cocoawebview.m +46 -6
- data/lib/cocoawebview/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 643ce577a44fe54d0867d7a1586bb09bdcc8b8a1d0ae26f9e787fade103a525d
|
4
|
+
data.tar.gz: e76f126629df47a94301a706b9e8f6870c0d19bfa4034fc4f6bb409b20029a2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b99b40bcab82dc562da9f5c3d0a4b085fc32066651cd551cd3aba5f3f416cf07fc4326f5ef6a9348356fb4a15208ecde9dd67ddb04f87e7ddb851d4a15ee8827
|
7
|
+
data.tar.gz: f5e2323e5d2116388ed9be1f972a6269997dd3f7264d7d23773e0cda8c0a04d0b7a1e8eb5ee0fabfdc6d5313a769d50f3aea199ee84384274da2636ac6055827
|
@@ -24,17 +24,13 @@ VALUE webview_set_title(VALUE self, VALUE title);
|
|
24
24
|
VALUE webview_center(VALUE self);
|
25
25
|
VALUE webview_is_visible(VALUE self);
|
26
26
|
VALUE webview_set_topmost(VALUE self, VALUE topmost);
|
27
|
+
VALUE webview_start_drag_drop(VALUE self);
|
27
28
|
|
28
29
|
@interface CocoaWKWebView : WKWebView
|
29
30
|
@property (nonatomic, strong) NSEvent *lastMouseDownEvent;
|
30
31
|
@end
|
31
32
|
|
32
33
|
@implementation CocoaWKWebView
|
33
|
-
|
34
|
-
- (void)mouseDown:(NSEvent *)event {
|
35
|
-
self.lastMouseDownEvent = event;
|
36
|
-
[super mouseDown:event];
|
37
|
-
}
|
38
34
|
@end
|
39
35
|
|
40
36
|
|
@@ -54,7 +50,7 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
|
|
54
50
|
}
|
55
51
|
@end
|
56
52
|
|
57
|
-
@interface CocoaWebview : NSWindow <WKScriptMessageHandler> {
|
53
|
+
@interface CocoaWebview : NSWindow <WKScriptMessageHandler, NSDraggingSource> {
|
58
54
|
CocoaWKWebView *webView;
|
59
55
|
VALUE rb_cocoawebview;
|
60
56
|
BOOL showDevTool;
|
@@ -66,6 +62,7 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
|
|
66
62
|
- (void)eval:(NSString*)code;
|
67
63
|
- (void)setCocoaWebview:(VALUE)view;
|
68
64
|
- (void)dragging;
|
65
|
+
- (void)beginNativeFileDrag;
|
69
66
|
@end
|
70
67
|
|
71
68
|
@implementation CocoaWebview
|
@@ -93,6 +90,40 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
|
|
93
90
|
return self;
|
94
91
|
}
|
95
92
|
|
93
|
+
- (void)beginNativeFileDrag {
|
94
|
+
NSString *filePath = @"/Users/rkt/Music/1.mp3";
|
95
|
+
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
|
96
|
+
|
97
|
+
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
|
98
|
+
NSLog(@"File doesn't exist");
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
|
102
|
+
NSPasteboardItem *item = [[NSPasteboardItem alloc] init];
|
103
|
+
[item setString:filePath forType:NSPasteboardTypeFileURL];
|
104
|
+
|
105
|
+
NSDraggingItem *dragItem = [[NSDraggingItem alloc] initWithPasteboardWriter:fileURL];
|
106
|
+
|
107
|
+
NSRect draggingRect = NSMakeRect(0, 0, 100, 30);
|
108
|
+
NSImage *dragImage = [[NSImage alloc] initWithSize:draggingRect.size];
|
109
|
+
[dragImage lockFocus];
|
110
|
+
[[NSColor grayColor] set];
|
111
|
+
NSRectFill(draggingRect);
|
112
|
+
[dragImage unlockFocus];
|
113
|
+
|
114
|
+
[dragItem setDraggingFrame:draggingRect contents:dragImage];
|
115
|
+
|
116
|
+
NSDraggingSession *session = [webView beginDraggingSessionWithItems:@[dragItem]
|
117
|
+
event:[NSApp currentEvent]
|
118
|
+
source:self];
|
119
|
+
session.animatesToStartingPositionsOnCancelOrFail = YES;
|
120
|
+
session.draggingFormation = NSDraggingFormationDefault;
|
121
|
+
}
|
122
|
+
|
123
|
+
- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context {
|
124
|
+
return NSDragOperationCopy;
|
125
|
+
}
|
126
|
+
|
96
127
|
- (void)setShouldMoveTitleButtons:(BOOL)flag {
|
97
128
|
shouldMoveTitleButtons = flag;
|
98
129
|
}
|
@@ -237,6 +268,7 @@ Init_cocoawebview(void)
|
|
237
268
|
rb_define_method(rb_mCocoaWebviewClass, "center", webview_center, 0);
|
238
269
|
rb_define_method(rb_mCocoaWebviewClass, "visible?", webview_is_visible, 0);
|
239
270
|
rb_define_method(rb_mCocoaWebviewClass, "set_topmost", webview_set_topmost, 1);
|
271
|
+
rb_define_method(rb_mCocoaWebviewClass, "start_drag_drop", webview_start_drag_drop, 0);
|
240
272
|
|
241
273
|
}
|
242
274
|
|
@@ -424,3 +456,11 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost) {
|
|
424
456
|
[webview setLevel:NSNormalWindowLevel];
|
425
457
|
}
|
426
458
|
}
|
459
|
+
|
460
|
+
VALUE webview_start_drag_drop(VALUE self) {
|
461
|
+
VALUE wrapper = rb_ivar_get(self, rb_intern("@webview"));
|
462
|
+
CocoaWebview *webview;
|
463
|
+
TypedData_Get_Struct(wrapper, CocoaWebview, &cocoawebview_obj_type, webview);
|
464
|
+
|
465
|
+
[webview beginNativeFileDrag];
|
466
|
+
}
|
data/lib/cocoawebview/version.rb
CHANGED