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.
This commit is contained in:
Christian Dywan 2010-05-06 22:27:29 +02:00
parent 896404ba75
commit affde90e2c
2 changed files with 26 additions and 13 deletions

View file

@ -2667,9 +2667,7 @@ _midori_browser_find_done (MidoriBrowser* browser)
midori_view_unmark_text_matches (MIDORI_VIEW (view)); midori_view_unmark_text_matches (MIDORI_VIEW (view));
gtk_widget_hide (browser->find); gtk_widget_hide (browser->find);
browser->find_typing = FALSE; browser->find_typing = FALSE;
gtk_window_set_focus (GTK_WINDOW (browser), gtk_window_set_focus (GTK_WINDOW (browser), view);
midori_view_get_web_view (MIDORI_VIEW (view)) ?
midori_view_get_web_view (MIDORI_VIEW (view)) : view);
} }
static void static void
@ -5024,8 +5022,7 @@ _action_tab_current_activate (GtkAction* action,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkWidget* view = midori_browser_get_current_tab (browser); GtkWidget* view = midori_browser_get_current_tab (browser);
GtkWidget* child = midori_view_get_web_view (MIDORI_VIEW (view)); gtk_widget_grab_focus (view);
gtk_widget_grab_focus (child ? child : view);
} }
static const gchar* credits_authors[] = static const gchar* credits_authors[] =
@ -7560,14 +7557,11 @@ midori_browser_set_current_page (MidoriBrowser* browser,
gint n) gint n)
{ {
GtkWidget* view; GtkWidget* view;
GtkWidget* web_view;
gtk_notebook_set_current_page (GTK_NOTEBOOK (browser->notebook), n); gtk_notebook_set_current_page (GTK_NOTEBOOK (browser->notebook), n);
view = gtk_notebook_get_nth_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")); 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 else
gtk_widget_grab_focus (view); gtk_widget_grab_focus (view);
} }
@ -7626,17 +7620,14 @@ midori_browser_set_current_tab (MidoriBrowser* browser,
GtkWidget* view) GtkWidget* view)
{ {
gint n; gint n;
GtkWidget* web_view;
g_return_if_fail (MIDORI_IS_BROWSER (browser)); g_return_if_fail (MIDORI_IS_BROWSER (browser));
g_return_if_fail (GTK_IS_WIDGET (view)); g_return_if_fail (GTK_IS_WIDGET (view));
n = gtk_notebook_page_num (GTK_NOTEBOOK (browser->notebook), view); n = gtk_notebook_page_num (GTK_NOTEBOOK (browser->notebook), view);
gtk_notebook_set_current_page (GTK_NOTEBOOK (browser->notebook), n); 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")); 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 else
gtk_widget_grab_focus (view); gtk_widget_grab_focus (view);
} }

View file

@ -225,6 +225,10 @@ midori_view_get_property (GObject* object,
GValue* value, GValue* value,
GParamSpec* pspec); GParamSpec* pspec);
static gboolean
midori_view_focus_in_event (GtkWidget* widget,
GdkEventFocus* event);
static void static void
midori_view_settings_notify_cb (MidoriWebSettings* settings, midori_view_settings_notify_cb (MidoriWebSettings* settings,
GParamSpec* pspec, GParamSpec* pspec,
@ -243,6 +247,7 @@ static void
midori_view_class_init (MidoriViewClass* class) midori_view_class_init (MidoriViewClass* class)
{ {
GObjectClass* gobject_class; GObjectClass* gobject_class;
GtkWidgetClass* gtkwidget_class;
GParamFlags flags; GParamFlags flags;
signals[ACTIVATE_ACTION] = g_signal_new ( 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->set_property = midori_view_set_property;
gobject_class->get_property = midori_view_get_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; flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS;
g_object_class_install_property (gobject_class, 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: * midori_view_new:
* @net: a #KatzeNet * @net: a #KatzeNet