Introduce midori_view_get_for_widget

Analogous to midori_browser_get_for_widget.
This commit is contained in:
Christian Dywan 2012-03-25 19:35:58 +02:00
parent f7d85602f8
commit 19f6fefe9b
3 changed files with 28 additions and 6 deletions

View file

@ -1780,8 +1780,8 @@ midori_browser_key_press_event (GtkWidget* widget,
&& !webkit_web_view_can_paste_clipboard (WEBKIT_WEB_VIEW (focus))) && !webkit_web_view_can_paste_clipboard (WEBKIT_WEB_VIEW (focus)))
{ {
/* Space at the bottom of the page: Go to next page */ /* 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)); 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); GtkAdjustment* vadjust = gtk_scrolled_window_get_vadjustment (scrolled);
if (gtk_adjustment_get_value (vadjust) if (gtk_adjustment_get_value (vadjust)
== (gtk_adjustment_get_upper (vadjust) - gtk_adjustment_get_page_size (vadjust))) == (gtk_adjustment_get_upper (vadjust) - gtk_adjustment_get_page_size (vadjust)))

View file

@ -2793,12 +2793,8 @@ static gboolean
webkit_web_view_web_view_ready_cb (GtkWidget* web_view, webkit_web_view_web_view_ready_cb (GtkWidget* web_view,
MidoriView* 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; 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 /* FIXME: Open windows opened by scripts in tabs if they otherwise
would be replacing the page the user opened. */ would be replacing the page the user opened. */
@ -5814,6 +5810,29 @@ midori_view_get_web_view (MidoriView* view)
return view->web_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 * midori_view_get_security
* @view: a #MidoriView * @view: a #MidoriView

View file

@ -248,6 +248,9 @@ midori_view_get_snapshot (MidoriView* view,
GtkWidget* GtkWidget*
midori_view_get_web_view (MidoriView* view); midori_view_get_web_view (MidoriView* view);
MidoriView*
midori_view_get_for_widget (GtkWidget* web_view);
MidoriSecurity MidoriSecurity
midori_view_get_security (MidoriView* view); midori_view_get_security (MidoriView* view);