From adbf3e8cadb66666f307352b72537fbac57b916f Mon Sep 17 00:00:00 2001 From: Andy Huang Date: Sat, 13 Oct 2012 13:30:19 -0700 Subject: toggle normalization & zoom on/off and wire it all up to a pref that re-renders upon change. separately, make a few improvements to whitespace management when zoomed in with normalized mode: * place attachment overlays at the top of their regions * place overlays above the first expanded message at the top of the conversation, instead of the usual position just above the message. * impose a max zoom factor to limit excessive spacer whitespace Bug: 7312540 Change-Id: Iae3afff0ee81e4ba9367568e884a041780b24ebf --- assets/script.js | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'assets') diff --git a/assets/script.js b/assets/script.js index 27da9be3e..2aaf314e5 100644 --- a/assets/script.js +++ b/assets/script.js @@ -111,9 +111,15 @@ function normalizeAllMessageWidths() { function normalizeElementWidths(elements) { var i; var el; - var documentWidth = document.body.offsetWidth; + var documentWidth; var newZoom, oldZoom; + if (!NORMALIZE_MESSAGE_WIDTHS) { + return; + } + + documentWidth = document.body.offsetWidth; + for (i = 0; i < elements.length; i++) { el = elements[i]; oldZoom = el.style.zoom; @@ -256,23 +262,32 @@ function setupContentReady() { // BEGIN Java->JavaScript handlers function measurePositions() { - var overlayBottoms; - var h; + var overlayTops, overlayBottoms; var i; var len; - var expandedSpacerDivs = document.querySelectorAll(".expanded > .spacer"); + var expandedBody, headerSpacer; + var prevBodyBottom = 0; + var expandedBodyDivs = document.querySelectorAll(".expanded > .mail-message-content"); + + // N.B. offsetTop and offsetHeight of an element with the "zoom:" style applied cannot be + // trusted. - overlayBottoms = new Array(expandedSpacerDivs.length + 1); - for (i = 0, len = expandedSpacerDivs.length; i < len; i++) { - h = expandedSpacerDivs[i].offsetHeight; + overlayTops = new Array(expandedBodyDivs.length + 1); + overlayBottoms = new Array(expandedBodyDivs.length + 1); + for (i = 0, len = expandedBodyDivs.length; i < len; i++) { + expandedBody = expandedBodyDivs[i]; + headerSpacer = expandedBody.previousElementSibling; // addJavascriptInterface handler only supports string arrays - overlayBottoms[i] = "" + (getTotalOffset(expandedSpacerDivs[i]).top + h); + overlayTops[i] = "" + prevBodyBottom; + overlayBottoms[i] = "" + (getTotalOffset(headerSpacer).top + headerSpacer.offsetHeight); + prevBodyBottom = getTotalOffset(expandedBody.nextElementSibling).top; } - // add an extra one to mark the bottom of the last message + // add an extra one to mark the top/bottom of the last message footer spacer + overlayTops[i] = "" + prevBodyBottom; overlayBottoms[i] = "" + document.body.offsetHeight; - window.mail.onWebContentGeometryChange(overlayBottoms); + window.mail.onWebContentGeometryChange(overlayTops, overlayBottoms); } function unblockImages(messageDomId) { -- cgit v1.2.3