diff options
| author | Joakim Verona | 2011-07-03 23:05:58 +0200 |
|---|---|---|
| committer | Joakim Verona | 2011-07-03 23:05:58 +0200 |
| commit | f929f1a90836282bfe85c81fcf8a757bf0b54b50 (patch) | |
| tree | d47270a8e2be10f467199de148e1bb7801244888 | |
| parent | d5aa6c9095f22bb9cbac9557b3502e6b90d98d0e (diff) | |
| download | emacs-f929f1a90836282bfe85c81fcf8a757bf0b54b50.tar.gz emacs-f929f1a90836282bfe85c81fcf8a757bf0b54b50.zip | |
inject javascript in embeddeb webkit instance
| -rw-r--r-- | README.xwidget | 41 | ||||
| -rw-r--r-- | src/xwidget.c | 34 |
2 files changed, 63 insertions, 12 deletions
diff --git a/README.xwidget b/README.xwidget index 59ddf9d2435..bc01ad95d66 100644 --- a/README.xwidget +++ b/README.xwidget | |||
| @@ -317,7 +317,8 @@ although embedding a browser is not my primary concern many are | |||
| 317 | interested in this. some suitable browser component needs to be found | 317 | interested in this. some suitable browser component needs to be found |
| 318 | supporting gtk. | 318 | supporting gtk. |
| 319 | 319 | ||
| 320 | *** webkit | 320 | *** DONE webkit |
| 321 | CLOSED: [2011-07-03 Sun 22:13] | ||
| 321 | there is a webkit gtk port. there is no obvious mvc support. | 322 | there is a webkit gtk port. there is no obvious mvc support. |
| 322 | http://live.gnome.org/WebKitGtk | 323 | http://live.gnome.org/WebKitGtk |
| 323 | http://webkitgtk.org/ | 324 | http://webkitgtk.org/ |
| @@ -370,7 +371,8 @@ idea is that whatever oddness webkit does so that offscreen rendering | |||
| 370 | doesnt work, doesnt happen on-screen. the window could be opened | 371 | doesnt work, doesnt happen on-screen. the window could be opened |
| 371 | somewhere not in the way. | 372 | somewhere not in the way. |
| 372 | 373 | ||
| 373 | *** firefox | 374 | *** CANCELLED firefox |
| 375 | CLOSED: [2011-07-03 Sun 22:13] | ||
| 374 | http://www-archive.mozilla.org/unix/gtk-embedding.html | 376 | http://www-archive.mozilla.org/unix/gtk-embedding.html |
| 375 | seems to be severly bitrotted | 377 | seems to be severly bitrotted |
| 376 | 378 | ||
| @@ -379,7 +381,33 @@ http://hg.mozilla.org/incubator/embedding/file/29ac0fe51754/gtk/tests/test.cpp | |||
| 379 | 381 | ||
| 380 | while webkit clearly has the best traction as an embeddee, the | 382 | while webkit clearly has the best traction as an embeddee, the |
| 381 | offscreen rendering issues makes it interesting to see what ff brings | 383 | offscreen rendering issues makes it interesting to see what ff brings |
| 382 | to the table. | 384 | to the table. turns out webkit has as good offscreen support as anyone. |
| 385 | |||
| 386 | |||
| 387 | *** TODO text field support | ||
| 388 | Emacs captures all keyboard events so text field support isn't super | ||
| 389 | straightforward. | ||
| 390 | |||
| 391 | **** propagate keyboard events | ||
| 392 | I have some old hacks for this and they are not good. | ||
| 393 | **** use the DOM model | ||
| 394 | expose document.activeElement to lisp. This is potentially more | ||
| 395 | interesting than just forwarding keyboard events. | ||
| 396 | |||
| 397 | webkit_web_view_get_dom_document () | ||
| 398 | |||
| 399 | **** DONE inject javascript | ||
| 400 | CLOSED: [2011-07-03 Sun 22:50] | ||
| 401 | webkit_web_view_execute_script () | ||
| 402 | |||
| 403 | this works now: | ||
| 404 | (xwidget-webkit-execute-script 5 "document.activeElement.value='test'") | ||
| 405 | |||
| 406 | so it should be possible to do some interesting stuff. | ||
| 407 | execute-script does however not return anything at the interface level | ||
| 408 | so satisfaction is not total. | ||
| 409 | |||
| 410 | http://markmail.org/message/4yowmdgras73z3x5 | ||
| 383 | 411 | ||
| 384 | 412 | ||
| 385 | ** TODO clipping of controllers | 413 | ** TODO clipping of controllers |
| @@ -479,13 +507,18 @@ the needed data is private to the base class. to overcome this: | |||
| 479 | ** TODO use FRAME_GTK_WIDGET (f) | 507 | ** TODO use FRAME_GTK_WIDGET (f) |
| 480 | rather than gwfixed | 508 | rather than gwfixed |
| 481 | 509 | ||
| 482 | ** TODO translate clicks | 510 | ** DONE translate clicks |
| 511 | CLOSED: [2011-07-03 Sun 22:12] | ||
| 483 | on onscreen webkit peer to offscreen | 512 | on onscreen webkit peer to offscreen |
| 484 | 513 | ||
| 485 | maybe | 514 | maybe |
| 486 | http://developer.gnome.org/gdk/stable/gdk-Windows.html#GdkWindow-from-embedder | 515 | http://developer.gnome.org/gdk/stable/gdk-Windows.html#GdkWindow-from-embedder |
| 487 | 516 | ||
| 517 | turned out tell be not so hard, captured events, copied them and | ||
| 518 | forwarded them offscreen! | ||
| 488 | 519 | ||
| 489 | ** TODO investigate gdk_window_redirect_to_drawable | 520 | ** TODO investigate gdk_window_redirect_to_drawable |
| 490 | http://developer.gnome.org/gdk/stable/gdk-Windows.html#gdk-offscreen-window-set-embedder | 521 | http://developer.gnome.org/gdk/stable/gdk-Windows.html#gdk-offscreen-window-set-embedder |
| 491 | maybe control be used in place of my own copy hacks? | 522 | maybe control be used in place of my own copy hacks? |
| 523 | |||
| 524 | |||
diff --git a/src/xwidget.c b/src/xwidget.c index a47d6c12dbc..c4e4f2c5ba2 100644 --- a/src/xwidget.c +++ b/src/xwidget.c | |||
| @@ -540,26 +540,21 @@ xwidget_init_view ( | |||
| 540 | } else if (EQ(xww->type, Qwebkit_osr)) { | 540 | } else if (EQ(xww->type, Qwebkit_osr)) { |
| 541 | #ifdef HAVE_WEBKIT_OSR | 541 | #ifdef HAVE_WEBKIT_OSR |
| 542 | xv->widget = gtk_drawing_area_new(); | 542 | xv->widget = gtk_drawing_area_new(); |
| 543 | gtk_widget_set_app_paintable ( xv->widget, TRUE); //because expose event handling | 543 | gtk_widget_set_app_paintable ( xv->widget, TRUE); //because expose event handling |
| 544 | #endif | 544 | #endif |
| 545 | #ifdef HAVE_GTK3 //and webkit_osr | 545 | #ifdef HAVE_GTK3 //and webkit_osr |
| 546 | gtk_widget_add_events(xv->widget, | 546 | gtk_widget_add_events(xv->widget, |
| 547 | GDK_BUTTON_PRESS_MASK | 547 | GDK_BUTTON_PRESS_MASK |
| 548 | | GDK_BUTTON_RELEASE_MASK | 548 | | GDK_BUTTON_RELEASE_MASK |
| 549 | | GDK_POINTER_MOTION_MASK | 549 | | GDK_POINTER_MOTION_MASK); |
| 550 | ); | ||
| 551 | |||
| 552 | g_signal_connect (G_OBJECT ( xv->widget), "draw", | 550 | g_signal_connect (G_OBJECT ( xv->widget), "draw", |
| 553 | G_CALLBACK (xwidget_osr_draw_callback), NULL); | 551 | G_CALLBACK (xwidget_osr_draw_callback), NULL); |
| 554 | |||
| 555 | g_signal_connect (G_OBJECT ( xv->widget), "button-press-event", | 552 | g_signal_connect (G_OBJECT ( xv->widget), "button-press-event", |
| 556 | G_CALLBACK (xwidget_osr_button_callback), NULL); | 553 | G_CALLBACK (xwidget_osr_button_callback), NULL); |
| 557 | g_signal_connect (G_OBJECT ( xv->widget), "button-release-event", | 554 | g_signal_connect (G_OBJECT ( xv->widget), "button-release-event", |
| 558 | G_CALLBACK (xwidget_osr_button_callback), NULL); | 555 | G_CALLBACK (xwidget_osr_button_callback), NULL); |
| 559 | g_signal_connect (G_OBJECT ( xv->widget), "motion-notify-event", | 556 | g_signal_connect (G_OBJECT ( xv->widget), "motion-notify-event", |
| 560 | G_CALLBACK (xwidget_osr_button_callback), NULL); | 557 | G_CALLBACK (xwidget_osr_button_callback), NULL); |
| 561 | |||
| 562 | |||
| 563 | #else | 558 | #else |
| 564 | g_signal_connect (G_OBJECT ( xv->widget), "expose_event", | 559 | g_signal_connect (G_OBJECT ( xv->widget), "expose_event", |
| 565 | G_CALLBACK (webkit_osr_expose_event_callback), NULL); | 560 | G_CALLBACK (webkit_osr_expose_event_callback), NULL); |
| @@ -774,6 +769,27 @@ DEFUN ("xwidget-webkit-goto-uri", Fxwidget_webkit_goto_uri, Sxwidget_webkit_got | |||
| 774 | 769 | ||
| 775 | webkit_web_view_load_uri(xw->widget_osr, SDATA(uri)); | 770 | webkit_web_view_load_uri(xw->widget_osr, SDATA(uri)); |
| 776 | } | 771 | } |
| 772 | |||
| 773 | DEFUN ("xwidget-webkit-execute-script", Fxwidget_webkit_execute_script, Sxwidget_webkit_execute_script, 2, 2, 0, | ||
| 774 | doc: /* webkit exec js.*/ | ||
| 775 | ) | ||
| 776 | (Lisp_Object xwidget_id, Lisp_Object script) | ||
| 777 | { | ||
| 778 | |||
| 779 | //TODO refactor this crap to something sane | ||
| 780 | struct xwidget *xw; | ||
| 781 | int xid; | ||
| 782 | |||
| 783 | CHECK_NUMBER (xwidget_id); | ||
| 784 | xid = XFASTINT (xwidget_id); | ||
| 785 | xw = &xwidgets[xid]; | ||
| 786 | |||
| 787 | //TODO check xw actually is of the correct type before trying stuff with it | ||
| 788 | |||
| 789 | webkit_web_view_execute_script(xw->widget_osr, SDATA(script)); | ||
| 790 | return Qnil; | ||
| 791 | } | ||
| 792 | |||
| 777 | #endif | 793 | #endif |
| 778 | 794 | ||
| 779 | 795 | ||
| @@ -868,7 +884,7 @@ DEFUN ("xwidget-set-keyboard-grab", Fxwidget_set_keyboard_grab, Sxwidget_set_key | |||
| 868 | xid = XFASTINT (xwidget_id); | 884 | xid = XFASTINT (xwidget_id); |
| 869 | kbd_flag = XFASTINT (kbd_grab); | 885 | kbd_flag = XFASTINT (kbd_grab); |
| 870 | xw = &xwidgets[xid]; | 886 | xw = &xwidgets[xid]; |
| 871 | if(xw->type != 3) return Qnil; //only relevant for xembed //TODO MVC | 887 | |
| 872 | 888 | ||
| 873 | printf ("kbd grab: %d %d\n", xid, kbd_flag); | 889 | printf ("kbd grab: %d %d\n", xid, kbd_flag); |
| 874 | if (kbd_flag) | 890 | if (kbd_flag) |
| @@ -991,7 +1007,9 @@ syms_of_xwidget (void) | |||
| 991 | defsubr (&Sxwidget_info); | 1007 | defsubr (&Sxwidget_info); |
| 992 | defsubr (&Sxwidget_resize_internal); | 1008 | defsubr (&Sxwidget_resize_internal); |
| 993 | defsubr (&Sxwidget_embed_steal_window); | 1009 | defsubr (&Sxwidget_embed_steal_window); |
| 1010 | |||
| 994 | defsubr (&Sxwidget_webkit_goto_uri); | 1011 | defsubr (&Sxwidget_webkit_goto_uri); |
| 1012 | defsubr (&Sxwidget_webkit_execute_script); | ||
| 995 | 1013 | ||
| 996 | DEFSYM (Qxwidget ,"xwidget"); | 1014 | DEFSYM (Qxwidget ,"xwidget"); |
| 997 | 1015 | ||