From d74fcd2e2c3e5ed61695fd576b04662fadfaf6c0 Mon Sep 17 00:00:00 2001 From: Michael James Gratton Date: Mon, 30 Jan 2017 01:01:56 +1100 Subject: [PATCH] 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 57f0b538..92192ca3 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 e1727e75..43ac1424 100644 --- a/ui/conversation-web-view.js +++ b/ui/conversation-web-view.js @@ -51,20 +51,6 @@ ConversationPageState.prototype = { document.documentElement.dir = "auto"; } }, - /** - * 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. */ @@ -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); }