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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb18e38b4326918bda4d126cbfea4917a5b34931185e20536402aa0c5854bfb2
4
- data.tar.gz: f6b1d04f8c067cb23dd837aebc7557f7df65bbd4f90f909b06b0e41c70d24a1b
3
+ metadata.gz: 643ce577a44fe54d0867d7a1586bb09bdcc8b8a1d0ae26f9e787fade103a525d
4
+ data.tar.gz: e76f126629df47a94301a706b9e8f6870c0d19bfa4034fc4f6bb409b20029a2b
5
5
  SHA512:
6
- metadata.gz: 2992271022820a0f681f75e5e420f6a1307f3c9a3f91bb1b32384e6d4191e820579b4e504aa1017263ff81da740065320a36012fb8713c54b4f9fcc2783dc5b5
7
- data.tar.gz: 966c3b7365ff87a3287e6d9749a38946084ddf59d6f29e31a5d6e23a8d14a5c3e88c6eb9bc3cd2427fc085a53f900bd19ab93124841882523e5f605f7d6db2e0
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
+ }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cocoawebview
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoawebview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy Jeff