From 19f6fefe9b227df63f58da2170f4fd8b20260216 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sun, 25 Mar 2012 19:35:58 +0200 Subject: [PATCH] Introduce midori_view_get_for_widget Analogous to midori_browser_get_for_widget. --- midori/midori-browser.c | 2 +- midori/midori-view.c | 29 ++++++++++++++++++++++++----- midori/midori-view.h | 3 +++ 3 files changed, 28 insertions(+), 6 deletions(-) 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); -- 2.39.5