| 540 } |
544 } |
| 541 |
545 |
| 542 void |
546 void |
| 543 gtk_webview_safe_execute_script(GtkWebView *webview, const char *script) |
547 gtk_webview_safe_execute_script(GtkWebView *webview, const char *script) |
| 544 { |
548 { |
| 545 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
549 GtkWebViewPriv *priv; |
| |
550 |
| |
551 g_return_if_fail(webview != NULL); |
| |
552 |
| |
553 priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
| 546 g_queue_push_tail(priv->js_queue, g_strdup(script)); |
554 g_queue_push_tail(priv->js_queue, g_strdup(script)); |
| 547 g_idle_add((GSourceFunc)process_js_script_queue, webview); |
555 g_idle_add((GSourceFunc)process_js_script_queue, webview); |
| 548 } |
556 } |
| 549 |
557 |
| 550 void |
558 void |
| 551 gtk_webview_load_html_string(GtkWebView *webview, const char *html) |
559 gtk_webview_load_html_string(GtkWebView *webview, const char *html) |
| 552 { |
560 { |
| |
561 g_return_if_fail(webview != NULL); |
| |
562 |
| 553 webkit_web_view_load_string(WEBKIT_WEB_VIEW(webview), html, NULL, NULL, |
563 webkit_web_view_load_string(WEBKIT_WEB_VIEW(webview), html, NULL, NULL, |
| 554 "file:///"); |
564 "file:///"); |
| 555 } |
565 } |
| 556 |
566 |
| 557 void |
567 void |
| 558 gtk_webview_load_html_string_with_selection(GtkWebView *webview, const char *html) |
568 gtk_webview_load_html_string_with_selection(GtkWebView *webview, const char *html) |
| 559 { |
569 { |
| |
570 g_return_if_fail(webview != NULL); |
| |
571 |
| 560 gtk_webview_load_html_string(webview, html); |
572 gtk_webview_load_html_string(webview, html); |
| 561 gtk_webview_safe_execute_script(webview, |
573 gtk_webview_safe_execute_script(webview, |
| 562 "var s = window.getSelection();" |
574 "var s = window.getSelection();" |
| 563 "var r = document.createRange();" |
575 "var r = document.createRange();" |
| 564 "var n = document.getElementById('caret');" |
576 "var n = document.getElementById('caret');" |
| 572 } |
584 } |
| 573 |
585 |
| 574 void |
586 void |
| 575 gtk_webview_append_html(GtkWebView *webview, const char *html) |
587 gtk_webview_append_html(GtkWebView *webview, const char *html) |
| 576 { |
588 { |
| 577 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
589 GtkWebViewPriv *priv; |
| 578 WebKitDOMDocument *doc; |
590 WebKitDOMDocument *doc; |
| 579 WebKitDOMHTMLElement *body; |
591 WebKitDOMHTMLElement *body; |
| |
592 |
| |
593 g_return_if_fail(webview != NULL); |
| |
594 |
| |
595 priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
| 580 doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
596 doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
| 581 body = webkit_dom_document_get_body(doc); |
597 body = webkit_dom_document_get_body(doc); |
| 582 webkit_dom_html_element_insert_adjacent_html(body, "beforeend", html, NULL); |
598 webkit_dom_html_element_insert_adjacent_html(body, "beforeend", html, NULL); |
| 583 priv->empty = FALSE; |
599 priv->empty = FALSE; |
| 584 } |
600 } |
| 585 |
601 |
| 586 void |
602 void |
| 587 gtk_webview_set_vadjustment(GtkWebView *webview, GtkAdjustment *vadj) |
603 gtk_webview_set_vadjustment(GtkWebView *webview, GtkAdjustment *vadj) |
| 588 { |
604 { |
| 589 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
605 GtkWebViewPriv *priv; |
| |
606 |
| |
607 g_return_if_fail(webview != NULL); |
| |
608 |
| |
609 priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
| 590 priv->vadj = vadj; |
610 priv->vadj = vadj; |
| 591 } |
611 } |
| 592 |
612 |
| 593 void |
613 void |
| 594 gtk_webview_scroll_to_end(GtkWebView *webview, gboolean smooth) |
614 gtk_webview_scroll_to_end(GtkWebView *webview, gboolean smooth) |
| 595 { |
615 { |
| 596 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
616 GtkWebViewPriv *priv; |
| |
617 |
| |
618 g_return_if_fail(webview != NULL); |
| |
619 |
| |
620 priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
| 597 if (priv->scroll_time) |
621 if (priv->scroll_time) |
| 598 g_timer_destroy(priv->scroll_time); |
622 g_timer_destroy(priv->scroll_time); |
| 599 if (priv->scroll_src) |
623 if (priv->scroll_src) |
| 600 g_source_remove(priv->scroll_src); |
624 g_source_remove(priv->scroll_src); |
| 601 if (smooth) { |
625 if (smooth) { |
| 740 |
776 |
| 741 void |
777 void |
| 742 pidgin_webview_set_spellcheck(GtkWebView *webview, gboolean enable) |
778 pidgin_webview_set_spellcheck(GtkWebView *webview, gboolean enable) |
| 743 { |
779 { |
| 744 WebKitWebSettings *settings; |
780 WebKitWebSettings *settings; |
| |
781 |
| |
782 g_return_if_fail(webview != NULL); |
| 745 |
783 |
| 746 settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview)); |
784 settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview)); |
| 747 g_object_set(G_OBJECT(settings), "enable-spell-checking", enable, NULL); |
785 g_object_set(G_OBJECT(settings), "enable-spell-checking", enable, NULL); |
| 748 webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webview), settings); |
786 webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webview), settings); |
| 749 } |
787 } |
| 750 |
788 |
| 751 void |
789 void |
| 752 gtk_webview_set_whole_buffer_formatting_only(GtkWebView *webview, gboolean wbfo) |
790 gtk_webview_set_whole_buffer_formatting_only(GtkWebView *webview, gboolean wbfo) |
| 753 { |
791 { |
| 754 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
792 GtkWebViewPriv *priv; |
| |
793 |
| |
794 g_return_if_fail(webview != NULL); |
| |
795 |
| |
796 priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
| 755 priv->edit.wbfo = wbfo; |
797 priv->edit.wbfo = wbfo; |
| 756 } |
798 } |
| 757 |
799 |
| 758 void |
800 void |
| 759 gtk_webview_set_format_functions(GtkWebView *webview, GtkWebViewButtons buttons) |
801 gtk_webview_set_format_functions(GtkWebView *webview, GtkWebViewButtons buttons) |
| 760 { |
802 { |
| 761 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
803 GtkWebViewPriv *priv; |
| 762 GObject *object = g_object_ref(G_OBJECT(webview)); |
804 GObject *object; |
| |
805 |
| |
806 g_return_if_fail(webview != NULL); |
| |
807 |
| |
808 priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
| |
809 object = g_object_ref(G_OBJECT(webview)); |
| 763 priv->format_functions = buttons; |
810 priv->format_functions = buttons; |
| 764 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); |
811 g_signal_emit(object, signals[BUTTONS_UPDATE], 0, buttons); |
| 765 g_object_unref(object); |
812 g_object_unref(object); |
| 766 } |
813 } |
| 767 |
814 |
| 850 |
912 |
| 851 char * |
913 char * |
| 852 gtk_webview_get_current_fontface(GtkWebView *webview) |
914 gtk_webview_get_current_fontface(GtkWebView *webview) |
| 853 { |
915 { |
| 854 WebKitDOMDocument *dom; |
916 WebKitDOMDocument *dom; |
| |
917 |
| |
918 g_return_val_if_fail(webview != NULL, NULL); |
| |
919 |
| 855 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
920 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
| 856 return webkit_dom_document_query_command_value(dom, "fontName"); |
921 return webkit_dom_document_query_command_value(dom, "fontName"); |
| 857 } |
922 } |
| 858 |
923 |
| 859 char * |
924 char * |
| 860 gtk_webview_get_current_forecolor(GtkWebView *webview) |
925 gtk_webview_get_current_forecolor(GtkWebView *webview) |
| 861 { |
926 { |
| 862 WebKitDOMDocument *dom; |
927 WebKitDOMDocument *dom; |
| |
928 |
| |
929 g_return_val_if_fail(webview != NULL, NULL); |
| |
930 |
| 863 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
931 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
| 864 return webkit_dom_document_query_command_value(dom, "foreColor"); |
932 return webkit_dom_document_query_command_value(dom, "foreColor"); |
| 865 } |
933 } |
| 866 |
934 |
| 867 char * |
935 char * |
| 868 gtk_webview_get_current_backcolor(GtkWebView *webview) |
936 gtk_webview_get_current_backcolor(GtkWebView *webview) |
| 869 { |
937 { |
| 870 WebKitDOMDocument *dom; |
938 WebKitDOMDocument *dom; |
| |
939 |
| |
940 g_return_val_if_fail(webview != NULL, NULL); |
| |
941 |
| 871 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
942 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
| 872 return webkit_dom_document_query_command_value(dom, "backColor"); |
943 return webkit_dom_document_query_command_value(dom, "backColor"); |
| 873 } |
944 } |
| 874 |
945 |
| 875 gint |
946 gint |
| 876 gtk_webview_get_current_fontsize(GtkWebView *webview) |
947 gtk_webview_get_current_fontsize(GtkWebView *webview) |
| 877 { |
948 { |
| 878 WebKitDOMDocument *dom; |
949 WebKitDOMDocument *dom; |
| 879 gchar *text; |
950 gchar *text; |
| 880 gint size; |
951 gint size; |
| |
952 |
| |
953 g_return_val_if_fail(webview != NULL, 0); |
| 881 |
954 |
| 882 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
955 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
| 883 text = webkit_dom_document_query_command_value(dom, "fontSize"); |
956 text = webkit_dom_document_query_command_value(dom, "fontSize"); |
| 884 size = atoi(text); |
957 size = atoi(text); |
| 885 g_free(text); |
958 g_free(text); |
| 896 void |
969 void |
| 897 gtk_webview_clear_formatting(GtkWebView *webview) |
970 gtk_webview_clear_formatting(GtkWebView *webview) |
| 898 { |
971 { |
| 899 GObject *object; |
972 GObject *object; |
| 900 |
973 |
| |
974 g_return_if_fail(webview != NULL); |
| |
975 |
| 901 object = g_object_ref(G_OBJECT(webview)); |
976 object = g_object_ref(G_OBJECT(webview)); |
| 902 g_signal_emit(object, signals[CLEAR_FORMAT], 0); |
977 g_signal_emit(object, signals[CLEAR_FORMAT], 0); |
| 903 g_object_unref(object); |
978 g_object_unref(object); |
| 904 } |
979 } |
| 905 |
980 |
| 906 void |
981 void |
| 907 gtk_webview_toggle_bold(GtkWebView *webview) |
982 gtk_webview_toggle_bold(GtkWebView *webview) |
| 908 { |
983 { |
| |
984 g_return_if_fail(webview != NULL); |
| 909 emit_format_signal(webview, GTK_WEBVIEW_BOLD); |
985 emit_format_signal(webview, GTK_WEBVIEW_BOLD); |
| 910 } |
986 } |
| 911 |
987 |
| 912 void |
988 void |
| 913 gtk_webview_toggle_italic(GtkWebView *webview) |
989 gtk_webview_toggle_italic(GtkWebView *webview) |
| 914 { |
990 { |
| |
991 g_return_if_fail(webview != NULL); |
| 915 emit_format_signal(webview, GTK_WEBVIEW_ITALIC); |
992 emit_format_signal(webview, GTK_WEBVIEW_ITALIC); |
| 916 } |
993 } |
| 917 |
994 |
| 918 void |
995 void |
| 919 gtk_webview_toggle_underline(GtkWebView *webview) |
996 gtk_webview_toggle_underline(GtkWebView *webview) |
| 920 { |
997 { |
| |
998 g_return_if_fail(webview != NULL); |
| 921 emit_format_signal(webview, GTK_WEBVIEW_UNDERLINE); |
999 emit_format_signal(webview, GTK_WEBVIEW_UNDERLINE); |
| 922 } |
1000 } |
| 923 |
1001 |
| 924 void |
1002 void |
| 925 gtk_webview_toggle_strike(GtkWebView *webview) |
1003 gtk_webview_toggle_strike(GtkWebView *webview) |
| 926 { |
1004 { |
| |
1005 g_return_if_fail(webview != NULL); |
| 927 emit_format_signal(webview, GTK_WEBVIEW_STRIKE); |
1006 emit_format_signal(webview, GTK_WEBVIEW_STRIKE); |
| 928 } |
1007 } |
| 929 |
1008 |
| 930 gboolean |
1009 gboolean |
| 931 gtk_webview_toggle_forecolor(GtkWebView *webview, const char *color) |
1010 gtk_webview_toggle_forecolor(GtkWebView *webview, const char *color) |
| 932 { |
1011 { |
| |
1012 g_return_val_if_fail(webview != NULL, FALSE); |
| |
1013 |
| 933 do_formatting(webview, "foreColor", color); |
1014 do_formatting(webview, "foreColor", color); |
| 934 emit_format_signal(webview, GTK_WEBVIEW_FORECOLOR); |
1015 emit_format_signal(webview, GTK_WEBVIEW_FORECOLOR); |
| 935 |
1016 |
| 936 return FALSE; |
1017 return FALSE; |
| 937 } |
1018 } |
| 938 |
1019 |
| 939 gboolean |
1020 gboolean |
| 940 gtk_webview_toggle_backcolor(GtkWebView *webview, const char *color) |
1021 gtk_webview_toggle_backcolor(GtkWebView *webview, const char *color) |
| 941 { |
1022 { |
| |
1023 g_return_val_if_fail(webview != NULL, FALSE); |
| |
1024 |
| 942 do_formatting(webview, "backColor", color); |
1025 do_formatting(webview, "backColor", color); |
| 943 emit_format_signal(webview, GTK_WEBVIEW_BACKCOLOR); |
1026 emit_format_signal(webview, GTK_WEBVIEW_BACKCOLOR); |
| 944 |
1027 |
| 945 return FALSE; |
1028 return FALSE; |
| 946 } |
1029 } |
| 947 |
1030 |
| 948 gboolean |
1031 gboolean |
| 949 gtk_webview_toggle_fontface(GtkWebView *webview, const char *face) |
1032 gtk_webview_toggle_fontface(GtkWebView *webview, const char *face) |
| 950 { |
1033 { |
| |
1034 g_return_val_if_fail(webview != NULL, FALSE); |
| |
1035 |
| 951 do_formatting(webview, "fontName", face); |
1036 do_formatting(webview, "fontName", face); |
| 952 emit_format_signal(webview, GTK_WEBVIEW_FACE); |
1037 emit_format_signal(webview, GTK_WEBVIEW_FACE); |
| 953 |
1038 |
| 954 return FALSE; |
1039 return FALSE; |
| 955 } |
1040 } |
| 956 |
1041 |
| 957 void |
1042 void |
| 958 gtk_webview_font_set_size(GtkWebView *webview, gint size) |
1043 gtk_webview_font_set_size(GtkWebView *webview, gint size) |
| 959 { |
1044 { |
| 960 char *tmp = g_strdup_printf("%d", size); |
1045 char *tmp; |
| |
1046 |
| |
1047 g_return_if_fail(webview != NULL); |
| |
1048 |
| |
1049 tmp = g_strdup_printf("%d", size); |
| 961 do_formatting(webview, "fontSize", tmp); |
1050 do_formatting(webview, "fontSize", tmp); |
| 962 emit_format_signal(webview, GTK_WEBVIEW_SHRINK|GTK_WEBVIEW_GROW); |
1051 emit_format_signal(webview, GTK_WEBVIEW_SHRINK|GTK_WEBVIEW_GROW); |
| 963 g_free(tmp); |
1052 g_free(tmp); |
| 964 } |
1053 } |
| 965 |
1054 |
| 966 void |
1055 void |
| 967 gtk_webview_font_shrink(GtkWebView *webview) |
1056 gtk_webview_font_shrink(GtkWebView *webview) |
| 968 { |
1057 { |
| |
1058 g_return_if_fail(webview != NULL); |
| 969 emit_format_signal(webview, GTK_WEBVIEW_SHRINK); |
1059 emit_format_signal(webview, GTK_WEBVIEW_SHRINK); |
| 970 } |
1060 } |
| 971 |
1061 |
| 972 void |
1062 void |
| 973 gtk_webview_font_grow(GtkWebView *webview) |
1063 gtk_webview_font_grow(GtkWebView *webview) |
| 974 { |
1064 { |
| |
1065 g_return_if_fail(webview != NULL); |
| 975 emit_format_signal(webview, GTK_WEBVIEW_GROW); |
1066 emit_format_signal(webview, GTK_WEBVIEW_GROW); |
| 976 } |
1067 } |
| 977 |
1068 |
| 978 void |
1069 void |
| 979 gtk_webview_insert_hr(GtkWebView *webview) |
1070 gtk_webview_insert_hr(GtkWebView *webview) |
| 980 { |
1071 { |
| 981 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
1072 GtkWebViewPriv *priv; |
| 982 WebKitDOMDocument *dom; |
1073 WebKitDOMDocument *dom; |
| 983 |
1074 |
| |
1075 g_return_if_fail(webview != NULL); |
| |
1076 |
| |
1077 priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
| 984 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
1078 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
| 985 |
1079 |
| 986 priv->edit.block_changed = TRUE; |
1080 priv->edit.block_changed = TRUE; |
| 987 webkit_dom_document_exec_command(dom, "insertHorizontalRule", FALSE, ""); |
1081 webkit_dom_document_exec_command(dom, "insertHorizontalRule", FALSE, ""); |
| 988 priv->edit.block_changed = FALSE; |
1082 priv->edit.block_changed = FALSE; |
| 989 } |
1083 } |
| 990 |
1084 |
| 991 void |
1085 void |
| 992 gtk_webview_insert_link(GtkWebView *webview, const char *url, const char *desc) |
1086 gtk_webview_insert_link(GtkWebView *webview, const char *url, const char *desc) |
| 993 { |
1087 { |
| 994 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
1088 GtkWebViewPriv *priv; |
| 995 WebKitDOMDocument *dom; |
1089 WebKitDOMDocument *dom; |
| 996 char *link; |
1090 char *link; |
| 997 |
1091 |
| |
1092 g_return_if_fail(webview != NULL); |
| |
1093 |
| |
1094 priv = GTK_WEBVIEW_GET_PRIVATE(webview); |
| 998 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
1095 dom = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(webview)); |
| 999 link = g_strdup_printf("<a href='%s'>%s</a>", url, desc ? desc : url); |
1096 link = g_strdup_printf("<a href='%s'>%s</a>", url, desc ? desc : url); |
| 1000 |
1097 |
| 1001 priv->edit.block_changed = TRUE; |
1098 priv->edit.block_changed = TRUE; |
| 1002 webkit_dom_document_exec_command(dom, "insertHTML", FALSE, link); |
1099 webkit_dom_document_exec_command(dom, "insertHTML", FALSE, link); |