[yelp: 1/2] [yelp-view] Use WebKitHitTestResult:inner-node for read-later link text
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp: 1/2] [yelp-view] Use WebKitHitTestResult:inner-node for read-later link text
- Date: Tue, 8 Jun 2010 15:51:19 +0000 (UTC)
commit 85a849d96cd06cd43ad15a83519a76195979ad29
Author: Shaun McCance <shaunm gnome org>
Date: Mon Jun 7 10:14:11 2010 -0500
[yelp-view] Use WebKitHitTestResult:inner-node for read-later link text
This property is not available in WebKit trunk yet. See
https://bugs.webkit.org/show_bug.cgi?id=40131
libyelp/yelp-view.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 50 insertions(+), 4 deletions(-)
---
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index d3fb67e..18a2229 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -29,7 +29,6 @@
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <webkit/webkit.h>
-#include <webkit/webkitwebresource.h>
#include "yelp-debug.h"
#include "yelp-docbook-document.h"
@@ -839,6 +838,7 @@ view_populate_popup (YelpView *view,
YelpViewPrivate *priv = GET_PRIV (view);
GList *children;
GtkWidget *item;
+ WebKitDOMNode *node, *cur, *link_node = NULL;
children = gtk_container_get_children (GTK_CONTAINER (menu));
while (children) {
@@ -851,7 +851,16 @@ view_populate_popup (YelpView *view,
event = gtk_get_current_event ();
result = webkit_web_view_get_hit_test_result (WEBKIT_WEB_VIEW (view), (GdkEventButton *) event);
- g_object_get (result, "context", &context, NULL);
+ g_object_get (result,
+ "context", &context,
+ "inner-node", &node,
+ NULL);
+ for (cur = node; cur != NULL; cur = webkit_dom_node_get_parent_node (cur)) {
+ gchar *name = webkit_dom_node_get_node_name (cur);
+ if (g_str_equal (name, "a"))
+ link_node = cur;
+ g_free (name);
+ }
if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
gchar *uri;
@@ -860,8 +869,45 @@ view_populate_popup (YelpView *view,
priv->popup_link_uri = uri;
g_free (priv->popup_link_text);
- /* FIXME */
- priv->popup_link_text = g_strdup (uri);
+ /* FIXME: Handled space-separated class names, etc. See about a convenience API
+ * in WebKit, because this kind of processing in C really sucks.
+ */
+ if (link_node != NULL) {
+ gboolean handled = FALSE;
+ WebKitDOMNode *child = webkit_dom_node_get_first_child (link_node);
+ gchar *childname = webkit_dom_node_get_node_name (child);
+ if (g_str_equal (childname, "div")) {
+ WebKitDOMNamedNodeMap *map = webkit_dom_node_get_attributes (child);
+ WebKitDOMNode *attr = webkit_dom_named_node_map_get_named_item (map, "class");
+ if (attr) {
+ gchar *htmlclass = webkit_dom_node_get_text_content (attr);
+ if (g_str_equal (htmlclass, "linkdiv")) {
+ child = webkit_dom_node_get_first_child (child);
+ g_free (childname);
+ childname = webkit_dom_node_get_node_name (child);
+ if (g_str_equal (childname, "div")) {
+ map = webkit_dom_node_get_attributes (child);
+ attr = webkit_dom_named_node_map_get_named_item (map, "class");
+ if (attr) {
+ g_free (htmlclass);
+ htmlclass = webkit_dom_node_get_text_content (attr);
+ if (g_str_equal (htmlclass, "title")) {
+ priv->popup_link_text = webkit_dom_node_get_text_content (child);
+ handled = TRUE;
+ }
+ }
+ }
+ }
+ g_free (htmlclass);
+ }
+ }
+ g_free (childname);
+ if (!handled)
+ priv->popup_link_text = webkit_dom_node_get_text_content (link_node);
+ }
+ else {
+ priv->popup_link_text = g_strdup (uri);
+ }
if (g_str_has_prefix (priv->popup_link_uri, "mailto:")) {
/* Not using a mnemonic because underscores are common in email
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]