svnno****@sourc*****
svnno****@sourc*****
Fri Feb 22 09:12:44 JST 2008
Revision: 3386 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=3386 Author: ikezoe Date: 2008-02-22 09:12:43 +0900 (Fri, 22 Feb 2008) Log Message: ----------- 2008-02-22 Hiroyuki Ikezoe <poinc****@ikezo*****> * module/embed/webkit-gtk/kz-webkit-gtk.c: more functional. Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2008-02-21 23:35:18 UTC (rev 3385) +++ kazehakase/trunk/ChangeLog 2008-02-22 00:12:43 UTC (rev 3386) @@ -1,3 +1,7 @@ +2008-02-22 Hiroyuki Ikezoe <poinc****@ikezo*****> + + * module/embed/webkit-gtk/kz-webkit-gtk.c: more functional. + 2008-02-22 Kouhei Sutou <kou****@cozmi*****> * module/embed/, po/: supported webkit_gtk in po. Modified: kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c =================================================================== --- kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c 2008-02-21 23:35:18 UTC (rev 3385) +++ kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c 2008-02-22 00:12:43 UTC (rev 3386) @@ -25,6 +25,16 @@ #include "kz-embed.h" +typedef struct _KzWebKitGtkPrivate KzWebKitGtkPrivate; +struct _KzWebKitGtkPrivate +{ + gint progress; + gchar *location; + gchar *title; + gboolean lock; +}; +#define KZ_WEBKIT_GTK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), KZ_TYPE_WEBKIT_GTK, KzWebKitGtkPrivate)) + static GType kz_type_webkit_gtk = 0; static WebKitWebViewClass *kz_webkit_gtk_parent_class; @@ -34,23 +44,46 @@ static void kz_webkit_gtk_init (KzWebKitGtk *webkit_gtk); static void kz_webkit_gtk_dispose (GObject *object); -static void load_url (KzEmbed *kzembed, - const gchar *url); -static void stop_load (KzEmbed *kzembed); -static void reload (KzEmbed *kzembed, - KzEmbedReloadFlag flags); -static void go_back (KzEmbed *kzembed); -static void go_forward (KzEmbed *kzembed); -static gboolean can_go_back (KzEmbed *kzembed); -static gboolean can_go_forward (KzEmbed *kzembed); -static gboolean can_cut_selection(KzEmbed *kzembed); -static gboolean can_copy_selection (KzEmbed *kzembed); -static gboolean can_paste (KzEmbed *kzembed); -static void cut_selection (KzEmbed *kzembed); -static void copy_selection (KzEmbed *kzembed); -static void paste (KzEmbed *kzembed); -static void select_all (KzEmbed *kzembed); +static void load_url (KzEmbed *kzembed, + const gchar *url); +static void stop_load (KzEmbed *kzembed); +static void reload (KzEmbed *kzembed, + KzEmbedReloadFlag flags); +static void go_back (KzEmbed *kzembed); +static void go_forward (KzEmbed *kzembed); +static gboolean can_go_back (KzEmbed *kzembed); +static gboolean can_go_forward (KzEmbed *kzembed); +static gboolean can_cut_selection (KzEmbed *kzembed); +static gboolean can_copy_selection (KzEmbed *kzembed); +static gboolean can_paste (KzEmbed *kzembed); +static void cut_selection (KzEmbed *kzembed); +static void copy_selection (KzEmbed *kzembed); +static void paste (KzEmbed *kzembed); +static void select_all (KzEmbed *kzembed); +static gdouble get_progress (KzEmbed *kzembed); +static const gchar *get_title (KzEmbed *kzembed); +static const gchar *get_location (KzEmbed *kzembed); +static gchar *ensure_title (KzEmbed *kzembed); +static gboolean selection_is_collapsed (KzEmbed *kzembed); +static gboolean is_loading (KzEmbed *kzembed); +static void cb_title_changed (WebKitWebView* web_view, + WebKitWebFrame* web_frame, + const gchar* title, + gpointer data); +static void cb_progress_changed(WebKitWebView* web_view, + gint progress, + gpointer data); +static void cb_load_committed (WebKitWebView* web_view, + WebKitWebFrame* frame, + gpointer data); +static void cb_load_started (WebKitWebView* web_view, + WebKitWebFrame* frame, + gpointer data); +static void cb_load_finished (WebKitWebView* web_view, + WebKitWebFrame* frame, + gpointer data); + void kz_webkit_gtk_register_type (GTypeModule *module) { @@ -103,6 +136,8 @@ widget_class = GTK_WIDGET_CLASS(klass); object_class->dispose = kz_webkit_gtk_dispose; + + g_type_class_add_private(object_class, sizeof(KzWebKitGtkPrivate)); } @@ -111,12 +146,12 @@ { iface->load_url = load_url; iface->view_source = NULL; - iface->is_loading = NULL; - iface->get_title = NULL; - iface->get_location = NULL; - iface->ensure_title = NULL; + iface->is_loading = is_loading; + iface->get_title = get_title; + iface->get_location = get_location; + iface->ensure_title = ensure_title; iface->get_link_message = NULL; - iface->get_progress = NULL; + iface->get_progress = get_progress; iface->can_cut_selection = can_cut_selection; iface->can_copy_selection = can_copy_selection; iface->can_paste = can_paste; @@ -127,7 +162,7 @@ iface->get_selection_string = NULL; iface->find = NULL; iface->incremental_search = NULL; - iface->selection_is_collapsed = NULL; + iface->selection_is_collapsed = selection_is_collapsed; iface->get_links = NULL; iface->copy_page = NULL; iface->shistory_copy = NULL; @@ -211,11 +246,44 @@ static void kz_webkit_gtk_init (KzWebKitGtk *webkit) { + KzWebKitGtkPrivate *priv = KZ_WEBKIT_GTK_GET_PRIVATE(webkit); + WebKitWebSettings *settings; + + priv->location = NULL; + priv->title = NULL; + + priv->progress = 0; + + priv->lock = FALSE; + + g_signal_connect(webkit, "title-changed", + G_CALLBACK(cb_title_changed), NULL); + g_signal_connect(webkit, "load-progress-changed", + G_CALLBACK(cb_progress_changed), NULL); + g_signal_connect(webkit, "load-committed", + G_CALLBACK(cb_load_committed), NULL); + g_signal_connect(webkit, "load-started", + G_CALLBACK(cb_load_started), NULL); + g_signal_connect(webkit, "load-finished", + G_CALLBACK(cb_load_finished), NULL); + + settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webkit)); + if (!settings) + return; + } static void kz_webkit_gtk_dispose (GObject *object) { + KzWebKitGtkPrivate *priv = KZ_WEBKIT_GTK_GET_PRIVATE(object); + if (priv->location) + g_free(priv->location); + if (priv->title) + g_free(priv->title); + priv->location = NULL; + priv->title = NULL; + if (G_OBJECT_CLASS(kz_webkit_gtk_parent_class)->dispose) G_OBJECT_CLASS(kz_webkit_gtk_parent_class)->dispose(object); } @@ -339,3 +407,107 @@ webkit_web_view_select_all(WEBKIT_WEB_VIEW(kzembed)); } +static const gchar * +get_title (KzEmbed *kzembed) +{ + g_return_val_if_fail(KZ_IS_WEBKIT_GTK(kzembed), NULL); + + return KZ_WEBKIT_GTK_GET_PRIVATE(kzembed)->title; +} + +static const gchar * +get_location (KzEmbed *kzembed) +{ + g_return_val_if_fail(KZ_IS_WEBKIT_GTK(kzembed), NULL); + + return KZ_WEBKIT_GTK_GET_PRIVATE(kzembed)->location; +} + +static gchar * +ensure_title (KzEmbed *kzembed) +{ + const gchar *title; + + title = get_title(kzembed); + if (title) + return g_strdup(title); + + title = get_location(kzembed); + if (title) + return g_strdup(title); + + return g_strdup(_("No title")); +} + +static gdouble +get_progress (KzEmbed *kzembed) +{ + return (gdouble) KZ_WEBKIT_GTK_GET_PRIVATE(kzembed)->progress / 100; +} + +static gboolean +selection_is_collapsed (KzEmbed *kzembed) +{ + return webkit_web_view_has_selection(WEBKIT_WEB_VIEW(kzembed)); +} + +static gboolean +is_loading (KzEmbed *kzembed) +{ + return FALSE; +} + +static void +cb_title_changed (WebKitWebView* web_view, + WebKitWebFrame* web_frame, + const gchar* title, + gpointer data) +{ + KzWebKitGtkPrivate *priv = KZ_WEBKIT_GTK_GET_PRIVATE(web_view); + if (priv->title) + g_free(priv->title); + priv->title = g_strdup(title); + + g_signal_emit_by_name(web_view, "kz-title"); +} + +static void +cb_progress_changed (WebKitWebView* web_view, + gint progress, + gpointer data) +{ + KzWebKitGtkPrivate *priv = KZ_WEBKIT_GTK_GET_PRIVATE(web_view); + priv->progress = progress; + + g_signal_emit_by_name(web_view, "kz-progress"); +} + +static void +cb_load_committed (WebKitWebView* web_view, + WebKitWebFrame* frame, + gpointer data) +{ + KzWebKitGtkPrivate *priv = KZ_WEBKIT_GTK_GET_PRIVATE(web_view); + const gchar* location = webkit_web_frame_get_uri(frame); + if (priv->location) + g_free(priv->location); + priv->location = g_strdup(location); + g_signal_emit_by_name(web_view, "kz-location"); +} + +static void +cb_load_started (WebKitWebView* web_view, + WebKitWebFrame* frame, + gpointer data) +{ + g_signal_emit_by_name(web_view, "kz-net-start"); +} + +static void +cb_load_finished (WebKitWebView* web_view, + WebKitWebFrame* frame, + gpointer data) +{ + g_signal_emit_by_name(web_view, "kz-net-stop"); +} +