[geary/mjog/558-webkit-shared-process: 1/11] conversation-viewer: privatize web_view



commit 876b3923a8418b2aec0dd93422cbb6bcf25e1899
Author: Konstantin Kharlamov <Hi-Angel yandex ru>
Date:   Sun May 5 03:44:19 2019 +0300

    conversation-viewer: privatize web_view
    
    Signed-off-by: Konstantin Kharlamov <Hi-Angel yandex ru>

 .../conversation-viewer/conversation-email.vala    | 22 +++---
 .../conversation-viewer/conversation-list-box.vala | 14 ++--
 .../conversation-viewer/conversation-message.vala  | 78 +++++++++++++++++++++-
 3 files changed, 93 insertions(+), 21 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-email.vala 
b/src/client/conversation-viewer/conversation-email.vala
index 02ac6096..ac9b23f1 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -479,7 +479,7 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
         if (this.body_selection_message != null) {
             try {
                 selection =
-                   yield this.body_selection_message.web_view.get_selection_for_quoting();
+                   yield this.body_selection_message.get_selection_for_quoting();
             } catch (Error err) {
                 debug("Failed to get selection for quoting: %s", err.message);
             }
@@ -495,7 +495,7 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
         if (this.body_selection_message != null) {
             try {
                 selection =
-                   yield this.body_selection_message.web_view.get_selection_for_find();
+                   yield this.body_selection_message.get_selection_for_find();
             } catch (Error err) {
                 debug("Failed to get selection for find: %s", err.message);
             }
@@ -588,12 +588,10 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
         Json.Generator generator = new Json.Generator();
         generator.set_root(builder.get_root());
         string js = "geary.addPrintHeaders(" + generator.to_data(null) + ");";
-        yield this.primary_message.web_view.run_javascript(js, null);
+        yield this.primary_message.run_javascript(js, null);
 
         Gtk.Window? window = get_toplevel() as Gtk.Window;
-        WebKit.PrintOperation op = new WebKit.PrintOperation(
-            this.primary_message.web_view
-        );
+        WebKit.PrintOperation op = this.primary_message.new_print_operation();
         Gtk.PrintSettings settings = new Gtk.PrintSettings();
 
         if (this.email.subject != null) {
@@ -620,14 +618,14 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
     }
 
     private void connect_message_view_signals(ConversationMessage view) {
+        view.content_loaded.connect(on_content_loaded);
         view.flag_remote_images.connect(on_flag_remote_images);
         view.internal_link_activated.connect((y) => {
                 internal_link_activated(y);
             });
+        view.internal_resource_loaded.connect(on_resource_loaded);
         view.save_image.connect(on_save_image);
-        view.web_view.internal_resource_loaded.connect(on_resource_loaded);
-        view.web_view.content_loaded.connect(on_content_loaded);
-        view.web_view.selection_changed.connect((has_selection) => {
+        view.selection_changed.connect((has_selection) => {
                 this.body_selection_message = has_selection ? view : null;
                 body_selection_changed(has_selection);
             });
@@ -703,7 +701,7 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
 
         // Load all messages
 
-        this.primary_message.web_view.add_internal_resources(cid_resources);
+        this.primary_message.add_internal_resources(cid_resources);
         yield this.primary_message.load_message_body(
             message, this.load_cancellable
         );
@@ -721,7 +719,7 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
                     this.config
                 );
             connect_message_view_signals(attached_message);
-            attached_message.web_view.add_internal_resources(cid_resources);
+            attached_message.add_internal_resources(cid_resources);
             this.sub_messages.add(attached_message);
             this._attached_messages.add(attached_message);
             attached_message.load_contacts.begin(this.load_cancellable);
@@ -956,7 +954,7 @@ public class ConversationEmail : Gtk.Box, Geary.BaseInterface {
     private void on_content_loaded() {
         bool all_loaded = true;
         foreach (ConversationMessage message in this) {
-            if (!message.web_view.is_content_loaded) {
+            if (!message.is_content_loaded) {
                 all_loaded = false;
                 break;
             }
diff --git a/src/client/conversation-viewer/conversation-list-box.vala 
b/src/client/conversation-viewer/conversation-list-box.vala
index 4e501aa4..8668b59d 100644
--- a/src/client/conversation-viewer/conversation-list-box.vala
+++ b/src/client/conversation-viewer/conversation-list-box.vala
@@ -898,7 +898,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
      */
     public void zoom_in() {
         message_view_iterator().foreach((msg_view) => {
-                msg_view.web_view.zoom_in();
+                msg_view.zoom_in();
                 return true;
             });
     }
@@ -908,7 +908,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
      */
     public void zoom_out() {
         message_view_iterator().foreach((msg_view) => {
-                msg_view.web_view.zoom_out();
+                msg_view.zoom_out();
                 return true;
             });
     }
@@ -918,7 +918,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
      */
     public void zoom_reset() {
         message_view_iterator().foreach((msg_view) => {
-                msg_view.web_view.zoom_reset();
+                msg_view.zoom_reset();
                 return true;
             });
     }
@@ -1122,8 +1122,7 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
         row.get_allocation(out alloc);
 
         int x = 0, y = 0;
-        ConversationWebView web_view = row.view.primary_message.web_view;
-        web_view.translate_coordinates(row, x, anchor_y, out x, out y);
+        row.view.primary_message.web_view_translate_coordinates(row, x, anchor_y, out x, out y);
 
         Gtk.Adjustment adj = get_adjustment();
         y = alloc.y + y;
@@ -1156,14 +1155,13 @@ public class ConversationListBox : Gtk.ListBox, Geary.BaseInterface {
                 ConversationMessage conversation_message = view.primary_message;
                  int body_top = 0;
                  int body_left = 0;
-                 ConversationWebView web_view = conversation_message.web_view;
-                 web_view.translate_coordinates(
+                 conversation_message.web_view_translate_coordinates(
                      this,
                      0, 0,
                      out body_left, out body_top
                  );
 
-                 int body_height = web_view.get_allocated_height();
+                 int body_height = conversation_message.web_view_get_allocated_height();
                  int body_bottom = body_top + body_height;
 
                  // Only mark the email as read if it's actually visible
diff --git a/src/client/conversation-viewer/conversation-message.vala 
b/src/client/conversation-viewer/conversation-message.vala
index f88be3de..80b29557 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -223,7 +223,9 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
     internal Gtk.Grid infobars;
 
     /** HTML view that displays the message body. */
-    internal ConversationWebView web_view { get; private set; }
+    private ConversationWebView web_view { get; private set; }
+
+    public bool is_content_loaded { get { return web_view.is_content_loaded; } }
 
     // The message headers represented by this view
     private Geary.EmailHeaderSet headers;
@@ -346,6 +348,20 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
         string uri, string? alt_text, Geary.Memory.Buffer? buffer
     );
 
+    /** Emitted when web_view has loaded a resource added to it. */
+    public signal void internal_resource_loaded(string name);
+
+    /** Emitted when web_view's selection has changed. */
+    public signal void selection_changed(bool has_selection);
+
+    /**
+     * Emitted when web_view's content has finished loaded.
+     *
+     * See {@link is_content_loaded} for detail about when this is
+     * emitted.
+     */
+    public signal void content_loaded();
+
 
     /**
      * Constructs a new view from an email's headers and body.
@@ -387,6 +403,18 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
         );
     }
 
+    private void trigger_internal_resource_loaded(string name) {
+        internal_resource_loaded(name);
+    }
+
+    private void trigger_content_loaded() {
+        content_loaded();
+    }
+
+    private void trigger_selection_changed(bool has_selection) {
+        selection_changed(has_selection);
+    }
+
     private ConversationMessage(Geary.EmailHeaderSet headers,
                                 string? preview,
                                 bool load_remote_resources,
@@ -487,6 +515,9 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
                 this.remote_images_infobar.show();
             });
         this.web_view.selection_changed.connect(on_selection_changed);
+        this.web_view.internal_resource_loaded.connect(trigger_internal_resource_loaded);
+        this.web_view.content_loaded.connect(trigger_content_loaded);
+        this.web_view.selection_changed.connect(trigger_selection_changed);
         this.web_view.set_hexpand(true);
         this.web_view.set_vexpand(true);
         this.web_view.show();
@@ -519,6 +550,51 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
         base.destroy();
     }
 
+    public async string? get_selection_for_quoting() throws Error {
+        return yield web_view.get_selection_for_quoting();
+    }
+
+    public async string? get_selection_for_find() throws Error {
+        return yield web_view.get_selection_for_find();
+    }
+
+    /**
+     * Adds a set of internal resources to web_view.
+     *
+     * @see add_internal_resource
+     */
+    public void add_internal_resources(Gee.Map<string,Geary.Memory.Buffer> res) {
+        web_view.add_internal_resources(res);
+    }
+
+    public WebKit.PrintOperation new_print_operation() {
+        return new WebKit.PrintOperation(web_view);
+    }
+
+    public async void run_javascript (string script, Cancellable? cancellable) throws Error {
+        yield web_view.run_javascript(script, cancellable);
+    }
+
+    public void zoom_in() {
+        web_view.zoom_in();
+    }
+
+    public void zoom_out() {
+        web_view.zoom_out();
+    }
+
+    public void zoom_reset() {
+        web_view.zoom_reset();
+    }
+
+    public void web_view_translate_coordinates(Gtk.Widget widget, int x, int anchor_y, out int x1, out int 
y1) {
+        web_view.translate_coordinates(widget, x, anchor_y, out x1, out y1);
+    }
+
+    public int web_view_get_allocated_height() {
+        return web_view.get_allocated_height();
+    }
+
     /**
      * Shows the complete message and hides the compact headers.
      */


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