43 Commits

Author SHA1 Message Date
Beng Tan
182fef7949 Handle binding of variadic functions (Go) (#338) 2020-04-07 19:36:34 +02:00
Beng Tan
d62dd8e3a7 (Go) Don't delete binding after it is called. (#337) 2020-04-07 19:36:19 +02:00
John Refior
10ddbc570a Add function and method comments to Go code (#321)
Augment package godoc by copying function comments from C source to Go
code and making minor edits.

Current godoc shows a [useful
interface](https://godoc.org/github.com/zserge/webview#WebView), but no
documentation on how to use its functions. I discovered the C code was
well documented, and copied function documentation over, adapting them
to the pattern of beginning each function comment with the name of the
function.

After changes:

```
$ go doc -all .

package webview // import "github.com/zserge/webview"

CONSTANTS

const (
	// Width and height are default size
	HintNone = C.WEBVIEW_HINT_NONE

	// Window size can not be changed by a user
	HintFixed = C.WEBVIEW_HINT_FIXED

	// Width and height are minimum bounds
	HintMin = C.WEBVIEW_HINT_MIN

	// Width and height are maximum bounds
	HintMax = C.WEBVIEW_HINT_MAX
)

TYPES

type Hint int
    Hints are used to configure window sizing and resizing

type WebView interface {

	// Run runs the main loop until it's terminated. After this function exits -
	// you must destroy the webview.
	Run()

	// Terminate stops the main loop. It is safe to call this function from
	// a background thread.
	Terminate()

	// Dispatch posts a function to be executed on the main thread. You normally
	// do not need to call this function, unless you want to tweak the native
	// window.
	Dispatch(f func())

	// Destroy destroys a webview and closes the native window.
	Destroy()

	// Window returns a native window handle pointer. When using GTK backend the
	// pointer is GtkWindow pointer, when using Cocoa backend the pointer is
	// NSWindow pointer, when using Win32 backend the pointer is HWND pointer.
	Window() unsafe.Pointer

	// SetTitle updates the title of the native window. Must be called from the UI
	// thread.
	SetTitle(title string)

	// SetSize updates native window size. See Hint constants.
	SetSize(w int, h int, hint Hint)

	// Navigate navigates webview to the given URL. URL may be a data URI, i.e.
	// "data:text/text,<html>...</html>". It is often ok not to url-encode it
	// properly, webview will re-encode it for you.
	Navigate(url string)

	// Init injects JavaScript code at the initialization of the new page. Every
	// time the webview will open a the new page - this initialization code will
	// be executed. It is guaranteed that code is executed before window.onload.
	Init(js string)

	// Eval evaluates arbitrary JavaScript code. Evaluation happens asynchronously,
	// also the result of the expression is ignored. Use RPC bindings if you want
	// to receive notifications about the results of the evaluation.
	Eval(js string)

	// Bind binds a callback function so that it will appear under the given name
	// as a global JavaScript function. Internally it uses webview_init().
	// Callback receives a request string and a user-provided argument pointer.
	// Request string is a JSON array of all the arguments passed to the
	// JavaScript function.
	//
	// f must be a function
	// f must return either value and error or just error
	Bind(name string, f interface{}) error
}

func New(debug bool) WebView
    New calls NewWindow to create a new window and a new webview instance. If
    debug is non-zero - developer tools will be enabled (if the platform
    supports them).

func NewWindow(debug bool, window unsafe.Pointer) WebView
    NewWindow creates a new webview instance. If debug is non-zero - developer
    tools will be enabled (if the platform supports them). Window parameter can
    be a pointer to the native window handle. If it's non-null - then child
    WebView is embedded into the given parent window. Otherwise a new window is
    created. Depending on the platform, a GtkWindow, NSWindow or HWND pointer
    can be passed here.
```
2020-03-07 10:09:06 +01:00
Serge A. Zaitsev
843c3aaba6 merge webview-x branch 2020-03-01 22:38:52 +01:00
Deomid Ryabkov
1a9ebffc26 FIx build on Mac OS X Catalina / XCode 11 (#298)
Fixes https://github.com/zserge/webview/issues/297
2019-11-03 19:45:48 +01:00
Jeremy Legendre
e94d679fff Objc-runtime re-write (#181)
* objc-runtime re-write

Cocoa version completely re-written in pure C.

Notes:
- No need to pass '-x', '-ObjC', or Cocoa framework flags to GCC anymore
- - Readme and various build files updated
- CoreGraphics.h needed for drawing windows
-Formatted with clang-format

* Made methods static for Go compatibility
2018-08-17 08:47:15 +02:00
Serge A. Zaitsev
46e124853a go: fix build 2018-03-25 14:01:11 +03:00
SkyrisBactera
1efca206df Make it actually work on windows (#108)
This causes an error on windows because -mwindows is not a proper flag
2018-02-19 16:38:58 +02:00
1l0
af1a71c17d go: Eval return error, objc: eval return -1 (#88) 2018-01-27 11:44:21 +02:00
1l0
7fd11d26d7 cocoa: window color (new proposal) (#73)
* window color

* separate RGBA parameters to be double
see examples/window-go as a demo

* example: SetColor before Run

* uint8_t as RGBA parameters
see examples/window-go as a demo

* WINAPI: add stdint.h

* add stdint.h globally
2018-01-22 01:02:13 +02:00
Serge A. Zaitsev
86f461e241 go: add freebsd support 2018-01-11 12:07:26 +02:00
Serge A. Zaitsev
a29901bbea gtk: implement full-screen api 2018-01-08 23:07:26 +02:00
Serge A. Zaitsev
e7c72e6ad5 gtk-webkit: add alert dialog flags for gtk, add go bindings 2018-01-08 16:58:13 +02:00
Serge A. Zaitsev
bc7869dd75 go: open directory flag for dialogs, example 2018-01-07 11:53:37 +02:00
Serge A. Zaitsev
7451f8d931 dialogs: use calloc instead of malloc and do not null-terminate forcefully 2018-01-06 20:08:16 +02:00
Serge A. Zaitsev
d32a197c8b webkit-gtk: migrate from webkit1 to webkit2 2018-01-06 15:26:45 +02:00
Serge A. Zaitsev
535f250b27 go: add InjectCSS 2017-11-28 18:12:00 +02:00
Serge A. Zaitsev
63342029ab webview: use default data url if url field is empty 2017-11-28 08:12:59 +02:00
Serge A. Zaitsev
eef5772f61 go: fix lint warning 2017-11-27 13:18:31 +02:00
Serge A. Zaitsev
a7dac7e2e7 go: fix lint warnings 2017-11-27 13:13:38 +02:00
Serge A. Zaitsev
4e5725934c go: add debug output functions 2017-11-27 12:22:27 +02:00
Serge A. Zaitsev
0b47eb5554 go: use debug flag 2017-11-27 12:08:26 +02:00
Serge A. Zaitsev
bebe945e2b go: fix typo 2017-11-02 23:22:18 +02:00
Serge A. Zaitsev
70223d1cd0 go: fix typo in default index.html 2017-10-31 22:01:06 +02:00
Serge A. Zaitsev
b0f88d703d go: pass coontroller data into render method 2017-10-31 21:14:00 +02:00
Serge A. Zaitsev
0227c2cebe go: implement go-to-js bindings, add app container element to the default html 2017-10-30 16:14:47 +02:00
Serge A. Zaitsev
15f17878c6 go: always have an external.invoke handler function 2017-10-29 10:22:42 +02:00
Serge A. Zaitsev
a9dac9b2ce go: use default empty HTML if no URL is provided 2017-10-29 10:22:02 +02:00
Serge A. Zaitsev
032f3b62c4 go: fix deadlock in calling external.invoke_() from webview.Dispatch() 2017-10-27 16:29:45 +03:00
Dimitri Sokolyuk
517af31baf Add OpenBSD support 2017-10-18 00:04:11 +02:00
Serge A. Zaitsev
9e2e12779d go: ensure that main.main is called from the main thread 2017-10-15 22:59:44 +03:00
Serge A. Zaitsev
fe917a00e8 go: fix potential crash on dispatch 2017-10-15 20:17:09 +03:00
Serge A. Zaitsev
5a9608fd9b go: add documentation for Dialog() function 2017-10-04 23:39:12 +03:00
Serge A. Zaitsev
18896ddb19 go: add dialog bindings 2017-10-04 20:19:33 +03:00
Serge A. Zaitsev
647525a53f go: fix govet warning about unsafe.Pointer 2017-10-04 17:03:25 +03:00
Serge A. Zaitsev
cf5273e100 go: SetTitle API wrapper 2017-09-27 09:07:46 +03:00
Serge A. Zaitsev
3eb0cf7258 go: fix golint warnings 2017-09-26 06:30:47 +03:00
Serge A. Zaitsev
ebbbe6ed26 go: add some package documentation 2017-09-21 10:47:37 +03:00
Serge Zaitsev
71b0e55a3d go: use void* and unsafe.Pointer to work around the problem with llvm/darwin struct size detection 2017-09-20 00:45:27 +03:00
Serge A. Zaitsev
8d5eee3f7c go: pass webview to external invoke callback, fix deadlock in recursive invocations 2017-09-19 01:45:21 +03:00
Serge A. Zaitsev
864fc1a160 go: bindings for the new extended api 2017-09-18 20:25:55 +03:00
Serge Zaitsev
083a796c6a fix mac build flags 2017-08-21 07:31:31 +03:00
Serge A. Zaitsev
8ec0a5c2dd golang: add minimal cgo wrapper 2017-08-19 14:32:11 +03:00