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