aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorXan Lopez <xan@igalia.com>2012-03-16 08:16:30 +0800
committerXan Lopez <xan@igalia.com>2012-03-16 08:18:08 +0800
commit9d8fd9a553a114ef9b5d8ba559bde0899539a44b (patch)
treed6a3b780c5567348cee169884f3ef715de0eca8b /src
parent76ba84b394edbaf7e0b4ff2053612fcb13c909da (diff)
downloadgsoc2013-epiphany-9d8fd9a553a114ef9b5d8ba559bde0899539a44b.tar
gsoc2013-epiphany-9d8fd9a553a114ef9b5d8ba559bde0899539a44b.tar.gz
gsoc2013-epiphany-9d8fd9a553a114ef9b5d8ba559bde0899539a44b.tar.bz2
gsoc2013-epiphany-9d8fd9a553a114ef9b5d8ba559bde0899539a44b.tar.lz
gsoc2013-epiphany-9d8fd9a553a114ef9b5d8ba559bde0899539a44b.tar.xz
gsoc2013-epiphany-9d8fd9a553a114ef9b5d8ba559bde0899539a44b.tar.zst
gsoc2013-epiphany-9d8fd9a553a114ef9b5d8ba559bde0899539a44b.zip
Fix bookmarklet's titles when they are created
This was pretty much broken since the Gecko days. On top of that, catch the case where the bookmarklet title is in the child node of the anchor element, which we never got right before. https://bugzilla.gnome.org/show_bug.cgi?id=672194
Diffstat (limited to 'src')
-rw-r--r--src/popup-commands.c68
1 files changed, 37 insertions, 31 deletions
diff --git a/src/popup-commands.c b/src/popup-commands.c
index 5860b461c..169062864 100644
--- a/src/popup-commands.c
+++ b/src/popup-commands.c
@@ -90,37 +90,51 @@ popup_cmd_bookmark_link (GtkAction *action,
EphyWindow *window)
{
EphyEmbedEvent *event;
- GValue link_title = { 0, };
- GValue link_rel = { 0, };
- GValue link = { 0, };
- GValue link_is_smart = { 0, };
- GValue linktext = { 0, };
- const char *title;
- const char *location;
- const char *rel;
- gboolean is_smart;
+ char *title;
+ char *location;
+ guint context;
+ WebKitHitTestResult *result;
+ WebKitDOMNode *node, *first_child;
event = ephy_window_get_context_event (window);
g_return_if_fail (event != NULL);
- /* FIXME: this is pretty much broken */
- ephy_embed_event_get_property (event, "link_is_smart", &link_is_smart);
- ephy_embed_event_get_property (event, "link-uri", &link);
- ephy_embed_event_get_property (event, "link_title", &link_title);
- ephy_embed_event_get_property (event, "link_rel", &link_rel);
- ephy_embed_event_get_property (event, "linktext", &linktext);
+ result = ephy_embed_event_get_hit_test_result (event);
+ g_object_get (result, "context", &context, NULL);
+ g_object_get (result, "inner-node", &node, NULL);
- location = g_value_get_string (&link);
- g_return_if_fail (location);
+ if (context != WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK)
+ {
+ node = WEBKIT_DOM_NODE (webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (node)));
+ if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (node))
+ location = webkit_dom_html_anchor_element_get_href (WEBKIT_DOM_HTML_ANCHOR_ELEMENT (node));
+ }
+ else
+ {
+ g_object_get (result, "link-uri", &location, NULL);
+ }
- rel = g_value_get_string (&link_rel);
- is_smart = g_value_get_int (&link_is_smart);
+ if (!node || !location)
+ return;
- title = g_value_get_string (&link_title);
+ title = webkit_dom_html_element_get_title (WEBKIT_DOM_HTML_ELEMENT (node));
+
+ if (title == NULL || title[0] == '\0')
+ {
+ title = webkit_dom_html_anchor_element_get_text (WEBKIT_DOM_HTML_ANCHOR_ELEMENT (node));
+ }
+ /* Sometimes boorkmaklets are presented as images inside a
+ * link, try that. */
if (title == NULL || title[0] == '\0')
{
- title = g_value_get_string (&linktext);
+ first_child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (node));
+ if (first_child && WEBKIT_DOM_IS_HTML_IMAGE_ELEMENT (first_child))
+ {
+ title = webkit_dom_html_image_element_get_alt (WEBKIT_DOM_HTML_IMAGE_ELEMENT (first_child));
+ if (title == NULL || title[0] == '\0')
+ title = webkit_dom_html_image_element_get_name (WEBKIT_DOM_HTML_IMAGE_ELEMENT (first_child));
+ }
}
if (title == NULL || title[0] == '\0')
@@ -128,17 +142,9 @@ popup_cmd_bookmark_link (GtkAction *action,
title = location;
}
- if (is_smart)
- {
- location = rel;
- }
-
ephy_bookmarks_ui_add_bookmark (GTK_WINDOW (window), location, title);
- g_value_unset (&link);
- g_value_unset (&link_rel);
- g_value_unset (&linktext);
- g_value_unset (&link_title);
- g_value_unset (&link_is_smart);
+ g_free (title);
+ g_free (location);
}
static void