From affde90e2c87902437163513a6c32c4bc73d81d1 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Thu, 6 May 2010 22:27:29 +0200 Subject: [PATCH] Consistently focus the view, which propagates Rather than trying to determine and focus the web view from different places, the parent view should simply propagate focus by default. The child needs to be constructed implicitly if focus comes in early. --- midori/midori-browser.c | 17 ++++------------- midori/midori-view.c | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 93734a7b..85440e0d 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -2667,9 +2667,7 @@ _midori_browser_find_done (MidoriBrowser* browser) midori_view_unmark_text_matches (MIDORI_VIEW (view)); gtk_widget_hide (browser->find); browser->find_typing = FALSE; - gtk_window_set_focus (GTK_WINDOW (browser), - midori_view_get_web_view (MIDORI_VIEW (view)) ? - midori_view_get_web_view (MIDORI_VIEW (view)) : view); + gtk_window_set_focus (GTK_WINDOW (browser), view); } static void @@ -5024,8 +5022,7 @@ _action_tab_current_activate (GtkAction* action, MidoriBrowser* browser) { GtkWidget* view = midori_browser_get_current_tab (browser); - GtkWidget* child = midori_view_get_web_view (MIDORI_VIEW (view)); - gtk_widget_grab_focus (child ? child : view); + gtk_widget_grab_focus (view); } static const gchar* credits_authors[] = @@ -7560,14 +7557,11 @@ midori_browser_set_current_page (MidoriBrowser* browser, gint n) { GtkWidget* view; - GtkWidget* web_view; gtk_notebook_set_current_page (GTK_NOTEBOOK (browser->notebook), n); view = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), n); - if (view && midori_view_is_blank (MIDORI_VIEW (view))) + if (midori_view_is_blank (MIDORI_VIEW (view))) gtk_action_activate (_action_by_name (browser, "Location")); - else if ((web_view = midori_view_get_web_view (MIDORI_VIEW (view)))) - gtk_widget_grab_focus (web_view); else gtk_widget_grab_focus (view); } @@ -7626,17 +7620,14 @@ midori_browser_set_current_tab (MidoriBrowser* browser, GtkWidget* view) { gint n; - GtkWidget* web_view; g_return_if_fail (MIDORI_IS_BROWSER (browser)); g_return_if_fail (GTK_IS_WIDGET (view)); n = gtk_notebook_page_num (GTK_NOTEBOOK (browser->notebook), view); gtk_notebook_set_current_page (GTK_NOTEBOOK (browser->notebook), n); - if (view && midori_view_is_blank (MIDORI_VIEW (view))) + if (midori_view_is_blank (MIDORI_VIEW (view))) gtk_action_activate (_action_by_name (browser, "Location")); - else if ((web_view = midori_view_get_web_view (MIDORI_VIEW (view)))) - gtk_widget_grab_focus (web_view); else gtk_widget_grab_focus (view); } diff --git a/midori/midori-view.c b/midori/midori-view.c index cdfd15aa..b9bf397b 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -225,6 +225,10 @@ midori_view_get_property (GObject* object, GValue* value, GParamSpec* pspec); +static gboolean +midori_view_focus_in_event (GtkWidget* widget, + GdkEventFocus* event); + static void midori_view_settings_notify_cb (MidoriWebSettings* settings, GParamSpec* pspec, @@ -243,6 +247,7 @@ static void midori_view_class_init (MidoriViewClass* class) { GObjectClass* gobject_class; + GtkWidgetClass* gtkwidget_class; GParamFlags flags; signals[ACTIVATE_ACTION] = g_signal_new ( @@ -439,6 +444,9 @@ midori_view_class_init (MidoriViewClass* class) gobject_class->set_property = midori_view_set_property; gobject_class->get_property = midori_view_get_property; + gtkwidget_class = GTK_WIDGET_CLASS (class); + gtkwidget_class->focus_in_event = midori_view_focus_in_event; + flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS; g_object_class_install_property (gobject_class, @@ -2988,6 +2996,20 @@ midori_view_get_property (GObject* object, } } +static gboolean +midori_view_focus_in_event (GtkWidget* widget, + GdkEventFocus* event) +{ + MidoriView* view = MIDORI_VIEW (widget); + + /* Always propagate focus to the child web view, + * create it if it's not there yet. */ + if (!view->web_view) + midori_view_construct_web_view (view); + gtk_widget_grab_focus (view->web_view); + return TRUE; +} + /** * midori_view_new: * @net: a #KatzeNet