Implement web inspector attaching/ detaching properly

This commit is contained in:
Christian Dywan 2009-12-23 16:46:14 +01:00
parent 407e4dd5d3
commit 112966fe67
2 changed files with 75 additions and 31 deletions

View file

@ -1205,10 +1205,17 @@ midori_view_attach_inspector_cb (GtkWidget* view,
GtkWidget* inspector_view, GtkWidget* inspector_view,
MidoriBrowser* browser) MidoriBrowser* browser)
{ {
GtkWidget* scrolled = gtk_widget_get_parent (browser->inspector_view); GtkWidget* toplevel;
gtk_container_remove (GTK_CONTAINER (scrolled), browser->inspector_view); GtkWidget* scrolled;
gtk_container_add (GTK_CONTAINER (scrolled), inspector_view);
toplevel = gtk_widget_get_toplevel (inspector_view);
gtk_widget_hide (toplevel);
scrolled = gtk_widget_get_parent (browser->inspector_view);
gtk_widget_destroy (browser->inspector_view);
gtk_widget_reparent (inspector_view, scrolled);
gtk_widget_show_all (browser->inspector);
browser->inspector_view = inspector_view; browser->inspector_view = inspector_view;
gtk_widget_destroy (toplevel);
} }
static void static void
@ -5991,7 +5998,7 @@ midori_browser_init (MidoriBrowser* browser)
gtk_widget_modify_style (browser->notebook, rcstyle); gtk_widget_modify_style (browser->notebook, rcstyle);
g_object_unref (rcstyle); g_object_unref (rcstyle);
gtk_notebook_set_scrollable (GTK_NOTEBOOK (browser->notebook), TRUE); gtk_notebook_set_scrollable (GTK_NOTEBOOK (browser->notebook), TRUE);
gtk_paned_pack2 (GTK_PANED (vpaned), browser->notebook, FALSE, FALSE); gtk_paned_pack1 (GTK_PANED (vpaned), browser->notebook, FALSE, FALSE);
g_signal_connect (browser->notebook, "switch-page", g_signal_connect (browser->notebook, "switch-page",
G_CALLBACK (gtk_notebook_switch_page_cb), G_CALLBACK (gtk_notebook_switch_page_cb),
browser); browser);
@ -6008,19 +6015,16 @@ midori_browser_init (MidoriBrowser* browser)
/* Inspector container */ /* Inspector container */
browser->inspector = gtk_vbox_new (FALSE, 0); browser->inspector = gtk_vbox_new (FALSE, 0);
gtk_paned_pack2 (GTK_PANED (vpaned), browser->inspector, TRUE, TRUE); gtk_paned_pack2 (GTK_PANED (vpaned), browser->inspector, FALSE, FALSE);
scrolled = gtk_scrolled_window_new (NULL, NULL); scrolled = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
GTK_POLICY_AUTOMATIC);
GTK_WIDGET_SET_FLAGS (scrolled, GTK_CAN_FOCUS); GTK_WIDGET_SET_FLAGS (scrolled, GTK_CAN_FOCUS);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
GTK_SHADOW_ETCHED_IN); GTK_SHADOW_ETCHED_IN);
gtk_box_pack_start (GTK_BOX (browser->inspector), gtk_box_pack_start (GTK_BOX (browser->inspector), scrolled, TRUE, TRUE, 0);
scrolled, TRUE, TRUE, 0); browser->inspector_view = gtk_viewport_new (NULL, NULL);
browser->inspector_view = webkit_web_view_new ();
gtk_container_add (GTK_CONTAINER (scrolled), browser->inspector_view); gtk_container_add (GTK_CONTAINER (scrolled), browser->inspector_view);
gtk_widget_show_all (browser->inspector);
/* Incremental findbar */ /* Incremental findbar */
browser->find = gtk_toolbar_new (); browser->find = gtk_toolbar_new ();

View file

@ -2080,7 +2080,7 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
#if HAVE_HILDON #if HAVE_HILDON
static void static void
midori_view_web_view_tap_and_hold_cb (GtkWidget* web_view, midori_view_web_view_tap_and_hold_cb (GtkWidget* web_view,
MidoriView* view) gpointer data)
{ {
gint x, y; gint x, y;
GdkEvent event; GdkEvent event;
@ -2722,10 +2722,11 @@ midori_view_get_progress (MidoriView* view)
return view->progress; return view->progress;
} }
static WebKitWebView* static void
webkit_web_inspector_inspect_web_view_cb (gpointer inspector, midori_view_web_inspector_construct_window (gpointer inspector,
WebKitWebView* web_view, WebKitWebView* web_view,
MidoriView* view) GtkWidget* inspector_view,
MidoriView* view)
{ {
gchar* title; gchar* title;
GtkWidget* window; GtkWidget* window;
@ -2735,7 +2736,6 @@ webkit_web_inspector_inspect_web_view_cb (gpointer inspector,
GtkIconTheme* icon_theme; GtkIconTheme* icon_theme;
GdkPixbuf* icon; GdkPixbuf* icon;
GdkPixbuf* gray_icon; GdkPixbuf* gray_icon;
GtkWidget* inspector_view;
title = g_strdup_printf (_("Inspect page - %s"), ""); title = g_strdup_printf (_("Inspect page - %s"), "");
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@ -2769,19 +2769,54 @@ webkit_web_inspector_inspect_web_view_cb (gpointer inspector,
} }
else else
gtk_window_set_icon_name (GTK_WINDOW (window), "midori"); gtk_window_set_icon_name (GTK_WINDOW (window), "midori");
inspector_view = webkit_web_view_new ();
gtk_container_add (GTK_CONTAINER (window), inspector_view); gtk_container_add (GTK_CONTAINER (window), inspector_view);
/* FIXME: Implement web inspector signals properly
FIXME: Save and restore window size
FIXME: Update window title with URI */
gtk_widget_show_all (window); gtk_widget_show_all (window);
/* inspector_view = webkit_web_view_new ();
gtk_widget_show (inspector_view); /* FIXME: Update window title with URI */
g_signal_emit (view, signals[ATTACH_INSPECTOR], 0, inspector_view); */ }
static WebKitWebView*
midori_view_web_inspector_inspect_web_view_cb (gpointer inspector,
WebKitWebView* web_view,
MidoriView* view)
{
GtkWidget* inspector_view = webkit_web_view_new ();
#if HAVE_HILDON
gtk_widget_tap_and_hold_setup (view->web_view, NULL, NULL, 0);
g_signal_connect (view->web_view, "tap-and-hold",
G_CALLBACK (midori_view_web_view_tap_and_hold_cb), NULL);
#endif
midori_view_web_inspector_construct_window (inspector,
web_view, inspector_view, view);
return WEBKIT_WEB_VIEW (inspector_view); return WEBKIT_WEB_VIEW (inspector_view);
} }
static gboolean
midori_view_web_inspector_attach_window_cb (gpointer inspector,
MidoriView* view)
{
GtkWidget* inspector_view = katze_object_get_object (inspector, "web-view");
g_signal_emit (view, signals[ATTACH_INSPECTOR], 0, inspector_view);
g_object_unref (inspector_view);
return TRUE;
}
static gboolean
midori_view_web_inspector_detach_window_cb (gpointer inspector,
MidoriView* view)
{
GtkWidget* inspector_view = katze_object_get_object (inspector, "web-view");
GtkWidget* parent = gtk_widget_get_parent (inspector_view);
if (GTK_IS_WINDOW (parent))
return FALSE;
gtk_widget_hide (parent);
gtk_container_remove (GTK_CONTAINER (parent), inspector_view);
midori_view_web_inspector_construct_window (inspector,
WEBKIT_WEB_VIEW (view->web_view), inspector_view, view);
g_object_unref (inspector_view);
return TRUE;
}
static void static void
midori_view_construct_web_view (MidoriView* view) midori_view_construct_web_view (MidoriView* view)
{ {
@ -2798,6 +2833,8 @@ midori_view_construct_web_view (MidoriView* view)
#if HAVE_HILDON #if HAVE_HILDON
gtk_widget_tap_and_hold_setup (view->web_view, NULL, NULL, 0); gtk_widget_tap_and_hold_setup (view->web_view, NULL, NULL, 0);
g_signal_connect (view->web_view, "tap-and-hold",
G_CALLBACK (midori_view_web_view_tap_and_hold_cb), NULL);
#endif #endif
g_object_connect (view->web_view, g_object_connect (view->web_view,
@ -2838,10 +2875,6 @@ midori_view_construct_web_view (MidoriView* view)
gtk_widget_scroll_event_cb, view, gtk_widget_scroll_event_cb, view,
"signal::populate-popup", "signal::populate-popup",
webkit_web_view_populate_popup_cb, view, webkit_web_view_populate_popup_cb, view,
#if HAVE_HILDON
"signal::tap-and-hold",
midori_view_web_view_tap_and_hold_cb, view,
#endif
"signal::console-message", "signal::console-message",
webkit_web_view_console_message_cb, view, webkit_web_view_console_message_cb, view,
"signal::window-object-cleared", "signal::window-object-cleared",
@ -2882,8 +2915,15 @@ midori_view_construct_web_view (MidoriView* view)
gtk_container_add (GTK_CONTAINER (view), view->web_view); gtk_container_add (GTK_CONTAINER (view), view->web_view);
inspector = katze_object_get_object (view->web_view, "web-inspector"); inspector = katze_object_get_object (view->web_view, "web-inspector");
g_object_connect (inspector, "signal::inspect-web-view", g_object_connect (inspector,
webkit_web_inspector_inspect_web_view_cb, view, NULL); "signal::inspect-web-view",
midori_view_web_inspector_inspect_web_view_cb, view,
"signal::attach-window",
midori_view_web_inspector_attach_window_cb, view,
"signal::detach-window",
midori_view_web_inspector_detach_window_cb, view,
NULL);
g_object_unref (inspector);
} }
/** /**