cocoawebview 0.2.10 → 0.3.1

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: bf110ec9ea94b5606dbaa5636e433a90d270658858a8aaa0cd9d119b2d214712
4
- data.tar.gz: f44dcefabcf6dcc713cec9be86fd79888eedca31a9d921de046518707d18687b
3
+ metadata.gz: fb18e38b4326918bda4d126cbfea4917a5b34931185e20536402aa0c5854bfb2
4
+ data.tar.gz: f6b1d04f8c067cb23dd837aebc7557f7df65bbd4f90f909b06b0e41c70d24a1b
5
5
  SHA512:
6
- metadata.gz: 7397d6370ce8eac4393adb458f2a83d51fe98730b4836a2497843b4df2c33d900695471f3735236b14db7539c789b6d7fe547705833eae613d275cdb06558ee7
7
- data.tar.gz: fa1400d3b9337b9263fbbab762d887882b21fe3c8498a9c673a485ff0bd1640703df5b1006f565fb93c5f2904d8fee5a532ca4b59cd2ce09ed923fd3f4bdf6e3
6
+ metadata.gz: 2992271022820a0f681f75e5e420f6a1307f3c9a3f91bb1b32384e6d4191e820579b4e504aa1017263ff81da740065320a36012fb8713c54b4f9fcc2783dc5b5
7
+ data.tar.gz: 966c3b7365ff87a3287e6d9749a38946084ddf59d6f29e31a5d6e23a8d14a5c3e88c6eb9bc3cd2427fc085a53f900bd19ab93124841882523e5f605f7d6db2e0
@@ -11,7 +11,7 @@ VALUE nsapp_initialize(VALUE self);
11
11
  VALUE nsapp_run(VALUE self);
12
12
  VALUE nsapp_exit(VALUE self);
13
13
 
14
- VALUE webview_initialize(VALUE self, VALUE debug, VALUE style);
14
+ VALUE webview_initialize(VALUE self, VALUE debug, VALUE style, VALUE move_title_buttons);
15
15
  VALUE webview_show(VALUE self);
16
16
  VALUE webview_hide(VALUE self);
17
17
  VALUE webview_eval(VALUE self, VALUE code);
@@ -25,6 +25,19 @@ 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 CocoaWKWebView : WKWebView
29
+ @property (nonatomic, strong) NSEvent *lastMouseDownEvent;
30
+ @end
31
+
32
+ @implementation CocoaWKWebView
33
+
34
+ - (void)mouseDown:(NSEvent *)event {
35
+ self.lastMouseDownEvent = event;
36
+ [super mouseDown:event];
37
+ }
38
+ @end
39
+
40
+
28
41
  @interface AppDelegate : NSObject <NSApplicationDelegate> {
29
42
  VALUE app;
30
43
  }
@@ -42,19 +55,21 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
42
55
  @end
43
56
 
44
57
  @interface CocoaWebview : NSWindow <WKScriptMessageHandler> {
45
- WKWebView *webView;
58
+ CocoaWKWebView *webView;
46
59
  VALUE rb_cocoawebview;
47
60
  BOOL showDevTool;
61
+ BOOL shouldMoveTitleButtons;
48
62
  }
63
+ - (void)setShouldMoveTitleButtons:(BOOL)flag;
49
64
  - (void)setDevTool:(BOOL)flag;
50
- - (id)initWithFrame:(NSRect)frame debug:(BOOL)flag style:(int)style;
65
+ - (id)initWithFrame:(NSRect)frame debug:(BOOL)flag style:(int)style moveTitleButtons:(BOOL)moveTitleButtons;
51
66
  - (void)eval:(NSString*)code;
52
67
  - (void)setCocoaWebview:(VALUE)view;
53
68
  - (void)dragging;
54
69
  @end
55
70
 
56
71
  @implementation CocoaWebview
57
- - (id)initWithFrame:(NSRect)frame debug:(BOOL)flag style:(int)style{
72
+ - (id)initWithFrame:(NSRect)frame debug:(BOOL)flag style:(int)style moveTitleButtons:(BOOL)moveTitleButtons{
58
73
  self = [super initWithContentRect:frame
59
74
  styleMask:style
60
75
  backing:NSBackingStoreBuffered
@@ -66,10 +81,42 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
66
81
  [self setTitlebarAppearsTransparent: YES];
67
82
  [self setTitleVisibility:NSWindowTitleHidden];
68
83
  [self addWebViewToWindow:self];
84
+ [self setShouldMoveTitleButtons:moveTitleButtons];
85
+ if (moveTitleButtons) {
86
+ [self moveWindowButtonsForWindow:self];
87
+ }
88
+ [[NSNotificationCenter defaultCenter] addObserver:self
89
+ selector:@selector(windowDidResize:)
90
+ name:NSWindowDidResizeNotification
91
+ object:self];
69
92
  }
70
93
  return self;
71
94
  }
72
95
 
96
+ - (void)setShouldMoveTitleButtons:(BOOL)flag {
97
+ shouldMoveTitleButtons = flag;
98
+ }
99
+
100
+ - (void)windowDidResize:(NSNotification *)notification {
101
+ if (shouldMoveTitleButtons) {
102
+ [self moveWindowButtonsForWindow:self];
103
+ }
104
+ }
105
+
106
+ - (void)moveWindowButtonsForWindow:(NSWindow *)window {
107
+ //Close Button
108
+ NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton];
109
+ [closeButton setFrameOrigin:NSMakePoint(closeButton.frame.origin.x + 10, closeButton.frame.origin.y - 10)];
110
+
111
+ //Minimize Button
112
+ NSButton *minimizeButton = [window standardWindowButton:NSWindowMiniaturizeButton];
113
+ [minimizeButton setFrameOrigin:NSMakePoint(minimizeButton.frame.origin.x + 10, minimizeButton.frame.origin.y - 10)];
114
+
115
+ //Zoom Button
116
+ NSButton *zoomButton = [window standardWindowButton:NSWindowZoomButton];
117
+ [zoomButton setFrameOrigin:NSMakePoint(zoomButton.frame.origin.x + 10, zoomButton.frame.origin.y - 10)];
118
+ }
119
+
73
120
  - (void)close {
74
121
  [self orderOut:nil]; // Hide instead of destroy
75
122
  }
@@ -129,7 +176,7 @@ VALUE webview_set_topmost(VALUE self, VALUE topmost);
129
176
 
130
177
  // Create the WKWebView with the configuration
131
178
  NSRect contentRect = [[window contentView] bounds];
132
- webView = [[WKWebView alloc] initWithFrame:contentRect configuration:config];
179
+ webView = [[CocoaWKWebView alloc] initWithFrame:contentRect configuration:config];
133
180
 
134
181
  // Enable autoresizing
135
182
  [webView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
@@ -177,7 +224,7 @@ Init_cocoawebview(void)
177
224
 
178
225
  /* CocoaWebview */
179
226
  rb_mCocoaWebviewClass = rb_define_class_under(rb_mCocoawebview, "CocoaWebview", rb_cObject);
180
- rb_define_method(rb_mCocoaWebviewClass, "initialize", webview_initialize, 2);
227
+ rb_define_method(rb_mCocoaWebviewClass, "initialize", webview_initialize, 3);
181
228
  rb_define_method(rb_mCocoaWebviewClass, "show", webview_show, 0);
182
229
  rb_define_method(rb_mCocoaWebviewClass, "hide", webview_hide, 0);
183
230
  rb_define_method(rb_mCocoaWebviewClass, "eval", webview_eval, 1);
@@ -210,7 +257,7 @@ VALUE nsapp_exit(VALUE self) {
210
257
  [[NSApplication sharedApplication] terminate:nil];
211
258
  }
212
259
 
213
- VALUE webview_initialize(VALUE self, VALUE debug, VALUE style) {
260
+ VALUE webview_initialize(VALUE self, VALUE debug, VALUE style, VALUE move_title_buttons) {
214
261
  rb_iv_set(self, "@var", rb_hash_new());
215
262
  rb_iv_set(self, "@bindings", rb_hash_new());
216
263
  BOOL flag = NO;
@@ -220,8 +267,14 @@ VALUE webview_initialize(VALUE self, VALUE debug, VALUE style) {
220
267
  flag = NO;
221
268
  }
222
269
 
270
+ BOOL c_move_title_buttons = NO;
271
+ if (move_title_buttons == Qtrue) {
272
+ c_move_title_buttons = YES;
273
+ } else {
274
+ c_move_title_buttons = NO;
275
+ }
223
276
  int c_style = NUM2INT(style);
224
- CocoaWebview *webview = [[CocoaWebview alloc] initWithFrame:NSMakeRect(100, 100, 400, 500) debug:flag style:c_style];
277
+ CocoaWebview *webview = [[CocoaWebview alloc] initWithFrame:NSMakeRect(100, 100, 400, 500) debug:flag style:c_style moveTitleButtons:c_move_title_buttons];
225
278
 
226
279
  [webview setReleasedWhenClosed:NO];
227
280
  [webview setCocoaWebview:self];
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cocoawebview
4
- VERSION = "0.2.10"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/cocoawebview.rb CHANGED
@@ -24,7 +24,7 @@ module CocoaWebview
24
24
  class CocoaWebview
25
25
  attr_accessor :callback
26
26
 
27
- def self.create(debug: false, min: true, resize: true, close: true, &block)
27
+ def self.create(debug: false, min: true, resize: true, close: true, move_title_buttons: false, &block)
28
28
  style = NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView
29
29
 
30
30
  style = style | NSWindowStyleMaskMiniaturizable if min
@@ -33,7 +33,7 @@ module CocoaWebview
33
33
 
34
34
  style &= ~NSWindowStyleMaskFullScreen
35
35
 
36
- webview = new(debug, style)
36
+ webview = new(debug, style, move_title_buttons)
37
37
  webview.callback = block
38
38
  webview
39
39
  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.2.10
4
+ version: 0.3.1
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: