Change MidoriView into a subclass of GtkVBox

This change makes it possible to pack widgets, notably info bars,
into a MidoriView.
This commit is contained in:
Arno Renevier 2010-03-30 22:45:49 +02:00 committed by Christian Dywan
parent dc90c7f093
commit c3238d7c12
2 changed files with 37 additions and 30 deletions

View file

@ -1270,9 +1270,9 @@ midori_browser_view_copy_history (GtkWidget* view_to,
guint length_from; guint length_from;
gint i; gint i;
copy_from = WEBKIT_WEB_VIEW (gtk_bin_get_child (GTK_BIN (view_from))); copy_from = WEBKIT_WEB_VIEW (midori_view_get_web_view (MIDORI_VIEW (view_from)));
list_from = webkit_web_view_get_back_forward_list (copy_from); list_from = webkit_web_view_get_back_forward_list (copy_from);
copy_to = WEBKIT_WEB_VIEW (gtk_bin_get_child (GTK_BIN (view_to))); copy_to = WEBKIT_WEB_VIEW (midori_view_get_web_view (MIDORI_VIEW (view_to)));
list_to = webkit_web_view_get_back_forward_list (copy_to); list_to = webkit_web_view_get_back_forward_list (copy_to);
length_from = webkit_web_back_forward_list_get_back_length (list_from); length_from = webkit_web_back_forward_list_get_back_length (list_from);
@ -1672,8 +1672,6 @@ _midori_browser_add_tab (MidoriBrowser* browser,
guint n; guint n;
GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS); GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view),
GTK_SHADOW_ETCHED_IN);
tab_label = midori_view_get_proxy_tab_label (MIDORI_VIEW (view)); tab_label = midori_view_get_proxy_tab_label (MIDORI_VIEW (view));
@ -2626,8 +2624,8 @@ _midori_browser_find_done (MidoriBrowser* browser)
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),
gtk_bin_get_child (GTK_BIN (view)) ? midori_view_get_web_view (MIDORI_VIEW (view)) ?
gtk_bin_get_child (GTK_BIN (view)) : view); midori_view_get_web_view (MIDORI_VIEW (view)) : view);
} }
static void static void
@ -3476,7 +3474,7 @@ _action_view_encoding_activate (GtkAction* action,
GtkWidget* web_view; GtkWidget* web_view;
name = gtk_action_get_name (current); name = gtk_action_get_name (current);
web_view = gtk_bin_get_child (GTK_BIN (view)); web_view = midori_view_get_web_view (MIDORI_VIEW (view));
if (!strcmp (name, "EncodingAutomatic")) if (!strcmp (name, "EncodingAutomatic"))
g_object_set (web_view, "custom-encoding", NULL, NULL); g_object_set (web_view, "custom-encoding", NULL, NULL);
else else
@ -3610,7 +3608,7 @@ _action_source_view_activate (GtkAction* action,
source = midori_view_new (browser->net); source = midori_view_new (browser->net);
midori_view_set_settings (MIDORI_VIEW (source), browser->settings); midori_view_set_settings (MIDORI_VIEW (source), browser->settings);
midori_view_set_uri (MIDORI_VIEW (source), ""); midori_view_set_uri (MIDORI_VIEW (source), "");
web_view = gtk_bin_get_child (GTK_BIN (source)); web_view = midori_view_get_web_view (MIDORI_VIEW (source));
webkit_web_view_set_view_source_mode (WEBKIT_WEB_VIEW (web_view), TRUE); webkit_web_view_set_view_source_mode (WEBKIT_WEB_VIEW (web_view), TRUE);
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), uri); webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), uri);
gtk_widget_show (source); gtk_widget_show (source);
@ -3675,7 +3673,7 @@ _action_scroll_somewhere_activate (GtkAction* action,
view = midori_browser_get_current_tab (browser); view = midori_browser_get_current_tab (browser);
if (!view) if (!view)
return; return;
web_view = WEBKIT_WEB_VIEW (gtk_bin_get_child (GTK_BIN (view))); web_view = WEBKIT_WEB_VIEW (midori_view_get_web_view (MIDORI_VIEW (view)));
name = gtk_action_get_name (action); name = gtk_action_get_name (action);
if (g_str_equal (name, "ScrollLeft")) if (g_str_equal (name, "ScrollLeft"))
@ -4355,12 +4353,14 @@ midori_browser_menu_middle_click_on_navigation_action (MidoriBrowser* browser,
else if (g_str_equal (name, "Back")) else if (g_str_equal (name, "Back"))
{ {
GtkWidget* view; GtkWidget* view;
GtkWidget* page;
WebKitWebBackForwardList* back_forward_list; WebKitWebBackForwardList* back_forward_list;
WebKitWebHistoryItem* back_item; WebKitWebHistoryItem* back_item;
const gchar* back_uri; const gchar* back_uri;
gint n; gint n;
view = gtk_bin_get_child (GTK_BIN (midori_browser_get_current_tab (browser))); page = midori_browser_get_current_tab (browser);
view = midori_view_get_web_view (MIDORI_VIEW (page));
back_forward_list = back_forward_list =
webkit_web_view_get_back_forward_list (WEBKIT_WEB_VIEW (view)); webkit_web_view_get_back_forward_list (WEBKIT_WEB_VIEW (view));
@ -4378,12 +4378,14 @@ midori_browser_menu_middle_click_on_navigation_action (MidoriBrowser* browser,
else if (g_str_equal (name, "Forward")) else if (g_str_equal (name, "Forward"))
{ {
GtkWidget *view; GtkWidget *view;
GtkWidget *page;
WebKitWebBackForwardList *back_forward_list; WebKitWebBackForwardList *back_forward_list;
WebKitWebHistoryItem *forward_item; WebKitWebHistoryItem *forward_item;
const gchar *forward_uri; const gchar *forward_uri;
gint n; gint n;
view = gtk_bin_get_child (GTK_BIN (midori_browser_get_current_tab (browser))); page = midori_browser_get_current_tab (browser);
view = midori_view_get_web_view (MIDORI_VIEW (page));
back_forward_list = back_forward_list =
webkit_web_view_get_back_forward_list (WEBKIT_WEB_VIEW (view)); webkit_web_view_get_back_forward_list (WEBKIT_WEB_VIEW (view));
@ -4928,7 +4930,7 @@ _action_inspect_page_activate (GtkAction* action,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkWidget* view = midori_browser_get_current_tab (browser); GtkWidget* view = midori_browser_get_current_tab (browser);
WebKitWebView* web_view = WEBKIT_WEB_VIEW (gtk_bin_get_child (GTK_BIN (view))); WebKitWebView* web_view = WEBKIT_WEB_VIEW (midori_view_get_web_view (MIDORI_VIEW (view)));
WebKitWebInspector* inspector = webkit_web_view_get_inspector (web_view); WebKitWebInspector* inspector = webkit_web_view_get_inspector (web_view);
webkit_web_inspector_show (inspector); webkit_web_inspector_show (inspector);
} }
@ -4958,7 +4960,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 = gtk_bin_get_child (GTK_BIN (view)); GtkWidget* child = midori_view_get_web_view (MIDORI_VIEW (view));
gtk_widget_grab_focus (child ? child : view); gtk_widget_grab_focus (child ? child : view);
} }
@ -7496,7 +7498,7 @@ midori_browser_set_current_page (MidoriBrowser* browser,
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 (view && 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 = gtk_bin_get_child (GTK_BIN (view)))) else if ((web_view = midori_view_get_web_view (MIDORI_VIEW (view))))
gtk_widget_grab_focus (web_view); gtk_widget_grab_focus (web_view);
else else
gtk_widget_grab_focus (view); gtk_widget_grab_focus (view);
@ -7565,7 +7567,7 @@ midori_browser_set_current_tab (MidoriBrowser* browser,
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 (view && 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 = gtk_bin_get_child (GTK_BIN (view)))) else if ((web_view = midori_view_get_web_view (MIDORI_VIEW (view))))
gtk_widget_grab_focus (web_view); gtk_widget_grab_focus (web_view);
else else
gtk_widget_grab_focus (view); gtk_widget_grab_focus (view);

View file

@ -61,7 +61,7 @@ midori_view_item_meta_data_changed (KatzeItem* item,
struct _MidoriView struct _MidoriView
{ {
KatzeScrolled parent_instance; GtkVBox parent_instance;
gchar* uri; gchar* uri;
gboolean special; gboolean special;
@ -106,14 +106,16 @@ struct _MidoriView
KatzeNet* net; KatzeNet* net;
GHashTable* memory; GHashTable* memory;
GtkWidget* scrolled_window;
}; };
struct _MidoriViewClass struct _MidoriViewClass
{ {
KatzeScrolledClass parent_class; GtkVBoxClass parent_class;
}; };
G_DEFINE_TYPE (MidoriView, midori_view, KATZE_TYPE_SCROLLED); G_DEFINE_TYPE (MidoriView, midori_view, GTK_TYPE_VBOX);
GType GType
midori_load_status_get_type (void) midori_load_status_get_type (void)
@ -1203,7 +1205,7 @@ midori_view_apply_scroll_position (MidoriView* view)
{ {
if (view->scrollh > 0) if (view->scrollh > 0)
{ {
GtkAdjustment* adjustment = katze_object_get_object (view, "hadjustment"); GtkAdjustment* adjustment = katze_object_get_object (view->scrolled_window, "hadjustment");
gtk_adjustment_set_value (adjustment, view->scrollh); gtk_adjustment_set_value (adjustment, view->scrollh);
g_object_unref (adjustment); g_object_unref (adjustment);
} }
@ -1213,7 +1215,7 @@ midori_view_apply_scroll_position (MidoriView* view)
{ {
if (view->scrollv > 0) if (view->scrollv > 0)
{ {
GtkAdjustment* adjustment = katze_object_get_object (view, "vadjustment"); GtkAdjustment* adjustment = katze_object_get_object (view->scrolled_window, "vadjustment");
gtk_adjustment_set_value (adjustment, view->scrollv); gtk_adjustment_set_value (adjustment, view->scrollv);
g_object_unref (adjustment); g_object_unref (adjustment);
} }
@ -2700,7 +2702,7 @@ midori_view_notify_hadjustment_cb (MidoriView* view,
GParamSpec* pspec, GParamSpec* pspec,
gpointer data) gpointer data)
{ {
GtkAdjustment* hadjustment = katze_object_get_object (view, "hadjustment"); GtkAdjustment* hadjustment = katze_object_get_object (view->scrolled_window, "hadjustment");
g_signal_connect (hadjustment, "notify::value", g_signal_connect (hadjustment, "notify::value",
G_CALLBACK (midori_view_hadjustment_notify_value_cb), view); G_CALLBACK (midori_view_hadjustment_notify_value_cb), view);
g_object_unref (hadjustment); g_object_unref (hadjustment);
@ -2721,7 +2723,7 @@ midori_view_notify_vadjustment_cb (MidoriView* view,
GParamSpec* pspec, GParamSpec* pspec,
gpointer data) gpointer data)
{ {
GtkAdjustment* vadjustment = katze_object_get_object (view, "vadjustment"); GtkAdjustment* vadjustment = katze_object_get_object (view->scrolled_window, "vadjustment");
g_signal_connect (vadjustment, "notify::value", g_signal_connect (vadjustment, "notify::value",
G_CALLBACK (midori_view_vadjustment_notify_value_cb), view); G_CALLBACK (midori_view_vadjustment_notify_value_cb), view);
g_object_unref (vadjustment); g_object_unref (vadjustment);
@ -2762,12 +2764,15 @@ midori_view_init (MidoriView* view)
view->download_manager = NULL; view->download_manager = NULL;
view->news_aggregator = NULL; view->news_aggregator = NULL;
view->web_view = NULL; view->web_view = NULL;
/* Adjustments are not created initially, but overwritten later */ /* Adjustments are not created initially, but overwritten later */
g_object_set (view, "hadjustment", NULL, "vadjustment", NULL, NULL); view->scrolled_window = katze_scrolled_new (NULL, NULL);
g_signal_connect (view, "notify::hadjustment", gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (view->scrolled_window),
GTK_SHADOW_ETCHED_OUT);
gtk_container_add (GTK_CONTAINER (view), view->scrolled_window);
g_signal_connect (view->scrolled_window, "notify::hadjustment",
G_CALLBACK (midori_view_notify_hadjustment_cb), view); G_CALLBACK (midori_view_notify_hadjustment_cb), view);
g_signal_connect (view, "notify::vadjustment", g_signal_connect (view->scrolled_window, "notify::vadjustment",
G_CALLBACK (midori_view_notify_vadjustment_cb), view); G_CALLBACK (midori_view_notify_vadjustment_cb), view);
} }
@ -2949,7 +2954,7 @@ _midori_view_update_settings (MidoriView* view)
if (view->web_view) if (view->web_view)
g_object_set (view->web_view, g_object_set (view->web_view,
"full-content-zoom", zoom_text_and_images, NULL); "full-content-zoom", zoom_text_and_images, NULL);
g_object_set (view, "kinetic-scrolling", kinetic_scrolling, NULL); g_object_set (view->scrolled_window, "kinetic-scrolling", kinetic_scrolling, NULL);
} }
static void static void
@ -3273,8 +3278,8 @@ midori_view_construct_web_view (MidoriView* view)
"zoom-text-and-images"), NULL); "zoom-text-and-images"), NULL);
} }
gtk_widget_show (view->web_view); gtk_container_add (GTK_CONTAINER (view->scrolled_window), view->web_view);
gtk_container_add (GTK_CONTAINER (view), view->web_view); gtk_widget_show_all (view->scrolled_window);
inspector = katze_object_get_object (view->web_view, "web-inspector"); inspector = katze_object_get_object (view->web_view, "web-inspector");
g_object_connect (inspector, g_object_connect (inspector,
@ -4797,7 +4802,7 @@ midori_view_get_snapshot (MidoriView* view,
GdkPixbuf* pixbuf; GdkPixbuf* pixbuf;
g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL); g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
web_view = gtk_bin_get_child (GTK_BIN (view)); web_view = view->web_view;
g_return_val_if_fail (web_view->window, NULL); g_return_val_if_fail (web_view->window, NULL);
x = web_view->allocation.x; x = web_view->allocation.x;