diff options
| author | Andrew De Angelis | 2023-02-23 22:47:41 -0500 |
|---|---|---|
| committer | Eli Zaretskii | 2023-03-02 12:53:35 +0200 |
| commit | a137f71c67e88204a32ebd747beb8fdd7db2fbe9 (patch) | |
| tree | c02765980dbbc5478fde4ac29e0a6060f4c4b4ab | |
| parent | 3f43a16bc63eac12db5707b26da2507077b4f13c (diff) | |
| download | emacs-a137f71c67e88204a32ebd747beb8fdd7db2fbe9.tar.gz emacs-a137f71c67e88204a32ebd747beb8fdd7db2fbe9.zip | |
Improvements to xwidget on macOS (bug#60703)
* src/nsxwidget.m ()
([XwWebView initWithFrame:configuration:xwidget:])
(nsxwidget_init): Fixed memory leaks: when sending an alloc
message to an object, send an autorelease message to any objects
we won't explictly release.
([XwWebView webView:didFinishNavigation:]): Second string to
store in 'store_xwidget_event_string' is "load finished" rather
than empty string.
([XwWebView webView:didStartProvisionalNavigation:])
([XwWebView webView:didReceiveServerRedirectForProvisionalNavigation:])
([XwWebView webView:didCommitNavigation:]): New functions.
(nsxwidget_webkit_estimated_load_progress): New function.
(nsxwidget_webkit_stop_loading): New function.
* src/xwidget.c (Fxwidget_webkit_estimated_load_progress): Call
'nsxwidget_webkit_estimated_load_progress' if we're on MacOS.
(Fxwidget_webkit_stop_loading): Call 'nsxwidget_webkit_stop_loading'
if we're on MacOS.
(syms_of_xwidget): Define symbol for function.
'xwidget_webkit_estimated_load_progress' if we're on MacOS.
* src/nsxwidget.h: Signature for functions
'nsxwidget_webkit_estimated_load_progress' and
'nsxwidget_webkit_stop_loading'.
* lisp/xwidget.el (xwidget-webkit-current-url): Message URL rather
than return value of 'kill-new' (which is always nil).
| -rw-r--r-- | lisp/xwidget.el | 3 | ||||
| -rw-r--r-- | src/nsxwidget.h | 2 | ||||
| -rw-r--r-- | src/nsxwidget.m | 100 | ||||
| -rw-r--r-- | src/xwidget.c | 63 |
4 files changed, 114 insertions, 54 deletions
diff --git a/lisp/xwidget.el b/lisp/xwidget.el index abbda29081e..7daca81f9f7 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el | |||
| @@ -925,7 +925,8 @@ Return the buffer." | |||
| 925 | "Display the current xwidget webkit URL and place it on the `kill-ring'." | 925 | "Display the current xwidget webkit URL and place it on the `kill-ring'." |
| 926 | (interactive nil xwidget-webkit-mode) | 926 | (interactive nil xwidget-webkit-mode) |
| 927 | (let ((url (xwidget-webkit-uri (xwidget-webkit-current-session)))) | 927 | (let ((url (xwidget-webkit-uri (xwidget-webkit-current-session)))) |
| 928 | (message "URL: %s" (kill-new (or url ""))))) | 928 | (when url (kill-new url)) |
| 929 | (message "URL: %s" url))) | ||
| 929 | 930 | ||
| 930 | (defun xwidget-webkit-browse-history () | 931 | (defun xwidget-webkit-browse-history () |
| 931 | "Display a buffer containing the history of page loads." | 932 | "Display a buffer containing the history of page loads." |
diff --git a/src/nsxwidget.h b/src/nsxwidget.h index 8d55fac5326..2b5596f905e 100644 --- a/src/nsxwidget.h +++ b/src/nsxwidget.h | |||
| @@ -36,6 +36,8 @@ Lisp_Object nsxwidget_webkit_uri (struct xwidget *xw); | |||
| 36 | Lisp_Object nsxwidget_webkit_title (struct xwidget *xw); | 36 | Lisp_Object nsxwidget_webkit_title (struct xwidget *xw); |
| 37 | void nsxwidget_webkit_goto_uri (struct xwidget *xw, const char *uri); | 37 | void nsxwidget_webkit_goto_uri (struct xwidget *xw, const char *uri); |
| 38 | void nsxwidget_webkit_goto_history (struct xwidget *xw, int rel_pos); | 38 | void nsxwidget_webkit_goto_history (struct xwidget *xw, int rel_pos); |
| 39 | double nsxwidget_webkit_estimated_load_progress(struct xwidget *xw); | ||
| 40 | void nsxwidget_webkit_stop_loading (struct xwidget *xw); | ||
| 39 | void nsxwidget_webkit_zoom (struct xwidget *xw, double zoom_change); | 41 | void nsxwidget_webkit_zoom (struct xwidget *xw, double zoom_change); |
| 40 | void nsxwidget_webkit_execute_script (struct xwidget *xw, const char *script, | 42 | void nsxwidget_webkit_execute_script (struct xwidget *xw, const char *script, |
| 41 | Lisp_Object fun); | 43 | Lisp_Object fun); |
diff --git a/src/nsxwidget.m b/src/nsxwidget.m index e1fbd749b62..0e00589bb7f 100644 --- a/src/nsxwidget.m +++ b/src/nsxwidget.m | |||
| @@ -57,12 +57,13 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 57 | @end | 57 | @end |
| 58 | @implementation XwWebView : WKWebView | 58 | @implementation XwWebView : WKWebView |
| 59 | 59 | ||
| 60 | - (id)initWithFrame:(CGRect)frame | 60 | - (id) initWithFrame:(CGRect)frame |
| 61 | configuration:(WKWebViewConfiguration *)configuration | 61 | configuration:(WKWebViewConfiguration *)configuration |
| 62 | xwidget:(struct xwidget *)xw | 62 | xwidget:(struct xwidget *)xw |
| 63 | { | 63 | { |
| 64 | /* Script controller to add script message handler and user script. */ | 64 | /* Script controller to add script message handler and user script. */ |
| 65 | WKUserContentController *scriptor = [[WKUserContentController alloc] init]; | 65 | WKUserContentController *scriptor = [[[WKUserContentController alloc] init] |
| 66 | autorelease]; | ||
| 66 | configuration.userContentController = scriptor; | 67 | configuration.userContentController = scriptor; |
| 67 | 68 | ||
| 68 | /* Enable inspect element context menu item for debugging. */ | 69 | /* Enable inspect element context menu item for debugging. */ |
| @@ -81,7 +82,8 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 81 | if (self) | 82 | if (self) |
| 82 | { | 83 | { |
| 83 | self.xw = xw; | 84 | self.xw = xw; |
| 84 | self.urlScriptBlocked = [[NSMutableDictionary alloc] init]; | 85 | self.urlScriptBlocked = [[[NSMutableDictionary alloc] init] |
| 86 | autorelease]; | ||
| 85 | self.navigationDelegate = self; | 87 | self.navigationDelegate = self; |
| 86 | self.UIDelegate = self; | 88 | self.UIDelegate = self; |
| 87 | self.customUserAgent = | 89 | self.customUserAgent = |
| @@ -89,23 +91,48 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 89 | @" AppleWebKit/603.3.8 (KHTML, like Gecko)" | 91 | @" AppleWebKit/603.3.8 (KHTML, like Gecko)" |
| 90 | @" Version/11.0.1 Safari/603.3.8"; | 92 | @" Version/11.0.1 Safari/603.3.8"; |
| 91 | [scriptor addScriptMessageHandler:self name:@"keyDown"]; | 93 | [scriptor addScriptMessageHandler:self name:@"keyDown"]; |
| 92 | [scriptor addUserScript:[[WKUserScript alloc] | 94 | WKUserScript *userScript = [[[WKUserScript alloc] |
| 93 | initWithSource:xwScript | 95 | initWithSource:xwScript |
| 94 | injectionTime: | 96 | injectionTime: |
| 95 | WKUserScriptInjectionTimeAtDocumentStart | 97 | WKUserScriptInjectionTimeAtDocumentStart |
| 96 | forMainFrameOnly:NO]]; | 98 | forMainFrameOnly:NO] autorelease]; |
| 99 | [scriptor addUserScript:userScript]; | ||
| 97 | } | 100 | } |
| 98 | return self; | 101 | return self; |
| 99 | } | 102 | } |
| 100 | 103 | ||
| 101 | - (void)webView:(WKWebView *)webView | 104 | /* These 4 functions emulate the behavior of webkit_view_load_changed_cb |
| 105 | in the GTK implementation*/ | ||
| 106 | - (void) webView:(WKWebView *)webView | ||
| 102 | didFinishNavigation:(WKNavigation *)navigation | 107 | didFinishNavigation:(WKNavigation *)navigation |
| 103 | { | 108 | { |
| 104 | if (EQ (Fbuffer_live_p (self.xw->buffer), Qt)) | 109 | if (EQ (Fbuffer_live_p (self.xw->buffer), Qt)) |
| 105 | store_xwidget_event_string (self.xw, "load-changed", ""); | 110 | store_xwidget_event_string (self.xw, "load-changed", "load-finished"); |
| 106 | } | 111 | } |
| 107 | 112 | ||
| 108 | - (void)webView:(WKWebView *)webView | 113 | - (void) webView:(WKWebView *)webView |
| 114 | didStartProvisionalNavigation:(WKNavigation *)navigation | ||
| 115 | { | ||
| 116 | if (EQ (Fbuffer_live_p (self.xw->buffer), Qt)) | ||
| 117 | store_xwidget_event_string (self.xw, "load-changed", "load-started"); | ||
| 118 | } | ||
| 119 | |||
| 120 | - (void) webView:(WKWebView *)webView | ||
| 121 | didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation | ||
| 122 | { | ||
| 123 | if (EQ (Fbuffer_live_p (self.xw->buffer), Qt)) | ||
| 124 | store_xwidget_event_string (self.xw, "load-changed", "load-redirected"); | ||
| 125 | } | ||
| 126 | |||
| 127 | /* Start loading WKWebView */ | ||
| 128 | - (void) webView:(WKWebView *)webView | ||
| 129 | didCommitNavigation:(WKNavigation *)navigation | ||
| 130 | { | ||
| 131 | if (EQ (Fbuffer_live_p (self.xw->buffer), Qt)) | ||
| 132 | store_xwidget_event_string (self.xw, "load-changed", "load-committed"); | ||
| 133 | } | ||
| 134 | |||
| 135 | - (void) webView:(WKWebView *)webView | ||
| 109 | decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction | 136 | decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction |
| 110 | decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler | 137 | decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler |
| 111 | { | 138 | { |
| @@ -114,13 +141,13 @@ decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler | |||
| 114 | decisionHandler (WKNavigationActionPolicyAllow); | 141 | decisionHandler (WKNavigationActionPolicyAllow); |
| 115 | break; | 142 | break; |
| 116 | default: | 143 | default: |
| 117 | // decisionHandler (WKNavigationActionPolicyCancel); | 144 | /* decisionHandler (WKNavigationActionPolicyCancel); */ |
| 118 | decisionHandler (WKNavigationActionPolicyAllow); | 145 | decisionHandler (WKNavigationActionPolicyAllow); |
| 119 | break; | 146 | break; |
| 120 | } | 147 | } |
| 121 | } | 148 | } |
| 122 | 149 | ||
| 123 | - (void)webView:(WKWebView *)webView | 150 | - (void) webView:(WKWebView *)webView |
| 124 | decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse | 151 | decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse |
| 125 | decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler | 152 | decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler |
| 126 | { | 153 | { |
| @@ -166,7 +193,7 @@ decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler | |||
| 166 | 193 | ||
| 167 | /* No additional new webview or emacs window will be created | 194 | /* No additional new webview or emacs window will be created |
| 168 | for <a ... target="_blank">. */ | 195 | for <a ... target="_blank">. */ |
| 169 | - (WKWebView *)webView:(WKWebView *)webView | 196 | - (WKWebView *) webView:(WKWebView *)webView |
| 170 | createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration | 197 | createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration |
| 171 | forNavigationAction:(WKNavigationAction *)navigationAction | 198 | forNavigationAction:(WKNavigationAction *)navigationAction |
| 172 | windowFeatures:(WKWindowFeatures *)windowFeatures | 199 | windowFeatures:(WKWindowFeatures *)windowFeatures |
| @@ -177,7 +204,7 @@ createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration | |||
| 177 | } | 204 | } |
| 178 | 205 | ||
| 179 | /* Open panel for file upload. */ | 206 | /* Open panel for file upload. */ |
| 180 | - (void)webView:(WKWebView *)webView | 207 | - (void) webView:(WKWebView *)webView |
| 181 | runOpenPanelWithParameters:(WKOpenPanelParameters *)parameters | 208 | runOpenPanelWithParameters:(WKOpenPanelParameters *)parameters |
| 182 | initiatedByFrame:(WKFrameInfo *)frame | 209 | initiatedByFrame:(WKFrameInfo *)frame |
| 183 | completionHandler:(void (^)(NSArray<NSURL *> *URLs))completionHandler | 210 | completionHandler:(void (^)(NSArray<NSURL *> *URLs))completionHandler |
| @@ -197,13 +224,13 @@ completionHandler:(void (^)(NSArray<NSURL *> *URLs))completionHandler | |||
| 197 | - Correct mouse hand/arrow/I-beam is displayed (TODO: not perfect yet). | 224 | - Correct mouse hand/arrow/I-beam is displayed (TODO: not perfect yet). |
| 198 | */ | 225 | */ |
| 199 | 226 | ||
| 200 | - (void)mouseDown:(NSEvent *)event | 227 | - (void) mouseDown:(NSEvent *)event |
| 201 | { | 228 | { |
| 202 | [self.xw->xv->emacswindow mouseDown:event]; | 229 | [self.xw->xv->emacswindow mouseDown:event]; |
| 203 | [super mouseDown:event]; | 230 | [super mouseDown:event]; |
| 204 | } | 231 | } |
| 205 | 232 | ||
| 206 | - (void)mouseUp:(NSEvent *)event | 233 | - (void) mouseUp:(NSEvent *)event |
| 207 | { | 234 | { |
| 208 | [self.xw->xv->emacswindow mouseUp:event]; | 235 | [self.xw->xv->emacswindow mouseUp:event]; |
| 209 | [super mouseUp:event]; | 236 | [super mouseUp:event]; |
| @@ -214,7 +241,7 @@ completionHandler:(void (^)(NSArray<NSURL *> *URLs))completionHandler | |||
| 214 | emacs as first responder to avoid focus held in an input element | 241 | emacs as first responder to avoid focus held in an input element |
| 215 | with matching text. */ | 242 | with matching text. */ |
| 216 | 243 | ||
| 217 | - (void)keyDown:(NSEvent *)event | 244 | - (void) keyDown:(NSEvent *)event |
| 218 | { | 245 | { |
| 219 | Lisp_Object var = Fintern (build_string ("isearch-mode"), Qnil); | 246 | Lisp_Object var = Fintern (build_string ("isearch-mode"), Qnil); |
| 220 | Lisp_Object val = buffer_local_value (var, Fcurrent_buffer ()); | 247 | Lisp_Object val = buffer_local_value (var, Fcurrent_buffer ()); |
| @@ -250,7 +277,7 @@ completionHandler:(void (^)(NSArray<NSURL *> *URLs))completionHandler | |||
| 250 | }]; | 277 | }]; |
| 251 | } | 278 | } |
| 252 | 279 | ||
| 253 | - (void)interpretKeyEvents:(NSArray<NSEvent *> *)eventArray | 280 | - (void) interpretKeyEvents:(NSArray<NSEvent *> *)eventArray |
| 254 | { | 281 | { |
| 255 | /* We should do nothing and do not forward (default implementation | 282 | /* We should do nothing and do not forward (default implementation |
| 256 | if we not override here) to let emacs collect key events and ask | 283 | if we not override here) to let emacs collect key events and ask |
| @@ -258,7 +285,7 @@ completionHandler:(void (^)(NSArray<NSURL *> *URLs))completionHandler | |||
| 258 | } | 285 | } |
| 259 | 286 | ||
| 260 | static NSString *xwScript; | 287 | static NSString *xwScript; |
| 261 | + (void)initialize | 288 | + (void) initialize |
| 262 | { | 289 | { |
| 263 | /* Find out if an input element has focus. | 290 | /* Find out if an input element has focus. |
| 264 | Message to script message handler when 'C-g' key down. */ | 291 | Message to script message handler when 'C-g' key down. */ |
| @@ -284,7 +311,7 @@ static NSString *xwScript; | |||
| 284 | 311 | ||
| 285 | /* Confirming to WKScriptMessageHandler, listens concerning keyDown in | 312 | /* Confirming to WKScriptMessageHandler, listens concerning keyDown in |
| 286 | webkit. Currently 'C-g'. */ | 313 | webkit. Currently 'C-g'. */ |
| 287 | - (void)userContentController:(WKUserContentController *)userContentController | 314 | - (void) userContentController:(WKUserContentController *)userContentController |
| 288 | didReceiveScriptMessage:(WKScriptMessage *)message | 315 | didReceiveScriptMessage:(WKScriptMessage *)message |
| 289 | { | 316 | { |
| 290 | if ([message.body isEqualToString:@"C-g"]) | 317 | if ([message.body isEqualToString:@"C-g"]) |
| @@ -343,6 +370,20 @@ nsxwidget_webkit_goto_history (struct xwidget *xw, int rel_pos) | |||
| 343 | } | 370 | } |
| 344 | } | 371 | } |
| 345 | 372 | ||
| 373 | double | ||
| 374 | nsxwidget_webkit_estimated_load_progress (struct xwidget *xw) | ||
| 375 | { | ||
| 376 | XwWebView *xwWebView = (XwWebView *) xw->xwWidget; | ||
| 377 | return xwWebView.estimatedProgress; | ||
| 378 | } | ||
| 379 | |||
| 380 | void | ||
| 381 | nsxwidget_webkit_stop_loading (struct xwidget *xw) | ||
| 382 | { | ||
| 383 | XwWebView *xwWebView = (XwWebView *) xw->xwWidget; | ||
| 384 | [xwWebView stopLoading]; | ||
| 385 | } | ||
| 386 | |||
| 346 | void | 387 | void |
| 347 | nsxwidget_webkit_zoom (struct xwidget *xw, double zoom_change) | 388 | nsxwidget_webkit_zoom (struct xwidget *xw, double zoom_change) |
| 348 | { | 389 | { |
| @@ -430,7 +471,7 @@ nsxwidget_webkit_execute_script (struct xwidget *xw, const char *script, | |||
| 430 | } | 471 | } |
| 431 | else if (result && FUNCTIONP (fun)) | 472 | else if (result && FUNCTIONP (fun)) |
| 432 | { | 473 | { |
| 433 | // NSLog (@"result=%@, type=%@", result, [result class]); | 474 | /* NSLog (@"result=%@, type=%@", result, [result class]); */ |
| 434 | Lisp_Object lisp_value = js_to_lisp (result); | 475 | Lisp_Object lisp_value = js_to_lisp (result); |
| 435 | store_xwidget_js_callback_event (xw, fun, lisp_value); | 476 | store_xwidget_js_callback_event (xw, fun, lisp_value); |
| 436 | } | 477 | } |
| @@ -440,19 +481,20 @@ nsxwidget_webkit_execute_script (struct xwidget *xw, const char *script, | |||
| 440 | /* Window containing an xwidget. */ | 481 | /* Window containing an xwidget. */ |
| 441 | 482 | ||
| 442 | @implementation XwWindow | 483 | @implementation XwWindow |
| 443 | - (BOOL)isFlipped { return YES; } | 484 | - (BOOL) isFlipped { return YES; } |
| 444 | @end | 485 | @end |
| 445 | 486 | ||
| 446 | /* Xwidget model, macOS Cocoa part. */ | 487 | /* Xwidget model, macOS Cocoa part. */ |
| 447 | 488 | ||
| 448 | void | 489 | void |
| 449 | nsxwidget_init(struct xwidget *xw) | 490 | nsxwidget_init (struct xwidget *xw) |
| 450 | { | 491 | { |
| 451 | block_input (); | 492 | block_input (); |
| 452 | NSRect rect = NSMakeRect (0, 0, xw->width, xw->height); | 493 | NSRect rect = NSMakeRect (0, 0, xw->width, xw->height); |
| 453 | xw->xwWidget = [[XwWebView alloc] | 494 | xw->xwWidget = [[XwWebView alloc] |
| 454 | initWithFrame:rect | 495 | initWithFrame:rect |
| 455 | configuration:[[WKWebViewConfiguration alloc] init] | 496 | configuration:[[[WKWebViewConfiguration alloc] init] |
| 497 | autorelease] | ||
| 456 | xwidget:xw]; | 498 | xwidget:xw]; |
| 457 | xw->xwWindow = [[XwWindow alloc] | 499 | xw->xwWindow = [[XwWindow alloc] |
| 458 | initWithFrame:rect]; | 500 | initWithFrame:rect]; |
| @@ -470,16 +512,18 @@ nsxwidget_kill (struct xwidget *xw) | |||
| 470 | ((XwWebView *) xw->xwWidget).configuration.userContentController; | 512 | ((XwWebView *) xw->xwWidget).configuration.userContentController; |
| 471 | [scriptor removeAllUserScripts]; | 513 | [scriptor removeAllUserScripts]; |
| 472 | [scriptor removeScriptMessageHandlerForName:@"keyDown"]; | 514 | [scriptor removeScriptMessageHandlerForName:@"keyDown"]; |
| 473 | [scriptor release]; | 515 | |
| 474 | if (xw->xv) | 516 | if (xw->xv) |
| 475 | xw->xv->model = Qnil; /* Make sure related view stale. */ | 517 | xw->xv->model = Qnil; /* Make sure related view stale. */ |
| 476 | 518 | ||
| 477 | /* This stops playing audio when a xwidget-webkit buffer is | 519 | /* This stops playing audio when a xwidget-webkit buffer is |
| 478 | killed. I could not find other solution. */ | 520 | killed. I could not find other solution. |
| 521 | TODO: improve this */ | ||
| 479 | nsxwidget_webkit_goto_uri (xw, "about:blank"); | 522 | nsxwidget_webkit_goto_uri (xw, "about:blank"); |
| 480 | 523 | ||
| 481 | [((XwWebView *) xw->xwWidget).urlScriptBlocked release]; | 524 | [((XwWebView *) xw->xwWidget).urlScriptBlocked release]; |
| 482 | [xw->xwWidget removeFromSuperviewWithoutNeedingDisplay]; | 525 | [xw->xwWidget removeFromSuperviewWithoutNeedingDisplay]; |
| 526 | |||
| 483 | [xw->xwWidget release]; | 527 | [xw->xwWidget release]; |
| 484 | [xw->xwWindow removeFromSuperviewWithoutNeedingDisplay]; | 528 | [xw->xwWindow removeFromSuperviewWithoutNeedingDisplay]; |
| 485 | [xw->xwWindow release]; | 529 | [xw->xwWindow release]; |
| @@ -507,7 +551,7 @@ nsxwidget_get_size (struct xwidget *xw) | |||
| 507 | /* Xwidget view, macOS Cocoa part. */ | 551 | /* Xwidget view, macOS Cocoa part. */ |
| 508 | 552 | ||
| 509 | @implementation XvWindow : NSView | 553 | @implementation XvWindow : NSView |
| 510 | - (BOOL)isFlipped { return YES; } | 554 | - (BOOL) isFlipped { return YES; } |
| 511 | @end | 555 | @end |
| 512 | 556 | ||
| 513 | void | 557 | void |
diff --git a/src/xwidget.c b/src/xwidget.c index efe27055629..7f30e48c954 100644 --- a/src/xwidget.c +++ b/src/xwidget.c | |||
| @@ -3063,6 +3063,36 @@ DEFUN ("xwidget-webkit-title", | |||
| 3063 | #endif | 3063 | #endif |
| 3064 | } | 3064 | } |
| 3065 | 3065 | ||
| 3066 | DEFUN ("xwidget-webkit-estimated-load-progress", | ||
| 3067 | Fxwidget_webkit_estimated_load_progress, Sxwidget_webkit_estimated_load_progress, | ||
| 3068 | 1, 1, 0, doc: /* Get the estimated load progress of XWIDGET, a WebKit widget. | ||
| 3069 | Return a value ranging from 0.0 to 1.0, based on how close XWIDGET | ||
| 3070 | is to completely loading its page. */) | ||
| 3071 | (Lisp_Object xwidget) | ||
| 3072 | { | ||
| 3073 | struct xwidget *xw; | ||
| 3074 | #ifdef USE_GTK | ||
| 3075 | WebKitWebView *webview; | ||
| 3076 | #endif | ||
| 3077 | double value; | ||
| 3078 | |||
| 3079 | CHECK_LIVE_XWIDGET (xwidget); | ||
| 3080 | xw = XXWIDGET (xwidget); | ||
| 3081 | CHECK_WEBKIT_WIDGET (xw); | ||
| 3082 | |||
| 3083 | block_input (); | ||
| 3084 | #ifdef USE_GTK | ||
| 3085 | webview = WEBKIT_WEB_VIEW (xw->widget_osr); | ||
| 3086 | value = webkit_web_view_get_estimated_load_progress (webview); | ||
| 3087 | #elif defined NS_IMPL_COCOA | ||
| 3088 | value = nsxwidget_webkit_estimated_load_progress (xw); | ||
| 3089 | #endif | ||
| 3090 | |||
| 3091 | unblock_input (); | ||
| 3092 | |||
| 3093 | return make_float (value); | ||
| 3094 | } | ||
| 3095 | |||
| 3066 | DEFUN ("xwidget-webkit-goto-uri", | 3096 | DEFUN ("xwidget-webkit-goto-uri", |
| 3067 | Fxwidget_webkit_goto_uri, Sxwidget_webkit_goto_uri, | 3097 | Fxwidget_webkit_goto_uri, Sxwidget_webkit_goto_uri, |
| 3068 | 2, 2, 0, | 3098 | 2, 2, 0, |
| @@ -3810,28 +3840,6 @@ LIMIT is not specified or nil, it is treated as `50'. */) | |||
| 3810 | return list3 (back, here, forward); | 3840 | return list3 (back, here, forward); |
| 3811 | } | 3841 | } |
| 3812 | 3842 | ||
| 3813 | DEFUN ("xwidget-webkit-estimated-load-progress", | ||
| 3814 | Fxwidget_webkit_estimated_load_progress, Sxwidget_webkit_estimated_load_progress, | ||
| 3815 | 1, 1, 0, doc: /* Get the estimated load progress of XWIDGET, a WebKit widget. | ||
| 3816 | Return a value ranging from 0.0 to 1.0, based on how close XWIDGET | ||
| 3817 | is to completely loading its page. */) | ||
| 3818 | (Lisp_Object xwidget) | ||
| 3819 | { | ||
| 3820 | struct xwidget *xw; | ||
| 3821 | WebKitWebView *webview; | ||
| 3822 | double value; | ||
| 3823 | |||
| 3824 | CHECK_LIVE_XWIDGET (xwidget); | ||
| 3825 | xw = XXWIDGET (xwidget); | ||
| 3826 | CHECK_WEBKIT_WIDGET (xw); | ||
| 3827 | |||
| 3828 | block_input (); | ||
| 3829 | webview = WEBKIT_WEB_VIEW (xw->widget_osr); | ||
| 3830 | value = webkit_web_view_get_estimated_load_progress (webview); | ||
| 3831 | unblock_input (); | ||
| 3832 | |||
| 3833 | return make_float (value); | ||
| 3834 | } | ||
| 3835 | #endif | 3843 | #endif |
| 3836 | 3844 | ||
| 3837 | DEFUN ("xwidget-webkit-set-cookie-storage-file", | 3845 | DEFUN ("xwidget-webkit-set-cookie-storage-file", |
| @@ -3874,19 +3882,23 @@ This will stop any data transfer that may still be in progress inside | |||
| 3874 | XWIDGET as part of loading a page. */) | 3882 | XWIDGET as part of loading a page. */) |
| 3875 | (Lisp_Object xwidget) | 3883 | (Lisp_Object xwidget) |
| 3876 | { | 3884 | { |
| 3877 | #ifdef USE_GTK | ||
| 3878 | struct xwidget *xw; | 3885 | struct xwidget *xw; |
| 3886 | #ifdef USE_GTK | ||
| 3879 | WebKitWebView *webview; | 3887 | WebKitWebView *webview; |
| 3888 | #endif | ||
| 3880 | 3889 | ||
| 3881 | CHECK_LIVE_XWIDGET (xwidget); | 3890 | CHECK_LIVE_XWIDGET (xwidget); |
| 3882 | xw = XXWIDGET (xwidget); | 3891 | xw = XXWIDGET (xwidget); |
| 3883 | CHECK_WEBKIT_WIDGET (xw); | 3892 | CHECK_WEBKIT_WIDGET (xw); |
| 3884 | 3893 | ||
| 3885 | block_input (); | 3894 | block_input (); |
| 3895 | #ifdef USE_GTK | ||
| 3886 | webview = WEBKIT_WEB_VIEW (xw->widget_osr); | 3896 | webview = WEBKIT_WEB_VIEW (xw->widget_osr); |
| 3887 | webkit_web_view_stop_loading (webview); | 3897 | webkit_web_view_stop_loading (webview); |
| 3888 | unblock_input (); | 3898 | #elif defined NS_IMPL_COCOA |
| 3899 | nsxwidget_webkit_stop_loading (xw); | ||
| 3889 | #endif | 3900 | #endif |
| 3901 | unblock_input (); | ||
| 3890 | 3902 | ||
| 3891 | return Qnil; | 3903 | return Qnil; |
| 3892 | } | 3904 | } |
| @@ -3936,8 +3948,9 @@ syms_of_xwidget (void) | |||
| 3936 | #ifdef USE_GTK | 3948 | #ifdef USE_GTK |
| 3937 | defsubr (&Sxwidget_webkit_load_html); | 3949 | defsubr (&Sxwidget_webkit_load_html); |
| 3938 | defsubr (&Sxwidget_webkit_back_forward_list); | 3950 | defsubr (&Sxwidget_webkit_back_forward_list); |
| 3939 | defsubr (&Sxwidget_webkit_estimated_load_progress); | ||
| 3940 | #endif | 3951 | #endif |
| 3952 | |||
| 3953 | defsubr (&Sxwidget_webkit_estimated_load_progress); | ||
| 3941 | defsubr (&Skill_xwidget); | 3954 | defsubr (&Skill_xwidget); |
| 3942 | 3955 | ||
| 3943 | DEFSYM (QCxwidget, ":xwidget"); | 3956 | DEFSYM (QCxwidget, ":xwidget"); |