diff options
author | John Reck <jreck@google.com> | 2010-11-04 12:00:17 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2010-11-09 11:35:04 -0800 |
commit | e14391e94c850b8bd03680c23b38978db68687a8 (patch) | |
tree | 3fed87e6620fecaf3edc7259ae58a11662bedcb2 /WebKitTools/GtkLauncher | |
parent | 1bd705833a68f07850cf7e204b26f8d328d16951 (diff) | |
download | external_webkit-e14391e94c850b8bd03680c23b38978db68687a8.zip external_webkit-e14391e94c850b8bd03680c23b38978db68687a8.tar.gz external_webkit-e14391e94c850b8bd03680c23b38978db68687a8.tar.bz2 |
Merge Webkit at r70949: Initial merge by git.
Change-Id: I77b8645c083b5d0da8dba73ed01d4014aab9848e
Diffstat (limited to 'WebKitTools/GtkLauncher')
-rw-r--r-- | WebKitTools/GtkLauncher/main.c | 138 |
1 files changed, 91 insertions, 47 deletions
diff --git a/WebKitTools/GtkLauncher/main.c b/WebKitTools/GtkLauncher/main.c index 17ed40f..4abee08 100644 --- a/WebKitTools/GtkLauncher/main.c +++ b/WebKitTools/GtkLauncher/main.c @@ -27,26 +27,24 @@ #include <gtk/gtk.h> #include <webkit/webkit.h> -static GtkWidget* main_window; -static GtkWidget* uri_entry; -static GtkStatusbar* main_statusbar; -static WebKitWebView* web_view; -static gchar* main_title; -static gdouble load_progress; -static guint status_context_id; +static gint window_count = 0; + +static GtkWidget* create_window (WebKitWebView** out_web_view); static void activate_uri_entry_cb (GtkWidget* entry, gpointer data) { + WebKitWebView *web_view = g_object_get_data (G_OBJECT (entry), "web-view"); const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry)); g_assert (uri); webkit_web_view_load_uri (web_view, uri); } static void -update_title (GtkWindow* window) +update_title (GtkWindow* window, WebKitWebView* web_view) { - GString* string = g_string_new (main_title); + GString *string = g_string_new (webkit_web_view_get_title(web_view)); + gdouble load_progress = webkit_web_view_get_progress (web_view) * 100; g_string_append (string, " - WebKit Launcher"); if (load_progress < 100) g_string_append_printf (string, " (%f%%)", load_progress); @@ -56,25 +54,24 @@ update_title (GtkWindow* window) } static void -link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data) +link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, GtkStatusbar* statusbar) { + guint status_context_id = + GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (statusbar), "link-hover-context")); /* underflow is allowed */ - gtk_statusbar_pop (main_statusbar, status_context_id); + gtk_statusbar_pop (statusbar, status_context_id); if (link) - gtk_statusbar_push (main_statusbar, status_context_id, link); + gtk_statusbar_push (statusbar, status_context_id, link); } static void -notify_title_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) +notify_title_cb (WebKitWebView* web_view, GParamSpec* pspec, GtkWidget* window) { - if (main_title) - g_free (main_title); - main_title = g_strdup (webkit_web_view_get_title(web_view)); - update_title (GTK_WINDOW (main_window)); + update_title (GTK_WINDOW (window), web_view); } static void -notify_load_status_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) +notify_load_status_cb (WebKitWebView* web_view, GParamSpec* pspec, GtkWidget* uri_entry) { if (webkit_web_view_get_load_status (web_view) == WEBKIT_LOAD_COMMITTED) { WebKitWebFrame* frame = webkit_web_view_get_main_frame (web_view); @@ -85,43 +82,68 @@ notify_load_status_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data } static void -notify_progress_cb (WebKitWebView* web_view, GParamSpec* pspec, gpointer data) +notify_progress_cb (WebKitWebView* web_view, GParamSpec* pspec, GtkWidget* window) { - load_progress = webkit_web_view_get_progress (web_view) * 100; - update_title (GTK_WINDOW (main_window)); + update_title (GTK_WINDOW (window), web_view); } static void -destroy_cb (GtkWidget* widget, gpointer data) +destroy_cb (GtkWidget* widget, GtkWidget* window) { - gtk_main_quit (); + if (g_atomic_int_dec_and_test (&window_count)) + gtk_main_quit (); } static void -go_back_cb (GtkWidget* widget, gpointer data) +go_back_cb (GtkWidget* widget, WebKitWebView* web_view) { webkit_web_view_go_back (web_view); } static void -go_forward_cb (GtkWidget* widget, gpointer data) +go_forward_cb (GtkWidget* widget, WebKitWebView* web_view) { webkit_web_view_go_forward (web_view); } +static WebKitWebView* +create_web_view_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, GtkWidget* window) +{ + WebKitWebView *new_web_view; + create_window (&new_web_view); + return new_web_view; +} + +static gboolean +web_view_ready_cb (WebKitWebView* web_view, GtkWidget* window) +{ + gtk_widget_grab_focus (GTK_WIDGET (web_view)); + gtk_widget_show_all (window); + return FALSE; +} + +static gboolean +close_web_view_cb (WebKitWebView* web_view, GtkWidget* window) +{ + gtk_widget_destroy (window); + return TRUE; +} + static GtkWidget* -create_browser () +create_browser (GtkWidget* window, GtkWidget* uri_entry, GtkWidget* statusbar, WebKitWebView* web_view) { GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ()); gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view)); - g_signal_connect (web_view, "notify::title", G_CALLBACK (notify_title_cb), web_view); - g_signal_connect (web_view, "notify::load-status", G_CALLBACK (notify_load_status_cb), web_view); - g_signal_connect (web_view, "notify::progress", G_CALLBACK (notify_progress_cb), web_view); - g_signal_connect (web_view, "hovering-over-link", G_CALLBACK (link_hover_cb), web_view); + g_signal_connect (web_view, "notify::title", G_CALLBACK (notify_title_cb), window); + g_signal_connect (web_view, "notify::load-status", G_CALLBACK (notify_load_status_cb), uri_entry); + g_signal_connect (web_view, "notify::progress", G_CALLBACK (notify_progress_cb), window); + g_signal_connect (web_view, "hovering-over-link", G_CALLBACK (link_hover_cb), statusbar); + g_signal_connect (web_view, "create-web-view", G_CALLBACK (create_web_view_cb), window); + g_signal_connect (web_view, "web-view-ready", G_CALLBACK (web_view_ready_cb), window); + g_signal_connect (web_view, "close-web-view", G_CALLBACK (close_web_view_cb), window); return scrolled_window; } @@ -129,14 +151,16 @@ create_browser () static GtkWidget* create_statusbar () { - main_statusbar = GTK_STATUSBAR (gtk_statusbar_new ()); - status_context_id = gtk_statusbar_get_context_id (main_statusbar, "Link Hover"); + GtkStatusbar *statusbar = GTK_STATUSBAR (gtk_statusbar_new ()); + guint status_context_id = gtk_statusbar_get_context_id (statusbar, "Link Hover"); + g_object_set_data (G_OBJECT (statusbar), "link-hover-context", + GUINT_TO_POINTER(status_context_id)); - return (GtkWidget*)main_statusbar; + return GTK_WIDGET (statusbar); } static GtkWidget* -create_toolbar () +create_toolbar (GtkWidget* uri_entry, WebKitWebView* web_view) { GtkWidget* toolbar = gtk_toolbar_new (); @@ -151,23 +175,23 @@ create_toolbar () /* the back button */ item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_BACK); - g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (go_back_cb), NULL); + g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (go_back_cb), web_view); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); /* The forward button */ item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD); - g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (go_forward_cb), NULL); + g_signal_connect (G_OBJECT (item), "clicked", G_CALLBACK (go_forward_cb), web_view); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); /* The URL entry */ item = gtk_tool_item_new (); gtk_tool_item_set_expand (item, TRUE); - uri_entry = gtk_entry_new (); gtk_container_add (GTK_CONTAINER (item), uri_entry); g_signal_connect (G_OBJECT (uri_entry), "activate", G_CALLBACK (activate_uri_entry_cb), NULL); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); /* The go button */ + g_object_set_data (G_OBJECT (uri_entry), "web-view", web_view); item = gtk_tool_button_new_from_stock (GTK_STOCK_OK); g_signal_connect_swapped (G_OBJECT (item), "clicked", G_CALLBACK (activate_uri_entry_cb), (gpointer)uri_entry); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); @@ -176,13 +200,36 @@ create_toolbar () } static GtkWidget* -create_window () +create_window (WebKitWebView** out_web_view) { - GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + WebKitWebView *web_view; + GtkWidget *vbox; + GtkWidget *window; + GtkWidget *uri_entry; + GtkWidget *statusbar; + + g_atomic_int_inc (&window_count); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); gtk_widget_set_name (window, "GtkLauncher"); + + web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ()); + uri_entry = gtk_entry_new (); + + vbox = gtk_vbox_new (FALSE, 0); + statusbar = create_statusbar (web_view); + gtk_box_pack_start (GTK_BOX (vbox), create_toolbar (uri_entry, web_view), FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), create_browser (window, uri_entry, statusbar, web_view), TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 0); + + gtk_container_add (GTK_CONTAINER (window), vbox); + g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL); + if (out_web_view) + *out_web_view = web_view; + return window; } @@ -201,17 +248,14 @@ static gchar* filenameToURL(const char* filename) int main (int argc, char* argv[]) { + WebKitWebView *web_view; + GtkWidget *main_window; + gtk_init (&argc, &argv); if (!g_thread_supported ()) g_thread_init (NULL); - GtkWidget* vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), create_toolbar (), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (vbox), create_statusbar (), FALSE, FALSE, 0); - - main_window = create_window (); - gtk_container_add (GTK_CONTAINER (main_window), vbox); + main_window = create_window (&web_view); gchar *uri = (gchar*) (argc > 1 ? argv[1] : "http://www.google.com/"); gchar *fileURL = filenameToURL(uri); |