[geary/wip/728002-webkit2] Fix conversation message not shrinking when collapsing quotes.



commit 818a0477d2c8bad4124c5cac0d1ea4bbf727468f
Author: Michael James Gratton <mike vee net>
Date:   Mon Jan 30 01:01:56 2017 +1100

    Fix conversation message not shrinking when collapsing quotes.
    
    * ui/conversation-web-view.js (ConversationPageState::createControllableQuotes):
      Since WK does not want to seem to reduce the value of offsetHeight for
      the HTML element when a quote is collapsed, calculate the difference
      and manually update the preferred height.
    
    * ui/client-web-view.js (PageState::updatePreferredHeight): Allow the new
      preferred height to be passed in as a param.

 ui/client-web-view.js       |    7 +++++--
 ui/conversation-web-view.js |   40 ++++++++++++++++++----------------------
 2 files changed, 23 insertions(+), 24 deletions(-)
---
diff --git a/ui/client-web-view.js b/ui/client-web-view.js
index 57f0b53..92192ca 100644
--- a/ui/client-web-view.js
+++ b/ui/client-web-view.js
@@ -84,9 +84,12 @@ PageState.prototype = {
     /**
      * Sends "preferredHeightChanged" message if it has changed.
      */
-    updatePreferredHeight: function() {
+    updatePreferredHeight: function(height) {
+        if (height === undefined) {
+            height = this.getPreferredHeight();
+        }
+
         let updated = false;
-        let height = this.getPreferredHeight();
         if (height > 0 && height != this.lastPreferredHeight) {
             updated = true;
             this.lastPreferredHeight = height;
diff --git a/ui/conversation-web-view.js b/ui/conversation-web-view.js
index e1727e7..43ac142 100644
--- a/ui/conversation-web-view.js
+++ b/ui/conversation-web-view.js
@@ -52,20 +52,6 @@ ConversationPageState.prototype = {
         }
     },
     /**
-     * Polls for a change in the page's preferred height.
-     */
-    pollPreferredHeightUpdate: function() {
-        let state = this;
-        let count = 0;
-        let timeoutId = window.setInterval(function() {
-            if (state.updatePreferredHeight() || ++count >= 10) {
-                // Cancel polling when height actually changes or if
-                // no change was found after a long enough period
-                window.clearTimeout(timeoutId);
-            }
-        }, 10);
-    },
-    /**
      * Add top level blockquotes to hide/show container.
      */
     createControllableQuotes: function() {
@@ -91,16 +77,30 @@ ConversationPageState.prototype = {
                     );
                 }
 
+                let quoteDiv = document.createElement("DIV");
+                quoteDiv.classList.add("geary-quote");
+                quoteDiv.appendChild(blockquote);
+
                 let state = this;
                 function newControllerButton(styleClass, text) {
                     let button = document.createElement("BUTTON");
                     button.classList.add("geary-button");
                     button.type = "button";
                     button.onclick = function() {
-                        quoteContainer.classList.toggle(
-                            ConversationPageState.QUOTE_HIDE_CLASS
-                        );
-                        state.pollPreferredHeightUpdate();
+                        let hide = ConversationPageState.QUOTE_HIDE_CLASS;
+                        quoteContainer.classList.toggle(hide);
+
+                        // Update the preferred height. We calculate
+                        // what the difference should be rather than
+                        // getting it directly, since WK won't ever
+                        // shrink the height of the HTML element.
+                        let height = quoteContainer.offsetHeight - quoteDiv.offsetHeight;
+                        if (quoteContainer.classList.contains(hide)) {
+                            height = state.lastPreferredHeight - height;
+                        } else {
+                            height = state.lastPreferredHeight + height;
+                        }
+                        state.updatePreferredHeight(height);
                     };
                     button.appendChild(document.createTextNode(text));
 
@@ -118,10 +118,6 @@ ConversationPageState.prototype = {
                     "geary-hider", "▲        ▲        ▲"
                 ));
 
-                let quoteDiv = document.createElement("DIV");
-                quoteDiv.classList.add("geary-quote");
-                quoteDiv.appendChild(blockquote);
-
                 quoteContainer.appendChild(quoteDiv);
                 parent.insertBefore(quoteContainer, nextSibling);
             }


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