cocoawebview 0.3.0 → 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: a6429fedf1d1f28dd4375f23a4874920db7df15a3ad1b8385ae97332315f9031
4
- data.tar.gz: 2697a99cd838afd93bf2af09c9a5d32e94ca596685149d53cab3735249b4d8f4
3
+ metadata.gz: 643ce577a44fe54d0867d7a1586bb09bdcc8b8a1d0ae26f9e787fade103a525d
4
+ data.tar.gz: e76f126629df47a94301a706b9e8f6870c0d19bfa4034fc4f6bb409b20029a2b
5
5
  SHA512:
6
- metadata.gz: 4cdd3cd1510626f4ae76f0ed65005e3d934d6ce6dfb35a490ec3e2293be6fe2b740427f7add14642c6566769d8d688e6f64f866ca1dbdb7442d6e025739e1bd2
7
- data.tar.gz: 7ca9097dbfecace2f6bdbfb42674d2d8ec8ae52751dc2a1e4b79ec04415ffc7d1deb71c3e0e220c22399751c241789a8c063a428a34f3299460540be716707b4
6
+ metadata.gz: b99b40bcab82dc562da9f5c3d0a4b085fc32066651cd551cd3aba5f3f416cf07fc4326f5ef6a9348356fb4a15208ecde9dd67ddb04f87e7ddb851d4a15ee8827
7
+ data.tar.gz: f5e2323e5d2116388ed9be1f972a6269997dd3f7264d7d23773e0cda8c0a04d0b7a1e8eb5ee0fabfdc6d5313a769d50f3aea199ee84384274da2636ac6055827
@@ -24,6 +24,15 @@ 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);
28
+
29
+ @interface CocoaWKWebView : WKWebView
30
+ @property (nonatomic, strong) NSEvent *lastMouseDownEvent;
31
+ @end
32
+
33
+ @implementation CocoaWKWebView
34
+ @end
35
+
27
36
 
28
37
  @interface AppDelegate : NSObject <NSApplicationDelegate> {
29
38
  VALUE app;
@@ -41,8 +50,8 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
41
50
  }
42
51
  @end
43
52
 
44
- @interface CocoaWebview : NSWindow <WKScriptMessageHandler> {
45
- WKWebView *webView;
53
+ @interface CocoaWebview : NSWindow <WKScriptMessageHandler, NSDraggingSource> {
54
+ CocoaWKWebView *webView;
46
55
  VALUE rb_cocoawebview;
47
56
  BOOL showDevTool;
48
57
  BOOL shouldMoveTitleButtons;
@@ -53,6 +62,7 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
53
62
  - (void)eval:(NSString*)code;
54
63
  - (void)setCocoaWebview:(VALUE)view;
55
64
  - (void)dragging;
65
+ - (void)beginNativeFileDrag;
56
66
  @end
57
67
 
58
68
  @implementation CocoaWebview
@@ -80,6 +90,40 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
80
90
  return self;
81
91
  }
82
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
+
83
127
  - (void)setShouldMoveTitleButtons:(BOOL)flag {
84
128
  shouldMoveTitleButtons = flag;
85
129
  }
@@ -163,7 +207,7 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
163
207
 
164
208
  // Create the WKWebView with the configuration
165
209
  NSRect contentRect = [[window contentView] bounds];
166
- webView = [[WKWebView alloc] initWithFrame:contentRect configuration:config];
210
+ webView = [[CocoaWKWebView alloc] initWithFrame:contentRect configuration:config];
167
211
 
168
212
  // Enable autoresizing
169
213
  [webView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
@@ -224,6 +268,7 @@ Init_cocoawebview(void)
224
268
  rb_define_method(rb_mCocoaWebviewClass, "center", webview_center, 0);
225
269
  rb_define_method(rb_mCocoaWebviewClass, "visible?", webview_is_visible, 0);
226
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);
227
272
 
228
273
  }
229
274
 
@@ -411,3 +456,11 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost) {
411
456
  [webview setLevel:NSNormalWindowLevel];
412
457
  }
413
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.0"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoawebview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy Jeff
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-07-01 00:00:00.000000000 Z
10
+ date: 2025-07-03 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Webview ruby binding for macOS
13
13
  email: