From 51c6fb1cdf37c1919ed9aa29c64f9e86cfe4b336 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sun, 22 Feb 2009 01:45:22 +0100 Subject: [PATCH] Implement a primitive find-as-you-type --- midori/marshal.list | 1 + midori/midori-browser.c | 10 ++++++++++ midori/midori-view.c | 44 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/midori/marshal.list b/midori/marshal.list index 53e9849d..c82c5639 100644 --- a/midori/marshal.list +++ b/midori/marshal.list @@ -1,4 +1,5 @@ BOOLEAN:VOID +VOID:BOOLEAN,STRING VOID:OBJECT,ENUM VOID:STRING,BOOLEAN VOID:STRING,INT,STRING diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 85c15cd0..cdc31652 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -855,12 +855,22 @@ midori_view_new_view_cb (GtkWidget* view, static void midori_view_search_text_cb (GtkWidget* view, gboolean found, + gchar* typing, MidoriBrowser* browser) { const gchar* text; gboolean case_sensitive; gboolean highlight; + if (typing) + { + gint position = -1; + + gtk_widget_show (browser->find); + gtk_window_set_focus (GTK_WINDOW (browser), browser->find_text); + gtk_editable_insert_text (GTK_EDITABLE (browser->find_text), typing, -1, &position); + gtk_editable_set_position (GTK_EDITABLE (browser->find_text), -1); + } if (GTK_WIDGET_VISIBLE (browser->find)) { gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (browser->find_text), diff --git a/midori/midori-view.c b/midori/midori-view.c index d49c0374..f029583d 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -275,6 +275,18 @@ midori_view_class_init (MidoriViewClass* class) MIDORI_TYPE_VIEW, MIDORI_TYPE_NEW_VIEW); + /** + * MidoriView::search-text: + * @view: the object on which the signal is emitted + * @found: whether the search was successful + * @typing: whether the search was initiated by typing + * + * Emitted when a search is performed. Either manually + * invoked or automatically by typing. The value of typing + * is actually the text the user typed. + * + * Note that in 0.1.3 the argument @typing was introduced. + */ signals[SEARCH_TEXT] = g_signal_new ( "search-text", G_TYPE_FROM_CLASS (class), @@ -282,9 +294,10 @@ midori_view_class_init (MidoriViewClass* class) 0, 0, NULL, - g_cclosure_marshal_VOID__BOOLEAN, - G_TYPE_NONE, 1, - G_TYPE_BOOLEAN); + midori_cclosure_marshal_VOID__BOOLEAN_STRING, + G_TYPE_NONE, 2, + G_TYPE_BOOLEAN, + G_TYPE_STRING); signals[ADD_BOOKMARK] = g_signal_new ( "add-bookmark", @@ -794,6 +807,27 @@ gtk_widget_button_press_event_cb (WebKitWebView* web_view, return FALSE; } +static gboolean +gtk_widget_key_press_event_cb (WebKitWebView* web_view, + GdkEventKey* event, + MidoriView* view) +{ + guint character = gdk_unicode_to_keyval (event->keyval); + + if (!webkit_web_view_can_cut_clipboard (web_view) + && !webkit_web_view_can_paste_clipboard (web_view)) + { + gchar* text = g_strdup_printf ("%c", character); + + g_signal_emit (view, signals[SEARCH_TEXT], 0, + webkit_web_view_search_text (web_view, + text, FALSE, TRUE, TRUE), text); + g_free (text); + } + + return FALSE; +} + static gboolean gtk_widget_scroll_event_cb (WebKitWebView* web_view, GdkEventScroll* event, @@ -1541,6 +1575,8 @@ midori_view_construct_web_view (MidoriView* view) webkit_web_view_hovering_over_link_cb, view, "signal::button-press-event", gtk_widget_button_press_event_cb, view, + "signal::key-press-event", + gtk_widget_key_press_event_cb, view, "signal::scroll-event", gtk_widget_scroll_event_cb, view, "signal::populate-popup", @@ -2434,7 +2470,7 @@ midori_view_search_text (MidoriView* view, g_signal_emit (view, signals[SEARCH_TEXT], 0, webkit_web_view_search_text (WEBKIT_WEB_VIEW (view->web_view), - text, case_sensitive, forward, TRUE)); + text, case_sensitive, forward, TRUE), NULL); } /** -- 2.39.5