webview_ruby2 0.1.1 → 0.2.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 +4 -4
- data/ext/webview/webview.h +68 -8
- data/lib/webview_ruby/version.rb +1 -1
- data/lib/webview_ruby.rb +19 -4
- 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: 3f6c1853c996c6411146688954116f2bd6325290ed6f71020e2df71bab7352c0
|
4
|
+
data.tar.gz: 68f16f8d2fb60a768a863d80ac8ddc3be0465687fb3e62dfdffda343a6d434e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 490f3bed05d9875c39d45ee6073b7a564ea20c2bd7d5889bd2094054c1ff0a83049104e15b5054a35889dbe57985351d893bc052e6c76b7cc6803d07e3f3daa7
|
7
|
+
data.tar.gz: 206b3e1c83c61c6827d736f74514972253ff31aa674081a503c7fa0a9e922f70119e877bad1c879a18b2c2d4b90e97c091d856a537b2f5502504f7f0c871ccff
|
data/ext/webview/webview.h
CHANGED
@@ -66,6 +66,15 @@ WEBVIEW_API void *webview_get_window(webview_t w);
|
|
66
66
|
// Updates the title of the native window. Must be called from the UI thread.
|
67
67
|
WEBVIEW_API void webview_set_title(webview_t w, const char *title);
|
68
68
|
|
69
|
+
// Update the background color of the native window
|
70
|
+
WEBVIEW_API void webview_set_bg(webview_t w, double r, double g, double b, double a);
|
71
|
+
|
72
|
+
// Update the position of the native window
|
73
|
+
WEBVIEW_API void webview_set_pos(webview_t w, int x, int y);
|
74
|
+
|
75
|
+
// Get x positionof native window
|
76
|
+
WEBVIEW_API int webview_get_x(webview_t w);
|
77
|
+
|
69
78
|
// Window size hints
|
70
79
|
#define WEBVIEW_HINT_NONE 0 // Width and height are default size
|
71
80
|
#define WEBVIEW_HINT_MIN 1 // Width and height are minimum bounds
|
@@ -73,7 +82,7 @@ WEBVIEW_API void webview_set_title(webview_t w, const char *title);
|
|
73
82
|
#define WEBVIEW_HINT_FIXED 3 // Window size can not be changed by a user
|
74
83
|
// Updates native window size. See WEBVIEW_HINT constants.
|
75
84
|
WEBVIEW_API void webview_set_size(webview_t w, int width, int height,
|
76
|
-
int hints);
|
85
|
+
int hints, int margin_top, bool resizable);
|
77
86
|
|
78
87
|
// Navigates webview to the given URL. URL may be a data URI, i.e.
|
79
88
|
// "data:text/text,<html>...</html>". It is often ok not to url-encode it
|
@@ -603,6 +612,8 @@ id operator"" _str(const char *s, std::size_t) {
|
|
603
612
|
|
604
613
|
class cocoa_wkwebview_engine {
|
605
614
|
public:
|
615
|
+
int pos_x = 0;
|
616
|
+
int pos_y = 0;
|
606
617
|
cocoa_wkwebview_engine(bool debug, void *window) {
|
607
618
|
// Application
|
608
619
|
id app = ((id(*)(id, SEL))objc_msgSend)("NSApplication"_cls,
|
@@ -705,6 +716,7 @@ public:
|
|
705
716
|
},
|
706
717
|
};
|
707
718
|
)script");
|
719
|
+
|
708
720
|
((void (*)(id, SEL, id))objc_msgSend)(m_window, "setContentView:"_sel,
|
709
721
|
m_webview);
|
710
722
|
((void (*)(id, SEL, id))objc_msgSend)(m_window, "makeKeyAndOrderFront:"_sel,
|
@@ -734,25 +746,56 @@ public:
|
|
734
746
|
delete f;
|
735
747
|
}));
|
736
748
|
}
|
749
|
+
|
750
|
+
void set_pos(int x, int y) {
|
751
|
+
((void (*)(id, SEL, CGPoint))objc_msgSend)(
|
752
|
+
m_window, "setFrameOrigin:"_sel,
|
753
|
+
CGPointMake(x, y)
|
754
|
+
);
|
755
|
+
this->pos_x = x;
|
756
|
+
}
|
757
|
+
|
758
|
+
int get_x() {
|
759
|
+
return this->pos_x;
|
760
|
+
}
|
761
|
+
|
762
|
+
void set_bg(double r, double g, double b, double a) {
|
763
|
+
((void (*)(id, SEL, id))objc_msgSend)(
|
764
|
+
m_window, "setBackgroundColor:"_sel,
|
765
|
+
((id(*)(id, SEL, double, double, double, double))objc_msgSend)(
|
766
|
+
"NSColor"_cls, "colorWithRed:green:blue:alpha:"_sel, r, g, b, a));
|
767
|
+
}
|
768
|
+
|
737
769
|
void set_title(const std::string title) {
|
738
770
|
((void (*)(id, SEL, id))objc_msgSend)(
|
739
771
|
m_window, "setTitle:"_sel,
|
740
772
|
((id(*)(id, SEL, const char *))objc_msgSend)(
|
741
773
|
"NSString"_cls, "stringWithUTF8String:"_sel, title.c_str()));
|
742
774
|
}
|
743
|
-
void set_size(int width, int height, int hints) {
|
744
|
-
|
745
|
-
|
746
|
-
|
775
|
+
void set_size(int width, int height, int hints, int margin_top, bool resizable) {
|
776
|
+
int style;
|
777
|
+
if (resizable) {
|
778
|
+
style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
|
779
|
+
NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable | NSWindowStyleMaskFullSizeContentView;
|
780
|
+
} else {
|
781
|
+
style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
|
782
|
+
NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskFullSizeContentView;
|
783
|
+
}
|
747
784
|
|
785
|
+
/*
|
748
786
|
((void (*)(id, SEL, unsigned long))objc_msgSend)(
|
749
787
|
m_window, "setTitleVisibility:"_sel, NSWindowTitleHidden);
|
788
|
+
*/
|
750
789
|
|
751
790
|
((void (*)(id, SEL, unsigned long))objc_msgSend)(
|
752
791
|
m_window, "setTitlebarAppearsTransparent:"_sel, 1);
|
753
792
|
|
793
|
+
((void (*)(id, SEL, unsigned long))objc_msgSend)(
|
794
|
+
m_window, "setMovableByWindowBackground:"_sel, 1);
|
795
|
+
|
796
|
+
|
754
797
|
if (hints != WEBVIEW_HINT_FIXED) {
|
755
|
-
|
798
|
+
//style = style | NSWindowStyleMaskResizable;
|
756
799
|
}
|
757
800
|
((void (*)(id, SEL, unsigned long))objc_msgSend)(
|
758
801
|
m_window, "setStyleMask:"_sel, style);
|
@@ -767,6 +810,11 @@ public:
|
|
767
810
|
((void (*)(id, SEL, CGRect, BOOL, BOOL))objc_msgSend)(
|
768
811
|
m_window, "setFrame:display:animate:"_sel,
|
769
812
|
CGRectMake(0, 0, width, height), 1, 0);
|
813
|
+
|
814
|
+
((void (*)(id, SEL, CGRect))objc_msgSend)(
|
815
|
+
m_webview, "setFrame:"_sel,
|
816
|
+
CGRectMake(0, 0, width, height - margin_top));
|
817
|
+
|
770
818
|
}
|
771
819
|
((void (*)(id, SEL))objc_msgSend)(m_window, "center"_sel);
|
772
820
|
}
|
@@ -1341,9 +1389,21 @@ WEBVIEW_API void webview_set_title(webview_t w, const char *title) {
|
|
1341
1389
|
static_cast<webview::webview *>(w)->set_title(title);
|
1342
1390
|
}
|
1343
1391
|
|
1392
|
+
WEBVIEW_API void webview_set_bg(webview_t w, double r, double g, double b, double a) {
|
1393
|
+
static_cast<webview::webview *>(w)->set_bg(r, g, b, a);
|
1394
|
+
}
|
1395
|
+
|
1396
|
+
WEBVIEW_API void webview_set_pos(webview_t w, int x, int y) {
|
1397
|
+
static_cast<webview::webview *>(w)->set_pos(x, y);
|
1398
|
+
}
|
1399
|
+
|
1400
|
+
WEBVIEW_API int webview_get_x(webview_t w) {
|
1401
|
+
static_cast<webview::webview *>(w)->get_x();
|
1402
|
+
}
|
1403
|
+
|
1344
1404
|
WEBVIEW_API void webview_set_size(webview_t w, int width, int height,
|
1345
|
-
int hints) {
|
1346
|
-
static_cast<webview::webview *>(w)->set_size(width, height, hints);
|
1405
|
+
int hints, int margin_top, bool resizable) {
|
1406
|
+
static_cast<webview::webview *>(w)->set_size(width, height, hints, margin_top, resizable);
|
1347
1407
|
}
|
1348
1408
|
|
1349
1409
|
WEBVIEW_API void webview_navigate(webview_t w, const char *url) {
|
data/lib/webview_ruby/version.rb
CHANGED
data/lib/webview_ruby.rb
CHANGED
@@ -12,12 +12,15 @@ module WebviewRuby
|
|
12
12
|
attach_function :webview_run, [:pointer], :void
|
13
13
|
attach_function :webview_terminate, [:pointer], :void
|
14
14
|
attach_function :webview_set_title, [:pointer, :string], :void
|
15
|
-
attach_function :
|
15
|
+
attach_function :webview_set_pos, [:pointer, :int, :int], :void
|
16
|
+
attach_function :webview_set_bg, [:pointer, :double, :double, :double, :double], :void
|
17
|
+
attach_function :webview_set_size, [:pointer, :int, :int, :int, :int, :bool], :void
|
16
18
|
attach_function :webview_navigate, [:pointer, :string], :void
|
17
19
|
attach_function :webview_destroy, [:pointer], :void
|
18
20
|
attach_function :webview_bind, [:pointer, :string, :pointer, :pointer], :void
|
19
21
|
attach_function :webview_eval, [:pointer, :string], :void
|
20
22
|
attach_function :webview_init, [:pointer, :string], :void
|
23
|
+
attach_function :webview_get_x, [:pointer], :int
|
21
24
|
|
22
25
|
class Webview
|
23
26
|
attr_reader :is_running
|
@@ -28,12 +31,24 @@ module WebviewRuby
|
|
28
31
|
@window = WebviewRuby.webview_create(debug ? 1 : 0, nil)
|
29
32
|
end
|
30
33
|
|
34
|
+
def get_x()
|
35
|
+
WebviewRuby.webview_get_x(@window)
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_pos(x, y)
|
39
|
+
WebviewRuby.webview_set_pos(@window, x, y)
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_bg(r, g, b, a)
|
43
|
+
WebviewRuby.webview_set_bg(@window, r, g, b, a)
|
44
|
+
end
|
45
|
+
|
31
46
|
def set_title(title)
|
32
47
|
WebviewRuby.webview_set_title(@window, title)
|
33
48
|
end
|
34
49
|
|
35
|
-
def set_size(width, height, hint=0)
|
36
|
-
WebviewRuby.webview_set_size(@window, width, height, hint)
|
50
|
+
def set_size(width, height, hint=0, margin_top=26, resizable=true)
|
51
|
+
WebviewRuby.webview_set_size(@window, width, height, hint, margin_top, resizable)
|
37
52
|
end
|
38
53
|
|
39
54
|
def navigate(page)
|
@@ -56,7 +71,7 @@ module WebviewRuby
|
|
56
71
|
|
57
72
|
def bind(name, func=nil, &block)
|
58
73
|
callback = FFI::Function.new(:void, [:string, :string, :pointer]) do |seq, req, arg|
|
59
|
-
begin
|
74
|
+
begin
|
60
75
|
params = JSON.parse(req)
|
61
76
|
if func
|
62
77
|
func(*params)
|