[kazehakase-svn] [3514] 2008-12-25 Hiroyuki Ikezoe <poinc****@ikezo*****>

Back to archive index

svnno****@sourc***** svnno****@sourc*****
Thu Dec 25 13:10:59 JST 2008


Revision: 3514
          http://svn.sourceforge.jp/view?root=kazehakase&view=rev&rev=3514
Author:   ikezoe
Date:     2008-12-25 13:10:58 +0900 (Thu, 25 Dec 2008)

Log Message:
-----------
2008-12-25  Hiroyuki Ikezoe  <poinc****@ikezo*****>

	* module/embed/webkit-gtk/kz-webkit-gtk.c: Open a new tab with middle
	click. Also store navigation history but still buggy.

Modified Paths:
--------------
    kazehakase/trunk/ChangeLog
    kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c

Modified: kazehakase/trunk/ChangeLog
===================================================================
--- kazehakase/trunk/ChangeLog	2008-10-28 15:07:31 UTC (rev 3513)
+++ kazehakase/trunk/ChangeLog	2008-12-25 04:10:58 UTC (rev 3514)
@@ -1,3 +1,8 @@
+2008-12-25  Hiroyuki Ikezoe  <poinc****@ikezo*****>
+
+	* module/embed/webkit-gtk/kz-webkit-gtk.c: Open a new tab with middle
+	click. Also store navigation history but still buggy.
+
 2008-10-29  Ryo SHIMIZU  <furyo****@on-ai*****>
 
 	* configure.ac: version 0.5.6

Modified: kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c
===================================================================
--- kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c	2008-10-28 15:07:31 UTC (rev 3513)
+++ kazehakase/trunk/module/embed/webkit-gtk/kz-webkit-gtk.c	2008-12-25 04:10:58 UTC (rev 3514)
@@ -94,7 +94,17 @@
 static gboolean	    get_allow_images	   (KzEmbed      *kzembed);
 static void	    set_allow_images	   (KzEmbed      *kzembed,
 					    gboolean      allow);
+static void	    get_history            (KzEmbed      *kzembed,
+					    KzBookmark   *history);
 
+static gboolean     shistory_get_pos       (KzEmbed      *kzembed,
+					    gint         *pos,
+					    gint         *count);
+static void         shistory_get_nth       (KzEmbed      *kzembed, 
+					    gint          nth,
+					    gboolean      is_relative,
+					    gchar       **uri,
+					    gchar       **title);
 static void	cb_title_changed   (WebKitWebView* web_view,
 				    WebKitWebFrame* web_frame,
 				    const gchar* title,
@@ -115,6 +125,16 @@
 				    const gchar *title,
 				    const gchar *location,
 				    gpointer data);
+static void     cb_populate_popup  (WebKitWebView* web_view,
+		                    GtkMenu *menu,
+                                    gpointer data);
+static gboolean cb_navigation_policy_decision_requested
+                                   (WebKitWebView* web_view,
+                                    WebKitWebFrame *frame,
+                                    WebKitNetworkRequest *request,
+                                    WebKitWebNavigationAction *action,
+                                    WebKitWebPolicyDecision *decision,
+                                    gpointer data);
 
 static void set_default_preferences (KzWebKitGtk *webkit);
 
@@ -203,8 +223,8 @@
 	iface->get_links              = NULL;
 	iface->copy_page              = NULL;
 	iface->shistory_copy          = NULL;
-	iface->shistory_get_pos       = NULL;
-	iface->shistory_get_nth       = NULL;
+	iface->shistory_get_pos       = shistory_get_pos;
+	iface->shistory_get_nth       = shistory_get_nth;
 	iface->reload                 = reload;
 	iface->stop_load              = stop_load;
 	iface->go_back                = go_back;
@@ -240,7 +260,7 @@
 	iface->get_text_size          = NULL;
 	iface->get_html_with_contents = NULL;
 	iface->set_history            = NULL;
-	iface->get_history            = NULL;
+	iface->get_history            = get_history;
 	iface->get_last_modified      = NULL;
 	iface->fine_scroll            = NULL;
 	iface->page_up                = NULL;
@@ -302,6 +322,10 @@
 			 G_CALLBACK(cb_load_finished), webkit);
 	g_signal_connect(priv->web_view, "hovering-over-link",
 			 G_CALLBACK(cb_hover_link), webkit);
+	g_signal_connect(priv->web_view, "populate-popup",
+			 G_CALLBACK(cb_populate_popup), webkit);
+	g_signal_connect(priv->web_view, "navigation-policy-decision-requested",
+			 G_CALLBACK(cb_navigation_policy_decision_requested), webkit);
 	set_default_preferences(webkit);
 }
 
@@ -639,6 +663,119 @@
 }
 
 static void
+merge_item_to_history (KzBookmark *history, GList **current_bookmark, WebKitWebHistoryItem *item)
+{
+	const gchar *title, *uri;
+	KzBookmark *bookmark;
+
+	title = webkit_web_history_item_get_title(item);
+	uri = webkit_web_history_item_get_uri(item);
+
+	if (!*current_bookmark)
+	{
+		bookmark = kz_bookmark_new_with_attrs(title, uri, NULL);
+		kz_bookmark_append(history, bookmark);
+		g_object_unref(bookmark);
+	}
+	else
+	{
+		bookmark = KZ_BOOKMARK((*current_bookmark)->data);
+		kz_bookmark_set_title(bookmark, title);
+		kz_bookmark_set_link(bookmark, uri);
+		kz_bookmark_set_last_visited(bookmark, 0);
+		*current_bookmark = g_list_next(*current_bookmark);
+	}
+}
+
+static void
+merge_history_items_to_history (KzBookmark *history, GList **current_bookmark, GList *items)
+{
+	GList *node;
+	for (node = items; node; node = g_list_next(node))
+	{
+		WebKitWebHistoryItem *item = WEBKIT_WEB_HISTORY_ITEM(node->data);
+		merge_item_to_history(history, current_bookmark, item);
+	}
+}
+
+static void
+get_history (KzEmbed *kzembed, KzBookmark *history)
+{
+	GList *children, *bookmark_node;
+	GList *backward_items, *forward_items;
+	WebKitWebBackForwardList *list;
+	WebKitWebHistoryItem *current_item;
+
+	list = webkit_web_view_get_back_forward_list(KZ_WEBKIT_GTK_GET_PRIVATE(kzembed)->web_view);
+	if (!list)
+		return;
+
+	backward_items = webkit_web_back_forward_list_get_back_list_with_limit(list, 99);
+	forward_items = webkit_web_back_forward_list_get_forward_list_with_limit(list, 99);
+	current_item = webkit_web_back_forward_list_get_current_item(list);
+
+	children = kz_bookmark_get_children(history);
+	bookmark_node = children;
+
+	merge_history_items_to_history(history, &bookmark_node, backward_items);
+	kz_bookmark_set_current(history, g_list_length(backward_items));
+
+	merge_item_to_history(history, &bookmark_node, current_item);
+	webkit_web_back_forward_list_get_current_item(list);
+
+	merge_history_items_to_history(history, &bookmark_node, forward_items);
+
+	if (bookmark_node)
+		bookmark_node = g_list_last(bookmark_node);
+	while (bookmark_node)
+	{
+		GList *previous_node;
+		KzBookmark *child = KZ_BOOKMARK(bookmark_node->data);
+		previous_node = g_list_previous(bookmark_node);
+		kz_bookmark_remove(history, child);
+		bookmark_node = previous_node;
+	}
+
+	g_list_free(children);
+}
+
+static gboolean
+shistory_get_pos (KzEmbed *kzembed, gint *pos, gint *count)
+{
+	WebKitWebBackForwardList *list;
+
+	list = webkit_web_view_get_back_forward_list(KZ_WEBKIT_GTK_GET_PRIVATE(kzembed)->web_view);
+	if (!list)
+		return FALSE;
+
+	*pos = webkit_web_back_forward_list_get_back_length(list);
+	*count = *pos + webkit_web_back_forward_list_get_forward_length(list);
+
+	return TRUE;
+}
+
+static void
+shistory_get_nth (KzEmbed *kzembed, 
+		  gint nth,
+		  gboolean is_relative,
+		  gchar **uri,
+		  gchar **title)
+{
+	WebKitWebBackForwardList *list;
+	WebKitWebHistoryItem *item;
+
+	list = webkit_web_view_get_back_forward_list(KZ_WEBKIT_GTK_GET_PRIVATE(kzembed)->web_view);
+	if (!list)
+		return;
+	item = webkit_web_back_forward_list_get_nth_item(list, nth);
+	if (!item)
+		return;
+
+	*uri = g_strdup(webkit_web_history_item_get_uri(item));
+	*title = g_strdup(webkit_web_history_item_get_title(item));
+}
+
+static void
 cb_title_changed (WebKitWebView* web_view,
 		  WebKitWebFrame* web_frame,
 		  const gchar* title,
@@ -710,6 +847,43 @@
 }
 
 static void
+cb_populate_popup (WebKitWebView* web_view,
+		   GtkMenu *menu,
+		   gpointer data)
+{
+}
+
+static gboolean
+cb_navigation_policy_decision_requested (WebKitWebView* web_view,
+	                                 WebKitWebFrame *frame,
+                                         WebKitNetworkRequest *request,
+                                         WebKitWebNavigationAction *action,
+                                         WebKitWebPolicyDecision *decision,
+                                         gpointer data)
+{
+	WebKitWebNavigationReason reason;
+	gint button;
+
+	reason = webkit_web_navigation_action_get_reason(action);
+	button = webkit_web_navigation_action_get_button(action);
+
+	if (reason == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED &&
+	    button == 2)
+	{
+		const char *uri;
+		KzWebKitGtk *webkit = NULL;
+
+		g_signal_emit_by_name(data, "kz-new-window", &webkit);
+		uri = webkit_network_request_get_uri(request);
+                webkit_web_view_open(KZ_WEBKIT_GTK_GET_PRIVATE(webkit)->web_view, uri);
+
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+static void
 set_font_preferences (KzProfile *profile, WebKitWebSettings *settings)
 {
 	/* font settings */



More information about the Kazehakase-cvs mailing list
Back to archive index