[devhelp/webkit2-for-3.4: 3/9] Initial WebKit2 port



commit 7ed9d181c4ec17b907ef235a00e8a85fe7bd3951
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Thu Jan 19 15:21:22 2012 +0100

    Initial WebKit2 port
    
    It builds and works, but some features haven't been ported yet so they
    just don't work.

 configure.ac            |   19 ++++++++-
 src/Makefile.am         |    4 ++
 src/dh-assistant-view.c |   17 +++++++-
 src/dh-assistant-view.h |    4 ++
 src/dh-assistant.c      |    9 ++++-
 src/dh-util.c           |    4 ++
 src/dh-util.h           |    4 ++
 src/dh-window.c         |   96 ++++++++++++++++++++++++++++++++++++----------
 8 files changed, 131 insertions(+), 26 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8967493..ff78579 100644
--- a/configure.ac
+++ b/configure.ac
@@ -57,10 +57,24 @@ else
 fi
 AM_CONDITIONAL(GCONF_SCHEMAS_INSTALL, test "x$IGE_PLATFORM" = xx11)
 
+AC_ARG_WITH(webkit2,
+        [AC_HELP_STRING([--with-webkit2], [build with WebKit2 [default=no]])],
+        [],[with_webkit2=no])
+
+if test "x$with_webkit2" != xno; then
+   WEBKITGTK_PC_NAME=webkit2gtk-3.0
+   WEBKITGTK_REQUIRED_VERSION=1.7.91
+   AC_DEFINE([HAVE_WEBKIT2],[1],[Define if building with WebKit2])
+else
+   WEBKITGTK_PC_NAME=webkitgtk-3.0
+   WEBKITGTK_REQUIRED_VERSION=1.6.0
+fi
+AM_CONDITIONAL(WITH_WEBKIT2, test "x$with_webkit2" != xno)
+
 PKG_CHECK_MODULES(DEVHELP, [
   gthread-2.0 >= 2.10.0
   gtk+-3.0 >= 3.0.2
-  webkitgtk-3.0
+  $WEBKITGTK_PC_NAME >= $WEBKITGTK_REQUIRED_VERSION
   glib-2.0 >= 2.25.11
 ])
 
@@ -68,7 +82,7 @@ PKG_CHECK_MODULES(LIBDEVHELP, [
   gtk+-3.0 >= 3.0.2
   $gconf_pkgconfig
   $gtkmacintegration_pkgconfig
-  webkitgtk-3.0
+  $WEBKITGTK_PC_NAME >= $WEBKITGTK_REQUIRED_VERSION
 ])
 
 AC_ARG_WITH(zlib, [  --with-zlib=DIR         use zlib in DIR], zlibdir=$with_zlib)
@@ -124,4 +138,5 @@ AC_OUTPUT
 echo
 echo "Prefix:    $prefix"
 echo "Platform:  $IGE_PLATFORM_NAME"
+echo "WebKit2:   $with_webkit2"
 echo
diff --git a/src/Makefile.am b/src/Makefile.am
index 436d267..355f254 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,6 +28,10 @@ AM_CPPFLAGS = 						\
 	-DGTK_DISABLE_SINGLE_INCLUDES			\
 	$(WARN_CFLAGS)
 
+if WITH_WEBKIT2
+AM_CPPFLAGS += -DHAVE_WEBKIT2
+endif
+
 bin_PROGRAMS = devhelp
 
 devhelp_SOURCES =					\
diff --git a/src/dh-assistant-view.c b/src/dh-assistant-view.c
index 796f97e..0c944ca 100644
--- a/src/dh-assistant-view.c
+++ b/src/dh-assistant-view.c
@@ -22,7 +22,6 @@
 #include "config.h"
 #include <string.h>
 #include <glib/gi18n-lib.h>
-#include <webkit/webkit.h>
 #include "dh-assistant-view.h"
 #include "dh-link.h"
 #include "dh-util.h"
@@ -60,6 +59,9 @@ view_finalize (GObject *object)
         G_OBJECT_CLASS (dh_assistant_view_parent_class)->finalize (object);
 }
 
+#ifdef HAVE_WEBKIT2
+/* TODO: Policy Client */
+#else
 static WebKitNavigationResponse
 assistant_navigation_requested (WebKitWebView        *web_view,
                                 WebKitWebFrame       *frame,
@@ -87,6 +89,7 @@ assistant_navigation_requested (WebKitWebView        *web_view,
 
         return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
 }
+#endif /* HAVE_WEBKIT2 */
 
 static gboolean
 assistant_button_press_event (GtkWidget      *widget,
@@ -110,8 +113,11 @@ dh_assistant_view_class_init (DhAssistantViewClass* klass)
         object_class->finalize = view_finalize;
 
         widget_class->button_press_event = assistant_button_press_event;
-
+#ifdef HAVE_WEBKIT2
+/* TODO: Policy Client */
+#else
         web_view_class->navigation_requested = assistant_navigation_requested;
+#endif
 
         g_type_class_add_private (klass, sizeof (DhAssistantViewPriv));
 }
@@ -352,12 +358,19 @@ dh_assistant_view_set_link (DhAssistantView *view,
                 g_free (javascript_uri);
 
                 priv->snippet_loaded = FALSE;
+#ifdef HAVE_WEBKIT2
+                webkit_web_view_load_html (
+                        WEBKIT_WEB_VIEW (view),
+                        html,
+                        filename);
+#else
                 webkit_web_view_load_string (
                         WEBKIT_WEB_VIEW (view),
                         html,
                         "text/html",
                         NULL,
                         filename);
+#endif
 
                 g_free (html);
         } else {
diff --git a/src/dh-assistant-view.h b/src/dh-assistant-view.h
index 2d70eac..2ecfbce 100644
--- a/src/dh-assistant-view.h
+++ b/src/dh-assistant-view.h
@@ -21,7 +21,11 @@
 #ifndef __DH_ASSISTANT_VIEW_H__
 #define __DH_ASSISTANT_VIEW_H__
 
+#ifdef HAVE_WEBKIT2
+#include <webkit2/webkit2.h>
+#else
 #include <webkit/webkit.h>
+#endif
 #include "dh-base.h"
 #include "dh-link.h"
 
diff --git a/src/dh-assistant.c b/src/dh-assistant.c
index c3e7f63..c614c59 100644
--- a/src/dh-assistant.c
+++ b/src/dh-assistant.c
@@ -64,7 +64,9 @@ static void
 dh_assistant_init (DhAssistant *assistant)
 {
         DhAssistantPriv *priv = GET_PRIVATE (assistant);
+#ifndef HAVE_WEBKIT2
         GtkWidget       *scrolled_window;
+#endif
 
         priv->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
         gtk_widget_show (priv->main_box);
@@ -79,7 +81,11 @@ dh_assistant_init (DhAssistant *assistant)
         g_signal_connect (assistant, "key-press-event",
                           G_CALLBACK (assistant_key_press_event_cb),
                           assistant);
-
+#ifdef HAVE_WEBKIT2
+        gtk_box_pack_start (GTK_BOX (priv->main_box),
+                            priv->view, TRUE, TRUE, 0);
+        gtk_widget_show (priv->view);
+#else
         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
@@ -90,6 +96,7 @@ dh_assistant_init (DhAssistant *assistant)
 
         gtk_box_pack_start (GTK_BOX (priv->main_box),
                             scrolled_window, TRUE, TRUE, 0);
+#endif
 
         dh_util_state_manage_window (GTK_WINDOW (assistant),
                                      "assistant/window");
diff --git a/src/dh-util.c b/src/dh-util.c
index 27c029a..897ef9e 100644
--- a/src/dh-util.c
+++ b/src/dh-util.c
@@ -669,6 +669,9 @@ view_destroy_cb (GtkWidget *view,
 static void
 view_setup_fonts (WebKitWebView *view)
 {
+#ifdef HAVE_WEBKIT2
+/* TODO: WebKit Settings */
+#else
         IgeConf           *conf;
         WebKitWebSettings *settings;
         gboolean           use_system_fonts;
@@ -700,6 +703,7 @@ view_setup_fonts (WebKitWebView *view)
 
         g_free (variable_name);
         g_free (fixed_name);
+#endif /* HAVE_WEBKIT2 */
 }
 
 static void
diff --git a/src/dh-util.h b/src/dh-util.h
index ecb4b42..0ac9778 100644
--- a/src/dh-util.h
+++ b/src/dh-util.h
@@ -23,7 +23,11 @@
 #define __DH_UTIL_H__
 
 #include <gtk/gtk.h>
+#ifdef HAVE_WEBKIT2
+#include <webkit2/webkit2.h>
+#else
 #include <webkit/webkit.h>
+#endif
 #include "dh-link.h"
 
 G_BEGIN_DECLS
diff --git a/src/dh-window.c b/src/dh-window.c
index 9944a7f..c0c6737 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -30,7 +30,11 @@
 #include <glib/gi18n-lib.h>
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
+#ifdef HAVE_WEBKIT2
+#include <webkit2/webkit2.h>
+#else
 #include <webkit/webkit.h>
+#endif
 
 #ifdef GDK_WINDOWING_QUARTZ
 #include <gtkosxapplication.h>
@@ -191,10 +195,14 @@ static void
 window_activate_print (GtkAction *action,
                        DhWindow  *window)
 {
+#ifdef HAVE_WEBKIT2
+/* TODO: Printing API */
+#else
     WebKitWebView *web_view;
 
     web_view = window_get_active_web_view (window);
     webkit_web_view_execute_script (web_view, "print();");
+#endif
 }
 
 static void
@@ -256,10 +264,14 @@ window_activate_copy (GtkAction *action,
                 gtk_clipboard_set_text (clipboard,
                                 dh_link_get_name(priv->selected_search_link), -1);
         } else {
+#ifdef HAVE_WEBKIT2
+/* TODO: Editor API */
+#else
                 WebKitWebView *web_view;
 
                 web_view = window_get_active_web_view (window);
                 webkit_web_view_copy_clipboard (web_view);
+#endif
         }
 }
 
@@ -267,6 +279,9 @@ static void
 window_activate_find (GtkAction *action,
                       DhWindow  *window)
 {
+#ifdef HAVE_WEBKIT2
+/* TODO: Find API */
+#else
         DhWindowPriv  *priv;
         WebKitWebView *web_view;
 
@@ -277,6 +292,7 @@ window_activate_find (GtkAction *action,
         gtk_widget_grab_focus (priv->findbar);
 
         webkit_web_view_set_highlight_text_matches (web_view, TRUE);
+#endif /* HAVE_WEBKIT2 */
 }
 
 static int
@@ -1020,14 +1036,12 @@ window_web_view_switch_page_cb (GtkNotebook     *notebook,
         new_page = gtk_notebook_get_nth_page (notebook, new_page_num);
         if (new_page) {
                 WebKitWebView  *new_web_view;
-                WebKitWebFrame *web_frame;
                 const gchar    *location;
 
                 new_web_view = g_object_get_data (G_OBJECT (new_page), "web_view");
 
                 /* Sync the book tree. */
-                web_frame = webkit_web_view_get_main_frame (new_web_view);
-                location = webkit_web_frame_get_uri (web_frame);
+                location = webkit_web_view_get_uri (new_web_view);
 
                 if (location) {
                         dh_book_tree_select_uri (DH_BOOK_TREE (priv->book_tree),
@@ -1275,7 +1289,9 @@ find_library_equivalent (DhWindow    *window,
         return local_uri;
 }
 
-
+#ifdef HAVE_WEBKIT2
+/* TODO: Policy Client */
+#else
 static gboolean
 window_web_view_navigation_policy_decision_requested (WebKitWebView             *web_view,
                                                       WebKitWebFrame            *frame,
@@ -1327,14 +1343,23 @@ window_web_view_navigation_policy_decision_requested (WebKitWebView
 
         return FALSE;
 }
+#endif /* HAVE_WEBKIT2 */
 
-
+#ifdef HAVE_WEBKIT2
+static gboolean
+window_web_view_load_failed_cb (WebKitWebView   *web_view,
+                                WebKitLoadEvent  load_event,
+                                const gchar     *uri,
+                                GError          *web_error,
+                                DhWindow        *window)
+#else
 static gboolean
 window_web_view_load_error_cb (WebKitWebView  *web_view,
                                WebKitWebFrame *frame,
                                gchar          *uri,
                                gpointer       *web_error,
                                DhWindow       *window)
+#endif
 {
         GtkWidget *info_bar;
         GtkWidget *content_area;
@@ -1426,11 +1451,12 @@ window_check_history (DhWindow      *window,
 }
 
 static void
-window_web_view_title_changed_cb (WebKitWebView  *web_view,
-                                  WebKitWebFrame *web_frame,
-                                  const gchar    *title,
-                                  DhWindow       *window)
+window_web_view_title_changed_cb (WebKitWebView *web_view,
+                                  GParamSpec    *param_spec,
+                                  DhWindow      *window)
 {
+        const gchar *title = webkit_web_view_get_title (web_view);
+
         if (web_view == window_get_active_web_view (window)) {
                 window_update_title (window, web_view, title);
         }
@@ -1453,6 +1479,9 @@ window_web_view_button_press_event_cb (WebKitWebView  *web_view,
 static gboolean
 do_search (DhWindow *window)
 {
+#ifdef HAVE_WEBKIT2
+/* TODO: Find API */
+#else
         DhWindowPriv  *priv = window->priv;
         WebKitWebView *web_view;
 
@@ -1471,6 +1500,7 @@ do_search (DhWindow *window)
                 web_view, egg_find_bar_get_search_string (EGG_FIND_BAR (priv->findbar)),
                 egg_find_bar_get_case_sensitive (EGG_FIND_BAR (priv->findbar)),
                 TRUE, TRUE);
+#endif /* HAVE_WEBKIT2 */
 
 	return FALSE;
 }
@@ -1504,10 +1534,13 @@ window_find_case_changed_cb (GObject    *object,
 
         string = egg_find_bar_get_search_string (EGG_FIND_BAR (priv->findbar));
         case_sensitive = egg_find_bar_get_case_sensitive (EGG_FIND_BAR (priv->findbar));
-
+#ifdef HAVE_WEBKIT2
+/* TODO: Find API */
+#else
         webkit_web_view_unmark_text_matches (view);
         webkit_web_view_mark_text_matches (view, string, case_sensitive, 0);
         webkit_web_view_set_highlight_text_matches (view, TRUE);
+#endif
 }
 
 static void
@@ -1525,8 +1558,11 @@ window_find_next_cb (GtkEntry *entry,
 
         string = egg_find_bar_get_search_string (EGG_FIND_BAR (priv->findbar));
         case_sensitive = egg_find_bar_get_case_sensitive (EGG_FIND_BAR (priv->findbar));
-
+#ifdef HAVE_WEBKIT2
+/* TODO: Find API */
+#else
         webkit_web_view_search_text (view, string, case_sensitive, TRUE, TRUE);
+#endif
 }
 
 static void
@@ -1544,8 +1580,11 @@ window_find_previous_cb (GtkEntry *entry,
 
         string = egg_find_bar_get_search_string (EGG_FIND_BAR (priv->findbar));
         case_sensitive = egg_find_bar_get_case_sensitive (EGG_FIND_BAR (priv->findbar));
-
+#ifdef HAVE_WEBKIT2
+/* TODO: Find API */
+#else
         webkit_web_view_search_text (view, string, case_sensitive, FALSE, TRUE);
+#endif
 }
 
 static void
@@ -1558,8 +1597,11 @@ window_findbar_close_cb (GtkWidget *widget,
         view = window_get_active_web_view (window);
 
         gtk_widget_hide (priv->findbar);
-
+#ifdef HAVE_WEBKIT2
+/* TODO: Find API */
+#else
         webkit_web_view_set_highlight_text_matches (view, FALSE);
+#endif
 }
 
 #if 0
@@ -1606,10 +1648,12 @@ window_open_new_tab (DhWindow    *window,
         DhWindowPriv *priv;
         GtkWidget    *view;
         GtkWidget    *vbox;
-        GtkWidget    *scrolled_window;
         GtkWidget    *label;
         gint          num;
         GtkWidget    *info_bar;
+#ifndef HAVE_WEBKIT2
+        GtkWidget    *scrolled_window;
+#endif
 
         priv = window->priv;
 
@@ -1649,6 +1693,9 @@ window_open_new_tab (DhWindow    *window,
 
         gtk_box_pack_start (GTK_BOX(vbox), info_bar, FALSE, TRUE, 0);
 
+#ifdef HAVE_WEBKIT2
+        gtk_box_pack_start (GTK_BOX(vbox), view, TRUE, TRUE, 0);
+#else
         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                         GTK_POLICY_AUTOMATIC,
@@ -1656,22 +1703,33 @@ window_open_new_tab (DhWindow    *window,
         gtk_container_add (GTK_CONTAINER (scrolled_window), view);
         gtk_widget_show (scrolled_window);
         gtk_box_pack_start (GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
+#endif
 
         label = window_new_tab_label (window, _("Empty Page"), vbox);
         gtk_widget_show_all (label);
 
-        g_signal_connect (view, "title-changed",
+        g_signal_connect (view, "notify::title",
                           G_CALLBACK (window_web_view_title_changed_cb),
                           window);
         g_signal_connect (view, "button-press-event",
                           G_CALLBACK (window_web_view_button_press_event_cb),
                           window);
+#ifdef HAVE_WEBKIT2
+/* TODO: Policy Client */
+#else
         g_signal_connect (view, "navigation-policy-decision-requested",
                           G_CALLBACK (window_web_view_navigation_policy_decision_requested),
                           window);
+#endif
+#ifdef HAVE_WEBKIT2
+        g_signal_connect (view, "load-failed",
+                          G_CALLBACK (window_web_view_load_failed_cb),
+                          window);
+#else
         g_signal_connect (view, "load-error",
                           G_CALLBACK (window_web_view_load_error_cb),
                           window);
+#endif
 
         num = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
                                         vbox, NULL);
@@ -1847,12 +1905,8 @@ window_update_title (DhWindow      *window,
 
         priv = window->priv;
 
-        if (!web_view_title) {
-                WebKitWebFrame *web_frame;
-
-                web_frame = webkit_web_view_get_main_frame (web_view);
-                web_view_title = webkit_web_frame_get_title (web_frame);
-        }
+        if (!web_view_title)
+                web_view_title = webkit_web_view_get_title (web_view);
 
         if (web_view_title && *web_view_title == '\0') {
                 web_view_title = NULL;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]