This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview.go
188 lines (156 loc) · 5.61 KB
/
view.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package ultralight
// #cgo CPPFLAGS: -I"./SDK/include"
// #cgo windows LDFLAGS: -L'./SDK/lib' -lUltralight -lUltralightCore -lWebCore -lAppCore
// #cgo linux LDFLAGS: -L'./SDK/bin' -lUltralight -lUltralightCore -lWebCore -lAppCore -Wl,-rpath,.
// #cgo darwin LDFLAGS: -L'./SDK/bin' -lUltralight -lUltralightCore -lWebCore -lAppCore -Wl,-rpath,.
// #include <ultralight.h>
import "C"
import "unsafe"
// View wraps the underlying struct
type View struct {
v C.ULView
}
// JSBindFunc defines the structure of JavaScript callback functions, where
// 'params' is an array of the parameters passed to the JavaScript function
type JSBindFunc func(view *View, params []string) *JSValue
// CreateView creates a View instance with the specified size (in device coordinates)
func CreateView(rend *Renderer, width, height uint, isTransparent bool) *View {
return &View{C.ulCreateView(rend.r, C.uint(width), C.uint(height), C.bool(isTransparent))}
}
// Destroy deletes the View instance
func (view *View) Destroy() {
C.ulDestroyView(view.v)
}
// GetURL returns the current URL
func (view *View) GetURL() string {
return ulStrToStr(C.ulViewGetURL(view.v))
}
// GetTitle returns the current Title
func (view *View) GetTitle() string {
return ulStrToStr(C.ulViewGetTitle(view.v))
}
// IsLoading checks if the main frame is loading
func (view *View) IsLoading() bool {
return bool(C.ulViewIsLoading(view.v))
}
// IsBitmapDirty checks if the bitmap has changed since the last call to GetBitmap()
func (view *View) IsBitmapDirty() bool {
return bool(C.ulViewIsBitmapDirty(view.v))
}
// GetBitmap returns the bitmap representation of the View
func (view *View) GetBitmap() *Bitmap {
return &Bitmap{C.ulViewGetBitmap(view.v)}
}
// LoadHTML loads a raw string of HTML into the main frame
func (view *View) LoadHTML(html string) {
cHTML := C.CString(html)
defer C.free(unsafe.Pointer(cHTML))
C.ulViewLoadHTML(view.v, C.ulCreateString(cHTML))
}
// LoadURL loads the specified URL into the main frame
func (view *View) LoadURL(url string) {
cURL := C.CString(url)
defer C.free(unsafe.Pointer(cURL))
C.ulViewLoadURL(view.v, C.ulCreateString(cURL))
}
// Resize changes the View dimensions to the specified width
// and height (in device coordinates)
func (view *View) Resize(width, height uint) {
C.ulViewResize(view.v, C.uint(width), C.uint(height))
}
// GetJSContext gets the JSContext of the current page
func (view *View) GetJSContext() JSContext {
return JSContext{C.ulViewGetJSContext(view.v)}
}
// EvaluateScript evaluates a raw string of JavaScript, and
// returns the result
func (view *View) EvaluateScript(script string) string {
cScript := C.CString(script)
defer C.free(unsafe.Pointer(cScript))
return C.GoString(C.evaluateScript(view.v, C.ulCreateString(cScript)))
}
// CanGoBack checks if backwards history navigation is available
func (view *View) CanGoBack() bool {
return bool(C.ulViewCanGoBack(view.v))
}
// CanGoForward checks if forward history navigation is available
func (view *View) CanGoForward() bool {
return bool(C.ulViewCanGoForward(view.v))
}
// GoBack navigates backwards through the View history
func (view *View) GoBack() {
C.ulViewGoBack(view.v)
}
// GoForward navigates forwards through the View history
func (view *View) GoForward() {
C.ulViewGoForward(view.v)
}
// GoToHistoryOffset navigates to the specified offset in the View history
func (view *View) GoToHistoryOffset(offset int) {
C.ulViewGoToHistoryOffset(view.v, C.int(offset))
}
// Reload refreshes the current page
func (view *View) Reload() {
C.ulViewReload(view.v)
}
// Stop terminates all page loads
func (view *View) Stop() {
C.ulViewStop(view.v)
}
// FireKeyEvent will fire the supplied keyboard event
func (view *View) FireKeyEvent(event *KeyEvent) {
C.ulViewFireKeyEvent(view.v, event.ke)
}
// FireMouseEvent will fire the supplied mouse event
func (view *View) FireMouseEvent(event *MouseEvent) {
C.ulViewFireMouseEvent(view.v, event.me)
}
// FireScrollEvent will fire the supplied scroll event
func (view *View) FireScrollEvent(event *ScrollEvent) {
C.ulViewFireScrollEvent(view.v, event.se)
}
// NeedsPaint sets whether the View should be repainted during the next
// call to Renderer.Render()
func (view *View) NeedsPaint(needsPaint bool) {
C.ulViewSetNeedsPaint(view.v, C.bool(needsPaint))
}
// GetNeedsPaint returns whether the View should be painted during the
// next call to Renderer.Render()
func (view *View) GetNeedsPaint() bool {
return bool(C.ulViewGetNeedsPaint(view.v))
}
// BindJSCallback executes the specified function when a JavaScript call
// to the 'name' function is made
func (view *View) BindJSCallback(name string, function JSBindFunc) {
cName := C.CString(name)
defer C.free(unsafe.Pointer(cName))
funcMap[C.bindScript(view.v, cName)] = viewFunc{view, function}
}
// JSBindString will wrap a string value to be retuned by a bound Go function
func (view *View) JSBindString(val string) *JSValue {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
return &JSValue{
jv: C.makeJSValueString(view.v, cVal),
}
}
// JSBindBool will wrap a boolean value to be retuned by a bound Go function
func (view *View) JSBindBool(val bool) *JSValue {
return &JSValue{
jv: C.makeJSValueBool(view.v, C.bool(val)),
}
}
// JSBindNum will wrap a numeric value to be retuned by a bound Go function
func (view *View) JSBindNum(val float64) *JSValue {
return &JSValue{
jv: C.makeJSValueNum(view.v, C.double(val)),
}
}
// JSBindJSON will wrap a JSON string value to be retuned by a bound Go function
func (view *View) JSBindJSON(val string) *JSValue {
cVal := C.CString(val)
defer C.free(unsafe.Pointer(cVal))
return &JSValue{
jv: C.makeJSValueJSON(view.v, cVal),
}
}