diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 55016797..0692d710 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -1780,8 +1780,8 @@ midori_browser_key_press_event (GtkWidget* widget, && !webkit_web_view_can_paste_clipboard (WEBKIT_WEB_VIEW (focus))) { /* Space at the bottom of the page: Go to next page */ + MidoriView* view = midori_view_get_for_widget (focus); GtkScrolledWindow* scrolled = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (focus)); - MidoriView* view = MIDORI_VIEW (gtk_widget_get_parent (GTK_WIDGET (scrolled))); GtkAdjustment* vadjust = gtk_scrolled_window_get_vadjustment (scrolled); if (gtk_adjustment_get_value (vadjust) == (gtk_adjustment_get_upper (vadjust) - gtk_adjustment_get_page_size (vadjust))) diff --git a/midori/midori-view.c b/midori/midori-view.c index 4a9fb4ca..e985aec4 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -2793,12 +2793,8 @@ static gboolean webkit_web_view_web_view_ready_cb (GtkWidget* web_view, MidoriView* view) { - #if GTK_CHECK_VERSION(3, 2, 0) - GtkWidget* new_view = gtk_widget_get_parent (gtk_widget_get_parent (gtk_widget_get_parent (web_view))); - #else - GtkWidget* new_view = gtk_widget_get_parent (gtk_widget_get_parent (web_view)); - #endif MidoriNewView where = MIDORI_NEW_VIEW_TAB; + GtkWidget* new_view = GTK_WIDGET (midori_view_get_for_widget (web_view)); /* FIXME: Open windows opened by scripts in tabs if they otherwise would be replacing the page the user opened. */ @@ -5814,6 +5810,29 @@ midori_view_get_web_view (MidoriView* view) return view->web_view; } +/** + * midori_view_get_for_widget: + * @widget: a #GtkWidget + * + * Determines the view appropriate for the specified widget. + * + * Return value: a #MidoriView + * + * Since 0.4.5 + **/ +MidoriView* +midori_view_get_for_widget (GtkWidget* web_view) +{ + GtkWidget* scrolled = gtk_widget_get_parent (web_view); + #if GTK_CHECK_VERSION(3, 2, 0) + GtkWidget* overlay = gtk_widget_get_parent (scrolled); + GtkWidget* view = gtk_widget_get_parent (overlay); + #else + GtkWidget* view = gtk_widget_get_parent (scrolled); + #endif + return MIDORI_VIEW (view); +} + /** * midori_view_get_security * @view: a #MidoriView diff --git a/midori/midori-view.h b/midori/midori-view.h index 837f424d..feba0526 100644 --- a/midori/midori-view.h +++ b/midori/midori-view.h @@ -248,6 +248,9 @@ midori_view_get_snapshot (MidoriView* view, GtkWidget* midori_view_get_web_view (MidoriView* view); +MidoriView* +midori_view_get_for_widget (GtkWidget* web_view); + MidoriSecurity midori_view_get_security (MidoriView* view);