[Xfce4-commits] <midori:master> Abstract view-source for WebKit1/ 2 in Midori.Tab

Christian Dywan noreply at xfce.org
Fri Apr 5 00:30:01 CEST 2013


Updating branch refs/heads/master
         to f8d82b437b0b2cd0ee0cb62d473940f9c340ce70 (commit)
       from 901d547c40cc16d752765c475a0f55da20e2352f (commit)

commit f8d82b437b0b2cd0ee0cb62d473940f9c340ce70
Author: Christian Dywan <christian at twotoasts.de>
Date:   Thu Apr 4 23:23:44 2013 +0200

    Abstract view-source for WebKit1/ 2 in Midori.Tab

 extensions/addons.c        |    3 +--
 midori/midori-browser.c    |    4 +---
 midori/midori-tab.vala     |   28 +++++++++++++++++++++-------
 midori/midori-view.c       |    4 +---
 midori/webkit2gtk-3.0.vapi |    6 ++++++
 tests/tab.vala             |   15 +++------------
 6 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/extensions/addons.c b/extensions/addons.c
index 1ce19c4..e157840 100644
--- a/extensions/addons.c
+++ b/extensions/addons.c
@@ -243,9 +243,8 @@ addons_notify_load_status_cb (MidoriView*      view,
                               MidoriExtension* extension)
 {
     const gchar* uri = midori_view_get_display_uri (view);
-    WebKitWebView* web_view = WEBKIT_WEB_VIEW (midori_view_get_web_view (view));
 
-    if (webkit_web_view_get_view_source_mode (web_view))
+    if (midori_tab_get_view_source (MIDORI_TAB (view)))
         return;
 
     if (uri && *uri)
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index a997f7f..3ceb8e3 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -3505,9 +3505,7 @@ _action_source_view_activate (GtkAction*     action,
 
         source = midori_view_new_with_item (NULL, browser->settings);
         source_view = midori_view_get_web_view (MIDORI_VIEW (source));
-#ifndef HAVE_WEBKIT2
-        webkit_web_view_set_view_source_mode (WEBKIT_WEB_VIEW (source_view), TRUE);
-#endif
+        midori_tab_set_view_source (MIDORI_TAB (source_view), TRUE);
         webkit_web_view_load_uri (WEBKIT_WEB_VIEW (source_view), source_uri);
         midori_browser_add_tab (browser, source);
     }
diff --git a/midori/midori-tab.vala b/midori/midori-tab.vala
index fd300e8..94a24ec 100644
--- a/midori/midori-tab.vala
+++ b/midori/midori-tab.vala
@@ -136,9 +136,26 @@ namespace Midori {
 #endif
         }
 
+#if HAVE_WEBKIT2
+        public bool view_source { get {
+            return web_view.view_mode == WebKit.ViewMode.SOURCE;
+        }
+        set {
+            web_view.view_mode = value ? WebKit.ViewMode.SOURCE : WebKit.ViewMode.WEB;
+        }
+        }
+#else
+        public bool view_source { get {
+            return web_view.get_view_source_mode ();
+        }
+        set {
+            web_view.set_view_source_mode (value);
+        }
+        }
+#endif
+
         public bool can_view_source () {
-#if !HAVE_WEBKIT2
-            if (is_blank () || special || web_view.get_view_source_mode ())
+            if (is_blank () || special || view_source)
                 return false;
             string content_type = ContentType.from_mime_type (mime_type);
 #if HAVE_WIN32
@@ -148,9 +165,6 @@ namespace Midori {
             string text_type = ContentType.from_mime_type ("text/plain");
 #endif
             return ContentType.is_a (content_type, text_type);
-#else
-            return true;
-#endif
         }
 
         public static string get_display_title (string? title, string uri) {
@@ -191,11 +205,11 @@ namespace Midori {
 
         /* Since: 0.4.3 */
         public bool can_save () {
-#if !HAVE_WEBKIT2
             if (is_blank () || special)
                 return false;
-            if (web_view.get_view_source_mode ())
+            if (view_source)
                 return false;
+#if !HAVE_WEBKIT2
             if (web_view.get_main_frame ().get_data_source ().get_data () == null)
                 return false;
 #endif
diff --git a/midori/midori-view.c b/midori/midori-view.c
index 13ef417..7350023 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -4337,9 +4337,7 @@ midori_view_set_uri (MidoriView*  view,
             midori_tab_set_uri (MIDORI_TAB (view), uri);
             katze_item_set_uri (view->item, midori_tab_get_uri (MIDORI_TAB (view)));
             katze_assign (view->title, NULL);
-#ifndef HAVE_WEBKIT2
-            webkit_web_view_set_view_source_mode (WEBKIT_WEB_VIEW (view->web_view), FALSE);
-#endif
+            midori_tab_set_view_source (MIDORI_TAB (view), FALSE);
             webkit_web_view_load_uri (WEBKIT_WEB_VIEW (view->web_view), uri);
         }
         g_free (temporary_uri);
diff --git a/midori/webkit2gtk-3.0.vapi b/midori/webkit2gtk-3.0.vapi
index 34766bd..0279812 100644
--- a/midori/webkit2gtk-3.0.vapi
+++ b/midori/webkit2gtk-3.0.vapi
@@ -464,6 +464,11 @@ namespace WebKit {
 		public signal void received_data (uint64 data_length);
 		public signal void sent_request (WebKit.URIRequest request, WebKit.URIResponse redirected_response);
 	}
+	[CCode (cheader_filename = "webkit2/webkit2.h", cprefix = "WEBKIT_VIEW_MODE_")]
+	public enum ViewMode {
+		WEB,
+		SOURCE
+	}
 	[CCode (cheader_filename = "webkit2/webkit2.h", type_id = "webkit_web_view_get_type ()")]
 	public class WebView : WebKit.WebViewBase, Atk.Implementor, Gtk.Buildable {
 		[CCode (has_construct_function = false, type = "GtkWidget*")]
@@ -509,6 +514,7 @@ namespace WebKit {
 		[NoAccessorMethod]
 		public WebKit.WebContext web_context { owned get; construct; }
 		public double zoom_level { get; set; }
+		public WebKit.ViewMode view_mode { get; set; }
 		public virtual signal void close ();
 		public virtual signal bool context_menu (WebKit.ContextMenu context_menu, Gdk.Event event, WebKit.HitTestResult hit_test_result);
 		public virtual signal void context_menu_dismissed ();
diff --git a/tests/tab.vala b/tests/tab.vala
index 6e9da64..d66927d 100644
--- a/tests/tab.vala
+++ b/tests/tab.vala
@@ -209,20 +209,14 @@ void tab_http () {
 
     var source = new Midori.View.with_title (null, tab.settings);
     browser.add_tab (source);
-#if HAVE_WEBKIT2
-#else
-    source.web_view.set_view_source_mode (true);
-#endif
+    source.view_source = true;
     source.web_view.load_uri (test_url);
     do { loop.iteration (true); } while (source.load_status != Midori.LoadStatus.FINISHED);
     assert (!source.is_blank ());
     assert (!source.can_view_source ());
     assert (!source.special);
     /* FIXME assert (source.can_save ()); */
-#if HAVE_WEBKIT2
-#else
-    assert (source.web_view.get_view_source_mode ());
-#endif
+    assert (source.view_source);
 
     source.set_uri ("http://.invalid");
     do { loop.iteration (true); } while (source.load_status != Midori.LoadStatus.FINISHED);
@@ -230,10 +224,7 @@ void tab_http () {
     assert (!source.can_view_source ());
     assert (source.special);
     assert (!source.can_save ());
-#if HAVE_WEBKIT2
-#else
-    assert (!source.web_view.get_view_source_mode ());
-#endif
+    assert (!source.view_source);
 
     Midori.Test.release_max_timeout ();
 }


More information about the Xfce4-commits mailing list