2011-03-31 Vamshikrishna.Yellenki <vamshi@motorola.com> and Alejandro G. Castro...
authoralex@webkit.org <alex@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Mar 2011 12:53:43 +0000 (12:53 +0000)
committeralex@webkit.org <alex@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Mar 2011 12:53:43 +0000 (12:53 +0000)
        Reviewed by Martin Robinson.

        Implement MiniBrowser for Gtk port.
        https://bugs.webkit.org/show_bug.cgi?id=48512

        Initial implementation of the Gtk MiniBrowser.

        * GNUmakefile.am:

2011-03-31  Vamshikrishna.Yellenki  <vamshi@motorola.com> and Alejandro G. Castro  <alex@igalia.com>

        Reviewed by Martin Robinson.

        Implement MiniBrowser for Gtk port.
        https://bugs.webkit.org/show_bug.cgi?id=48512

        Initial implementation of the Gtk MiniBrowser.

        * MiniBrowser/gtk/GNUmakefile.am: Added.
        * MiniBrowser/gtk/main.c: Added.
        (activateUriEntryCallback):
        (destroyCallback):
        (goBackCallback):
        (goForwardCallback):
        (createToolbar):
        (createWebView):
        (createWindow):
        (argumentToURL):
        (main):

2011-03-31  Vamshikrishna.Yellenki  <vamshi@motorola.com> and Alejandro G. Castro  <alex@igalia.com>

        Reviewed by Martin Robinson.

        Implement MiniBrowser for Gtk port.
        https://bugs.webkit.org/show_bug.cgi?id=48512

        * Shared/API/c/gtk/WKBaseGtk.h: Add the stdbool.h include.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@82570 268f45cc-cd09-0410-ab3c-d52691b4dbfc

ChangeLog
GNUmakefile.am
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/c/gtk/WKBaseGtk.h
Tools/ChangeLog
Tools/MiniBrowser/gtk/GNUmakefile.am [new file with mode: 0644]
Tools/MiniBrowser/gtk/main.c [new file with mode: 0644]

index 4ffbb80..f824e2b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-03-31  Vamshikrishna.Yellenki  <vamshi@motorola.com> and Alejandro G. Castro  <alex@igalia.com>
+
+        Reviewed by Martin Robinson.
+
+        Implement MiniBrowser for Gtk port.
+        https://bugs.webkit.org/show_bug.cgi?id=48512
+
+        Initial implementation of the Gtk MiniBrowser.
+
+        * GNUmakefile.am:
+
 2011-03-30  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [Qt] Typo fix, remove an accidentally added line.
index f87694b..af54891 100644 (file)
@@ -229,6 +229,7 @@ include Source/JavaScriptCore/GNUmakefile.am
 include Source/WebCore/GNUmakefile.am
 if ENABLE_WEBKIT2
 include Source/WebKit2/GNUmakefile.am
+include Tools/MiniBrowser/gtk/GNUmakefile.am
 # [GTK] Refactor the translations now that we have webkit2
 # https://bugs.webkit.org/show_bug.cgi?id=55153
 stamp-po:
index 9f76824..2be31fa 100644 (file)
@@ -1,3 +1,12 @@
+2011-03-31  Vamshikrishna.Yellenki  <vamshi@motorola.com> and Alejandro G. Castro  <alex@igalia.com>
+
+        Reviewed by Martin Robinson.
+
+        Implement MiniBrowser for Gtk port.
+        https://bugs.webkit.org/show_bug.cgi?id=48512
+
+        * Shared/API/c/gtk/WKBaseGtk.h: Add the stdbool.h include.
+
 2011-03-30  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Maciej Stachowiak.
index 8f34ed3..eb88f70 100644 (file)
@@ -32,6 +32,8 @@
 #error "Please #include \"WKBase.h\" instead of this file directly."
 #endif
 
+#include <stdbool.h>
+
 typedef const struct OpaqueWKView* WKViewRef;
 
 #endif /* WKBaseGtk_h */
index f3c7557..218b64f 100644 (file)
@@ -1,3 +1,24 @@
+2011-03-31  Vamshikrishna.Yellenki  <vamshi@motorola.com> and Alejandro G. Castro  <alex@igalia.com>
+
+        Reviewed by Martin Robinson.
+
+        Implement MiniBrowser for Gtk port.
+        https://bugs.webkit.org/show_bug.cgi?id=48512
+
+        Initial implementation of the Gtk MiniBrowser.
+
+        * MiniBrowser/gtk/GNUmakefile.am: Added.
+        * MiniBrowser/gtk/main.c: Added.
+        (activateUriEntryCallback):
+        (destroyCallback):
+        (goBackCallback):
+        (goForwardCallback):
+        (createToolbar):
+        (createWebView):
+        (createWindow):
+        (argumentToURL):
+        (main):
+
 2011-03-30  Dominic Cooney  <dominicc@google.com>
 
         Reviewed by Dimitri Glazkov.
diff --git a/Tools/MiniBrowser/gtk/GNUmakefile.am b/Tools/MiniBrowser/gtk/GNUmakefile.am
new file mode 100644 (file)
index 0000000..24da0ad
--- /dev/null
@@ -0,0 +1,33 @@
+bin_PROGRAMS += \
+       Programs/MiniBrowser
+
+Programs_MiniBrowser_CPPFLAGS = \
+       -I$(srcdir)/Source \
+       -I$(top_builddir)/DerivedSources/WebKit2/include \
+       $(global_cppflags) \
+       $(GLIB_CFLAGS) \
+       $(GTK_CFLAGS)
+
+Programs_MiniBrowser_SOURCES = \
+       Tools/MiniBrowser/gtk/main.c
+
+BUILT_SOURCES += \
+       generate-minibrowser-forward-headers
+
+MiniBrowser := $(srcdir)/Tools/MiniBrowser/gtk
+MiniBrowserFwdHeaders := $(GENSOURCES_WEBKIT2)/include
+generate-minibrowser-forward-headers: $(WebKit2)/Scripts/generate-forwarding-headers.pl $(Programs_MiniBrowser_SOURCES)
+       $(AM_V_GEN)$(PERL) $< $(MiniBrowser) $(MiniBrowserFwdHeaders) gtk
+       $(AM_V_GEN)$(PERL) $< $(MiniBrowser) $(MiniBrowserFwdHeaders) soup
+
+Programs_MiniBrowser_LDADD = \
+       libwebkit2gtk-@WEBKITGTK_API_MAJOR_VERSION@.@WEBKITGTK_API_MINOR_VERSION@.la \
+       $(GLIB_LIBS) \
+       $(GTK_LIBS)
+
+Programs_MiniBrowser_LDFLAGS = \
+       -no-fast-install \
+       -no-install
+
+CLEANFILES += \
+       $(top_builddir)/Programs/MiniBrowser
diff --git a/Tools/MiniBrowser/gtk/main.c b/Tools/MiniBrowser/gtk/main.c
new file mode 100644 (file)
index 0000000..0c32510
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc.
+ * Copyright (C) 2007 Alp Toker <alp@atoker.com>
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <WebKit2/WebKit2.h>
+#include <gtk/gtk.h>
+
+static void activateUriEntryCallback(GtkWidget *entry, gpointer data)
+{
+    WKViewRef webView = g_object_get_data(G_OBJECT(entry), "web-view");
+    const gchar *uri = gtk_entry_get_text(GTK_ENTRY(entry));
+    WKPageLoadURL(WKViewGetPage(webView), WKURLCreateWithURL(uri));
+}
+
+static void destroyCallback(GtkWidget *widget, GtkWidget *window)
+{
+    gtk_main_quit();
+}
+
+static void goBackCallback(GtkWidget *widget, WKViewRef webView)
+{
+    WKPageGoBack(WKViewGetPage(webView));
+}
+
+static void goForwardCallback(GtkWidget *widget, WKViewRef webView)
+{
+    WKPageGoForward(WKViewGetPage(webView));
+}
+
+static GtkWidget *createToolbar(GtkWidget *uriEntry, WKViewRef webView)
+{
+    GtkWidget *toolbar = gtk_toolbar_new();
+
+#if GTK_CHECK_VERSION(2, 15, 0)
+    gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
+#else
+    gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
+#endif
+    gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH_HORIZ);
+
+    GtkToolItem *item = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK);
+    g_signal_connect(item, "clicked", G_CALLBACK(goBackCallback), (gpointer)webView);
+    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
+
+    item = gtk_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD);
+    g_signal_connect(G_OBJECT(item), "clicked", G_CALLBACK(goForwardCallback), (gpointer)webView);
+    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
+
+    item = gtk_tool_item_new();
+    gtk_tool_item_set_expand(item, TRUE);
+    gtk_container_add(GTK_CONTAINER(item), uriEntry);
+    g_signal_connect(uriEntry, "activate", G_CALLBACK(activateUriEntryCallback), NULL);
+    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
+
+    g_object_set_data(G_OBJECT(uriEntry), "web-view", (gpointer)webView);
+    item = gtk_tool_button_new_from_stock(GTK_STOCK_OK);
+    g_signal_connect_swapped(item, "clicked", G_CALLBACK(activateUriEntryCallback), (gpointer)uriEntry);
+    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
+
+    return toolbar;
+}
+
+static WKViewRef createWebView()
+{
+    return WKViewCreate(WKContextGetSharedProcessContext(), 0);
+}
+
+static GtkWidget *createWindow(WKViewRef webView)
+{
+    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
+    gtk_widget_set_name(window, "MiniBrowser");
+
+    GtkWidget *uriEntry = gtk_entry_new();
+
+    GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(vbox), createToolbar(uriEntry, webView), FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(vbox), WKViewGetWindow(webView), TRUE, TRUE, 0);
+
+    gtk_container_add(GTK_CONTAINER(window), vbox);
+
+    g_signal_connect(window, "destroy", G_CALLBACK(destroyCallback), NULL);
+
+    return window;
+}
+
+static gchar *argumentToURL(const char *filename)
+{
+    GFile *gfile = g_file_new_for_commandline_arg(filename);
+    gchar *fileURL = g_file_get_uri(gfile);
+    g_object_unref(gfile);
+
+    return fileURL;
+}
+
+int main(int argc, char *argv[])
+{
+    gtk_init(&argc, &argv);
+
+    if (!g_thread_supported())
+        g_thread_init(NULL);
+
+    WKViewRef webView = createWebView();
+    GtkWidget *mainWindow = createWindow(webView);
+
+    gchar* url = argumentToURL(argc > 1 ? argv[1] : "http://www.webkitgtk.org/");
+    WKPageLoadURL(WKViewGetPage(webView), WKURLCreateWithURL(url));
+    g_free(url);
+
+    gtk_widget_grab_focus(WKViewGetWindow(webView));
+    gtk_widget_show_all(mainWindow);
+    gtk_main();
+
+    return 0;
+}