cocoawebview 0.3.1 → 0.3.3
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 +54 -2
- data/lib/cocoawebview/version.rb +1 -1
- data/lib/cocoawebview.rb +4 -0
- 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: 4dfd6a0ea22013b05a7f7c4196895acbac3fa26ed812300710eba89533fb2f5c
|
4
|
+
data.tar.gz: 712c44cb10e4b5b012b26e50bcd57866d6fce83d84e230fa7bb1817627ac4590
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0870326d11a4edc86ee060ae0cec4d35e70b82de815a61a1a914aaf010ece4ba2b07ec214626c1c845d498de895afb841f50174047a6ea4d4ea16eb800d859e
|
7
|
+
data.tar.gz: c1703e437b9651bf3ea0e6cd25f526f735044ca9645a411e45368971d0eba72d28861617f76c36b8fd9fdb8c5f3a03b35daac5bc33c938f0c4901830070e5936
|
@@ -25,6 +25,50 @@ VALUE webview_center(VALUE self);
|
|
25
25
|
VALUE webview_is_visible(VALUE self);
|
26
26
|
VALUE webview_set_topmost(VALUE self, VALUE topmost);
|
27
27
|
|
28
|
+
@interface FileDropContainerView : NSView {
|
29
|
+
VALUE rb_cocoawebview;
|
30
|
+
}
|
31
|
+
|
32
|
+
- (void)setObj:(VALUE)o;
|
33
|
+
@end
|
34
|
+
|
35
|
+
@implementation FileDropContainerView
|
36
|
+
|
37
|
+
- (instancetype)initWithFrame:(NSRect)frame {
|
38
|
+
self = [super initWithFrame:frame];
|
39
|
+
if (self) {
|
40
|
+
[self registerForDraggedTypes:@[NSPasteboardTypeFileURL]];
|
41
|
+
}
|
42
|
+
return self;
|
43
|
+
}
|
44
|
+
|
45
|
+
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
|
46
|
+
return NSDragOperationCopy;
|
47
|
+
}
|
48
|
+
|
49
|
+
- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender {
|
50
|
+
return YES;
|
51
|
+
}
|
52
|
+
|
53
|
+
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
|
54
|
+
NSPasteboard *pasteboard = [sender draggingPasteboard];
|
55
|
+
NSArray<NSURL *> *fileURLs = [pasteboard readObjectsForClasses:@[[NSURL class]]
|
56
|
+
options:@{NSPasteboardURLReadingFileURLsOnlyKey: @YES}];
|
57
|
+
|
58
|
+
if (fileURLs.count > 0) {
|
59
|
+
NSString *filePath = fileURLs[0].path;
|
60
|
+
VALUE ruby_file_path = rb_str_new_cstr([filePath UTF8String]);
|
61
|
+
rb_funcall(rb_cocoawebview, rb_intern("file_did_drop"), 1, ruby_file_path);
|
62
|
+
return YES;
|
63
|
+
}
|
64
|
+
return NO;
|
65
|
+
}
|
66
|
+
|
67
|
+
- (void)setObj:(VALUE)o {
|
68
|
+
rb_cocoawebview = o;
|
69
|
+
}
|
70
|
+
@end
|
71
|
+
|
28
72
|
@interface CocoaWKWebView : WKWebView
|
29
73
|
@property (nonatomic, strong) NSEvent *lastMouseDownEvent;
|
30
74
|
@end
|
@@ -59,6 +103,7 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
|
|
59
103
|
VALUE rb_cocoawebview;
|
60
104
|
BOOL showDevTool;
|
61
105
|
BOOL shouldMoveTitleButtons;
|
106
|
+
FileDropContainerView *fileDropView;
|
62
107
|
}
|
63
108
|
- (void)setShouldMoveTitleButtons:(BOOL)flag;
|
64
109
|
- (void)setDevTool:(BOOL)flag;
|
@@ -146,6 +191,7 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
|
|
146
191
|
|
147
192
|
- (void)setCocoaWebview:(VALUE)view {
|
148
193
|
rb_cocoawebview = view;
|
194
|
+
[fileDropView setObj:view];
|
149
195
|
}
|
150
196
|
|
151
197
|
- (void)eval:(NSString*)code {
|
@@ -157,6 +203,11 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
|
|
157
203
|
}
|
158
204
|
|
159
205
|
- (void)addWebViewToWindow:(NSWindow *)window {
|
206
|
+
NSRect contentRect = [[window contentView] bounds];
|
207
|
+
|
208
|
+
fileDropView = [[FileDropContainerView alloc] initWithFrame:contentRect];
|
209
|
+
fileDropView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
210
|
+
|
160
211
|
WKUserContentController *userContentController = [[WKUserContentController alloc] init];
|
161
212
|
[userContentController addScriptMessageHandler:self name:@"native"];
|
162
213
|
|
@@ -175,7 +226,6 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
|
|
175
226
|
[[config preferences] setValue:@YES forKey:@"DOMPasteAllowed"];
|
176
227
|
|
177
228
|
// Create the WKWebView with the configuration
|
178
|
-
NSRect contentRect = [[window contentView] bounds];
|
179
229
|
webView = [[CocoaWKWebView alloc] initWithFrame:contentRect configuration:config];
|
180
230
|
|
181
231
|
// Enable autoresizing
|
@@ -189,7 +239,9 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
|
|
189
239
|
*/
|
190
240
|
|
191
241
|
// Add to window's contentView
|
192
|
-
[window
|
242
|
+
[[window contentView] addSubview:fileDropView];
|
243
|
+
//[[window contentView] addSubview: webView];
|
244
|
+
//[[window contentView] addSubview:fileDropView positioned:NSWindowAbove relativeTo:webView];
|
193
245
|
|
194
246
|
webView.navigationDelegate = self;
|
195
247
|
}
|
data/lib/cocoawebview/version.rb
CHANGED
data/lib/cocoawebview.rb
CHANGED
@@ -46,6 +46,10 @@ module CocoaWebview
|
|
46
46
|
puts "CocoaWebview did loaded"
|
47
47
|
end
|
48
48
|
|
49
|
+
def file_did_drop(file_path)
|
50
|
+
puts "#{file_path} dropped"
|
51
|
+
end
|
52
|
+
|
49
53
|
def bind(name, &block)
|
50
54
|
param_info = block.parameters
|
51
55
|
param_count = param_info.count { |type, _| type == :req || type == :opt }
|