Merge lp:~midori/midori/innernodeselect into lp:midori

Proposed by Cris Dywan
Status: Work in progress
Proposed branch: lp:~midori/midori/innernodeselect
Merge into: lp:midori
Diff against target: 69 lines (+22/-10)
1 file modified
midori/midori-view.c (+22/-10)
To merge this branch: bzr merge lp:~midori/midori/innernodeselect
Reviewer Review Type Date Requested Status
gue5t gue5t Needs Fixing
Review via email: mp+194033@code.launchpad.net

Commit message

Get selected text for context menu from hit test result

To post a comment you must log in.
lp:~midori/midori/innernodeselect updated
6461. By Cris Dywan

Check for HTML element if it's not a text node

Revision history for this message
gue5t gue5t (gue5t) wrote :

This looks good but it regresses behavior. After this patch, selecting a few letters of a word, right-clicking, and choosing "Search with->Duckduckgo" searches for the entire DOM node's contents instead of just the selected letters. This is not what happens before the patch and not what I would expect to happen as a user.

review: Needs Fixing
Revision history for this message
Cris Dywan (kalikiana) wrote :

What was lost in IRC conversations is the fact that neither the current trunk nor this branch fully work depending on the website, the original motivation was that it's subjectively broken in trunk.

We need a good idea on how to deal with this. Including how to test it, because opening the next best website is meaningless for this issue.

Unmerged revisions

6461. By Cris Dywan

Check for HTML element if it's not a text node

6460. By Cris Dywan

Get selected text for context menu from hit test result

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'midori/midori-view.c'
2--- midori/midori-view.c 2013-11-05 23:09:04 +0000
3+++ midori/midori-view.c 2013-11-05 23:53:58 +0000
4@@ -2246,9 +2246,10 @@
5 {
6 MidoriView* view = user_data;
7 const gchar* search = g_object_get_data (G_OBJECT (action), "search");
8+ const gchar* selected = g_object_get_data (G_OBJECT (action), "selected");
9 if (search == NULL)
10 search = midori_settings_get_location_entry_search (MIDORI_SETTINGS (view->settings));
11- gchar* uri = midori_uri_for_search (search, view->selected_text);
12+ gchar* uri = midori_uri_for_search (search, selected);
13
14 if (view->open_new_pages_in == MIDORI_NEW_PAGE_WINDOW)
15 g_signal_emit (view, signals[NEW_WINDOW], 0, uri);
16@@ -2449,18 +2450,28 @@
17 webkit_web_view_can_copy_clipboard (WEBKIT_WEB_VIEW (view->web_view)));
18 }
19
20- /* Ensure view->selected_text */
21- midori_view_has_selection (view);
22- if (midori_uri_is_valid (view->selected_text))
23+ WebKitDOMNode* selected_node;
24+ g_object_get (hit_test_result, "inner-node", &selected_node, NULL);
25+ gchar* selected;
26+ if (WEBKIT_DOM_IS_TEXT (selected_node))
27+ selected = webkit_dom_text_get_whole_text (WEBKIT_DOM_TEXT (selected_node));
28+ else if (WEBKIT_DOM_IS_HTML_ELEMENT (selected_node))
29+ selected = webkit_dom_html_element_get_inner_text (WEBKIT_DOM_HTML_ELEMENT (selected_node));
30+ else
31+ {
32+ selected = NULL;
33+ g_warn_if_reached ();
34+ }
35+ if (midori_uri_is_valid (selected))
36 {
37 /* :// and @ together would mean login credentials */
38- if (g_str_has_prefix (view->selected_text, "mailto:")
39- || (strchr (view->selected_text, '@') != NULL
40- && strstr (view->selected_text, "://") == NULL))
41+ if (g_str_has_prefix (selected, "mailto:")
42+ || (strchr (selected, '@') != NULL
43+ && strstr (selected, "://") == NULL))
44 {
45- gchar* text = g_strdup_printf (_("Send a message to %s"), view->selected_text);
46+ gchar* text = g_strdup_printf (_("Send a message to %s"), selected);
47 GtkAction* action = gtk_action_new ("SendMessage", text, NULL, GTK_STOCK_JUMP_TO);
48- g_object_set_data_full (G_OBJECT (action), "uri", g_strdup (view->selected_text), (GDestroyNotify)g_free);
49+ g_object_set_data_full (G_OBJECT (action), "uri", g_strdup (selected), (GDestroyNotify)g_free);
50 g_signal_connect (action, "activate", G_CALLBACK (midori_view_menu_open_email_activate_cb), view);
51 midori_context_action_add (menu, action);
52 g_free (text);
53@@ -2468,7 +2479,7 @@
54 else
55 {
56 GtkAction* action = gtk_action_new ("OpenAddressInNewTab", _("Open Address in New _Tab"), NULL, GTK_STOCK_JUMP_TO);
57- g_object_set_data_full (G_OBJECT (action), "uri", g_strdup (view->selected_text), (GDestroyNotify)g_free);
58+ g_object_set_data_full (G_OBJECT (action), "uri", g_strdup (selected), (GDestroyNotify)g_free);
59 g_signal_connect (action, "activate", G_CALLBACK (midori_view_menu_open_link_tab_activate_cb), view);
60 midori_context_action_add (menu, action);
61 }
62@@ -2496,6 +2507,7 @@
63 }
64 gtk_action_set_always_show_image (GTK_ACTION (action), TRUE);
65 g_object_set_data (G_OBJECT (action), "search", (gchar*)katze_item_get_uri (item));
66+ g_object_set_data_full (G_OBJECT (action), "selected", g_strdup (selected), (GDestroyNotify)g_free);
67 g_signal_connect (action, "activate",
68 G_CALLBACK (midori_web_view_menu_search_web_activate_cb), view);
69 i++;

Subscribers

People subscribed via source and target branches

to all changes: