Mercurial > dwindows
changeset 2013:7303b35a9f4d
Mac: Added DW_SIGNAL_HTML support on Mac when using WKWebView.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 07 Nov 2019 07:00:32 +0000 |
parents | 75c6eb796e91 |
children | b1838dd5509a |
files | mac/dw.m |
diffstat | 1 files changed, 67 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/mac/dw.m Thu Nov 07 05:26:04 2019 +0000 +++ b/mac/dw.m Thu Nov 07 07:00:32 2019 +0000 @@ -338,16 +338,6 @@ DWTID _dw_mutex_locked = (DWTID)-1; #endif -/* Apparently the WKWebKit API is only enabled on intel 64bit... - * Causing build failures on 32bit builds, so this should allow - * WKWebKit on intel 64 and the old WebKit on intel 32 bit and earlier. - */ -#if WK_API_ENABLED -#define DWWebView WKWebView -#else -#define DWWebView WebView -#endif - unsigned long _colors[] = { 0x00000000, /* 0 black */ @@ -518,7 +508,7 @@ } SignalList; /* List of signals */ -#define SIGNALMAX 17 +#define SIGNALMAX 19 SignalList SignalTranslate[SIGNALMAX] = { { 1, DW_SIGNAL_CONFIGURE }, @@ -537,7 +527,9 @@ { 14, DW_SIGNAL_VALUE_CHANGED }, { 15, DW_SIGNAL_SWITCH_PAGE }, { 16, DW_SIGNAL_TREE_EXPAND }, - { 17, DW_SIGNAL_COLUMN_CLICK } + { 17, DW_SIGNAL_COLUMN_CLICK }, + { 18, DW_SIGNAL_HTML_RESULT }, + { 19, DW_SIGNAL_HTML_CHANGED } }; int _event_handler1(id object, NSEvent *event, int message) @@ -772,19 +764,34 @@ return switchpagefunc(handler->window, pageid, handler->data); } + /* Tree expand event */ case 16: { int (* API treeexpandfunc)(HWND, HTREEITEM, void *) = (int (* API)(HWND, HTREEITEM, void *))handler->signalfunction; return treeexpandfunc(handler->window, (HTREEITEM)event, handler->data); } + /* Column click event */ case 17: { - int (*clickcolumnfunc)(HWND, int, void *) = handler->signalfunction; + int (* API clickcolumnfunc)(HWND, int, void *) = handler->signalfunction; int column_num = DW_POINTER_TO_INT(event); return clickcolumnfunc(handler->window, column_num, handler->data); } + /* HTML result event */ + case 18: + { + } + /* HTML changed event */ + case 19: + { + int (* API htmlchangedfunc)(HWND, int, char *, void *) = handler->signalfunction; + void **params = (void **)event; + NSString *uri = params[1]; + + return htmlchangedfunc(handler->window, DW_POINTER_TO_INT(params[0]), (char *)[uri UTF8String], handler->data); + } } } return -1; @@ -1325,6 +1332,49 @@ -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; @end +/* Apparently the WKWebKit API is only enabled on intel 64bit... + * Causing build failures on 32bit builds, so this should allow + * WKWebKit on intel 64 and the old WebKit on intel 32 bit and earlier. + */ +#if WK_API_ENABLED +@interface DWWebView : WKWebView <WKNavigationDelegate> { } +-(void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation; +-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation; +-(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation; +-(void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation; +@end + +@implementation DWWebView : WKWebView { } +-(void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation +{ + void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), [[self URL] absoluteString] }; + _event_handler(self, (NSEvent *)params, 19); +} +-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation +{ + void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), [[self URL] absoluteString] }; + _event_handler(self, (NSEvent *)params, 19); +} +-(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation +{ + void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), [[self URL] absoluteString] }; + _event_handler(self, (NSEvent *)params, 19); +} +-(void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation +{ + void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_REDIRECT), [[self URL] absoluteString] }; + _event_handler(self, (NSEvent *)params, 19); +} +@end +#else +@interface DWWebView : WebView { } +@end + +@implementation DWWebView : WebView { } +@end +#endif + + @implementation DWAppDel -(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { @@ -8740,7 +8790,7 @@ [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:nil]; return DW_ERROR_NONE; #else - return DW_ERROR_UKNOWN; + return DW_ERROR_UNKNOWN; #endif } @@ -8758,6 +8808,9 @@ { DW_FUNCTION_INIT; DWWebView *web = [[DWWebView alloc] init]; +#if WK_API_ENABLED + web.navigationDelegate = web; +#endif /* [web setTag:cid]; Why doesn't this work? */ DW_FUNCTION_RETURN_THIS(web); }