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.
This commit is contained in:
Michael James Gratton 2017-01-30 01:01:56 +11:00
parent 8bf68bd345
commit d74fcd2e2c
2 changed files with 23 additions and 24 deletions

View file

@ -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);
}