changeset 2014:b1838dd5509a

Mac: Added support on MacOS versions that only support WebView.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 07 Nov 2019 08:11:28 +0000
parents 7303b35a9f4d
children c30f4354966e
files mac/dw.m
diffstat 1 files changed, 37 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Thu Nov 07 07:00:32 2019 +0000
+++ b/mac/dw.m	Thu Nov 07 08:11:28 2019 +0000
@@ -782,6 +782,11 @@
             /* HTML result event */
             case 18:
             {
+                int (* API htmlresultfunc)(HWND, int, char *, void *, void *) = handler->signalfunction;
+                void **params = (void **)event;
+                NSString *result = params[0];
+                
+                return htmlresultfunc(handler->window, [result length] ? DW_ERROR_NONE : DW_ERROR_UNKNOWN, [result length] ? (char *)[result UTF8String] : NULL, params[1], handler->data);
             }
             /* HTML changed event */
             case 19:
@@ -1367,10 +1372,29 @@
 }
 @end
 #else
-@interface DWWebView : WebView { }
+@interface DWWebView : WebView
+{ }
+-(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame;
+-(void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame;
+-(void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame;
 @end
 
 @implementation DWWebView : WebView { }
+-(void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), [self mainFrameURL] };
+    _event_handler(self, (NSEvent *)params, 19);
+}
+-(void)webView:(WebView *)sender didCommitLoadForFrame:(WebFrame *)frame
+{
+    void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), [self mainFrameURL] };
+    _event_handler(self, (NSEvent *)params, 19);
+}
+-(void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame
+{
+    void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), [self mainFrameURL] };
+    _event_handler(self, (NSEvent *)params, 19);
+}
 @end
 #endif
 
@@ -8750,7 +8774,7 @@
 #else
     [[html mainFrame] loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil];
 #endif
-    return 0;
+    return DW_ERROR_NONE;
 }
 
 /*
@@ -8770,7 +8794,7 @@
 #else
     [[html mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]];
 #endif
-    return 0;
+    return DW_ERROR_NONE;
 }
 
 /*
@@ -8785,13 +8809,17 @@
  */
 int dw_html_javascript_run(HWND handle, char *script, void *scriptdata)
 {
+    DWWebView *html = handle;
+    DW_LOCAL_POOL_IN;
+    
 #if WK_API_ENABLED
-    DWWebView *html = handle;
     [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:nil];
+#else
+    NSString *result = [html stringByEvaluatingJavaScriptFromString:[NSString stringWithUTF8String:script]];
+    _event_handler(html, (NSEvent *)result, 18);
+#endif
+    DW_LOCAL_POOL_OUT;
     return DW_ERROR_NONE;
-#else
-    return DW_ERROR_UNKNOWN;
-#endif
 }
 
 /*
@@ -8810,6 +8838,8 @@
     DWWebView *web = [[DWWebView alloc] init];
 #if WK_API_ENABLED
     web.navigationDelegate = web;
+#else
+    web.frameLoadDelegate = web;
 #endif
     /* [web setTag:cid]; Why doesn't this work? */
     DW_FUNCTION_RETURN_THIS(web);