[geary/wip/728002-webkit2] Only use HTML preferred height for conversation web view, not composer's.



commit 2dd15028d0069c2e72811b4742ffd73033e01178
Author: Michael James Gratton <mike vee net>
Date:   Thu Jan 26 22:00:00 2017 +1100

    Only use HTML preferred height for conversation web view, not composer's.
    
    * src/client/components/client-web-view.vala
      (ClientWebView::preferred_height): Make preferred_height a public
      property so it can be accessed outside the class. Move
      ::get_preferred_height and ::get_preferred_width to
      ConversationWebView. Tidy up ::on_preferred_height_changed a bit.

 src/client/components/client-web-view.vala         |   44 ++++++++------------
 .../conversation-viewer/conversation-web-view.vala |   16 +++++++
 2 files changed, 33 insertions(+), 27 deletions(-)
---
diff --git a/src/client/components/client-web-view.vala b/src/client/components/client-web-view.vala
index e6e94c3..086a177 100644
--- a/src/client/components/client-web-view.vala
+++ b/src/client/components/client-web-view.vala
@@ -154,7 +154,9 @@ public class ClientWebView : WebKit.WebView {
     /** Determines if the view has started rendering the HTML */
     public bool has_valid_height { get; private set; default = false; }
 
-    private string _document_font;
+    /** The HTML content's current preferred height. */
+    public int preferred_height { get; private set; default = 0; }
+
     public string document_font {
         get {
             return _document_font;
@@ -168,8 +170,8 @@ public class ClientWebView : WebKit.WebView {
             set_settings(settings);
         }
     }
+    private string _document_font;
 
-    private string _monospace_font;
     public string monospace_font {
         get {
             return _monospace_font;
@@ -183,14 +185,13 @@ public class ClientWebView : WebKit.WebView {
             set_settings(settings);
         }
     }
+    private string _monospace_font;
 
     private weak string? body = null;
 
     private Gee.Map<string,Geary.Memory.Buffer> internal_resources =
         new Gee.HashMap<string,Geary.Memory.Buffer>();
 
-    private int preferred_height = 0;
-
 
     /** Emitted when the view's selection has changed. */
     public signal void selection_changed(bool has_selection);
@@ -336,22 +337,6 @@ public class ClientWebView : WebKit.WebView {
         this.zoom_level -= (this.zoom_level * ZOOM_FACTOR);
     }
 
-    // XXX Surely since we are doing height-for-width, we should be
-    // overriding get_preferred_height_for_width here, but that
-    // doesn't seem to work.
-    public override void get_preferred_height(out int minimum_height,
-                                              out int natural_height) {
-        minimum_height = natural_height = this.preferred_height;
-    }
-
-    // Overridden since we always what the view to be sized according
-    // to the available space in the parent, not by the width of the
-    // web view.
-    public override void get_preferred_width(out int minimum_height,
-                                             out int natural_height) {
-        minimum_height = natural_height = 0;
-    }
-
     /**
      * Convenience function for registering and connecting JS messages.
      */
@@ -448,14 +433,19 @@ public class ClientWebView : WebKit.WebView {
 
     private void on_preferred_height_changed(WebKit.JavascriptResult result) {
         try {
-            this.preferred_height = (int) WebKitUtil.to_number(result);
-            if (this.preferred_height >= 1) {
-                // Avoid firing multiple notifies if the value hasn't
-                // changed
-                if (!this.has_valid_height) {
-                    this.has_valid_height = true;
+            int height = (int) WebKitUtil.to_number(result);
+            // Avoid notifying if the values have not changed
+            if (this.preferred_height != height) {
+                // value has changed
+                this.preferred_height = height;
+                if (height >= 1) {
+                    // value is valid
+                    if (!this.has_valid_height) {
+                        // validity has changed
+                        this.has_valid_height = true;
+                    }
+                    queue_resize();
                 }
-                queue_resize();
             }
         } catch (Geary.JS.Error err) {
             debug("Could not get preferred height: %s", err.message);
diff --git a/src/client/conversation-viewer/conversation-web-view.vala 
b/src/client/conversation-viewer/conversation-web-view.vala
index 78889cd..ffbdac8 100644
--- a/src/client/conversation-viewer/conversation-web-view.vala
+++ b/src/client/conversation-viewer/conversation-web-view.vala
@@ -80,6 +80,22 @@ public class ConversationWebView : ClientWebView {
         return WebKitUtil.to_string(result);
     }
 
+    // XXX Surely since we are doing height-for-width, we should be
+    // overriding get_preferred_height_for_width here, but that
+    // doesn't seem to work.
+    public override void get_preferred_height(out int minimum_height,
+                                              out int natural_height) {
+        minimum_height = natural_height = this.preferred_height;
+    }
+
+    // Overridden since we always what the view to be sized according
+    // to the available space in the parent, not by the width of the
+    // web view.
+    public override void get_preferred_width(out int minimum_height,
+                                             out int natural_height) {
+        minimum_height = natural_height = 0;
+    }
+
     private void on_deceptive_link_clicked(WebKit.JavascriptResult result) {
         try {
             JS.GlobalContext context = result.get_global_context();


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